akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int x[n];
    rep(i,0,n)cin>>x[i];
    int u=101,d=0;
    while(u-d>2){
        int m1=(u+2*d)/3;
        int m2=(u*2+d)/3;
        int s1=0,s2=0;
        rep(i,0,n){
            s1+=(x[i]-m1)*(x[i]-m1);
            s2+=(x[i]-m2)*(x[i]-m2);
            
        }
        if(s1<s2)u=m2;
        else d=m1;
    }
    int s1=0,s2=0,s3=0;
    rep(i,0,n){
        s1+=(x[i]-d)*(x[i]-d);
        s2+=(x[i]-u)*(x[i]-u);
        s3+=(x[i]-d-1)*(x[i]-d-1);
    }
    cout<<min({s1,s2,s3})<<endl;
}





Measured memory_bytes: 256
N = int(input())

result = [input() for _ in range(N)]

C_AC,C_TLE,C_WA,C_RE = [0,0,0,0]

for i in result:
  if i == "AC":
    C_AC += 1
  elif i == "WA":
    C_WA += 1
  elif i == "TLE":
    C_TLE += 1
  elif i == "RE":
    C_RE += 1

print("AC x " + str(C_AC))
print("WA x " + str(C_WA))
print("TLE x " + str(C_TLE))
print("RE x " + str(C_RE))

Measured memory_bytes: 16260
n = int(input())
a = list(map(int, input().split()))
list.sort(a, reverse=True)

if n % 2 == 0:
    ans = sum(a[: int(n/2)])*2 - a[0]
if n % 2 == 1:
    ans = sum(a[: int(n/2 + 0.5)])*2 -a[0] - a[int(n/2 - 0.5)]
    
