akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int INFTY = 2e9;

struct Card{
    char M;
    int V;
};

Card A[100001], B[100001], L[50001], R[50001];

void merge(int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) L[i] = A[left+i];
    for(int i = 0; i < n2; i++) R[i] = A[mid+i];
    L[n1].V = INFTY;
    R[n2].V = INFTY;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        if(L[i].V <= R[j].V){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

void MySwap(Card &a, Card &b){
  Card tmp = a;
  a = b;
  b = tmp;
}
  

int partition(int p, int r){
  int x = B[r].V;
  int i = p - 1;
  for(int j = p; j < r; j++){
    if(B[j].V <= x){
      MySwap(B[++i], B[j]);
    }
  }
  MySwap(B[++i], B[r]);
  return i;
}

void quicksort(int p, int r){
    if(p < r){
        int q = partition(p, r);
        quicksort(p, q-1);
        quicksort(q+1, r);
    }
}

int main(){
    int n;
    Card a;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a.M >> a.V;
        A[i] = a;
        B[i] = a;
    }
    mergeSort(0, n);
    quicksort(0, n - 1);
    bool f = false;
    for(int i = 0; i < n; i++) if(A[i].M != B[i].M) f = true;
    if(f) cout << "Not stable" << endl;
    else cout << "Stable" << endl;
    for(int i = 0; i < n; i++) cout << B[i].M << " " << B[i].V << endl;
    return 0;
}


