akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

struct edge {
    int to,len;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int l;
    cin >> l;
    if(l == 2) {
        cout << "2 2" << endl;
        cout << "1 2 0" << endl;
        cout << "1 2 1" << endl;
        return 0;
    }
    l--;
    int n = 0;
    int nl = l;
    while(nl > 0) {
        n++;
        nl /= 2;
    }
    vector<vector<edge>> ans(n);
    vector<int> pow2(25,1);
    rep2(i,1,25) pow2[i] = pow2[i-1]*2;
    rep(i,n-1) {
        ans[n-2-i].pb({n-1-i,0});
        ans[n-2-i].pb({n-1-i,pow2[i]});
    }
    int now = pow2[n-1];
    int m = 2*(n-1);
    rrep(i,n-1) {
        if(l>>i&1) {
            ans[0].pb({n-1-i,now});
            now += pow2[i];
            m++;
        }
    }
    ans[0].pb({n-1,now});
    m++;
    cout << n << " " << m << endl;
    rep(i,n) {
        for(auto e : ans[i]) {
            cout << i+1 << " " << e.to+1 << " " << e.len << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    bool before = false;
    rep(i, s.length())
    {
        if (!before)
        {
            ans++;
            before = true;
        }
        else
        {
            if (s[i - 1] == s[i])
            {
                if (i == s.length() - 1)
                    break;
                i++;
                before = false;
                ans++;
            }
            else
            {
                ans++;
                before = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

int main() {
	string str;
	cin >> str;
	REP(i, str.size()) {
		if (i == 3) { cout << "8"; }
		else {
			cout << str[i];
		}
	}
	cout << endl;

}

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

int main(){
    int n,cnt=1;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    int m=1;
   pair<int,string>p[n];
     p[0].first=1;
     p[0].second=s[0];
   for(int i=1;i<n;i++){
       if(s[i-1]==s[i]){
        cnt++;
       }
     else{
        cnt=1;
     }
       p[i].first=cnt;
       m=max(m,cnt);
       p[i].second=s[i];
   }
   sort(p,p+n);

    for(int i=0;i<n;i++){
            if(p[i].first==m)
                cout<<p[i].second<<"\n";
                        }

    }


Measured memory_bytes: 17408
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  string S; cin >> S;
  string cf = "CODEFESTIVAL2016";

  int result = 0;
  rep(i, 16) if (S[i]!=cf[i]) result++;
  cout << result << endl;
  return 0;
}

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

int main(){
	int p,q;
	int amari[80];
	int work,keta;
	int i;

	while(cin>>p>>q){
		keta=0;amari[keta]=p%q;
		while(1){
			work=amari[keta++]*10;
			amari[keta]=work%q;

			cout<<work/q;

			if(amari[keta]==0) break;
			i=0;while(i<keta && amari[i]!=amari[keta]) i++;
			if(i<keta) break;
		}
		cout<<endl;

		if(amari[keta]!=0){
			while(i--){cout<<' ';keta--;}
			while(keta--) cout<<'^';
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
// --------------------------------------------------</TEMPLATE>--------------------------------------------------


void solve()
{
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<s.length();i++)
    {
        ans=(ans%9+(s[i]-'0'))%9;
    }
    if(ans==0)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 3768
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=998244353;


main(){
    ll n=in();
    string s;cin>>s;
    ll dp[6]={};
    ll ans=1;
    rep(i,s.size()){
        if(s[i]=='R'){
            if(dp[5]){
                ans=(ans*dp[5])%MOD;
                dp[5]--;
            }
            else if(dp[1]){
                ans=(ans*dp[1])%MOD;
                dp[1]--;
                dp[3]++;
            }
            else if(dp[2]){
                ans=(ans*dp[2])%MOD;
                dp[2]--;
                dp[4]++;
            }
            else{
                dp[0]++;
            }
        }
        else if(s[i]=='G'){
            if(dp[3]){
                ans=(ans*dp[3])%MOD;
                dp[3]--;
            }
            else if(dp[0]){
                ans=(ans*dp[0])%MOD;
                dp[0]--;
                dp[4]++;
            }
            else if(dp[1]){
                ans=(ans*dp[1])%MOD;
                dp[1]--;
                dp[5]++;
            }
            else{
                dp[2]++;
            }
        }
        else{
            if(dp[4]){
                ans=(ans*dp[4])%MOD;
                dp[4]--;
            }
            else if(dp[0]){
                ans=(ans*dp[0])%MOD;
                dp[0]--;
                dp[3]++;
            }
            else if(dp[2]){
                ans=(ans*dp[2])%MOD;
                dp[2]--;
                dp[5]++;
            }
            else{
                dp[1]++;
            }
        }
    }
    rep2(i,1,n){
        ans=ans*i%MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 900
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int C[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K; cin >> K;
    cout << C[K - 1] << endl;

    return 0;
}


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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 201000;
struct Edge {int v, nxt;} a[N*4];
int head[N], Head[N], indeg[N];
int sz[N], pr[N];
bool vis[N];
int n, _;

inline void add(int x, int y, int*arr) {
	a[++_].v = y, a[_].nxt = arr[x], arr[x] = _;
}

const int p = 1e9+7;
int fac[N], ifac[N], inv[N];

int st[N], tp;
#define FID(i) for(int id=1,i;i=st[id],id<=tp;++id)

int X, Y;
int et, pt;

void bfs(int x, int las) {
	vis[st[++tp] = x] = true, ++pt;
	for(int i=head[x];i;++et,i=a[i].nxt)
		if(!vis[a[i].v]) bfs(a[i].v, x);
		else if(a[i].v != las) X = x, Y = a[i].v;
}

void tfs(int x, int las) {
	for(int i=head[x];i;i=a[i].nxt)
		if(a[i].v != las and a[i].v != X)
			pr[a[i].v] = x, tfs(a[i].v, x);
}

void dfs(int x, int las) {
	sz[x] = 1;
	for(int i=Head[x];i;i=a[i].nxt)
		if(a[i].v != las)
			dfs(a[i].v, x), sz[x] += sz[a[i].v];
}

int solve() {
	tfs(X, Y);
	pr[X] = Y;
	FID(i) Head[i] = indeg[i] = 0;
	FID(x) for(int i=head[x];i;i=a[i].nxt)
		if(a[i].v < pr[x]) add(x, a[i].v, Head), ++indeg[a[i].v];
	
	FID(i) if(!indeg[i]) dfs(i, i);
	int Ans = fac[pt];
	FID(i) Ans = (ll)Ans * inv[sz[i]]%p;
	return Ans;
}

int main() {
	read(n);
	for(int i=1,x,y;i<=(n<<1);++i) {
		read(x), read(y), y += n;
		add(x, y, head);
		add(y, x, head);
	}
	
	n <<= 1;
	fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
	for(int i=2;i<=n;++i) {
		fac[i] = (ll)fac[i-1] * i%p;
		inv[i] = (ll)(p-p/i) * inv[p%i]%p;
		ifac[i] = (ll)ifac[i-1] * inv[i]%p;
	}
	
	int Ans = fac[n];
	for(int i=1;i<=n;++i)
		if(!vis[i]) {
			tp = pt = et = 0;
			bfs(i, i);
			Ans = (ll)Ans * ifac[pt]%p;
			if((pt << 1) != et) return puts("0"), 0;
			int res = solve();
			swap(X, Y);
			res += solve();
			Ans = (ll)Ans * res%p;
		}
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long powK[105];

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

  powK[0] = 1;
  rep(i,n) powK[i+1] = powK[i]*(K+1)%MOD;

  vector<long> dp = {1};
  long ans = 0;
  for(int i=n; i>0; i--){
    vector<long> nxt(dp.size(), 0);
    rep(j,dp.size()) rep(k,K+1){
      // これまでにj回addされてて，自分の値はkでスタート
      long val = k + j;
      if(k<=i) val %= i;
      ans += val * powK[i-1] %MOD * dp[j];
      ans %= MOD;

      int nj = j;
      if(k<=i) nj = (j + (k+j)/i);
      if(nxt.size() <= nj) nxt.resize(nj+1, 0);
      nxt[nj] += dp[j];
      nxt[nj] %= MOD;
    }
    // dbg(nxt);
    swap(dp, nxt);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int A  = keyboard.nextInt();
		int B  = keyboard.nextInt();
		int C  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		String S = keyboard.next();
		
		String[] masu = S.split("");
		
		String ans = "Yes";
		if(C > D) {	
		  ans = "No";
          int count = 0;
          for(int m = B-2; m <= D; m++) {
            if(masu[m].equals("#")) {
                count = 0;
            } else {
                    count++;
                    if(count == 3) {
                        ans = "Yes";
                        break;
                    }
              }
            }	
        }
		
  		int StartB = B;	

		if(ans.equals("Yes")) {
			for(int i = B-1; i < D-1; i++) {
				if(masu[i+1].equals(".")) {
					StartB++;
				}else if(masu[i+2].equals(".")) {
					StartB+=2;
                  	i++;
				}else {
					ans = "No";
					break;
				}
			}
		}

		int StartA = A;
		
		if(ans.equals("Yes")) {
			for(int i = A-1; i < C-1; i++) {
				if(masu[i+1].equals(".")) {
					StartA++;
				}else if(masu[i+2].equals(".")) {
					StartA+=2;
                  	i++;
				}else {
					ans = "No";
					break;
				}
			}
		}
		
		System.out.println(ans);
		keyboard.close();	
	}
}


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

using namespace std;
typedef long long ll;
const int MAXN=2e5+10;
int x,n,pos[MAXN];
set<int> s;ll res=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x),pos[x]=i;
	s.insert(0);s.insert(n+1);
	for(int i=1;i<=n;i++)
	{
		set<int>::iterator it=s.lower_bound(pos[i]);
		int r=*it,l=*(--it);s.insert(pos[i]);
		res+=1ll*i*(pos[i]-l)*(r-pos[i]);
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>

int main(void){
    int a,b,c,tmp;
    
    scanf("%d",&a);
    scanf("%d",&b);
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    c=a%b;
    
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    printf("%d\n",b);
    
    return 0;
}


Measured memory_bytes: 2092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long h = sc.NextLong();
        long w = sc.NextLong();

        long answer = (n - h + 1) * (n - w + 1);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27480
s = gets.chomp
x = s[0..1].to_i
y = s[2..3].to_i

if (x > 12 && y > 12) || (x > 12 && y == 0) || (x == 0 && y > 12) || (x == 0 && y == 0)
  puts 'NA'
elsif 0 < x && x <= 12 && 0 < y && y <= 12
  puts 'AMBIGUOUS'
elsif 0 < y && y <= 12
  puts 'YYMM'
elsif x <= 12
  puts 'MMYY'
end


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  vector<string> s(n);

  rep(i, n) cin >> s[i];

  int a = 0, b = 0, c = 0;
  rep(i, n) {
    if (s[i].front() == 'B' && s[i].back() == 'A') ++c;
    else if (s[i].front() == 'B') ++b;
    else if (s[i].back() == 'A') ++a;
  }

  int ans = 0;
  rep(i, n) rep(j, si(s[i])-1) if (s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;

  if (a > 0 && c > 0) {
    --a;
    ++ans;
  }

  if (b > 0 && c > 0) {
    --b;
    ++ans;
  }

  ans += max(0, c-1);
  ans += min(a, b);

  cout << ans << endl;
}



Measured memory_bytes: 3720
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int A,B;
	cin >> A >> B;
	if(B%A==0){
		cout << A+B<<endl;
	}
	else{
		cout << B-A<<endl;
	}

	return 0;
}



Measured memory_bytes: 888
#include <iostream>
             #include <cstdio>
            using namespace std;
            
                int main()
                {
                 int a,b,n,bnew;
                scanf("%d%d",&a,&b);
                n=b-a;
               bnew=(n*(n+1))/2;
               printf("%d",(bnew-b));
                return 0;
             
                }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <fstream>

using namespace std;

long long mod = 1000000007;

void dfs(int p, int prev, vector<int> &a, vector<int> &dp, int dpl, vector<vector<int>> &v, vector<int> &res)
{
    int l = -1, r = dpl, mid;
    while (r - l > 1)
    {
        mid = (l + r) / 2;
        if (dp[mid] >= a[p])
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    int temp = dp[r];
    dp[r] = a[p];
    if (temp == -1)
    {
        dpl++;
    }
    res[p] = dpl;
    for (int i = 0; i < v[p].size(); i++)
    {
        if (v[p][i] == prev)
        {
            continue;
        }
        dfs(v[p][i], p, a, dp, dpl, v, res);
    }
    dp[r] = temp;
}

int main()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    // ifstream cin("in.txt");
    // ofstream cout("out.txt");
    
    
    // int t;
    // cin >> t;
    // for (int qwe = 0; qwe < t; qwe++)
    // {
    //     cout << "Case #" << qwe + 1 << ": ";
    // }


    string s, v;
    cin >> s >> v;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != v[i])
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int gcd(int a,int b){
    return (b?gcd(b,a%b):a);
}
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin >> n >> k;
    vector<int> a(n);
    mint K=k;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    mint ans=0;
    for(int i=0;i<n;i++){
        mint l=0,r=0;
        for(int j=0;j<n;j++){
            if(a[j]<a[i]){
                if(j<i){
                    l+=1;
                }
                else{
                    r+=1;
                }
            }
        }
        mint u=K*(K-1)/2,v=K*(K+1)/2;
        ans+=l*u+r*v;
    }
    cout << ans << endl;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (z < 0) continue;
      if (z > K) continue;
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n , a[N] , b[N];
map < int , bool > mp; 
main(){
	scanf("%d" , &n);
    for(int i = 1 ; i <= n; i++)
      	scanf("%d" , a + i) , b[i] = a[i];
	sort(b + 1, b + 1 + n);
  	for(int i = 1 ;  i <= n ; i++)
      	mp[b[i]] = i&1;
  	int pos = 1 , ans = 0;
  	for(int i = 1 ; i <= n ; i++)
      	if(mp[a[i]])
          	ans += abs(pos - i) % 2 , pos += 2;
 	cout << ans;
}

Measured memory_bytes: 5760
N = int(input())
ans = []

# 105 = 3 * 5 * 7
# yakusu = 1, 3, 5, 7, 15, 21, 35, 105

for i in range(1, N+1, 2):
    count = 0
    for j in range(1, i + 1):
        if i % j == 0:
            count += 1
    if count == 8:
        ans.append(i)

print(len(ans))

Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main(void){
	while(1){
		int n, m; cin >> n;
		if(n == 0) return 0;
		cin >> m;
		string s; cin >> s;
		string ans;
		rep(i, n) ans += "IO";
		ans += "I";
		int sum = 0;
		for (int i = 0; i < m; ++i){
			if(s[i] != 'I') continue;
			if(ans == s.substr(i, 2 * n + 1))
				sum++;
		}
		printf("%d\n", sum);
	}
}

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

int n;
ll a[200];
ll Max=INT_MIN;
bool b[105];

void dfs(int p,ll c){
	if(p==n+1){
		Max=max(Max,c);
		return;
	}
	ll cnt=0;
	for(int i=p;i<=n;i++){
		if(!b[i]&&a[i]>0)cnt+=a[i];
	}
	if(c+cnt<=Max)return;
	if(b[p]==1)dfs(p+1,c);
	else{
		map<int,bool>d;
		for(int j=p;j<=n;j+=p){
			d[j]=b[j];
			b[j]=1;
		}
		dfs(p+1,c);
		for(int j=p;j<=n;j+=p){
			b[j]=d[j];
		}
		dfs(p+1,c+a[p]);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	dfs(1,0);
	cout<<Max<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 1005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    int n,k,sum=0;
    sc(n)
    sc(k)
    for(int i=0;i<n;i++)
    {
        sc(arr[i])
    }
    sort(arr,arr+n);
    for(int i=0;i<k;i++)
     {
         sum+=arr[i];
     }
     cout<<sum;

}







Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int h, w;
	cin>>h>>w;
	int sx, sy;
	cin>>sx>>sy; sx--; sy--;
	int gx, gy;
	cin>>gx>>gy; gx--; gy--;
	vector<string> s(h);
	rep(i, h) cin>>s[i];

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

	queue<P> q, nq;
	q.push(make_pair(sx, sy));
	int cnt=0;
	bool ok=false;
	while(!q.empty()){
		while(!q.empty()){
			P p=q.front(); q.pop();
			int x=p.first, y=p.second;
			if(x==gx && y==gy){
				cout<<cnt<<endl;
				return 0;
			}
			if(s[x][y]=='#') continue;
			s[x][y]='#';
			rep(k, 4){
				int nx=x+dx[k], ny=y+dy[k];
				if(0<=nx && nx<h && 0<=ny && ny<w) if(s[nx][ny]=='.'){
					q.push(make_pair(nx, ny));
				}
			}
			for(int di= -2; di<=2; di++) for(int dj= -2; dj<=2; dj++){
				int nx=x+di, ny=y+dj;
				if(0<=nx && nx<h && 0<=ny && ny<w) if(s[nx][ny]=='.'){
					nq.push(make_pair(nx, ny));
				}
			}
		}
		swap(q, nq);
		cnt++;
	}

	cout<<(-1)<<endl;
	return 0;
}


Measured memory_bytes: 5916
N, M = map(int, input().split())
query = [[] for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    query[a].append(b)
nearest = [0] * (N + 1)
for i in range(1, N + 1):
    nearest[i] = min(query[i]) if len(query[i]) > 0 else 0

ans = 0
a_current = 0
b_current = N + 1
for i in range(1, N + 1):
    if nearest[i] > 0:
        a = i
        b = nearest[i]
        if a >= b_current:
            ans += 1
            a_current = a
            b_current = b
        else:
            a_current = a
            b_current = min(b_current, b)
ans += 1

print(ans)


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


using namespace std;

void Solution()
{
    int n;
    
    while (cin>>n, n)
    {
        vector<int> s(n), nextSequence(n);
        int count = 0;
        
        for (int i = 0; i < n; i++)
        {
            cin>>s[i];
        }
        
        while (1)
        {
            for (int i = 0; i < n; i++)
            {
                nextSequence[i] = 0;
                
                for (int j = 0; j < n; j++) //repeat this step for every element, so start from 0, everytime.
                {
                    if (s[i] == s[j])
                    {
                        nextSequence[i]++;
                    }
                }
            }
            
            if ( s == nextSequence)
            {
                cout<<count<<endl;
                
                for (int i = 0; i < n; i++)
                {
                    if (i != 0)
                    {
                        cout<<" ";
                    }
                    
                    cout<<s[i];
                }
                
                cout<<endl;
                break;
            }
            else
            {
                s = nextSequence;
                count++;
            }
        }
    }

}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N;
  cin>>N;
  cout<<(10000-N)%1000<<endl;
return 0;}


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

int main(){
	int h,w;
	cin>>h>>w;

	vector<vector<int>> arr(h,vector<int>(w));
	for(int i = 0; i < h; i++){
	 for(int j = 0; j < w; j++){
	  cin>>arr[i][j];
	 }
	}

	vector< tuple< int, int, int, int> > pr;

	for(int i = 0; i < h-1; i++){
		for(int j = 0; j < w; j++){
			if(arr[i][j]%2){
				arr[i+1][j]++;
				pr.push_back(make_tuple(i,j,i+1,j));
			}
		}
	}
	for(int i = 0; i < w-1; i++){
		if(arr[h-1][i]%2){
			arr[h-1][i+1]++;
			pr.push_back(make_tuple(h-1,i,h-1,i+1));
		}
	}

	cout<<pr.size()<<endl;
	for(auto p : pr){
		int a,b,c,d;
		tie(a,b,c,d) = p;
		cout<<a+1<<" "<<b+1<<" "<<c+1<<" "<<d+1<<endl;
	}
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    string s2;
    for(char c: s) {
        if (c != 'x') {
            s2 += c;
        }
    }
    int l = 0, r = s2.size()-1;
    while(l < r) {
        if (s2[l++] != s2[r--]) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> cnt_x(s2.size()+1, 0);
    int cnt = 0, idx = 0;
    for(char c: s){
        if (c != 'x') {
            cnt_x[idx++] = cnt;
            cnt = 0;
        } else {
            cnt++;
        }
    }
    if (cnt > 0) {
        cnt_x[idx++] = cnt;
    }
    int ans = 0;
    l = 0, r = cnt_x.size()-1;
    while (l < r)
        ans += abs(cnt_x[l++]-cnt_x[r--]);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 976
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
import heapq
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')


def main():
    # ダイクストラ
    def dijkstra(start, edge):
        costs=[inf]*N
        costs[start]=0
        hash={}
        queue=[(0, start)]  # 第一要素が優先的に評価されるので
        while queue:
            c, v=heapq.heappop(queue)
            if v in hash:
                continue
            hash[v]=1
            costs[v]=c
            for node, cost in edge[v]:
                if node in hash:
                    continue
                heapq.heappush(queue, (c + cost, node))

        return costs
    N = I()
    #Kからdijkstra
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = MI_()
        c+=1
        edge[a].append((b, c))
        edge[b].append((a,c))
    
    Q, K = MI()
    
    cost = dijkstra(K-1, edge)
    for _ in range(Q):
        x, y = MI_()
        print(cost[x]+cost[y])

    
    
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 94240
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int u = 0; u < 50; u++)
	{
		long n;
		long id[10000],a[10000],b[10000];
		int p = -1;
		int q = 0;

		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (long i = 0; i < n; i++)
		{
			cin >> id[i] >> a[i] >> b[i];
		}

		for (long i = 0; i < n; i++)
		{
			if (a[i] + b[i] > q)
			{
				p = 0;
				p = id[i];
				q = 0;
				q = a[i] + b[i];
			}
		}

		cout << p << " " << q << endl;
	}
}



Measured memory_bytes: 3320
<?php                                                                                                                                                          
                                                                                                                                                               
function fget_array()                                                                                                                                          
{                                                                                                                                                              
    return explode(' ', trim(fgets(STDIN)));                                                                                                                   
}                                                                                                                                                              
                                                                                                                                                               
$num = fget_array();                                                                                                                                           
$result = 0;                                                                                                                                                   
$i = 0;                                                                                                                                                        
foreach (fget_array() as $a) {                                                                                                                                 
    if ($i >= $num[0]) break;                                                                                                                                  
    if (empty($a)) continue;                                                                                                                                   
    $result += 1 / $a;                                                                                                                                         
    $i++;                                                                                                                                                      
}                                                                                                                                                              
$result = 1 / $result;                                                                                                                                         
echo $result.PHP_EOL; 

Measured memory_bytes: 4856
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  set<ll> st;
  REP(i,n){
    ll d;
    cin >> d;
    st.insert(d);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int x = fs.nextInt();
        final int[] arr = fs.nextIntArray(n);
        int res = Math.abs(x - arr[0]);
        for (int i = 0; i < n; i++) {
            res = gcd(res, Math.abs(x - arr[i]));
        }
        System.out.println(res);
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 45044
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())
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;
}
#define pb push_back
#define mp make_pair
#define mt make_tuple

int dfs(int v, vector<int> &dp, const vector<vector<int>>& edges) {
    if (dp[v] != -1) return dp[v];

    if (SIZE(edges[v]) == 0) {
        dp[v] = 0;
        return 0;
    }

    for (auto u: edges[v]) {
        chmax(dp[v], dfs(u, dp, edges) + 1);
    }
    return dp[v];
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edges(N);
    REP(m, M) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        edges[x].pb(y);
    }

    vector<int> dp(N, -1);

    REP(n, N) {
        dfs(n, dp, edges);
    }

    // REP(n, N) {
    //     cout << n << ": " << dp[n] << endl;
    // }

    int ans = 0;
    REP(n, N) chmax(ans, dp[n]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
ll abs(ll a, ll b){
  if(a-b>=0){
    return a-b;}
  else{
    return b-a;}
}

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

  ll a[n+1];
  ll sum=0;
  for(int i=1;i<=n;i++){
    ll p;
    cin>>p;
    a[i]=p;
    sum+=p;
  }
  
  ll minm=2020202020;
  minm*=200001;

  
  ll suml=0;
  for(int i=1;i<=n-1;i++){
    ll minmin=0;
    suml+=a[i];
    minmin=abs(suml, sum-suml);
    minm=min(minm, minmin);
  }
  
  cout<<minm<<endl;
  
 
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.println(a - 2 * b <= 0 ? 0 : a - 2 * b);
    }
}


Measured memory_bytes: 21844
n = int(input())
a = [int(x) for x in input().split()]

b = a[0]
bef = 0

for i in a:
  #print("bef1=", bef)
  if i >= bef:
    b = b + i
    #print("b1=", b)
  else:
    b = b - bef + i + i
    #print("b2=", b)
  bef = i
  #print("bef2=", bef)

print(b)


Measured memory_bytes: 2940