akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int K, X;
    cin >> K >> X;
    vector<int> ans;
    for(int i = -K + 1; i <= K - 1; i++){
        ans.push_back(X + i);
    }
    array_output(all(ans));
}


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	map<vector<int>, ll> freq;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		vector<int> t(26);
		for (char c: s) ++t[c-97];
		++freq[t];
	}
	ll res = 0;
	for (auto x: freq) res += x.second * (x.second - 1) / 2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 22336
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    dp = [10 ** 15] * (2 ** n)
    dp[0] = 0
    for i in range(m):
        a, b = list(map(int, input().rstrip('\n').split()))
        c = sum([2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split()))])
        for j in range(len(dp)):
            dp[j | c] = min(dp[j | c], dp[j] + a)
    print(dp[-1] if dp[-1] != 10 ** 15 else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42220
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

#define ll long long
#define ull unsigned long long
#define lld long double
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll,ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(),v.end()
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl '\n'
template <typename T> using mxpq = priority_queue<T>;
template <typename T> using mnpq = priority_queue<T, vt<T>, greater<T>>;
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define go_t int testcases; cin>>testcases; ffo(caseno,1,testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"

const ll mod = 1e9 + 7;
const ll N = 6e4 + 6;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

int dx[4] = { -1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// up, right, down, left
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions
//int dx[]={-2,-2,-1,1,-1,1,2,2};///Knight moves
//int dy[]={1,-1,-2,-2,2,2,-1,1};///Knight moves

ll powerM(ll x, ll y, ll M = mod) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in4.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	FIO
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({b * d, a * c, a * d, c * b});
	return 0;
}


Measured memory_bytes: 3644
n,a,b,c,d=map(int,input().split())
L=input()[a-1:max(c,d)]
f=0
r="."
for i in list(L):
  if r=="#" and i=="#":
    f=1
    break
  r=i

if c < d:
  print('No' if f==1 else 'Yes')
else:
  g=0
  t="#"
  s="#"
  for i in range(b-1,d):
    if L[i-1:i+2]=="...":
      g=1
      break
    s=i
  print('No' if f==1 or g==0 else 'Yes')

 
  


Measured memory_bytes: 4916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   string s;
   cin >> n >> s;
   int ans = 0;
   rep(i, 1000) {
      string t;
      int x = i;
      rep(j, 3) {
         t += '0' + x % 10;
         x /= 10;
      }
      int ti = 0;
      rep(j, n) {
         if (s[j] == t[ti]) {
            ti++;
            if (ti == 3)
               break;
         }
      }
      if (ti == 3)
         ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
const int maxn=2000+50;
int n;
int cnt;
int f[maxn];
int siz[maxn];
int sum[maxn];
int head[maxn];
char s[maxn];
struct edge
{
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline void addedge(int u,int v)
{
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
void dp(int u,int fa)
{
	siz[u]=sum[u]=0;
	if(s[u]=='1')
	{
		siz[u]=1;
	}
	int mx=-1;
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=fa)
		{
			dp(v,u);
			f[v]+=siz[v];
			siz[u]+=siz[v];
			sum[u]+=sum[v]+siz[v];
			if(mx==-1||f[mx]<f[v]) mx=v;
		}
	}
	if(mx==-1) f[u]=0;
	else
	{
		int t=sum[u]-sum[mx]-siz[mx];
		if(t>=f[mx]) f[u]=sum[u]&1;
		else f[u]=f[mx]-t;
	}
}
int solve(int root)
{
	dp(root,-1);
	return f[root]==0?sum[root]>>1:-1;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	memset(head,-1,sizeof(head));
	for(int i=1;i<n;++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		addedge(a,b);
	}
	int an=-1;
	for(int i=1;i<=n;++i)
	{
		int r=solve(i); if(r==-1) continue;
		if(an==-1||an>r) an=r;
	}
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 512
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

s = ns().replace('?', 'D')
ans = s.count('D')
for i in range(len(s)-1):
    if s[i:i+2] == 'PD':
        ans += 1
print(s)


Measured memory_bytes: 9292
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[1000060],b[1000060];
int main()
{
	ll cnt=0;
	for(int i=2;i<1000050;i++){
		if(a[i]==0){
			for(int j=i+i;j<1000050;j+=i){
				a[j]=1;
			}
			b[cnt++]=i;
		}
	}
	ll n,m;
	scanf("%lld %lld",&n,&m);
	ll mx=max(n,m);
	ll mn=min(n,m);
	ll cc=1;
	for(int i=0;b[i]*b[i]<=mn;i++){
		if(mn%b[i]==0){
			if(mx%b[i]==0){
				cc++;
			}
			while(mn%b[i]==0){
				mn/=b[i];
			}
		}
	}
	if(mn!=1){
		if(mx%mn==0) cc++;
	}
	printf("%lld\n",cc);
	return 0;
}

Measured memory_bytes: 10368
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s = sc.next();
		long ans = sc.nextInt();
		long a = 0,b=0;
		
		// for a
		String[] ss =s.split("\\+");
		for(int i = 0;i<ss.length;i++){
			String sp[] = ss[i].split("\\*");
			long z = 1;
			for(String t:sp){
				int x = Integer.parseInt(t);
				z = z * x;
			}
			a += z;
		}
		
		b = s.charAt(0)-'0';
		// for b
		for(int i=1;i<s.length();i+=2){
			int num = s.charAt(i+1)-'0';
			if(s.charAt(i)=='+'){
				b = b + num;
			} else {
				b = b * num;
			}
		}
		if(a==b && a==ans){
			System.out.println("U");
		} else if((a!=ans && b!=ans)){
			System.out.println("I");
		} else if(a==ans){
			System.out.println("M");
		} else if(b==ans){
			System.out.println("L");
		}
		
	}

}

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

int main()
{
    int N,K,d,j1;
    cin >> N >> K;
    vector<int> A(N);
    int count = 0;
    for ( int i = 0 ; i < K ; ++i)
    {
        cin >> d;
        for ( int j = 0 ; j < d; ++j)
        { 
            cin >> j1;
            A.at(j1 - 1)++;
        }   
    }
    for ( int i = 0 ; i < A.size(); ++i)
    {
        if ( A.at(i) == 0 )
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3632
n,m=map(int, input().split())
xy=[list(map(int, input().split())) for _ in range(m)]

ball=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
    x=xy[i][0]-1
    y=xy[i][1]-1
    ball[y]+=1
    ball[x]-=1
    if red[x]:
        red[y]=True
        if ball[x]==0:
            red[x]=False
print(red.count(True))


Measured memory_bytes: 28516
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<int>a(9);
    for(int i = 0; i < 9; i++){
        cin >> a[i];
    }
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        for(int i = 0; i < 9; i++){
            if(a[i] == b) a[i] = 0;
        }
    }
    if(a[0] == 0 && a[1] == 0 && a[2] == 0) cout << "Yes";
    else if (a[3] == 0 && a[4] == 0 && a[5] == 0) cout << "Yes";
    else if (a[3] == 0 && a[4] == 0 && a[5] == 0) cout << "Yes";
    else if (a[6] == 0 && a[7] == 0 && a[8] == 0) cout << "Yes";
    else if (a[0] == 0 && a[3] == 0 && a[6] == 0) cout << "Yes";
    else if (a[1] == 0 && a[4] == 0 && a[7] == 0) cout << "Yes";
    else if (a[2] == 0 && a[5] == 0 && a[8] == 0) cout << "Yes";
    else if (a[0] == 0 && a[4] == 0 && a[8] == 0) cout << "Yes";
    else if (a[2] == 0 && a[4] == 0 && a[6] == 0) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			long[] a = new long[n];
			long[] b = new long[n];
			long[] c = new long[m];
			long[] d = new long[m];
			
			long[] ret = new long[n];
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextLong();
				b[i] = sc.nextLong();
			}
			
			for(int i=0;i<m;i++) {
				c[i] = sc.nextLong();
				d[i] = sc.nextLong();
			}
			
			long dis = 0;
			long reti = 0;
			long man = 0;
			
			for(int i=0;i<n;i++) {
				 dis = 0;
				 reti = 0;
				
				 for(int j=0;j<m;j++) {
					if(j==0) {
						dis = (Math.abs((a[i]-c[j])))+(Math.abs((b[i]-d[j])));
					}else {
						man = (Math.abs((a[i]-c[j])))+(Math.abs((b[i]-d[j])));
						if(man<dis) {
							reti=j;
						}
						dis = Math.min(dis, man);
					}
				}
				
				ret[i]=reti+1;
			}
			
			for(int i=0;i<n;i++) {
				System.out.println(ret[i]);
			}
		}	
	}

Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int d[100005][35];
int e[100005];