print(int(ans))

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int x=0;
  for(auto it:a)x^=it;
  vector<bool>X(32);
  for(int i=0;i<32;i++)X[i]=((x>>i)&1);
  map<int,int>m;
  for(int i=0;i<N;i++){
    for(int j=0;j<32;j++){
      if((a[i]>>j)&1){
        m[j]++;
        break;
      }
    }
  }
  ll ans=0;
  for(int i=31;i>=0;i--){
    if(X[i]){
      if(!m[i]){
        cout<<-1<<endl;
        return 0;
      }
      for(int j=i;j>=0;j--)X[j]=!X[j];
      ans++;
    }
  }
  bool ok=true;
  for(auto it:X)if(it)ok=false;
  if(ok)cout<<ans<<endl;
  else cout<<-1<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mod = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    int ret = inf;
    for(ll a=1;a*a<=n;++a)if(n%a == 0){
        ll b = n/a;
        int tmp = a;
        int ac,bc;
        ac = bc = 0;
        while(tmp > 0)ac++,tmp/=10;
        while(b > 0)bc++,b/=10;
        ret = min(max(ac,bc),ret);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
  char b;
  cin >> b;  
  char ans;
  if(b=='A') ans='T';
  if(b=='T') ans='A';
  if(b=='C') ans='G';
  if(b=='G') ans='C';
  

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const ll INF = 1LL << 60;

int main(){

    string s;
    cin >> s;
    int len = s.length();
    int cnt = 0;

    bool flag1 = (s[0] == s[len-1]);//先頭と末尾が同じ文字である場合true
    bool flag2 = ((len % 2) == 1);//文字列長が奇数である場合true
    
    if(flag1^flag2){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
n=int(input())
h = list(map(int,input().split()))
ans=-1
if n==1:
    ans=h[0]
    h[0]=-1
while h[-1]>=0:
    flag=0
    for i in range(n-1):
        if h[i]>h[i+1]:
            h[i]-=1
            flag=1
            break
        h[i]=h[i]-1
    if flag==0:
        h[i+1]-=1
    ans+=1
print(ans)

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

using namespace std;
main(){
  string in[2];
  while(1){
    cin >> in[0] >> in[1];
    if(in[0]=="0" && in[1]=="0") break;

    int hit=0, bro=0;

    for(int i=0;i<4;i++){
      if(in[0][i]==in[1][i]) hit++;
      for(int j=0;j<4;j++){
	if(in[0][i]==in[1][j]) bro++;
      }
    }
    bro-=hit;

    cout << hit << ' '<< bro << endl;
      }
  return 0;
}

Measured memory_bytes: 0
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> cnt(N, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int id;
      cin >> id;
      id--;
      cnt[id]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (cnt[i] == 0) ans++;
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 200001;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
        signed main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;cout<<min(a,b)+min(c,d);

      }


        


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    int q;
    cin >> s >> q;
    int flag;
    int fi;
    string c;
    bool is_rev = false;

    rep(i,q){
        cin >> flag;
        if(flag==1){
            is_rev = !is_rev;
        }else{
            cin >> fi >> c;
            if(fi == 1){
                if(!is_rev){
                    s.insert(0,c);
                }else{
                    s += c;
                }
            }else{
                if(!is_rev){
                    s += c;
                }else{
                    s.insert(0,c);
                }
            }
        }
    }
    if(is_rev){
        reverse(s.begin(),s.end());
    }
    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef string::const_iterator State;

void assume(State &begin, char expected) {
    // cerr << "assume: " << *begin << " " << expected << endl;
    assert(*begin == expected);
    begin++;
}

int term(State&, vi);
int formula(State&, vi);

int term(State &begin, vi v) {
    // cerr << "term: " << *begin << endl;
    int ret = formula(begin, v);

    if (*begin == '*') {
        begin++;
        ret = min(ret, formula(begin, v));
    } else {
        assume(begin, '+');
        ret = max(ret, formula(begin, v));
    }

    return ret;
}

int formula(State &begin, vi v) {
    // cerr << "formula: " << *begin << endl;
    int ret;

    if (isdigit(*begin)) {
        ret = *begin - '0';
        begin++;
    } else if (isalpha(*begin)) {
        ret = v[*begin - 'P'];
        begin++;
    } else if (*begin == '-') {
        begin++;
        ret = 2 - formula(begin, v);
    } else {
        assume(begin, '(');
        ret = term(begin, v);
        assume(begin, ')');
    }

    return ret;
}

int solve(string s) {
    int ret = 0;
    rep(i, 27) {
        // cerr << "i = " << i << ":" << endl;
        State begin = s.begin();
        vi v({i % 3, (i / 3) % 3, i / 9});
        if (formula(begin, v) == 2) {
            ret++;
        }
    }
    return ret;
}

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

    string s;
    int t = 0;
    while (cin >> s, s[0] - '.') {
        // cerr << "--- t = " << t++ << " ---"<< endl;
        cout << solve(s) << endl;
    }
}

Measured memory_bytes: 3028
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int a[200005],t[200005],n,ans[200005],len;
V<int> g[200005],v[200005];
void dfs(int p,int fa){
	int last=lwb(t+1,t+n+1,a[p])-t;
	g[last].PB(a[p]);
	t[last]=g[last].back();
	gmax(len,last);
	ans[p]=len;
	for(auto u:v[p])if(u!=fa){
		dfs(u,p);
	}
	g[last].pop_back();
	t[last]=g[last].back();
	while(g[len].size()==1)len--;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	FOR(i,1,n)cin>>a[i];
	int x,y;
	rep(i,1,n){
		cin>>x>>y;
		v[x].PB(y);
		v[y].PB(x);
	}
	FOR(i,1,n)g[i].PB(2000000000),t[i]=g[i].back();
	dfs(1,-1);
	FOR(i,1,n)cout<<ans[i]<<'\n';
	RE 0;
}




Measured memory_bytes: 43064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const long long oo = 1000000000000ll;

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int m, n;
ll res;

int main() {
    res = oo;
    cin >> m >> n;
    foru(i, 1, m - 1) {
        ll area1 = 1ll * i * n;
        ll area2 = 1ll * ((m - i) / 2) * n;
        ll area3 = 1ll * (m - i) * n - area2;
        res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));

        area2 = 1ll * (n / 2) * (m - i);
        area3 = 1ll * (n - (n / 2)) * (m - i);
        res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));

        if (m - i >= 2) {
            area2 = 1ll * n * ((m - i) / 2);
            area3 = 1ll * n * (m - ((m - i) / 2));
            res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));
        }
    }
    swap(m, n);
    foru(i, 1, m - 1) {
        ll area1 = 1ll * i * n;
        ll area2 = 1ll * ((m - i) / 2) * n;
        ll area3 = 1ll * (m - i) * n - area2;
        res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));

        area2 = 1ll * (n / 2) * (m - i);
        area3 = 1ll * (n - (n / 2)) * (m - i);
        res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));

        if (m - i >= 2) {
            area2 = 1ll * n * ((m - i) / 2);
            area3 = 1ll * n * (m - ((m - i) / 2));
            res = min(res, max(max(area1, area2), area3) - min(min(area1, area2), area3));
        }
    }
    cout << res;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		double length = 0;
		int count = 0;
		
		for(int i=0;i<n;i++) {
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
		}
		
		for(int i=0;i<n;i++) {
			length = Math.pow(x[i], 2) + Math.pow(y[i], 2);
			length = Math.sqrt(length);
			if(length <= d) {
				count++;
			}
		}
		System.out.println(count);

	}

}


