akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	int sum = -1, sugar = 0;
	for (int i = 0; 100 * i <= f; i += a) {
		for (int j = 0; 100 * (i + j) <= f; j += b) {
			for (int k = 0; 100 * (i + j) + k <= f; k += c) {
				for (int l = 0; 100 * (i + j) + k + l <= f; l += d) {
					int tmp = k + l;
					int t = 100 * (i + j) + tmp;
					if (tmp <= (i + j)*e&&t > 0 && (sum < 0 || sugar * t < tmp*sum)) {
						sugar = tmp; sum = t;
					}
				}
			}
		}
	}
	cout << sum << " " << sugar << endl;
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if j >= w[i][1]:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i][1]] + w[i][0])

print(dp[N][W])



Measured memory_bytes: 25952
#include <stdio.h>
 
int A[25], n;
 
int main()
{
  int M, q, i;
  
  scanf("%d", &n);  
  for(i=0; i<n; i++){
	scanf("%d", &A[i]);
  }
    scanf("%d", &q);
	
    for(i=0; i<q; i++){
	  scanf("%d", &M);   
	  if(solve(0, M) == 1) puts("yes");
	  else puts("no");
    }
    return 0;
}


int solve(int p, int t)
{  
  if(p == n){
	if(t == 0) return 1;
	else return 0;	
  }
  
  if(solve(p+1, t-A[p]) == 1) return 1;
  if (solve(p + 1, t) == 1) return 1;
}

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

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    double answer=0;
    for(int i=0; i<n; i++){
        int tmp;
        cin>>tmp;
        answer+=1/(double)tmp;
    }
    cout<<1/answer;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(V) V.begin,V.end