int main(){
    int n,C;
    cin >> n>> C;
    rep(i,n){
        int s, t, c;
        cin >> s>> t>> c;
        d[s][c]++;
        d[t][c]--;
    }
    rep2(i,C){
        rep2(j,100001){
            if(d[j][i]>0){
                e[j-1]++;
            }else if(d[j][i]<0){
                e[j]--;
            }
        }
    }
    int ans=e[0];
    rep2(i,100001){
        //cerr<<d[i]<<' ';
        e[i]+=e[i-1];
        ans=max(ans,e[i]);
    }
    //cerr<<endl;
    cout<<ans<<endl;
    return 0;
}

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


Graph G;

int main(int argc, char **argv)
{
	ll N, X, Y; cin >> N >> X >> Y; --X, --Y;
	G.resize(N);

	for (ll i = 0; i < N-1; ++i)
	{
		G[i].push_back(i+1);
		G[i+1].push_back(i);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);

	queue<int> que;
	vector<vector<ll>> dist(N, vector<ll>(N, -1));
	vector<ll> c_dist(N, 0);

	for (int v = 0; v < N; ++v)
	{
		dist[v][v] = 0;
		que.push(v);

		while (!que.empty())
		{
			int cv = que.front(); que.pop();
			for (auto &nv : G[cv])
			{
				if (dist[v][nv] != -1) continue;

				ll d = dist[v][cv] + 1;
				++c_dist[d];
				dist[v][nv] = d;
				que.push(nv);

			}
		}
	}
	
	for (ll i = 1; i < N; ++i)
		std::cout << c_dist[i]/2 << std::endl;
}

