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

long long fp;
int n;
string s;
map<string, long long> ma;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> s;
		sort(s.begin(), s.end());
		fp += ma[s];
		++ma[s];
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define INF 1000000000
const int maxn = 1e5 + 5;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    string s;
    cin >> s;
    int n = s.size();
    if(n<5){
    	cout << "No" << endl;
    }
    if(s[2] == s[3] && s[4] == s[5]){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}


Measured memory_bytes: 3576
let id x = x
let n = Scanf.scanf "%d\n" id
let array = Array.init n (fun _ -> Scanf.scanf "%d %d\n" (fun a b -> (a,b)))
let list = Array.to_list array

let rec func l =
  match l with
  | [] -> 0
  | (a,b) :: rest -> (b-a+1) + func rest
  
let ans = func list
  
let () =
  Printf.printf "%d\n" ans

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int d; cin >> d;
  if (d == 25) cout << "Christmas" << endl;
  if (d == 24) cout << "Christmas Eve" << endl;
  if (d == 23) cout << "Christmas Eve Eve" << endl;
  if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}

Measured memory_bytes: 2980
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:268435456")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i,n) for (int i=1;i<=n;++i)
#define loop(i,begin,end) for (__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif


template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 100005

ll dp[N], h[N], n, k;

int main() {
  FAST_IO;
  cin >> n >> k;
  rep(i, n) cin >> h[i];
  loop(i, 1, n) {
    dp[i] = INF;
    for (int j = i - 1; j >= i - k && j >= 0; j--) {
      remin(dp[i], dp[j] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n - 1];
  rtn 0;
}


Measured memory_bytes: 1792
/// 8:13 PM 21/06/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    char c;
    cin >> c;
    if (c >= 'a' && c <= 'z') {
        cout << 'a';
        return 0;
    }
    cout << 'A';    
    return 0;
}

Measured memory_bytes: 3636
#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 D; cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }


    vector<int> day(26,0);
    vector<int> contest_no;
    rep(z,D){
        int contest=1;
        int score=-1;

        // int n_contest=1;
        // int n_score=0;
        // rep(i,26){
        //     if(n_score < c[i] * ((z+1) - day[i])){
        //         n_score= c[i] * ((z+1) - day[i]);
        //         n_contest = i+1;   
        //     }
        // }
        // day[n_contest - 1] = z+1;

        // rep(i,26){
        //     if(score < s[z][i]){
        //         score = s[z][i];
        //         contest = i+1;
        //     }
        // }

        int m_contest=1;
        int m_score=-1e9;
        rep(i,26){
            if(m_score <  s[z][i] - c[i] * ((z+1) - day[i])){
                m_score = s[z][i] - c[i] * ((z+1) - day[i]);
                m_contest = i+1;
            }
        }
        day[m_contest - 1] = z+1;

        contest_no.push_back(m_contest);
    }

    //解の出力
    for(int i:contest_no){
        cout << i << endl;
    }
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int K, N;
    cin >> K >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    for(int i=1; i<N; i++) {
        B[i] = A[i] - A[i-1];
    }
    B[0] = K-A[N-1] + A[0];

    cout << K - *max_element(B.begin(), B.end()) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <climits>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  string s;
  cin >> s;
  int na, nb, nc;
  na = nb = nc = 0;
  REPe(e, s) {
    if (e == 'a') {
      na++;
    } else if (e == 'b') {
      nb++;
    } else {
      nc++;
    }
  }
  vecint x{na, nb, nc};
  sort(all(x));
  string ans = "NO";
  
    if (s.size() == 1) {
    ans = "YES";
    }else if (s.size() == 2) {
    if (x[2] != 2) {
      ans = "YES";
    }
  } else {
    if (x[0] != 0 && x[1] != 0 && x[2] - x[0] <= 1) {
      ans = "YES";
    }
  }
  cout << ans << endl;
}
//////////////////////////////////////////////


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <time.h>

using namespace std;
typedef long long ll;

#define MOD 1000000007


