akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vint dx = {1,0,-1,0};
vint dy = {0,1,0,-1};

int h, w;
vector<string> field;


void bfs(P s, vvint &dis) {
    queue<P> q;
    q.push(s);
    dis[s.first][s.second] = 0;
    while (!q.empty()) {
        P p = q.front(); q.pop();
        rep(i,4) {
            int n_x = p.second + dx[i];
            int n_y = p.first + dy[i];
            if (n_x >= 0 && n_x < w && n_y >= 0 && n_y < h) {
                if (field[n_y][n_x] != '#' && dis[n_y][n_x] == inf) {
                    dis[n_y][n_x] = dis[p.first][p.second] + 1;
                    q.push(P(n_y,n_x));
                }
            }
        }
    }
}

int main() {
    cin >> h >> w;
    field.resize(h);
    rep(i,h) cin >> field[i];
    P s, g;
    int ans = -1;
    rep(i,h)rep(j,w) {
        if (field[i][j] == '#') continue;
        s = P(i,j);
        vvint dis(h,vint(w,inf));
        bfs(s,dis);
        rep(i_,h)rep(j_,w) {
            if (dis[i_][j_] == inf) continue;
            else ans = max(ans,dis[i_][j_]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {          
    
  public static void main(String[] args) {
   
     Scanner sc = new Scanner(System.in);          
     
     int N = sc.nextInt();
    
     String S = String.valueOf(N);
     
     if(S.contains("9")){
         System.out.println("Yes");
     }else{
         System.out.println("No");         
     }
     
     
  }                            
}
    



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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  ll  i, n ,d,cnt=0;
  string s; cin>>n>>s;
  ll ans= min(count(s.begin() , s.end() ,'R') ,count( s.begin() , s.end() , 'W'));
  ll r= count(s.begin() , s.end() ,'R');
  for(i=0;i<r;i++){
    if(s[i]=='W')cnt++;
    ans = min( ans , cnt+ r-i-1);
  }
  cout<< ans ;
}   

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[300],b[300],c[300],dp[300][300],s[300],n,d,ans;
int main(){
	cin>>d>>n;
	r(i,d)cin>>s[i];
	r(i,n)cin>>a[i]>>b[i]>>c[i];
	r(i,n)if(a[i]<=s[0]&&s[0]<=b[i])dp[0][i]=1;
	for(int i=1;i<d;i++)r(j,n)r(k,n)if(dp[i-1][j])if(a[k]<=s[i]&&s[i]<=b[k])
		dp[i][k]=max(dp[i][k],dp[i-1][j]+abs(c[j]-c[k]));
	r(i,n)ans=max(ans,dp[d-1][i]);
	cout<<ans-1<<endl;
}

Measured memory_bytes: 3268
n = int(input())
d = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}

for _ in range(n):
  s = input()
  d[s] += 1

print("AC x {}".format(d["AC"]))
print("WA x {}".format(d["WA"]))
print("TLE x {}".format(d["TLE"]))
print("RE x {}".format(d["RE"]))

Measured memory_bytes: 9196
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
 
 
def main():

    s=input()
    t=input()
    n=len(s)
    m=len(t)
    ans=m
    for x in range(n-m+1):
        count=0
        cc=0
        for y in range(x,x+m):
            #print(s[y],end="")
            if s[y]!=t[cc]:
                count+=1
            cc+=1
        ans=min(count,ans)
    print(ans)


#-----------------------------BOSS-------------------------------------!
# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 67592
#include <iostream>
#include <string.h>
#define ll long long
using namespace std;


void printA(int *A,int size)
{
    for(int i=0;i<size;i++)
        cout<<A[i]<<" ";
}
void scanA(int *A,int size)
{
    for(int i=0;i<size;i++)
        cin>>A[i];
}



int sum(int n);
int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    int height[n],result[n];
    for(int i=0;i<n;i++)
    {
        cin>>height[i];
        result[i]=0;
    }
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(height[a-1]>height[b-1])
        {
            result[b-1]=-1;
        }
        else if(height[a-1]<height[b-1])
            result[a-1]=-1;
        else
        {
            result[a-1]=-1;
            result[b-1]=-1;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(!result[i]) sum++;
    }
    cout<<sum;


}






Measured memory_bytes: 4328
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        L = max(A).bit_length()
        s = [0]*L

        def check(x):
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            return(x == 0)

        def update(x):
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            id = x.bit_length() - 1
            if id >= 0:
                s[id] = x

        res = 0
        for i in range(N-1, -1, -1):
            k = int(S[i])
            if k:
                if check(A[i]):
                    continue
                else:
                    res = 1
                    break
            else:
                update(A[i])
        print(res)


main()


Measured memory_bytes: 9236
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.LinkedList;
import java.util.Collections;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DStringFormation solver = new DStringFormation();
        solver.solve(1, in, out);
        out.close();
    }

    static class DStringFormation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            Character[] arr = str.chars().mapToObj(c -> (char) c).toArray(Character[]::new);
            LinkedList<Character> l = new LinkedList<>(Arrays.asList(arr));
            int q = Integer.parseInt(in.next());
            int t = 0;
            int f = 0;
            char c;

            boolean reverseFlg = false;
            for (int i = 0; i < q; i++) {
                t = Integer.parseInt(in.next());
                if (t == 1) {
                    reverseFlg = !reverseFlg;
                } else {
                    f = Integer.parseInt(in.next());
                    c = in.next().charAt(0);
                    if ((f == 2 && !reverseFlg) || (f == 1 && reverseFlg)) {
                        l.add(c);
                    } else {
                        l.addFirst(c);
                    }
                }
            }
            String r;
            if (reverseFlg) {
                Collections.reverse(l);
                r = l.stream().map(String::valueOf).collect(Collectors.joining());
            } else {
                r = l.stream().map(String::valueOf).collect(Collectors.joining());
            }
            out.append(r);
        }

    }
}



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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n, a[101];
int getcolour(int rating)
{
	if(rating <= 399)
		return 0;
	else if(rating >= 400 && rating <= 799)
		return 1;
	else if(rating >= 800 && rating <= 1199)
		return 2;
	else if(rating >= 1200 && rating <= 1599)
		return 3;
	else if(rating >= 1600 && rating <= 1999)
		return 4;
	else if(rating >= 2000 && rating <= 2399)
		return 5;
	else if(rating >= 2400 && rating <= 2799)
		return 6;
	 //if(rating >= 2800 && rating <= 3199)
	return 7;
}
void minmax()
{
	VB used(8, false);

	int grandmaster = 0;
	for(int i = 0; i < n; ++i)
	{
		if(a[i] >= 3200) {
			++grandmaster;
			continue;
		}
		int col = getcolour(a[i]);
		used[col] = true;
	}

	int mincolor = count(ALL(used), true);
	cout << max(1, mincolor) << " ";

	int available = 0;
	for(int i = 0; i < n; ++i)
		if(!used[i]) ++available;

	cout << mincolor + min(grandmaster, available) << endl;
	int e = 10;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	REP(i, 0, n) cin >> a[i];

	minmax();

	return 0;
}

