akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



const ll MOD = 1000000007;



ll K, N;
/*
	
	   B    R    B    R    B        // N=5, K=3, i=3 の場合
	                                // ここにRとBを追加する方法は何通りか?

	R*   B*   R*   B*   R*   B* R*  
*/

// memo[a][b] : a個の石をb個の箱に、それぞれ0個以上入れる方法
ll memo[2001][2001];

ll f( int a, int b ){
	if ( memo[a][b] != -1 )
		return memo[a][b];
	ll result = 1;
	if ( b <= 1 || a == 0 ){
		result = 1;
	}
	else {
		result = 0;
		for ( int i = 0; i <= a; i++ ){
			// b-1個目までの箱に a-i 個、
			// b個目の箱にi個入れる
			result += f( a-i, b-1 );
		}
	}
	result %= MOD;
	memo[a][b] = result;
	//cout << a << "/" << b << "/" << result << endl;
	return result;
}

int main(){
	cin >> N >> K;
	
	for ( int i = 0; i <= 2000; i++ )
		for ( int j = 0; j <= 2000; j++ )
			memo[i][j] = -1;
	
	for ( int i = 1; i <= K; i++ ){
		// 指定されたiで、Nが最小の場合を考える。
		int Rfix = i-1;
		int Bfix = i;
		
		// 残りのRとBを、i+1個の塊とi個の塊に振り分ける
		int R = (N-K)-Rfix;
		int B = K - Bfix;
		
		if ( R < 0 || B < 0 ){
			cout << 0 << endl;
		}
		else {
			cout << (f(R,i+1)*f(B,i))%MOD << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 31488
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<long long> number(100001, 0);

int main() {
	int xgroup, ygroup;
	long long x, y;
	cin >> x >> y;
	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
		xgroup = 1;
	if (x == 4 || x == 6 || x == 9 || x == 11)
		xgroup = 2;
	if (x == 2)
		xgroup = 3;

	if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
		ygroup = 1;
	if (y == 4 || y == 6 || y == 9 || y == 11)
		ygroup = 2;
	if (y == 2)
		ygroup = 3;

	if (xgroup == ygroup)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1024
use std::collections::BinaryHeap;
use std::io;

struct PartTimeJob {
    a: i64,
    b: i64,
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();

    let mut line_one_iter = buf.split_whitespace();

    let n: i64 = line_one_iter.next().unwrap().parse().unwrap();
    let m: i64 = line_one_iter.next().unwrap().parse().unwrap();

    let mut part_time_jobs_list: Vec<PartTimeJob> = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();

        let mut iter = buf.split_whitespace();

        let a: i64 = iter.next().unwrap().parse().unwrap();
        let b: i64 = iter.next().unwrap().parse().unwrap();

        let part_time_job = PartTimeJob { a: a, b: b };

        part_time_jobs_list.push(part_time_job);
    }
    part_time_jobs_list.sort_by(|a, b| a.a.cmp(&b.a));

    let mut total_salary = 0;
    let mut days_left = 1;
    let mut primary_queue: BinaryHeap<i64> = BinaryHeap::new();
    let mut loop_count: usize = 0;

    for _ in 0..m {
        while (loop_count as i64) < n && part_time_jobs_list[loop_count].a <= days_left {
            primary_queue.push(part_time_jobs_list[loop_count].b);
            loop_count += 1;
        }

        if let Some(salary) = primary_queue.pop() {
            total_salary += salary;
        }
        days_left += 1;
    }

    println!("{}", total_salary);
}


Measured memory_bytes: 8444
#include<iostream>
using namespace std;
int main(){
  int bell,student[100]={0};
  for(int i=0;i<28;i++){
    cin >> bell;
    student[bell]++;
  }
  for(int i=1;i<=30;i++){
    if(student[i]==0){
      cout << i << endl;
    }
  }
  return (0);
}

Measured memory_bytes: 1156
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void Solve(){
    string s , t;
    cin >> s;
    cin >> t;
    int c = 0;
    for (int i = 0; i < (int) s.length(); i++){
        c += (s[i] != t[i]);
    }
    cout << c << endl;
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        Solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> t(n);
  
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    t[a-1]++;
    t[b-1]++;
  }
  
  rep(i,n) cout << t[i] << endl;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<P> vec(m);
  rep(i, m) {
    ll b, c; cin >> b >> c;
    vec[i] = P(c, b);
  }
  sort(vec.rbegin(), vec.rend());

  int cnt = 0;
  rep(i, m) {
    P p = vec[i];
    ll c = p.first; ll b = p.second;
    rep(j, b) {
      if (cnt == n) break;
      if (c > a[cnt]) {
        a[cnt] = c;
      } else {
        break;
      }
      cnt++;
    }
  }

  ll ans = 0;
  rep(i, n) {
    ans += a[i];
  }
  cout << ans << endl;

}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    int pos = 0;
    while ((int)a.size() > 1) {
      pos = (pos + m - 1) % a.size();
      a.erase(a.begin() + pos);
    }
    cout << a[0] << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
import sys
# input = sys.stdin.readline
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
s = [input() for _ in range(n)]


def bracket(x):
    # f: final sum of brackets '(':+1, ')': -1
    # m: min value of f
    f = m = 0
    for i in range(len(x)):
        if x[i] == '(':
            f += 1
        else:
            f -= 1
        m = min(m, f)
    # m <= 0
    return f, m


def func(l):
    # l = [(f, m)]
    l.sort(key=lambda x: -x[1])
    v = 0
    for fi, mi in l:
        if v + mi >= 0:
            v += fi
        else:
            return -1
    return v


l1 = []
l2 = []
for i in range(n):
    fi, mi = bracket(s[i])
    if fi >= 0:
        l1.append((fi, mi))
    else:
        l2.append((-fi, mi - fi))

v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
    ans = 'No'
else:
    ans = 'Yes' if v1 == v2 else 'No'

print(ans)


Measured memory_bytes: 91936
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

t=[int(input())-1 for i in range(D)]

v=[]
S=0


last=[0]*27
for d in range(D):
    S+=s[d][t[d]]

    last[t[d]]=d+1

    for i in range(26):
        S-=c[i]*(d+1 - last[i])
    
    print(S)


Measured memory_bytes: 74324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<LL> A(N);
    int mcnt = 0;
    REP(i,N)
    {
        cin>>A[i];
        if(A[i] < 0) mcnt++;
        A[i] = abs(A[i]);
    }
    if(mcnt % 2 == 0)
    {
        LL ans = 0;
        REP(i,N)
        {
            ans += A[i];

        }
        cout << ans << endl;
        return 0;
    }
    else
    {
        LL ans = 0;
        sort(A.begin(), A.end());
        FOR(i,1,N)
        {
            ans += A[i];
        }
        ans -= A[0];
        cout << ans << endl;
        return 0;
    }






}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  
  int x;
  set<int> s;
  
  rep(i,n){
    cin>>x;
    s.insert(x);
  }
  
  if(s.size()==n) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  return 0;
}