Measured memory_bytes: 31744
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    char c;
    int l[26] = {};
    while(cin >> c)
    {
        if(isupper(c))
        {
            c = tolower(c);
        }
        ++l[c - 'a'];
    }
    for(int i = 0;i < 26;i++)
    {
        cout << char('a' + i) << " : " << l[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  int N, K; cin >> N >> K;
  vector<int> H(N); rep(i, N) cin >> H.at(i);
  sort(all(H));
  long long int ans = 0;
  rep(i, N-K) ans += H.at(i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#define MAXN 100010 
using namespace std;
int h[MAXN];
int dp[MAXN];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] =abs(h[1] - h[0]);
	for (int i = 2; i <= N-1; i++) {
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
		
	}
	cout << dp[N-1] << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
import scala.io.Source.stdin

object Main extends App {
  def isLeapYear(y:Int) = {
    if(y%4 != 0) false
    else if(y%100 != 0) true
    else if(y%400 != 0) false
    else true
  }

  println {
    stdin.getLines.filter( _.trim != "0 0").map { s=>
      val y = s.split(" ").map(_.toInt)
      val leapYear = for(i<-y(0) to y(1);if isLeapYear(i)) yield i
      if(leapYear.length==0) "NA"
      else leapYear.mkString("\n")
    }.mkString("\n\n")
  }
}

Measured memory_bytes: 44892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxm=2e6+5;
char s[maxm];
int n,k;
signed main(){
    cin>>n>>k;
    scanf("%s",s+1);
    int ans=0;
    for(int i=2;i<=n;i++){
        if(s[i]==s[i-1])ans++;
    }
    ans=min(ans+k*2,n-1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3760
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool foo = true;
  for (int i = 1; i <= 1000; i++) {
    if (i % 2 != 0) {
      c -= b;
      if (c <= 0) break;
    } else {
      a -= d;
      if (a <= 0) {
        foo = false;
        break;
      }
    }
  }
  foo ? cout << "Yes\n" : cout << "No\n";
  return 0;
}


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

using namespace std;

typedef long long int64;

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

  int64 val = stoll(S);
  int64 power = 1;
  for(int i = 0; i < S.size(); i++) power *= 10;
  vector< int > vv(10);
  iota(begin(vv), end(vv), 0);

  pair< int64, int64 > ret(1LL << 59, -1);
  do {
    int64 v = 0;
    for(int i = 0; i < S.size(); i++) v = v * 10 + vv[i];
    ret = min(ret, {-min(power - llabs(v - val), llabs(v - val)), v});
  } while(next_permutation(begin(vv), end(vv)));

  printf("%0*lld\n", S.size(), ret.second);
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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)
#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 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;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi p(N);
  rep(i,N) {
    cin >> p[i];
  }
  int ans = 0;
  rep(i,N-1) {
    if(p[i] == i+1) {
      swap(p[i],p[i+1]);
      ans++;
    }
  }
  if(p[N-1] == N) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main (void){
    int b[28],x,y,z[31]={0};
    for(x=0;x<=27;x++){
        scanf("%d",&b[x]);
        y=b[x];
        z[y]=1;
    }
    for(y=1;y<=30;y++){
        if(z[y]==0)printf("%d\n",y);
    }

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int MN = 100012;
int n,a[MN],dp[MN];
int main (void) {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    dp[1] = abs(a[1]-a[0]);
    for (int 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] << "\n";
    return 0;
}


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

int main(){
  int n;
  int f=1;
  long long s=0;
  cin >> n;
  long long a[100010];
  for(int i=0; i<n; i++){
    cin >> a[i];
    s += f*a[i];
    f = -f;
  }
  long long x = s/2;
  for(int i=0; i<n; i++){
    cout << 2*x << " ";
    x = a[i]-x;
  }
}

Measured memory_bytes: 2048
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535
#define MOD 1000000007
#define rep(i, n) for(ll i=0;i<(n);i++)

int main(void) {
	int n; cin >> n;
	vector<string> s(n);
	unordered_map<string,ll> mp;
	ll ans=0;
	rep(i, n) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
		mp[s[i]]++;
	}
	for (auto& x:mp) {
		ll a = x.second;
		ans += a * (a - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17700
N,x = map(int,input().split())
a = list(map(int,input().split()))
b = [x if a[0]>x else a[0]]
for i in range(N-1):
  if b[i]+a[i+1]>x:
    b.append(x-b[i])
  else:
    b.append(a[i+1])
ans = 0
for i in range(N):
  ans += a[i]-b[i]
print(ans)

Measured memory_bytes: 14052
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <numeric>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}
function<void(int,int)> pro___shumi=[&](int v,int d){
};

void no() {
	cout << "No" << endl;
	exit(0);
}
int main() {
	string ope;
	cin >> ope;
	int X = in();
	int Y = in();
	vint xs, ys;
	{
		int i;
		for (i = 0; ope[i] == 'F'; i++) X--;
		bool isx = true;
		int acc = 0;
		for (;; i++) {
			if (ope[i] == 'F') {
				acc++;
			}
			else {
				if (acc > 0) {
					isx ? xs.pb(acc) : ys.pb(acc);
				}
				acc = 0;
				isx = !isx;
			}
			
			if (ope[i] == 0) break;
		}
	}
	pr(X);
	pr(Y);
	pra(xs);
	pra(ys);
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	int xsum = accumulate(xs.begin(), xs.end(), 0);
	int ysum = accumulate(ys.begin(), ys.end(), 0);
	pr(xsum);
	pr(ysum);
	if (xsum < X || ysum < Y || (X + xsum) % 2 || (Y + ysum) % 2) {
		no();
	}
	int targetx = (xsum - X) / 2;
	int targety = (ysum - Y) / 2;
	
	function<int(int, vint&)> solve=[&](int target, vint &data) {
		vint dp(target + 10);
		dp[0] = 1;
		rep(i, data.size()) {
			for (int k = dp.size() - data[i] - 1; k >= 0; k--) {
				if (dp[k]) dp[k + data[i]] = 1;
			}
		}
		return dp[target];
	};
	
	if (! solve(targetx, xs) || ! solve(targety, ys)) no();
	cout << "Yes" << endl;
	
	return 0;
}


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

using namespace std;

void invalid() {
    cout << -1 << endl;
    exit(0);
}

// # 方針
// 一旦 $K_{n}$ の完全グラフを作り、そこから「不要な辺」を削っていくことで、辺コストの総和を最小にすることを目指す。
// 「不要な辺」とは、 「v-u 間の最短経路」と「v-i 間の最短経路 + i-u 間の最短経路」が等しくなる頂点 i が存在するときの $E_{v,u}$
int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            // 完全グラフを仮定して、二重辺を作らないように注意しながらコストの総和を計算する
            if (i < j)sum += a[i][j];
        }
    }

    for (int v = 0; v < n - 1; v++) {
        for (int u = v + 1; u < n; u++) {
            if (a[v][u] != a[u][v])invalid(); // v-u間の最短経路とu-v間の最短経路が同じでない無向グラフは明らかに存在しない
            for (int i = 0; i < n; i++) {
                if (i == v || i == u)continue;
                if (a[v][u] > a[v][i] + a[i][u])invalid(); // v-u間の最短経路よりv-i間最短経路+i-u間の最短経路の方が短くなるグラフは明らかに存在しない
                if (a[v][u] == a[v][i] + a[i][u]){
                    sum -= a[v][u];
                    break;
                }
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 4004
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    vector<int> a;
    cin >> n;
    REP(i, n)
    {
        int temp;
        cin >> temp;
        temp -= i + 1;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());
    int midium = a[a.size() / 2];
    long long sum = 0;
    REP(i, n)
    {
        sum += abs(a[i] - midium);
    }
    cout << sum << endl;
}

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

int main() {
    long long num;

    cin >> num;

    vector<long long> vec(num+1);
    for (int i = 0; i < num; i++) cin >> vec.at(i+1);

    if (num % 2 == 0){
        // 6 4 2 1 3 5
        for (int i = num; i > 1; i -= 2){
            cout << vec.at(i) << " ";
        }

        for (int i = 1; i < num; i += 2){
            cout << vec.at(i) << " ";
        }
    }else{
        // 5 3 1 2 4
        for (int i = num; i > 0; i -= 2){
            cout << vec.at(i) << " ";
        }

        for (int i = 2; i < num; i += 2){
            cout << vec.at(i) << " ";
        }
    }
}

Measured memory_bytes: 3712
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

bool can(vector<int> a) {
  int n = (int)a.size();
  sort(begin(a), end(a));
  
  if (a[n-1]-a[0] > 1) {
    return false;
  }
  
  if (a[n-1] >= n) {
    return false;
  }
  
  int m = (a[0] != n-1) ? a[n-1] : n;
  
  int i = 0, tmp = m;
  while (i < n && a[i] == (m-1)) {
    i++, tmp--;
  }
  m = tmp;
  
  
  if (m < 0) {
    return false;
  }
    
  if (m == 0 && i < n) {
    return false;
  }
  
  return (n - i) >= 2 * m; 
}

int main(void) {
  int n;
  scanf("%i", &n);
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%i", &a[i]);
  }
  
  puts(can(a) ? "Yes" : "No");
    
  return 0;
}

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

template <class T1> void write(T1 e)
{
    cout << e << endl;
}
template <class T1,class T2> void write(T1 e1,T2 e2)
{
    cout << e1 << " "<< e2 << endl;
}
template <class T1,class T2,class T3> void write(T1 e1,T2 e2,T3 e3)
{
    cout << e1 << " " << e2 << " " << e3 << endl;
}

#define oo          (1<<30)
#define SZ(a)       (int)a.size()
#define LL          long long int
#define ULL         unsigned long long
#define ISS         istringstream
#define OSS         ostringstream
#define VS          vector <string>
#define VI          vector <int>
#define VD          vector <double>
#define VLL         vector <long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define fs          first
#define sc          second
#define pii         pair < int , int >

#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
#define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
#define BE(a)       a.begin(),a.end()
#define RBE(a)      a.rbegin(),a.rend()
#define rev(a)      reverse(BE(a));
#define sorta(a)    sort(BE(a))
#define pb          push_back
#define popb        pop_back
#define Round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;

#define makeint(n,s)  istringstream(s)>>n
#define string_to_int(str) atoll(str.c_str());

#define LCM(A,B)    ((__gcd(A,B))/A)*B
#define GCD(A,B)     __gcd(A,B)

#define YES     write("YES")
#define Yes     write("Yes")
#define yes     write("yes")
#define NO      write("NO")
#define No      write("No")
#define no      write("no")

#define read()      freopen("test.txt","r",stdin)
#define write_file()     freopen("WA.txt", "w", stdout);
#define Faster      {ios_base::sync_with_stdio(false); cin.tie(0);}

#define PI          3.141592653589793
#define pi          2*acos(0)
#define gama        0.57721566490
#define ERR         1e-5
#define PRE         1e-8
#define MAX         1000009

#define Scan(A)         scanf("%lld", &A)
#define Scan2(A, B) 	scanf("%lld %lld",&A, &B)
#define Scan3(A, B, C) 	scanf("%lld %lld %lld",&A, &B, &C)
#define Scan4(A, B, C, D) 	scanf("%lld %lld %lld %lld",&A, &B, &C, &D)

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

bool isvowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
}

struct myStruct
{
    LL Sum;
    string name;
    string Party;
};

bool cmp(myStruct a, myStruct b)
{
    return a.Sum > b.Sum ? 0 : 1;
}

map <char, int> Mp;

void Method()
{
    int j = 0;
    for(char i = 'a'; i <= 'z'; i++)
    {
        char temp = (char) i;
        Mp[temp] = j;
        j++;
    }
}

int main()
{
    LL A, B, C, D;
    while(cin >> A >> B >> C >> D)
    {
        if(A + B == C + D)
            write("Balanced");
        else if(A + B > C + D)
            write("Left");
        else
            write("Right");
    }
    return 0;
}


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

ll n, p, q;

int main() {
  cin >> n;
  vector<ll> a(n);
  vector<ll> s(n);
  rep (i, n) {
    cin >> a[i];
    a[i] *= 2;
  }
  rep (i, n) {
    s[i] += a[i];
    if (i != 0) s[i] += s[i-1];
  }
  auto itr = lower_bound(s.begin(), s.end(), s[n-1]/2);
  p = *itr;
  if (itr != s.begin()) --itr;
  q = *itr;
  cout << min(p- s[n-1]/2, s[n-1]/2 - q) << endl;
  return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

ll cal(ll a) {
    if (a < 0) return 0;
    ll res = (a + 1) / 2 % 2;
    if (a%2==0) res ^= a;
    return res;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = cal(b) ^ cal(a-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	int ans=0;
	for(int i = 1; i <= n; i++) {
		string S = to_string(i);
		int sum = 0;
		for(int j = 0; j < S.size(); j++) {
			sum += S[j] - '0';
		}
		if (sum >= a && sum <= b){
			ans += i;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int A,B,C,X,Y;
	cin>>A>>B>>C>>X>>Y;
	if(A+B<=C*2){
		cout<<A*X+B*Y<<endl;
		return 0;
	}
	if(X<Y){
		cout<<min(Y*2*C,X*2*C+(Y-X)*B)<<endl;
	}else{
		cout<<min(X*2*C,Y*2*C+(X-Y)*A)<<endl;
	}

}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())

ans = 1

for i in range(N):
    T = int(input())
    ans = lcm(ans, T)

print(ans)

Measured memory_bytes: 38512
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a + min(b, c), b + c) << endl;
	return 0;
}

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

int main(){
  using lint= long long int;
  lint N,M,buf;
  cin >> N  >> M;

  lint duration= 0;
  for(auto i=0; i<M; i++){
    cin >> buf;
    duration+= buf;
  }

  lint ans= max(N-duration, -1LL);

  cout << ans << endl;
}


Measured memory_bytes: 3636
# ABC133E - Virus Tree 2
from collections import deque


def dfs() -> int:
    cand, ret, MOD = K - 1, K, 10 ** 9 + 7
    queue, seen = deque([1]), [0] * (N + 1)
    seen[1] = 1
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if not seen[u]:
                seen[u] = 1
                ret = (ret * cand) % MOD
                cand -= 1
                queue.append(u)
        cand = K - 2
    return ret


def main():
    global N, K, G
    N, K, *AB = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(AB)] * 2):
        G[v].append(u), G[u].append(v)
    ans = dfs()
    print(ans)


if __name__ == "__main__":
    main()

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};