Measured memory_bytes: 256
n, d = map(int,input().split())
x=[]
dist=0
count=0
for i in range(n):
  x.append(list(map(int,input().split())))

for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      dist+=(x[i][k]-x[j][k])**2
    dist=dist**0.5
    if dist.is_integer():
      count+=1
    dist=0
print(count)

Measured memory_bytes: 3188
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int dp[100005];
    FOR(i, 0, N + 1) {
        dp[i] = INF;
    }

    dp[0] = 0;
    REP(i, N) {
        FOR(j, 1, K) {
            if (i + j >= N) break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N - 1] << endl;

    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, t;

int main() {
	cin >> n >> t;
	t /= 1000;
	
	incII(x, 0, n) {
	incII(y, 0, n) {
		int z = n - (x + y);
		if(z < 0) { continue; }
		if(10 * x + 5 * y + z == t) { cout << x << " " << y << " " << z << endl; return 0; }
	}
	}
	
	cout << "-1 -1 -1" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	ll n;
	cin >> n;
	ll a[n+5];
	rep(i, n){
		cin >> a[i];
	}
	vector<ll> ans;
	for (int i = 0; i < n; i += 2){
		ans.pb( a[i]^a[i + 1] );
	}
	ll combXOR = 0;
	for (auto val : ans){
		combXOR ^= val;
	}
	rep(i, n){
		a[i] ^= combXOR;
	}
	rep(i, n){
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5876
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] chars = new int[256];
    for(int i=0;i<256;i++){
      chars[i]=0;
    }
    while(sc.hasNextLine()){
      String line = sc.nextLine();
      for(int i=0;i<line.length();i++){
        char ch = Character.toLowerCase(line.charAt(i));
        chars[ch]++;
      }
    }
    for(char ch ='a';ch <='z';ch++){
      System.out.println(ch+" : "+chars[ch]);
    }
  }
}