Measured memory_bytes: 62408
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll min_num = min({a, b, c, d, e});
    cout << (n + min_num-1) / min_num + 4 << endl;;
    return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>

#define MAX 1000000000
#define min(x, y) ((x) < (y) ? (x) : (y))

#define MAX_STATION 101

int croute[MAX_STATION][MAX_STATION];
int troute[MAX_STATION][MAX_STATION];
int cost[MAX_STATION];
int check[MAX_STATION];
int n, m;

void dijkstra(int start, int route[MAX_STATION][MAX_STATION]) {
    int i, u;

    for (i = 1; i < m + 1; i++) {
	cost[i] = MAX;
	check[i] = 0;
    }
    cost[start] =0;
    while (1) {
	// まだ確定しておらず，一番コストが小さいとこを探す
	int v = -1;
	for (u = 1; u < m + 1; u++) {
	    if (check[u] == 0 && (v == -1 || cost[u] < cost[v]))
		v = u;
	}
	if (v == -1)
	    break;
	check[v] = 1;

	// v を経由した経路でcostが更新できるかどうか
	for (u = 1; u < m + 1; u++) {
	    cost[u] = min(cost[u], cost[v] + route[v][u]);
	}
    }
}

int main(void) {
    int i, j, k;
    int result;

    while (scanf("%d%d", &n, &m), n != 0) {
	for (i = 0; i < MAX_STATION; i++) {
	    for (j = 0; j < MAX_STATION; j++) {
		croute[i][j] = i == j ? 0 : MAX;
		troute[i][j] = i == j ? 0 : MAX;
	    }
	}
	while (n > 0) {
	    int a, b, c, t;
	    scanf("%d%d%d%d", &a, &b, &c, &t);
	    croute[a][b] = croute[b][a] = c;
	    troute[a][b] = troute[b][a] = t;
	    n--;
	}
	scanf("%d", &k);
	while (k > 0) {
	    int p, q, r;
	    scanf("%d%d%d", &p, &q, &r);
	    dijkstra(p, r == 0 ? croute : troute);
	    result = cost[q];
	    printf("%d\n", result);
	    k--;
	}
    }
    return 0;
}

Measured memory_bytes: 680
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a,b=map(int,input().split())
set_a=set(prime_factorize(a))
set_b=set(prime_factorize(b))
l=len(set_a & set_b)
print(l+1)

Measured memory_bytes: 39152
n, k = map(int, input().split(' '))
INF = int(1e9)
h = list(map(int, input().split(' ')))
dp = [INF for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i - j >= 0:
            # print(i-j)
            dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j])

print(dp[n-1])


Measured memory_bytes: 57452
using System;