int main(void){
  int n;
  cin >> n;
  VI a(n + 1), b(n + 1);
  REP(i, 0, n) {
    cin >> a[i];
    a[n] ^= a[i];
  }
  REP(i, 0, n) {
    cin >> b[i];
    b[n] ^= b[i];
  }
  {
    VI acp(a);
    VI bcp(b);
    sort(acp.begin(), acp.end());
    sort(bcp.begin(), bcp.end());
    if (acp != bcp) {
      cout << "-1" << endl;
      return 0;
    }
  }
  // coord comp
  set<int> comp;
  REP(i, 0, n + 1) {
    comp.insert(a[i]);
    comp.insert(b[i]);
  }
  vector<int> aux(comp.begin(), comp.end());
  sort(aux.begin(), aux.end());
  map<int, int> tbl;
  REP(i, 0, aux.size()) {
    tbl[aux[i]] = i;
  }
  REP(i, 0, n + 1) {
    a[i] = tbl[a[i]];
    b[i] = tbl[b[i]];
  }
  vector<PI> ops;
  vector<int> nop(n + 1, 0);
  UnionFind uf(n);
  REP(i, 0, n + 1) {
    if (a[i] != b[i]) {
      ops.push_back(PI(a[i], b[i]));
      uf.unite(a[i], b[i]);
    }
  }
  REP(i, 0, ops.size()) {
    nop[uf.root(ops[i].first)] += 1;
  }
  int tot = 0;
  int top = uf.root(b[n]);
  REP(i, 0, n + 1) {
    if (nop[i] > 0) {
      // cerr << "(" << i << ", " << nop[i] << ")" << endl;
      assert (nop[i] >= 2);
      bool flag = i == top;
      tot += flag ? nop[i] : nop[i] + 1;
    }
  }
  if (a[n] != b[n]) {
    tot -= 1;
  }
  cout << tot << endl;
}