ll modpow(ll a, int n)
{
	ll res = 1;
	while (n > 0) {
		//ビットが立っていれば計算
		if (n & 1) {
			res = res * a % MOD;
		}
		//桁を二乗分ずらす
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}


class Combination
{
	vector<ll> fact;	//n!
	vector<ll> finv;	//n!の逆元
public:Combination(int n)
{
	vector<ll> inv(n + 1, 1);	//iの逆元
	fact.resize(n + 1, 1);
	finv.resize(n + 1, 1);
	for (int i = 2; i <= n; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

public:ll cmb(int n, int k)
{
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
};


int main()
{
	int K; cin >> K;
	string S; cin >> S;
	int len = K + S.size();
	Combination cmb = Combination(len);

	ll ans = 0;
	ll buf;
	//k文字を最後に置く。26**k通り
	//最後のk文字の前に固定の一文字
	//残りの文字の置き場所の選び方 cmb(len-k-1, S.size()-1) * 25**(K-k)
	for (int k = 0; k <= K; ++k) {
		//ans = ans + cmb.cmb(len - k - 1, S.size() - 1) * modpow(25, K - k) * modpow(26, k);
		buf = cmb.cmb(len - k - 1, S.size() - 1) * modpow(25, K - k) % MOD;
		buf = buf * modpow(26, k) % MOD;
		ans += buf;
		ans = ans % MOD;
	}
	cout << ans << endl;
}


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

const int MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int N,K;
	cin >> N>>K;
	vector<long long>P;
	vector<long long>M;
	for (int n = 0;n<N;++n) {
		long long num;
		cin >> num;
		if (num > 0) {
			P.push_back(num);
		}
		else {
			M.push_back(-num);
		}
	}
	sort(P.begin(),P.end(),std::greater<int>());
	sort(M.begin(), M.end(), std::greater<int>());
	//例外処理答えがマイナスになる
	if (P.size() == 0 && 1 == K%2) {
		sort(M.begin(), M.end()); 
		mint ans = 1;
		for (int n = 0;n<K;++n) {
			ans *= (mint)M[n];
		}
		cout << -ans << endl;
		return 0;
	}
	if (M.size() + P.size() ==K &&1 == M.size()%2) {
		mint ans = 1;
		for (int n = 0; n < M.size(); ++n) {
			ans *= (mint)M[n];
		}	
		for (int n = 0; n < P.size(); ++n) {
			ans *= (mint)P[n];
		}
		cout << -ans << endl;
		return 0;
	}
	


	int p = 0;
	int m = 0;
	mint ans = 1; 
	if (K%2 == 1) {
		ans *= (mint)P[m];
		p++;
		K--;
	}
	while (K != 0) {
			if (P.size()-p < 2 ) {
				ans *= (mint)M[m];
				ans *= (mint)M[m + 1];
				m += 2;
			}
			else if (M.size() - m < 2) {
				ans *= (mint)P[p];
				ans *= (mint)P[p + 1];
				p += 2;
			}
			else {
				if (P[p] * P[p + 1] > M[m] * M[m + 1]) {
					ans *= (mint)P[p];
					ans *= (mint)P[p + 1];
					p += 2;
				}
				else {
					ans *= (mint)M[m];
					ans *= (mint)M[m + 1];
					m += 2;
				}
			}
			K -= 2;
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 5488
from copy import deepcopy

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

B = deepcopy(A)
B.sort(reverse=1)
max_a = B[0]
max_b = B[1]

if A.count(max_a) == 1:
	for a in A:
		if a == max_a:
			print(max_b)
		else:
			print(max_a)
else:
	for a in A:
		print(max_a)

Measured memory_bytes: 14588
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
 

using P = pair<int, int>;
int main(){
	int N, Q;
	cin >> N >> Q;
	vector<int> c(N), id(N+1, -1);
	vector<vector<int>> arrow(N);
	for(int i=0; i<N; i++){
		cin >> c[i];
		//c[i]--;
		//if(id[c[i]] != -1) arrow.emplace_back(id[c[i]], i); 
		if(id[c[i]] != -1) arrow[id[c[i]]].push_back(i);
		id[c[i]] = i;
	}
	//sort(arrow.begin(), arrow.end());

	vector<vector<P>> query(N);
	for(int i=0; i<Q; i++){
		int l, r;
		cin >> l >> r;
		l--, r--;
		query[l].emplace_back(r, i);
	}

	// cout << " arrow: "; print_vec2(arrow);
	//cout << " query: "; print_vec2(query);
	BIT<int> bi(N+1);
	vector<int> ans(Q);
	for(int x=N-1; x>=0; x--){
		for(int y: arrow[x]) bi.add(y, 1);
		for(P q: query[x]){
			int r = q.first, i = q.second;
			// cout << " r: " << r << " i: " << i << endl;
			ans[i] = (r-x+1) - bi.sum(r);
		}

	}
	for(int i=0; i<Q; i++) cout << ans[i] << endl;
	


	return 0;
}



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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)

enum Dir { NORTH, SOUTH, EAST, WEST };

struct Polygon {
    vector<pair<Dir, int>> edges;
    pair<int, int> prev;
    bool empty = true;

    pair<Dir, int> get_edge(int x, int y) {
        assert(!empty);
        Dir dir = (x == prev.first?
                (y > prev.second? NORTH : SOUTH):
                (x > prev.first? EAST : WEST));
        int dis = abs(x - prev.first) + abs(y - prev.second);
        return {dir, dis};
    }
    
    void add(int x, int y) {
        if(!empty) {
            edges.push_back(get_edge(x, y));
        }
        empty = false;
        prev = {x, y};
    }
    
    void rev() {
        assert(!edges.empty());
        reverse(edges.begin(), edges.end());
        for(auto iter=edges.begin(); iter!=edges.end(); iter++) {
            iter->first = (
                iter->first == NORTH? SOUTH:(
                iter->first == SOUTH? NORTH:(
                iter->first == EAST? WEST: EAST)));
        }
    }
    
    void rot90() {
        assert(!edges.empty());
        for(auto iter=edges.begin(); iter!=edges.end(); iter++) {
            iter->first = (
                iter->first == NORTH? EAST:(
                iter->first == SOUTH? WEST:(
                iter->first == EAST? SOUTH: NORTH)));
        }
    }
    
    bool operator==(const Polygon& p) {
        if(edges.size() != p.edges.size()) return false;
        rep(i, edges.size())
            if(edges[i].first != p.edges[i].first || edges[i].second != p.edges[i].second)
                return false;
        return true;
    }
};

int main() {
    int n, m, x, y;
    while(cin>>n, n) {
        Polygon q;
        cin >> m;
        rep(_, m) { cin >> x >> y; q.add(x, y); }
        
        rep(i, n) {
            Polygon p;
            cin >> m;
            rep(_, m) { cin >> x >> y; p.add(x, y); }
            
            bool eq = false;
            rep(_, 4) { eq = eq || p == q; p.rot90();}
            p.rev();
            rep(_, 4) { eq = eq || p == q; p.rot90();}
            if(eq) { cout << i + 1 << endl;}
        }
        cout << "+++++" << endl;
    }
}



Measured memory_bytes: 3060
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int N = sc.nextInt(),B[] = new int[N-1],ans[]=new int[N],temp=0;
        for(int i=0;i<N-1;i++){
            B[i]=sc.nextInt();
            ans[0]=B[0];
            if(i!=0)
              ans[i] = Math.min(B[i],B[i-1]);
        }
        ans[N-1]=B[N-2];
        for(int i=0;i<N;i++){
            temp+=ans[i];
        }
       System.out.println(temp);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

vector<string> split(const string &s, char delim) {
    vector<string> result;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            result.push_back(item);
        }
    }
    return result;
}

int main() {
    int N; cin >> N;
    vector<int> L(N); rep(i, N) cin >> L[i];
    int Q; cin >> Q;

    map<int64, int64> v;
    rep(i, N) {
        v[L[i]]++;
    }

    int64 ans = 0;
    for (auto kv : v) {
        ans += kv.first * kv.second;
    }

    rep(_, Q) {
        int64 B, C; cin >> B >> C;

        ans -= C * v[C];
        ans -= B * v[B];

        v[C] += v[B];
        v[B] = 0;

        ans += C * v[C];

        cout << ans << endl;
    }
}


Measured memory_bytes: 9504
n=int(input())
ab_num=0
last_a=0
first_b=0
ba=0
for i in range(n):
    s=input()
    if(s[0]=='B' and s[-1]=='A'):
        ba+=1
    elif(s[0]=='B'):
        first_b+=1
    elif(s[-1]=='A'):
        last_a+=1

    ab_idx=s.find('AB')
    while(ab_idx!=-1):
        ab_num+=1
        ab_idx=s.find('AB',ab_idx+1)

ans=0
if(ba>1):
    ans+=ba-1

if(ba>0):
    if(last_a>0):
        ans+=1
        last_a-=1
    if(first_b>0):
        ans+=1
        first_b-=1
ans+=min(last_a,first_b)
ans+=ab_num
print(ans)

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    string s;cin >> s;
    int re=0,lw=0,le=0;
    REP(i,n)if(s[i]=='E')re++;
    int ans = re;
    REP(i,n+1){
       if(i!=n)if(s[i]=='E')re--;
       if(i>=1)if(s[i-1]=='W')lw++;
       ans = min(ans,re+lw);
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 900
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
ll arr[1000000];
int main(){
	ll n;
	cin>>n;
	cout<<(n-1)*n/2<<endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        int N = int.Parse(input);
        int ans = 0;
        if (N == 100000) { ans = 90909; }
        else if (N >= 10000) { ans = N - 9999+900+9; }
        else if (N >= 1000) { ans = 909; }
        else if (N >= 100) { ans = N - 99 + 9; }
        else if (N >= 10) { ans = 9; }
        else { ans = N; }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x,y; cin >> x >> y;
    OUT(x + y/2);

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> que;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        que.push(a);
    }

    for (int i = 0; i < m; ++i) {
        int ne = que.top();
        que.pop();
        que.push(ne/2);
    }

    ll res = 0;
    while (!que.empty()) {
        int v = que.top();
        res += (ll)v;
        que.pop();
    }
    cout << res << endl;
}

Measured memory_bytes: 3916
#include <stdio.h>
#include <string.h>
typedef unsigned int uint;

inline static uint gl(void){
    uint x = 0;
    for(;;){
        const uint c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

#define H 200000
uint v[H] __attribute__((aligned(64)));
int main(void){
    memset(v, 0x33, sizeof(uint)*H);
    {
        const uint h = gl();
        gl();
        const uint n = gl();
        for(uint i=0; i<n; i++){
            const uint x = gl()-1;
            const uint y = gl()-1;
            v[x] = y<v[x] ? y : v[x];
        }
        v[h] = 0;
    }
    {
        uint right = 0;
        for(uint x=1; ; x++){
            const auto b = v[x];
            const auto r = right+1;
            if(b<r){
                printf("%d\n", x);
                return 0;
            }else if(b>r){
                right=r;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int di(int x) {
  int a, b, c;
  a = x % 2;
  b = (x / 2) % 2;
  c = ((x / 2) / 2) % 2;
  int t = 0;
  t = c * 100 + b * 10 + a;
  return t;
}

void nadesiko(vector<int> &num, int x) {
  //cout << x << endl;
  int t = 0;
  t = di(x);
  int a, b, c;
  a = t / 100;
  b = (t - a * 100) / 10;
  c = t % 10;
  
  char op1, op2, op3;
  int s = 0;
  s += num.at(0);
  if(a == 1) {
    op1 = '+';
    s += num.at(1);
  }
  
  else if(a == 0) {
    op1 = '-';
    s -= num.at(1);
  }
  
  if(b == 1) {
    op2 = '+';
    s += num.at(2);
  }
  
  else if(b == 0) {
    op2 = '-';
    s -= num.at(2);
  }
  
  if(c == 1) {
    op3 = '+';
    s += num.at(3);
  }
  
  else if(c == 0) {
    op3 = '-';
    s -= num.at(3);
  }
  
  if(s == 7) {
    cout << num.at(0) << op1 << num.at(1) << op2 << num.at(2) << op3 << num.at(3) << "=7" << endl;
    return;
  }
  
  return nadesiko(num, x - 1);
  
}

int main() {
  string NUM;
  cin >> NUM;
  vector<int> num(4);
  for(int i = 0; i < 4; i++) {
    if(NUM.at(i) == '0') {
      num.at(i) = 0;
    }
    
    else if(NUM.at(i) == '1') {
      num.at(i) = 1;
    }
    
    else if(NUM.at(i) == '2') {
      num.at(i) = 2;
    }
    
    else if(NUM.at(i) == '3') {
      num.at(i) = 3;
    }
    
    else if(NUM.at(i) == '4') {
      num.at(i) = 4;
    }
    
    else if(NUM.at(i) == '5') {
      num.at(i) = 5;
    }
    
    else if(NUM.at(i) == '6') {
      num.at(i) = 6;
    }
    
    else if(NUM.at(i) == '7') {
      num.at(i) = 7;
    }
    
    else if(NUM.at(i) == '8') {
      num.at(i) = 8;
    }
    
    else {
      num.at(i) = 9;
    }
    
  }
  
  nadesiko(num, 7);
}


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

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

    long long cnt = 0;
    int sums = 0;
    int oneCnt=0;
    for(int i=0;i<S.size();i++){
        if(S[i] == '1'){
            oneCnt++;
            if(oneCnt == K){
                cout << 1 << endl;
                break;
            }
        }
        else if(S[i] != '1'){
            cout << S[i] << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
use std::io::{Read};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  
  let mut lines = buf.lines();
  let n:usize = lines.next().unwrap().parse().unwrap();
  let s = lines.next().unwrap().trim().as_bytes();
  
  let mut rsum = vec![0; n + 1];
  for i in 1 ..= n {
    if s[i - 1] == b'R' {
      rsum[i] = rsum[i - 1] + 1;
    } else {
      rsum[i] = rsum[i - 1];
    }
  }

  let ans = (0 ..= n).map(|i|{
    let lw = i - rsum[i];
    let rr = rsum[n] - rsum[i];
    std::cmp::max(lw, rr)
  }).min().unwrap();
  
  println!("{}", ans);
  Ok(())
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n,m,x,y;
int a[maxn],b[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m>>x>>y;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    for (int i=0; i<m; i++) {
	cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);

    for (int z=x+1; z<=y; z++) {
	if (a[n-1]<z && b[0]>=z) out("No War");
    }

    out("War");
    
    
    return 0;
}


Measured memory_bytes: 3664
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        long ans = 0;
        var tmpS = s.Skip(1).Reverse().Skip(1).ToArray();
        int r = tmpS.Count(t => t == 'R');
        int g = tmpS.Count(t => t == 'G');
        int b = tmpS.Count(t => t == 'B');

        int right = n - 1;
        int left = 0;

        if (n <= 3)
        {
            Console.WriteLine("0");
            return;
        }
        // 区間を選択し、違うものを選ぶ
        // 区間の色違いの数を数える

        bool containR = false;
        bool containG = false;
        bool containB = false;
        if (s[left] == 'R' || s[right] == 'R') containR = true;
        if (s[left] == 'G' || s[right] == 'G') containG = true;
        if (s[left] == 'B' || s[right] == 'B') containB = true;

        while(true)
        {
            var saveRight = right;
            var saveLeft = left;
            var saveR = r;
            var saveG = g;
            var saveB = b;

            while(true)
            {
                if (s[left] != s[right] && Math.Abs(right - left) > 2)
                {

                    if (s[left] == 'R' || s[right] == 'R') containR = true;
                    else containR = false;
                    if (s[left] == 'G' || s[right] == 'G') containG = true;
                    else containG = false;
                    if (s[left] == 'B' || s[right] == 'B') containB = true;
                    else containB = false;

                    var tmp = 0;

                    if (containR == false) tmp = tmp + r;
                    if (containG == false) tmp = tmp + g;
                    if (containB == false) tmp = tmp + b;

                    // 真ん中を取り除く
                    if (Math.Abs(right - left) % 2 == 0)
                    {
                        if (s[left] == s[left + ((right - left) / 2)] || s[right] == s[left + ((right - left) / 2)]) tmp = tmp;
                        else tmp = tmp - 1;
                    }

                    ans = ans + tmp;


                }

                right = right - 1;
                if (s[right] == 'R') r = r - 1;
                if (s[right] == 'G') g = g - 1;
                if (s[right] == 'B') b = b - 1;

                if (right - left == 2) break;
                if (right < left + 2) break;
            }

            // 最初のものから変更
            right = saveRight;
            left = saveLeft;
            r = saveR;
            g = saveG;
            b = saveB;

            left = left + 1;
            if (s[left] == 'R') r = r - 1;
            if (s[left] == 'G') g = g - 1;
            if (s[left] == 'B') b = b - 1;

            if (right - left == 2) break;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28340
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Pair> list = new ArrayList<>();
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            list.add(new Pair(sc.nextLong(), sc.nextLong()));
        }
        Collections.sort(list, new ComparatorB());
        boolean ng = false;
        long time = 0;
        for (int i = 0; i < n; i++) {
            time += list.get(i).a;
            if (list.get(i).b < time) {
                ng = true;
                break;
            }
        }
        if (ng) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

class Pair {
    public long a;
    public long b;
    public Pair(long a, long b) {
        this.a = a;
        this.b = b;
    }
}

class ComparatorB implements Comparator<Pair> {
    @Override
    public int compare(Pair p1, Pair p2) {
        if (p1.b == p2.b) {
            return 0;
        } else if (p1.b > p2.b) {
            return 1;
        } else {
            return -1;
        }
    }
}


Measured memory_bytes: 111048
A,B=map(int,input().split())
n=1
a=0
b=0
flag=1

while flag==1:

    if a==A and b==B:        
        flag=0
        print(n)
            
    elif a>A or b>B:
        
        flag=0
        print(-1)
        
    
    else:
        
        n+=1
        a=int(n*0.08)
        b=int(n*0.1)

Measured memory_bytes: 3064
N = int(input())
f = [0] + [1] + [2] * (N - 1)
for d in range(2, int(N ** 0.5) + 1):
    for i in range((N // d) * d, d * d - 1, -d):
        if d * d == i:
            f[i] += 1
        else:
            f[i] += 2

ans = 0
for i in range(1, N + 1):
    ans += i * f[i]

print(ans)

Measured memory_bytes: 221180
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

d = {}
for i in A:
    d[i] = B[i-1]

before = -1
ans = 0
for i in A:
    ans+=d[i]
    if i-before==1:
        ans += C[i-2]
    before = i

print(ans)

Measured memory_bytes: 3064
// Problem : C - Low Elements
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli t,n,i,k=1e6;
	cin>>n;
	vector<lli>v;
	for(i=0;i<n;i++){
		cin>>t;
		v.pb(t);
	}
	t=0;
	for(i=0;i<n;i++){
		if(v[i]<k)
		t++;
		k=min(k,v[i]);
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 5340
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric> // 最大公約数が使える
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main(){
    int N;
    string S;

    cin >> N >> S;
    ll R=0,G=0,B=0;
    ll ans;
    for (int i = 0; i < N; i++)
    {
        if(S[i]=='R'){
            R++;
        }
        if(S[i]=='G'){
            G++;
        }
        if(S[i]=='B'){
            B++;
        }
    }
    ans = R*G*B;

    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++) //被らない,逆パターンもない
        {
            int k = 2*j-i;
            if(k>=N){continue;}
            if(S[k]!=S[i] && S[k]!=S[j] && S[i]!=S[j]){
                ans--;
            }
        }
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int a = sc.nextInt();
        String str = "Christmas";
        if (a < 25) {
            for (int i = 0; i < 25 - a; i++) {
                str += " Eve";
            }
        }
        System.out.println(str);
    }
}


Measured memory_bytes: 22356
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    int a, b;
    cin >> a >> b;

    int ans = 0;
    int now = 1;
    while(now < b){
        now += a - 1;
        ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

const long double PI = acos(-1);

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    if(x * 2 > a * a * b) {
        long double A = a, B = b, X = x;
        long double res = atan(2 * (A * A * B - X) / (A * A * A)) * 180.0 / PI;
        cout << fixed << setprecision(10) << res << endl;
    } else {
        long double A = a, B = b, X = x;
        long double res = atan(A * B * B / (2.0 * X)) * 180.0 / PI;
        cout << fixed << setprecision(10) << res << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC132
{
    class Program
    {
        static int Main(string[] args)
        {
            problemA();
            return 0;
        }

        static void problemA()
        {
            string input = Console.ReadLine();
            string ans = "No";

            if (input[0] == input[1] && input[1] != input[2] && input[2] == input[3])
            {
                ans = "Yes";
            }
            else if (input[0] == input[2] && input[0] != input[1] && input[1] == input[3])
            {
                ans = "Yes";
            }
            else if (input[0] == input[3] && input[0] != input[1] && input[1] == input[2])
            {
                ans = "Yes";
            }
            

            Console.WriteLine(ans);
        }
    }
}

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

int main(){
	int n, m1 = 0, m2 = 0;
	string s1, s2;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s1 >> s2;
		if (s1 > s2)
			m1 +=3;
		else if (s2 > s1){
			m2 += 3;
		}
		else {
			m1++;
			m2++;
		}
	}
	cout << m1 << ' ' << m2 << '\n';
}


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

int main() {
  ll x,a=100;
  ll count=0;
  cin >>x;
  while(x>a){
    a*=1.01;
    count++;
  }
  cout << count<<endl;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#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 eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int imos[100010];
signed main() {
	int n, m, l, r;
	cin >> n >> m;
	rep(i, m) {
		cin >> l >> r;
		imos[l]++;
		imos[r + 1]--;
	}
	REP(i, n)imos[i] += imos[i - 1];
	int ans = 0;
	REP(i, n) {
		if (imos[i] == m)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}

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

int w,h;
char M[25][25];
int cnt;

void dfs(int y,int x)
{
    M[y][x]='#';
    cnt++;
    REP(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(0<=ny && ny<h && 0<=nx && nx<w && M[ny][nx]=='.') dfs(ny,nx);
    }
}

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

    while(cin>>w>>h,w|h)
    {
        REP(i,h) cin>>M[i];
        REP(i,h) REP(j,w){
            if(M[i][j]=='@'){
                cnt=0; dfs(i,j);
                cout<<cnt<<endl;
                i=h,j=w;
            }
        }
    }
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Array a(n);
    map<ll, ll> mp;
    ll sum = 0;
    REP(i, n) {
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }
    ll q;
    cin >> q;
    REP(i, q) {
        ll b, c;
        cin >> b >> c;
        ll con = mp[b];
        sum -= con * b;
        sum += con * c;
        mp[b] -= con;
        mp[c] += con;
        cout << sum << en;
    }
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 10084
from collections import deque


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n)]

for i in range(m):
    a, b = info[i]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

start = 0
visited = [False] * n
visited[start] = True

li = [0]
q = deque([start])
while True:
    pos = q.pop()
    for next_pos in graph[pos]:
        if not visited[next_pos]:
            visited[next_pos] = True
            q.append(next_pos)
            li.append(next_pos)
            break
    else:
        break

li2 = []       
q = deque([start])
while True:
    pos = q.pop()
    for next_pos in graph[pos]:
        if not visited[next_pos]:
            visited[next_pos] = True
            q.append(next_pos)
            li2.append(next_pos)
            break
    else:
        break

for i in range(len(li)):
    li[i] += 1
for i in range(len(li2)):
    li2[i] += 1

print(len(li) + len(li2))
print(*(li[::-1] + li2))

Measured memory_bytes: 82264
#include <iostream>
using namespace std;
bool binarysearch(int x,int a,int* fi){
    int left=0;
    int right = a;
    while(left<right){
        int mid=(left+right)/2;
        if(fi[mid]==x)return true;
        else if(fi[mid]>x)right = mid;
        else left=mid+1;
    }
    
    return false;
}


int main(){
    int a,b;
    int ans=0;
    cin>>a;
    int fi[a];
    for(int i=0;i<a;i++)cin>>fi[i];
    cin>>b;
    for(int i=0;i<b;i++){
        int x;
        cin>>x;
        
        if(binarysearch(x,a,fi))ans++;
        
    }

    cout<<ans<<endl;

return 0;
}



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

int main() {
	string s;
    getline(cin,s);
    int count = 700;
  	for(int i=0;i<3;i++){
      if(s.at(i) == 'o'){
        count += 100;
      }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 

 
 
int solve() {
 	
 	deque <char> dq;
 	string s;
 	cin>>s;
 	int q=Int;
 	for(int i=0;i<s.size();i++){
 		dq.push_back(s[i]);
 	}
 	int chk=0;
 	while(q--){
 		int x=Int;
 		if(x==1){
 			if(chk==0) chk=1;
 			else chk=0;
 		}
 		else{
 			int y;
 			char z;
 			cin>>y>>z;
 			if(chk==0) {
 				if(y==1) dq.push_front(z);
 				else dq.push_back(z);
 			}
 			else{
 				if(y==2) dq.push_front(z);
 				else dq.push_back(z);
 			}

 		}
 	}
 	string ans="";
 	while(!dq.empty()){
 		ans+=dq.front();
 		dq.pop_front();
 	}
 	if(chk==1) reverse(ans.begin(), ans.end());

 	cout<<ans<<endl;

 
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 1412