class Program
{
  static void Main()
  {
    string[] str1 = Console.ReadLine().Split();
    string[] str2 = Console.ReadLine().Split();
    string u = Console.ReadLine();
    
    int a = int.Parse(str2[0]);
    int b = int.Parse(str2[1]);
    
    a -= str1[0] == u ? 1 : 0;
    b -= str1[1] == u ? 1 : 0;
    
    Console.WriteLine("{0} {1}", a, b);
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define vi vector<int>
#define ll long long
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define MOD 1000000007
#define endL << '\n'
#define ii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define endL << '\n'
#define vii vector<ii>
#define pb push_back

/*
ll powmod(ll x, ll y, ll mod){
	ll res = 1;
	while (y > 0){
		if (y%2) res = (res*x) % mod;
		x = (x*x) % mod;
		y /= 2;
	}
	return res;
}
*/

/*const int N = 1000000;
int lp[N+1];
vector<ll> pr;

void sieve(){
	for (int i=2; i<=N; ++i) {
	    if (lp[i] == 0) {
	        lp[i] = i;
	        pr.push_back (i);
	    }
	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
	        lp[i * pr[j]] = pr[j];
	}
}*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1; //cin >> t;
	while(t--){
		int n; cin >> n; n++;
		vll a(n); for (int i = 0; i < n; i++) cin >> a[i];
		vll suff(n); 
		for (int i = n-1; i >= 0; i--){
			suff[i] = (i == n-1) ? a[i] : a[i] + suff[i+1];
		}
		ll ans = 0ll, up = 1ll;
		for (int i = 0; i < n; i++){
			up = min(up, suff[i]);
			if (a[i] > up) {cout << -1; return 0;}
			ans += up;
			up = (up - a[i]) * 2;
		}
		cout << ans;
	}
}

Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

bool isprime(int a) {
    for (int i = 2; i <= sqrt(a) ; ++i) {
        if (a % i == 0) return false;

    }
    return true;

}

int main() {
    vector<int> p;
    int cnt = 0;
    int n;
    cin >> n;
    for (int i = 2; i <=5555 ; ++i) {
        if(isprime(i) && i % 5 == 1) {
            p.push_back(i);
            cnt++;
            if(cnt > n) break;
        }
    }

    for (int j = 0; j < n; ++j) {
        if(j) cout << " ";
        cout << p[j];
    }


    return 0;
}


Measured memory_bytes: 256
def binarySearch(A, n, key):
    left = 0
    right = n
    while left < right:
        mid = (right + left) // 2
        if A[mid] == key:
            return True
        elif A[mid] < key:
            left = mid +1
        elif A[mid] > key:
            right = mid
    return False


if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    cnt = 0
    for i in range(q):
        if binarySearch(S, n,T[i]):
            cnt += 1
    print(cnt)

Measured memory_bytes: 18648
#define _USE_MATH_DEFINES
 
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
 
#include <bits/stdc++.h> 
 
using namespace std;
 
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<int, int>
#define beg begin
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
	for (auto &i : a) {
		str >> i; 
	}
	return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    solve();    
}
 
const int INF = 1e18, MAXN = 3e5 + 10, MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vi l(n);
	cin >> l;

	int ans = 0;
	sort(all(l));
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			for (int k = j + 1; k < n; ++k) {
				if (l[i] < l[j] + l[k] && 
					l[j] < l[k] + l[i] &&
					l[k] < l[i] + l[j]) {
					ans++;
				}
			}	
		}
	}

	cout << ans << endl;
}	

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

using namespace std;

const int p = 1000000007;

int a[17];
int b[65537];
int c[65537];
int d[65536][17];

int f(int x, int y) {
	return y ? y & 1 ? (long long)f(x, y ^ 1) * x % p : f((long long)x * x % p, y >> 1) : 1;
}

int ncr(int n, int r) {
	if (r > n) return 0;
	return (long long)b[n] * c[r] % p * c[n - r] % p;
}

int main() {
	int i, j, k, l, n, m, t, tt, r = 0;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++) scanf("%d", &a[i]);
	reverse(a + 1, a + m + 1);
	b[0] = 1;
	for (i = 1; i <= 1 << n; i++) b[i] = (long long)b[i - 1] * i % p;
	c[1 << n] = f(b[1 << n], p - 2);
	for (i = 1 << n; i >= 1; i--) c[i - 1] = (long long)c[i] * i % p;
	d[0][0] = 1;
	for (i = 0; i < 1 << n; i++) for (j = 0; j <= m; j++) if (d[i][j]) {
		tt = (long long)d[i][j] * b[(1 << n) - i - 1] % p;
		for (k = l = 0; k < n; k++) {
			if (!(i >> k & 1)) tt = (long long)tt * c[1 << k] % p;
			else l = !l;
		}
		if (l) r = (r - tt + p) % p;
		else r = (r + tt) % p;
		for (k = 0; k < n; k++) if (!(i >> k & 1)) for (l = j + 1; l <= m; l++) {
			d[i | 1 << k][l] = (d[i | 1 << k][l] + (long long)d[i][j] * ncr((1 << n) - a[l] - i, (1 << k) - 1)) % p;
		}
	}
	for (i = 0; i < n; i++) r = 2ll * r * b[1 << i] % p;
	printf("%d\n", r);
	return 0;
}


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

int ans[100010];
int main(void) {
  string s;
  cin >> s;
  s += "R";

  bool rf = false, lf = false;
  int index = 0;
  int rcnt = 0, lcnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'R') {
      if (!rf) rf = true;
      if (rf && lf) {
        //rcnt wo huru
        ans[index - 1] += (rcnt + 1) / 2;
        ans[index] += rcnt - (rcnt + 1) / 2;
        //lcnt wo huru
        ans[index] += (lcnt + 1) / 2;
        ans[index - 1] += lcnt - (lcnt + 1) / 2;
        //init
        rf = lf = false;
        rcnt = lcnt = index = 0;
      }
      rcnt++;
    }
    if (s[i] == 'L') {
      if (!lf) {
        index  = i;
        lf = true;
      }
      lcnt++;
    }
  }
  for (int i = 0; i < s.length() - 1; i++) {
    if (i != 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
}


Measured memory_bytes: 1088
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

class Solution
{
    //static long almostSorted(int[] arr)
    //{
    //    
    //}



    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var x = int.Parse(input[1]);
        var t = int.Parse(input[2]);

        var result = n / x;
        if (n % x != 0)
        {
            result++;
        }

        //var result = almostSorted(arr);
        //var a = almostSorted(new[] { 10, 3 });
        Console.WriteLine(result * t);
    }
}

Measured memory_bytes: 27076
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

	int a[10];
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a,a+10,greater<int>());
	cout<<a[0]<<endl<<a[1]<<endl<<a[2]<<endl;

return 0;
}

Measured memory_bytes: 1176
def main():
    import sys
    import collections
    input = sys.stdin.readline
    N = int(input())
    S = [input() for i in range(N)]
    c = collections.Counter(S)
    max_num = c.most_common(1)[0][1]
    ss = [cc[0] for cc in c.most_common() if cc[1] == max_num]
    ss.sort()
    for s in ss:
        print(s,end="")

if __name__ == "__main__":
    main()


Measured memory_bytes: 45288
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define f for
#define tn return
#define bk break
#define cn continue
#define ve vector
#define st string
#define ch char
#define ft first
#define sec second


void solve()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int x=a,y=b,z=c;
	if(y>x && z>y)
	{
		cout<<"Yes";
		return;
	}
	for(int j=1;j<=k;j++)
	{
		x=a,y=b,z=c;
		for(int l=0;l<=j;l++)
		{
			x=a,y=b,z=c;
			int t1=pow(2,l);
			int t2=pow(2,j-l);
			y=y*t1,z=z*t2;
			if(y>x && z>y)
			{		
				cout<<"Yes";
				return;
			}		
		}	
	}
	cout<<"No";
}


int main()
{
	fastio
	solve();
}

Measured memory_bytes: 4112
program gob
    implicit none
    integer :: n=0,i=0,is_DomainOver=0,j=0,is_fault=0,cnt=1
    integer, allocatable :: H(:)
    read(*,*)n
    allocate(H(n))
    read(*,*) (H(i),i=1,n)
    !Domein check
    if(n<1 .or. 20<n)then
        is_DomainOver = 1
    endif
    do i=1,n
        if(H(i)<1 .or. 100<H(i))then
            is_DomainOver = 1
        endif
    enddo

    if(is_DomainOver == 1)then
    else
        do i=2,n
            do j=1,i-1
                
                if(H(j)<=H(i))then
                else
                    is_fault = 1
                endif
            enddo
            if(is_fault == 1)then
            else
                cnt = cnt + 1
            endif
            is_fault=0
        enddo
        write(*,*)cnt
    endif
    deallocate(H)
end program gob

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
//型の定義
typedef long long i64;
typedef int i32;
typedef float f32;
typedef double f64;
typedef string String;
typedef vector<long long> vecT64;
typedef vector<int> vecT32;
//最大値問題　最少値問題用void
void chmin(i64 &a, i64 b){
  if(a > b){
    a = b;
  }
}

void chmax(i64 &a, i64 b){
  if(a < b){
    a = b;
  }
}
//無限大
const i64 Infinite = 1LL << 60;

//ここからメイン関数
int main(){
  i64 N;
  cin >> N;
  i64 h[100001];
  i64 dp[100001];
  for(i32 i = 0; i < N; i++){
    cin >> h[i];
  }
  //cout << Infinite << endl;
  //Infiniteで初期化
  for(i32 i = 0; i < 100001; i++){
    dp[i] = Infinite;
  }
  
  //dp初期化
  dp[0] = 0;
  
  //貰うdp cost i-1 OR i-2
  for(i32 i = 0; i < N; i++){
    chmin(dp[i],dp[i-1] + abs(h[i]-h[i-1]));
    if(i > 1){
      chmin(dp[i],dp[i-2] + abs(h[i]-h[i-2]));
    }
  }
  cout << dp[N-1] << endl;
  
  //配るdp cost i+1 OR i+2
  /*for(i32 i = 0; i < N; i++){
    cout << dp[i+1] << " " << dp[i]+abs(h[i]-h[i+1]) << endl;
    cout << dp[i+2] << " " << dp[i]+abs(h[i]-h[i+2]) << endl;
    
    //minimum cost
    chmin(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    chmin(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
   
    }*/
  //cout << dp[N-1] << endl;
  return 0;
}


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

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

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

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

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

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let base = 753;
    let mut x: i64 = sc.read();
    let mut keta: i64 = 1000;
    let mut count = 3;