Measured memory_bytes: 13552
import numpy as np
N,M,C = map(int,input().split())
BList= list(map(int,input().split()))
X = np.array(BList)

count = 0
for _ in range(N):
    src = list(map(int,input().split()))
    Y = np.array(src)
    if np.dot(X,Y)+C > 0:
        count += 1

print(count)

Measured memory_bytes: 12480
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int ans = 0;
  string s; cin >> s;

  for (int i = 0; i < (int)s.size()-1; i++) {
    if (s.substr(i, 2) == "BW" || s.substr(i, 2) == "WB") {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            q[i] = sc.nextInt();
        }

        int a = findRank(p,n);
        int b = findRank(q,n);
        System.out.println(Math.abs(a - b));

    }

    public static int fac(int n) {
        int res = 1, i;
        for (i=2; i<=n; i++)
            res *= i;
        return res;
    }

    public static int findSmallerInRight(int[] array, int low, int high) {
        int countRight = 0, i;

        for (i = low + 1; i <= high; i++)
            if (array[i] < array[low])
                countRight++;

        return countRight;
    }

    public static int findRank(int[] array, int length) {
        int mul = fac(length);
        int rank = 1;
        int countRight;

        for (int i = 0; i < length; ++i) {
            mul /= length - i;

            countRight = findSmallerInRight(array, i, length - 1);

            rank += countRight * mul;
        }

        return rank;
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

import static java.lang.System.out;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = (scanner.nextInt());
        int [] S= new int[size];
        for (int i = 0; i < size; i++) {
            S[i] = scanner.nextInt();
        }

        int ansSize = (scanner.nextInt());
        int[] T = new int[ansSize];
        for (int i = 0; i < ansSize; i++) {
            T[i] = scanner.nextInt();
        }

        int count = 0;
        for (int i = 0; i <T.length ; i++) {
            for (int j = 0; j < S.length; j++) {
                if(T[i]==S[j]){
                    count++;
                    break;
                }
            }

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


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

using namespace std;

int s1,s2,s3;
int n;
int p;
int a,b;

int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		cin>>p;
		if(p<=a) s1++;
		else if(p<=b) s2++;
		else s3++;
	}
	cout<<min(s1,min(s2,s3));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
int dp[200005];
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N ;
    vector<int> P(N);
    rep(i,N)cin >> P[i];
    int ans = 0;
    for(int i=0;i<N;i++){
        int p = P[i];
        dp[p] = dp[p-1] + 1;
        chmax(ans,dp[p]);
    }
    cout << N - ans << endl;
}

