akhauriyash/Code-Regression huggingface dataset:
def solve():

    S = input()

    words = ['dream', 'dreamer', 'erase', 'eraser']

    while(True):
        if(len(S) == 0):
            break
        flag = False
        for w in words:
            if(S.endswith(w)):
                S = S[0:len(S) - len(w)]
                flag = True
        
        if(not flag):
            print('NO')
            return
            
        
    print('YES')
    
solve()

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

int N;
vector<double> v;

int main()
{
	cin >> N;
	v = vector<double>( N );
	for( int i = 0; i < N; i++ ) {
		cin >> v[i];
	}

	sort( v.begin(), v.end() );
	double ans = v[0];
	for( int i = 1; i < N; i++ ) {
		ans = (ans + v[i]) / 2;
	}

	cout << fixed << setprecision(12) << ans <<  endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int main()
{
    int  a=0,b=0,iii=0,n=0;
    cin >> n;
    for(iii=0;iii<n;iii++){
        cin >> a;
        if(a==2 || a==3 || a==5 || a==7){
            b++;
        }

        else if(a>=9 && a%2!=0){
            int i=3;
            b++;
            while(i<=sqrt(a)){

                if(a%i==0){
                    b--;
                    break;
                }
                i=i+2;
            }
        }
    }
    cout << b;
    cout << endl;
}

Measured memory_bytes: 1160
// hhttps://atcoder.jp/contests/apg4b/tasks/APG4b_ca
// g++ -std=c++11 ex22.cpp && ./a.out
#include <vector>
#include <tuple>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdio>
#include <cmath>
#include <climits>

using namespace std;
#include <cstdint>
#include <iostream>

using namespace std;

// MOD (素数)
const int64_t MOD = 1000000007; // 10^9 + 7

struct Modint
{
    int64_t value;

    Modint(uint64_t value_ = 0)
    {
        value = value_ % MOD;
        value += value < 0 ? MOD : 0;
    }

    Modint operator-() const
    {
        return Modint(-value);
    }

    Modint &operator+=(const Modint n)
    {
        value += n.value;
        if (value >= MOD)
        {
            value -= MOD;
        }
        return *this;
    }
    Modint &operator-=(const Modint n)
    {
        value = value - n.value + MOD;
        if (value >= MOD)
        {
            value -= MOD;
        }
        return *this;
    }
    Modint &operator*=(const Modint n)
    {
        value = value * n.value % MOD;
        return *this;
    }
    Modint &operator/=(const Modint n)
    {
        *this *= n.inv();
        return *this;
    }

    Modint operator+(const Modint n) const
    {
        Modint ret(*this);
        ret += n;
        return ret;
    }
    Modint operator-(const Modint n) const
    {
        Modint ret(*this);
        ret -= n;
        return ret;
    }
    Modint operator*(const Modint n) const
    {
        Modint ret(*this);
        ret *= n;
        return ret;
    }
    Modint operator/(const Modint n) const
    {
        Modint ret(*this);
        ret /= n;
        return ret;
    }

    // mod MODにおける逆元を返す
    Modint inv() const
    {
        // 1 = inv(a) * a  (mod MOD) をみたすinv(a)を求める
        // フェルマーの小定理：
        //  1 = a ** (MOD - 1)  (mod MOD)
        //      (MOD: 素数, aとMODは互いに素)
        //  --> 1 = (a ** (MOD - 2)) * a  (mod MOD)
        //  --> inv(a) = a ** (MOD - 2)
        return this->pow(MOD - 2);
    }

    // expon乗した値を返す
    Modint pow(const int64_t expon) const
    {
        if (expon == 0)
        {
            return Modint(1);
        }
        Modint ret = this->pow(expon / 2);
        ret *= ret;
        if (expon % 2)
        {
            ret *= (*this);
        }
        return ret;
    }

    // 2項係数 (this, r) を返す
    // O(r)
    Modint comb(const int64_t r) const
    {
        Modint numer(1), denom(1);
        for (int64_t i = 0; i < r; i++)
        {
            numer *= value - i;
            denom *= i + 1;
        }
        return numer / denom;
    }
};

std::ostream &operator<<(std::ostream &stream, const Modint &modint)
{
    return stream << modint.value;
}

int main()
{
    int64_t n, a, b;
    cin >> n >> a >> b;

    // n種類からの花束の種類の総数
    // (0, 1) の2通りをn本なので
    // (2 ** n) - 1
    // -1は0本の花束
    Modint comb_all = Modint(2).pow(n) - 1;

    // x本からなる花束の種類の総数
    // nCx = n! / x! / (n - x)!

    // 求める種類の総数
    Modint ans = comb_all - Modint(n).comb(a) - Modint(n).comb(b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define ll long long
const int maxm=1e5+5;
int a[maxm];
int d[66];
int n;
void add(int x){
    for(int i=60;i>=0;i--){
        if(x>>i&1){
            if(d[i]){
                x^=d[i];
            }else{
                d[i]=x;
                break;
            }
        }
    }
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int sum=0;
    for(int i=1;i<=n;i++)sum^=a[i];
    for(int j=0;j<=60;j++){
        if(sum>>j&1){
            for(int i=1;i<=n;i++){
                if(a[i]>>j&1)a[i]^=(1LL<<j);
            }
        }
    }
    for(int i=1;i<=n;i++){
        add(a[i]);
    }
    int ans=0;
    for(int i=60;i>=0;i--){
        if((ans^d[i])>ans)ans^=d[i];
    }
    cout<<ans+(ans^sum)<<endl;
    return 0;
}


Measured memory_bytes: 4404
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()

typedef long long ll;

int dp[100][101];

bool bt(int n,int now,int *inp,int *vol);

set<ll> D[100];
bool distribute(int n,int now,int *inp,int *vol){
  if (vol[now] == 0)return bt(n,now+1,inp,vol);

  ll state = 0;
  REP(i,now,n){
    state=(state<<1);
    if (vol[i] == inp[i])state++;
  }
  
  if (D[now].find(state) != D[now].end())return false;
  D[now].insert(state);
  if (vol[now] == 0)return false;



  REP(i,now+1,n){
    if (vol[i] != 0)continue;
    if (vol[now]-inp[i] < 0)continue;
    if (i-1 >= now+1 && inp[i-1] == inp[i] && vol[i-1] == 0)continue;
    vol[now]-=inp[i];
    vol[i]=inp[i];
    if (distribute(n,now,inp,vol))return true;
    vol[i]=0;
    vol[now]+=inp[i];
  }
  return false;
}

set<ll> S[100];
bool bt(int n,int now,int *inp,int *vol){
  if (now == n){
    return true;
  }

  ll state = 0;
  REP(i,now,n){
    state=(state<<1);
    if (vol[i] == inp[i])state++;
  }
  
  if (S[now].find(state) != S[now].end())return false;
  S[now].insert(state);
  if (vol[now] == 0)return false;

  //through
  if (bt(n,now+1,inp,vol))return true;

  //distribute
  if (distribute(n,now,inp,vol))return true;
  return false;
}

main(){
  int n;
  while(cin>>n && n){
    int in[n];
    int vol[n];
    vector<int> a;
    rep(i,n){
      cin>>in[i];vol[i]=0;a.push_back(in[i]);
      S[i].clear();
      D[i].clear();
    }
    sort(in,in+n,greater<int>());
    sort(ALL(a));
    vol[0]=in[0];
    if (bt(n,0,in,vol) == true)puts("YES");
    else puts("NO");
  }
  return false;
}

Measured memory_bytes: 3344
#include<stdio.h>
#define N 100
int main()
{
  int r[N],c[N][N];
  int i,j,k,l,m,n;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d%d",&r[i],&j);
  
  r[n]=j;
  
  for(i=1;i<=n;i++){
    c[i][i]=0;
  }
   for(j=2;j<=n;j++){
    for(i=1;i<=n-j+1;i++){
      l =i+j-1;
      c[i][l]=10000000;
      for(k=i;k<=l-1;k++){
	
    m=c[i][k]+c[k+1][l]+(r[i-1]*r[k]*r[l]);
        
    if(c[i][l]>m) c[i][l]=m;
      }
    }
  }
  printf("%d\n",c[1][n]);
    
  return 0;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    int k, s, x, y;
    cin>>k>>s;
    int cnt = 0;
    for(x = 0; x<=k; x++){
        for(y = 0; y<=k; y++){
            if(s-(x+y) <= k && s-(x+y) >= 0)
                cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long[] val = new long[3*N];
		for(int i=0; i<3*N; i++){
			val[i] = sc.nextLong();
		}
		
		PriorityQueue<Long> pq1 = new PriorityQueue<>();
		long[] ans = new long[N+1];
		long sum=0;
		for(int i=0; i<N; i++){
			pq1.offer(val[i]);
			sum+=val[i];
		}
		ans[0] = sum;
		for(int i=N; i<2*N; i++){
			pq1.offer(val[i]);
			sum += val[i] - pq1.poll();
			ans[i-N+1] = sum;
		}
		
		PriorityQueue<Long> pq2 = new PriorityQueue<>(Collections.reverseOrder());
		sum=0;
		for(int i=3*N-1; i>=2*N; i--){
			pq2.offer(val[i]);
			sum+=val[i];
		}
		ans[N] -= sum;
		for(int i=2*N-1; i>=N; i--){
			pq2.offer(val[i]);
			sum += val[i] - pq2.poll();
			ans[i-N] -= sum;
		}
		Arrays.sort(ans);
		System.out.println(ans[N]);
		return;
	}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const ll inf = 1e9;
const ll MOD = 1e9 + 7;
const ll nax = 1000000 + 10;

ll n, arr[nax];

bool is(ll mid)
{
    ll temp = mid;
    for(ll i = 1; i <= n; i++)
    {
        ll tosub = (arr[i] + 1 + mid - n);
        if(tosub <= 0)
            continue;
        if((tosub % (1 + n)) == 0)
            tosub = (tosub / (1 + n));
        else
            tosub =  (tosub / (1 + n)) + 1;
        temp -= tosub;
    }
    if(temp >= 0) return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(ll i = 1; i <= n; i++)
        cin >> arr[i];
    ll l = 0, r = 5e17;
    while(r - l > 1)
    {
        ll mid = (r + l) / 2;
        if(is(mid) == true)
            r = mid;
        else
            l = mid;
    }
    ll cnt = 0;
    ll ans = l;
    if(is(l + 1))
        ans = l + 1;

    for(ll i = (l - 1); i >= 0 && cnt++ <= 100000; i--)
    {
        if(is(i))
            ans = min(ans, i);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //昇順
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順

int main(){
  string s;
  cin >> s;
  int count = 0;
  if (s.length()%2 == 0){
    int i = (s.length()/2) - 1;
    int v = i + 1;
    while (i >= 0){
      if(s[i] != s[v]){
        count += 1;
      }
      i -= 1;
      v += 1;
    }
  }else{
    int i = (s.length()/2) - 1;
    int v = i + 2;
    while (i >= 0){
      if(s[i] != s[v]){
        count += 1;
      }
      i -= 1;
      v += 1;
    }
  }
  cout << count << endl;
}

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

int main()
{
	int n;
	cin>>n;
	int arr[n+1];
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		arr[x]=i;
	}
	for(int i=1;i<=n;i++)
	cout<<arr[i]<<" ";
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main()
{
 int a,s;int sum=0;
  cin>>a>>s;
  if (a>s)
  {sum+=a;
   a--;
  }
else 
   {sum+=s;
   s--;
  }

  if (a>s)
  {sum+=a;
   a--;
  }
else 
   {sum+=s;
   s--;
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	if(N%2==0) cout << 0.5 << endl;
	else cout << setprecision(20) << (double)((N+1)/2)/N << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll N, M;
    scanf("%lld", &N);

    double ans = ((double)N * 2.) * acos(-1);


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

    return 0;

}

Measured memory_bytes: 3220
import java.io.*;

public class Main{
  public static void main(String... args) throws IOException {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String line = stdin.readLine();
    String[] in = line.split(" ");
    int n = Integer.parseInt(in[0]);
    System.err.println(n);
    int k = Integer.parseInt(in[1]);
    System.err.println(k);
    System.out.println(n-k+1);
  }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define ll 				long long
#define int             long long int
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }


void solve()
{
	int n;
	cin >> n;
	cout << ((n+999)/1000)*1000-n;
}
 
int32_t main()
{
	FIO
    //aks();
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3700
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

long long int psum[200001];
long long int p[200001];
int n, k;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n >> k;

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

	psum[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		psum[i] = psum[i - 1] + p[i];
	}

	int idx = 0;
	long long int Max = 0;

	for (int i = 1; i <= n; i++)
	{
		int r = i + k - 1;
		if (r > n)
		{
			break;
		}
		if (psum[r] - psum[i - 1] > Max)
		{
			Max = psum[r] - psum[i - 1];
			idx = i;
		}
	}

	double res = 0;

	for (int i = idx; i < idx + k; i++)
	{
		double e = (p[i] * (p[i] + 1)) / 2;
		e /= p[i];
		res += e;
	}

	cout << fixed;
	cout.precision(16);
	
	cout << res << '\n';

	return 0;
}


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

using namespace std;

int N;

int main() {
	
	scanf("%d", &N);
	
	for (int i = 0; i <= 100; i++)
		for (int j = 0; j <= 100; j++)
			if (i * 4 + j * 7 == N) {
				printf("Yes\n");
				return 0;
			}
	
	printf("No\n");
	
	return 0;
	
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select((s,i)=>int.Parse(s)-i-1).ToArray();
var b = a.OrderBy(x=>x).ElementAt(n/2);
Console.WriteLine(a.Sum(x=>(long)Math.Abs(x-b)));
}
}


Measured memory_bytes: 31492
W,H,N=map(int,input().split())

xl=0
xr=W
yu=H
yd=0

for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1 and xl<x:
        xl=x
    elif a==2 and xr>x:
        xr=x
    elif a==3 and yd<y:
        yd=y
    elif a==4 and yu>y:
        yu=y

print(max(0,(yu-yd))*max(0,(xr-xl)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int a,b;
  cin>>a>>b;
  if(13<=a) cout<<b<<endl;
  else if(6<=a&&a<=12) cout<<b/2<<endl;
  else if(a<=5) cout<<0<<endl;
return 0;
}

Measured memory_bytes: 3596
def resolve():
    h, w = map(int, input().split())
    d = []
    # d[u][v] : 辺uvのコスト(存在しないときはinf)
    for i in range(10):
        d.append(list(map(int, input().split())))
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    from scipy.sparse.csgraph import floyd_warshall
    cost = floyd_warshall(d)
    ans = 0
    for i in range(h):
        for j in map(int, input().split()):
            if j > -1:
                ans += cost[j][1]
    print("{:.0f}".format(ans))


resolve()


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=(ll)1e9+7;

int main(){
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    ll res1=A, res2=B;
    if(U == S) res1--;
    else res2--;
    cout << res1  << " " << res2 << endl;
    return 0;
}

Measured memory_bytes: 3588
def gcd(x,y):
	if x%y == 0:
		return y
	else:
		return gcd(y,x%y)
A,B,C,D = map(int, raw_input().split())
A = A-1
g = C*D/gcd(C,D)
data = [A/C,A/D,B/C,B/D,A/g,B/g]
print((B-A)-(data[2]+data[3]+data[4]-data[0]-data[1]-data[5]))

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int n;
    cin >> n;
    int p[n];
    rep(i,n) cin >> p[i];

    int ans=0;
    for(int i=1;i<n-1;i++){
        if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] &&p[i]>p[i+1])) ans++; 
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define DATA_SIZE 10

int pow(int num){
	if(num <= 1){
		return 1;
	}
	return num * pow(num - 1);
}

int main(){
	
	int sum[11][10001]; // sum[i][j]: n = i ?????¨??????????¨??????? j ??¨????????????????????°
	
	for(int i = 0; i < 11; i++){
		for(int j = 0; j < 10001; j++){
			sum[i][j] = 0;
		}
	}
	
	int a[DATA_SIZE];
	
	for(int i = 0; i < DATA_SIZE; i++){
		a[i] = i;
	}
	
	do{
		int p = 0;
		for(int i = 1; i <= 10; i++){
			p += i * a[i - 1];
			sum[i][p]++;
		}
	}while(next_permutation(a, a + DATA_SIZE));
	
	int n, s;
	
	while(true){
		cin >> n >> s;
		if(cin.eof()){
			break;
		}
		cout << sum[n][s] / pow(10 - n) << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3400
#include<stdio.h>
int main()
{
    int m,n,a[100000],b[100000],i,j,cnt=0,str[1000]={0},max=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        for(j=0;j<a[i];j++)
        {
            scanf("%d",&b[j]);
            str[b[j]]++;
            if(max<b[j])
                max=b[j];
        }
    }
    for(i=0;i<=max;i++)
    {
        if(str[i]==n)
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
ll h,n;
//ld ;
// string s,t;
// char c;
 
int main() {
  cin >> h >> n;
  ll sum = 0;
  for(int i=0;i<n ;i++){
    ll a;
    cin >> a;
    sum += a;
  }
  yorn(h <= sum);
}

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

const long long INF = 1LL << 60;
int MOD = 1000000007;
double PI = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define For(i,s,n) for (int i=s;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define vs vector<string>
#define All(c) (c).begin(), (c).end()
#define Print(x) cout<<(x)<<"\n"

int A, B, K;

int main() {
	cin >> A >> B >> K;
	rep(i, K) {
		if (i % 2 == 0) {
			A -= A % 2;
			A /= 2;
			B += A;
		}
		if (i % 2 == 1) {
			B -= B % 2;
			B /= 2;
			A += B;
		}
	}
	cout << A << ' ' << B << endl;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
v = []
w = []
for i in range(N):
    a, b = map(int, input().split())
    v.append(a)
    w.append(b)

dp = [[-1 for i in range(W+1)] for j in range(N+1)]

for i in range(W+1):
    dp[0][i] = 0

for i in range(N):
    for j in range(W+1):
        if j >= w[i]:
            dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])



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

using namespace std;

int a[100001];

int main()
{
	int n;
	cin>>n;
	for (int i = 0; i < n;i++)
		cin >> a[i+1];
	queue<pair<int,int>> que;
	que.push(pair<int, int>(1, 0));
	while(que.size())
	{
		pair<int, int> q = que.front();
		que.pop();
		if(q.first==2)
		{
			cout<< q.second<< endl;
			return 0;
		}
		if(a[q.first]!=-1)
		{
			que.push(pair<int, int>(a[q.first],q.second + 1));
			a[q.first] = -1;
		}
	}
	cout << "-1" << endl;

	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int c_0 = 0, c_1 = 0;
    int ans = 0;
    bool ok = true;
    while(ok){
        ok = false;
        if(s.size() < 2) continue;
        for(int i = 0;i < s.size()-1;i++){
            if(s[i] != s[i+1]){
                c_0--;
                c_1--;
                ans += 2;
                s.erase(i,2);
                //cout << s << endl;
                //cout << ans << endl;
                ok = true;
                break;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    static int n;
    static int w;
    static int[] weights;
    static int[] values;
    public static void solve() {
        n = in.nextInt();
        w = in.nextInt();

        weights = new int[n];
        values = new int[n];

        for(int i = 0; i < n; i += 1) {
            weights[i] = in.nextInt();
            values[i] = in.nextInt();
        }

        int v = 0;
        for(int value: values)
            v += value;

        long[][] store = new long[n][v+1];

        for(int j = 1; j <= v; j += 1){
            store[0][j] = values[0] == j ? weights[0] : Long.MAX_VALUE;
        }

        for(int i = 1; i < n; i += 1) {
            for(int j = 1; j <= v; j += 1) {
                store[i][j] = store[i-1][j];

                if(j-values[i] >= 0) {
                    if(store[i-1][j-values[i]] != Long.MAX_VALUE)
                        store[i][j] = Math.min(store[i][j], weights[i] + store[i-1][j-values[i]]);
                }
            }
        }
        int result = 0;
        for(int j = 1; j <= v; j += 1){
            if(store[n-1][j] <= w)
                result = Math.max(result, j);
        }
        out.println(result);
    }


    public static InputReader in = new InputReader();
    public static PrintWriter out;

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        /**
         * When you call next(), that entire line will be skipped.
         * No flushing buffers.
         * Doesn't work when you want to scan the remaining line.
         *
         * @return entire line
         */
        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
                tokenizer = null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }
}

Measured memory_bytes: 127188
#include <iostream>

using namespace std;

int main() {
    int sx, tx, sy, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i=0; i<ty-sy; i++) cout << "U";
    for (int i=0; i<tx-sx; i++) cout << "R";
    for (int i=0; i<ty-sy; i++) cout << "D";
    for (int i=0; i<tx-sx; i++) cout << "L";
    cout << "L";
    for (int i=0; i<ty-sy+1; i++) cout << "U";
    for (int i=0; i<tx-sx+1; i++) cout << "R";
    cout << "DR";
    for (int i=0; i<ty-sy+1; i++) cout << "D";
    for (int i=0; i<tx-sx+1; i++) cout << "L";
    cout << "U" << endl;
}


Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m;
    while(cin>>n,n!=0){
        int h[200],r[200];
        rep(i,n)cin>>r[i]>>h[i];
        int m;cin>>m;
        rep(i,m)cin>>r[n+i]>>h[n+i];
        vector<int>ord(n+m);
        rep(i,n+m)ord[i]=i;
        sort(ord.begin(),ord.end(),[&](int x,int y){return pint(r[x],-h[x])<pint(r[y],-h[y]);});
        int dp[222];
        rep(i,222)dp[i]=inf;
        dp[0]=0;
        for(auto i:ord){
            int idx=lower_bound(dp,dp+222,h[i])-dp;
            dp[idx]=h[i];
        }
        int ans=lower_bound(dp,dp+222,inf)-dp;
        cout<<ans-1<<endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
ll dp[100005];
int main()
{
    fio;
    ll n,l;
    cin>>n>>l;
    ll a[n];
    ll sum=0;
    ll neg=0,pos=0;
    rep(i,n)
    {
        a[i]=l+i;
        sum+=a[i];
        if(a[i]<0)
            neg++;
        else
            pos++;
    }
    sort(a,a+n);
   if(abs(a[neg-1])<a[neg])
        cout<<sum-a[neg-1];
    else
    cout<<sum-a[neg];
    return 0;
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;


// cur 桁目を決める(i>=0)
lli rec(lli n, lli &ans, lli cur, lli val, bool ok_3, bool ok_5, bool ok_7) {
    if (ok_3 && ok_5 && ok_7) {
        //cout3(ans, cur, val);
        ans++;
    }
    lli next;
    // cur 桁目が3
    next = val + 3*pow(10, cur);
    if (next > n) {
        return ans;
    }
    rec(n, ans, cur+1, next, true, ok_5, ok_7);

    // cur 桁目が5
    next = val + 5*pow(10, cur);
    if (next > n) {
        return ans;
    }
    rec(n, ans, cur+1, next, ok_3, true, ok_7);

    // cur 桁目が7
    next = val + 7*pow(10, cur);
    if (next > n) {
        return ans;
    }
    rec(n, ans, cur+1, next, ok_3, ok_5, true);
    return ans;
}

int main() {
    lli n;
    cin1(n);
    lli ans = 0;

    cout << rec(n, ans, 0, 0, false, false, false) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int main(){
  int S;
  int W;
  rd(S);
  rd(W);
  if(S <= W){
    wt_L("unsafe");
    wt_L('\n');
  }
  else{
    wt_L("safe");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200430-1

// --- original code ---
// {
//   int S, W;
//   rd(S, W);
//   wt(if[S <= W, "unsafe", "safe"]);
// }


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

using namespace std;

int main(){
	ll n,x,p,z,i,j;
	
	cin>>n;
	
	z=0;
	for(i=1;i<=n;i++){
		p=0;
		cin>>x;
		if(x>2 && x%2==0) p=1;
		for(j=3;j*j<=x;j+=2){
			if(x%j==0) p=1,j=x;
		}
		if(p==0) z++;
	}
	
	cout<<z<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define err(x) cout<<#x<<"= "<<x<<endl;
#define FOR(i,a,b) for(int i =a; i< b; ++i)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define INF 1000000000
#define TRVI(it,it1,it2) for(vi::iterator it = it1; it!= it2; it++)
#define ff first
#define ss second
#define mp make_pair
#define pq priority_queue<int, vector<int>, greater<int> >
#define ll long long
const ll PR = 1000000009;
#define SIZE 100009
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
int A[SIZE],n;
set<int> Wins[SIZE];
int depth[SIZE];
void dfs(int a){
	depth[a] = 0;
	int premax= 0;
	vector<int> hts;
	for(set<int>::iterator it = Wins[a].begin(); it!= Wins[a].end(); it++){
		int now = *it;
		dfs(now);
		hts.pb(depth[now]);
//		premax = max(depth[now],premax);
	}
	sort(hts.begin(),hts.end());
	int cnt = 1;
	for(int i = hts.size()-1; i>=0; i--){
		depth[a] = max(depth[a] , cnt+ hts[i]);//premax + Wins[a].size();
		cnt++;
	}
}


int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("a.in", "r" , stdin);
//	freopen("a.out", "w", stdout);
//      cin.tie(false); cout.tie(false);	
//	#endif
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i =1;i< n; i++){
		int a;
		cin>>a;a--;
		Wins[a].insert(i);
	}
	dfs(0);
//	for(int i =0; i< n; i++){
//		cout<<depth[i]<<' ';
//	}
	cout<<endl;
	cout<<depth[0]<<endl;

	return 0;
};

Measured memory_bytes: 17792
S=input()
def kai(s):
    if len(s)%2 == 0:
        if s[:int(len(s)/2)] == ''.join(list(reversed(s[int(len(s)/2):]))):
            return True
        else:
            return False

    else:
        if s[:int((len(s)-1)/2)] == ''.join(list(reversed(s[int((len(s)+1)/2):]))):
            return True
        else:
            return False

S1 = S[:int((len(S)-1)/2)]
S2 = S[int((len(S)+1)/2):]
if kai(S) & kai(S1) & kai(S2):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	string s;
	cin >> s;
	int ans = 0;
	for (char c : s) {
		if (c == '+')
			ans++;
		else
			ans--;
	}
	cout << ans << endl;
}

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

	solve();
}

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 = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		sc.close();

		if(N % (2 * D + 1) == 0) {
			System.out.println(N / (2 * D + 1));
		}else {
			System.out.println(N / (2 * D + 1) + 1);
		}

	}

}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define pb push_back
#define fi first
#define se second

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

const int mod = 998244353;
int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 105;

bool seen[MAXN];
int matchR[MAXN];

int n, m;
bool e[MAXN][MAXN];

bool f(int u) {
  REP(v, n) {
    if(!e[u][v] || seen[v]) continue;
    seen[v] = true;

    if(matchR[v] == -1 || f(matchR[v])) {
      matchR[v] = u;
      return true;
    }
  }
  return false;
}

int a[MAXN][MAXN];
int sol1[MAXN][MAXN];

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

  cin >> n >> m;
  REP(i, n) REP(j, m) {
    cin >> a[i][j];
    a[i][j] --;
  }

  REP(col, m) {
    memset(e, 0, sizeof e);
    REP(i, n) matchR[i] = -1;

    REP(i, n) REP(j, m) {
      if(a[i][j] != -1) {
        e[a[i][j] / m][i] = 1;
      }
    }

    REP(i, n) {
      memset(seen, 0, sizeof seen);
      f(i);
    }

    REP(i, n) REP(j, m) {
      if(a[i][j] != -1 && a[i][j] / m == matchR[i]) {
        sol1[i][col] = a[i][j];
        a[i][j] = -1;
        break;
      }
    }
  }

  REP(i, n) {
    REP(j, m) cout << sol1[i][j] + 1 << " ";
    cout << endl;
  }

  REP(i, n) {
    REP(j, m) {
      REP(k, n) {
        if(sol1[k][j] / m == i) cout << sol1[k][j] + 1 << " ";
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int b = in.nextInt();
		if (a <= 8 && b <= 8)
			System.out.println("Yay!");
		else
			System.out.println(":(");
		in.close();
	}
}

Measured memory_bytes: 19796
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int N;
vector<string> S;
void input() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        S.push_back(s);
    }
}
int solve() {
    input();
    int ans = 0;
    int a = 0, b = 0, ba = 0;
    for(auto s : S) {
        for(unsigned int i = 0; i < s.size() - 1; i++) {
            if(s.at(i) == 'A' && s.at(i+1) == 'B') ans++;
        }
        if(s.at(0) == 'B') b++;
        if(s.at(s.size()-1) == 'A') a++;
        if(s.at(0) == 'B' && s.at(s.size()-1) == 'A') ba++;
    }
    if(ba == 0) {
        return ans + min(a, b);
    }
    else if(a == b && b == ba) {
        return ans + a - 1;
    }
    else if(a == b) {
        return ans + a;
    }
    else {
        return ans + min(a, b);
    }
}
int main() {
    cout << solve() << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define MAX 2000000

class PriorityQueue{
  public:
  int size;
  int buffer[MAX+1];

  PriorityQueue(){
    size = 0;
  }

  
  void insert(int x){  
    size++;
    buffer[size] = x;
    upHeap(size); 
  }

  int get(){
    int v = buffer[1];
    buffer[1] = buffer[size];
    size--;
    downHeap(1);
    return v;
  }

  private:
  void upHeap(int cursor){   
    int parent;

    while(1){ 
      parent = cursor / 2;
      if( parent < 1 ) break;
      
      if( buffer[parent] < buffer[cursor] ){
	swap( buffer[parent],buffer[cursor]);
      }else break;

      cursor = parent;
    }
  }

  void downHeap( int cursor ){
    int child;

    while(1){
      if( cursor > size / 2 ) break;

      child = cursor * 2;
      if( child < size && buffer[child] < buffer[child+1]){
	child++;
      }

      if( buffer[cursor] < buffer[child] ){
	swap( buffer[cursor],buffer[child]);
      }else break;

      cursor = child;
    }
  }
};

int main(void){
  PriorityQueue PQ = PriorityQueue();
  int x;
  string command;

  while(1){
    cin >> command;

    if( command == "insert" ){
      cin >> x;
      PQ.insert(x);
    }else if(command == "extract" ){
      cout << PQ.get() << endl;
    }else break;
  }

  return 0;
}

Measured memory_bytes: 5700
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0
ans = "No"
for i in range(3):
    if a[i][0] + a[i][1] + a[i][2] == 0:
        ans = "Yes"
    elif a[0][i] + a[1][i] + a[2][i] ==0:
        ans = "Yes"
if a[0][0] + a[1][1] + a[2][2] ==0:
    ans = "Yes"
elif a[0][2] + a[1][1] + a[2][0] ==0:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;

int h, w;
char s[13][13];
char ns[13][13];

int p[13];
bool used[13];

bool finished;

void check(){
	for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
			ns[i][j] = s[i][p[j]];


	int cnt=0;
	int chk = 0;
	for(int i=1; i<=h; i++){
		if(chk & (1<<i)) continue;
		bool found=false;
		for(int j=i+1; j<=h; j++){
			if(chk & (1<<j)) continue;
			bool flag=true;
			for(int k=1, l=w; k<=w; k++, l--)
				if(ns[i][k] != ns[j][l]){
					flag=false;
					break;
				}
			if(flag){
				found=true;
				chk |= (1<<i);
				chk |= (1<<j);
				break;
			}
		}
		if(!found) cnt++;
		if((h%2==0 && cnt>0) || (h%2==1 && cnt>1)) return;
	}
	finished = true;
}

void backtrack(int now, int val, int cnt){
	for(int i=val+1; i<=w; i++){
		if(used[i]) continue;
		used[i]=true;
		p[now]=i;

		if(cnt == w){ /// end condition
			check();
		}
		else if(cnt&1) backtrack(w+1-now, i, cnt+1);
		else backtrack(w+2-now, 0, cnt+1);

		used[i]=false;

		if(finished) return;
	}
	return;
}

int main(){
	scanf("%d %d", &h, &w);
	for(int i=1; i<=h; i++){
		scanf("\n");
		for(int j=1; j<=w; j++)
			scanf("%c", &s[i][j]);
	}
	backtrack(1, 0, 1);
	puts(finished?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n;
	int i,sum,c,d;
	int j;
	
	while(1)
	{
		scanf("%d",&n);
		if(n==0)break;
		
		c = 0;
		for(i=1;i<=n/2+1;i++){
		  d = 0;
			sum = 0;
			j = i;
			while(sum<n)
			{
				sum += j;
				j++;
				d++;
			}
			if(sum == n && d > 1)c++;
		}
		
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int a[100005];
int b[100005];
bool used[100005];

bool comp(pair<int, int> a, pair<int, int> b)
{
	return a.first > b.first;
}

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

	vector<pair<int, int> > C;

	for (int i = 0;i < n;i++) {
		C.push_back(make_pair(a[i] + b[i], i));
	}

	sort(C.begin(), C.end(), comp);

	ll ans = 0;
	for (int i = 0;i < n;i++) {
		if (i % 2 == 0) {
			ans += (ll)a[C[i].second];
		}
		else {
			ans -= (ll)b[C[i].second];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2168
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10 , P = 1e9 + 7;
const ll inf = 2e18;
inline void pp(int &x,int d) {if((x+=d)>=P)x-=P;}
ll A , B , s[N];
int n;

struct Fenwick {
  int n , a[N];
  vector<pii> rec;
  void ini(int _n) {fill_n(a,(n=_n)+1,0);}
  void add(int x,int d) {rec.pb(mp(x,d));for(;x<=n;x+=x&-x)pp(a[x],d);}
  int sum(int x) {int r=0;for(;x>=1;x&=x-1)pp(r,a[x]);return r;}
  void clear() {
    for(auto e : rec)
      for(int x=e.fi;x<=n;x+=x&-x)
        pp(a[x],P-e.se);
    rec.clear();
  }
} f , g;

int main(){
  scanf("%d%lld%lld",&n,&A,&B);
  s[1] = s[2] = -inf;
  rep(i,3,3+n) scanf("%lld",s+i);
  f.ini(3+n);g.ini(3+n);
  f.add(1,1);
  rep(i,3,3+n) {
    // s[t] <= s[i] - B
    int t = upper_bound(s + 1 , s + i , s[i] - B) - s - 1;
    int addg = f.sum(t);
    t = upper_bound(s + 1 , s + i , s[i] - A) - s - 1;
    int addf = g.sum(t);
    if(s[i] - s[i-1] < A)
      f.clear();
    if(s[i] - s[i-1] < B)
      g.clear();
    f.add(i - 1 , addf);
    g.add(i - 1 , addg);
  }
  int ans = (f.sum(3+n)+g.sum(3+n))%P;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 3608