Measured memory_bytes: 12988
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

ans = A[0]
if (N-2)%2==0:
    for i in range((N-2)//2):
        ans+=A[i+1]*2
else:
    for i in range((N-2)//2):
        ans+=A[i+1]*2
    ans+=A[(N-2)//2+1]
print(ans)
    

Measured memory_bytes: 93996
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  map<string, ll> mp;
  REP(i, n){
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << mp.size() << endl;
  return 0;
}

Measured memory_bytes: 19124
package main

import (
	"fmt"
	"sort"
)

type Pair struct {
	Index int
	Value int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].Value < p[j].Value
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	arr := make(Pairs, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i].Value)
		arr[i].Index = i + 1
	}

	sort.Sort(arr)

	for i, p := range arr {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(p.Index)
	}
	fmt.Println("")
}


Measured memory_bytes: 7684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(std::string S){
  if (S[0] == S[1] && S[0] == S[2]) {
    std::cout << "No" << std::endl;
    return;
  }
  if (S[0] == S[1]) {
    if (S[2] == S[3]) {
      std::cout << "Yes" << std::endl;
      return;
    }
  } else if (S[0] == S[2]) {
    if (S[1] == S[3]) {
      std::cout << "Yes" << std::endl;
      return;
    }
  } else if (S[0] == S[3]) {
    if (S[1] == S[2]) {
      std::cout << "Yes" << std::endl;
      return;
    }
  }
  std::cout << "No" << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int Ans=1;
  for(int i=1; i<N; i++){
    if(S.at(i)!=S.at(i-1)){
      Ans++;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 512
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int a,b;
vector<int> v;
void input(){
    cin>>a>>b;
}
void src(){
    cout<<((500*a>=b)? "Yes":"No");
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
    }else if((h*w)%2 == 0){
        cout << h*w/2 << endl;
    }else{
        cout << h*w/2+1 << endl;
    }
}


Measured memory_bytes: 256
n = gets.to_i

values = gets.split.map(&:to_i)

count = 0
loopcount = 0
values.each do |num|
  if num < 0
    count += 1
    values[loopcount] *= -1
  end
  loopcount += 1
end

values.sort!.reverse!

if count.even?
  p values.inject(:+)
else
  p values[0..(n-2)].inject(:+) - values[-1]
end

Measured memory_bytes: 9464
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N=200005;
const int mod=1e9+7;

ll n,a[N],res;

int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        res=(res+a[i]*a[i-1])%mod;
        a[i]=(a[i]+a[i-1])%mod;
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main(void)
{
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    std::cout << std::fixed;
    cout << setprecision(10) << double(double(W) * double(H) / 2.0) << " ";
    cout << int((x*2 == W) && (y*2 == H)) << endl;
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [ list(map(int,input().split())) for i in range(M) ]
BC = sorted(BC, key=itemgetter(1), reverse=True)
sumval=0
idx=0
for i in range(len(BC)):
    sumval += BC[i][0]
    idx += 1
    if sumval >= N:
        break
BC = BC[0:idx]
for i in range(len(BC)):
    for j in range(BC[i][0]):
        A.append(BC[i][1])
A = sorted(A, reverse=True)
print(sum(A[0:N]))


Measured memory_bytes: 34836
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#define M 500005
using namespace std;
long long ans=0;
vector<int>g[M];
int col[M];
int n,m;
bool flag=0;

void dfs(int u,int color)
{
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i];
		if(!col[v])
		{
			col[v]=color;
			dfs(v,color^1);
		} 
		else if(col[v]==col[u])flag=1;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	col[1]=1;
	dfs(1,0);
	if(flag)printf("%lld",(long long)n*(n-1)/2-m);
	else
	{
		long long cnt=0;
		for(int i=1;i<=n;i++)
		{
			if(col[i])cnt++;
		}
		printf("%lld",(long long)cnt*(n-cnt)-m);
	}
	return 0;
}

Measured memory_bytes: 23424
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll u = 10000;
    rep(i, n) {
        ll m;
        cin >> m;
        x -= m;
        chmin(u, m);
    }

    out(n + x/u);
    re0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    s=input()
    if(s[0]==">"):
        s="<"+s
    if(s[-1]=="<"):
        s=s+">"
    G=groupby(s)
    ans=0
    for i,g in enumerate(G):
        if(i%2==0):
            a=len(list(g[1]))
        else:
            b=len(list(g[1]))
            c=max(a,b)
            ans+=a*(a-1)//2+b*(b-1)//2+c
    print(ans)
resolve()

Measured memory_bytes: 78756
n = int(input())
a = ['3', '5', '7']

depth = len(str(n)) 
ans = 0

def search(s, i):
  if s != '':
    if int(s) <= n and '3' in s and '5' in s and '7' in s:
      global ans
      ans += 1
  if i != 0:
    for _a in a:
      search(s + _a, i - 1)

search('', depth)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B; cin >> A >> B;
  string result;
  if (A<=8&&B<=8) result = "Yay!";
  else result = ":(";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int sz=1e6+5;
typedef unsigned long long ull;
const ull step=119;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n;
char s[15];
struct node{
	ull a;
	int b;
};
vector<node> ha[sz];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",s);
		ull tmp=0;
		sort(s,s+10);
		for(int j=0;j<10;j++){
			tmp=tmp*step+s[j];
		}
		ull qaq=tmp%sz;
		int l=ha[qaq].size();
		int flag=1;
		for(int i=0;i<l;i++){
			if(ha[qaq][i].a==tmp){
				ha[qaq][i].b++;
				flag=0;break;
			}
		}
		if(flag){
			ha[qaq].push_back((node){tmp,1});
		}
	}
	long long ans=0;
	for(int i=0;i<sz;i++){
		int l=ha[i].size();
		for(int j=0;j<l;j++){
			ans=ans+1ll*ha[i][j].b*(ha[i][j].b-1)/2;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	int t=0;
	
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='+')
			t++;
		if(s[i]=='-')
			t--;
	}
	
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <queue>
#include <cmath>
#define ll long long
#define finish(x) cout<<x<<endl
#define all(x) (x).begin(), (x).end()
using namespace std;

ll mod = 998244353;
 
 int main() {
     string s1;
     string s2;
     cin>>s1>>s2;
     reverse(s2.begin(),s2.end());
     if(s1==s2)
        cout<<"YES"<<endl;
    else 
        cout<<"NO"<<endl;
    return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int bin_search(int target, int l, int r, vector<int> &vec){
    int mid = (l+r)/2+(l+r)%2;
    if(r-l==1){
        mid=r;
    }
    //cout << l << ' ' << r << ' ' << mid << endl;
    if(mid==r){
        //cout << vec[mid] << endl;
        return vec[mid];
    }

    if(vec[mid]>target){
        return bin_search(target, l, mid, vec);
    }else{
        return bin_search(target, mid, r, vec);
    }
}

int main(){
    string s, t;
    cin >> s >> t;
    int ss=s.size();
    int ts=t.size();
    long long sl=0;
    long long tl=0;

    vector<vector<int> > ch(26,vector<int>());
    for(int i=0; i<ss; i++){
        int tmp = s[i]-'a';
        ch[tmp].push_back(i);
    }

    for(int i=0; i<26; i++){
        ch[i].push_back(ss);
    }

    int ans=0;
    int k=-1;
    for(int i=0; i<ts; i++){
        int tmp = t[i]-'a';
        if((int) ch[tmp].size() == 1){
            cout << -1 << endl;
            return 0;
        }
        int next_ = bin_search(k, -1, (int) ch[tmp].size() -1, ch[tmp]);
        if(next_==ss){
            ans++;
            k=ch[tmp][0];
        }else{
            k=next_;
        }
    }
    cout << (long long) ans*ss+k+1 << endl;
}

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

int main() {
    int N; cin >> N;
    int prev, ans = 0;
    REP(i, 0, N) {
        int h; cin >> h;
        if (i == 0) {
            ans += h;
        } else if (prev < h) {
            ans += h - prev;
        }
        prev = h;
    }
    cout << ans << endl;
    return 0;
}

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

bool isEqualArray(int n, int* s1, int* s2) {
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* s1 = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> s1[i];
        }
        int count = 0;
        int* s2 = new int [n];
        while (!isEqualArray(n, s1, s2)) {
            for (int i = 0; i < n; i++) {
                s2[i] = s1[i];
            }
            for (int i = 0; i < n; i++) {
                int exist = 0;
                for (int j = 0; j < n; j++) {
                    if (s2[i] == s2[j]) {
                        exist++;
                    }
                }
                s1[i] = exist++;
            }
            count++;
        }
        cout << count - 1 << endl;
        for (int i = 0; i < n - 1; i++) {
            cout << s1[i] << " ";
        }
        cout << s1[n - 1] << endl;
        delete[] s1;
        delete[] s2;
    }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  priority_queue<ll> q;
  for (int i = 0; i < n; i++) q.push(a[i]);
  while (m) {
    auto v = q.top();
    q.pop();
    q.push(v / 2);
    m--;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define x first
#define y second
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const long long INF = 1e18;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll a,b,c,d; cin >> a >> b >> c >> d;
    cout << max({a*c,a*d,b*c,b*d});
}


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(y%2==0){
    
    if((x*2) <= y && y <= (x*4)){
            printf("Yes\n");
        }
        else{
         printf("No\n");
    
    }
        }
    else printf("No\n");
    
    return 0;
    
}

