akhauriyash/Code-Regression huggingface dataset:
from collections import OrderedDict

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

ans = 0
for i in range(N):
    if (i == N - 1):
        break
    L = ''.join(OrderedDict.fromkeys(S[0:i + 1]))
    R = ''.join(OrderedDict.fromkeys(S[i + 1:]))
    count = 0
    for j in range(len(L)):
        if (L[j] in R):
            count += 1
        else:
            continue
    ans = max(ans, count)

print(ans)


Measured memory_bytes: 3316
n, k = map(int, input().split())
heights = list(map(int, input().split()))
heights = [0] + heights
dp = [10**10]*(n+1)
dp[1] = 0

for i in range(1, n+1):
    for step in range(1, k+1):
        if (i + step) <= n:
            dp[i+step] = min(dp[i+step], abs(heights[i+step] - heights[i]) + dp[i])
print(dp[n])



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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

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

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

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

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n | m)
	{
		vector<int> fl[512];
		bool f[512];
		fill(f, f + n, false);
		for (int i = 0; i < m; ++i)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			--a; --b;
			if (a == 0)
				f[b] = true;
			fl[a].push_back(b);
			fl[b].push_back(a);
		}
		bool ff[512];
		fill(ff, ff + n, false);
		for (int i = 1; i < n; ++i)
			if (f[i])
				foreach(it, fl[i])
					ff[*it] = true;
		int res = 0;
		for (int i = 1; i < n; ++i)
			if (f[i] || ff[i])
				++res;
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> a(n),dp(n+10,mod);
    rep(i,n) cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<=n;i++) {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <queue>
using namespace std;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;
int M[MAX][MAX], n;
int d[MAX], color[MAX];
queue<int> Q;

void bfs(int s)
{
    int u, v;
    Q.push(s);
    color[s] = GRAY;
    d[s] = 0;
    while (!Q.empty())
    {
        u = Q.front();
        Q.pop();
        for (int v = 0; v != n; ++v)
        {
            if (M[u][v] && color[v] == WHITE)
            {
                Q.push(v);
                color[v] = GRAY;
                d[v] = d[u] + 1;
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
    int id, m, v;
    cin >> n;
    for (int i = 0; i != MAX; ++i)
    {
        d[i] = NIL;
        color[i] = WHITE;
        for (int j = 0; j != MAX; ++j)
        {
            M[i][j] = 0;
        }
    }
    for (int i = 0; i != n; ++i)
    {
        cin >> id >> m;
        for (int j = 0; j != m; ++j)
        {
            cin >> v;
            M[id-1][v-1] = 1;
        }
    }
    bfs(0);

    for (int i = 0; i != n; ++i)
    {
        cout << i + 1 << " " << d[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb(a) push_back((a))


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

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int ans = 0;
	int x = 200001;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (x > a[i]) {
			x = a[i];
			ans++;
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<ll> area(s.size()+1,0);
    vector<ll> hei(40000,1e9),wid(40000,1e9);


    ll maxh=20000,minh=400000;
    ll loch=20000;
    hei[20000]=0;
    for(ll i=1;i<=s.size();i++){
//        cout << s[i-1];
//        cout <<"loch : "<< loch << endl;
        if(s[i-1]=='\\'){
            loch--;
        }else if(s[i-1]=='/'){
            loch++;
            if(hei[loch]!=1e9){
                area[i]=(i-hei[loch]-1); //area
                wid[i]=hei[loch]; //start i of area
            }
        }
        hei[loch]=i;
    }
//    for(ll i=0;i<=s.size();i++){
//        cout << i;
//        cout << " area : "<< area[i];
//        cout << " begin wid : "<<wid[i] << endl;
//    }
//
    ll bw=0,cou=-1;
    stack<pair<ll,ll> > st;
    for(ll i=0;i<=s.size();i++){
        if(area[i]!=0){
            if(wid[i]>=bw){
                st.push(make_pair(i,area[i]));
                bw=wid[i];
            }else{
                for(;!st.empty();){
                    ll j=st.top().first;
                    ll a=st.top().second;
                    if(wid[j]>wid[i]){
                        area[i]+=a;
                        st.pop();
                    }else{
                        break;
                    }
                }
                st.push(make_pair(i,area[i]));
            }
        }
    }

    ll sumare=0;
    ll siz=st.size();
    vector<ll> vc;
    for(ll i=0;i<siz;i++){
        sumare += st.top().second;
        vc.push_back(st.top().second);
        st.pop();
    }

    cout << sumare << endl;
    cout << siz << (siz!=0?" ":"\n");
    for(ll i=vc.size()-1;i>=0;i--){
        cout << vc[i] << (i!=0?" ":"\n");
    }
}



Measured memory_bytes: 3988
//
//  main.c
//  ITP1_5_D
//
//  Created by ??±??°?????? on 2015/10/11.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

#include <stdio.h>

void call(int n);

int main(int argc, const char * argv[]) {
    int num;
    
    scanf("%d", &num);
    call(num);
    
    return 0;
}

void call(int n){
    int i;
    int x;
    
    for (i=1; i<=n; i++) {
        x = i;
        if (x%3 == 0) {
            printf(" %d", i);
        }
        else{
            while (x){
                if (x%10 == 3) {
                    printf(" %d", i);
                    break;
                }
                x /= 10;
            }
        }
        
    }
    puts("");
}

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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  rep(i, N) {
    cin >> card.at(i);
  }
  int alice, bob, tmp;
  alice = 0;
  bob = 0;
  tmp = 0;
  
  rep(i, N) {
    for (int j = i+1; j < N ; j++) {
      if (card.at(i) < card.at(j)) {
        tmp = card.at(i);
        card.at(i) = card.at(j);
        card.at(j) = tmp;
      }
    }
  }
  
  if (N % 2 == 0) {
    rep(i, N/2) {
      alice += card.at(2*i);
      bob += card.at(2*i+1);
    }
  }
  else {
    rep(i, N/2 ) {
      alice += card.at(2*i);
      bob += card.at(2*i+1);
    }
    alice += card.at(N-1);
  }
  
  cout << alice-bob << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string s;
cin >> s;
s[5] = ' '; s[13] = ' ';
cout << s << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int f[3010][3010];
string s, t;

inline void work() {
    cin >> s >> t;
    for (int i = 1; i <= s.size(); ++i) {
        for (int j = 1; j <= t.size(); ++j) {
            f[i][j] = max(max(f[i][j - 1], f[i - 1][j]), f[i - 1][j - 1] + (s[i - 1] == t[j - 1]));
        }
    }
    string ans;
    int i = s.size(), j = t.size();
    while (i && j) {
        if (f[i][j] == f[i][j - 1]) {
            --j;
        }
        else if (f[i][j] == f[i - 1][j]) {
            --i;
        }
        else {
            ans += s[i - 1];
            --i;
            --j;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 35584
import sys


def solve(S: int, W: int):

    if S <= W:
        print('unsafe')
    else:
        print('safe')

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include<stdio.h>
int main() {
	int i = 0, j, n, sw = 0, flag, a[100], x;
	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &a[i]);
	flag = 1;
	for (i = 0; flag; i++) {
		flag = 0;
		for (j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				x = a[j];
				a[j] = a[j - 1];
				a[j - 1] = x;
				flag = 1;
				sw++;
			}
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if (i != n - 1)printf(" ");
	}
	printf("\n%d\n", sw);
	return 0;
}

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int a, b;
    in2(a, b);
    int ans;
    rep1(i, 3)
    {
        if (i != a && i != b)
        {
            ans = i;
        }
    }
    out(ans);
}

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

int main()
{
int W;int H;int x;int y;int r;
	cin >> W;
	if(W<0||W>100){
	cout << "error" << endl;
       return 0;
	}
     cin >> H;
     if(H<0||H>100){
     cout << "error" << endl;
       return 0;
	}
     cin >> x;
	if(x<-100||x>100){
     cout << "error"<< endl;
       return 0;
	}
     cin >> y;
	if(y<-100||y>100){
     cout << "error" << endl;
       return 0;
	}
     cin >> r;
     if(r<0||r>100){
     cout << "error" << endl;
       return 0;
	}
       if(x-r<0||x+r>W){
	cout << "No" << endl;
       return 0;
	}else if(y-r<0||y+r>H){
       cout << "No" << endl;
       return 0;
       }else{
       cout << "Yes" << endl;
       return 0;
}
return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define N 1000

int A[N],B[N],n,m;
int solve(int,int);

int solve(int i, int k){
  int res;
  if ( k == 0 ) return 1; // true
  if ( i >= n ) return 0; // false
  res = solve(i + 1, k) || solve(i + 1, k - A[i]);
  return res;
}

int main(){

  int i,flag=1;

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

  scanf("%d",&m);
  for( i = 0 ; i < m ; i++ ){
    scanf("%d",&B[i]);
    flag = solve(0,B[i]);
    if( flag == 0 ) puts("no");
    else puts("yes");
      }
  return 0;
}

Measured memory_bytes: 588
n = int(input())
d = []
for i in range(n):
    s, p = input().split()
    d.append((s,int(p),i+1))
d.sort(key = lambda x: x[1], reverse = True)
d.sort(key = lambda x: x[0])
for i in range(n):
    print(d[i][2])

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

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

	return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>

void SelectionSort(int n,int A[]);

int count=0;

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

  SelectionSort(n,&A[0]);

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

void SelectionSort(int n,int A[]){
  int i,j;
  int mini,key;
  
  for(i=0;i<n;i++){
    mini = i; 
    for(j=i+1;j<n;j++){
      if(A[j] < A[mini]){
	mini = j;
      }
    }
    if(mini != i){
      key = A[i];
      A[i] = A[mini];
      A[mini] = key;
      ++count;
    }
  }
}

Measured memory_bytes: 604
import java.util.*

fun main(args: Array<String>) {
  val (N, M, K) = readInts()
  val AB = (1..M).map { readInts() }
  val CD = (1..K).map { readInts() }

  // ブロックメモ作成
  val blocks = Array(N) { HashSet<Int>() }
  CD.forEach {
    val (C, D) = it
    blocks[C - 1].add(D - 1)
    blocks[D - 1].add(C - 1)
  }

  // 友達グラフ作成
  val G = Array(N) { HashSet<Int>() }
  AB.forEach {
    val (A, B) = it
    G[A - 1].add(B - 1)
    G[B - 1].add(A - 1)
  }

  // グループ作成
  val groups = arrayOfNulls<Set<Int>>(N)
  for (i in 0 until N) {
    if (groups[i] != null) continue
    val set = HashSet<Int>()
    fun f(n: Int) {
      if (groups[n] != null) return
      set.add(n)
      groups[n] = set
      G[n].forEach { f(it) }
    }
    f(i)
  }

  // 友達候補の出力
  val builder = StringBuilder()
  for (i in 0 until N) {
    // 所属グループ - 既存友達 - ブロック者 - 自分 が候補になる
    val group = groups[i]!!
    val friends = G[i]
    val block = blocks[i]

    val friendCnt = friends.count { group.contains(it) } // 所属グループ内の既存友達の数
    val blockCnt = block.count { group.contains(it) } // 所属グループ内のブロック者の数
    if (i != 0) builder.append(" ")
    builder.append(group.size - friendCnt - blockCnt - 1)
  }
  builder.appendln()
  println(builder.toString())
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map(Integer::parseInt)
//fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()

fun readLongs() = readStrings().map { it.toLong() }


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define dupli(a)     unique(all(a)),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define f first
#define s second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;



int main(){

   
    
  	ll a,b,c,k;
  	cin>>a>>b>>c>>k;
  	if(a>=k){pt(k); return 0;}
  	if(a+b>=k){pt(a); return 0;}
  	else{
  		ll p=k-(a+b);
  		pt(a-p);

  	}


    

    

}


/*

// 

*/

Measured memory_bytes: 3612
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
  	String s=sc.next();
  	if(a>=3200){
    System.out.println(s);
    }else{
    System.out.println("red");
    }
}
}

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

int main()
{
  string S;

  cin >> S;

  if ( S[0] != S[1]
    && S[0] != S[2]
    && S[1] != S[2] )
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b,h,m=gsmi
pi=Math::PI
rad_h=2*pi/12*(h+m.to_f/60)
rad_m=2*pi*(m.to_f/60)
d = (rad_h - rad_m).abs
rad= d>pi ? 2*pi - d : d
x2=a**2+b**2-2*a*b*Math.cos(rad)

puts Math.sqrt x2

Measured memory_bytes: 14796
x = int(input())
for a in range(-int(x**0.3), int(x**0.3) + 1):
    for b in range(-int(x**0.3), int(x**0.3) + 1):
        if a**5 - b**5 == x:
            print(a, b)
            break
    else:
        continue
    break

Measured memory_bytes: 9328
#include <iostream>
#include <string.h>
using namespace std;
#define ll long long
const int N=2e5+5;
int a[N],b[N];

int main(){
    int n,k;cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    while(k--){
    int flag=0;
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++){
        b[max(i-a[i],0)]++;
        if(i+a[i]+1<=n-1)
        b[i+a[i]+1]--;
    }
    a[0]=b[0];
    for(int i=1;i<n;i++){
        b[i]+=b[i-1];
        a[i]=b[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]!=n){
            flag=1;
            break;
        }
    }
    if(flag==0) break;
    }
    for(int i=0;i<n;i++)
        cout<<a[i]<<' ';
    return 0;
}

Measured memory_bytes: 5164
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int ans = 1;
    if((n % k) == 0) ans = 0;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    if(a==0)
        printf("%d\n",1);
    else if(b==0)
    printf("%d\n",2);
        else if(c==0)
        printf("%d\n",3);
        else if(d==0)
        printf("%d\n",4);
        else if(e==0)
        printf("%d\n",5);
    return 0;


}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 100005
vi v[MAX_N];

int dfs(int x){
    int m = v[x].size();
    if(m==0){
        return 0;
    }

    int tmp[m] = {};

    rep(i,m){
        tmp[i] = dfs(v[x][i]);
    }
    sort(tmp,tmp+m);
    int ret = 0;
    rep(i,m){
        ret = max(ret,m-i+tmp[i]);
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    srep(i,2,n+1){
        int a;
        cin >> a;
        v[a].push_back(i);
    }
    
    int ans = dfs(1);
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 16640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInts(n int) []int {
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	xs := readInts(n)

	ds := make([]int, n)
	for i, v := range xs {
		ds[i] = abs(x - v)
	}
	ans := ds[0]
	for _, d := range ds {
		ans = gcd(d, ans)
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    ll r,c;
    cin>>r>>c;
    ll res=r*c;
    if(r==1||c==1){
        cout<<"1\n";
        exit(0);
    }
    res=(res+1)/2;
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	set<int> D;
	Rep(i, N) cin >> d[i], D.insert(d[i]);
	cout << D.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	set<int> s;
	
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		s.insert(x);
	}
	
	if(s.size() == n)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int mod = 1e9 + 7;

vector<bool> isPrime(2000, true);
vector<int> p;
map<int,int> numPrime;
void addDiv(int);

int main()
{
	int N;
	cin >> N;
	rep(i, 2) isPrime[i] = false;
	for (int i = 2; i*i <= 2000; i++)
	{
		if(isPrime[i]==true)
		{
			for (int j = 2; i*j <= 2000; j++)
			{
				isPrime[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= 2000; i++)
	{
		if (isPrime[i]) p.push_back(i);
	}
	rep1(i, N) addDiv(i);
	ll ans = 1;
	for (auto x:numPrime)
	{
		ans *= (x.second + 1);
		ans %= mod;
	}
	co(ans);
	return 0;
}
void addDiv(int a)
{
	int i = 0;
	while (p[i]<= a)
	{
		int buf = a;
		int cnt = 0;
		while (buf%p[i] == 0)
		{
			buf /= p[i];
			cnt++;
		}
		numPrime[p[i]] += cnt;
		i++;
	}
}

Measured memory_bytes: 256
input()
a = [int(i) for i in input().split()]
mode = ''
cnt = 1
for i in range(len(a)-1):
  if mode == '' and a[i] < a[i+1]:
    mode = 'inc'
  elif mode == '' and a[i] > a[i+1]:
    mode = 'dec'
  elif mode == 'inc' and a[i] > a[i+1]:
    mode = ''
    cnt += 1
  elif mode == 'dec' and a[i] < a[i+1]:
    mode = ''
    cnt += 1
print(cnt)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 x;
  cin >> x;
  i64 c = x / 11;
  i64 rest = x - c * 11;
  c *= 2;
  c += rest > 6 ? 2 : (rest > 0 ? 1 : 0);
  cout << c << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{  int n,a[100],i,s=0;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(i=0;i<n;i++)
   if(i%2==0&&(a[i]%2!=0)) s++;
   printf("%d",s);
   return 0;
} 

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int q, x, y;
	ll a, b;
	
	scanf("%d", &q);
	ll n = 1, m = 1;
	while (q--) {
		scanf("%d%d", &x, &y);
		a = n / x;
		if (n % x) a++;
		b = m / y;
		if (m % y) b++;
		a = max(a, b);
		n = a * x, m = a * y;
	}
	printf("%lld\n", n + m); 
}

Measured memory_bytes: 256
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,n,count=0;
    char s[100];
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0; i<n; i++)
    {
        if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C'))
        {
            count++;
        }

    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 1700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;
typedef __float128 FL;

bool startswith(const string s, int start, const string prefix) {
  if(s.size() - start < prefix.size())
    return false;
  return equal(prefix.cbegin(), prefix.cend(), s.cbegin() + start);
  
}

int main() {
  string S;
  cin >> S;
  int len = S.size();
  vector<bool> dp(len+1, false);
  vector<string> pattern = {"dream", "dreamer", "erase", "eraser"};
  dp[0] = true;
  REP(i, len) {
    if(!dp[i]) continue;
    REP(j, pattern.size()) {
      if(startswith(S, i, pattern[j])) {
        dp[i+pattern[j].size()] = true;
      }
    }
  }
  cout << (dp[len] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
using namespace std;

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

/*
  n m s g1 g2
  a b c
  ...
  am bm cm
  0 0 0 0 0
  */

int n,m,s,g1,g2;
int edge[128][128];
int main(){
  while(scanf("%d%d%d%d%d",&n,&m,&s,&g1,&g2),n|m|s|g1|g2){
    s--; g1--; g2--;
    //init
    //rep(i,128)rep(j,128)edge[i][j]=INT_MAX;
    memset(edge, 0x2a, sizeof(edge));
    //printf("%d\n",edge[1][2]);
    //printf("%d\n",INT_MAX/3);
    //return 0;
    rep(i,100)edge[i][i]=0;

    // input
    rep(i,m){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      edge[a-1][b-1]=c;
    }

    // í[µáéÓë¢Ç
    rep(k,n){
      rep(i,n){
        rep(j,n){
          edge[i][j] = min(edge[i][j], edge[i][k]+edge[k][j]);
        }
      }
    }

    int ans = 707406378;
    rep(k,n){
      if( k==g1 ){
        ans = min(ans, edge[s][g1]+edge[g1][g2]);
      }else if( k==g2 ){
        ans = min(ans, edge[s][g2]+edge[g2][g1]);
      }else{
        ans = min(ans, edge[s][k]+edge[k][g1]+edge[k][g2]);
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
  
   ll n;
    cin >> n;
   vll a(n);
    rep(i,0,n) cin >> a[i];
    string s;
    cin >> s;
   
    vll b;
    repr(i,n,0){
     ll v=a[i];
      for(auto w:b) chmin(v,(v^w));
      if(v){
       if(s[i]=='1'){
        cout << 1 << endl;
         return;
       }
        else b.eb(v);
      }
      
    }
   
   cout << 0 << endl; 
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll t;
  cin >> t;
  while(t--) solve();
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int h,w;cin>>h>>w;
    char s[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s[i][j];
        }
    }

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

    int ans = 0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j] == '#') continue;

            vector<vector<int>> dist(h,vector<int>(w,-1));
            queue<pair<int,int>> que;

            dist[i][j] = 0;
            que.emplace(i,j);

            while(!que.empty()){
                pair<int,int> v = que.front();
                que.pop();

                for(int dir = 0; dir < 4; dir++){
                    int nh = v.first + dx[dir];
                    int nw = v.second + dy[dir];
                    if(nh<0||nh>=h||nw<0||nw>=w) continue;
                    if(s[nh][nw] == '#') continue;
                    if(dist[nh][nw] != -1) continue;

                    dist[nh][nw] = dist[v.first][v.second] + 1;

                    que.emplace(nh,nw);
                }
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    ans = max(ans,dist[i][j]);
                }
            }
        }
    }

    cout<<ans<<endl;

}

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

const int mxN=200005,M=1e9+7;
int n,a,b,tot;
int fat[mxN],inv[mxN];
int mod(int x,int M){int ret=x%M;if(ret<0)ret+=M;return ret;}

int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);

    int t=mod(exp(a,b/2,M),M);
    if(b%2==1)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);

}

int C(int n,int k){
    int ans=1LL;
    for(int i=n;i>=n-k+1;i--){
        ans=mod(ans*i,M);
    }
    return mod(ans*inv[k],M);
}

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

    cin>>n>>a>>b;
    fat[0]=inv[0]=1;
    tot=exp(2,n,M);
    for(int i=1;i<mxN;i++){
        fat[i]=(i*fat[i-1]%M);
        inv[i]=exp(fat[i],M-2,M);
    }

    tot=(tot-1-C(n,a)-C(n,b))%M;
    if(tot<0)tot+=M;

    cout<<tot;



}

Measured memory_bytes: 3328
N,K = map(int, input().split())
S=input()
RL=S.count('RL')
LR=S.count('LR')
diff=RL+LR
happy=N-1-diff
if diff%2==0:
    print(happy+2*min(diff//2,K))
else:
    print(happy+2*K if (diff//2+1)>K else happy+diff)


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


int main(){
 int A,B,C,D;
 cin>>A>>B>>C>>D;
 int i = 0;
 while(true){
  if(i % 2 == 0)C = C-B;
  else A = A-D;
  i++;
  if(A <= 0||C <= 0)break;
 }
 if(A <= 0)cout<<"No";
 if(C <= 0)cout<<"Yes";
}

Measured memory_bytes: 3548
//#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

const int maxn = 200100;
ll t[maxn];
int n;
ll T;
void solve() {
  cin >> n >> T;
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  ll sum = T;
  for (int i = 1; i < n; ++i) {
    sum += T;
    if (t[i - 1] + T > t[i]) {
      sum -= t[i - 1] + T - t[i];
    }
  }
  cout << sum << endl;
}

int main() {
  solve();
  return 0;
}


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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
 
#define INF (int)100000000000000000
#define PI (double)3.14159265358979
#define MOD 1000000007


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
    int n, x, t;
    cin >> n >> x >> t;
    int a = (n+x-1)/x;

    cout << a*t << "\n";
 
    return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

bool used[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    rep(i, N) cin >> a[i];
    int t = 0;
    rep(i, N) t ^= a[i];
    //cout << t << endl;
    int ans = 0;
    
    RREP(i, 30, 0) {
        if (!(t & (1 << i))) continue;
        ans++;
        bool change = false;
        //cout << t <<  "->";
        rep(j, N) {
            if (used[j]) continue;
            t = t ^ a[j];
            int nxt = t ^ (a[j] - 1);
            if (!(nxt & (1 << i)) && (t ^ a[j]) > nxt) {
                t = t ^ (a[j] - 1);
                change = true;
                used[j] = true;
                break;
            }
            t = t ^ a[j];
        }
        //cout <<  t << endl;
        if(!change) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 640
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.float64).reshape(n, n)

def main():
    B = floyd_warshall(csr_matrix(A), directed=False).astype(np.int64)
    if np.any(B < A):
        return -1
        
    np.fill_diagonal(A, np.inf)
    
    total_length = 0
    for v in range(n-1):
        for u in range(v+1, n):
            detours = A[v] + A[u]
            if np.all(detours > B[v, u]):
                total_length += B[v, u]

    return total_length

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

Measured memory_bytes: 28184
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int r, c, k;
    cin >> r >> c >> k;
    vector< vector< vector< long long > > > dp(4, vector< vector<long long> >(r, vector<long long>(c, 0)));
    vector< vector< int > > p(r, vector<int>(c, 0));
    for(int i=0;i<k;i++){
        int x, y, z;
        cin >> x >> y >> z;
        p[--x][--y] = z;
    }

    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            for(k=0;k<4;k++){
                long long tmp = 0;
                if(k > 0) tmp = dp[k-1][i][j];
                if(k > 0) tmp = max(tmp, dp[0][i][j] + p[i][j]);

                if(i > 0) tmp = max(tmp, dp[3][i-1][j]);
                if(j > 0) tmp = max(tmp, dp[k][i][j-1]);
                if(k > 0){
                    if(i > 0) tmp = max(tmp, dp[3][i-1][j] + p[i][j]);
                    if(j > 0) tmp = max(tmp, dp[k-1][i][j-1] + p[i][j]);
                }
                dp[k][i][j] = tmp;
            }
        }
    }
    cout << dp[3][r-1][c-1] << endl;
}


Measured memory_bytes: 355068
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	ll n;
	cin>>n;
	for(int i=sqrt(n);i>=1;i--) {
		if(n%i==0){
			cout<<i+n/i-2;
			return;
		}
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3696
// AtCoder Grand Contest 011
// A - Airport Bus

#include <cstdio>
#include <algorithm>
#define MAX_N 100000
using namespace std;
typedef long long int ll;


int N;
ll C, K;
ll T[MAX_N];
int ans;

int main() {

  ll cnt, lim_t;

  scanf("%d%lld%lld", &N, &C, &K);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &T[i]);
  }
  sort(T, T + N);

  ans = 1;
  cnt = 1;
  lim_t = T[0];
  for (int i = 1; i < N; i++) {
    if (cnt >= C || lim_t + K < T[i]) {
      ans++;
      cnt = 1;
      lim_t = T[i];
    } else {
      cnt++;
    }
  }

  printf("%d\n", ans);

  return 0;

}




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

int main() { 
  int n, m;
  cin >> n >> m;
  if(n==m){
    cout <<  "Yes" << endl;
  }else{
  cout <<   "No"  << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define LOOP(i,s,e) for(int i=s;i<e;i++)
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define MAX3(a,b,c) (a>b)?MAX(a,c):MAX(b,c)
#define MIN3(a,b,c) (a>b)?MIN(b,c):MIN(a,c)

int intcmp(const int *a,const int *b) {return (*a - *b);}

int intrcmp(const int *a,const int *b) {return (*b - *a);}

int dblcmp(const double *a,const double *b) { return (*a < *b) ? -1 : (*a == *b) ? 0 : 1; }

int stcmp(const char *a[],const char *b[]) { return(strcmp(*a, *b)); }

int main() {
	char S[4]="";
	scanf("%s",&S);
	if(strcmp("SUN",&S)==0) printf("7\n");
	if(strcmp("MON",&S)==0) printf("6\n");
	if(strcmp("TUE",&S)==0) printf("5\n");
	if(strcmp("WED",&S)==0) printf("4\n");
	if(strcmp("THU",&S)==0) printf("3\n");
	if(strcmp("FRI",&S)==0) printf("2\n");
	if(strcmp("SAT",&S)==0) printf("1\n");
	return 0;
}

Measured memory_bytes: 128