const int N = 100005;
vector<pair<int,int>> adj[N];
int col[N];
bool vis[N];
int dist[N];
void dfs(int x,int dis)
{
    col[x] = dis&1;
    //cout << "x " << x <<  "dis " << dis;
    vis[x] = true;
    for(auto t:adj[x])
    {
        //cout << t.first << " ";
        int w = t.second;
        if(!vis[t.first])
        {
            dfs(t.first,dis+w);
        }
    }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for(int i=0;i<n-1;++i)
    {
        int u,v,w;
        cin >> u >> v >> w;
        --u,--v;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    // for(int i=0;i<n;++i)
    // {
    //     cout << i << " ";
    //     for(auto x:adj[i])
    //     {
    //         cout << x.first << " ";
    //     }
    //     cout << endl;
    // }
    dfs(0,0);
    cout << endl;
    for(int i=0;i<n;++i)
    cout << col[i] << endl;
}

Measured memory_bytes: 7680
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long a = n % k;
		long b = k - a;
		long ans = Math.min(a, b);
		
		out.println(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

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

int main(){
  string S;cin >> S;
  if(S[0]==S[1]&&S[1]==S[2]){
    cout << "Yes" << endl;
  }else if(S[1]==S[2]&&S[2]==S[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main() {
	
	string s;
	cin>>s;
	
	int len = s.length();
	int a[26];
	
	string ans;
	memset(a,0,sizeof(a));
	
	for(int i=0;i<len;i++){
	    a[s[i]-'a']++;
	}
	
	bool flag = false;
	char c = 'a';
	for(int i=0;i<26;i++){
	    if(!a[c-'a']){
	        flag = true;
	        ans.pb(c);
	        break;
	    }
	    c++;
	}
	
	if(!flag) cout<<"None"<<'\n';
	else cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 512
package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n,m,low int
	Fscan(in, &n,&m,&low)
	cost := make([]int,n)
	mat := make([][]int, n)
	for i := range mat {
		Fscan(in, &cost[i])
		mat[i] = make([]int, m)
		for j := range mat[i] {
			Fscan(in, &mat[i][j])
		}
	}
	ans := int(1e9)
	//outer:
	for sub := 0; sub < 1<<n; sub++ {
		// do(sub)
		s := 0
		level := make([]int, m)
		for i := 0; i < n; i++ {
			if sub>>i&1 == 1 {
				s+=cost[i]
				for j, v := range mat[i] {
					level[j]+=v
				}
			}
		}
		ok := true
		for _, v := range level {
			if v<low {
				ok=false
				break
			}
		}
		if ok {
			ans = min(ans, s)
		}
	}
	if ans == 1e9 {
		ans = -1
	}
	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 2228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, d;
  cin >> n >> d;
  int ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x*x+y*y <= d*d)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <bitset>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool neg=c=='-';
	neg?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return neg?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
template<class T>inline void mset(T a,int v,int n){memset(a,v,n*sizeof(a[0]));}
const int N=2010;
bitset<N*N>f;
int main(){
	const int n=ni;
	int sum=0;
	f.set(0);
	for(int i=1;i<=n;i++){
		const int a=ni;
		f|=f<<a;
		sum+=a;
	}
	sum=(sum+1)>>1;
	for(int i=sum;;i++){
		if(f.test(i)){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
let n = stdin.ReadLine() |> int
let str = stdin.ReadLine().ToCharArray();

let getABC s = 
    let rec inner s count =
      if (s |> Array.length) <= 2 then count
      else
        let str = s.[0..2] |> System.String 
        inner (s |> Array.tail) (if str = "ABC" then count+1 else count)
    inner s 0

str |> getABC |> stdout.WriteLine

Measured memory_bytes: 27816
def nxt(i,j,h,w)
  ret = []
  ret << [i-1,j] if i > 0
  ret << [i+1,j] if i < h-1
  ret << [i,j-1] if j > 0
  ret << [i,j+1] if j < w-1
  return ret
end

h,w = gets.split.map(&:to_i)
s = []
h.times do 
  s << gets.chomp
end
table=Array.new(h){Array.new(w,true)}
id = 1
ans = 0
h.times do |i|
  w.times do |j|
    if table[i][j]
      table[i][j] = false
      search = [[i,j]]
      cnt = [0,0]
      cnt[s[i][j]=="#" ? 0 : 1] += 1
      while tmp = search.shift
        a,b = tmp
        color = s[a][b] == "#" ? "." : "#"
        nxt(a,b,h,w).each do |x,y|
          if table[x][y] && s[x][y] == color
            table[x][y] = false
            search << [x,y]
            cnt[s[x][y]=="#" ? 0 : 1] += 1
          end
        end
      end
      ans += cnt[0]*cnt[1]
      #p cnt
    end
  end
end
p ans

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	double n, ans = 0;
	cin >>n ;
	const double PI = acos(-1);
	
	printf("%.13f\n", 2.0*PI*n);
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <string.h>

using namespace std;
int main(void){

  int length;

  std::string s;

  cin >> s;

  length = s.size();


  if(length == 2)
    cout << s << endl;
  else
    for(int i=length-1; i >= 0; i--)
      cout << s[i];


}


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

int main()
{
	int A[4][3][10];
	int n;
	int b, f, r, v;
	int i, j, k;

	for (i = 0;i < 4;i++)
		for (j = 0;j < 3;j++)
			for (k = 0;k < 10;k++)
				A[i][j][k] = 0;

	cin >> n;
	for (i = 0;i < n;i++) {
		cin >> b >> f >> r >> v;
		A[b-1][f-1][r-1] = A[b-1][f-1][r-1]+v;
	}

	for (i = 0;i < 4;i++) {
		for (j = 0;j < 3;j++) {
			for (k = 0; k < 10;k++)
				cout << " " << A[i][j][k];
			cout << endl;
		}
		if (i != 3)cout << "####################" << endl;
	}

	return 0;
}


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

int main(){
  string S;
  int K,t;
  bool a=true;
  cin>>S>>K;
  for(int i=0;i<K;i++){
    if(i>=S.size())break;
    if(S.at(i)!='1'){
      a=false;
      t=i;
      break;
    }
  }
  if(a){
    cout<<1<<endl;
  }else{
    cout<<S.at(t)<<endl;
  }
  
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> masu(H);
  for (int i=0;i<H;i++){
    cin>>masu.at(i);
  }

  vector<int> H_kuro(H,0);
  vector<int> W_kuro(W,0);

  for (int i = 0;i<H;i++){
    for (int j = 0;j<W;j++){
      if(masu.at(i).at(j)=='#'){
        H_kuro.at(i)=1;
        W_kuro.at(j)=1;
      }
    }
  }

  for (int i = 0;i<H;i++){
    for (int j = 0;j<W;j++){
      if(H_kuro.at(i)==1 && W_kuro.at(j)==1){
        cout<<masu.at(i).at(j);
      }
      if(H_kuro.at(i)==1 && j==W-1){
        cout<<endl;
      }
    }
  }
}


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

int main() 
{
  while(true){
    int m,f,r;
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1){
      return 0;
    }else if(m == -1 || f == -1){
      cout << "F" << endl;
      continue;
    }else if(m+f >= 80){
      cout << "A" << endl;
      continue;
    }else if(m+f >= 65){
      cout << "B" << endl;
      continue;
    }else if(m+f >= 50){
      cout << "C" << endl;
      continue;
    }else if(m+f >= 30 && r >= 50){
      cout << "C" << endl;
      continue;
    }else if(m+f >= 30){
      cout << "D" << endl;
      continue;
    }else{
      cout << "F" << endl;
      continue;
    }
  }
}


Measured memory_bytes: 3088
#include <stdio.h>

int N, M, adj[10][10] = {}, bit[10] = {0, 0, 1, 2, 4, 8, 16, 32, 64}, dp[10][128];

int recursion(int n, int rest)
{
	if (dp[n][rest] >= 0) return dp[n][rest];
	else if (rest == bit[n]) {
		dp[n][rest] = 1;
		return dp[n][rest];
	} else dp[n][rest] = 0;
	
	int i;
	for (i = 2; i <= N; i++) {
		if (adj[n][i] == 1 && (rest | bit[i]) == rest) dp[n][rest] += recursion(i, rest ^ bit[n]);
	}
	return dp[n][rest];
}

int main()
{
	int i, u, w;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		scanf("%d %d", &u, &w);
		adj[u][w] = 1;
		adj[w][u] = 1;
	}
	
	int j, ans = 0, all = 1 << (N - 1);
	for (i = 2; i <= N; i++) for (j = 1; j <= 127; j++) dp[i][j] = -1;
	for (i = 2; i <= N; i++) if (adj[1][i] == 1) ans += recursion(i, all - 1);
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b, c = (int(_) for _ in input().split())  
    print(min(a*b,c))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
nx = input().split()
an = input().split()

n = int(nx[0])
x = int(nx[1])

count = 0
an = list(map(int, an))
an.sort()
num = len(an) - 1
for i in range(len(an)):
    if (x >= an[i]):
        count += 1
        x = x - an[i]
        if (i == num):
            if (x != 0):
                count -= 1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[10000];
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	int ans=0;
	for(register int i=1;i<=n/2;i++){
		if(c[i]!=c[n-i+1])ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int tx[128][128], ty[128][128];
		rep (i, n)
			rep (j, n)
				scanf("%d%d", &tx[i][j], &ty[i][j]);

		int visit[128][128];
		memset(visit, -1, sizeof(visit));

		int res = 0;
		for (int y = 0; y < n; ++y)
		{
			for (int x = 0; x < n; ++x)
			{
				int mark = n * y + x;
				if (visit[y][x] == -1)
				{
					int cx = x, cy = y;
					while (visit[cy][cx] == -1)
					{
						visit[cy][cx] = mark;
						int xx = cx, yy = cy;
						cx = tx[yy][xx];
						cy = ty[yy][xx];

						if (visit[cy][cx] == mark)
							++res;
					}
				}
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    double ans = 0.0;
    bool f = false;
    for(int i = 0; i < n; ) {
      if(!f) ans = (v[i] + v[i+1])/2.0;
      else ans = (ans + v[i]) / 2.0;
      if(f) ++i;
      if(!f){
        i += 2;
        f = true;
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
Vs=LI()
Vs.sort()

value = Vs[0]
for i in range(1, N):
    value = (value + Vs[i]) * 0.5

print(value)


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

long long a[55], p[55];//a:暑さ、p:パティ

long long burger(int n, long long x){
    if(n==0){
        return x <= 0 ? 0 : 1;
    }else if(x <= 1 + a[n-1]){
        return burger(n-1, x-1);
    }else{
        return p[n-1] + 1 + burger(n - 1, x - 2 - a[n-1]);
    }
}

int main(){
    int n;
    long long x;
    cin >> n >> x;
    a[0] = 1;
    p[0] = 1;
    for(int i = 1; i <= n; i++){
        a[i] = a[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }

    cout << burger(n, x) << endl;
    return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;
const int MAX_N = 131702;

ll pow(ll a, ll n) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a) {
		if (n % 2LL == 1LL) {
			ret = ret * a;
		}
	}
	return ret;
}

struct SegmentTree{//RMQ

  ll n;
  ll dat[MAX_N*4];

  void init(){
    for(ll i = 0LL; i < 2LL*n-1LL;i++) dat[i]=0LL;
  }

  void update(ll i,ll x) {
    i += n-1LL;
    dat[i]=x;

    while(i>0LL){
      i=(i-1LL)/2LL;
      dat[i]=max(dat[i*2LL+1LL],dat[i*2LL+2LL]);
    }
  }

  ll query(ll a,ll b,ll k, ll l, ll r){
    if(r<=a||b<=l) return 0LL;
    if(a<=l&&r<=b) return dat[k];
    else{
      ll vl = query(a,b,k*2LL+1LL,l,(l+r)/2LL);
      ll vr = query(a,b,k*2LL+2LL,(l+r)/2LL,r);
      return max(vl,vr);
    }
  }
};

int main() {
  ll N;
  cin>>N;
  vector<ll> h(N);
  vector<ll> a(N);
  for(ll i = 0LL; i < N; i++) {cin>>h[i];h[i]--;}
  for(ll i = 0LL; i < N; i++) cin>>a[i];
  ll cnt = 0LL;
  ll s = N-1;
  while(s>0){
    s/=2LL;
    cnt++;
  }
  ll n = pow(2,cnt);
  SegmentTree tree={n};
  tree.init();
  for(ll i = 0LL; i < N; i++){
    tree.update(h[i],tree.query(0,h[i],0,0,n)+a[i]);
  }
  cout<<tree.dat[0]<<endl;
}

Measured memory_bytes: 7552
implicit none
integer(8):: n, i, ans, k
integer(8),allocatable,dimension(:):: a

ans=0
k=0
 
read (5,*) n
allocate(a(n))
read(5,*) (a(i),i=1,n)

call heapsort(n,a)
 
do i=n,1,-1
    if(mod(k,2)==0)then
        ans=ans+a(i)
    else
        ans=ans-a(i)
    endif
    k=k+1
enddo


write(6,"(i0)") ans

end
 
!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    double precision,intent(inout) :: array(1:n)
   
    integer ::i,k,j,l
    double precision :: t
   
    if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
    endif
    if(n.eq.1)return
 
    l=n/2+1
    k=n
    do while(k.ne.1)
        if(l.gt.1)then
            l=l-1
            t=array(L)
        else
            t=array(k)
            array(k)=array(1)
            k=k-1
            if(k.eq.1) then
                array(1)=t
                exit
            endif
        endif
        i=l
        j=l+l
        do while(j.le.k)
            if(j.lt.k)then
                if(array(j).lt.array(j+1))j=j+1
            endif
            if (t.lt.array(j))then
                array(i)=array(j)
                i=j
                j=j+j
            else
                j=k+1
            endif
        enddo
        array(i)=t
    enddo
 
    return
end subroutine heapsort

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(a: int, b: int, c: int):
    print("YES" if b - a == c - b else "NO")
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


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

int main() 
{
   int a,b,ans,count=2;
   cin>>a>>b;
   while(count>0)
   {
      if(a>=b)
      {
        ans+=a;
        a--;
        count--;
      }
      else if(b>=a)
      {
          ans+=b;
          b--;
          count--;
      }
   }
   cout<<ans;
   return 0;
   
}

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

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

  vector<int> cnt(m);
  for(int i=0; i<n; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int x;
      cin >> x;
      cnt[x-1]++;
    }
  }

  int ans=0;
  for(int i=0; i<m; i++) ans+=(cnt[i]>=n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n, m, k = map(int, raw_input().split(" "))
    for i in range(0, n + 1):
        for j in range(0, m + 1):
            a = j
            b = i
            if b * m + a * n - 2 * a * b == k:
                return "Yes"
    return "No"

if __name__ == '__main__':
    m = main()
    print m

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

int main() {
    int a[3];
    for (int i = 0; i < 3; i++){
        cin >> a[i];
    }
    
    int min = a[0];
    int max = a[0];
    int mid = a[0];
    int minA = 0;
    int maxA = 0;
    
    for(int i = 1; i < 3; i++){
        if(a[i] < min){
            min = a[i];
            minA = i;
        }
        if(a[i] > max){
            max = a[i];
            maxA = i;
        }
    }
    mid = a[3 - minA - maxA];
    
    cout << min << " " << mid << " " << max << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  long long A[N], y[N];
  int s = 0, As=0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    s += A[i];
    if ((i+1)%2==0) As += A[i];
  }

  y[0] = s - 2 * As;
  for (int j = 1; j < N; j ++) {
    y[j] = A[j-1] * 2 - y[j-1];
  }

  
  for (int i = 0; i < N; i++){
    printf("%llu ", y[i]);
  }
  printf("\n");
  
  
}


Measured memory_bytes: 5308
a = list(map(int, input().split()))

if a[0] % 2 == 1 or a[1] % 2 == 1 or a[2] % 2 == 1:
    print(0)
    exit()

cnt = 0
for _ in range(1000):
    for i in a:
        if i % 2 == 1:
            print(cnt)
            exit()
    a[0], a[1], a[2] = a[1] // 2 + a[2] // 2, a[0] // 2 + a[2] // 2, a[0] // 2 + a[1] // 2
    cnt += 1
else:
    print(-1)

Measured memory_bytes: 3064
n,k,q = map(int, input().split())

a_cnt = [0]*n
for _ in range(q):
    a = int(input()) - 1
    a_cnt[a] += 1


for a in a_cnt:
    if k - (q-a) > 0:
        print('Yes')
    else:
        print('No')

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pi;
typedef map<ll,ll> mi;

template<class T> T nrem(T x,T y){return ((x%y)+y)%y;}

#define For(i,a,n) for(int i=a;i<n;++i)
#define For0(i,n) for(int i=0;i<n;++i)
#define For1(i,n) for(int i=1;i<=n;++i)
#define Forl0(i,n) for(ll i=0;i<n;++i)
#define Forl1(i,n) for(ll i=1;i<=n;++i)
#define fi freopen("input.txt","r",stdin);
#define fo freopen("output.txt","w",stdout);
#define pb push_back
#define mp make_pair
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cs 1000005
#define pi acos(-1)
#define INF (int)INFINITY
void in()
{
     #ifndef ONLINE_JUDGE
         freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
     #endif
}

int main()
{  in();
    int n;
    cin>>n;

    
    long double mx=log(1e18),x;
    ll s=1;
    long double sum=0.0;
    int f=0,g=0;
    
  For0(i,n)
   {
     cin>>x;

     if(x!=0)
     sum+=log10(x);
     else f=1;
   //  cout<<sum<<endl;
     if(sum>mx)
     g=1,s=0;
      s*=x;
   }
 //  cout<<sum<<endl;
  if(f==1)
  cout<<0<<endl;
  else if(g==1||s>(ull)1e18)
  cout<<-1<<endl;
  else cout<<s<<endl;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int i = 0;
    int count = 0;
    while(i < N){
        int j = 1;
        while(i+j < N){
            if(S[i+j] == S[i]){
                j++;
            }
            else break;
        }
        count++;
        i += j;
    }
    cout << count << endl;
}

Measured memory_bytes: 512
import sys
from operator import itemgetter
import collections


def r(n, m, kl):
    nc = 0
    al = []
    for k in kl:
        al.extend(k[1:])
    c = collections.Counter(al)
    for v in c.values():
        if v == n:
            nc += 1
    return nc

def main():
    input = sys.stdin.readline
    n, m = list(map(int, input().split()))
    kl = [tuple(map(int, input().split())) for _ in range(n)]

    print(r(n, m, kl))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3452
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				for(int k = j+1; k < n; k++) {
					ans += (check(a[i], a[j], a[k]) && a[i] != a[j] && a[j] != a[k] && a[i] != a[k] ? 1 : 0);
				}
			}
		}
		System.out.println(ans);
	}
	
	public static boolean check(int a, int b, int c) {
		if(c > Math.abs(a-b) && c < Math.abs(a+b) && b > Math.abs(a-c) && b < Math.abs(a+c) && a > Math.abs(b-c) && a < Math.abs(b+c)) {
			return true;
		}
		return false;
	}
}


Measured memory_bytes: 37588
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  vector<string> line;
  vector<int> cnt;
  getline(cin,s);
  string word = "";
  string longest = "";
  
  rep(i,s.size()){
    if(s[i] == ' '){
      if(longest.size() < word.size()){
	longest = word;
      }
      bool find = false;
      
      rep(j,line.size()){
	if(line[j] == word){
	  cnt[j] ++;
	  find = true;
	  word = "";
	}
      }
      
      if(find)continue;
      line.pb(word);
      word = "";
    }else{
      word += s[i];
      cnt.pb(1);
    }
  }
  
  int ma = 0;
  string res = "";
  
  rep(i,line.size()){
    if(ma < cnt[i]){
      ma = cnt[i];
      res = line[i];
    }
  }
  
  cout<<res<<" "<<longest<<endl;

}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	char a, b;
	cin >> a >> b;
	if (a == b) cout << "H" << endl;
	else cout << "D" << endl;
}

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

const long long mod  = 1e9 + 7;

long long modpow(long long a, long long n) {
    long long r = 1;
    while(n) {
        r = r * ( (n%2) ? a : 1) % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return r;
}

long long modcomb(int n, int k) {
    if ( n < 0 || k < 0 || k > n) return 0;
    k = min(k, n - k); //nCk = nC(n-k)
    long long p = 1, q = 1;
    while ( k > 0 ) {
        p = p * n-- % mod; // p = n*(n-1)*(n-2)...(n-k+1)
        q = q * k-- % mod; // q = k*(k-1)*(k-2)...1
    }
    // 1/q = q^(p-2) (mod p)
    return p * modpow(q, mod - 2) % mod;
}

int main(){
	int N, M, K;
	cin >> N >> M >> K;
    long long x = 0, y = 0;
    for (int d = 1; d < N; ++d){
        x += 1LL * d * (N-d) % mod;
    }
    x = x * M % mod * M % mod;
    for (int d = 1; d < M; ++d){
        y += 1LL * d * (M-d) % mod;
    }
    y = y * N % mod * N % mod;
    cout << (x + y) % mod * modcomb(N * M - 2, K - 2) % mod << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int q = in.nextInt();
		StringBuilder str1 = new StringBuilder();
		StringBuilder str2 = new StringBuilder(s);
		boolean hanten =false;
		for (int i = 0; i < q; i++) {
			int t = in.nextInt();
			if (t == 1) {
				hanten = !hanten;
			} else {
				int f = in.nextInt();
				String c = in.next();
				if(hanten == false){
					if (f == 1) {
						str1.append(c);
					} else {
						str2.append(c);
					}
				} else {
					if (f == 1) {
						str2.append(c);
					} else {
						str1.append(c);
					}
				}
			}
		}
		if(hanten){
			str2.reverse().append(str1);
			System.out.println(str2);
		} else {
			str1.reverse().append(str2);	
			System.out.println(str1);
		}
	}
}


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

int main(){
    int N;
    std::cin >> N;
    std::vector< int > A(N);
    for(int i=0; i<N;i++){
        std::cin >> A[i];
    }
    
    long long sum = 0;
    int min = 1e9;
    bool odd = false;
    for(int i=0; i<N;i++){
        if(A[i] < 0){
            A[i] *= -1;
            odd = odd ^ 1;
        }
        sum += A[i];
        if(min > A[i]){
            min = A[i];
        }
    }
    
    if(odd){
        sum -= 2 * min;
    }
    std::cout << sum << std::endl;
    
    
    
    return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
    int n, m;
    int time, ans;
    
    cin >> n >> m;
    
    time = (n-m)*100 + m*1900;
    ans = time * int(exp2(m));
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

vector <vector <int> > g;
int n;
vector <int> size;
int dfs1(int s,vector <bool> &visited);
ll mod=1e9+7;
vector <ll> test;
void dfs2(int s,vector <bool> &visited);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    n=nxt();
    vector <int> row;
    g.resize(n+1,row);
    for(int i=0;i<n-1;i++)
    {
        int u=nxt(),v=nxt();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    size.resize(n+1,0);
    vector <bool> visited;
    visited.resize(n+1,0);
    dfs1(1,visited);
    test.resize(n+1);
    ll num=1;
    for(ll i=2;i<=n;i++)
        (num*=i)%=mod;
    ll den=1;
    for(int i=1;i<=n;i++)
        (den*=size[i])%=mod;
    test[1]=(num*power(den,mod-2,mod))%mod;
    for(int i=0;i<n+1;i++)
        visited[i]=0;
    dfs2(1,visited);
    for(int i=1;i<=n;i++)
        cout<<test[i]<<endl;




    
    
    return 0;   
}

int dfs1(int s,vector <bool> &visited)
{
    visited[s]=1;
    int val=0;
    for(auto i:g[s])
    {
        if(!visited[i])
            val+=dfs1(i,visited);
    }
    size[s]=val+1;
    return val+1;
}

void dfs2(int s,vector <bool> &visited)
{
    visited[s]=1;
    for(auto i:g[s])
    {
        if(!visited[i])
        {
            test[i]=(test[s]*size[i])%mod;
            test[i]=(test[i]*power(n-size[i],mod-2,mod))%mod;
            dfs2(i,visited);
        }
    }
}

 
 


Measured memory_bytes: 16372
#include <iostream>
#include <cstring>
#include <cstdio>

#define LL long long

using namespace std;

inline LL read() {
    LL x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int main() {
    LL a, b, v, w, t;
    a = read(); v = read(); b = read(); w = read(); t = read();
    LL dist = b - a; if(dist < 0) dist = -dist;
    if((v - w) * t >= dist) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N, K;
string S;

int main() {
	cin >> N >> K;
	cin >> S;
	int A = 0;
	int B = 0;
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == S[i]) A++;
		else B++;
	}
	cout << A + min(B, 2 * K) << endl;
	return 0;
}

Measured memory_bytes: 512
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	w = list(S())
	c = Counter(w)
	c_array = np.array(list(c.values()))
	if np.all(c_array % 2 == 0):
		print('Yes')
	else:
		print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 13460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, a, b, c, x;
	a=b=c=0;
	cin >> n;
	rep(i, n)
	{
		cin >> x;
		if(x%4==0) a++;
		else if(x%2==0) b++;
		else c++; 
	}
	if(a>=c) cout << "Yes" << endl;
	else if(c==a+1 && b==0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    // 入力
    try (Scanner sc = new Scanner(System.in);) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      int bigger = b > a ? b : a;
      List<Integer> list = new ArrayList<>();
      for (int i = 1; i <= bigger; i++) {
        if (a % i == 0 && b % i == 0) {
          list.add(i);
        }
      }

      System.out.println(list.get(list.size() - c));
    }
  }
}

Measured memory_bytes: 21716
n = int(input())
hs = list(map(int, input().split()))
ms = [hs[0]]
for h in hs[1:]:
    m = ms[-1]
    if m >= h:
        ms.append(m)
    else:
        ms.append(h)
count = 0
for h, m in zip(hs, ms):
    if h >= m:
        count += 1
print(count)

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

int main() {
    int a, b, c, k, t=0;
    cin >> a >> b >> c >> k;
    t += min(k, a);
    k -= min(k, a);
    if (k>0) {
        k -= min(k, b);
    }
    if (k>0) {
        t -= min(k, c);
        k -= min(k, c);
    }
    cout << t << endl;
}


Measured memory_bytes: 3620
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()

    var cnt = 0

    for (i in 1..n) {
        cnt += i

        if (cnt >= n) {
            val diff = cnt - n
            val ans = mutableListOf<Int>()
            for (j in 1..i) {
                if (j != diff) ans.add(j)
            }
            println(ans.joinToString(separator = System.lineSeparator()))
            return
        }
    }
}

Measured memory_bytes: 37136
N = int(input())
A = list(map(int, input().split()))

counts = {}
for i in range(N):
    a = A[i]
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1

# print(counts)

ans_memory = {}
ans_memory_val = {}
for k in range(N):
    if A[k] in ans_memory:
        print(ans_memory[A[k]])
        continue
    if counts[A[k]] in ans_memory_val:
        print(ans_memory_val[counts[A[k]]])
        continue

    counts_tmp = counts.copy()
    counts_tmp[A[k]] -= 1

    # print(counts_tmp)
    ans = 0
    for v in counts_tmp.values():
        ans += v * (v - 1) // 2
    ans_memory[A[k]] = ans
    ans_memory_val[counts[A[k]]] = ans
    print(ans)


Measured memory_bytes: 36660
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        
        int start = Math.max(a,c);
        int end = Math.min(b,d);
        
        int ans = end - start;
        if(ans>0)
        {
            System.out.println(ans);
        }
        else
        {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 22868
n, k = map(int, input().split())
p = list(map(int, input().split()))
s = [0] * (n+1)

for i in range(0, n):
    s[i+1] = s[i] + p[i]

s_max = -1
pos = 0
for i in range(n-k+1):
    ss = s[i+k] - s[i]
    if ss > s_max:
        s_max = ss
        pos = i

ans = 0.0
for i in range(pos, pos+k):
    ans += (p[i]+1) / 2

print(ans)


Measured memory_bytes: 25060
#include <iostream>
using namespace std;
int main() {
	int N;
	int n = 0;
	int t = 0;
	cin >> N;
	for (int i = 111; i < 1110; i += 111) {
		if (t == 0) {
			if (N > i) {
				n = i;
			}
			else {
				t = 1;
			}
		}
	}
	cout << n+111 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    string s;
    cin >> N >> s;
    int x = 0, res = 0;
    for (char c : s) {
        x += (c == 'I' ? +1 : -1);
        
        res = max(res, x);
    }
    cout << res << endl;
    return 0;
}


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



int main(){
    ll N;
    cin >> N;
    ll count =0;
    while(N){
        ll s1,s2;
        cin >> s1 >> s2;
        
        if(s1==s2)count++;
        else count =0;
        if(count==3){
            cout << "Yes" << endl;
            return 0;
        }
        
        N--;
    }
    cout << "No" << endl;
    
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> X(N);
    for(int &x:X) cin >> x;
    
    vector<int> C(N);
    C = X;
    sort(C.begin(), C.end());
    int me1 = C[N/2-1];
    int me2 = C[N/2];
    
    for(int i=0; i<N; i++){
        if(X[i]<=me1) cout << me2 << endl;
        else cout << me1 << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3712
#include <stdio.h>
#define N 100
int main(){
  int n,a[N],v,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  } for(i=0;i<n;i++){
      if(i)printf(" ");
      printf("%d",a[i]);
    }
  printf("\n");
  for(i=1;i<=n-1;i++){
    v = a[i];
    j = i - 1;
    while(j>=0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
      a[j+1] = v;
    for(k=0;k<n;k++){
      if(k)printf(" ");
      printf("%d",a[k]);
    }
    printf("\n");
}
    return 0;
}



Measured memory_bytes: 2144