Measured memory_bytes: 26072
def overlap(a, b, c, d):
    if d <= a:  return False
    if b <= c:  return False
    return True
 
a, b = map(int, input().split())
res = 0
for i in range(int(input())):
    s, t = map(int, input().split())
    if overlap(a, b, s, t): res = 1
print(res)


Measured memory_bytes: 5600
#include <stdio.h>

int main(){
	int n, G[100][100], tree[100][99] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			scanf("%d", &G[i][j]);
		}
	}

	int min0 = 2001;
	tree[0][0]++;
	for (int i = 1; i < n; i++){
		if (G[0][i]+1 && G[0][i] < min0){
			min0 = G[0][i];
			tree[0][1] = i;
		}
	}
	tree[tree[0][1]][0]++;

	for (int connected = 2; connected < n; connected++){
		int min = 2001,mink,minl;
		for (int k = 0; k < n; k++){
			if (!tree[k][0]){
				continue;
			}
			for (int l = 0; l < n; l++){
				if (!tree[l][0] && G[k][l] + 1 && G[k][l] < min){
					min = G[k][l];
					mink = k;
					minl = l;
				}
			}
		}
		tree[mink][++tree[mink][0]] = minl;
		tree[minl][++tree[minl][0]] = mink;
	}

	int sum = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < tree[i][0]; j++){
			sum += G[i][tree[i][j + 1]];
		}
	}

	printf("%d\n", sum >> 1);
	return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
typedef long long ll;
typedef pair<ll, ll> P;
map<long long, long long> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
signed main() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> graph(h, vector<char>(w));
    ll sum = 0;
    REP(i, h) {
        REP(j, w) {
            cin >> graph[i][j];
            if (graph[i][j] == '#') {
                sum++;
            }
        }
    }
    ll ans = 0;
    REP(i, 1 << h) {
        REP(j, 1 << w) {
            ll nowsum;
            nowsum = sum;
            REP(y, h) {
                REP(x, w) {
                    if (((i >> y) & 1) || ((j >> x) & 1)) {
                        if (graph[y][x] == '#') {
                            nowsum--;
                        }
                    }
                }
            }
            if (nowsum == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
n, m= map(int, input().split())
h = list(map(int, input().split()))

e = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

ans = 0
for j in range(n):
    if not e[j]:
        ans += 1
        continue
    hs = [h[k] for k in e[j]]
    if h[j] > max(hs):
        ans += 1
print(ans)




Measured memory_bytes: 98184
#include <bits/stdc++.h> 
using namespace std; 
#define rep(i,a,b)		for(int i=a;i<=b;i++)

int n,k,d,temp;
set<int> s;

int main() 
{ 

	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    while(k--)
    {
    	cin>>d;
    	while(d--)
    	{
    		cin>>temp;
    		s.insert(temp);
    	}
    }
    cout<<n-s.size();

} 


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  cin >> n;
  int a = n % 10;
  if (a == 3) {
    cout << "bon\n";
  } else if (a == 0 || a == 1 || a == 6 || a == 8) {
    cout << "pon\n";
  } else {
    cout << "hon\n";
  }
  return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
def main():
    import numpy as np

    np.set_printoptions(linewidth=200)

    N, W = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(N)]
    v_max = 10 ** 3 * 100 * 10
    w_max = 10 ** 9 * v_max

    # i以上の価値を持つときの最小重量
    dp = np.full(v_max, w_max, dtype=np.int64)
    # initialize
    dp[0] = 0

    for n in range(N):
        w, v = lst[n]
        dp[v:] = np.minimum(dp[v:], dp[:-v] + w)

    ans = 0
    for i, w in enumerate(dp):
        if w <= W:
            ans = i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50204
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int s,w;
    cin>>s>>w;
    cout<<(s<=w?"unsafe":"safe")<<endl;
}

Measured memory_bytes: 3640
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;
int k=2;

ll tab[nax];
ll dp[nax];

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
	}
	for (int i=2; i<=n; i++)
	{
		dp[i]=1e18;
		for (int j=1; j<=k && j<i; j++)
			dp[i]=min(dp[i], dp[i-j]+abs(tab[i]-tab[i-j]));
	}
	printf("%lld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 5120
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N = int(input())
Pn = list(map(int, input().split()))
ans = 0
for i in range(1,N-1):
  if Pn[i] == sorted([Pn[i-1],Pn[i],Pn[i+1]])[1]:
    ans += 1
print(ans)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!
    val b = readLine()!!
    val c = readLine()!!
    var ans = 0
    for (i in 0 until n) {
        ans += setOf(a[i], b[i], c[i]).size - 1
    }
    println(ans)
}

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

