akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int n, x;
	cin >> n;
	for (int i = 1;i <= n; i++){
		if ( i % 3 == 0 ) cout << " " << i;
		else {
			x = i;
			while( x != 0 ){
				if ( x % 10 == 3 ) {cout << " " << i; break;}
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <functional>
#include <unordered_set>
using namespace std;

typedef long long ll;

vector<int>ans;
vector<unordered_set<int>>E;
vector<unordered_set<int>>revE;
void solve(int i)
{
	vector<int>eda;
	vector<int>erase_node;
	for(int k : E[i])
	{
		if (revE[k].size() == 1)
		{
			eda.push_back(k);
		}
		else
		{	
			erase_node.push_back(k);
		}
	}
	for (int j = 0; j < erase_node.size(); j++)
	{
		E[i].erase(erase_node[j]);
		revE[erase_node[j]].erase(i);
	}

	for (int j = 0; j < eda.size(); j++)
	{
		int k = eda[j];
		ans[k] = i;
		solve(k);
	}
}

int main() {
	int N,M;
	cin>>N>>M;
	ans.resize(N);
	E.resize(N);
	revE.resize(N);
	for (int i = 0; i < N - 1 + M; i++)
	{
		int a,b;cin>>a>>b;
		E[a-1].insert(b-1);
		revE[b-1].insert(a-1);
	}

	int root = -1;
	for(int i=0;i<N;i++)if(revE[i].size() == 0)root = i;

	ans[root]=-1;
	solve(root);

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

	return 0;
}

Measured memory_bytes: 38656
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

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

using i64 = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i64 n, a, b;
    cin >> n >> a >> b;
    vector<i64> x(n);
    for(auto& k : x) cin >> k;
    i64 cur = x.front(), sum = 0LL;
    for(auto k : x) {
        if(cur == k) continue;
        i64 dis = k - cur;
        sum += min(dis * a, b);
        cur = k;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
#define END system("PAUSE");return 0
int n, x;
int a[11];
bool b[11];
signed main() {
	cin >> n >> x;
	rep(i, 10)b[i] = 1;
	rep(i, x) {
		cin >> a[i];
		b[a[i]] = 0;
	}
	for (int i = n;; i++) {
		string s = to_string(i);
		rep(j, s.size()) {
			if (!b[(s[j] - '0')])goto A;
		}
		cout << i << endl;
		END;
	A:;
	}
	END;
}


Measured memory_bytes: 504
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
ds=LI()
s=sorted(ds)
ans=s[n//2]-s[n//2-1]
print(ans)
    

Measured memory_bytes: 14172
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,c,k;
	cin>>n>>c>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	
	int ans=1;
	
	int nc=1;
	int nt=a[0];
	for(int i=1;i<n;i++){
		if(nc<c&&a[i]<=nt+k){
			nc++;
		}else{
			ans++;
			nc=1;
			nt=a[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int a = nextInt();
		int b = nextInt();
		int t = nextInt();

		int res = 0;

		double time = 0;
		while (time <= t + 0.5) {
			time += a;
			if (time <= t + 0.5) {
				res += b;
			}
		}

		out.println(res);
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

void solver() {
  long long n, k;
  cin >> n >> k;

  int ans = 0;
  int div = 1;
  while(true) {
    if (n / div == 0) break;
    else {
      div *= k;
      ans++;
    }
  }

  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <stdio.h>

#define DEBUG 1
#define NINF -1
#define PINF 1E9+1

int main()
{
	int total,ret;
	int n,m,c,a[21][21],b[21];
	int i,j;

	ret = 0;

	scanf("%d %d %d",&n, &m, &c);
	for (i=0;i<m;i++) scanf("%d",&b[i]);
	for (i=0;i<n;i++) {
		for (j=0;j<m;j++) {
			scanf("%d",&a[i][j]);
		}
	}

	for (i=0;i<n;i++) {
		total = 0;
		for (j=0;j<m;j++) {
			total += a[i][j] * b[j];
		}
		total += c;

		if (total>0) ret++;
	}


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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A, B;
ll D[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> D[i];
	A = 2; B = 3;
	rer(i, N, 0) {
		ll C = D[i];
		A = ((A + C - 1) / C) * C;
		B = ((B - 1) / C + 1) * C;
	}
	if(A == B) cout << "-1\n";
	else cout << A << " " << B - 1 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
	int N;
	cin >> N;
	map<string, int> m;

	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		m[s]++;
	}

	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = INT_MAX/2;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	vector<int> dp(N+K);
	fill(all(dp), INF), dp[0] = 0;
	rep(i, N) {
		rep1(j, K) {
			chmin(dp[i+j], dp[i] + abs(v[i]-v[i+j]));
		}
	}
	cout << dp[N-1] << '\n';
}


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

int main() {
  int N, W, i, j;
  int DP[110][10010];
  int weight[1010];
  int value[1010];

  cin >> N >> W;

  for (i = 0; i < N; ++i) {
    cin >> value[i] >> weight[i];
  }

  for (i = 0; i < W; ++i) {
    DP[0][i] = 0;
  }

  for (i = 0; i <= N; ++i) {
    for (j = 0; j <= W; ++j) {
      if (j >= weight[i]) {
        DP[i + 1][j] = max(DP[i][j], DP[i][j - weight[i]] + value[i]);
      } else {
        DP[i + 1][j] = DP[i][j];
      }
    }
  }

  cout << DP[N][W] << endl;

  return 0;
}


Measured memory_bytes: 7088
using System;
using System.Text.RegularExpressions;

class C {
    static Regex Regex1 = new Regex("^(dream|dreamer|erase|eraser)*$");

    public static void Main() {
        var s = Console.ReadLine();
        Console.WriteLine(Regex1.IsMatch(s) ? "YES" : "NO");
    }
}


Measured memory_bytes: 17108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String str2=br.readLine();
		String[] a=str.split(" ");
		String[] b=str2.split(" ");
		int[] aa=new int[2];
		for(int i=0;i<2;i++)
		{
			aa[i]=Integer.parseInt(a[i]);
		}
		int[] bb=new int[aa[0]];
		for(int i=0;i<aa[0];i++)
		{
			bb[i]=Integer.parseInt(b[i]);
		}
		int buf=0;
		for(int i=0;i<aa[0];i++)
		{
			for(int j=i+1;j<aa[0];j++)
			{
				if(bb[i]<bb[j])
				{
					buf=bb[i];
					bb[i]=bb[j];
					bb[j]=buf;
				}
			}
		}
		int max=0;
		for(int i=0;i<aa[1];i++)
		{
			max+=bb[i];
		}
		System.out.println(max);



	}

}


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

typedef long long ll;
vector<ll> x;
vector<ll> L;

ll getGCD(ll x, ll y){
    if(x<y) swap(x, y);
    ll r;
    while(y>0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll N, X;
int main(){
    scanf("%lld%lld", &N, &X);
    ll xx;
    for(ll i=0; i<N; i++){
        scanf("%lld", &xx);
        x.push_back(xx);
    }
    x.push_back(X);
    sort(x.begin(), x.end());
    for(ll i=0; i<=N; i++){
        L.push_back(x[i+1]-x[i]);
    }
    ll g = L[0];
    for(ll i=1; i<N; i++){
        g = getGCD(g, L[i]);
    }
    printf("%lld", g);
}


Measured memory_bytes: 2548
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

const int INF = 1e9;

string N;

int dp[1000002][2];

int process(int idx, int carry)
{
	if (idx == N.size()) return carry;

	int& ret = dp[idx][carry];
	if (ret != -1) return ret;

	ret = INF;

	int digit = N[idx] - '0' + carry;
	if (digit < 10) ret = min(ret, process(idx + 1, 0) + digit);
	ret = min(ret, process(idx + 1, 1) + 10 - digit);

	return ret;
}

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

	fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -1);

	cin >> N;

	reverse(N.begin(), N.end());

	cout << process(0, 0);
	
	return 0;
}


Measured memory_bytes: 56092
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d){
		cout<<"Left"<<endl;
	}
	else if(a+b==c+d){
		cout<<"Balanced"<<endl;
	}
	else{
		cout<<"Right"<<endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<cstdio>
#include<cstring>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const int MOD = 1e9+7;
const ll INF =1e18;


int main(){
    int n;cin >> n;
    vi a(n),b(n);
    vl da(n+1),db(n+1);
    da[0] = 0;
    db[0] = 0;
    fr(i,n){
        cin >> a[i];
        da[i+1] = da[i] + a[i];
    }
    fr(i,n){
        cin >> b[i];
        db[i+1] = db[i] + b[i];
    }
    ll ans = 0;
    fr(i,n){
        ans = max(ans,da[i+1] + db[n]-db[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
        int a, b, t, GCD;
        while(std::cin >> a >> b)
        {
                t = a, GCD = b;
                while(t != GCD)
                        if(t > GCD)
                                t -= GCD;
                        else
                                GCD -= t;
                std::cout << GCD << " " << (a / GCD)*b << std::endl;
        }
        return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  int h, n;
  cin >> h >> n;
  vector <int> a(n + 1), b(n + 1);
  REP1(i, n) {
	cin >> a[i] >> b[i];
  }
  vector <vector <int> > dp(n + 1, vector <int>(h + 1, 1e9));
  REP(i, n + 1) {
	dp[i][0] = 0;
  }
  REP1(i, n) {
	REP1(j, h) {
	  dp[i][j] = min(dp[i][j], dp[i - 1][j]);
	  dp[i][j] = min(dp[i][j], dp[i][max(j - a[i], 0)] + b[i]);
	}
  }
  cout << dp[n][h] << endl;
  return 0;
}


Measured memory_bytes: 39424
#D Card Eater
N = int(input())
List = [int(i) for i in input().split(" ")]
List.sort()
result = 1
for i in range(1,N):
    if List[i]!=List[i-1]:
        result+=1
if result%2 == 0:
    print(result-1)
else:
    print(result)

Measured memory_bytes: 14004
#include "bits/stdc++.h"

#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define hsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define hkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define zen(v) (v).begin(),(v).end()
#define yu(v) v.erase(unique(zen(v)), v.end());
#define syutu(v) si(a, (v).size()) {cout << v[a];if(a != v.size()-1)cout << " ";else cout << endl;}
#define mug 10000000111;
#define yo 10000000711;
#define kyo 1e-9;

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

using namespace std;
typedef long long sei;
typedef long double syo;
typedef vector<sei> vs;
typedef vector<syo> vy;
typedef vector<vs> vvs;
typedef vector<vy> vvy;
typedef pair<sei, sei> kS;
sei max(sei a, int b) {return max(a, sei(b));}
sei max(int a, sei b) {return max(sei(a), b);}

sei kaiki(sei n){
    static sei ki[1001];

    if (n==0) return 0;
    if (n==1) return 1;

    if(ki[n] ==0) {
        ki[n] = kaiki(n-1) + n;
    }else{
    }
    return ki[n];
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sei a, b, c, d;
    cin >> a  >> b;
    c = b - a;
    cout << kaiki(c)-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int count = 0;
        for(int j=1;j<=sqrt(i);j++){
            if(i%j==0){
                if(i==1){
                    count++;
                }
                else{
                    count+=2;
                }
            }
        }
        if(count==8 && i%2!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#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()

const int N = 1e5+5;
int par[N];
int find(int x) {
  if (par[x] < 0) {
    return x;
  }
  return par[x] = find(par[x]);
}

bool join(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return false;
  if (par[x] < par[y]) {
    swap(x,y);
  }
  par[x] += par[y];
  par[y] = x;
  return true;
}

int main() {
  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);
  // Emily <3
  int n, m;
  cin >> n >> m;
  memset(par, -1, sizeof par);
  int ans = n;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    ans -= join(x,y);
  }
  cout << ans << nl;
  return 0;
}


Measured memory_bytes: 768
n,m = map(int,input().split())
s = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort()
for i in s:
    if m<i[1]:
        ans += m*i[0]
        break
    else:
        ans += i[0]*i[1]
        m -= i[1]
print(ans)

Measured memory_bytes: 24248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

vector<int> read();
vector<int> think(const vector<int> &);
void write(const vector<int> &);

int firstRainAmount(const vector<int> &);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

vector<int> read() {
  int n, buf;
  auto input = vector<int>();

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &buf);
    input.push_back(buf);
  }
  return input;
}

vector<int> think(const vector<int> &input) {
  auto r = vector<int>(input.size());
  r.at(0) = firstRainAmount(input);

  // a.at(0) = (r.at(0) + r.at(1)) / 2
  // 2 * a.at(0) = r.at(0) + r.at(1)
  // r.at(1) = 2 * a.at(0) - r.at(0)

  for (int i = 1; i < r.size(); i++) {
    r.at(i) = 2 * input.at(i - 1) - r.at(i - 1);
  }
  return r;
}

void write(const vector<int> &output) {
  for (int i = 0; i < output.size(); i++) {
    if (i > 0) {
      printf(" ");
    }
    printf("%d", output.at(i));
  }
  printf("\n");
}

int firstRainAmount(const vector<int> &input) {
  // a = input
  // N = a.size(), N is odd number.
  // S = a.at(0) + ... + a.at(N - 1)

  // r = rainAmount
  // S = r.at(0) + ... + r.at(N - 1)

  // a.at(0) = (r.at(0) + r.at(1)) / 2
  // 2 * a.at(0) = r.at(0) + r.at(1)

  // r.at(0) = S - (r.at(1) + ... + r.at(N - 1))
  //               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ N - 1 elements, where N - 1 is EVEN number.
  // r.at(1) + r.at(2) = 2 * a.at(1),
  // r.at(3) + r.at(4) = 2 * a.at(3)
  //
  // r.at(0) = S - 2 * (a.at(1) + a.at(3) + ...)

  long sum = 0;
  for (int i = 0; i < input.size(); i++) {
    sum += input.at(i);
  }
  long subSum = 0;
  for (int i = 1; i < input.size(); i += 2) {
    subSum += input.at(i);
  }
  return static_cast<int>(sum - 2 * subSum);
}


Measured memory_bytes: 2296
input1 = raw_input()

input2 = []
for str in raw_input().split():
    input2.append(int(str))

input3 = raw_input()

input4 = []
for num in range(int(input3)):
    input4.append(raw_input())

for value in input4:
    result = 0
    list1 = list(input2)
    value = value.split()
    list1[int(value[0]) - 1] = int(value[1])
    for num in list1:
        result = result + num
    print result

Measured memory_bytes: 2568
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
using ll = long long;
using Set = multiset<ll>;

bool is_prime (ll n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (n == 3) return true;

  ll sqrtn = sqrt(n);

  for (ll i = 2; i < sqrtn + 1; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

Set get_prime_factors (ll n) {
  ll sqrtn = sqrt(n);
  Set prime_factors;

  for (ll i = 1; i < sqrtn + 1; i++) {
    if (n % i != 0) continue;

    ll I = n / i;

    if (is_prime(i)) prime_factors.insert(i);
    if (is_prime(I)) prime_factors.insert(I);
  }

  return prime_factors;
}

ll gcd (ll x, ll y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}

int main () {
  ll A, B;
  cin >> A >> B;

  Set p1 = get_prime_factors(A);
  Set p2 = get_prime_factors(B);
  Set S;

  set_intersection(
    p1.begin(), p1.end(),
    p2.begin(), p2.end(),
    inserter(S, S.end())
  );

  S.insert(1);

  cout << S.size() << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;

const long long MOD = 1000000007;
//* calculate x^n mod something in O(log n) -- recursive version
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0) return 1;
    ll res = mod_pow(x*x % mod, n/2, mod);
    if(n & 1) res = res * x % mod;
    return res;
}
void solve(long long N, std::vector<long long> A){
    ll ans = 0;
    REP(j, 62){
        ll cnt = 0;
        REP(i, N){
            if((A[i] >> j )&1) 
                cnt++;
        }
        ll tmp = (cnt * (N-cnt)) % MOD;
        tmp = (tmp * mod_pow(2, j, MOD)) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<vector<ll>> B(2*K+1, vector<ll>(2*K+1));
    vector<vector<ll>> W(2*K+1, vector<ll>(2*K+1));
    rep(i,N) {
        int x,y; char c; cin >> x >> y >> c;
        if (c == 'B') B[x%(2*K)+1][y%(2*K)+1]++;
        else W[x%(2*K)+1][y%(2*K)+1]++;
    }

    rep(i,2*K) rep(j,2*K+1) B[i+1][j] += B[i][j];
    rep(j,2*K) rep(i,2*K+1) B[i][j+1] += B[i][j];
    rep(i,2*K) rep(j,2*K+1) W[i+1][j] += W[i][j];
    rep(j,2*K) rep(i,2*K+1) W[i][j+1] += W[i][j];

    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            int cnt = 0;
            cnt += (B[i][j]-B[0][j]-B[i][0]+B[0][0]);
            cnt += (B[i+K][j+K]-B[i][j+K]-B[i+K][j]+B[i][j]);
            cnt += (B[2*K][2*K]-B[i+K][2*K]-B[2*K][j+K]+B[i+K][j+K]);
            cnt += (B[2*K][j]-B[i+K][j]-B[2*K][0]+B[i+K][0]);
            cnt += (B[i][2*K]-B[0][2*K]-B[i][j+K]+B[0][j+K]);
            cnt += (W[i+K][j]-W[i][j]-W[i+K][0]+W[i][0]);
            cnt += (W[i][j+K]-W[0][j+K]-W[i][j]+W[0][j]);
            cnt += (W[2*K][j+K]-W[i+K][j+K]-W[2*K][j]+W[i+K][j]);
            cnt += (W[i+K][2*K]-W[i][2*K]-W[i+K][j+K]+W[i][j+K]);
            chmax(ans,cnt);
            cnt = 0;
            cnt += (W[i][j]-W[0][j]-W[i][0]+W[0][0]);
            cnt += (W[i+K][j+K]-W[i][j+K]-W[i+K][j]+W[i][j]);
            cnt += (W[2*K][2*K]-W[i+K][2*K]-W[2*K][j+K]+W[i+K][j+K]);
            cnt += (W[2*K][j]-W[i+K][j]-W[2*K][0]+W[i+K][0]);
            cnt += (W[i][2*K]-W[0][2*K]-W[i][j+K]+W[0][j+K]);
            cnt += (B[i+K][j]-B[i][j]-B[i+K][0]+B[i][0]);
            cnt += (B[i][j+K]-B[0][j+K]-B[i][j]+B[0][j]);
            cnt += (B[2*K][j+K]-B[i+K][j+K]-B[2*K][j]+B[i+K][j]);
            cnt += (B[i+K][2*K]-B[i][2*K]-B[i+K][j+K]+B[i][j+K]);
            chmax(ans,cnt);
        }
    }

    cout << ans << endl;

} 


Measured memory_bytes: 62976
#include <stdio.h>
#define N 100
#define INF 2000001
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, adj[N][N], color[N], d[N]; 
void dijkstra( int );

int main(){
    int i, j, k, u, v, c;


    //initialize
    for( i=0; i<N; i++)
	for( j=0; j<N; j++)
	    adj[i][j] = INF;

    //input
    scanf("%d", &n);
    for( i=0; i<n; i++){
	scanf("%d%d", &u, &k);
	for( j=0; j<k; j++){
	    scanf("%d%d", &v, &c);
	    adj[u][v] = c;
	}
    }
    //process
    dijkstra( 0 );

    //print
    for( i=0; i<n; i++ ){
	printf("%d ", i);
	if( d[i] == INF ) printf("-1");
	else printf("%d", d[i]);
	printf("\n");
    }
    return 0;
}

void dijkstra( int start ){
    int mincost, i, j, k, u, v;

    //initialize
    for( i=0; i<n; i++ ){
	d[i] = INF;
	color[i] = WHITE;
    }
    d[start] = 0;
    color[start] = GRAY;

    //process
    while( 1 ){
	mincost = INF;
	for( i=0; i<n; i++ ){
	    if( color[i] != BLACK && mincost > d[i] ){
		k = i;
		mincost = d[i];
	    }
	}
	if( mincost == INF ) break;
	color[k] = BLACK;
	for( i = 0; i<n; i++ ){
	    if( color[i] != BLACK && adj[k][i] != INF ){
		if( d[i] > d[k] + adj[k][i] ){
		    d[i] = d[k] + adj[k][i];
		    color[i] = GRAY;
		}
	    }
	}
    }
    return ;
}



Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << (a + b < c + d ? "Right" : (a + b > c + d ? "Left" : "Balanced")) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
vector<ll> hr[300001];
vector<ll> wr[300001];
main()
{
    IO
    ll h,w;
    cin>>h>>w;
    ll m;
    cin>>m;
    ll u,v;
    for(int x=0;x<m;x++)
    {   cin>>u>>v;
        hr[u].pb(v);
        wr[v].pb(u);
    }
    set<pair<ll,ll>> as;
    for(int x=1;x<=3e5;x++)
    {
        as.insert({(ll)wr[x].size(),x});
    }
    ll ans=0;
    for(int x=1;x<=3e5;x++)
    {
        for(auto it : hr[x])
        {
            ans=max(ans,(ll)hr[x].size()+(ll)wr[it].size()-1);
            as.erase({(ll)wr[it].size(),it});
        }
        if(!as.empty())
        {
            auto it=as.end();
            --it;
            ans=max(ans,it->first+(ll)hr[x].size());
        }
         for(auto it : hr[x])
        {
            as.insert({(ll)wr[it].size(),it});
        }
    }
    cout<<ans;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  if(S[0]==S[1]&&S[1]==S[2]&&S[0]==S[2])cout << "No" << endl;
  else{
    cout << "Yes" << endl;
  }
}
  
  

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

	static int n = 1;
	static int[] seg;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		int n_ = Integer.parseInt(line.substring(0,line.indexOf(" ")));
		int q = Integer.parseInt(line.substring(line.indexOf(" ")+1));

		while (n <= n_)
			n *= 2;

		seg = new int[2*n-1];

		for (int i=0; i<q; i++) {
			line = br.readLine();
			String[] str = line.split(" ");
			int com = Integer.parseInt(str[0]);
			int x = Integer.parseInt(str[1]);
			int y = Integer.parseInt(str[2]);
			if (com == 0)
				update(x,y);
			else
				System.out.println(query(x,y,0,0,n-1));
		}

		br.close();
	}

	static void update(int i,int a){
		i += n-1;
		seg[i] += a;
		while (i > 0) {
			i = (i-1)/2;
			seg[i] = seg[2*i+1] + seg[2*i+2];
		}
	}

	static int query(int a,int b,int i,int l,int r){
		if (r<a || b<l)
			return 0;
		if (a<=l && r<=b){
			return seg[i];
		}else {
			int vl = query(a,b,i*2+1,l,(l+r)/2);
			int vr = query(a,b,i*2+2,(l+r+1)/2,r);
			return vl+vr;
		}
	}
}

Measured memory_bytes: 67292
def combination(n, a):
    mod = pow(10, 9)+7
    x, y = 1, 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod
    return x * pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
n, m = (2*y - x)//3, (2*x - y)//3
if (x + y)%3 != 0 or (n < 0 or m < 0):
    print(0)
else:
    ans2 = combination(n+m, n)
    print(ans2)


Measured memory_bytes: 3064
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let _: usize = read();
    let a: Vec<i32> = readnc();

    let mut four = 0;
    let mut two = 0;
    let mut zero = 0;
    for a in a {
        match a % 4 {
            0 => { four += 1 },
            2 => { two += 1  },
            _ => { zero += 1 },
        }
    }

    if (four >= zero) || (four + 1 == zero && two == 0) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 6396
n=int(input())
ar=[int(x) for x in input().split()]
ar.sort()

ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if(ar[i]!=ar[j] and ar[j]!=ar[k] and ar[i]+ar[j]>ar[k]):
          ans+=1

print(ans)

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

const int MAX = 100001;
char p[MAX] = {0};

int main(){
	for(int i=2 ; i < MAX ; i++ ) p[i] = 1;
	for(int i=2 ; i*i < MAX ; i++ ){
		if( p[i] ){
			for(int j=i+i ; j < MAX ; j += i ){
				p[j] = 0;
			}
		}
	}
	
	int n;
	while( cin >> n , n ){
		int a, b;
		for(int i=2 ; i <= n ; i++ ){
			if( p[i-2] && p[i] ){
				a = i-2;
				b = i;
			}
		}
		cout << a << " " << b << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
   fastio
   string s;
   cin>>s;
   int flag=0;
   if(s.size()==1)cout<<"Good"<<endl;
   else
   {
   for(int i=1;i<s.size();i++)
{
  if(s[i]==s[i-1]){flag=1;break;}
}
if(flag==1)cout<<"Bad"<<endl;
else cout<<"Good"<<endl;
}
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define N 100
int m[N][N];
int MCOrder(int *p, int num);

int main(){
  int num,i,p[N+1];
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }
  printf("%d\n",MCOrder(p,num));
  return 0;
}

int MCOrder(int *p,int num){
  int i,j,k,l,r;
  for(i=1;i<=num;i++){
    m[i][i]=0;
  }
  for(j=2;j<=num;j++){
    for(i=1;i<=num-j+1;i++){
      l=i+j-1;
      m[i][l]=INT_MAX;
      for(k=i;k<=l-1;k++){
        r=m[i][k]+m[k+1][l]+p[i-1]*p[k]*p[l];
        m[i][l]=((m[i][l]<=r)?m[i][l]:r);
      }
    }
  }
  return m[1][num];
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int takahashiA = sc.nextInt();
        int takahashiKougeki = sc.nextInt();
        int aokiC = sc.nextInt();
        int aokiKougeki = sc.nextInt();

        while (takahashiA > 0 && aokiC > 0) {
            aokiC -= takahashiKougeki;
            if (aokiC <= 0) {
                System.out.println("Yes");
                break;
            }
            takahashiA -= aokiKougeki;
            if (takahashiA <= 0) {
                System.out.println("No");
                break;
            }
        }
    }
}

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

const int INF = 999'999'999;
int main(){
    int n;
    string s;
    cin >> n >> s;

    vector<int> vW(n+1), vE(n+1);
    for(int i = 0; i < n; i++){
        vW[i+1] += vW[i];
        if(s[i]=='W') vW[i+1]++;
        vE[i+1] += vE[i];
        if(s[i]=='E') vE[i+1]++;
    }
    int ans = INF;
    for(int i = 0; i < n; i++){
        int now = vW[i] + (vE[n] - vE[i+1]);
        if(ans > now) ans = now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3076
n,m,l=list(map(int,input().split()))
A = [list(map(int,input().split()))for i in range(n)]
B = [list(map(int,input().split()))for i in range(m)]
ans=[[0]*l for i in range(n)]
for x in range(n):
    for y in range(m):
        for z in range(l):
            ans[x][z]+=A[x][y]*B[y][z]
for row in range(n):
    print("%d"%(ans[row][0]),end="")
    for col in range(1,l):
        print(" %d"%(ans[row][col]),end="")
    print()



Measured memory_bytes: 7052
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	int n;
	cin>>n;
	int x=n%10;
	if(x==2 or x==4 or x==5 or x==7 or x==9)
	puts("hon");
	else if(x==0 or x==1 or x==6 or x==8)
	puts("pon");
	else puts("bon");
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<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; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int dp[101][9];

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

    vvi dp(h + 1, vi(w));
    dp[0][0] = 1;

    rep(i, h) {
        rep(j, w) {
            rep(bit, (1 << (w - 1))) {
                bool ok = true;
                
                rep(k, w - 2) {
                    if ((bit >> k) & 1 && (bit >> (k + 1)) & 1) {
                        ok = false;
                        break;
                    }
                }

                if (ok) {
                    if (j >= 1 && ((bit >> (j - 1)) & 1)) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= mod;
                    }
                    else if (j <= w - 2 && ((bit >> j) & 1)) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= mod;
                    }
                    else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int X, A;
    cin >> X >> A;
    cout << (X >= A ? 10 : 0) << endl;
    return 0;
};


Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: a,b

read*, a,b

if ( a-2 >= b ) then
  print'(i0)', 2*a-1
else if ( b-2 >= a ) then
  print'(i0)', 2*b-1
else
  print'(i0)', a+b
end if

END PROGRAM ATCODER

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  string s;cin>>s;
  string abc="ABC";
  ll res=0;
  rep(i,n-2){
    if(s.substr(i,3)==abc){
      res++;
    }
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 384
/*
 *  Created on: 2017/06/27
 *      Author: LitMc
 */
//#define MYDEBUG
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
#define EPS = 1e-14;
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;
using std::ostream;
using std::unique;

template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}

struct edge {
	int from, to, cost;
	edge() {
		*this = edge(-1, -1, -1);
	}
	edge(int from_, int to_, int cost_) {
		from = from_;
		to = to_;
		cost = cost_;
	}
	bool operator<(const edge& e) const {
		return cost < e.cost;
	}
	bool operator==(const edge& e) const {
		return (from == e.from && to == e.to && cost == e.cost)
				|| (from == e.to && to == e.from && cost == e.cost);
	}
};

const int MAX_N = 21;
const int MAX_M = 2010;
int n, q, a[MAX_N], m;
bool used[MAX_N];
int dp[MAX_N][MAX_M];

bool dfs(int d, int x) { //d???????????§????????£???x????????£???
	if (d > n) {
		return false;
	}
	if (x == m) {
		return true;
	}
	if (dp[d][x] != 0) {
		return dp[d][x] == 1;
	}
	bool ret = dfs(d + 1, x);
	REP(k,d+1,n)
	{
		if (!used[k]) {
			used[k] = true;
			ret = ret || dfs(k, x + a[k]);
			used[k] = false;
		}
	}
	dp[d][x] = (ret ? 1 : -1);
	return ret;
}

void solve() {
	cin >> n;
	REP(i,1,n)
	{
		cin >> a[i];
	}
	cin >> q;
	rep(query,0,q)
	{
		memset(used, 0, sizeof(used));
		memset(dp, 0, sizeof(dp));
		cin >> m;
		cout << (dfs(0, 0) ? "yes" : "no") << endl;
	}
}

int main() {
	solve();
}

Measured memory_bytes: 3280
N = int(input())
ans = 0
Count_A = 0
Count_B = 0
Count_BA = 0
s = []
for _ in range(N):
    s.append(input())

for i in range(N):
    ans += s[i].count("AB")
    if s[i][0] == "B" and s[i][-1] == "A":
        Count_BA += 1
    elif s[i][0] == "B":
        Count_B += 1
    elif s[i][-1] == "A":
        Count_A += 1

if Count_BA == 0:
    ans += min(Count_A, Count_B)
elif Count_A + Count_B == 0:
    ans += Count_BA-1
else:
    ans += Count_BA + min(Count_A, Count_B)

print(ans)

Measured memory_bytes: 9744