Measured memory_bytes: 1664
n = int(input())
l = []
ans = 0
check = True
for _ in range(n):
    m = int(input())
    l.append([list(map(int, input().split())) for _ in range(m)])
for i in range(2 ** n):
    bin_i = format(i, 'b').rjust(n, "0")
    check = True
    for k in range(n):
        for x in range(len(l[k])):
            if bin_i[k] == "1":
                if (bin_i[l[k][x][0] - 1] == "1") and (l[k][x][1] == 0):
                    check = False
                elif (bin_i[l[k][x][0]-1] == "0") and (l[k][x][1] == 1):
                    check = False
    if check:
        ans = max(ans, bin_i.count("1"))
print(ans)

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

int main() {
  int N,G,q=1,Z=1000;
  cin>>N>>G;
  vector<vector<int>> p(N,vector<int>(3));
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    p.at(i).at(0)=a,p.at(i).at(1)=b;p.at(i).at(2)=a*(1+i)*100+b;
    q*=2;
  }
  for(int i=0;i<q;i++){
    vector<int> r(N);
    int A=0,B=i,C=G,D=N;
    for(int j=0;j<N;j++){
      if(B%2==1){
        A+=p.at(j).at(0);
        C-=p.at(j).at(2);
        r.at(j)=1;
      }
      B/=2;
    }
    while(C>0){
      D--;
      if(r.at(D)==0){
        if((C-1)/((D+1)*100)+1<p.at(D).at(0)){
          A+=(C-1)/((D+1)*100)+1;
          C=0;
        }
        else{
          A+=p.at(D).at(0);
          C-=p.at(D).at(2);
        }
      }
    }
    Z=min(Z,A);
  }
  cout<<Z<<endl;
    
}

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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    map<int, int> data;
    map<int, bool> flag;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
      int id, p, num;
      cin >> id >> p >> num;
      for(int j = 0; j < num; j++) {
	data[id] += p;
	if(data[id] >= 1000000 && !flag[id]) {
	  cout << id << endl;
	  flag[id] = true;
	  cnt++;
	  break;
	}
      }
    }
    if(cnt == 0) cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int n, r;
    cin >> n >> r;
    if (n >= 10) cout << r << endl;
    else cout << r + 100 * (10 - n) << endl;

}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(a) int(a.size())
#define pb push_back

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

