akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
#define P 1000000007
typedef long long ll;
int n , m;
int a , b , c;
int A[MAXN];
void solve() {
    cin >> n >> m;
    rep( i ,1 , n ) scanf("%d",A + i) , a += A[i];
    rep( i , 1 , n ) {
        if( A[i] * 4 * m >= a ) ++ b;
    }
    puts(b >= m ? "Yes" : "No");
}
signed main() {
//    freopen("2.in","r",stdin);
//    freopen("fuckout","w",stdout);
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    string s,a;
    cin >> s >> a;
    int cnt=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]==a[i])
            cnt++;
    }
    cout << cnt <<endl;

    return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int H,N;

int fld[11111];

int dp[11111][16];

signed main(){
    cin>>H>>N;
    rep(i,N){
        int x,y;
        cin>>x>>y;
        fld[y]|=1<<x;
    }

    fill_n(*dp,11111*16,INT_MIN);
    dp[0][15]=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<16;j++){
            chmax(dp[i+1][fld[i]],dp[i][j]);
            if((j&3)==0&&(fld[i]&3)==0)chmax(dp[i+1][fld[i]|3],dp[i][j]+1);
            if((j&6)==0&&(fld[i]&6)==0)chmax(dp[i+1][fld[i]|6],dp[i][j]+1);
            if((j&12)==0&&(fld[i]&12)==0)chmax(dp[i+1][fld[i]|12],dp[i][j]+1);
            if(j==0&&fld[i]==0)chmax(dp[i+1][15],dp[i][j]+2);
        }
    }

    cout<<*max_element(dp[H],dp[H]+16)<<endl;
    return 0;
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.size(), m=t.size();
  vector<int> ss(n+1, 0);
  vector<int> tt(m+1, 0);

  rep(i,n) ss[i+1] = ((s[i]=='A')?1:-1);
  rep(i,m) tt[i+1] = ((t[i]=='A')?1:-1);

  rep(i,n) ss[i+1] += ss[i];
  rep(i,m) tt[i+1] += tt[i];

  int q;
  cin>>q;
  rep(_,q){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;c--;
    if((ss[b]%3-ss[a]%3+30)%3 == (tt[d]%3-tt[c]%3+30)%3) cout << "YES" << endl;
    else cout<<"NO" << endl;
  }


  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
   cin >> h.at(i);
  }
  int result = 0;
  for(int i = 0; i < N; i++){
   if(h.at(i) >= K) result++;
  }
  cout << result << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n, p, q, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p >> q;
		sum += q - p + 1;
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
	string ch,chl,chr;
    int count,shuffle;
    cin >> ch;
    while(ch != "-"){
    	cin >> count;
        for(int i = 0; i < count ; i++){
            cin >> shuffle;
            chr = ch.substr(0,shuffle);
            chl = ch.substr(shuffle,ch.length()-shuffle);
            ch = chl + chr;;
        }
        cout << ch << endl;
        cin >> ch;
    }
	return 0;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}
template < typename T, typename U >
ostream &operator<<(ostream &os, const pair< T, U > &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

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

struct edge {
	int from, to, d, c, i;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, b * d), max(a * d, b * c)) << endl;
	return 0;
}

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