Measured memory_bytes: 1792
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on("data",function(chunk){
   var line = chunk.trim().split("\n");
   var res = line.map(function(e){
       var ele = e.split(" ");
       switch(ele[1]){
           case "+":
               return parseInt(ele[0]) + parseInt(ele[2]);
               
           case "-":
               return parseInt(ele[0]) - parseInt(ele[2]);
           case "*":
               return parseInt(ele[0]) * parseInt(ele[2]);
           case "/":
               return parseInt(parseInt(ele[0])/ parseInt(ele[2]));
           case "?":
               break;

       }
   });
   console.log(res.slice(0,-1).join("\n"));
});

Measured memory_bytes: 15672
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int prime[300005]={};
  for(i=2;i<300005;i++)
    if(prime[i]==0 &&(i%7==1||i%7==6))
      for(j=2;i*j<300005;j++)
        prime[i*j]++;
  int n;
  while(1){
    cin>>n;
    if(n==1)break;
    cout<<n<<":";
    for(i=2;i<=n;i++)
      if(i%7==1 || i%7==6)
        if(prime[i]==0&&n%i==0)
          cout<<" "<<i;
    cout<<endl;
  }
}

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long int a = 0, b = 0, len = 0, out = 0;
    cin >> a >> b;
 
    if(a < b){
        out = a;
        len = b;
    }else{
        out = b;
        len = a;
    }
    for(int i = 0 ; i < len ; i++){
        cout << out;
    }
    return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