struct dat {
	int p,v,l,r;
};

int n,l;
ll ans=0;

struct cmp1 {
	bool operator()(const dat &A,const dat &B) {
		return A.p<B.p;
	}
};

struct cmp2 {
	bool operator()(const dat &A,const dat &B) {
		return make_pair(A.v,A.p)<make_pair(B.v,B.p);
	}
};

set<dat,cmp1> s1;
set<dat,cmp2> s2;

ll cal(const vector<dat> &v) {
	ll ret=0,sum=0;
	for(int i=0;i+l-1<sz(v);i++) sum+=v[i].l,ret+=sum*v[i+l-1].r;
	return ret;
}

int main() {
	cin>>n>>l;
	for(int i=1;i<=n;i++) {
		dat a=(dat){i,gi(),1,1};
		s1.insert(a);s2.insert(a);
	}
	while(!s2.empty()) {
		int mn=s2.begin()->v;
		vector<dat> vec;
		while(!s2.empty()&&s2.begin()->v==mn) vec.pb(*s2.begin()),s2.erase(s2.begin());
		for(int i=0,j;i<sz(vec);i=j) {
			j=i+1;
			while(j<sz(vec)&&++s1.find(vec[j-1])==s1.find(vec[j])) ++j;
			vector<dat> tmp(vec.begin()+i,vec.begin()+j);
			int len=j-i,cnt=len/l;
			if(cnt) {
				for(auto x:tmp) s1.erase(x);
				ans+=cal(tmp);
				vector<dat> now;
				for(int k=0;k<cnt;k++) now.pb((dat){tmp[0].p+k,mn+1,0,0});
				for(int k=0;k<sz(tmp)-l+1;k++) now[cnt-(sz(tmp)-k)/l].l+=tmp[k].l;
				for(int k=l-1;k<sz(tmp);k++) now[(k+1)/l-1].r+=tmp[k].r;
				ans-=cal(now);
				for(auto x:now) s1.insert(x),s2.insert(x);
			}
		}
	}
	cout<<ans+n;
	return 0;
}


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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