Measured memory_bytes: 5432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, k;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        k = sc.nextInt();
        solve();
    }

    void solve() {
        long count = 0;
        for (int b = k + 1; b <= n; b++) {
            int m = b != 0 ? n / b : 0;
            int r = b != 0 ? n % b : n - 1;
            count += m * Math.max(0, b - k) + Math.max(0, r - k + 1);
            if (k == 0) count--;
        }
        System.out.println(count);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 110;
int a[N];

void no() {
	puts("Impossible");
	exit(0);
}

void yes() {
	puts("Possible");
	exit(0);
}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n;
	cin >> n;
	forn(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	if (n == 2) {
		puts((a[0] == 1 && a[1] == 1)?("Possible"):("Impossible"));
		return 0; 
	}
	if (n == 3) {
		puts((a[0] == 1 && a[1] == 2 && a[2] == 2)?("Possible"):("Impossible"));
		return 0; 
	}
	int maxx = a[n - 1];
	if (a[n - 1] != a[n - 2]) {
		no();
		return 0;
	}
	multiset<int> s;
	forn(i, n - 2) {
		s.insert(a[i]);
	}
	for (int i = 1; i < maxx; ++i) {
		int res = max(i, maxx - i);
		if (s.find(res) == s.end()) {
			no();
		}
		s.erase(s.find(res));
	}
	for (auto it: s) {
		int val = it;
		if (val < (maxx + 1) / 2 + 1) {
			no();
		}
	}
	yes();
	
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] k = new int[m];
        List<List<Integer>> sw = new ArrayList<>();
        int[] p = new int[m];
        for(int i=0;i<m;i++){
            k[i] = Integer.parseInt(sc.next());
            sw.add(new ArrayList<>());
            for(int j=0;j<k[i];j++){
                sw.get(i).add(Integer.parseInt(sc.next())-1);
            }
        }
        for(int i=0;i<m;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int temp;
        int count = 0;
        boolean flag = true;
        int res = 0;
        for(int i=0;i<1<<n;i++){
            flag = true;
            for(int j=0;j<m;j++){
                count = 0;
                for(int l=0;l<k[j];l++){
                    temp = sw.get(j).get(l);
                    if(((i>>temp) & 1)==1){
                        count++;
                    }
                }
                if(count%2!=p[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                res++;
            }

        }
        System.out.println(res);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

int ret = 0;
ll n;

void dfs(string str, bool three, bool five, bool seven)
{
    if(stoll(str) > n) return;
    if(three && five && seven)
        ret += 1;
    
    dfs(str + "3", true, five, seven);
    dfs(str + "5", three, true, seven);
    dfs(str + "7", three, five, true);
    
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> n;
    
    dfs("3", true, false, false);
    dfs("5", false, true, false);
    dfs("7", false, false, true);
    
    cout << ret << endl;
    return 0;
}


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

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

  string ans= (Nleg%2==0 && 2*N <= Nleg && Nleg <= 4*N) ? "Yes"
                                                     : "No";
  
  cout << ans << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

  	int3(a, b, c);
  	set<int> s;
  	s.insert(a);
  	s.insert(b);
  	s.insert(c);
  	cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

int main(){	
	ll N;
	cin >> N;
	map<ll, ll> m;
	repn(i, N) {
		ll a;
		cin >> a;
		m[a] = i;
	}
	repn(i, N-1) {
		cout << m[i] << " ";
	}
	cout << m[N] << endl;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

const double pi=acos(-1);

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	double r;
	cin>>r;
	cout<<fixed<<setprecision(10)<<r*2*pi<<endl;

}

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

int main()
{
  long  n;
  long k;
  cin>>n;
  cin>>k;
  vector<long> nums(n);
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    nums[i]=x;
  }
    vector<long> dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(nums[0]-nums[1]);
    for(long i=2;i<n;i++)
    {  
  		for(long j=i-1;j>=0&&j>=i-k;j--)
          dp[i]=min(dp[i],dp[j]+abs(nums[i]-nums[j]));
    }
    cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt() * 2;
			if(n == 0){
				break;
			}
			int [][] dp = new int[n][2];
			int [] jumpA = {1,3,5};
			int [] jumpB = {-1,1,3};
			for(int i=0; i < n; i+= 2){
				dp[i][0] = -1;
				dp[i][1] = sc.nextInt();
			}
			for(int i=1; i < n; i+= 2){
				dp[i][0] = -1;
				dp[i][1] = sc.nextInt();
			}

			for(int i=0; i <= 1; i++){
				int j = i;
				if(dp[i][1] == 1){
					while(j < n && dp[j][1] == 1)
						j += 2;
					j -= 2;
				}
				dp[j][0] = 0;
			}

			//dp start
			boolean repeat = true;
			for(int i=0; i < n * 2; i++){
				int ind = i % n;
				if(dp[ind][0] == -1)
					continue;
				for(int j=0; j <= 2; j++){
					int value = dp[ind][0] + 1;
					int k;

					if(ind%2 == 0)
						k = ind + jumpA[j];
					else
						k = ind + jumpB[j];

					if(k >= n)
						continue;

					if(dp[k][1] == 1){
						while(k < n && dp[k][1] == 1)
							k += 2;
						k -= 2;
					}
					else if(dp[k][1] == 2){
						while(dp[k][1] == 2)
							k -= 2;
					}

					if(dp[k][0] == -1 || value < dp[k][0])
						dp[k][0] = value;
				}
			}

			//print
			if(dp[n-1][0] == -1 && dp[n-2][0] == -1)
				System.out.println("NA");
			else if(dp[n-1][0] == -1 || dp[n-2][0] == -1){
				if(dp[n-1][0] == -1)
					System.out.println(dp[n-2][0]);
				else
					System.out.println(dp[n-1][0]);
			}
			else{
				int result = Math.min(dp[n-1][0], dp[n-2][0]);
				System.out.println(result);
			}

		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let r = read::<u32>();
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
    int d,n;
    cin>>d>>n;
    if(n==100)n++;
    cout<<(int)pow(100,d)*n<<endl;
	return 0;
}



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

// 入力
const int DEBUG = 0;
int N, C[409], S[409][409];

// 出力
int Last[409];
int Answer[409];

int solve(int pos) {
	pair<int, int> maxn = make_pair(-(1 << 30), -1);
	for (int i = 1; i <= 26; i++) {
		int score = S[pos][i];
		for (int j = 1; j <= 26; j++) {
			if (i != j) score -= C[j] * (pos - Last[j]);
		}
		maxn = max(maxn, make_pair(score, i));
	}
	return maxn.second;
}

int getscore(vector<int> vec) {
	for (int i = 1; i <= 26; i++) Last[i] = 0;
	int t = 0;
	for (int i = 0; i < vec.size(); i++) {
		Last[vec[i]] = i + 1; t += S[i + 1][vec[i]];
		for (int j = 1; j <= 26; j++) t -= C[j] * ((i + 1) - Last[j]);
	}
	return t;
}

int main() {
	if (DEBUG == 0) {
		cin >> N;
		for (int i = 1; i <= N; i++) cin >> C[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) cin >> S[i][j];
		}
	}
	else {
		N = 365;
		for (int i = 1; i <= N; i++) C[i] = rand() % 101;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) S[i][j] = ((rand() % 32768) * 32768 + (rand() % 32768)) % 20001;
		}
	}

	// Step #2. 貪欲法で初期解を求める
	for (int i = 1; i <= N; i++) {
		Answer[i] = solve(i);
		Last[Answer[i]] = i;
	}

	// Step #3. 山登り法を使ってより良い解を求める
	vector<int> R;
	for (int i = 1; i <= N; i++) R.push_back(Answer[i]);

	int CurrentMax = getscore(R);
	for (int t = 1; t <= 80000; t++) {
		int ty = rand() % 2;
		if (ty == 0) {
			int v1 = rand() % (N - 1);
			swap(R[v1], R[v1 + 1]);
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; }
			else { swap(R[v1], R[v1 + 1]); }
		}
		else {
			int v1 = rand() % N, v2 = rand() % 26;
			int moto = R[v1];
			R[v1] = v2;
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; }
			else { R[v1] = moto; }
		}
	}
	for (int i = 1; i <= N; i++) cout << Answer[i] << endl;
	return 0;
}

