akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	N := ReadInt()
	D := ReadInts(N)
	M := ReadInt()
	T := ReadInts(M)

	m := make(map[int]int)
	for i := 0; i < N; i++ {
		m[D[i]]++
	}

	for i := 0; i < M; i++ {
		if m[T[i]] == 0 {
			fmt.Println("NO")
			return
		}
		m[T[i]]--
	}
	fmt.Println("YES")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 17056
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
	Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
	let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
	    .skip_while(|c| c.is_whitespace())
	    .take_while(|c| !c.is_whitespace())
	    .collect::<String>();
	token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
	self.read1().unwrap()
    }
}

#[derive(Clone, Debug)]
enum State {
    White,
    Black,
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let (h,w): (usize, usize) = (sc.read(), sc.read());
    let mut f = vec![Vec::new(); h];
    for i in 0..h {
	let line : String = sc.read();
	for c in line.chars() {
	    f[i].push(match c {
		'#' => State::Black,
		'.' => State::White,
		_ => panic!(""),
	    });
	}
    }
    let mut cost_table = vec![vec![0usize; w]; h];
    cost_table[0][0] = match f[0][0] {
	State::Black => 1,
	State::White => 0,
    };

    for i in (0..h) {
	for j in (0..w) {
	    if i == 0 && j == 0 { continue; }
	    cost_table[i][j] = std::cmp::min(
		if let Some(above) = i.checked_sub(1) {
		    cost_table[above][j] + match (&f[above][j], &f[i][j]) {
			(&State::White, &State::Black) => 1,
			_ => 0,
		    }
		} else { usize::max_value() },
		if let Some(right) = j.checked_sub(1) {
		    cost_table[i][right] + match (&f[i][right], &f[i][j]) {
			(&State::White, &State::Black) => 1,
			_ => 0,
		    }
		} else { usize::max_value() }
	    );
	}
    }

    //for i in cost_table {
    //    for j in i {
    //        print!("{}",j);
    //    }
    //    println!("");
    //}
    println!("{}", cost_table[h-1][w-1]);
}



Measured memory_bytes: 4352
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n, p[30];
	cin >> n;
	rep(i, n)cin >> p[i];
	int ans = 0;
	REP(i, n - 2) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1])ans++;
		if (p[i - 1] > p[i] && p[i] > p[i + 1])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Main {
    static final ByteBuffer buf = ByteBuffer.allocate(1000000);
    static final ReadableByteChannel in = Channels.newChannel(System.in);
    static final int NAME = 0;
    static final int T = 1;// top;
    static final int B = 2;// Bottom;
    static final int L = 3;// left;
    static final int R = 4;// right;
    static final int UNDERS = 5;

    public static void main(String[] args) throws IOException {
	init();
	int n = getInt();
	for (int i = 0; i < n; i++) {
	    int h = getInt();
	    int w = getInt();
	    byte[][] box = new byte[h][w];
	    int[][] item = new int[7][6];
	    int count = 0;
	    for (int y = 0; y < h; y++) {
		getLine(box[y]);
		for (int x = 0; x < w; x++) {
		    final byte c = box[y][x];
		    if (c != '.') {
			for (int k = 0; k < 7; k++) {
			    if (item[k][NAME] == 0) {
				item[k][NAME] = c;
				item[k][T] = item[k][B] = y;
				item[k][L] = item[k][R] = x;
				count++;
				break;
			    } else if (item[k][NAME] == c) {
				if (item[k][B] != y) {
				    item[k][B] = y;
				}
				if (x < item[k][L]) {
				    item[k][L] = x;
				} else if (item[k][R] < x) {
				    item[k][R] = x;
				}
				break;
			    }
			}
		    }
		}
	    }
	    boolean isSUSPICIOUS = false;
	    for (int num = 0; !isSUSPICIOUS && num < count; num++) {
		for (int y = item[num][T]; !isSUSPICIOUS && y <= item[num][B]; y++) {
		    for (int x = item[num][L]; !isSUSPICIOUS
			    && x <= item[num][R]; x++) {
			final byte parts = box[y][x];
			if (parts != item[num][NAME]) {
			    if (parts == '.') {
				isSUSPICIOUS = true;
			    } else {
				int partsNum;
				for (int j = 0; j < count; j++) {
				    if (item[j][0] == parts) {
					partsNum = j;
					isSUSPICIOUS = !setUnders(item, partsNum,
						num);
					break;
				    }
				}
			    }

			}
		    }
		}
	    }
	    System.out.println(isSUSPICIOUS?"SUSPICIOUS":"SAFE");

	}

    }

    private static boolean setUnders(int[][] item, int upperNum, int underNum) {
	if (underNum == upperNum) {
	    return false;
	}
	for (int i = 0; i < 7; i++) {
	    if ((item[underNum][UNDERS] & getLayer(i)) != 0) {
		if (!setUnders(item, upperNum, i)) {
		    return false;
		}
	    }
	}
	item[upperNum][UNDERS] |= getLayer(underNum);
	return true;
    }

    static int getLayer(int i) {
	return 1 << i;
    }

    static void init() throws IOException {
	buf.clear();
	in.read(buf);
	buf.flip();
    }

    static int getInt() {
	byte b = buf.get();
	while (b < '0' || '9' < b) {
	    b = buf.get();
	}
	int result = 0;
	while ('0' <= b && b <= '9') {
	    result = result * 10 + (b - '0');
	    b = buf.get();
	}
	return result;
    }

    static void getLine(byte[] array) {
	byte b = buf.get();
	while (b != '.' && (b < 'A' || 'Z' < b)) {
	    b = buf.get();
	}
	buf.position(buf.position() - 1);
	buf.get(array);
    }
}