typedef long long ll;
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int t=1;
	//cin>>t;
	while(t--){
	 ll n,x;
	 cin>>n>>x;
	 ll sum=0;
	 ll a[n];
	 for(int i=1;i<=n;i++) cin>>a[i];
	 if(a[1]>x)
	 {
	 	sum+=a[1]-x;
	 	a[1]=x;
	 }
	 for(int i=2;i<=n;i++)
	 {
	 	ll t=a[i]+a[i-1];
	 	if(t<=x) continue;
	 	t-=x;
	 	sum+=t;
	 	
	 	//ll mintake=min(a[i],t);
	 	a[i]-=t;
	 	 
	 }
	 cout<<sum<<endl;
	}		
}

Measured memory_bytes: 4392
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
ans = B[0]
cnt = 1
#print(B,ans)
for i in range(1,N-1):
    ans += B[cnt]
    #print(ans,B[cnt],cnt)

    if i%2 == 0:
        cnt += 1
    #print(ans,B[cnt],cnt)

print(ans)

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Measured memory_bytes: 31440
// template {{{

#include <bits/stdc++.h>
using namespace std;

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline void chmax(T &x, U y){ x = std::max<T>(x, y); }

template<typename T, typename U>
inline void chmin(T &x, U y){ x = std::min<T>(x, y); }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(std::begin(c), std::end(c))); }

// }}}

using pr = pair<int, int>;
using tp = tuple<int, int, int>;

int n, m, c;
vector<pr> g[100];
int dist[100][110];