for i in range(dy):
  print('U', end = '')
for i in range(dx):
  print('R', end = '')
for i in range(dy):
  print('D', end = '')
for i in range(dx):
  print('L', end = '')
print('L', end = '')
for i in range(dy + 1):
  print('U', end = '')
for i in range(dx + 1):
  print('R', end = '')
print('DR', end = '')
for i in range(dy + 1):
  print('D', end = '')
for i in range(dx + 1):
  print('L', end = '')
print('U')

Measured memory_bytes: 4468
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


int main() {
    string s;
    auto solve = [](string &a, string &b, string &c, int val){
        ll x = 0, y = 0, z = 0;
        for (auto &&i : a) x = (x*10 + (isdigit(i) ? i-'0' : val))%MOD;
        for (auto &&i : b) y = (y*10 + (isdigit(i) ? i-'0' : val))%MOD;
        for (auto &&i : c) z = (z*10 + (isdigit(i) ? i-'0' : val))%MOD;
        return (x+y)%MOD == z%MOD;
    };
    while(cin >> s){
        string A, B, C;
        int cur = 0;
        for (auto &&i : s) {
            if(i == '+' || i == '=') cur++;
            else if(cur == 0) A += i;
            else if(cur == 1) B += i;
            else C += i;
        }
        int ok = 0;
        for (int i = ((A.size() != 1 && A[0] == 'X') || (B.size() != 1 && B[0] == 'X') ||  (C.size() != 1 && C[0] == 'X')); i < 10; ++i) {
            if(solve(A, B, C, i)) {
                cout << i << "\n";
                ok = 1;
                break;
            }
        }
        if(!ok) puts("NA");
    }
    return 0;
}



Measured memory_bytes: 2980