akhauriyash/Code-Regression huggingface dataset:
fn solve(s: String) -> Vec<usize> {
    let n = s.len();
    let mut v = vec![0; n];

    let mut acc = 0;
    for (i, c) in s.chars().enumerate() {
        if c == 'R' {
            acc += 1;
        } else {
            if acc == 0 {
                continue;
            }

            if acc % 2 == 0 {
                v[i - 1] += acc / 2;
                v[i] += acc / 2;
            } else {
                v[i - 1] += acc / 2 + 1;
                v[i] += acc / 2;
            }
            acc = 0;
        }
    }

    acc = 0;
    for (i, c) in s.chars().rev().enumerate() {
        if c == 'L' {
            acc += 1;
        } else {
            if acc == 0 {
                continue;
            }

            if acc % 2 == 0 {
                v[n - i] += acc / 2;
                v[n - 1 - i] += acc / 2;
            } else {
                v[n - i] += acc / 2 + 1;
                v[n - 1 - i] += acc / 2;
            }
            acc = 0;
        }
    }

    v
}

#[test]
fn solve_test() {
    assert_eq!(solve("RRLRL".to_owned()), vec![0, 1, 2, 1, 1]);
    assert_eq!(
        solve("RRLLLLRLRRLL".to_owned()),
        vec![0, 3, 3, 0, 0, 0, 1, 1, 0, 2, 2, 0]
    );
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    println!(
        "{}",
        solve(s)
            .iter()
            .map(|i| i.to_string())
            .collect::<Vec<String>>()
            .join(" ")
    );
}


Measured memory_bytes: 10620
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            a[i] = stdin.nextInt();
        }

        Map<Integer, Integer> map = new HashMap<>();
        int l = 0;
        int r = 0;
        for (int i = 0; i <= n; i++) {
            if (map.containsKey(a[i])) {
                l = map.get(a[i]);
                r = i;
                break;
            }
            map.put(a[i], i);
        }

        int m = 1000000007;
        for (int k = 1; k <= n + 1; k++) {
            int x = c(n + 1, k);
            int y = c(l + (n + 1 - r - 1), k - 1);
            System.out.println((x - y + m) % m);
        }

    }

    private static List<BigInteger> fct = new ArrayList<>();
    private static List<BigInteger> inv = new ArrayList<>();
    private static BigInteger mod = BigInteger.valueOf(1000000007);
    private static int c(int n, int r) {
        if (n < r) {
            return 0;
        }

        if (fct.isEmpty()) {
            fct.add(BigInteger.ONE);
            inv.add(fct.get(0).modInverse(mod));
        }

        for (int i = fct.size(); i <= n; i++) {
            fct.add(fct.get(i - 1).multiply(BigInteger.valueOf(i)).mod(mod));
            inv.add(fct.get(i).modInverse(mod));
        }

        return fct.get(n).multiply(inv.get(n - r).multiply(inv.get(r)).mod(mod)).mod(mod).intValue();
    }
}


Measured memory_bytes: 112988
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>


using namespace std;

int main() {

	long long int n;
	cin >> n;

	vector<long long int> a(n);

	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= (i + 1);
	}

	sort(a.begin(), a.end());
	long long int l = a[0];
	long long int r = a[n - 1];
	/*
	for (long long int i = l; i <= r; i++) {
		long long int ka = 0;
		for (long long int j = 0; j < n; j++) {
			ka += abs(a[j] - i);
		}
		cout << i << ' ' << ka << endl;
	}
	*/
	while (r - l > 2) {
		//cout << l << ' ' << r << endl;
		long long int dd = (r - l) / 3;
		long long int m1, m2;
		m1 = l + dd;
		m2 = r - dd;
		long long int kl, kr;
		kl = kr = 0;
		for (long long int i = 0; i < n; i++) {
			kl += abs(a[i] - m1);
			kr += abs(a[i] - m2);
		}
		if (kl >= kr) {
			l = m1;
		}
		else {
			r = m2;
		}
	}

	long long int MIN = -1;

	for (long long int i = l; i <= r; i++) {
		long long int ka = 0;
		for (long long int j = 0; j < n; j++) {
			ka += abs(a[j] - i);
		}
		if (MIN == -1) {
			MIN = ka;
		}
		else {
			MIN = min(MIN, ka);
		}
			
	}
	
	cout << MIN << endl;

	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