int main()
{
	while (cin >> n >> m >> c, n){
		rep(i, n) g[i].clear();
		fill_n(*dist, 100 * 110, INF);

		rep(i, m){
			int x, y, z;
			cin >> x >> y >> z;
			x--, y--;
			g[x].eb(y, z);
		}

		priority_queue<tp, vector<tp>, greater<tp>> pq;
		dist[0][0] = 0;
		pq.emplace(0, 0, 0);
		int res;
		while (pq.size()){
			int v, cnt, sum;
			tie(cnt, sum, v) = pq.top(); pq.pop();
			if (v == n - 1){
				res = cnt;
				break;
			}
			for (auto &e : g[v]){
				int to, cost;
				tie(to, cost) = e;
				if (dist[to][cnt] > sum + cost && sum + cost <= c){
					dist[to][cnt] = sum + cost;
					pq.emplace(cnt, sum + cost, to);
				}
				if (dist[to][cnt + 1] > sum && cnt + 1 < 110){
					dist[to][cnt + 1] = sum;
					pq.emplace(cnt + 1, sum, to);
				}
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 3132
public class Main {
	public static void main(String[] age){
		String input = new java.util.Scanner(System.in).nextLine();
		String[] inputarray = input.split(" ");
		int W = Integer.parseInt(inputarray[0]);
		int H = Integer.parseInt(inputarray[1]);
		int x = Integer.parseInt(inputarray[2]);
		int y = Integer.parseInt(inputarray[3]);
		int r = Integer.parseInt(inputarray[4]);
		int z=0;

		if(x<r){
			z++;
		}else if(y<r){
			z++;
		}else if(W<x+r){
			z++;
		}else if(H<y+r){
			z++;
		}
		if(z==0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d, d + n);
    cout << d[n / 2] - d[n / 2 - 1] << endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

void dfs(int now, int dist, vi &d, const vii &tree, vector<bool> &seen) {
  seen[now] = true;
  d[now] = dist;
  for(int next : tree[now]) {
    if(seen[next]) continue;
    dfs(next, dist+1, d, tree, seen);
  }
  return;
}


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

  int n;
  cin >> n;
  vii tree(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vi db(n), dw(n);
  vector<bool> seenb(n), seenw(n);
  db[0] = 0; dw[n-1] = 0;
  dfs(0, 0, db, tree, seenb);
  dfs(n-1, 0, dw, tree, seenw);
  int cntb = 0, cntw = 0;
  rep(i,n) {
    if(db[i] <= dw[i]) cntb++;
    else cntw++;
  }
  if(cntb > cntw) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

Measured memory_bytes: 12800
// Sun May 17 14:33:59 IST 2020      
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define MOD                998244353 
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()
const double pi = 3.141592653589793238;
using namespace std ;     
using namespace __gnu_pbds;
 
typedef tree<pair <int,int>,null_type,less<pair <int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 1e6+3; 
const int INF = INT_MAX;
struct comp{
    bool operator()(const int A,const int& B )const{
        return A > B; 
    }
};    
int tests(){  
    int n ;
    string s ;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0 ; i < n-2 ; i++ )
        if(s.substr(i,3) == "ABC")
            ans++ ;
    cout << ans << '\n'; 
    return 0;
}  
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;  
    while(cases--){    
        tests(); 
    }
    return 0 ; 
}
 
// -Wall -Wextra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  int n = s.size();
  vector<bool> v(26, false);

  if (n == 26) {
    v[s[n - 1] - 'a'] = true;
    repr(i, 0, n - 1) {
      int t = s[i] - 'a';
      rep(j, t, 26) {
        if (v[j]) {
          cout << s.substr(0, i) << (char)(j + 'a') << endl;
          return 0;
        }
      }
      v[s[i] - 'a'] = true;
    }
    cout << -1 << endl;
  } else {
    rep(i, 0, n) v[s[i] - 'a'] = true;
    rep(i, 0, 26) {
      if (!v[i]) {
        cout << s << (char)(i + 'a') << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,e) for(int i=s;i<e;i++)

using namespace std;

int main(void) {
	int H, A, B, ans = 0;
	cin >> H >> A >> B;
	FOR(i, A, B + 1) {
		if (H % i == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}


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

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; }

// v[i][j]はi日目に活動jを選んだ時の幸福度の最大値
int v[100010][3];

// DPテーブル
long long dp[100010][3];

int main() {
  int N; std::cin >> N;
  for (int i = 0; i < N; ++i) std::cin >> v[i][0] >> v[i][1] >> v[i][2];

  dp[0][0] = v[0][0]; // 0日目にaを選んだ時の幸福度の最大値
  dp[0][1] = v[0][1]; // 0日目にbを選んだ時の幸福度の最大値
  dp[0][2] = v[0][2]; // 0日目にcを選んだ時の幸福度の最大値

  // 配るDP
  for (int i = 0; i < N-1; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (j == k) continue;       
        chmax(dp[i+1][j], dp[i][k] + v[i+1][j]);
      }
    } 
  }
  long long ans = -1;
  for (int i = 0; i < 3; ++i) ans = std::max(ans, dp[N-1][i]);
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 7056
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(void){

	int N,inp,cnt=0;
	bool f;

	cin>>N;

	for(int i=0;i<N;i++){
		cin>>inp;
		f=true;
		for(int i=2;i<=sqrt((double)inp);i++){
			if(inp%i==0){
				f=false;
				break;
			}
		}
		if(f) cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
using namespace std;
int main() {
        string s;
        cin >> s;
        if (s[0] == '7')
                cout << "Yes" << endl;
        else if (s[1] == '7')
                cout << "Yes" << endl;
        else if (s[2] == '7')
                cout << "Yes" << endl;
        else
                cout << "No" << endl;
        return 0;
}

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

int main(){
  int n;
  cin >> n;
  ll sum=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0) sum += i; 
  }
  cout << sum << endl;
  return 0;
}

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

int arr[100007];

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

	for( int i=1;i<=n;i++ )
		cin>>arr[i], arr[i]= (arr[i]-1>=arr[i-1])?arr[i]-1:arr[i];

	bool f= 1;

	for( int i=2;i<=n;i++ )
		if( arr[i]<arr[i-1] )
			f= 0;

	if(f)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 3832
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(void){
	while(1){
		string str;
		int a[2]={0,0};
		cin >> str;
		if(str=="0")break;
		for(int i=1;i<str.size();i++){
			a[str[i]-'A']++;
		}
		if(a[0]>a[1])a[0]++;
		else a[1]++;
		printf("%d %d\n",a[0],a[1]);
	}
    return 0;
}

Measured memory_bytes: 0
using System;

class Program {
  static void Main(string[] args) {
    int c = Console.Read();
    if((c != 'a') && (c != 'i') && (c != 'u') && (c != 'e') && (c != 'o'))
      Console.WriteLine("consonant");
    else
      Console.WriteLine("vowel");
  }
}


Measured memory_bytes: 13140
//#FINALLY its gonna be A.C>

#include <bits/stdc++.h>
using namespace std;
long long int dp[109][100009];


long long int ansd(long long int value[], int wts[], int n, int max_wt)
{
    for (int i = 1; i < n+1; i++)
    {
        for (int j = 0; j < max_wt+1; j++)
        {
            if(j>=wts[i-1])
            dp[i][j]=max(dp[i-1][j-wts[i-1]]+value[i-1],dp[i-1][j]);
            else
            {
                dp[i][j]=dp[i-1][j];
            }
            
        }
        
    }
    return dp[n][max_wt];
    // for (int o = 0; o < max_wt+1; o++)
    // {
    //     for (int j = 0; j < n+1; j++)
    //     {
    //         cout<<dp[o][j]<<"  ";

    //     }
    //     cout<<'\n';
    // }


}
int main()
{
    int n, w;
    cin >> n >> w;
    long long int val[n];
    int wts[n];
    for (int i = 0; i < n; i++)
    {
        cin >> wts[i];
        cin >> val[i];
    }
    cout << ansd(val, wts, n, w);
}


Measured memory_bytes: 79360
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int to[100005];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d", &to[i]);
  }
  int ret = 0;
  for(int i = 1; i <= n; i++) {
    if(i == to[to[i]]) ret++;
  }
  printf("%d\n", ret/2);
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {

        static void Main(string[] args)
        {
            SolveB(args);
        }
        static void SolveA(string[] args)
        {
            string szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            int a = int.Parse(szArr[0]);
            int b = int.Parse(szArr[1]);

            int dif = a - b;
            if( dif < 0 ) { dif = -dif; }
            if (dif > 8)
            {
                Console.WriteLine(":(");
            }
            else
            {
                Console.WriteLine("Yay!");
            }
        }

        static void SolveB(string[] args)
        {
            string szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            int d = int.Parse(szArr[0]);
            int n = int.Parse(szArr[1]);

            int answer = 0;
            if( d == 0)
            {
                if (n == 100)
                {
                    answer = 101;
                    
                }
                else
                {
                    answer = n;
                }
            }else if( d == 1)
            {
                if (n == 100)
                {
                    answer = 100 * 101;
                }
                else
                {
                    answer = 100 * n;
                }
            }else // d == 2
            {
                if (n == 100)
                {
                    answer = 100 * 100 * 101;
                }
                else
                {
                    answer = 10000 * n;
                }
            }
            Console.WriteLine(answer);
        }

        static void SolveC(string[] args)
        {
            string szLine = Console.ReadLine();
            int n = int.Parse(szLine);
            szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            long[] a = new long[szArr.Length];


            // 各数に対し、2^ki の倍数かを求め　ki を足し合わせるイメージ？
            int total = 0;
            for(int i=0;i<a.Length;++i)
            {
                long tmp = long.Parse(szArr[i]);
                a[i] = tmp;

                while ( tmp % 2 == 0)
                {
                    tmp /= 2;
                    total++;
                }
            }

            


            Console.WriteLine(total);
        }
    }

}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
string s;

int main() {
    cin >> n >> k;
    cin >> s;

    vl data;
    char now = s.at(0);
    cnt = 0;
    NREP() {
        if (now == s.at(i)) {
            cnt++;
        } else {
            data.push_back(cnt);
            cnt = 1;
            now = s.at(i);
        }
    }
    data.push_back(cnt);

    ans = 0;
    REP(i, data.size()) {
        if (i <= 2 * k - 1) {
            ans += data.at(i);
        } else {
            ans += data.at(i) - 1;
        }
    }

    if (ans == s.length()) ans--;
    MSG(ans)
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<vector<ll>> pascals_triangle(int n) {
    vector<vector<ll>> combi(n + 1, vector<ll>(n + 1));
    REP(i, n + 1) REP(j, i + 1) {
        if (j == 0 || j == i) combi[i][j] = 1LL;
        else combi[i][j] = combi[i - 1][j - 1] + combi[i - 1][j];
    }
    return combi;
}

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

ll lcm(ll m, ll n) {
    // If both m and n are large numbers, the result is overflow without parentheses.
    return m * (n / gcd(m, n));
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vl c(26);
    REP(i, n) c[s[i] - 'a']++;
    ll ans = 1;
    REP(i, 26) if (c[i]) {
        ans *= (c[i] + 1);
        ans %= MOD;
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void)
{
  char s[11];
  scanf("%s", s);

  int ans = 0;
  for (int i = 0; s[i] != 0 ; i++) {
    int count = 0;
    for (int j = i;; j++) {
      if (s[j] == 'A' || s[j] == 'G' || s[j] == 'C' || s[j] == 'T')
        count++;
      else {
        if (ans < count)
          ans = count;
        break;
      }
    }
  }
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
class Card {
  constructor(mark, value) {
    this.mark = String(mark);
    this.value = Number(value);
  }

  equals(other) { return this.value === other.value && this.mark === other.mark; }

  compareTo(other) {
    if (this.value === other.value) return 0;
    else if (this.value < other.value) return -1;
    else return 1;
  }

  toString() { return `${this.mark} ${this.value}` }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.map(r => r.split(' ')).map(c => new Card(c[0], c[1]));
  const quick_arr = Array.from(arr);

  quickSort(quick_arr, 0, n - 1);
  console.log(arr.map((e, idx) => ({val: e, idx: idx}))
      .sort((a, b) => a.val.compareTo(b.val) || a.idx - b.idx)
      .every((card, i) => card.val.equals(quick_arr[i]))
          ? 'Stable' : 'Not stable'
        );
  console.log(quick_arr.join('\n'));
})();

function quickSort(arr, p, r) {
  const partition = function(arr, p, r) {
     let x  = arr[r];
     let i = p - 1;
     for (let j = p; j < r; j++) {
       if (arr[j].compareTo(x) <= 0) {
         i++;
         [arr[i], arr[j]] = [arr[j], arr[i]];
       }
     }
     [arr[i + 1], arr[r]] = [arr[r], arr[i + 1]];
     return i + 1;
  }

  quickSort = function(arr, p, r) {
    if (p < r) {
      let q = partition(arr, p, r);
      quickSort(arr, p, q - 1);
      quickSort(arr, q + 1, r);
    }
  }
  quickSort(arr, p, r);
}



Measured memory_bytes: 75252
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<list>
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323
#define MOD 20091101
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
int a[200];
int main() {
	int n;
	scanf("%d", &n);
	fup(i, 0, 2*n - 1, 1)
		scanf("%d", a + i);
	sort(a, a + 2 * n);
	int ans = 0;
	fup(i, 0, 2*n - 1, 2)
		ans += a[i];
	printf("%d", ans);
}

Measured memory_bytes: 256