int main(){
    string s;
    cin>>s;
    
    if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535
int main(void)
{
    int a,b,C;
    double S,L,h;
    scanf("%d %d %d",&a,&b,&C);
    S = sin(C*PI/180)*a*b/2 ;
    L = a+b+sqrt(a*a+b*b-2*a*b*cos(C*PI/180));
    h = S/a*2;
    
    printf("%f %f %f",S,L,h);
    
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
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; }

const long long INF = 1LL << 60;

int main ()
{
    char a,b;
    cin >> a;
    b= a+1;
    cout << b << endl;
}

     



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e15+4;
const int Nmax=2e5+1;
const int Nd=61;
ll dfs[3003][3003][4];
ll  v[3003][3003];

int main(){
  int n,x,t;cin>>n>>x>>t;
  int nokori=n;
  int ans=0;
  while(nokori>0){
    nokori-=x;
    ans+=t;
  }
  cout<<ans<<endl;




  return 0;
}


Measured memory_bytes: 3560
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 102
ll dp[N][N*N];
ll n, k;
int main(){
	cin>>n>>k;
	mset(dp, -1);
	dp[n+1][0] = 1;
	for(int i = n; i >= 1; i--){
		for(int j = 0; j <= n*k; j++){
			if(dp[i+1][j]==-1) continue;
			for(int l = 0; l <= k; l++){
				int j2 = j+(l>i?0:(l+j)/i);
				chmax(dp[i][j2], 0LL);
				(dp[i][j2]+=dp[i+1][j])%=mod;
			}
		}
	}
	ll res = 0;
	rep(j, n*k+1) if(dp[1][j]>=0) (res+=dp[1][j]*j)%=mod;
	ll pw = 1;
	rep(i, n-1) (pw*=k+1)%=mod;
	ll res2 = k*(k+1)/2*n*pw%mod;
	cout<<(res2-res+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 8576
// C - Dubious Document 2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
string S, T;

bool match(int k){
	rp(i,0,T.size()) if(S[k+i] != '?' && S[k+i] != T[i]) return false;
	return true;
}

string create(int k){
	string s = S;
	rp(j,0,T.size()) s[k+j] = T[j];
	rp(j,0,S.size()) if(s[j] == '?') s[j] = 'a';
	return s;
}

string solve(){
	for(int i=S.size()-T.size(); i>=0; --i) if(match(i)) return create(i);
	return "UNRESTORABLE";
}

int main(){
	cin>>S>>T;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <queue>
#include <numeric>

int n, m;

int main(){
  std::priority_queue<int> Q;
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    Q.push(x);
  }
  for(int i=0;i<m;i++){
    int x = Q.top();
    Q.pop();
    Q.push(x/2);
  }
  long long int r = 0;
  while(!Q.empty()){
    r += Q.top();
    Q.pop();
  }
  printf("%lld\n", r);
  return 0;
}


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

using ll = long long;
const int INF = 1e9+100;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, x, m;
	cin>>n>>x>>m;
	map<int, int> vals;
	int cycStart;
	vector<int> sequence;
	// ll val = x;
	int id = 0;
	while (vals.count(x) == 0){
		vals[x] = id;
		sequence.push_back(x);
		x *= x; x %= m;
		id++;
	}
	cycStart = vals[x];
	int len = id;
	// for (auto it: sequence){
	// 	cout<<it<<' ';
	// }
	// cout<<'\n';
	// cout<<cycStart<<'\n';
	if (n < cycStart){
		ll res = 0;
		for (int i = 0; i < n; i++){
			res += sequence[i];
		}
		cout<<res<<'\n';
	}else{
		ll res = 0;
		ll cycsum = 0;
		for (int i = 0; i < cycStart; i++){
			res += sequence[i];
		}
		for (int i = cycStart; i < len; i++){
			cycsum += sequence[i];
		}
		n -= cycStart;
		res += n/(len - cycStart)*cycsum;
		n = n % (len - cycStart);
		for (int i = cycStart; i < cycStart + n; i++){
			res += sequence[i];
		}
		cout<<res<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5908
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int buf[3]={-1}, h, count=0;
	
	while(scanf("%d", &h) != EOF) {
		count++;
		if(h >= min(buf[0], min(buf[1], buf[2]))) {
			sort(buf, buf+3);
			reverse(buf, buf+3);
			buf[2] = h;
		}
	}
	sort(buf, buf+3);
	reverse(buf, buf+3);
	if(count <3) {
		for(int i=1; i<=count; i++) {
			printf("%d\n", buf[i-1]);
		}
	}
	else {
		for(int i=1; i<=3; i++)
			printf("%d\n", buf[i-1]);
	}
	return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new  Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double gal = a - b;
		if(gal>0) {
			System.out.println("GREATER");
		}else if(gal<0) {
			System.out.println("LESS");
		}else if(gal == 0) {
			System.out.println("EQUAL");
		}
	}

}


Measured memory_bytes: 22612
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
template <class T>
T gcd(T a, T b){
    T m, n, r;
    if(a > b){
        m = a;
        n = b;
    }else{
        m = b;
        n = a;
    }
    
    while(n != 0){
        r = m % n;
        m = n;
        n = r;
    }
    
    return m;
}

int main(){
    long long int a, b;

    cin >> a >> b;
    long long int c = gcd(a, b);
    long long int lim = (sqrt(c)+2 < c) ? sqrt(c)+2: c;

    vector<bool> is_prime(lim+1, true);
    for(long long int i = 2; i <= lim; i++){
        if(is_prime[i]){
            for(long long int j = i*2; j <= lim; j += i) is_prime[j] = false;
        }
    }

    long long int c2 = c;
    long long int res = 1;
    while(c2 > 1){
        bool c2_isprime = true;
        long long int prime;
        for(prime = 2; prime <= lim; prime++){
            if(is_prime[prime] && c2 % prime == 0){
                c2_isprime = false;
                break;
            }
        }

        if(c2_isprime){
            res++;
            break;
        }else{
            res++;
            do{
                c2 /= prime;
            }while(c2 % prime == 0);
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int temp = 0;
            int v = sc.nextInt();
            while (v % 2 == 0) {
                temp++;
                v /= 2;
            }
            ans = Math.min(ans, temp);
        }

        System.out.println(ans);
        sc.close();
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <string>
int main(){
    std::vector<std::string> s;
    int N;
    std::cin>>N;
    int A=0,B=0,AB=0;
    int ans=0;
    for(int j=0;j<N;++j){
        std::string z;
        std::cin>>z;
        if(z[z.length()-1]=='A' && z[0]=='B'){
            AB+=1;
        }else if(z[z.length()-1]=='A'){
            A+=1;
        }else if(z[0]=='B'){
            B+=1;
        }
        for(int i=0;i<z.length()-1;++i){

            if(z[i]=='A' && z[i+1]=='B'){
                ans+=1;
            }
        }
    }
    if(A>0 && AB>0){
        A-=1;
        ans+=1;
    }
    if(AB>0) ans+=(AB-1);

    if(B>0 and AB>0){
        B-=1;
        ans+=1;
    }

    ans+=std::min(A,B);
    std::cout<<ans<<std::endl;


}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static char[] S;

	public static void main(String[] args) {
		S = sc.next().toCharArray();
		System.out.println(solve(0, S.length));
	}

	static long solve(int l, int r) {
		if (l == r) return 0;
		long ret = Long.parseLong(String.valueOf(S, l, r - l));
		for (int i = 1; l + i < r; ++i) {
			long base = Long.parseLong(String.valueOf(S, l, i));
			ret += base * (1 << (r - l - 1 - i)) + solve(l + i, r);
		}
		return ret;
	}

}


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

using namespace std;
int n, m;
double cal(double g[][110]) {
  int i, j, k;
  double dp[110][110] = {};
  double all_MAX = 0.0;
  
  for(i = 1; i <= n; i++) {
    dp[1][i] = 1.0;
  }
  
  for(i = 2; i <= m; i++)
    for(j = 1; j <= n; j++) {
      dp[i][j] = 0.0;
      for(k = 1; k <= n; k++) {
	dp[i][j] = 1.0 * max(dp[i-1][k]*g[k][j], dp[i][j]);
      }
    }
  
    for(j = 1; j <= n; j++) {
      //     cout << dp[i][j] << ' ';
      all_MAX = max(dp[m][j], all_MAX);
    //     cout << endl;
  }
  
  return all_MAX;
}

	  
int main() {
  int i, j;
  while(cin >> n >> m, n != 0 || m != 0) {
    double g[110][110] = {};
    
    for(i = 1; i <= n; i++)
      for(j = 1; j <= n; j++)
	cin >> g[i][j];
    printf("%.2lf\n", cal(g));
  }
  
  return 0;
}

Measured memory_bytes: 1436
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f,g;


    while(cin>>a>>b>>c)
    {
        if(a*b<=c)
        {
            cout<<a*b<<endl;
        }
        else
        {
            cout<<c<<endl;
        }
    }








    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

ll n;
ll k;
ll a[maxn], idx[maxn];
const ll LOG = 60;
ll add[LOG][maxn];

vector<ll> ans;
int cnt[maxn];

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);

    for (int i = n - 1; i >= 0; i--)
        idx[a[i]] = i;
    for (int i = n - 1; i >= 0; i--)
    {
        if (idx[a[i]] <= i)
            add[0][i] = idx[a[i]] + n - i + 1;
        else
            add[0][i] = idx[a[i]] - i + 1;
        idx[a[i]] = i;
    }

    for (int i = 1; i < LOG; i++)
        for (int j = 0; j < n; j++)
        {
            add[i][j] = add[i - 1][(add[i - 1][j] + j) % n] + add[i - 1][j];
            if (add[i][j] > n * k + 2)
                add[i][j] = n * k + 2;
        }

    ll now = 0;
    for (int i = LOG - 1; i >= 0; i--)
    {
        if (now + add[i][now % n] <= k * n)
            now += add[i][now % n];
    }
    //printf("%lld\n", add[LOG - 1][0]);
    //printf("%lld\n", now);
    if (now == k * n)
        return 0;

    for (ll i = now; i <= n * k - 1; i++)
    {
        ll x = i % n;
        if (cnt[a[x]] == 0)
        {
            ans.push_back(a[x]);
            cnt[a[x]]++;
        }
        else
        {
            while (cnt[a[x]] > 0)
            {
                cnt[ans.back()]--;
                ans.pop_back();
            }
        }
    }
    for (int i = 0; i < ans.size(); i++)
        printf("%lld ", ans[i]);
    return 0;
}


Measured memory_bytes: 100848
// Problem : Cycle Finding
// Contest : CSES - CSES Problem Set
// URL : https://cses.fi/problemset/task/1197
// Memory Limit : 512 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat 
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 1e3 + 1;//                                                             |
//----------------------------------------------------------------------------------
 

//solution
void solve(){
    ll n;cin>>n;
    ii m;
    for(int i=1;i<=n;i++){
    	ll k=i;
        for(int j=2;j*j<=i;j++){
            while(k%j==0){
                m[j]++;
                k/=j;
            }
        }
        if(k>1){
        	m[k]++;
        }
    }
    ll ans=1;
    for(auto i:m){
    	ans*=(i.ss+1);
    	ans%=mod;
    }
    cout<<ans<<"\n";
}
 
int main()
{   
    
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     
 
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
vector<pair<int, int> > ans;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    int smax = (n - 2) * (n - 1) / 2;
    for (int i = 2; i <= n; ++i){
        ans.push_back(make_pair(1, i));
    }
    if (smax > k){
        for (int i = 2; i < n; ++i){
            for (int j = i + 1; j <= n; ++j){
                ans.push_back(make_pair(i, j));
                --smax;
                if (smax <= k) break;
            }
            if (smax <= k) break;
        }
    }
    if (smax == k){
        cout << ans.size() << '\n';
        for (auto e : ans){
            cout << e.first << " " << e.second << endl;
        }
    }else{
        cout << "-1" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import sys
import bisect
import math
input = sys.stdin.readline

n, k = map(int, input().split())
l = list(map(int, input().split()))

m = {}
for v in l:
    if m.get(v) != None:
        m[v] += 1
    else:
        m[v] = 1
        
m = list(m.values())
m.sort()
t = len(m) - k
if t < 0:
    t = 0
print(sum(m[:t]))

Measured memory_bytes: 33780
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    const double pi = 3.14159265358979323846;
    int time=h*60+m;
    double a1=2*pi/60*time;
    double a2=2*pi/60/12*time;
    if(a1>=2*pi) a1-=(2*pi);
    if(a2>=2*pi) a2-=(2*pi);
    double diff=abs(a1-a2);
    double ans=sqrt(a*a+b*b-2*a*b*cos(diff));
    printf("%0.11f",ans);
    return 0;
}


Measured memory_bytes: 4212