void inorder(Node);
void prerder(Node);
void insert(int);
Node treeSearch(Node, int);

Node root = NIL;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if( y == NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else y->right = z;
}

void inorder(Node u){
  if( u->left != NIL ){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if( u->right != NIL ){
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if( u->left != NIL ){
    preorder(u->left);
  }
  if( u->right != NIL ){
    preorder(u->right);
  }
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

int main(void){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d",&x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  return 0;
}

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

using namespace std;

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

	vector<int> L(2 * N);

	for (auto&& Li : L) {
		cin >> Li;
	}

	sort(L.begin(), L.end());

	int ans = 0;

	for (int i = 0; i < 2 * N - 1; i += 2) {
		int l1 = L[i];
		int l2 = L[i + 1];

		ans += min(l1, l2);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  vector<string> t = {"dream", "dreamer", "erase", "eraser"};
  ll n = SZ(s);
  vector<bool> dp(n + 1, false);
  dp[0] = true;
  REP(i, n) REP(j, 4) {
    if (!dp[i]) {
      continue;
    }
    if (i + SZ(t[j]) > n) {
      continue;
    }
    if (s.substr(i, SZ(t[j])) == t[j]) {
      dp[i + SZ(t[j])] = true;
    }
  }
  cout << (dp[n] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

using V = vector<int>;
struct P {int a, b;};

bool f(int i, V &m, P c) {
	if (!(c.a || c.b))
		return true;
	while (!m[i])
		i++;
	bool r = false;
	if (c.a && m[i] >= 3) {
		m[i] -= 3, c.a--;
		r = f(i, m, c);
		m[i] += 3, c.a++;
		if (r)
			return true;
	}
	if (c.a && i < 8 && m[i] && m[i + 1] && m[i + 2]) {
		m[i]--, m[i + 1]--, m[i + 2]--, c.a--;
		r = f(i, m, c);
		m[i]++, m[i + 1]++, m[i + 2]++, c.a++;
		if (r)
			return true;
	}
	if (c.b && m[i] >= 2) {
		m[i] -= 2, c.b--;
		r = f(i, m, c);
		m[i] += 2, c.b++;
		if (r)
			return true;
	}
	return r;
}

int main() {
	for (string s; scan(s);) {
		V m(9), r;
		for (int c: s)
			m[c - '0' - 1]++;
		for (int i = 0; i < 9; i++)
			if (m[i] < 4) {
				m[i]++;
				if (f(0, m, P{4, 1}))
					r.push_back(i + 1);
				m[i]--;
			}
		if (r.size())
			out(r);
		else
			outl(0);
	}
}


Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
string s,s1="CF";
long long c,f,t=0;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==s1[t]){
			t++;
			if(t==2)
				break;
		}
	if(t==2)
		cout<<"Yes";
	else
		cout<<"No";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    if(s.at(0) == s.at(1) && s.at(1) == s.at(2)){
        cout << "Yes" << endl;
    }
    else if(s.at(1) == s.at(2) && s.at(2) == s.at(3)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
in_list = [int(w) for w in input().split()]
p_li = tuple(in_list)
q_li = tuple([int(w) for w in input().split()])


permu = permutations(sorted(in_list))

p_in = 0
q_in = 0

for i, p in enumerate(permu):
    if p == p_li:
        p_in = i
    if p == q_li:
        q_in = i

print(abs(p_in-q_in))


Measured memory_bytes: 9188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int n; cin >> n;

    vector<vector<ll>> dp(n, vector<ll>(4));
    dp[0][0] = 8; dp[0][1] = 1; dp[0][2] = 1;

    rept(i, 1, n){
        dp[i][0] = (dp[i-1][0] * 8) % MOD;
        dp[i][1] = (((dp[i-1][1] * 9) % MOD) + dp[i-1][0]) % MOD;
        dp[i][2] = (((dp[i-1][2] * 9) % MOD) + dp[i-1][0]) % MOD;
        dp[i][3] = (((dp[i-1][1] + dp[i-1][2]) % MOD) + (dp[i-1][3] * 10 % MOD)) % MOD;
    } 

    cout << dp[n-1][3] % MOD << ln;
}



Measured memory_bytes: 73348
#include<cstdio>
const int N=233,md=998244353;
struct point{
	int x,y;
	inline point operator-(const point&rhs)const{return(point){x-rhs.x,y-rhs.y};}
}a[N];
inline int cross(point a,point b){return a.x*b.y-a.y*b.x;}
int n,p2[N],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i].x,&a[i].y);
	for(int i=*p2=1;i<=n;++i)p2[i]=p2[i-1]*2%md;
	ans=(p2[n]-n-1LL-n*(n-1LL)/2%md+md*4LL)%md;
	for(int i=1;i<n;++i)
		for(int j=i+1;j<=n;++j){
			int x=0;
			for(int k=j+1;k<=n;++k)
				x+=!cross(a[j]-a[i],a[k]-a[i]);
			ans=(ans-p2[x]+1+md)%md;
		}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    int dp[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>dp[i][j];
    }
    
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]+=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

string S;
int N;

int main(){
  cin>>S;
  N=S.size();

  ll ans=0;
  int now=0;
  bool op=false;
  for(int i=0;i<N-2;i++){
    if(op){
      if(S[i+1]=='B'&&S[i+2]=='C'){
        ans+=now;
        i++;
      }else if(S[i+1]=='A'){
        now++;
      } else{
        op=false;
        now=0;
      }
    }else{
      if(S[i]=='A') now++;
      else now=0;

      if(S[i+1]=='B'&&S[i+2]=='C'){
        op=true;
        ans+=now;
        i++;
      }else if(S[i+1]!='A') now=0;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n;
	int d1, d2;
	int count=0;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d1 >> d2;
		if (d1 == d2) count++;
		else count = 0;
		if (count == 3) {
			cout << "Yes";
			exit(0);
		}
	}

	cout << "No";
	
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

class DisjointSet {
    public:
    vector<int> rank, p;
    
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++) makeSet(i);
    }
    
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }
    
    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
            rank[y]++;
            }
        }
    }
    
    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main() {
    int n, a, b, q;
    int t;
    
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    
    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;
        if (t == 0) ds.unite(a, b);
        else if (t == 1) {
            if (ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int d,t,s;
	cin>>d>>t>>s;
	cout<<(s*t>=d?"Yes":"No")<<endl; 
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
    static const int AbnormalValueMin = 1;
    static const int AbnormalValueMax = 100;
    int num;
    std::cin >> num;
    assert(AbnormalValueMin <= num && num <= AbnormalValueMax); /* Abnormal value */
    std::cout << num*num*num << std::endl;
    return 0;
}

Measured memory_bytes: 3080
/**
 *     author: qodjf
 *     created: 05.03.2020 02:41:10
 */
#include <iostream>
using namespace std;

#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

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

  int N, M;
  cin >> N >> M;

  int half = (N - 1) / 2;
  int l = 1, r = half + 1;
  int cnt = 0;
  while (l < r) {
    cout << l << ' ' << r << endl;
    if (++cnt >= M) return 0;
    l++;
    r--;
  }

  l = half + 2, r = l + half - 1;
  while (l < r) {
    cout << l << ' ' << r << endl;
    if (++cnt >= M) return 0;
    l++;
    r--;
  }
}


Measured memory_bytes: 3200
n = int(input())
a = list(map(int, input().split()))

xs = [0] * (max(a) + 1)

for v in a:
    if xs[v] == 0:
        for j in range(v, len(xs), v):
            xs[j] += 1
    else:
        xs[v] += 1
print(len(list(filter(lambda v: xs[v] == 1, a))))


Measured memory_bytes: 32188
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    string S, T; cin >> S >> T;
    REP(i, N){
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX;
const long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll P = 1e9 + 7;
	//const ll P = 998244353;

	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
	priority_queue<vector<ll>> pq;
	for (ll i = 0; i < n; i++) pq.push({a[i] + b[i], i});
	ll ans = 0;
	while (pq.size()) {
		ll i = pq.top()[1];
		pq.pop();
		ans += a[i];
		if (pq.empty()) break;
		i = pq.top()[1];
		pq.pop();
		ans -= b[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 10284
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int N;
double p,a,b,c,d,e,f,s,m,ef;
string l;

int main(){
	while(cin>>N){
		if(!N)return 0;
		pair<double,string> pa[50];
		for(int i=0;i<N;i++){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			ef=-1*((f*s*m)-p)/(a+b+c+(d+e)*m);
			pa[i]=make_pair(ef,l);
		}
		sort(pa,pa+N);
		for(int i=0;i<N;i++)cout<<pa[i].second<<endl;
		cout<<"#"<<endl;
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

vector<long long int>t;
int n;
long long int ans;
void R(vector<long long int>a) {
    if (a.size() >= n) {
        int d = 1;
        for (int i = 0; i < a.size(); i++) {
            if (a[i] % 2 == 0) {
                d = 0;
            }
                
        //    cout << a[i] << " ";
            
            
        } if (!d)ans++;
      //  cout<<d <<" "<<ans<< endl;
       
        return;

    }int i = a.size();
    
    a.push_back(t[i]); R(a);
    a[i] = t[i] - 1; R(a);
    a[i] = t[i ]+ 1; R(a);

}

int main()
{

    cin >> n;
    vector<long long int>a(n),b;
    t = a;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    ans = 0;
    R(b);
    cout << ans << endl;


    return 0;

}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var z = Array.ConvertAll(line, int.Parse);
            if (z[0] == 0 && z[1] == 0 && z[2] == 0) break;
            Array.Sort(z);
            var a = z[1] * z[1] / 4d;
            var b = z[0] * z[0] / 4d;
            var n = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < n; i++)
            {
                var r = int.Parse(Console.ReadLine().Trim());
                var r2 = r * r;
                Console.WriteLine(r2 - a > b ? "OK" : "NA");
            }
        }
    }
}

Measured memory_bytes: 9060
import bisect
N = int(input())
D = [0]*12
SD = [0]*12
tmp = 26
for i in range(1, 12):
    D[i] = tmp
    SD[i] = SD[i-1] + D[i]
    if SD[i] > 1000000000000001:
        break
    tmp *= 26


L = bisect.bisect_left(SD, N)
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = []
N -= SD[L-1] + 1
for i in range(L):
    ans.append(alpha[N % 26])
    N //= 26


print("".join(ans[::-1]))


Measured memory_bytes: 9200
#include<stdio.h>
#include<string.h>

int main(){
	char str[10001];
	int i;
	int aj=0,ai=0;
	while(~scanf("%s",str)){
		aj=ai=0;
		for(i=0;i<strlen(str);i++){
			if(strstr(&str[i],"JOI")!=NULL){
				aj++;
				i=(strstr(&str[i],"JOI")-str);
			}
		}
		for(i=0;i<strlen(str);i++){
			if(strstr(&str[i],"IOI")!=NULL){
				ai++;
				i=(strstr(&str[i],"IOI")-str);
			}
		}
		printf("%d\n%d\n",aj,ai);
	}
	return 0;
}

Measured memory_bytes: 560
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: usize,
        b: usize,
    }
    let ans = std::cmp::min(n * a, b);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;
ll get_xor_one_to_n(ll n)
{
    if (n % 4 == 0)
        return n;
    if (n % 4 == 1)
        return 1;
    if (n % 4 == 2)
        return n + 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll a, b;
    cin >> a >> b;
    ll ans = get_xor_one_to_n(a - 1) ^ get_xor_one_to_n(b);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


typedef std::pair<int, int> pii;


long long calc(const std::vector<pii>& ranges)
{
  long long d = 0;

  int x = 0, size = ranges.size();

  bool used[111111] = {0};

  std::priority_queue<pii, std::vector<pii>, std::less   <pii>> lpq;
  std::priority_queue<pii, std::vector<pii>, std::greater<pii>> rpq;
  

  for (int i = 0; i < size; i ++) {
    const pii& range = ranges[i];

    lpq.emplace(range.first,  i);
    rpq.emplace(range.second, i);
  }

  // Firstly, move toward right!

  while (1) {
    pii l = lpq.top(); lpq.pop();

    while (used[l.second]) {
      if (lpq.empty())
        goto endloop;
      
      l = lpq.top(); lpq.pop();
    }

    if (x < l.first) {
      d += l.first - x;

      x = l.first;
    }
    else if (x > ranges[l.second].second){
      d += x - ranges[l.second].second;

      x = ranges[l.second].second;
    }
    else {
      assert(ranges[l.second].first <= x && x <= ranges[l.second].second);
    }

    used[l.second] = true;

    pii r = rpq.top(); rpq.pop();

    while (used[r.second]) {
      if (rpq.empty())
        goto endloop;
      
      r = rpq.top(); rpq.pop();
    }

    if (x > r.first) {
      d += x - r.first;

      x = r.first;
    }
    else if (x < ranges[r.second].first){
      d += ranges[r.second].first - x;

      x = ranges[r.second].first;
    }
    else {
      assert(ranges[r.second].first <= x && x <= ranges[r.second].second);
    }

    used[r.second] = true;
  }

endloop:
  
  return d + std::abs(x);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::vector<std::pair<int, int>> ranges(N);

  for (auto& range : ranges)
    std::cin >> range.first >> range.second;

  int x = 0;

  long long d1 = calc(ranges);

  for (auto& range : ranges) {
    range.first  *= -1;
    range.second *= -1;

    std::swap(range.first, range.second);
  }

  long long d2 = calc(ranges);

  std::cout << std::max(d1, d2) << std::endl;

  return 0;
}


Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	a=a*100+b*10+c;
	if(a%4==0)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N; cin >> N;
    vector<int> A(N);
    vector<pair<int, int>> ops;
    for (auto&& i : A) cin >> i;
    auto m = min_element(A.begin(), A.end());
    auto M = max_element(A.begin(), A.end());
    if (abs(*m) <= abs(*M)) {
        int i = M - A.begin() + 1;
        ops.push_back(make_pair(2, i));
        ops.push_back(make_pair(2, i));
        for (i = 3; i <= N; i++) {
            ops.push_back(make_pair(i, i-1));
            ops.push_back(make_pair(i, i-1));
        }
    } else {
        int i = m - A.begin() + 1;
        ops.push_back(make_pair(N-1, i));
        ops.push_back(make_pair(N-1, i));
        for (i = N-2; i >= 1; i--) {
            ops.push_back(make_pair(i, i+1));
            ops.push_back(make_pair(i, i+1));
        }
    }
    cout << ops.size() << endl;
    for (const auto& op : ops) cout << op.second << ' ' << op.first << '\n';
    return 0;
}

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

ll n;
WeightedGraph<ll> g;
vl d;

void dfs(ll x,ll p=-1){
    for(auto &e:g[x]){
        if(e.to==p)continue;
        d[e.to]=d[x]+e.cost;
        dfs(e.to,x);
    }
}

void solve(){
    cin>>n;
    g=WeightedGraph<ll>(n);
    rep(i,n-1){
        ll u,v,w;cin>>u>>v>>w;
        g[u-1].emplace_back(v-1,w);
        g[v-1].emplace_back(u-1,w);
    }

    d=vl(n,INF);
    d[0]=0;
    dfs(0);

    rep(i,n)cout<<d[i]%2<<endl;
}

Measured memory_bytes: 9984
#include<iostream>
using namespace std;
using ll=long long;
int main(){
  ll a,b,n;
  cin>>n>>a>>b;
  ll rep,ans=0;
  ans=n/(a+b)*a;
  rep=n%(a+b);
  ans+=min(rep,a);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e5 + 10;
int N, K, H[MAX];

int main(void) {
    cin >> N >> K;
    REP(i, N) {
        cin >> H[i];
    }

    sort(H, H + N);
    reverse(H, H + N);

    LL ans = 0;
    REP(i, N) {
        if (i < K) {
            // ans++;
        } else {
            ans += H[i];
        }
    }

    cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Ad[N] = {0};
  for(int i = 0; i < N; i++) {
    Ad[A[i] - 1]++;
  }
  int count = 0;
  sort(Ad, Ad + N, greater<int>());
  for(int i = K; i < N; i++) {
    if(Ad[i]) {
      count += Ad[i];
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int k;
	cin >> k;
	ll ans = 0;
	repn(i, 1, k + 1) repn(j, 1, k + 1) repn(l, 1, k + 1){
		int g = gcd(i, j);
		g = gcd(g, l);
		ans += g;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3648
# coding: utf-8
import collections
import math

l = int(input())
st = []
for i in range(l):
    x = ''.join(sorted(input()))
    st.append(x)
c = collections.Counter(st)
cv = c.values()
sum = 0
for i in cv:
    if int(i) > 1:
        tm = 0
        for j in range(int(i)-1):
            tm = tm + int(i)-1-j
        sum = sum + tm

print(math.floor(sum))

Measured memory_bytes: 68696
#include<bits/stdc++.h>
using namespace std;
#define maxn 10010
typedef long long ll;
typedef long double ld;
const ll inF=1e18;
int a,b,c,d;
int main(){
    cin >> a >> b >> c >> d;
    while (a>0&&c>0) {
        c-=b;
        if (c<=0) {cout << "Yes";exit(0);}
        a-=d;
        if (a<=0) {cout << "No";exit(0);}
    }
}



Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<string> s(n); rep(i, n)cin >> s[i];
	int ans = 0;
	rep(i, n) {
		rep(j, s[i].size() - 1) {
			if (s[i][j] == 'A'&&s[i][j + 1] == 'B')ans++;
		}
	}
	int ab = 0, a = 0, b = 0;
	rep(i, n) {
		if (s[i][0] == 'B'&&s[i][s[i].size() - 1] == 'A')ab++;
		else if (s[i][0] == 'B')b++;
		else if (s[i][s[i].size() - 1] == 'A')a++;
	}
	if (ab == 0)cout << ans + min(a, b) << endl;
	else {
		if (a + b > 0)cout << ans + ab + min(a, b) << endl;
		else cout << ans + ab - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ARC066C();


#if 1
int main()
{
	ARC066C();
	fflush(stdout);
	return 0;
}
#endif

static void ARC066C()
{
	int N;
	getint(N);

	std::vector<int> an(N, 0);
	for (int i = 0; i < N; i++) {
		getint(an[i]);
	}

	int center = N / 2;
	bool even = !(N % 2);
	std::vector<LLONG> est(N, 0);
	for (int i = 0; i < N; i++) {
		est[center + (an[i] / 2)]++;
		if (an[i]) {
			est[center - (an[i] / 2) - even]++;
		}
	}

	LLONG ans = 1;
	for (int i = 0; i < center; i++) {
		if (est[i] < 2) ans = 0;
		ans = ans * est[i] % MOD_NUM;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ld=long double;
 
int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n],c[n-1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>b[i];
        sum+=b[i];
    }
    for(int i=1;i<=n-1;i++){
        cin>>c[i];
    }
    for(int i=1;i<n;i++){
        int t=a[i];
        if(t+1==a[i+1])
        {
            sum+=c[a[i]];
        }
    }
    cout<<sum;
    
    
    
    return 0;
}

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

int main(){
    int N;
    cin >> N;
     
    if(N % 10 == 3)
        cout << "bon" << endl;
    else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
        cout << "pon" << endl;
    else 
        cout << "hon" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 10000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vvll g(n,vll(n,0)) ;
	for(int i=0;i<m;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).at(b) = g.at(b).at(a) = 1 ;
	}
	vll num(n-1) ;
	ll ans = 0 ;
	for(int i=0;i<n-1;i++) num.at(i) = i+1 ;
	do{
		vll p(n) ;
		p.at(0) = 0 ;
		for(int i=0;i<n-1;i++){
			p.at(i+1) = num.at(i) ;
		}
		bool ok = true ;
		for(int i=0;i<n-1;i++){
			if(g.at(p.at(i)).at(p.at(i+1))) continue ;
			ok = false ;
		}
		ans += ok ;
	}while(next_permutation(num.begin(),num.end())) ;
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int main(){
	int N,K,R=0,k=0;
	scanf("%d%d",&N,&K);
	vector<int>v(N),b(K+1);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	int start=0,stop=0;
	for(;;){
		for(;stop<N&&k<K;stop++){
			if(v[stop]<=K&&++b[v[stop]]==1)k++;
		}
		if(k<K)break;
		for(;start<N&&k>=K;start++){
			if(!R||R>stop-start)R=stop-start;
			if(v[start]<=K&&!--b[v[start]])k--;
		}
	}
	printf("%d\n",R);
}

Measured memory_bytes: 3160
#include <stdio.h>

int main(void)
{
	int A[100], i, j, k, N, key;

	scanf("%d", &N);

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

	for (i = 0; i < N; i++) {
		key = A[i];
		j = i - 1;
		while (j >= 0&&A[j]>key) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;

		for (k = 0; k < N; k++)
			printf("%d%c", A[k], (k == N - 1) ? '\n' : ' ');
	}

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second

const int MAXN = 100, MAXW = 10e5 + 10;
ll dp[MAXN][MAXW];

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

    vector<pii> obj(N);

    for(int i=0; i<N; i++) cin >> obj[i].F >> obj[i].S;

    /// initialize the table
    for(int j=0; j<=W; j++) dp[0][j] = (j >= obj[0].F) ? obj[0].S : 0;

    for(int i=1; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j < obj[i].F) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-obj[i].F] + obj[i].S);
        }
    }

    cout << dp[N-1][W] << "\n";
}

Measured memory_bytes: 285696
N = int(input())
Si = [input() for i in range(N)]

r = {}
c = 0
for s in Si:
    if not s in r:
        r[s] = 0
    r[s] += 1 
    if r[s] > c:
        c = r[s]

aa = [k for k, u in r.items() if u == c] 
aa.sort()
for a in aa :
    print(a)
    


Measured memory_bytes: 35220
while True:
    n,x=map(int,input().split())
    if n+x==0: break
    ans=0
    for i in range(1,n+1):
        for j in range(i+1,n):
            k=x-i-j
            if i<j<k<=n and i+j+k==x: ans+=1
    print(ans)



Measured memory_bytes: 5592
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int H = intArray[0];
            int A = intArray[1];
            if(H % A == 0)
            {
                Console.WriteLine(H / A);
            }
            else
            {
                Console.WriteLine(H / A +1);
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var AB = int.Parse(inputs[0]);
        var BC = int.Parse(inputs[1]);
        var CA = int.Parse(inputs[2]);

        Console.WriteLine(AB * BC / 2);
    }

}



Measured memory_bytes: 13140