akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int M,D;
    cin >> M >> D;
    int ans=0;
    for(int m=1;m<=M;m++){
        for(int d=1;d<=D;d++){
            int d1=d%10;
            int d10=d/10;
            if(d1*d10==m&&d1>=2&&d10>=2){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o A.exe A.cpp 
Execute: ./A
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int d, t, s; 
	cin >> d >> t >> s; 
	
	if(s * t >= d) {
		cout << "Yes" << endl; 
	} else {
		cout << "No" << endl; 
	}
	
	return 0; 
} 


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

int main() {
	int a, b, c, list[11] = {0};
	cin >> a >> b >> c;
	++list[a];
	++list[b];
	++list[c];
	cout << (list[5] == 2 && list[7] == 1 ? "YES" : "NO") << endl;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINV(A, N) REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl

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

  S.at(4) == 0;
  S.at(7) == 0;

  if (atoi(&S.at(0)) <= 2019 && atoi(&S.at(5)) <= 4)
    ANS("Heisei");
  else
    ANS("TBD");

  return 0;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

def cal(A, N):
    cnt1 = 0
    cnt2 = 0
    for i in range(N):
        for j in range(i+1,N):
            if A[N-1-j] > A[N-1-i]:
                cnt1 += 1
    for i in range(N):
        for j in range(N):
            if A[N-1-i] < A[j]:
                cnt2 += 1
    
    return int(cnt1), int(cnt2)
    
    
x, y = cal(A,N)
R = int(1*10**9 +7)
tmp = K*(K-1)//2
ans =  tmp*y + x*K
print(int(ans%R))






Measured memory_bytes: 3188
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

typedef pair<int,int> ii;
typedef long long ll;

const int MOD = 1e9+7;

ll dp[101][int(1e5+1)];

void solve(){
    ll n,W;
    cin >> n >> W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++)
        cin >> w[i] >> v[i];
    for(ll i=0;i<W+1;i++){
        dp[0][i] = 0;
    }
    for(ll i=0;i<n+1;i++){
        dp[i][0] = 0;
    }
    ll ans = 0;
    memset(dp,0,sizeof(dp));
    for(ll j=1;j<=n;j++){
        for(ll i=1;i<=W;i++){
            dp[j][i] = dp[j-1][i];
            if(w[j-1]<=i){
                dp[j][i] = max(dp[j][i],dp[j-1][i-w[j-1]]+v[j-1]);
            }
            ans = max(ans,dp[j][i]);
            // cout << dp[j][i] << " ";
        }
        // cout << "\n";

    }
    // cout << dp[n][W];
    cout << ans;
}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 79232
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 1e3 + 5;
int n;
int X[N] , Y[N] , len[N];
char s[50];
int main()
{
	n = read(); int tmp = -1;
	for(int i = 1;i <= n;i ++)
	{
		X[i] = read(); Y[i] = read();
		if(tmp == -1) tmp = abs(X[i] + Y[i]) & 1;
		else if((abs(X[i] + Y[i]) & 1) != tmp) return puts("-1") , 0;
	}
	printf("%d\n1",32 - tmp);
	len[1] = 1; int cnt = 1;
	if(tmp) for(int i = 1;i <= 30;i ++) printf(" %d",len[++ cnt] = 1 << i);
	else for(int i = 0;i <= 30;i ++) printf(" %d",len[++ cnt] = 1 << i);
	puts("");
	for(int i = 1;i <= n;i ++)
	{
		ll x = 0 , y = 0 , dx , dy;
		for(int j = cnt;j >= 1;j --)
		{
			dx = X[i] - x; dy = Y[i] - y;
			if(abs(dx) > abs(dy)) 
			{
				if(dx > 0) x += len[j] , s[j] = 'R';
				else x -= len[j] , s[j] = 'L';
			}
			else
			{
				if(dy > 0) y += len[j] , s[j] = 'U';
				else y -= len[j] , s[j] = 'D';
			}
		}
		printf("%s\n",s + 1);
	}
	return 0;
}

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

struct Card { char suit, value; };

void bubble(struct Card A[],int N){
  for(int i = 0; i < N; i++){
    for(int j = N - 1; j >= i + 1; j--){
      if(A[j].value < A[j - 1].value){
	Card t = A[j];
	A[j] = A[j - 1];
	A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    if (i > 0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
   for(int i = 0; i < N; i++){
     if(C1[i].suit != C2[i].suit)return false;
   }
   return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0; i < N; i++)C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }
  else {
    cout << "Not stable" << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] v = new long[n];
        for (int i = 0; i < n; i++) v[i] = sc.nextLong();
        long ans = 0L;
        int max = Math.min(n, k);
        for (int l = 0; l <= max; l++) {
            for (int r = 0; r <= max - l; r++) {
                long tmp = 0L;
                PriorityQueue<Long> pq = new PriorityQueue<>();
                for (int i = 0; i < l; i++) {
                    tmp += v[i];
                    if(v[i] < 0) pq.add(v[i]);
                }
                for (int i = 0; i < r; i++) {
                    tmp += v[n-1-i];
                    if(v[n-1-i] < 0) pq.add(v[n-1-i]);
                }
                int cnt = 0;
                while(0 < k -l -r -cnt && !pq.isEmpty()){
                    tmp -= pq.poll();
                    cnt++;
                }
                if(ans < tmp) ans = tmp;
            }
        }

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

    }

}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

template <int MOD>
struct modint {
  int v; modint(int val=0) : v(val) { if ((v%= MOD) < 0) v += MOD; }
  modint& operator += (const modint& b) { (v += b.v) %= MOD; return *this; }
  modint& operator -= (const modint& b) { return (*this) += MOD-b.v; }
  modint& operator *= (const modint& b) { v = ((ll)v*(ll)b.v) % MOD; return *this; }
  modint& operator /= (const modint& b) { return (*this) *= b.pow(MOD-2); }
#define _op(op, op2) modint operator op (const modint& b) const { modint ans = *this; return ans op2 b; }
  _op(+, +=); _op(-, -=); _op(*, *=); _op(/, /=);
#undef _op
  modint pow(ll e) const { modint res(1), b(*this); for (; e>0; e/=2, b*=b) { if (e&1) res*=b; } return res; }
};

using mi = modint<(int)1e9+7>;

const int N = 1e5+5, D = 102;
string k;
int d;
mi dp[N][D][2];
bool vis[N][D][2];

mi solve(int i, int m, bool tight) {
  if (i == k.size()) {
    return m == 0;
  }
  if (!vis[i][m][tight]) {
    if (tight) {
      int maxd = k[i] - '0';
      dp[i][m][1] += solve(i+1, (m+maxd)%d, 1);
      for (int j = 0; j < maxd; ++j) {
        dp[i][m][1] += solve(i+1, (m+j)%d, 0);
      }
    } else {
      for (int j = 0; j < 10; ++j) {
        dp[i][m][0] += solve(i+1, (m+j)%d, 0);
      }
    }
    vis[i][m][tight] = 1;
  }
  return dp[i][m][tight];
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> k >> d;
  mi ans = solve(0, 0, 1) - 1;
  cout << ans.v << nl;

  return 0;
}



Measured memory_bytes: 84224
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

vector<string> parse(string s, char c) {
	string t = "";
	vector<string> res;
	rep(i, s.size()) {
		if (s[i] == c) {
			res.pb(t);
			t = "";
		}
		else {
			t += s[i];
		}
	}
	if (t != "") res.pb(t);
	return res;
}

int main() {
	for(string e; cin >> e, e != "#"; ) {
		vector<string> cs = parse(e, '|');
		bool isok = false;
		rep(i, cs.size()) {
			vector<string> vs = parse(cs[i].substr(1, cs[i].size() - 2), '&');
			bool no = false;
			rep(j, vs.size()) rep(k, vs.size()) {
				if (vs[j] == "~" + vs[k]) {
					no = true;
				}
			}
			isok |= !no;
		}
		if (isok) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n,k;
ll a[10000];
ll sum[10010];
ll cnt[10010];
bool f[2000000];

int main(){
	cin >> n >> k;
	rep(i,n)cin >> a[i];
	rep(i,n)sum[i+1] = sum[i] + a[i];
	vector<ll> vl;
	rep(i,n+1){
		FOR(j,i+1,n+1)vl.push_back(sum[j] - sum[i]);
	}
	ll ans = 0;
	rep(j,45){
		ll cnt = 0;
		rep(i,vl.size()){
			if(f[i])continue;
			if(vl[i] & (1LL << (44-j)))cnt++;
		}
		if(cnt >= k){
			rep(i,vl.size()){
				if((vl[i] & (1LL << (44-j))) == 0)f[i] = 1;
			}
			ans |= (1LL << (44-j));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6128
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

int main() {
    int n; cin >> n;
    while (n--) {
        vector<pair<double, double>> p(4);
        for (int i = 0; i < 4; i++) {
            double x, y; cin >> x >> y;
            p[i] = {x, y};
        }

        double l1_r = p[1].first - p[0].first;
        double l1_i = p[1].second - p[0].second;
        double l2_r = p[3].first - p[2].first;
        double l2_i = p[3].second - p[2].second;

        if (abs(l1_r * l2_i - l1_i * l2_r) < 1e-10)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
    string s; cin >> s;
    ll ans = 0;
    rep(i, (1<<s.size()-1)) {
        ll cur = s[0] - '0';
        rep(j, s.size()-1) {
            if(i & (1<<j)) {
                ans += cur;
                cur = s[j+1] - '0';
            }
            else {
                cur *= 10;
                cur += s[j+1] - '0';
            }
        }
        ans += cur;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::vector<long> heights(n);
  for (auto& h : heights) {
    std::cin >> h;
  }
  std::deque<bool> is_goods(n, true);

  for (int i = 0; i < m; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a;
    --b;
    if (heights.at(a) <= heights.at(b)) is_goods.at(a) = false;
    if (heights.at(b) <= heights.at(a)) is_goods.at(b) = false;
  }

  std::cout << std::setprecision(20);
  std::cout << std::count(is_goods.begin(), is_goods.end(), true) << std::endl;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

int INF = 1001001001;

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

ll gcd(ll a, ll b) {
    if (b == INF) return a;
    if (a == INF) return b;
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}


struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    // 元配列 v をセグメント木で表現する
    SegmentTree(vector<int> v) {
        // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        // セグメント木全体で必要なノード数は 2n-1 個である
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);

        // 最下段に値を入れたあとに、下の段から順番に値を入れる
        // 値を入れるには、自分の子の 2 値を参照すれば良い
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = gcd(node[2*i+1], node[2*i+2]);
    }
    void update(int x, int val) {
        // 最下段のノードにアクセスする
        x += (n - 1);

        // 最下段のノードを更新したら、あとは親に上って更新していく
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = gcd(node[2*x+1], node[2*x+2]);
        }
    }
    int getgcd(int a, int b, int k=0, int l=0, int r=-1) {
        // 最初に呼び出されたときの対象区間は [0, n)
        if(r < 0) r = n;

        // 要求区間と対象区間が交わらない -> 適当に返す
        if(r <= a || b <= l) return INF;

        // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
        if(a <= l && r <= b) return node[k];

        // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        // 左側の子を vl ・ 右側の子を vr としている
        // 新しい対象区間は、現在の対象区間を半分に割ったもの
        int vl = getgcd(a, b, 2*k+1, l, (l+r)/2);
        int vr = getgcd(a, b, 2*k+2, (l+r)/2, r);
        return gcd(vl, vr);
    }
};

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    SegmentTree st(as);
    ll m = 0;
    rep(i, n) {
        chmax(m, gcd(st.getgcd(0, i), st.getgcd(i + 1, n)));
    }
    cout<<m<<endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
  int a,b;
  char op;

  while(cin >> a >> op >> b){
    if(op=='+'){
      cout << a + b <<  endl;
    }
    if(op=='-'){
      cout << a - b <<  endl;
    }
    if(op=='*'){
      cout << a * b <<  endl;
    }
    if(op=='/'){
      cout << a / b <<  endl;
    }
    if(op=='?'){
     break;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3088
import Control.Applicative
import Data.List

main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  field <- lines <$> getContents

  let
    red = [if odd i then reverse ('.' : replicate (w-1) '#') else '#' : replicate (w-1) '.' | i<-[1..h]]
    blue = [if odd i then reverse ('#' : replicate (w-1) '.') else '.' : replicate (w-1) '#' | i<-[1..h]]

  let
    red' = add red field
    blue' = add blue field

  --mapM_ print $ mul red' blue'

  mapM_ putStrLn $ red'
  putStrLn ""
  mapM_ putStrLn $ blue'
  


f '#' '#' = '#'
f '.' '.' = '.'
f _ _ = '#'

g '#' '#' = '#'
g _ _ = '.'

add a b = zipWith (zipWith (\x y -> f x y)) a b

mul a b = zipWith (zipWith (\x y -> g x y)) a b


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int a[maxn];

int dist[maxn];

int main()
{
  MSET(dist, -1);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;

  for(int i = 1 ; i <= n; i++)
    cin >> a[i];

  dist[1] = 0;
  int cnt = 0;
  int pos = 1;
  while(k--)
  {
    cnt++;
    pos = a[pos];
    if(dist[pos] == -1)
    {
      dist[pos] = cnt;
    }
    else
    {
      int p = cnt - dist[pos];
      k %= p;
    }
  }

  cout << pos << endl;

  return 0;
}

Measured memory_bytes: 5148
#include<iostream>

int main() {
  int sum, num_sum;
  std::cin >> num_sum >> sum;
  int count = 0;
  for (int i=0; i < num_sum+1; i++) {
    for (int j=0; j < num_sum+1; j++) {
      if (sum -(i + j) < num_sum+1 && sum -(i+j) > -1) {
        count++;
      }
    }
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
m = len(s)
l = len(t)
ans = m
for i in range(m-l+1):
  defe = 0
  for j in range(l):
    if t[j] != s[i+j]:
      defe += 1
  ans = min(defe, ans)
  
print(ans)

Measured memory_bytes: 9120
N=int(input())
ans=0
re=0
for _ in range(N):
  a=int(input())
  if a%2==0:
    ans+=a//2
    if a==0:
      re=0
  else:
    if re==1:
      ans+=a//2+1
      re=0
    else:
      ans+=a//2
      re=1
      
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    long long a = 0;
    int b = 0;
    scanf("%d",&n);
    while(n--){
        a++;
        int sum = 0;
        long long aa = a;
        while(aa){
            sum += (int)(aa % 10);
            aa /= 10;
        }
        if(sum + (b * 9) < a || (sum + (b * 9) == a && b > 0)){
            b++;
            a /= 10;
        }
        printf("%lld", a);
        for(int i=0;i<b;i++) printf("9");
        printf("\n");
    }
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
graph = {i: set() for i in range(1, N + 1)}
banned = {i: set() for i in range(1, N + 1)}

for _ in range(M):
    A, B = map(int, input().split())
    graph[A].add(B)
    graph[B].add(A)

for _ in range(K):
    C, D = map(int, input().split())
    banned[C].add(D)
    banned[D].add(C)

# BFS
group = {i: -1 for i in range(1, N + 1)}
count = {i: 0 for i in range(1, N + 1)}
for i in range(1, N + 1):
    if group[i] >= 0:
        continue
    queue = [i]
    group[i] = i
    count[i] += 1
    while queue:
        new = []
        for cur in queue:
            for nxt in graph[cur]:
                if group[nxt] == -1:
                    group[nxt] = group[cur]
                    count[group[nxt]] += 1
                    new.append(nxt)
        queue = new

res = [0] * N
# Remove itself
for i in range(N):
    res[i] = count[group[i + 1]] - 1

# Remove friends and blocked users
for i in range(N):
    for j in banned[i + 1]:
        if group[i + 1] == group[j]:
            res[i] -= 1
    for j in graph[i + 1]:
        if group[i + 1] == group[j]:
            res[i] -= 1
print(*res)

Measured memory_bytes: 126352
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    ll=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ll[j]+=1
    

    ans=0
    for k,v in enumerate(ll):
        if k==0: continue
        ans+=k*v

    print(ans)
        

    
resolve()

Measured memory_bytes: 146048
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define sz(x) (int)x.size()
#define el '\n'
#define M 10e9 + 7 
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int x=n%100;
  int y=n/100;
  if(x>0 && x<=12 && y>0 && y<=12 )cout<<"AMBIGUOUS"<<el;
  else if(x>0 && x<=12)cout<<"YYMM"<<el;
  else if(y>0 && y<=12)cout<<"MMYY"<<el;
  else cout<<"NA"<<el;
  return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  int h, w;
  cin >> h >> w;
  int cnt = 0;
  rep(i,h)rep(j,w) {
    char c;
    cin >> c;
    if(c == '#') cnt++;
  }
  if(cnt == h+w-1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3600
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()

p=0

ori_d=[]
for i in range (N):
    _d=a[i]-b[i]
    ori_d.append([i,_d])

d=sorted(ori_d,key=lambda x: x[1])
d2=[0]*N
for j in range (N):
    if d[j][1]>=0:
        break
    else:
        p+=abs(d[j][1])
        d2[j]+=1

for k in range (N-1,0,-1):
    if p==0:
        break
    elif d[k][1]<p:
        p-=d[k][1]
        d[k][1]=0
        d2[k]+=1
    else:
        d[k][1]-=p
        p=0
        d2[k]+=1

print(sum(d2))

Measured memory_bytes: 30260
<?php
/*
    http://code-festival-2016-qualb.contest.atcoder.jp/tasks/codefestival_2016_qualB_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d %d", $N, $A, $B);
fscanf(STDIN, "%s", $S);
$arrS = str_split($S);
$kakutei = 0;
$countB = 0;

for ($i = 0; $i < $N; $i++) {
	switch ($arrS[$i]) {
		case "a":
			if ($kakutei < $A + $B) {
				echo "Yes" . PHP_EOL;
				$kakutei++;
			} else {
				echo "No" . PHP_EOL;
			}
			break;

		case "b":
			if (
				($kakutei < $A + $B) && 
				($countB < $B)
			) {
				echo "Yes" . PHP_EOL;
				$kakutei++;
			} else {
				echo "No" . PHP_EOL;
			}
			$countB++;
			break;

		case "c":
			echo "No" . PHP_EOL;
			break;
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n >> m;
    cout << max(n - m, 0) << endl;
    return 0;
}


Measured memory_bytes: 3684
import java.util.*;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
	
	public static HashMap<String,String> map = new HashMap<>();


	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int r = sc.nextInt();
		int ans = 0;
		if(h + r == 0) ans = 0;
		else if(h + r < 0) ans = -1;
		else ans = 1;
		System.out.println(ans);
	}
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v;
    while(n--){
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    int sum = 0;
    int i = 0;
    while (i < k){
        sum += v[i];
        i++;
    }
    cout << sum << endl;
}

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

int main() {
  int r=0,b=0;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='0') r++;
    else b++;
  };
  cout << min(r,b)*2 << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline
def main():
    def Dfs(G, v, cur=0):
        color[v] = cur % 2
        for next_v in G[v]:
            if color[next_v[0]] != -1:
                continue
            Dfs(G, next_v[0], cur+next_v[1])


    n = int(input())
    e = [[0, 0, 0]] + [list(map(int, input().split())) for i in range(n-1)]
    g = [[] for i in range(n+1)]

    for i in range(1, n):
        g[e[i][0]].append([e[i][1], e[i][2]])
        g[e[i][1]].append([e[i][0], e[i][2]])

    color = [-1 for i in range(n+1)]
    for v in range(1, n+1):
        if color[v] != -1:
            continue
        Dfs(g, v)

    for i in range(1, n+1):
        print(color[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 113444
#include <iostream>
#include <stdlib.h>

using namespace std ;


int main()
{
    int a, b, c, distance ;

    cin >> a >> b >> c >> distance ;

    if ( abs( a - c ) <= distance )
        cout << "Yes" << endl ;
    else if ( abs( a - b ) <= distance && abs( b - c ) <= distance )
        cout << "Yes" << endl ;
    else
        cout << "No"  << endl ;

    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int an=0;
  string s,t="CODEFESTIVAL2016";
  cin>>s;
  for(int i=0;i<16;i++)if(s[i]!=t[i])an++;
  cout<<an<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	printf("%d\n", n * (n - 1) / 2 - n / 2);
	if (n % 2 == 0)
	{
		for (i = 1; i < n; i++)
			for (j = i + 1; j <= n; j++)
				if (i + j != n + 1)
					printf("%d %d\n", i, j);
	}
	else
	{
		for (i = 1; i < n; i++)
			for (j = i + 1; j <= n; j++)
				if (i + j != n)
					printf("%d %d\n", i, j);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
#ifndef ONLINE_JUDGE
	// freopen("out.txt", "w", stdout);
#endif
	int x;
	cin >> x;
	int cur = 100;
	for(int i = 0; i <= 3760; ++i) {
		if(cur >= x) {
			cout << i << endl;
			return 0;
		}
		cur += cur / 100;
	}


    
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<queue>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin >> n;
  int b[n-1];
  for(int i=0;i<n-1;++i) cin >> b[i];
  
  int sum=b[0];
  for(int i=0;i<n-2;++i){
    sum+=min(b[i], b[i+1]);
  }
  sum+=b[n-2];

  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 256
my $N=<>;
my $s=<>;chomp $s;
my @A = split(/ /,$s);
my $mod = 10**9+7;


my $sum =0;
my $cal =0;

for(my $i=0;$i<=($#A-1);$i++ ){
    
    $cal = ( $cal + $A[$i])%$mod;
    $sum = ($sum +  $cal * $A[$i+1])%$mod;
     
}

print "$sum";

Measured memory_bytes: 27156
R=range(3)
def op(x,y,i):
    if i=="+": return x+y
    elif i=="-": return x-y
    elif i=="*": return x*y

e0 = '((({0} {1} {2}) {3} {4}) {5} {6})'
e1 = '(({0} {1} {2}) {3} ({4} {5} {6}))'
def check(A, n):
    w,x,y,z = A
    S="+-*"
    for i in S:
        a = op(w,x,i)
        for j in S:
            b = op(a,y,j)
            for k in S:
                if op(b,z,k)==n: return e0.format(w,i,x,j,y,k,z)
            b = op(y,z,j)
            for k in S:
                if op(a,b,k)==n: return e1.format(w,i,x,k,y,j,z)
    return ''

def permutations(L):
    if L==[]: return [[]]
    s= [[h]+t for i,h in enumerate(L) for t in permutations(L[:i]+L[i+1:])]
    return s

n=10
while 1:
    x = map(int,raw_input().split())
    if x==[0,0,0,0]:break
    x = permutations(x)
    for e in x:
        s = check(e,n)
        if s!="": break
    else: s = "0"
    print s

Measured memory_bytes: 4288
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mid ((x+y)/2)
#define timer printf("\n%lf seconds.\n",(double)clock()/CLOCKS_PER_SEC)
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define d3(x,y,z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
using namespace std;
typedef pair<int,int> ii;
typedef string string;
typedef long long int lli;
const int N=(int)(1e6+5);
int n;
int main() 
{
	// freopen("inp.in","r",stdin);
	// freopen("out.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(b+c>a || (a-b-c)%2) 
		{
			printf("No");
			return 0;	
		}	
	}
	printf("Yes");
}	

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

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

ll N;
constexpr ll DP_MAX = 100010;
ll dp[DP_MAX][3];
vector<ll> A, B, C;

int main(int argc, char **argv)
{
	cin >> N;
	A.resize(N), B.resize(N), C.resize(N);
	for (ll i = 0; i < N; ++i) cin >> A[i] >> B[i] >> C[i];
	for (ll i = 0; i < DP_MAX; ++i)
		for (ll j = 0; j < 3; ++j)
			dp[i][j] = -(1ll<<50);
	dp[0][0] = dp[0][1] = dp[0][2] = 0;

	for (ll i = 1; i <= N; ++i)
	{
		// chmax(dp[i+1][0], max(dp[i][1]+A[i], dp[i][2]+A[i]));
		// chmax(dp[i+1][1], max(dp[i][0]+B[i], dp[i][2]+B[i]));
		// chmax(dp[i+1][2], max(dp[i][0]+C[i], dp[i][1]+C[i]));
		chmax(dp[i][0], max(dp[i-1][1]+A[i-1], dp[i-1][2]+A[i-1]));
		chmax(dp[i][1], max(dp[i-1][0]+B[i-1], dp[i-1][2]+B[i-1]));
		chmax(dp[i][2], max(dp[i-1][0]+C[i-1], dp[i-1][1]+C[i-1]));
		
	}
	std::cout << max({dp[N][0], dp[N][1], dp[N][2]})<< std::endl;
}


Measured memory_bytes: 4992
class BinaryIndexedTree
  def initialize(arg)
    if arg.is_a?(Array)
      @n   = arg.size
      @bit = Array.new(@n + 1){ 0 }
      arg.each_with_index { |e, i| add(i, e) }  
    else
      @n   = arg
      @bit = Array.new(@n + 1){ 0 }
    end
  end

  def sum(i)
    i += 1
    res = 0
    while i > 0
      res += @bit[i]
      i -= ( i & -i )
    end
    res
  end

  def add(i, x)
    i += 1
    while i <= @n
      @bit[i] += x
      i += ( i & -i )
    end
  end
end

n, q = gets.split.map { |e| e.to_i }
a    = gets.split.map { |e| e.to_i }

bit = BinaryIndexedTree.new(a)

q.times do
  query = gets.split.map { |e| e.to_i }

  if query[0] == 0
    _, q, x = query
    bit.add(q, x)
  else
    _, l, r = query
    puts bit.sum(r-1) - bit.sum(l-1)
  end
end

Measured memory_bytes: 57384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b;
  cin>>a>>b;
  int count=0;
  for(int i=a;i<=b;i++){
    string s=to_string(i);
    string s1=s;
    reverse(s.begin(),s.end());
    if(s1==s) count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int m,n1,n2;
    int p[300];
    while(cin>>m>>n1>>n2,m){
        for(int i=0;i<m;i++) cin>>p[i];
        sort(p,p+m);
        reverse(p,p+m);
        int mx_g=0,mx_m=0;
        for(int i=0;i<m;i++){
            if(i<n1-1 || i>n2-1 || n1-1<0 || n2-1>m-1) continue;
            if(p[i]-p[i+1]>=mx_g){
                mx_g=p[i]-p[i+1];
                mx_m=max(mx_m,i+1);
            }
        }
        cout<<mx_m<<endl;
    }
    return 0;
}




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

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

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <ll mod>
class modint
{
public:
    constexpr modint(ll value = 0) : _value(value >= 0 ? value % mod : (value % mod) + mod) {}

    constexpr modint operator+() const { return *this; }
    constexpr modint operator-() const { return modint(-_value); }

    constexpr modint &operator+=(const modint &rhs) {
        if ((_value += rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
        if ((_value += mod - rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
        (_value *= rhs._value) %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
        *this *= rhs.inv();
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }

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

    constexpr bool operator==(const modint &rhs) const { return _value == rhs._value; }
    constexpr bool operator!=(const modint &rhs) const { return _value != rhs._value; }

    constexpr modint inv() const {
        ll a = _value, b = mod, u = 1LL, v = 0LL;
        while (b > 0) {
            ll tmp = a / b;
            a -= tmp * b; swap(a, b);
            u -= tmp * v; swap(u, v);
        }
        return modint(u);
    }

    constexpr modint pow(ll n) const {
        modint e = *this, res = 1;
        while (n) {
            if (n & 1) res *= e;
            e *= e, n >>= 1;
        }
        return res;
    }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m._value;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }

private:
    ll _value;
};
using mint = modint<998244353>;

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

    int n, s; cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<vector<mint>> dp(n + 1, vector<mint>(s + 1, 0));
    for (int i = 0; i < n; i++) dp[i][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i + 1][j] += dp[i][j];
            if (j - a[i] >= 0) {
                dp[i + 1][j] += dp[i][j - a[i]];
            }
        }
    }

    mint ans = 0;
    for (int i = 0; i <= n; i++) ans += dp[i][s];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
s=list(input())

if s[0]=='A' and s[1].islower():
    s=s[2:]
    if s[:len(s)-1].count('C')==1:
        s_last=s[-1]
        s=s[:len(s)-1]
        s.remove('C')
        s=s+[s_last]
        for i in range(len(s)):
            if not s[i].islower():
                print("WA")
                exit()    
        print("AC")
        exit()
print("WA")

Measured memory_bytes: 3064
#include<stdio.h>
#define size 200


int main( )
{
    int n , num[size] , i , j , count= 0 , sum , x , max , k ;
    
    scanf("%d%d" , &n , &x);
    for( i = 1 , sum = 0; i <= n ; i++)
    {
        scanf("%d" , &num[i] );
        sum += num[i] ;
    }
    
    if( (sum-x) == 0)
        printf("%d\n" , n);
        
    else 
    {
        sum = x- sum ;
        i = 1 ;
        max = 0 ;
        for( i = 1 ; i <= n ; i++)
        {
            k = sum ;
            count = 0 ;
            while( k)
            {
                k = k - num[i] ;
                count++ ;
                if( k < num[i])
                    break ;
            }
            if( count >= max)
                max = count ;
        }
        printf("%d\n" , max+n);
    }
    
    return 0;    
}


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

int main(){
	int n,l;
	cin >> n >> l;
	string s[n];
	for(int i = 0;i < n;i++) cin >> s[i];
	stable_sort(s,s + n);
	for(int i = 0;i < n;i++) cout << s[i];
	cout << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll n;cin>>n;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  ll count=0,a=0,b=0,ab=0;
  rep(i,n){
    rep(j,s[i].size()-1){
      if(s[i][j]=='A'&&s[i][j+1]=='B')count++;
    }
    if(s[i][0]=='B'&&s[i][s[i].size()-1]!='A')b++;
    if(s[i][0]!='B'&&s[i][s[i].size()-1]=='A')a++;
    if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')ab++;
  }
  if(ab==0)cout<<count+min(a,b)<<endl;
  else if(a+b==0)cout<<count+ab-1<<endl;
  else cout<<count+ab+min(a,b)<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N; cin >> N;
    int H[N+1]; H[0] = 0; for(int i = 1; i <= N; i++) cin >> H[i];
    int dp[N+1]; dp[0] = 0;
    for(int i = 1; i <= N; i++){
        if(i == 1) { dp[i] = 0; continue; }
        if(i == 2) { 
            int cost = H[i] - H[i-1];
            if(cost < 0) cost *= -1;
            dp[i] = cost;
            continue;
        }
        int cost1 = H[i] - H[i-1];// + dp[i-1];
        int cost2 = H[i] - H[i-2];// + dp[i-2];
        if(cost1 < 0) cost1 *= -1;
        if(cost2 < 0) cost2 *= -1;
        cost1 += dp[i-1];
        cost2 += dp[i-2];
        dp[i] = min(cost1, cost2);
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define N 1000

typedef struct array{
	int *a;
	int num;
}array;

int main(){
	int n,q,i,com,x,y;
	array S[N];
	
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		S[i].a=malloc(sizeof(int)*q);
		S[i].num=0;
	}
	
	for(i=0;i<q;i++){
		scanf("%d",&com);
		
		if(com==0){
			scanf("%d %d",&x,&y);
			S[x].a[S[x].num++]=y;
		}
		
		if(com==1){
			scanf("%d",&x);
			if(S[x].num==0)printf("\n");
			else {
				for(int j=0;j<S[x].num-1;j++)printf("%d ",S[x].a[j]);
				printf("%d\n",S[x].a[S[x].num-1]);
			}
		}
		
		if(com==2){
			scanf("%d",&x);
			free(S[x].a);
			S[x].a=malloc(sizeof(int)*(q-i));
			S[x].num=0;
		}
		
	}
	
	return 0;
	
}


Measured memory_bytes: 208552
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0;
  cin>>n;
  string input;
  vector<string> reward;
  for(int i=1;i<=n;i++)
  {
   cin>>input;
    reward.push_back(input);


  }
  sort(reward.begin(),reward.end());
   for(int i=1;i<n;i++)
  {
  if(reward[i-1]!=reward[i])
    c++;


  }



cout<<c+1;



}


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

using namespace std;

#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 rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void) {

	int x = 0;
	int i = 0; 
	scanf("%d", &x);


	
	while(x>0){
		
		
		printf("Case %d: %d\n", ++i, x);

		scanf("%d", &x);
	}


	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#define mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii map<int,int>
#define mll map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
int n;
string str;	
ll dp[3005][3005];

int main(){
	boost;
	cin>>n;
	cin>>str;
	
	dp[1][1] = 1;
	for(int i = 2;i<=n;i++){
		for(int j = 1;j<=n;j++){
			int l = 0,r = 0;
			if(str[i-2]=='<'){
				l = 1;
				r = j -1;
			}else{
				l = j;
				r = i-1;
			}
			
			if(l<=r){
				dp[i][j] = (dp[i-1][r] - dp[i-1][l-1] + mod)%mod;
			}
		
		}
		
		for(int j = 1;j<=n;j++){
			dp[i][j] = (dp[i][j-1] + dp[i][j])%mod;
		}
	}
	
	cout<<dp[n][n];
	return 0;
}



Measured memory_bytes: 74068
#include<iostream>
#include<string>
#include<algorithm>
#include<set>

using namespace std;
set<char> st;

bool check(string s){
    set<char> st2;
    for(int i=0; i<s.size(); i++){
        st2.insert(s[i]);
    }
    for(char c='0'; c<='9'; c++){
        if(st.count(c)==1&&st2.count(c)==1) return false;
    }
    return true;
}

int main(){

    int N, K;
    cin>> N>> K;
    vector<char> D(K);
    for(int i=0; i<K; i++){
        cin>> D[i];
    }

    for(int i=0; i<K; i++){
        st.insert(D[i]);
    }
    auto n=to_string(N);
    while(1){
        if(check(n)){
            cout<< n<< endl;
            break;
        }
        n.clear();
        n=to_string(++N);
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
char a[37],a1[37],a2[37];
int b[37],b1[37],b2[37];
int n,t;
void mpsort(int n)
{
	int i,j;
	for(i=n-1;i>0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(b1[j]>b1[j+1])
			{
				swap(a1[j],a1[j+1]);
				swap(b1[j],b1[j+1]);
			}
		}
	}
}
void xzsort(int n)
{
	int i,j,minn,mini;
	for(i=0;i<n-1;i++)
	{
		mini=i;
		for(j=i+1;j<n;j++)
		{
			if(b2[j]<b2[mini]) mini=j;
		}
		if(i!=mini) 
		{
			swap(a2[i],a2[mini]);
			swap(b2[i],b2[mini]);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i]>>b[i];
	for(int i=0;i<n;i++)
	{
		a1[i]=a[i];
		a2[i]=a[i];
		b1[i]=b[i];
		b2[i]=b[i];
	}
	mpsort(n);
	xzsort(n);
	for(int i=0;i<n-1;i++)
	cout<<a1[i]<<b1[i]<<" ";
	cout<<a1[n-1]<<b1[n-1]<<endl;
	cout<<"Stable"<<endl;
	for(int i=0;i<n-1;i++)
	cout<<a2[i]<<b2[i]<<" ";
	cout<<a2[n-1]<<b2[n-1]<<endl;
	for(int i=0;i<n;i++)
	{
		if(a1[i]!=a2[i])
		t=1;
	}
	if(t==0)
	cout<<"Stable"<<endl;
	else
	cout<<"Not stable"<<endl;
	return 0;
 } 


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define EB emplace_back

typedef long long ll;
typedef std::pair <ll, ll> pr;
const int N = 131154, L = 500000;

int n;
int p[N], lc[N], rc[N];
ll dep[N];
pr g[L], h[L], tmp[L];
std::vector <pr> f[N];

inline void link(int x, int px) {(lc[px] ? rc[px] : lc[px]) = x;}

inline bool check(ll v) {
	int i, j, x, l, r, L, R, cg, ch; ll lim;
	for (x = n; x; --x) {
		f[x].clear(), l = lc[x], r = rc[x];
		if (!(l || r)) {f[x].EB(dep[x], dep[x]); continue;}
		assert(l && r);
		L = f[l].size(), R = f[r].size(), lim = v + 2 * dep[x];
		for (cg = ch = j = i = 0; i < L; ++i) {
			for (; j < R && f[l][i].first + f[r][j].second > lim; ++j);
			if (j == R) break;
			g[cg++] = pr(f[l][i].second, f[r][j].first);
			h[ch++] = pr(f[r][j].first, f[l][i].second);
		}
		std::reverse(g, g + cg), j = std::merge(g, g + cg, h, h + ch, tmp) - tmp;
		if (!j) return false;
		for (f[x].EB(*tmp), i = 1; i < j; ++i)
			if (tmp[i].second < f[x].back().second) f[x].EB(tmp[i]);
	}
	return true;
}

int main() {
	int i; ll L = 0, R = 0, M;
	scanf("%d", &n);
	for (i = 2; i <= n; ++i)
		scanf("%d%d", p + i, dep + i), link(i, p[i]), R += dep[i], dep[i] += dep[ p[i] ];
	for (; L < R; check(M = (L + R) / 2) ? R = M : (L = M + 1));
	printf("%lld\n", L);
	return 0;
}

Measured memory_bytes: 36216
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	int N;
	cin >> N;
	int ans = (N - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256