Measured memory_bytes: 4200
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N,K=mint()
D=lint()
S=set([str(d) for d in D])

for x in range(N,100000):
    s=str(x)
    tmp=True
    for i in range(len(s)):
        if s[i] in S:
            tmp=False
            break
    if tmp:
        print(x)
        exit()

Measured memory_bytes: 74484
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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 <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    map<int,int> cnt;
    int n;
    cin>>n;
    REP(i,n) {
        int D;
        cin>>D;
        cnt[D]++;
    }
    int M;
    cin>>M;
    REP(i,M) {
        int T;
        cin>>T;
        if(CONTAIN(cnt,T) && cnt[T]>0) {
            cnt[T]--;
        } else {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
long long a, maks = -1, data[100005], sum[100005];

int main() {
	cin >> a;
	for (long i = 0; i < a; i++){
		cin >> data[i];
		sum[data[i]]++;
		sum[data[i]+1]++;
		sum[data[i]-1]++;
	}
	for (long i = 0; i < 100005; i ++){
		if (sum[i] > maks){
			maks = sum[i];
		}
	}
	cout << maks << endl;
}
 


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  v(string) strs(N);
  rep(i,N) {
    cin >> strs[i];
  }
  int tailA = 0,headB = 0,AnB = 0;
  int ans = 0;
  rep(i,N) {
    string str = strs[i];
    if(str[0] == 'B' && str[sz(str)-1] == 'A') {
      AnB++;
    } else if(str[0] == 'B') {
      headB++;
    } else if(str[sz(str)-1] == 'A') {
      tailA++;
    }
    rep(j,sz(str)-1) {
      if(str[j] == 'A' && str[j+1] == 'B') {
        ans++;
      }
    }
  }
  if(headB > 0 || tailA > 0) {
    ans += AnB;
    cout << ans + min(headB,tailA) << endl;
    return 0;
  } else if(AnB > 0) {
    headB = 1;
    ans += AnB-1;
    cout << ans + min(headB,tailA) << endl;
    return 0;
  } else {
    cout << ans << endl;
    return 0;
  }
  
  return 0;
}

Measured memory_bytes: 768
def main():
    import sys
    n, k, *a = map(int, sys.stdin.read().split())
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print(path[d])
            break
        path.append(nx)
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()


Measured memory_bytes: 32440
#include<iostream>
#include<queue>

using namespace std;

static const int N =100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];
void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++)d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();q.pop();
        for(int v=0;v<n;v++){
            if(M[u][v]==0)continue;
            if(d[v]!=INFTY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << ((d[i]==INFTY)?(-1):d[i]) << endl;    
    }
}
int main(){
    int u,k,v;
    
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        u--;
        for(int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int l[n], r[n];
    for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
    int sum = 0;
    for (int i = 0; i < n; i++) sum += r[i]-l[i]+1;
    cout << sum << endl;
}

Measured memory_bytes: 256
N=int(input())
cnt_list={}

for i in range(1,N+1):
    cnt=0
    tmp=i
    while True:
        if tmp%2!=0:
            break
        else:
            cnt=cnt+1
            tmp=tmp//2
    cnt_list[i]=cnt

print(max(cnt_list,key=cnt_list.get))


Measured memory_bytes: 2940
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack 
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <list>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0; i<n; i++){
    cin >> l[i];
  }
  long long sum=0;
  sort(l.begin(),l.end());
  for(int i=0; i<n-2; i++){
    for(int j=i+1; j<n-1; j++){
      int x =lower_bound(l.begin()+j+1,l.end(),l[i]+l[j])-l.begin()-j-1;
      sum+=x;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N,a,z,c,sum=0;
	cin>>N;
	int n=N;
	while(n>0)
	{
		sum+=n%10;
		n=n/10;
	}
	if(N%sum==0)
	{
		cout<<"Yes";
    } 
    else
    {
    	cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
int main()
{
  int n, d;
  scanf("%d %d", &n, &d);
  long x[n], y[n];
  int i, cnt = 0;
  for (i = 0; i < n; i++)
  {
    scanf("%ld %ld", &x[i], &y[i]);
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d)
      cnt++;
  }
  printf("%d", cnt);
}

Measured memory_bytes: 5272
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  if (x > y) {
    swap(a, b);
    swap(x, y);
  }
  if (a + b <= 2 * c) {
    printf("%d\n", a * x + b * y);
    return 0;
  }

  int numab = min(x, y) * 2;
  x -= numab / 2;
  y -= numab / 2;

  if (b <= 2 * c) {
    printf("%d\n", c * numab + b * y);
  } else {
    int addab = y * 2;
    printf("%d\n", c * (numab + addab));
  }

  return 0;
}


Measured memory_bytes: 256
n,x,m = map(int,input().split())
k_1 = set()
k_2 = set()
tmp = list()
loop_number = 0
loop_sum = 0
while x not in k_1:
	k_1.add(x)
	x = x*x%m
while x not in k_2:
	k_2.add(x)
	tmp.append(x)
	loop_number+=1
	loop_sum+=x 
	x = x*x%m
ans = 0
k_1 = list(k_1)
for i in range(len(k_1)):
	ans +=  k_1[i]
ans = ans + loop_sum * ((n-len(k_1))//loop_number)
for i in range((n-len(k_1))%loop_number):
	ans += tmp[i]
print(ans)

Measured memory_bytes: 16928
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
def solve(N):
    N = [int(c) for c in N][::-1]
    p = 0
    b = 0
    for i in range(len(N)):
        c = N[i] + b
        p += X[c]
        if c == 5:
            b = 0 if i == len(N)-1 or N[i+1] < 5 else 1
        else:
            b = c > 5
    return p + b

print(solve(input()))


Measured memory_bytes: 116260
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;
 

int main() {
    ll n;
    cin >> n;
    bool yes = true;
    vector<ll> hs(n);
    for (ll i = 0; i < n; ++i) {
        cin >> hs[i];
    }
    for (ll i = n -1; i > 0; --i) {
        if (hs[i-1] - hs[i] == 1) {
            hs[i-1] = hs[i-1] - 1;
        }
    }
    for (ll i = 0; i < n-1; ++i) {
        if (hs[i] > hs[i+1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


def cmb(n, k, p):
    global fact, factinv
    if (k < 0) or (n < k):
        return 0
    r = min(k, n - k)
    return fact[n] * factinv[k] * factinv[n - k] % p



def main():
    N, M, K = [int(x) for x in input().split()]

    MOD = 998244353

    global fact, factinv, inv
    for i in range(2, 10 ** 6 + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)


    ans = 0
    for i in range(K + 1):
        ans += M * pow(M - 1, N - 1 - i, MOD) * cmb(N - 1, i, MOD)
        ans %= MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 168084
#include <math.h>
#include <iostream>
#include <vector>
#include <set>
#include <regex>

using namespace std;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(_debuged) cerr << #_debuged << ":" << _debuged << endl;

struct L
{
	int t;
	int x;
	int y;
};

vector<int> loadn(int n)
{
	vector<int> v(n);
	REP(i, n)
		cin >> v[i];
	return v;
}

uint64_t modpower(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
	uint64_t ret = 1;
	uint64_t k2 = N;
	REP(i, 31)
	{
		if ((K >> i) & 0x1)
		{
			ret *= k2;
			ret = ret % MOD;
		}
		k2 = (k2 * k2) % MOD;
	}
	return ret;
}

class ModCombinationMemo
{
public:
	const unsigned int N;
	const unsigned int MOD;
	vector<uint64_t> memo = { 1 };

	ModCombinationMemo(uint32_t N, uint32_t MOD)
		: N(N), MOD(MOD)
	{
	}

	uint64_t c(uint64_t k)
	{
		if (memo.size() > k)
		{
			return memo[k];
		}

		FOR(i, memo.size(), k + 1)
		{
			const auto number = (memo[i - 1] * (N - i + 1)) % MOD;
			const auto reverceDeon = modpower(i, MOD - 2, MOD);
			memo.push_back(number * reverceDeon % MOD);
		}

		return memo[k];
	}
};

uint64_t c(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
	if (K == 0)
	{
		return 1;
	}

	uint64_t n = 1, k = 1;

	REP(i, K)
	{
		n *= N - i;
		k *= i + 1;

		n = n % MOD;
		k = k % MOD;
	}

	uint64_t powerk = modpower(k, MOD - 2, MOD);

	return (n * powerk) % MOD;
}

unsigned trailing_zeros(unsigned n)
{
	if (!n)
		return -1;
	unsigned int c = 32; // c will be the number of zero bits on the right
	n &= -(signed)n;
	if (n)
		c--;
	if (n & 0x0000FFFF)
		c -= 16;
	if (n & 0x00FF00FF)
		c -= 8;
	if (n & 0x0F0F0F0F)
		c -= 4;
	if (n & 0x33333333)
		c -= 2;
	if (n & 0x55555555)
		c -= 1;
	return c;
}

unsigned int digitssum(uint64_t source) {
	int result = 0;

	while (source > 0) {
		result += source % 10;
		source /= 10;
	}

	return result;
}

struct oishisa
{
	int64_t x;
	int64_t y;
	int64_t z;
};

int64_t cint()
{
	int64_t i;
	cin >> i;
	return i;
}

int main(int argc, char *argv[], char *envp[])
{
	const int64_t N(cint());
	const int64_t K(cint());

	vector<int64_t> A;
	REP(i, N) {
		A.push_back(cint());
	}

	cout << ceil(double(N - 1) / (K - 1)) << endl;
}
/*

int main(int argc, char *argv[], char *envp[])
{
int i = 0;
REP(n, 4) {
char sign;
cin >> sign;
i += (sign == '+' ? +1 : -1);
}
cout << i;
}
/*
int main(int argc, char *argv[], char *envp[])
{
const int K(cint());


int result = 0;

for (uint64_t target = 1; result < K; target++) {
FOR(s, 1, 127) {
int minimum = target + 1;
while(digitssum(minimum) != s) {
minimum +=
}

if (target * digitssum(minimum) > minimum * digitssum(target)) {
goto b;
}
}

cout << target << endl;
result++;

b:;

}

return 0;
}
*/


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

template <int Mod, bool IsPrime = false>
class mod_int {
    using ll = long long;

public:
    constexpr mod_int() : n(0) {}
    constexpr mod_int(int n_) : n(n_) {
        if(n >= Mod)     n %= Mod;
        else if(n < 0) n = (n % Mod + Mod) % Mod;
    }
    constexpr mod_int(ll n_) : n(n_) { n = (n + Mod) % Mod; }

    constexpr operator int() const { return n; }
    constexpr operator ll() const  { return n; }

    constexpr bool operator==(mod_int const& other) const { return n == other.n; }
    constexpr mod_int& operator+=(mod_int const& other) {
        if((n += other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator-=(mod_int const& other) {
        if((n += Mod - other.n) >= Mod) n -= Mod;
        return *this;
    }
    constexpr mod_int& operator*=(mod_int const& other) {
        n = (unsigned long long)n * other.n % Mod;
        return *this;
    }
    constexpr typename std::enable_if<IsPrime, mod_int>::type& operator/=(mod_int const& other) {
        return *this *= other.inverse();
    }
    constexpr mod_int operator+(mod_int other) const { return mod_int(*this) += other; }
    constexpr mod_int operator-(mod_int other) const { return mod_int(*this) -= other; }
    constexpr mod_int operator*(mod_int other) const { return mod_int(*this) *= other; }
    constexpr mod_int operator/(mod_int other) const { return mod_int(*this) /= other; }

    constexpr typename std::enable_if<IsPrime, mod_int>::type inverse() const {
        ll a = n, b = Mod, u = 1, v = 0;
        while(b) {
            ll t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        return mod_int(u);
    }

private:
    ll n;
};

template <int Mod, bool IsPrime>
std::ostream& operator<<(std::ostream& os, mod_int<Mod, IsPrime> const& n) {
    os << (int)n;
    return os;
}

constexpr int default_mod = 1000000007;

template <int Mod = default_mod>
mod_int<Mod, true> fact(int n) {
    static std::vector<mod_int<Mod, true>> v = {1};
    if(n >= static_cast<int>(v.size())) {
        const int from = v.size(), to = n + 1024;
        v.reserve(to);
        for(int i = from; i < to; ++i) {
            v.push_back(v.back() * mod_int<Mod, true>(i));
        }
    }
    return v[n];
}

template <int Mod = default_mod>
mod_int<Mod, true> comb(int n, int r) { // nCr
    if(r < 0 || r > n) return 0;
    return fact<Mod>(n) / fact<Mod>(r) / fact<Mod>(n - r);
}

using mint = mod_int<default_mod, true>; // default

mint modpow(mint x, int n) {
    mint res = 1;
    while(n) {
        if(n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    int n, k; cin >> n >> k;
    k = min(k, n - 1);

    mint ans = 1;
    for(int i = 1; i <= k; ++i) {
        ans += comb(n, i) * comb(n - 1, i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int h = sc.nextInt();
			
			if(n == 0 && h == 0){
				break;
			}
			
			boolean[][] xy = new boolean[n][n];
			boolean[][] yz = new boolean[n][n];
			boolean[][] xz = new boolean[n][n];
					
			int ans = n * n * n;
			
			for(int i = 0; i < h; i++){
				final String c = sc.next();
				final int a = sc.nextInt() - 1;
				final int b = sc.nextInt() - 1;
				
				if("xy".equals(c) && !xy[a][b]){
					int hole = 0;
					for(int z = 0; z < n; z++){
						if(yz[b][z] || xz[a][z]){
							hole++;
						}
					}
					
					ans -= n - hole;
					
					xy[a][b] = true;
				}else if("yz".equals(c) && !yz[a][b]){
					int hole = 0;
					for(int x = 0; x < n; x++){
						if(xy[x][a] || xz[x][b]){
							hole++;
						}
					}
					
					ans -= n - hole;
					
					yz[a][b] = true;
				}else if("xz".equals(c) && !xz[a][b]){
					int hole = 0;
					for(int y = 0; y < n; y++){
						if(yz[y][b] || xy[a][y]){
							hole++;
						}
					}
					
					ans -= n - hole;
					
					xz[a][b] = true;
				}
			}
			
			System.out.println(ans);
		}
		
	}

}

Measured memory_bytes: 38636
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

signed main() {
    string S;
    cin >> S;

    int seq=0;
    while(seq<S.size()) {
        string t1="";
        FOR(i, seq, seq+5) {
            if(i>=S.size()) {
                cout << "NO" << endl;
                return 0;
            }
            t1 += S[i];
        }
        seq+=5;
        if(seq==S.size()) {
            if(t1=="dream" || t1=="erase") {
                cout << "YES" << endl;
                return 0;
            } else {
                cout << "NO" << endl;
                return 0;
            }
        }
        if(t1=="dream") {
            string t2="";
            FOR(i, seq, seq+2) {
                if(i>=S.size()) {
                    cout << "NO" << endl;
                    return 0;
                }
                t2 += S[i];
            }
            if(t2=="er") {
                if(seq+2==S.size()) {
                    cout << "YES" << endl;
                    return 0;
                }
                else if(S[seq+2]!='a') seq+=2;
                else continue;
            } else continue;
        } else if(t1=="erase") {
            if(S[seq]=='r') seq+=1;
            else continue;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    } 

    cout << "YES" << endl;

    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S;
    cin >> S;
    ll N = (ll)S.size();
    ll ans = 0;
    ll cur = S[0] == 'W' ? 0 : 1;
    for (ll i = 1; i < N; i++) {
        ll t = S[i] == 'W' ? 0 : 1;
        if (cur != t) {
            ++ans;
            cur = t;
        }
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var s = io.S;
        io.Write(s.StartsWith("YAKI") ? "Yes" : "No");
    }
}

Measured memory_bytes: 13408
#56c
import math
X = int(input())

#1,2,3…の等差数列の和以下ならたどり着ける
#S = n * (2*a +(n-1)*d) / 2
#d = 1,a=1より
#S = n * (2 + n - 1) / 2
#2S = n * (n + 1) = n^2 + n
#0 = n^2 + n - 2S
#→ n = -1±√1-4*1*(-2X) / 2

n = math.ceil((-1 + math.sqrt(1 + 8*X) ) / 2)
print(n)


Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var c = Enumerable.Repeat(0, nm[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        for (int i = 0; i < 1000; i++)
        {
            var s = i.ToString();
            if (s.Length != n) continue;
            if (!c.All(x => s[x[0] - 1] - '0' == x[1])) continue;
            Console.WriteLine(i);
            return;
        }
        Console.WriteLine(-1);
    }
}


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

int main() {
  vector<int>x(3);
  for(int i=0;i<3;i++) cin>>x[i];
  sort(x.begin(),x.end());
  int ans=x[0]+x[1]+10*x[2];
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    if len(str(i))==n:
        x=str(i)
        for b,c in a:
            if int(x[b-1])!=c:
                break
        else:
            print(i)
            exit()
print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int H, W; cin >> H >> W;
  int K; cin >> K;
  vector<string> c(H); REP(i, H) cin >> c[i];
  vector<string> cp(H);
  REP(i, H) {
    cp[i] = c[i];
  }
  int ans = 0;
  for(int a = 0; a < (1 << H); ++a) {
    for(int b = 0; b < (1 << W); ++b) { // cpを赤で埋める
      for(int i = 0; i < H; ++i) {
        if(a & (1 << i)) {
          REP(k, W) {
            cp[i][k] = '@';
          }
        }
      }
      for(int i = 0; i < W; ++i) {
        if(b & (1 << i)) {
          REP(k, H) {
            cp[k][i] = '@';
          }
        }
      }
      int tmp = 0;
      REP(i, H) { // #の数を数える
        REP(k, W) {
          if(cp[i][k] == '#') tmp++;
        }
        if(i == H - 1) {
          if(tmp == K) {
            ans++;
          }
        }
      }
      REP(i, H) { // もとに戻す
        REP(k, W) {
          cp[i][k] = c[i][k];
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632