    while x % keta != x {
        keta = keta * 10;
        count = count + 1;
    }

    let keta = 1000;
    let mut res = 999;
    count = count - 2;
    for _i in 0..count {
        let tmp = x % keta;
        x = x / 10;
        let mut can;
        if tmp < base {
            can = base - tmp;
        } else {
            can = tmp - base;
        }
        res = cmp::min(res, can);
    }

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> x(n),y(n),root(n);
  rep(i,n) {
    cin >> x[i] >> y[i];
    root[i]=i;
  }
  double sum=0;
  do{

    for(int i=0; i<n-1; i++){
      sum+=sqrt((x[root[i]]-x[root[i+1]])*(x[root[i]]-x[root[i+1]])+(y[root[i]]-y[root[i+1]])*(y[root[i]]-y[root[i+1]]));
    }
  }while(next_permutation(all(root)));
  int d=1;
  for(int i=1; i<=n; i++) d*=i;
  printf("%.9f\n",sum/d );
  return 0;
}


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

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int main() {
	LL n = read(), a = read(), b = read();
	if (a > b) puts("0"), exit(0);
	if (n == 1 && a != b) puts("0"), exit(0);
	cout<<(n - 1) * b + a - ((n - 1) * a + b) + 1;
	return 0;
}



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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> L(N);
    for (int64_t& l : L) {
        cin >> l;
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = i + 1; j < N; j++) {
            for (int64_t k = j + 1; k < N; k++) {
                if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) {
                    continue;
                }
                int64_t max_l = max({ L[i], L[j], L[k] });
                int64_t sum = L[i] + L[j] + L[k];
                int64_t others = sum - max_l;
                if (others > max_l) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

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

int main(void) {
   long A,B,C;
   cin>>A>>B>>C;
   long ans = 0;
   if (C>=B) {
      ans += 2 * B;
      C -= B;
      if (C > A) ans += A+1;
      else ans += C;
   } else {
      ans = B+C;
   }
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = N.times.map { gets.chomp }
table = Hash.new { 0 }
S.each do |s|
  table[s] += 1
end
max = table.values.max
filtered = []
table.each do |s, c|
  if c == max
    filtered.push(s)
  end
end
filtered.sort!
filtered.each do |s|
  puts s
end

Measured memory_bytes: 40552
// #pragma GCC optimize("O3,no-stack-protector")
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx")
// AtCoder新ジャッジ以降
// #pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }

    Int ans = 0;
    if (n < m) {
        sort(x.begin(), x.end());
        vector<int> dif(m - 1);
        for (int i = 0; i < m - 1; i++) {
            dif[i] = x[i + 1] - x[i];
        }
        sort(dif.begin(), dif.end());
        ans = accumulate(dif.begin(), prev(dif.end(), n - 1), 0);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M,K=1;
ll T,a,b;
ll A,B,C,Q,l,r;
bool D[100005];
ll S[100005]={};
string str;
map<string,int> m;

int main(){
	cin>>A>>B;
	cout<<(A+B)%24;
	return 0;
}


Measured memory_bytes: 384
/*************************************************************************
    > File Name: a.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2019年12月22日 星期日 20时16分40秒
 ************************************************************************/

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    int a,b;
    scanf("%d%d", &a, &b);
    a = 6-a-b;
    printf("%d\n", a);
    return 0;
}



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

int main(void) {
	int h, w; cin >> h >> w;
	char a[h][w];
	int i, j;

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	for (i = 0; i < w + 2; i++) {
		cout << "#";
	}
  cout<<endl;
	for (i = 0; i < h; i++) {
		cout << "#";
		for (j = 0; j < w; j++) {
			cout << a[i][j];
		}
		cout << "#" << endl;
	}
	for (i = 0; i < w + 2; i++) {
		cout << "#";
	}

	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc160/tasks/abc160_c

use proconio::input;

fn main() {
    input! {
      k: i32, n: i32,
      mut a_s: [i32; n],
    }
    a_s.sort();
    let mut prev = -(k - a_s.last().unwrap());
    let mut max = 0;
    for a in a_s {
        let diff = a - prev;
        if max < diff {
            max = diff;
        }
        prev = a;
    }
    println!("{}", k - max);
}


Measured memory_bytes: 4392
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n , t=0;
    cin>>n;
    int *a = new int[n];
    for(int i = 0 ; i<n ; i++){
        cin>>a[i];
        if(a[i]%2 != 0 && i%2 ==0 )
            t++;
    }
    cout<<t;
    return 0;
}


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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}

int main()
{
	// cpc();
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// lli t;
	// cin >> t;
	// while (t--)
	// {
	lli n , sum = 0;

	cin >> n;
	forl(i, n)
	{
		if ((i % 3 != 0) && (i % 5 != 0))
		{
			sum += i;
		}

	}
	cout << sum << endl;
	// }
	return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  sort(all(a));
  cout << *(a.end()-1) - *a.begin() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N;
	string s[N];

	int ans = 0;
	int both = 0;
	int tailA = 0;
	int headB = 0;

	cin >> N;

	//long long N, M;
	//double d, e;
	for(int i=0; i<N; i++) {
		string str;
		cin >> str;
		int idx = 0;
		int pos;
		while((pos = str.find("AB", idx)) != -1) {
			ans++;
			idx = pos + 2;
		}
		if(str[0] == 'B' && str[str.size()-1] == 'A') {
			both++;
		} else if(str[0] == 'B') {
			headB++;
		} else if(str[str.size()-1] == 'A') {
			tailA++;
		}
	}

	if(tailA == 0 && headB == 0) {
		ans += max(0, both-1);

	} else {
		ans += min(tailA + both, headB + both);
	}
	
	cout << ans;
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<sstream>
#include<stack>
#include<map>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define maxn 210

int n, m,t;
int a[110000];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++)
	{
		if (a[i] >= a[i - 1])
		{
			if (a[i] > a[i - 1])
			{
				a[i]--;
			}
		}
		else
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main()
{
  string s,t;
  cin>>s>>t;
  int i=0;
  int z=t.size();
  while(s.size()-i>=t.size())
  {
    int r=0;
    for(int j=0;j<t.size();j++)
      if(s[i+j]!=t[j])
        r++;
    
    if(r<z)
      z=r;
    i++;
  }
    cout<<z<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    ll n;
    ll h[100000];
    ll dp[100000];
    cin >> n;
    rep(i,n){cin >> h[i];}

    rep(i,100000){
        dp[i] = INF;
    }
    dp[0] = 0;
    repi(i,1,n){
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if (i>1){
            chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] vals = new int[N];
		for (int i = 0; i < vals.length; i++) {
			vals[i] = sc.nextInt();
		}
		List<Pair> all = new ArrayList<>();
		for (int i = 0; i < M; i++) {
			all.add(new Pair(sc.nextInt(), sc.nextInt()));
		}
		Collections.sort(all, Collections.reverseOrder());
		Arrays.sort(vals);
		long ans = 0;
		int idx = 0, iPair = 0;
		while (idx < N && iPair < M) {
			Pair pair = all.get(iPair);
			if (pair.value > vals[idx]) {
				vals[idx] = pair.value;
				pair.cant--;
				if (pair.cant == 0) iPair++;
				idx++;
			} else break;
		}
		for (int i = 0; i < N; i++) {
			ans += vals[i];
		}
		
		out.println(ans);
		
		out.flush();
	}
	
	static class Pair implements Comparable<Pair> {
		int value, cant;
		
		public Pair(int cant, int value) {
			this.value = value;
			this.cant = cant;
		}
		
		@Override
		public int compareTo(Pair o) {
			return Integer.compare(value, o.value);
		}
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main() {
    ll N; cin >> N;
    ll x=0;
    vector<ll> div(10000000,0);

    for(ll i=1; i<=N; i++) {
        for(ll j=1; i*j<=N; j++) {
            div[i*j]++;
        }
    }

    for(ll k=1; k<=N; k++) {
       x += k*div[k];
    }
    cout << x << endl;
}

Measured memory_bytes: 81408
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

#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)


class UnionFind
{
    private:
        std::vector<int> parent;  // parent[x]: x の根の番号
                                  //            x が根の場合はその連結成分の大きさ
        std::vector<int> rank;    // rank[x]  : x が属する木の高さ
        std::size_t sz;           // 連結成分の数

    public:
        // x が親の場合、parent[x] = -(その連結成分の大きさ)
        UnionFind( std::size_t n ): parent(n, -1), rank(n, 0), sz(n) {}

        // x が属する集合の親を返し、x を親に直接繋ぎ直す(経路圧縮)
        int find( int x )
        {
            if( parent[x] < 0 ) return x;
            else return parent[x] = find( parent[x] );
        }

        // x が属する集合と y が属する集合を統合する
        bool unite( int x, int y )
        {
            x = find( x );
            y = find( y );
            if( x == y ) return false;

            // 大きい方(x)に小さい方(y)を繋げる
            if( rank[x] < rank[y] ) std::swap( x, y );

            parent[x] += parent[y];  // x に連結している成分の大きさを更新する
            parent[y] = x;           // y を x に繋ぐ
            if( rank[x] == rank[y] ) rank[x]++;
            sz--;

            return true;
        }

        bool same( int x, int y ) { return find(x) == find(y); }
        std::size_t size()        { return sz; }
        std::size_t size( int x ) { return - parent[find(x)]; }
};


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

    UnionFind uni(M);
    vector<bool> is_used(M, false);
    REP(i, N){
        int K, now, prev = -1;
        cin >> K;
        REP(j, K){
            cin >> now; --now;
            if(prev != -1) uni.unite(prev, now);
            is_used[now] = true;
            prev = now;
        }
    }

    int not_used = M - accumulate(is_used.begin(), is_used.end(), 0);
    bool can_commnucate = (uni.size() == not_used+1)? true: false;
    if(can_commnucate) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	if (A != C) {
		printf("1");
		return 0;
	}
	printf("0");
	return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
 
#define INF 1000000000
 
 
 
int main(){
  int n;
  cin >> n;
 
  while(n-->0){
    string s;
    cin >> s;
    string rs = string(s);
    reverse(s.begin(), s.end());
    int sz=s.size();
     
    set<string> m;
    m.insert(s);
    m.insert(rs);
    rep(i,sz){
      if(i==0)continue;
      string s1=s.substr(0,i), //ab
    s2=s.substr(i,sz-i),   //cd
    s3=rs.substr(sz-i,i),  //ba
    s4=rs.substr(0,sz-i);  //dc
 
      m.insert(s1+s4);
      m.insert(s3+s2);
      m.insert(s3+s4);
      m.insert(s2+s1);
      m.insert(s2+s3);
      m.insert(s4+s1);
    }
/*
    for(auto it : m)
      cout << it << endl;
*/
    cout << m.size() << endl;
  }
 
}

Measured memory_bytes: 1288