int main(){
   // freopen( "in.txt" , "r" , stdin );

    string s , t;
    cin >> s >> t;

    deque<char> a , b;
    for ( char i : s )
        a.push_back(i);
    for ( char i : t )
        b.push_back(i);

    for ( int i = 0; i < (int)s.size(); ++i ){
        a.push_front(a.back());
        a.pop_back();
        if ( a == b ){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
#define INF 1000000000000000007ll
using namespace __gnu_pbds;
using namespace std;

int n,d,a[200010],p[200010];
vector<pair<int,pair<int,int> > > e;

inline int find_set(int x)
{
	return p[x]==x?x:p[x]=find_set(p[x]);
}

inline bool unite(int x,int y)
{
	int rootx=find_set(x),rooty=find_set(y);
	if(rootx==rooty) return false;
	p[rooty]=rootx;
	return true;
}

inline void solve(int l,int r)
{
	if(l==r) return;
	int mid=(l+r)/2;
	int minv1=INF,pos1=-1;
	for(int i=l;i<=mid;i++){
		if(a[i]-d*i<minv1){
			minv1=a[i]-d*i;
			pos1=i;
		}
	}
	int minv2=INF,pos2=-1;
	for(int i=mid+1;i<=r;i++){
		if(a[i]+d*i<minv2){
			minv2=a[i]+d*i;
			pos2=i;
		}
	}
	for(int i=l;i<=mid;i++){
		e.push_back(make_pair(a[i]-d*i+minv2,make_pair(i,pos2)));
	}
	for(int i=mid+1;i<=r;i++){
		e.push_back(make_pair(a[i]+d*i+minv1,make_pair(i,pos1)));
	}
	solve(l,mid);
	solve(mid+1,r);
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>d;
	for(int i=1;i<=n;i++) cin>>a[i];
	solve(1,n);
	sort(e.begin(),e.end());
	int ans=0;
	for(int i=1;i<=n;i++) p[i]=i; 
	for(int i=0;i<e.size();i++){
		int x=e[i].second.first,y=e[i].second.second;
		if(unite(x,y)){
			ans+=e[i].first;
		}
	}
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 103348
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
ll f[41][41][41];
int vis[41][41][41],n;
char mp[41][42];
ll solve(int l,int mid,int r){
	if(l==r) return 1;
	if(l==mid||r==mid) return 0;
	if(vis[l][mid][r]) return f[l][mid][r];
	vis[l][mid][r]=1;
	ll ans=0;
	for(int j=l;j<mid;j++)
		for(int k=mid+1;k<=r;k++)
			if(mp[j][k]=='1')
			for(int p=j;p<mid;p++)
				for(int q=mid;q<k;q++)
					ans+=solve(l,j,p)*solve(q+1,k,r)*solve(p+1,mid,q);
	return f[l][mid][r]=ans;
}
int main(){
	read(n);
	for(int i=1;i<=2*n;i++)
		cin>>mp[i]+1;
	ll ans=0;
	for(int i=2;i<=2*n;i++)
		if(mp[1][i]=='1')
		ans+=solve(2,i,2*n);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 768
def mapping(string):
    return 1 if string == "L" else -1


n, k = map(int, input().split())
s = list(map(mapping, input()))

flips = []
for i in range(n - 1):
    if s[i] != s[i + 1]:
        flips.append(i + 1)

print(min(n - 1, n - 1 - len(flips) + 2 * k))


Measured memory_bytes: 7840
N,K = map(int,input().split())
S = list(input())
i=1
count =0
owari = False
while i < N:
    if S[i]!=S[0]:
        for j in range(i,N,1):
            if S[j]!=S[0]:
                S[j]=S[0]
            else:
                i = j
                break
            if j==N-1:
                i=N
        count+=1
        if count >= K:
            owari = True
    i+=1
    if owari:
        break
score=0
for i in range(0,N,1):
    if S[i]=="R":
        if i < N-1 and S[i+1]==S[i]:
            score+=1
    else:
        if i > 0 and S[i-1]==S[i]:
            score+=1
print(score)

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

using namespace std;
#define nl "\n"
int check();
int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    double tt = (double)d/float(s);
    if(t<tt)
        cout << "No"<<nl;
    else
        cout << "Yes"<<nl;

return 0;

}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>

int main(){
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        char c;
        std::cin >> c;
        if(c == 'Y'){
            std::cout << "Four" << std::endl;
            return 0;
        }
    }

    std::cout << "Three" << std::endl;
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
h=range(H)
S=[input() for _ in h]
M=[[-1]*W for _ in h]
k=0
for y in h:
    for x in range(W):
        if M[y][x]!=-1:continue
        M[y][x]=k;Q=[(y,x)]
        while len(Q)>0:
            i,j=Q.pop();s=S[i][j];p=i+1;q=i-1;r=j+1;t=j-1
            if p<H and M[p][j]==-1 and s!=S[p][j]:M[p][j]=k;Q+=[(p,j)]
            if i>0 and M[q][j]==-1 and s!=S[q][j]:M[q][j]=k;Q+=[(q,j)]
            if r<W and M[i][r]==-1 and s!=S[i][r]:M[i][r]=k;Q+=[(i,r)]
            if j>0 and M[i][t]==-1 and s!=S[i][t]:M[i][t]=k;Q+=[(i,t)]
        k+=1
s={}
d={}
for i in range(H):
    for j in range(W):
        m=M[i][j]
        if S[i][j]=='#':s[m]=s.get(m,0)+1
        else:d[m]=d.get(m,0)+1
print(sum(s.get(i,0)*d.get(i,0)for i in range(k)))

Measured memory_bytes: 18020
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 205;

int n,ans;
int l[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	n <<= 1;
	for (int i = 1;i <= n;i++)
		cin >> l[i];
	sort(l + 1,l + n + 1);
	for (int i = 1;i <= n;i += 2)
		ans += l[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K;
int main() {
	cin >> N >> K;
	if (pow(2, N) <= K) {
		cout << -1 << endl;
	}
	else if (N == 1 && K == 0) {
		cout << "1 1 0 0";
	}
	else if (N == 1 && K == 1) {
		cout << -1 << endl;
	}
	else {
		REP(i, 1 << N) {
			if (i == K) continue;
			cout << i << " ";
		}
		cout << K << " ";
		IREP(i, 1 << N) {
			if (i == K) continue;
			cout << i << " ";
		}
		cout << K;
	}
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i=0;i<N;i++) {
		cin >> A[i];
	}
	for (int i=K;i<A.size();i++) {
		if (A[i] > A[i-K]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 4068
import sys
n = int(input())
a = [ 2*int(i) for i in sys.stdin.readline().split()]
f = (sum(a) - 2* sum(a[1::2]))//2
ans = [f] + [0 for i in range(n-1)]
for i in range(n-1):
    ans[i+1] =  a[i] - ans[i]
print(" ".join(map(str, ans)))


Measured memory_bytes: 19904
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        int a, b, c;
        int five = 0;
        int seven = 0;
        Scanner scanner = new Scanner(System.in);
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();

        if(a == 5){
            five++;
        }else if(a == 7){
            seven++;
        }
        if(b == 5){
            five++;
        }else if(b == 7){
            seven++;
        }
        if(c == 5){
            five++;
        }else if(c == 7){
            seven++;
        }

        if(five == 2){
            if(seven == 1){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 9424
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS

main = abc164a

abc164a = do
    [s,w] <- getIntList
    putStrLn $ if s > w then "safe" else "unsafe"

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

Measured memory_bytes: 3820
/*
 * ITP1_6_B.cpp
 *
 *  Created on: Apr 20, 2018
 *      Author: 13743
 */

#include<iostream>

using namespace std;

long gcd(long x, long y) {
	if(x == 0 || y == 0) {
		return x + y;
	}
	if(x > y) {
		return gcd(y, x % y);
	}
	return gcd(x, y % x);
}

int main() {
	long x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3088
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    string t;
    cin >> t;
    int z = 100000000;
    for(int i = 0; i < t.size(); i++)
    {
        if(t[i] != t[i+1])
        {
            int maxz = max(i+1, (int)t.size()-i-1);
            z = min(z, maxz);
        }
    }
    cout << z << endl;
}


Measured memory_bytes: 512
#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++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int h[110];
int renzoku;
int main()
{ 
    int n;
    cin >> n;
    int maxh =0;
    rep(i,n){
        cin >> h[i];
        maxh = max(maxh,h[i]);
    }
    int ans = 0;
    for(int j = maxh;j >0; j--){
        renzoku = 0;
        rep(i,n){
            if (h[i] == j){
                renzoku = 1;
                h[i] -= 1;
            }
            else if(renzoku == 1 && h[i] != j){
                ans+=1;
                renzoku = 0;
            }
        }
        if (renzoku >0){
            ans+=1;
        }
    }
 
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
void solve(void)
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i, n)
    {
        string x = s.substr(0, i);
        string y = s.substr(i, n - i);
        set<char> sx, sy;
        rep(j, i) sx.insert(x[j]);
        rep(j, n - i) sy.insert(y[j]);
        int res = 0;
        for (auto i : sx)
        {
            if (sy.find(i) != sy.end())
                res++;
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

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

#define ll long long

using namespace std;

ll pos[100500];

ll a[100500];

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    set <ll> st;
    ll n,x,res = 0;
    cin >> n;
    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
        pos[a[i]] = i;
    }
    for(ll i = n; i >= 1; i--)
    {
        ll bmxl,bmxr,amxl,amxr;
        st.insert(pos[i]);
        auto mid = st.find(pos[i]);
        if(mid == st.begin())
        {
            bmxl = pos[i] + 1;
            amxl = 0;
        } else
            {
                mid--;
                bmxl = pos[i] - *mid;
                if(mid == st.begin())
                {
                    amxl = *mid + 1;
                } else
                    {
                        ll x = *mid;
                        mid--;
                        amxl = x - *mid;
                    }
            }
        mid = st.find(pos[i]);
        if(*mid == *st.rbegin())
        {
            bmxr = n - *mid;
            amxr = 0;
        } else
            {
                mid++;
                bmxr = *mid - pos[i];
                if(*mid == *st.rbegin())
                {
                    amxr = n - *mid;
                } else
                    {
                        ll x = *mid;
                        mid++;
                        amxr = *mid - x;
                    }
            }
        res += (bmxl * amxr * i);
        res += (bmxr * amxl * i);
    }
    cout << res;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    string s, ans = "";
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        if(s[i]=='0') ans += '0';
        else if(s[i] == '1') ans += '1';
        else{
            int n = ans.size();
            if(n <= 1) ans = "";
            else ans = ans.substr(0,n-1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	int H, W, K;
	scanf("%d%d%d", &H, &W, &K);
	char m[H * W];
	for (int i = 0; i < H * W; i++) {
		scanf(" %c", &m[i]);
	}
	int count = 0;
	for (int h = 0; h < 1 << H; h++) {
		for (int w = 0; w < 1 << W; w++) {
			int black = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (h >> i & 1 && w >> j & 1 && m[i * W + j] == '#') {
						if (++black > K) {
							break;
						}
					}
				}
			}
			if (black == K) {
				count++;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<b) {
    rep(i,b) cout << a;
  }
  else {
    rep(i,a) cout << b;
  }
  cout << endl;
  return 0; 
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
int main() {
          
         
        int n;
        cin>>n;
        vector<int>A(n),B(n);
        REP(i,0,n)
        {
            cin>>A[i];
        }
        REP(i,0,n)
        {
            cin>>B[i];
        }
        int count1=0,count2=0;
        while(next_permutation(A.begin(),A.end())){count1++;}
        while(next_permutation(B.begin(),B.end())){count2++;}
        
        cout<<abs(count1-count2);
    return 0;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc097/tasks/arc097_a */

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

std::string solve(const std::string s, const int K)
{
  int s_len = s.length();
  std::set<std::string> sub_s;

  for (int i = 1; i <= K; ++i) {
    for (int j = 0; j+i-1 <= s_len; ++j) {
      std::string sub = s.substr(j, i);
      sub_s.insert(sub);
    }
  }

  auto ite = sub_s.begin();
  for (int i = 0; i < K; ++i) {
    ite++;
  }

  return *(ite);
}

int main(int argc, char *argv[])
{
  // Input
  std::string s;
  int K;

  std::cin >> s >> K;

  // Output
  std::cout << solve(s, K) << std::endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n/2-1){
    s.pop_back();
    s.pop_back();
    if(s.substr(0,s.size()/2) == s.substr(s.size()/2,s.size()/2)){
      cout << s.size() << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main()
{	
    int x, y;
    cin >> x >> y;
    bool ok = false;
    REP(i, 100){
        REP(j, 100){
            if(i + j == x && 2*i+4*j == y) ok = true;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3636
N,M=map(int,input().split())

roads_cnt=[0]*N
for i in range(M):
    a_i,b_i=map(int,input().split())
    roads_cnt[a_i-1] +=1
    roads_cnt[b_i-1] +=1

for road_cnt in roads_cnt:
    print(road_cnt)




Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}

int main(void) {
  int N, d[110];
  cin >> N;
  REP(i,N) cin >> d[i];
  int sum=0;
  REP(i,N) {
    for(int j=i+1;j<N;++j) {
      sum+=d[i]*d[j];
    }
  }
  pr(sum);
  return 0;
}



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

int main(){
    string S;
    cin >> S;
    int k;
    cin >> k;
    int n = S.length();

    vector<vector<vector<int64_t>>> DP(n + 1, vector<vector<int64_t>>(k + 2, vector<int64_t>(2)));
    DP[0][0][0] = 1;

    for (int i = 0; i < n; i++){
        for (int j = 0; j <= k; j++){
            for (int l = 0; l < 10; l++){
                if (S[i] - '0' == l)
                    DP[i + 1][j + min(1, l)][0] += DP[i][j][0];
                else if (l < S[i] - '0')
                    DP[i + 1][j + min(1, l)][1] += DP[i][j][0];
                DP[i + 1][j + min(1, l)][1] += DP[i][j][1];
            }
        }
    }

    cout << DP[n][k][0] + DP[n][k][1] << endl;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
flag = 0

for i in range(1, 1001):
    hati = int(i * 0.08)
    juu = int(i * 0.1)
    
    if hati == a and juu == b:
        flag = 1
        print(i)
        break
    
if flag == 0:
    print("-1")

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


ll beki[2][200020];

ll f(ll n){
    ll ret = 0;
    ll tmp = n;
    ll now = 0;
    while(tmp){
        if(tmp%2)now++;
        tmp /= 2;
    }
    if(now) ret = 1 + f(n%now);
    return ret;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt = 0;
    for(int i=0;i<n;i++)if(s[i] == '1')cnt++;
    // mod -> cnt+1, cnt-1
    ll l=0,r=0;
    beki[0][0] = 1;
    beki[1][0] = 1;
    for(int i=0;i<n;i++){
        l *= 2;
        r *= 2;
        beki[0][i+1] = beki[0][i]*2;
        if(cnt!=1)beki[1][i+1] = beki[1][i]*2;
        if(s[i] == '1'){
            l++;
            r++;
        }
        l %= (cnt+1);
        beki[0][i+1] %= (cnt+1);
        if(cnt!=1){
            r %= (cnt-1);
            beki[1][i+1] %= (cnt-1);
        }
    }
    for(int i=0;i<n;i++){
        ll now = 0;
        if(s[i] == '1'){
            // cnt-1
            ll ans = r - beki[1][n-1-i] + cnt-1;
            if(cnt != 1)now++;
            if(cnt != 1)ans %= (cnt-1);
            cout << now + f(ans) << "\n";
        }
        else{
            ll ans = l + beki[0][n-1-i];
            now++;
            ans %= (cnt+1);
            cout << now + f(ans) << "\n";
        }
    }
}

Measured memory_bytes: 6864
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        abc141_c solver = new abc141_c();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc141_c {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int Q = in.nextInt();

            int Player[] = new int[N + 1];
/*
        for (int i = 1; i <= N; i++) {
            Player[i]= K;
        }
 */
            for (int i = 0; i < Q; i++) {
                int acc = in.nextInt();
                Player[acc] += 1;
            /*
            for (int j = 1; j <=N ; j++) {
                if (j != acc) {
                    Player[j]-=1;
                }
            }
            */
            }
            for (int i = 1; i <= N; i++) {
                int dif = Player[i] - Q;
                if (K + dif > 0) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            }

        }

    }
}



Measured memory_bytes: 51176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>k){
        a=a-k;
    }
    else{
        k=k-a;
        a=0;
        b=b-k;
        if(b<0){
            b=0;
        }
    }
    cout<<a<<" "<<b<<endl;

    return 0;
}

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


Measured memory_bytes: 7004
n = int(input())
x = [0,0,0,0]
y = ["AC","WA","TLE","RE"]
for _ in range(n):
  si = str(input())
  if si == "AC":
    x[0] += 1
  elif si == "WA":
    x[1] += 1
  elif si == "TLE":
    x[2] += 1
  elif si == "RE":
    x[3] += 1
for i in range(4):
  print(y[i],"x",x[i])

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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

ofstream outfile;
ifstream infile;

int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	fastIO;
	lli n, t, sum1 = 0, sum2 = 0, i, mini = INT_MAX;

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

	sum1 = arr[1];
	for(i = 2; i <= n; ++i)
		sum2 += arr[i];

	mini = min(mini, abs(sum1-sum2));

	for(i = 2; i < n; ++i)
	{
		sum1 += arr[i];
		sum2 -= arr[i];
		mini = min(mini, abs(sum1-sum2));
	}
	cout << mini << "\n";
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

int main() {
  size_t N;
  std::cin >> N;
  std::vector<int> h(N);
  std::for_each(h.begin(), h.end(), [](auto& v) { std::cin >> v; });

  std::vector<int> dp(N, 0);
  dp[1] = std::abs(h[0] - h[1]);
  for (size_t i = 2; i < N; ++i) {
    dp[i] = std::min(std::abs(h[i - 1] - h[i]) + dp[i - 1],
                     std::abs(h[i - 2] - h[i]) + dp[i - 2]);
  }
  std::cout << dp[N - 1] << std::endl;
  return 0;
}


Measured memory_bytes: 1024
import bisect

N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dp = [0] * (N+2)
dp[0] = 1

for i in range(1, N+1):
  idx = bisect.bisect_left(A, i)
  if idx < len(A) and A[idx] == i:
    continue
  if i < 2:
    dp[i] = dp[i-1]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N]%(10**9+7))

Measured memory_bytes: 460020
// AOJ 0296 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0296)
#include<cstdio>
#define rep(i,a) for(int i=0;i<(a);++i)

const int V[6] = { 1, 5, 10, 50, 100, 500 };

int main()
{
	int s = 0;

	rep( i, 6 )
	{
		int c;
		scanf( "%d", &c );

		s += c*V[i];
	}

	printf( "%d\n", s>=1000 );

	return 0;
}

Measured memory_bytes: 1032
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

int main(void) {
    string S;
    cin >> S;
    const int slen = (int) S.size();

    vector<int> ans(slen, 0);


    // for R
    {
        int cnt = 0;
        for (int i = 0; i < slen; i++) {
            if (S[i] == 'R') {
                cnt++;
            } else {
                ans[i] += cnt/2;
                ans[i - 1] += cnt - cnt/2;
                cnt = 0;
            }
        }
    }

    // for L
    {
        int cnt = 0;
        for (int i = slen - 1; i >= 0; i--) {
            if (S[i] == 'L') {
                cnt++;
            } else {
                ans[i] += cnt/2;
                ans[i + 1] += cnt - cnt/2;
                cnt = 0;
            }
        }
    }

    cout << ans[0];
    for (int i = 1; i < slen; i++) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3824
#include <iostream> 
#include <vector> 
#include <string>
#include <algorithm> 
#include <stack> 
#include <set>

using namespace std;

int	main()
{
	int n;
	int	j;
	cin >> n >> j;
	n -= j;
	if (n > 0)
		cout << n << endl;
	else
		cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    static long res;
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong(); long x = sc.nextLong();
        long gcd = gcd(n, x); res = n;
        go(x, n - x);
        System.out.println(res - gcd);
    }

    static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    static void go(long a, long b) {
        if (a < b) {
            long temp = a;
            a = b; b = temp;
        }
        if (b == 0) return;
        res += (a / b) * b * 2;
        go(b, a % b);
    }


}

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

int main() {
  ll n, a,b; cin >> n >>a>>b;
  ll s = a+b; ll k =a*(n/s);
  if(n%s >a)cout << a+k<<endl;
  else cout << n%s+k<<endl;
}


Measured memory_bytes: 256
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 9/18/2020
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int64_t INF = (int64_t)1e18;
const int mxN = 1e5+20;

int n;
int64_t arr[mxN][3];

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

	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	// dp[i][j] max happ points can get ending at day i with last used j;
	vector<vector<int64_t>> dp(n+1, vector<int64_t>(3));
	dp[n][0] = dp[n][1] = dp[n][2] = 0; // empty set of activities, max we can get here is 0;
	for(int i = n-1; i >= 0; i--) {
		for(int j = 0; j < 3; j++) {
			dp[i][j] = -INF;
			if(j != 0) {
				dp[i][j] = max(dp[i][j], dp[i+1][0] + arr[i][0]);
			}
			if(j != 1) {
				dp[i][j] = max(dp[i][j], dp[i+1][1] + arr[i][1]);
			}
			if(j != 2) {
				dp[i][j] = max(dp[i][j], dp[i+1][2] + arr[i][2]);
			}
		}
	}
	cout << max({dp[0][0], dp[0][1], dp[0][2]}) << "\n";

	return 0;
}


Measured memory_bytes: 11084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K := sc.nextInt(), sc.nextInt()
	S := sc.nextStr()
	rlCount := 0
	for i := 0; i < N-1; i++ {
		if S[i:i+2] == "RL" {
			rlCount++
		}
	}
	unhappy := max(0, rlCount-K) * 2
	if S[0] == S[N-1] {
		unhappy++
	} else if S[0] == 'R' && S[N-1] == 'L' {
		if unhappy == 0 {
			unhappy++
		}
	} else {
		unhappy += 2
		if rlCount < K {
			unhappy--
		}
	}

	fmt.Fprintln(wtr, N-unhappy)
	wtr.Flush()
}


Measured memory_bytes: 896
S=input()
l=len(S)
dp=[[0,0,0] for i in range(l+2)]
dp[1][0]=dp[2][1]=1
for i in range(l):
    if(i>0 and S[i-1]!=S[i]):
        dp[i+1][1]=max(dp[i+1][1],dp[i][1]+1)
    if(i>=2 and S[i-2:i]!=S[i:i+2]):
        dp[i+2][2]=max(dp[i+2][2],dp[i][2]+1)
    dp[i+2][2]=max(dp[i+2][2],dp[i][1]+1)
    dp[i+1][1]=max(dp[i+1][1],dp[i][2]+1)
print(max(dp[l]))

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

int n;
string a[11], b[11], start, goal;

map<string, int> found;

struct State {
	string str; int cnt;
	State(string _str, int _cnt) : str(_str), cnt(_cnt) {}
};
bool operator > (const State& a, const State& b) { return a.cnt > b.cnt; }

void solve() {
	found.clear();
	
	priority_queue< State, vector<State>, greater<State> > q;
	q.push(State(start, 0));
	found[start] = 0;
	
	while (!q.empty()) {
		State s = q.top(); q.pop();
		
		if (s.str == goal) {
			cout << s.cnt << endl;
			return;
		}
		
		if (size_of(s.str) >= size_of(goal)) continue;
		
		if (found[s.str] < s.cnt) continue;
		
		for_(i,0,n) {
			int p = 0;
			string nxt = s.str;
			
			while (p < size_of(nxt) && (size_of(nxt) - p >= size_of(a[i])) ) {
				if (nxt.substr(p, size_of(a[i])) == a[i]) {
					nxt = nxt.substr(0, p) + b[i] + nxt.substr(p + size_of(a[i]));
					p += size_of(b[i]);
				} else {
					p++;
				}				
			}
			
			if (found[nxt] == 0 || found[nxt] > s.cnt + 1) {
				found[nxt] = s.cnt + 1;
				q.push(State(nxt, s.cnt + 1));
			}
		}
	}
	
	cout << -1 << endl;
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> a[i] >> b[i];
		cin >> start;
		cin >> goal;
		solve();
	}
	return 0;
}

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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = a, y[i] = b;
  }

  int mx1 = -1e9-4, mn1 = 1e9+4;
  int mx2 = mx1, mn2 = mn1;
  for (int i = 0; i < N; i++) {
    mx1 = max(mx1, x[i] + y[i]);
    mn1 = min(mn1, x[i] + y[i]);
    mx2 = max(mx2, x[i] - y[i]);
    mn2 = min(mn2, x[i] - y[i]);
  }

  cout << max(mx1 - mn1, mx2-mn2);
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
int memo[105][5][5],day[105],n,k,ans;

int solve(int dp,int s1,int s2){
    int sum=0;

    if(dp>k){
            return 1;
    }
    if(memo[dp][s1][s2]>0)return memo[dp][s1][s2];

    if(day[dp]==0){

        for(int i=1;i<=3;i++){
        if(s1!=i||s2!=i){
        sum+=solve(dp+1,s2,i);
        sum%=10000;
            }
        }

    }else {

        if(s1!=day[dp]||s2!=day[dp]){
                sum+=solve(dp+1,s2,day[dp]);
                sum%=10000;
            }
    }

    return memo[dp][s1][s2]=sum%10000;
}


int main(){
    cin >> k >> n;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        day[a]=b;
    }

    cout << solve(1 ,0 , 0)  << endl;
 return 0;
}

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

using namespace std;

int dp[5000][5000];
pair<int,int> par[5000][5000];

int main()
{
    string s, t;
    cin>>s>>t;
    for (int x = 1; x <= s.size(); x++)
    {
        auto ss = s[x-1];
        for (int y = 1; y <= t.size(); y++)
        {
            auto tt = t[y-1];
            if (ss == tt)
                dp[x][y] = dp[x-1][y-1] + 1, par[x][y] = make_pair(x-1, y-1);
            else
            {
                if (dp[x][y-1] > dp[x-1][y])
                    dp[x][y] = dp[x][y-1], par[x][y] = {x, y-1};
                else
                    dp[x][y] = dp[x-1][y], par[x][y] = {x-1, y};
            }
        }
    }
    string ret = "";
    pair<int,int> cur = {s.size(), t.size()};
    while (dp[cur.first][cur.second])
    {
        if (s[cur.first-1] == t[cur.second-1])
            ret += s[cur.first-1];
        cur = par[cur.first][cur.second];
    }
    reverse(ret.begin(), ret.end());
    cout<<ret<<endl;
}


Measured memory_bytes: 177792
#include <bits/stdc++.h>
#define int long long
#define md 1000000007
using namespace std;
int h,w;
int a[100][100],b[100][100];
int dp[81][81][13000];
int path(int i,int j,int k){
	if(dp[i][j][k]!=-1)
		return dp[i][j][k];
	int sum=LONG_LONG_MAX;
	int nk[2]={abs(k+a[i][j]-b[i][j]),abs(k-a[i][j]+b[i][j])};
	if(i==h-1 and j==w-1)
		return min(nk[0],nk[1]);

	if(i<h-1)
		sum=min(path(i+1,j,nk[0]),min(path(i+1,j,nk[1]),sum));
	if(j<w-1)
		sum=min(path(i,j+1,nk[0]),min(path(i,j+1,nk[1]),sum));
	return dp[i][j][k]=sum;
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> h >> w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin >> a[i][j];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin >> b[i][j];
	memset(dp,-1,sizeof dp);
	cout << path(0,0,0) << endl;
}


Measured memory_bytes: 666752
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0]-1] ~= s[1]-1;
        edges[s[1]-1] ~= s[0]-1;
    }

    if (N == 2) {
        writeln("Second");
        return;
    } else if (N == 3) {
        writeln("First");
        return;
    }

    
    int root;
    
    foreach (i; 0..N) {
        if (edges[i].length > 1) {
            root = i;
            break;
        }
    }
    
    bool first = false;
    
    int dfs(int n, int p) {
        int[] tmp;
        foreach (m; edges[n]) if (m != p)
            tmp ~= dfs(m, n);

        if (tmp.sum > 1)
            first = true;

        //writeln(n, tmp);
        return tmp.sum ? 0 : 1;
    }

    if (dfs(root, -1) == 1)
        first = true;
    writeln( first ? "First" : "Second" );
}


Measured memory_bytes: 12284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N,K,Q;
    cin>>N>>K>>Q;
    long long a[N+1]={};
    long long b[N];
    long long mi=0;
    long long ma=0;
    for(long long i=0;i<Q;i++){
    cin>>ma;
    a[ma]++;}
    for(long long i=1;i<=N;i++){
    if(K-Q+a[i]>0){
    cout<<"Yes"<<endl;}
    else
    cout<<"No"<<endl;}}


Measured memory_bytes: 1408