Measured memory_bytes: 30700
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
S=sum(A)
DivS=set()
index=1
while(index*index<=S):
    if S%index==0:
        DivS.add(index)
        DivS.add(S//index)
    index+=1
#print(DivS)
ans=1
for d in DivS:
    B=[A[i] for i in range(N)]
    for i in range(N):
        if A[i]%d==0:
            continue
        #kd<A[i]<(k+1)d
        #k=A[i]//d
        tmp1=(A[i]//d)*d
        tmp2=tmp1+d
        if abs(tmp1-A[i])<=abs(tmp2-A[i]):
            B[i]=tmp1
        else:
            B[i]=tmp2
    nowsum=sum(B)
    #print(d,B)
    if nowsum!=S:
        C=sorted(range(N),key=lambda i:abs(A[i]-B[i]),reverse=True)
        if nowsum>S:
            k=0
            need=(nowsum-S)//d
            for i in C:
                if B[i]>A[i]:
                    B[i]-=d
                    k+=1
                if k>=need:
                    break
        if nowsum<S:
            k=0
            need=(S-nowsum)//d
            for i in C:
                if B[i]<A[i]:
                    B[i]+=d
                    k+=1
                if k>=need:
                    break
    #print(d,A,B)
    cost=sum([abs(A[i]-B[i]) for i in range(N)])
    if cost<=2*K:
        ans=max(ans,d)
print(ans)
    

Measured memory_bytes: 48348
n = int(input())
arr = list(map(int,input().split()))

for i in range(n):
    arr[i] = arr[i] - (i+1)

arr.sort()

if n % 2 == 1:
    num = arr[n // 2]
else:
    num = (arr[n // 2] + arr[n // 2 - 1]) / 2
    
ans = 0

for j in range(n):
    ans += abs(arr[j-1] - num)
    
print(int(ans))

Measured memory_bytes: 26180
data = input()
pos_list = list(map(int, data.split()))

if abs(pos_list[0] - pos_list[1]) > abs(pos_list[0] - pos_list[2]) and \
    (pos_list[0] - pos_list[1]) * (pos_list[0] - pos_list[2]) > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

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

	ll s = 100000;
	rep(i,0,n){
		s += double(s)*0.05;
		//cout << s << endl;
		if( s % 1000 ){
			s = s / 1000 * 1000 + 1000;
		}
		//cout << s << endl;
	}

	cout << s << endl;
	
	ret 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  ll n,m; cin>>n>>m;

  ll ans;
  ll mg=0;
  if(n>m/2){
    ans=m/2;
    // mg=(n-m/2)/2;
  }else{
    ans=n;
    mg=(m-2*n)/4;
  }
  ans+=mg;
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int k,n,a[200000]={};
	cin >> k>>n;
    int first;
    int hoge=0,huga=0;
    fori(n){
        cin>>hoge;
        if(i==0){
            first=hoge;
        }
        a[i]=hoge-huga;
        huga=hoge;
    }
    a[n]=k-hoge+first;
    sort(a,a+n+1,greater<int>());
    cout<<k-a[0];
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def main():
    H,W = ints_raw()
    DFST = [[-1 for i in range(W)]for i in range(H)]
    qu = deque()
    dirs = [[1,0,1],[0,1,1],[-1,0,1],[0,-1,1]]
    ans = 0
    for h in range(H):
        S = input()
        for w in range(W):
            if S[w]=="#":
                DFST[h][w]=0
                qu.append([h,w,0])
    while len(qu)!=0:
        cpos = qu.popleft()
        for dir in dirs:
            
            ny,nx,nt = [cpos[0]+dir[0],cpos[1]+dir[1],cpos[2]+dir[2]]
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if DFST[ny][nx]!=-1:
                continue
            DFST[ny][nx]=nt
            ans = max(ans,nt)
            qu.append([ny,nx,nt])
    return ans

print(main())


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

int main() {
	int n;

	while(std::cin >> n, n) {
		std::vector<int> v;
		for(int i = 0; i < n; i++) {
			int tmp;
			std::cin >> tmp;
			v.push_back(tmp);
		}

		std::sort(v.begin(), v.end());

		long long ans = 0;
		for(int i = 0, wait = 0; i < v.size(); i++) {
			ans += wait;
			wait += v[i];
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
char s[100001];
long long p=0,r=0,w=0,l=0;
int main()
{
    cin>>s;
    for (long long i=0;i<strlen(s);i++)
    {
        if (s[i]=='p')
        {
            if (p>=r)
            {
            l++;
            r++;
            }
            else
            p++;
        }
        if (s[i]=='g')
        {
            if (p<r)
            {
            p++;
            w++;
            }
            else
            r++;
        }
    }
    cout<<w-l<<endl;
    return 0; 
} 

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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    vector<ll> num(n+1,0);
    REP(i,n){
        cin >> a[i];
        num[a[i]]++;
    }
    ll def=0;
    REP(i,n){
        if(num[i]>=2){
            ll s = num[i]*(num[i]-1)/2;
            def += s;
        }
    }
    
    REP(i,n){
        if(num[a[i]]<=1){
            cout << def << endl;
        }else{
            cout << def-num[a[i]]+1 << endl;
        }
    }
}

Measured memory_bytes: 6416
s = input()
t = input()
if len(s) == len(t):
  a = 0
  for i in range(len(t)):
    if s[i] == t[i]:
      a+=1
  print(len(s)-a)
  exit(0)
g = []
for i in range(len(s)-len(t)):
  n = 0
  for j in range(len(t)):
    if s[i+j]==t[j]:
      n+=1
  g.append(len(t)-n)
print(min(g))

Measured memory_bytes: 9140
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
MOD = 10 ** 9 + 7

dp = [0] * (1 << N)
dp[0] = 1
for b in range(1, 1 << N):
    i = bin(b).count('1')
    for x in range(N):
        if (b >> x) & 1 and A[i - 1][x]:
            dp[b] += dp[b ^ (1 << x)]
    dp[b] %= MOD
print(dp[-1])


Measured memory_bytes: 57580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
int a[105][105],n,m,t,xx[100005];
int main()
{
	cin>>n>>m;
	int x=1,y=1;
	cin>>t;
	for(int i=1;i<=t;i++)
	xx[i]=read();
	for(int i=1;i<=t;i++)
	{
		for(int j=1;j<=xx[i];j++)
		{
			a[x][y]=i;
			if((x==n&&y%2==1)||(x==1&&y%2==0))
			{
				y++;
				if(y%2==0)
				x=n;
				else
				x=1;
			}
			else
			{
				if(y%2==0)
				x--;
				else
				x++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			printf("%d ",a[i][j]);
		}
		cout<<endl;
	}
}


Measured memory_bytes: 384
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long[] city = new long[6],
               capacity = new long[5];
        for(int i = 0; i < 5; i++){
            capacity[i] = sc.nextLong();
        }
        sc.close();
        city[0] = N;
        long time;
        int minIdx = minIdx(capacity);
        time = 5 + (N-1)/capacity[minIdx];       
        System.out.println(time);
    }
    public static int minIdx(long[] capa){
        int idx = 0;
        long min = capa[0];
        for(int i = 1; i < 5; i++){
            if(capa[i] < min){
                min = capa[i];
                idx = i;
            }
        }
        return idx;
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();

		double min = 1e9;
		int ans = 0;

		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			double tmp = Math.abs(a - (t - h * 0.006));
			if (min > tmp) {
				min = tmp;
				ans = i + 1;
			}
		}

		System.out.println(ans);
	}

}


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

int main(){
    int n;
    cin >> n;
    int x[n],tmp;
    for(int i = 0;i < n;i++)cin >> x[i];

    for(int i = 0;i < n-1;i++){
        for(int j = 0;j < n-i-1;j++){
            if(x[j] < x[j+1]){
                tmp = x[j];
                x[j] = x[j+1];
                x[j+1] = tmp;
            }
        }
    }
    int cnt = 1;
    for(int i=0;i<n-1;i++){
        if(x[i] > x[i+1])cnt++;
    }
    cout << cnt <<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a.at(i);
  int alice=0, bob=0;
  sort(a.begin(), a.end(), std::greater<int>());
  for (int i=0; i<N; i++) {
    if (i % 2 == 0) alice += a.at(i);
    else bob += a.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

const int MAX = 400010;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//main関数にCOMinit();を忘れない

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    COMinit();
    int n,k; cin>>n>>k;
    if(k==1){
        cout<<(n*(n-1))%MOD<<endl;
        return 0;
    }else if(n-1<=k) {
        cout << COM(2 * n - 1, n - 1) << endl;
        return 0;
    }else{
        ll ans=1ll;
        for (int i = 1; i <= k; ++i) {
            (ans+=(COM(n,i)*COM(n-1,n-i-1)))%=MOD;
        }
        cout<<ans<<endl;
    }
    return 0;

}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll r,d,x20,xi;
    while(cin>>r>>d>>x20){
        xi=x20;
        for(ll i=1;i<=10;i++){
            ll rslt=r*xi-d;
            cout<<rslt<<endl;
            xi=rslt;


        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

int main(){

    int n,k;
    cin>>n>>k;
    ll ans=0;
    if(k==0){
        cout<<(ll)n*n<<endl;
        return 0;
    }
    
    for(int i=k+1;i<=n;i++){
        
        ans+=(n/i)*(i-k)+max(0,n%i-k+1);
    }
    cout<<ans<<endl;
    
    
    
return 0;
}


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

using namespace std;

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

    vector<vector<int>> v(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            int x;
            cin >> x;
            v[i].push_back(x);
        }
    }

    int count = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int tmp = 0;
            for (int k = 0; k < d; ++k)
                tmp += (v[j][k] - v[i][k]) * (v[j][k] - v[i][k]);

            double dist = sqrt(tmp);
            if (dist == floor(dist))
                ++count;
        }
    }
    cout << count << '\n';
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();

		List<String> list = new ArrayList<String>();
		for (int i = 0 ; i < N; i++) {
			String s = scan.next();
			list.add(s);
		}
		scan.close();
		List<String> ans = new ArrayList<>(new HashSet<>(list));
		System.out.println(ans.size());
	}
}

Measured memory_bytes: 78780
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]

def solve() :
  cnt = Counter(D)
  one = []
  L1 = []
  for k, v in cnt.items() :
    if v >= 3 :
      return 0
    if v == 2 :
      L1.append(k)
      L1.append(24 - k)
    if v == 1 :
      one.append(k)

  ret = 0
  for i in range(1 << len(one)) :
    L2 = L1[::]
    for j in range(len(one)) :
      if i & 1 :
        L2.append(one[j])
      else :
        L2.append(24 - one[j])

      i >>= 1

    L2.append(0)
    L2.append(24)
    L2.sort()
    tmp = float('inf')
    for i in range(1, len(L2)) :
      tmp = min(tmp, L2[i] -  L2[i-1])
    if tmp != float('inf') :
      ret = max(ret, tmp)

  return ret

print(solve())

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

int main(){
    ios_base::sync_with_stdio(false);
    for(int i=0;i<1e6;i++){
        cerr<<"Wrong Answer"<<endl;  
    }
    long long x,y; cin>>x>>y;
    cout<<(x%y==0 ? -1 : x)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	char x, y;
	int A, B, C, D, E, F;
    A == 10, B == 11, C == 12, D == 13, E == 14, F == 15;
    scanf("%c %c", &x, &y);
    if(x > y)
    {
        printf(">\n");
    }
    else if(x < y)
	{
		printf("<\n");
	}
    else printf("=\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <climits>

using namespace std;
#define forn(x, n)         for (int x = 0; x < n; x++)
#define forr(x, n)         for (int x = n; x >= 0; x--)
#define for1(x, n)         for (int x = 1; x < n; x++)
#define fore(x, a, b, c)   for (int x = a; x <= b; x += c)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).rbegin(), container.rend()
#define sz(container)      (int) (container).size()
#define pb                 push_back
#define eb                 emplace_back
#define fi                 first
#define sc                 second

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define eprint(...) 0
#endif
template<class T> bool smin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool smax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int N = 10010;
int ans[N];

int main(void)
{
    memset(ans, 0, sizeof(ans));
    int n;
    scanf("%d", &n);
    const int mx = 1e4;
    for1(i, 101) for1(j, 101) for1(k, 101) {
        if (i * i + j * j + k * k + i * j + j * k + i * k <= mx)
            ++ans[i * i + j * j + k * k + i * j + j * k + i * k];
    }
    for1(i, n + 1) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 3756
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	int n;
	ll d;
	scanf("%d%lld",&n,&d);
	int ans = 0;
	for(int i=1; i<=n; ++i)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x*x + y*y <= d*d) ++ans;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

void calc(int x) {
  repI(i, -200, 200) {
    repI(j, -200, 200) {
      if (pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << endl;
        return;
      }
    }
  }
  return;
}

int main() {
  ll x;
  cin >> x;
  calc(x);

  return 0;
}


Measured memory_bytes: 4028
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;scanf("%d",&n);
	if(n<1200) printf("ABC\n");
	else if(n<2800) printf("ARC\n");
	else printf("AGC\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n;bool a[25][25];
int dp[5000000];
signed main(){
  cin>>n;
  rep(i,n)rep(j,n)cin>>a[i][j];
  dp[0] = 1;
  rep(bit, 1<<n){
    int cnt = 0;
    rep(i,n)if(bit&(1<<i))cnt++;
    rep(i,n){
      if(bit&(1<<i) && a[i][cnt-1]){
        dp[bit] = (dp[bit] + dp[bit & ~(1<<i)])%MOD;
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{ 
    string s1;
    string s2;
  cin>>s1>>s2;
  if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0])
     printf("YES");
  
  else
     printf("NO");
                
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;

  int a = 0;
  int z = s.size();

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
        a = i;
        break;
    }
  }

   for (int j = s.size() - 1; j >= 0; j--) {
    if (s[j] == 'Z') {
        z = j;
        break;
    }
  } 

  cout << z - a + 1 << endl;

}

Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))
min_abs = 1000000000000000000000000
for i in range(1, n):
  A[i] += A[i-1]

for i in range(0, n-1):
  abs_val = abs(A[-1] - (A[i] * 2))
  min_abs = min(min_abs, abs_val)
print(min_abs)

Measured memory_bytes: 76880
nd=input()
nn=nd.split()
n=int(nn[0])
d=int(nn[1])
x=[]
y=[]
for i in range(0,n):
  xy=input()
  xx=xy.split()
  x.append(int(xx[0]))
  y.append(int(xx[1]))

coucou=0
for i in range(0,n):
  dis=(((x[i])**2)+((y[i])**2))**(0.5)
  if dis <= d:
    coucou=coucou+1

print(coucou)

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

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

  vector<int> a(n), b(m);
  vector<ll> c(n+1), d(m+1);
  rep(i,n) cin >> a[i];
  rep(j,m) cin >> b[j];
  for (int i = 0; i < n; ++i) c[i+1] = c[i] + a[i];
  for (int i = 0; i < m; ++i) d[i+1] = d[i] + b[i];
  int ans = 0;
  int j = m;
  for (int i = 0; i <= n; ++i) {
    ll r = k-c[i];
    if (r < 0) break;
    while (r < d[j]) --j;
    ans = max(ans, i+j);
  }
  cout << ans << endl;
}

Measured memory_bytes: 7888
h = gets.to_i
w = gets.to_i
n = gets.to_i
total = 0
count = 0

if h <= w
  for i in 1..h do
    total += w
    if total >= n
      count = i
      print count
      break
    end
  end
else
  for i in 1..w do
    total += h
    if total >= n
      count = i
      print count
      break
    end
  end
end


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    map<ll, ll> mp;

    ll a[n];

    rep(i, n)
    {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll sum = 0;

    for (auto x : mp)
    {
        if (x.second <= 1)
            continue;
        sum += (x.second * (x.second - 1) / 2);
    }

    rep(i, n)
    {
        ll x = mp[a[i]];
        if (x <= 1)
            OP(sum);
        else
            OP(sum - (x * (x - 1) / 2) + (x - 1) * (x - 2) / 2);
    }

    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int n, x[9], y[9];
double s;
int main() {
	int i, j;
	cin >> n;
	for(i=0; i<n; i++) cin >> x[i] >> y[i];
	for(i=0; i<n; i++) for(j=i+1; j<n; j++) s += sqrt((x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]));
	printf("%.9f", s*2/n);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll x, y;
    cin >> x >> y;
    ll ans = 1;

    while (x * 2 <= y)
    {
        x += x;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,F[50],i;
  scanf("%d",&n);
  F[0] = 1;
  F[1] = 1;
  for(i = 2;i <= n;i++){
    F[i] = F[i-2] + F[i-1];
  }
  printf("%d\n",F[n]);
  return 0;
}



Measured memory_bytes: 2052
//Walking Takahashi 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int x,k,d;cin>>x>>k>>d;
    x=abs(x);
    int c = x%d;
    int v = abs(x%d-d);
    if(x/d>=k){
        cout<<x-d*k<<nnn;
        return 0;
    }
    k-=x/d;
    if(k%2){
        cout<<v<<nnn;
    }else{
        cout<<c<<nnn;
    }
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;
const long long MOD = 1000000007;

long long dat[2 * MAX_N - 1];

ll fact(ll n) {
	if (n == 1) return 1;
	if (n == 0) return 0;
	return n * fact(n - 1);
}

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

//ABC152

//D
int main(void) {
	ll n;
	cin >> n;
	vector<vector<ll>> c = vector<vector<ll>>(10, vector<ll>(10, 0));
	rep(i, 1, n+1) {
		string s = to_string(i);
		ll top = s[0] - '0';
		ll botom = s[s.size() - 1] - '0';
		c[top][botom]++;
	}
	ll ans = 0;
	rep(i, 1, 10) {
		rep(j, 1, 10) {
			ans += c[i][j] * c[j][i];
		}
	}
	cout << ans << endl;
}


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

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value/500; value%=500;
coins += value/100; value%=100;
coins += value/50; value%=50;
coins += value/10; value%=10;
coins += value/5; value%=5;
coins += value;
cout << coins << endl;
coins = 0;
}
return 0;
}

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

struct StPoint
{
  StPoint() :
    m_nTime(0), m_nXcrd(0), m_nYcrd(0)
  { }

  int m_nTime;
  int m_nXcrd;
  int m_nYcrd;
};

void fnInput(vector<int>& rvnNum)
{
  for (int& rnElm : rvnNum)
    cin >> rnElm;
}

int fnSameIntTimes(const vector<int>& cnrvnNum)
{
  auto itMaxNum = max_element(begin(cnrvnNum), end(cnrvnNum));

  int  nSum = 0;
  for (int nElm : cnrvnNum)
    nSum += nElm;

  int nSameIntTimes;
  if (*itMaxNum * 3 % 2 == nSum % 2)
    nSameIntTimes = (*itMaxNum * 3 - nSum) / 2;
  else
    nSameIntTimes = ((*itMaxNum + 1) * 3 - nSum) / 2;

  return nSameIntTimes;
}

int main()
{
  vector<int> vnNum(3);

  fnInput(vnNum);
  cout << fnSameIntTimes(vnNum) << endl;

  return 0;
}

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

using namespace std;

int main() {
  int N;
  string S, T;
  cin >> N;
  cin >> S >> T;
  string str = "";
  for (int i = 0; i < N; i++) {
    str += S[i];
    str += T[i];
  }
  cout << str << endl;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X, Y = MAP()

# 簡単のため大小関係を固定
X, Y = min(X, Y), max(X, Y)
# 偶奇が合ってるなら直接会いに行く
if X % 2 == Y % 2:
    ans = abs(X - Y) // 2
# 合わないなら、どっちかの端で調整してから向かう
else:
    cnt1 = abs(X - 1) + 1
    Y1 = Y - cnt1
    cnt2 = abs(Y - N) + 1
    X2 = X + cnt2
    ans = min(cnt1 + abs(1 - Y1) // 2, cnt2 + abs(N - X2) // 2)
print(ans)


Measured memory_bytes: 3192
#include <stdio.h>


void insertionSort(int A[], const int n, const int g, int *cnt)
{
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
            //cout << A[j+g] << "<-->" << A[j] << endl;
            A[j+g] = A[j];
            j = j - g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] =n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

   
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

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

  
    shellSort(A, n);

    return 0;
}


Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n;
    bool ans=false;
    string s,t,c;
    cin>>s>>t;
    n=s.size();
    c=s;
    for(i=0;i<n;i++)
    {
        if(c==t)
        {
            ans=true;
            cout<<"Yes"<<endl;
            break;
        }
        else
        {
            for(j=0;j<n;j++)
            {
                if(j==0)
                    c[j]=s[n-1];
                else
                    c[j]=s[j-1];
            }
        }
        s=c;
    }
    if(!ans)
        cout<<"No"<<endl;
}


Measured memory_bytes: 3404
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const int MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

int D[33][33];
int c[550][550];
int sum[3][33];
int main() {
    int N, C;
    cin >> N >> C;
    rep(i, C) rep(j, C) scanf("%d", D[i] + j);
    rep(i, N) rep(j, N) scanf("%d", c[i] + j);

    rep(color, C){
        rep(i, N) rep(j, N){
            if((i+j+2) % 3 == 0) sum[0][color] += D[c[i][j]-1][color];
            if((i+j+2) % 3 == 1) sum[1][color] += D[c[i][j]-1][color];
            if((i+j+2) % 3 == 2) sum[2][color] += D[c[i][j]-1][color];
        }
    }
    int ans = INF;
    rep(c0, C){
        rep(c1, C){
            if(c0 == c1) continue;
            rep(c2, C){
                if(c1 == c2 || c0 == c2) continue;
                chmin(ans, sum[0][c0]+sum[1][c1]+sum[2][c2]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    map<int,int>d,t;
    rep(i,n){
        int a; cin>>a;
        d[a]++;
    }
    int m;
    cin>>m;
    rep(i,m){
        int a; cin>>a;
        t[a]++;
    }
    for(auto&p:t){
        if(p.second>d[p.first]){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

int main() {
    while (1) {
        int i, j;
        char op;
        cin >> i >> op >> j;

        if (op == '+') {
            cout << i + j << endl;
        } else if (op == '-') {
            cout << i - j << endl;
        } else if (op == '*') {
            cout << i * j << endl;
        } else if (op == '/') {
            cout << i / j << endl;
        } else if (op == '?') {
            break;
        }
    }
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    int k;cin >>k;
    vector<int>p(n);
    for (int i = 0; i < n; ++i) {
        cin >>p[i];
    }
    sort(all(p));
    int sum=0;
    for (int i = 0; i < k; ++i) {
        sum+=p[i];
    }
    cout <<sum<<endl;
}


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

int main () {
  int N;
  cin >> N;
  int a[N*3];
  
  for (int i=0;i<N*3;++i) {
    cin >> a[i];
  }
  sort(a, a + (N*3), greater<int>());
  long sum = 0;
  for (int i=0;i<N;++i) {
    sum += a[2 * i + 1];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
int n;
  cin>>n;
  
  int cnt=0;
  int ea=0;
  int be=0;
  int ba=0;
  for(int i=1;i<=n;i++){
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
      if(s[i]=='A'&&s[i+1]=='B'){
        cnt++;}
    }
  int n=s.size();
    if(s[0]=='B'&&s[n-1]!='A'){
      be++;}
    if(s[0]!='B'&&s[n-1]=='A'){
      ea++;}
    if(s[0]=='B'&&s[n-1]=='A'){
      ba++;}
  }
    
  if(ba!=0){
  if(max(ea,be)!=0){
   cnt+=ba+min(ea,be);}
  if(max(ea,be)==0){
    cnt+=ba-1;}
  }
  if(ba==0){
    cnt+=min(be,ea);}
  
  cout<<cnt<<endl;

  
}


Measured memory_bytes: 256
use std::collections::BTreeSet;
use std::io::{BufRead, Write};

fn main () {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let (h, w): (usize, usize) = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let mut set1: BTreeSet<(usize, usize)> = (0..w).map(|i| (i, 0)).collect();
    let mut set2: BTreeSet<(usize, usize)> = (0..w).map(|i| (0, i)).collect();
    for i in 0..h {
        let (a, b): (usize, usize) = {
            let mut buf = String::new();
            reader.read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            )
        };

        let mut tmp = Vec::new();
        for &(i, val) in set1.range((a, 0)..) {
            if i <= b {
                tmp.push((i, val));
            } else {
                break;
            }
        }
        let mut res = std::usize::MAX;
        for (i, val) in tmp {
            res = std::cmp::min(res, val + b + 1 - i);
            set1.remove(&(i, val));
            set2.remove(&(val, i));
        }
        if res != std::usize::MAX && b + 1 < w {
            set1.insert((b + 1, res));
            set2.insert((res, b + 1));        
        }
        match set2.iter().next() {
            Some((val, _)) => writeln!(writer, "{}", val + i + 1).unwrap(),
            None => writeln!(writer, "-1").unwrap(),
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

template<int m>
struct modint {

	unsigned x;

	modint() : x(0) {}

	modint(long long arg) {
		arg %= m;
		if (arg < 0) {
			x = arg + m;
		} else {
			x = arg;
		}
	}	

	modint& operator+= (const modint& other) {
		x += other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint& operator*= (const modint& other) {
		x = (x * 1ull * other.x) % m;
		return *this;
	}

	modint& operator-= (const modint& other) {
		x += m - other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint operator+ (const modint& other) const {
		modint tmp = *this;
		tmp += other;
		return tmp;
	}

	modint operator- (const modint& other) const {
		modint tmp = *this;
		tmp -= other;
		return tmp;
	}

	modint operator* (const modint& other) const {
		modint tmp = *this;
		tmp *= other;
		return tmp;
	}

	explicit operator int () const {
		return x;
	}

	modint& operator++ () {
		++x;
		if (x == m) {
			x = 0;
		}
		return *this;
	}

	modint& operator-- () {
		if (x == 0) {
			x = m-1;
		} else {
			--x;
		}
		return *this;
	}

	modint operator++ (int) {
		modint tmp = *this;
		++*this;
		return tmp;
	}

	modint operator-- (int) {
		modint tmp = *this;
		--*this;
		return tmp;
	}

	bool operator== (const modint& other) const {
		return x == other.x;
	}

	bool operator!= (const modint& other) const {
		return x != other.x;
	}

	template<class T>
	modint operator^ (T arg) const {
		if (arg == 0) {
			return 1;
		}
		if (arg == 1) {
			return x;
		}
		auto t = *this ^ (arg >> 1);
		t *= t;
		if (arg & 1) {
			t *= *this;
		}
		return t;
	}

	template<class T>
	modint operator^= (T arg) {
		return *this = *this ^ arg;
	}

	modint inv() const {
		return *this ^ (m-2);
	}
};

const int MOD = 998244353;
typedef modint<MOD> mint;

const int HI = 10'000'005;
mint f[HI], finv[HI];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n;
	cin >> n;

	f[0] = finv[0] = 1;
	for (int i=1; i<HI; i++) {
		f[i] = f[i-1] * i;
		finv[i] = f[i].inv();
	}

	mint sol = mint(3) ^ n;
	for (int i=n/2+1; i<=n; i++) {
		sol -= f[n] * finv[i] * finv[n-i] * (mint(2) ^(n-i)) * 2;
	}
	cout << (int)sol << '\n';
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  int cnt = 0;
  rep(i,n){
  	if(h[i] >= k)  cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int fN;
  int tN = N;
  for(int i; i < 8; i++){
    fN += tN%10;
    tN /= 10;
  }
  if (N % fN == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
 


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

using namespace std;
using LL = long long;

int X,Y,Z,K;
vector<LL>A,B,C;
vector<LL>AB;

int main() {
    cin >> X >> Y >> Z >> K;
    for(int i=0;i<X;++i){
        LL tmp;cin>>tmp;A.push_back(tmp);
    }
    for(int i=0;i<Y;++i){
        LL tmp;cin>>tmp;B.push_back(tmp);
    }
    for(int i=0;i<Z;++i){
        LL tmp;cin>>tmp;C.push_back(tmp);
    }
    sort(C.rbegin(),C.rend());
    for(int i=0;i<X;++i){
        for(int j=0;j<Y;++j){
            AB.push_back(A[i]+B[j]);
        }
    }
    sort(AB.rbegin(),AB.rend());
    priority_queue<LL>que;
    for(int p=0;p<min(K,X*Y);++p){
        for(int q=0;q<min(K,Z);++q){
            que.push(AB[p]+C[q]);
        }
    }
    for(int i = 0;i < K;++i){
        cout << que.top() << endl;
        que.pop();
    }
    return 0;
}


Measured memory_bytes: 43256
n, m = map(int, input().split())

cakes = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0
for b in range(8):
    signs = [1 if (b & (1 << i)) != 0 else -1 for i in range(3)]
    gains = [(signs[0] * x + signs[1] * y + signs[2] * z, x, y, z) for x, y, z in cakes]
    gains.sort(reverse=True)

    sx, sy, sz = 0, 0, 0
    for _, x, y, z in gains[:m]:
      	sx, sy, sz = sx+x, sy+y, sz+z

    ans = max(ans, abs(sx) + abs(sy) + abs(sz))

print(ans)




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

int main(){
    int n,x;
    cin >> n >> x;
    int l[n];
    for(int i=0;i<n;i++)cin >> l[i];
    int count=1;
    int d=0;
    for(int i=0;i<n;i++){
        d+=l[i];
        if(d<=x)count++;
        else break;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

int main() {
  ll x; cin >> x;

  ll cnt = x / 11;
  if(x % 11 == 0){
    cout << 2 * cnt << endl;
  }else if(x % 11 <= 6){
    cout << 2 * cnt + 1 << endl;
  } else {
    cout << 2 * cnt + 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256