akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

ll k[15];
ll p[15];
int main(void) {
	int n, m;
	cin >> n;
	cin >> m;
	vector<vector<ll>>s(m);
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		s[i].resize(k[i]);
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	ll ans = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		
		bool ok = true;
		for (int i = 0; i < m; i++) {
			ll count = 0;
			for (int j = 0; j < k[i]; j++) {
				if (bit & (1<<s[i][j])) {
					count++;
				}
			}
			if (p[i] % 2 != count % 2) {
				ok = false;
				break;
			}
			
		}
		
		
		if (ok) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3592
// 最大長方形
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cassert>

#include<vector>
#include<queue>
#include<set>

using namespace std;

#define MAX 1400

struct Rectangle{ int height; int pos; };

int getLargestRectangle( int size, int buffer[])
{
	stack<Rectangle> S;

	int maxv = 0;
	buffer[size] = 0;

	for(int i = 0; i <= size; i++)
	{
		Rectangle rect;

		// 追加したい要素を設定する
		rect.height = buffer[i];
		rect.pos = i;

		if( S.empty() )
		{
			S.push(rect);
		}
		else
		{
			if( S.top().height < rect.height )
			{
				// スタックの先頭要素よりも, 高さの高い要素はプッシュしていく
				S.push(rect);
			}
			else if( S.top().height > rect.height )
			{
				// 追加する要素の高さが, スタックの先頭よりも低い時
				int target = i;

				while( !S.empty() && S.top().height >= rect.height )
				{
					// スタックから取り出す要素の高さが, 追加要素よりも低くなるまで取り出しを続ける
					Rectangle pre = S.top(); S.pop();
					// 面積を計算する
					int area = pre.height * ( i - pre.pos );
					maxv = max(maxv, area);
					target = pre.pos;
				}
				// 追加要素の左端の位置を更新する
				rect.pos = target;
				S.push(rect);
			}
		}
	}

	return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle()
{
	for( int j = 0; j < W; j++ )
	{
		for( int i = 0; i < H; i++ )
		{
			if( buffer[i][j] )
			{
				// 汚れたタイルの時
				T[i][j] = 0;
			}
			else
			{
				T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
			}
		}
	}

	int maxv = 0;
	for( int i = 0; i < H; i++ )
	{
		maxv = max( maxv, getLargestRectangle(W, T[i]) );
	}

	return maxv;
}

int main()
{
	scanf("%d %d", &H, &W);

	for( int i = 0; i < H; i++ )
	{
		for( int j = 0; j < W; j++ )
		{
			scanf("%d", &buffer[i][j]);
		}
	}

	cout << getLargestRectangle() << endl;

	return 0;
}



Measured memory_bytes: 18488
#include <bits/stdc++.h>
long long r,n,a[500000],b[500000],c[500000];
using namespace std;
#define f for(int i = 0; i < n; i++)
signed main()
{
    cin >> n;
    f cin >> a[i];
    f cin >> b[i];
    f cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    f
    {
        r += (lower_bound(a, a + n, b[i]) - a) * (c + n - upper_bound(c, c + n, b[i]));
    }
    cout << r;
}


Measured memory_bytes: 9216
n = int(input())
cards = [[s+ " "+str(n) for n in range(1,14)]for s in ["S","H","C","D"]]
for i in range(n):
  suit,num = input().split()
  if suit=="S":
    cards[0][int(num)-1]=0
  elif suit=="H":
    cards[1][int(num)-1]=0
  elif suit=="C":
    cards[2][int(num)-1]=0
  elif suit=="D":
    cards[3][int(num)-1]=0
for s in cards:
  for n in s:
    if n !=0:
      print(n)


Measured memory_bytes: 5600
import java.util.*;

class Main {

	static int board[][] = new int[10][10];
	static int dx[] = {1,0,-1,0,1,-1,-1,1,2,0,-2,0};
	static int dy[] = {0,1,0,-1,1,1,-1,-1,0,2,0,-2};
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		in.useDelimiter("[,{\\n}]");
		while(in.hasNext()){
			sub(in.nextInt(), in.nextInt(), in.nextInt());
		}
		int cnt=0, best=0;
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(board[i][j]==0) cnt++;
				else if(board[i][j] > best) best=board[i][j];
			}
		}
		
		System.out.println(cnt);
		System.out.println(best);
	}
	
	private static void sub(int x, int y, int s){
		if(x<0 || x>=10 || y<0 || y>=10) return ;
		board[x][y]++;
		for(int i=0; i<((s==0)?0:(s==1)?4:(s==2)?8:12);i++){
			sub(x+dx[i], y+dy[i], 0);
		}
		return ;
	}
}

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

int main(){
  int n,x;cin>>n>>x;
  int l[n];for(int i=0;i<n;i++){cin>>l[i];}
  
  int coun=0;
  int pos=0;
  
  for(int i=0;i<n+1;i++){
    if(pos<=x){
      ++coun;
    }
    pos=pos+l[i];
  }
  cout<<coun<<endl;
  return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const int N = 100005;

void add_self(int &a, int b){
	a += b;
	if(a >= mod)
		a -= mod;
}

void sub_self(int &a, int b){
	a -= b;
	if(a < 0)
		a += mod;
}

int main(){
	fastio;
	int n, k;
	cin >> n >> k;
	vi lim(n), dp(k+1);
	for(int i = 0; i < n; i++)
		cin >> lim[i];
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		vi pref(k+1);
		for(int used = k; used >= 0; used--){
			int value = dp[used];
			int l = used + 1;
			int r = used + min(lim[i], k-used);
			if(l <= r){
				add_self(pref[l], value);
				if(r+1 <= k)
					sub_self(pref[r+1], value);
			}
			/*for(int now = 1; now <= min(lim[i], k-used); now++){
				dp[used + now] += dp[used];
			}*/
		}
		int sum = 0;
		for(int i = 0; i <= k; i++){
			add_self(sum, pref[i]);
			add_self(dp[i], sum);
		}
	}
	cout << dp[k] << '\n';
	return 0;
}


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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	ll A, B, C;
	cin >> A >> B >> C;

	vector<string> S(N);
	for(int i=0; i<N; i++) cin >> S[i];

	vector<char> ans;
	for(int i=0; i<N; i++){
		char next;
		if(S[i]=="AB"){
			if(A==0&&B==0) break;
			if(A==0) next = 'A';
			else if(B==0) next = 'B';
			else if(i<N-1 && S[i+1]=="BC") next='B';
			else next='A';
			if(next=='A'){
				A++;
				B--;
			} else {
				A--;
				B++;
			}
		} else if(S[i]=="BC"){
			if(C==0&&B==0) break;
			if(C==0) next = 'C';
			else if(B==0) next = 'B';
			else if(i<N-1 && S[i+1]=="AC") next='C';
			else next='B';
			if(next=='B'){
				B++;
				C--;
			} else {
				B--;
				C++;
			}
		} else {
			if(C==0&&A==0) break;
			if(C==0) next = 'C';
			else if(A==0) next = 'A';
			else if(i<N-1 && S[i+1]=="BC") next='C';
			else next='A';
			if(next=='A'){
				A++;
				C--;
			} else {
				A--;
				C++;
			}
		}
		ans.push_back(next);
	}
	if(ans.size()<N){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		for(int i=0; i<N; i++){
			cout << ans[i] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 6628
var readline  = require('readline').createInterface(process.stdin, process.stdout);
var result = 0;
var temp = 0;
readline.on('line', function(line) {
  if ( temp > 0) {
    result += Math.min(temp, parseInt(line));
    temp = 0
  } else {
    temp = parseInt(line);
  }
});

readline.on('close', function(line) {
  console.log(result);
});


Measured memory_bytes: 7500
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int  N = sc.nextInt();
 
 	if(N%2 == 0){
   		System.out.println("0.5");
    }else{
 	  	System.out.println(((double)N+1)/2/(double)N);
    }
      }
}




Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n + 1), b(n);
	for(int i = 0; i <= n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	long long ans = 0;
	for(int i = 0; i < n; i++){
		int d = min(a[i], b[i]);
		ans += d;
		a[i] -= d;
		b[i] -= d;
		int d2 = min(a[i + 1], b[i]);
		ans += d2;
		a[i + 1] -= d2;
		b[i] -= d2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
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 << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(),m=in.nextInt();
		int dist[][]=new int[2][n+1];
		
		for(int i=1;i<n;i++) {
			dist[0][i]=dist[0][i-1]+in.nextInt();
			dist[1][n-1-(i-1)]=dist[0][i];
		}
		
		int pos[]=new int[m+1];long L=0;
		pos[0]=0;
		for(int i=1;i<=m;i++) {
			int acl=Integer.parseInt(in.next());
			pos[i]=pos[i-1]+acl;
			if(acl>0)L+=dist[0][pos[i]]-dist[0][pos[i-1]];
			else L+=dist[0][pos[i-1]]-dist[0][pos[i]];
		}
		
		
		System.out.println(L%100000);
		
	}

}




Measured memory_bytes: 74736
#include <bits/stdc++.h>
using namespace std;
long long number(string &S, int &p, map<char, int> &mp);
long long factor(string &S, int &p, map<char, int> &mp);
long long expression(string &S, int &p, map<char, int> &mp, int d);
long long number(string &S, int &p, map<char, int> &mp){
  long long ans = 0;
  while (isdigit(S[p])){
    ans *= 10;
    ans += S[p] - '0';
    p++;
  }
  return ans;
}
long long factor(string &S, int &p, map<char, int> &mp){
  if (S[p] == '('){
    p++;
    long long ans = expression(S, p, mp, 0);
    p++;
    return ans;
  } else {
    return number(S, p, mp);
  }
}
long long expression(string &S, int &p, map<char, int> &mp, int d){
  long long ans;
  if (d == 3){
    ans = factor(S, p, mp);
  } else {
    ans = expression(S, p, mp, d + 1);
  }
  while (1){
    bool ok = false;
    long long tmp;
    char op = S[p];
    if (mp.count(op)){
      if (mp[op] == d){
        p++;
        if (d == 3){
          tmp = factor(S, p, mp);
        } else {
          tmp = expression(S, p, mp, d + 1);
        }
        ok = true;
      }
    }
    if (!ok){
      break;
    } else {
      if (op == '+'){
        ans += tmp;
      }
      if (op == '-'){
        ans -= tmp;
      }
      if (op == '*'){
        ans *= tmp;
      }
    }
  }
  return ans;
}
int main(){
  string S;
  cin >> S;
  long long ans = -1;
  for (int i = 0; i < 63; i++){
    ans *= 2;
  }
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < 3; k++){
        map<char, int> mp;
        mp['+'] = i;
        mp['-'] = j;
        mp['*'] = k;
        int p = 0;
        ans = max(ans, expression(S, p, mp, 0));
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3232
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(' '.join(map(str, X)))
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 19144
// AOJ 2857: Tournament Chart
// 2018.1.5 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int l, r; char p; } T;		// left node, right node, person
T tbl[60]; int sz;
char s[200];
int n;
int a[27];			//  won time

void tree(int i, char *p)
{
	int c;

	if (*p >= 'a' && *p <= 'z') {
		tbl[i].p = c = *p-'a'+1;
		n++;
		return;
	}
	tbl[i].l = sz++, tree(sz-1, ++p);
	if (*p == '[') {
		c = 1; while (1) {
			if    (*++p == '[') c++;
			else if (*p == ']') c--;
			if (!c) break;
		}
	}
	tbl[i].r = sz++, tree(sz-1, p+2);
}

int check(int i)
{
	int l, r;
	char lp, rp;

	l = tbl[i].l, r = tbl[i].r;
	if (tbl[l].p == 0) { if (!check(l)) return 0; }
	if (tbl[r].p == 0) { if (!check(r)) return 0; }
	lp = tbl[l].p, rp = tbl[r].p; 
	if      (a[lp] == 0) { tbl[i].p = rp; if (--a[rp] < 0) return 0; return 1; }
	else if (a[rp] == 0) { tbl[i].p = lp; if (--a[lp] < 0) return 0; return 1; }
	return 0;
}

int main()
{
	int i, v;
	char b[5];

	scanf("%s", s);
	n = 0, sz = 1;
	tree(0, s);

	for (i = 0; i < n; i++) {
		scanf("%s%d", b, &v);
		a[*b-'a'+1] = v;
	}

	puts(check(0) && a[tbl[0].p] == 0? "Yes": "No");
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a[21];
int ans;

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	for (int i = 1; i < n - 1; i++) {
		if ((a[i]<a[i - 1] && a[i]>a[i + 1]) || (a[i] > a[i - 1] && a[i] < a[i + 1]))ans++;
	}
	cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,Q; cin >> N >> Q;
    dsu d(N);
    REP(i,Q){
        int t,u,v; cin >> t >> u >> v;
        if(t==0){
            d.merge(u,v);
        }else{
            cout << d.same(u,v) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4056
import java.util.*;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            double a = sc.nextInt();
            double b = sc.nextInt();
            int c = sc.nextInt();
            double d = Math.ceil(a/b);
            System.out.println((int)d * c);
        }
    }


Measured memory_bytes: 35560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC002_A
{
    class Program
    {
        static void Main(string[] args)
        {
           
            var a = scan();
            if ( a[0] <0 &&  0<a[1] ||a[0]==0||a[1]==0)
            {
                Console.WriteLine("Zero");
            }
            else
            {
                if (a[0]>0)
                {
                    Console.WriteLine("Positive");
                }
                else
                {
                    if ((a[1]-a[0])%2==0)
                    {
                        Console.WriteLine("Negative");
                    }
                    else
                    {
                        Console.WriteLine("Positive");
                    }
                }
            }
        }
        static int[] scan()
        {
            return
                Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
    }
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    vector<pair<char, Int>> v;
    Int i = 0;
    char a = s[0];
    Int n = s.size();
    Int cnt = 0;
    while (i < n) {
        cnt = 0;
        a = s[i];
        while (i < n && a == s[i]) {
            i++;
            cnt++;
        }
        v.emplace_back(a, cnt);
    }
    Int m = v.size();
    if (m == 1) {
        dump(v[0].se * (v[0].se + 1) / 2);
    }
    else if (m == 2) {
        if (v[0].fi == '>') {
            dump(v[0].se * (v[0].se + 1) / 2 + v[1].se * (v[1].se + 1) / 2);
        }
        else {
            Int a = max(v[0].se, v[1].se);
            Int b = min(v[0].se, v[1].se);
            dump(a * (a + 1) / 2 + b * (b - 1) / 2);
        }
    }
    else {
        Int res = 0;
        if (v[0].fi == '>') {
            res += v[0].se * (v[0].se + 1) / 2;
        }
        for (Int i = (v[0].fi == '<') ? 0 : 1; i < m - 1; i+=2) {
            Int a = max(v[i].se, v[i + 1].se);
            Int b = min(v[i].se, v[i + 1].se);
            res += a * (a + 1) / 2 + b * (b - 1) / 2;
        }
        if (v.back().fi == '<') {
            res += v.back().se * (v.back().se + 1) / 2;
        }
        dump(res);
    }
    return 0;
}

Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    if (m < n) swap(n, m);
    if (n == 1) {
        if (m == 1) printf("1\n");
        else printf("%lld\n", m - 2);
    }
    else {
        printf("%lld\n", (n - 2) * (m - 2));
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int maxi = 404;

ll dp[maxi][maxi];

int main()
{
	FASTIO;
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin >> arr[i];
		
	auto sum=[&](int a,int b){
		ll su=0;
		for(int i=a;i<=b;i++){
			su += arr[i];
		}
		return su;
	};
	
	for(int L=n-1;L>=0;--L){
		for(int R=L;R<n;R++){
			if(L==R)
				dp[L][R]=0;
			else
			{
				ll s = sum(L,R);
				dp[L][R]=MAX;
				for(int i=L;i<=R-1;i++)
					dp[L][R] = min(dp[L][R], dp[L][i]+dp[i+1][R]+s);
			}
		}
	}
	cout << dp[0][n-1] << "\n";
	return 0;
}


Measured memory_bytes: 1536
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#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 repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=200010;

int n,h[maxn],a[maxn];
int64 dp[maxn],bit[maxn],ans;

inline int64 query(int i)
{
	int64 res=0;
	while(i>0)
	{
		res=max(res,bit[i]);
		i-=i&-i;
	}

	return res;
}

inline void modify(int i,int64 x)
{
	while(i<=n)
	{
		bit[i]=max(bit[i],x);
		i+=i&-i;
	}
}

int main()
{
	SF("%d",&n);
	for(int i=1;i<=n;i++) SF("%d",&h[i]);
	for(int i=1;i<=n;i++) SF("%d",&a[i]);

	for(int i=1;i<=n;i++)
	{
		dp[i]=query(h[i])+a[i];
		modify(h[i],dp[i]);

		ans=max(ans,dp[i]);
	}

	PF("%lld",ans);

	return 0;
}

Measured memory_bytes: 8472
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs


N,K = map(int,input().split())

A = list(map(int,input().split()))

A.sort()

fac,inv = prepare(N,10**9+7)

ans = 0
for i in range(N-K+1):

    nowind = i+K-1
    #print (A[nowind],nowind,K-1)
    ans += A[nowind] * (fac[nowind] * inv[K-1] * inv[nowind-(K-1)]) % (10**9+7)
    #print (ans)

ans2 = 0
for i in range(N-K+1):
    nowind = i+K-1
    nowind2 = N-K-i
    #print (A[nowind2],nowind,K-1)
    ans2 += A[nowind2] * (fac[nowind] * inv[K-1] * inv[nowind-(K-1)]) % (10**9+7)

#print (ans,ans2)
print ((ans-ans2) % (10**9+7))

    


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

int main() {
    string S;
    cin >> S;
    int count = 0;

    for(int i = 0; i < 3; i++) {
        if(S[i] == 'o') {
            ++count;
        }
    }

    cout << 700 + 100*count;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

ll Phi(ll a){
    ll ans=a;
    vector<ll> p;
    for(ll i=2;i*i<=a;i++){
        if(a%i==0){
            p.push_back(i);
            while(a%i==0){
                a/=i;
            }
        }
    }
    if(a!=1){p.push_back(a);}
    for(int i=0;i<p.size();i++){
        ans/=p[i];
        ans*=p[i]-1;
    }
    return ans;
}



int main(){
    ll n;
    cin>>n;
    cout<<Phi(n)<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3160
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define ll long long
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define forn(x) for(int i=1;i<=x;i++) 
#define sforn(x, y) for(int i=1;i<=x;i++)for(int j=1;j<=y;j++)
#define pii pair<int, int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

/*
    LOL KEK CHEBUREK
 
    PIHALITI
 
*/
ll mod = 1e9 + 7;
ll fac[2000100];
ll bin(ll x){
    ll lvl = mod -2;
    ll ret = 1;
    while(lvl){
        if(lvl & 1) ret *= x, ret %= mod;
        lvl /= 2;
        x *= x;
        x %= mod;
    }
    return ret;
}
ll C(ll a, ll b){
    return fac[a] * bin(fac[b]) %mod * bin(fac[a-b]) % mod;
}
int main(){ speed;
    fac[0] = 1;
    for(int i=1;i<=1e6;i++){
        fac[i] = fac[i-1] * i;
        fac[i] %= mod;
    }
    ll x, y;
    cin >> x >> y;
    ll n = x + y;
    ll a = n/3;
    if(n%3 || x < a || y < a){
        cout << 0 << endl;
    } else {
        ll b =  abs(a - x);
        cout << C(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>

using namespace std;

#define ll long long

map <ll, int> a;

int b[300000] = { 0 };
ll c[300000] = { 0 };


int main()
{
	int n;
	cin >> n;
	ll sum = 0;
	a[0] = 1;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
		c[i] = b[i] + c[i - 1];
		if (a[c[i]]) {
			sum += a[c[i]];
			a[c[i]]++;
		}
		else
			a[c[i]]++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

void get_even_divisors(ll n, vector<ll> &divisors) {
    for(ll i=1;i*i<=n;++i) {
        if(n % i) continue;
        if(i % 2) divisors.push_back(i);
        if(i * i != n && (n/i) % 2) divisors.push_back(n/i);
    }
    return;
}

ll calc_patterns(ll d, ll n, string &s) {
    int pattern_length = n / d;
    vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
    dp[n][0] = 1;
    for(int i=n;i>n-pattern_length;--i) {
        if(s[n-i] == '1') {
            dp[i-1][0] = dp[i][0];
            dp[i-1][1] = (dp[i][0] + (2 * dp[i][1]) % MOD) % MOD;
        } else {
            dp[i-1][0] = dp[i][0];
            dp[i-1][1] = (2 * dp[i][1]) % MOD;
        }
    }
    if(dp[n-pattern_length][0] == 0) return dp[n-pattern_length][1];
    for(int i=n-pattern_length;i>0;--i) {
        char pattern_c = s[(n-i)%pattern_length];
        if(((n-i) / pattern_length) % 2 == 1) {
            pattern_c = (pattern_c == '1') ? '0' : '1';
        }
        if(s[n-i] == '1') {
            if(pattern_c == '1') {
                dp[i-1][0] = dp[i][0];
            } else {
                dp[i-1][1] = dp[i][0];
            }
        } else {
            if(pattern_c == '1') {
                
            } else {
                dp[i-1][0] = dp[i][0];
            }  
        }
        dp[i-1][1] += dp[i][1];
        dp[i-1][1] %= MOD;
    }
    return (dp[0][0] + dp[0][1]) % MOD;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> divisors;
    get_even_divisors(n, divisors);
    string s;
    cin >> s;

    int nd = divisors.size();
    sort(divisors.rbegin(), divisors.rend());
    ll ans = 0LL;
    vector<ll> patterns(nd);
    for(int i=0;i<nd;++i) {
        int pattern_length_i = n / divisors[i];
        patterns[i] = calc_patterns(divisors[i], n, s);
        for(int j=0;j<i;++j) {
            int pattern_length_j = n / divisors[j];
            if(pattern_length_i % pattern_length_j == 0) {
                patterns[i] += MOD - patterns[j];
                patterns[i] %= MOD;
            }
        }
        ans += (((patterns[i] * pattern_length_i) % MOD) * 2) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 11396
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = -1;
        for (int x = 1; x <= 2000; x++) {
            if (8*x/100 == A && 10*x/100 == B) {
                ans = x;
                break;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
string s;
int main()
{
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if(s[i] == '?') cout << "D";
        else cout << s[i];
    }
}


Measured memory_bytes: 3716
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr int MOD = 1'000'000'007;

#define CNKMAX 1000001
class CNK1 {
    std::vector<long long> fac, finv, inv;
    int MOD;
public:
    CNK1(int mod = 1000000007): MOD(mod), fac(CNKMAX), finv(CNKMAX), inv(CNKMAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < CNKMAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    int get(const int &n, const int &k) const {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

void solve() {
    int x,y;
    cin >> x >> y;
    CNK1 cnk;
    REP(i,0,x+1) {
        int rx = x - 2 * i, ry = y - i;
        if (rx * 2 != ry) continue;
        int cx = i, cy = rx;
        cout << cnk.get(cx+cy,cx) << endl;
        return;
    }
    cout << 0 << endl;
}

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

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

int min1(int w, int x){
  if(w < x) return w;
  else return x;
}
int min2(int y, int z){
  if(y < z) return y;
  else return z;
}

int main(){
  int a, b, c;
  int d, e;
  cin >> a >> b >> c;
  cin >> d >> e;
  
  cout<<min1(min1(a,b),c)+min2(d,e)-50<<endl;

  return 0;
}

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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

    int sum = A;
    int ans = 0;
    while (true) {
        sum = A + (A - 1) * (ans - 1);
        if (sum >= B) {
            break;
        }
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int N,A,x;
long long dp[100][8000],ans=0;
int main(){
	dp[0][0]=1;
	scanf("%d%d",&N,&A);
	for(int i=1;i<=N;++i){
		scanf("%d",&x);
		for(int j=i;j;--j){
			for(int k=2500;k>=x;--k){
				dp[j][k]+=dp[j-1][k-x];
			}
		}
	}
	for(int i=1;i<=N;++i){
		ans+=dp[i][i*A];
	}
	printf("%lld",ans);
	return 0;
}
/*#include<bits/stdc++.h>
#define N 55
#define ll long long
using namespace std;
ll f[N][N*N],ans=0;
int x,a,n;
int main(){
	f[0][0]=1,scanf("%d%d",&n,&a);
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		for(int j=i;j;--j)for(int k=2500;k>=x;--k)f[j][k]+=f[j-1][k-x];
	}
	for(int i=1;i<=n;++i)ans+=f[i][i*a];
	cout<<ans;
	return 0;
}*/

Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// データセット数を取得
		String lineCountStr = br.readLine();

		// 各データセットを処理
		for (int lineCount = 0; lineCount < Integer.parseInt(lineCountStr); lineCount ++) {

			String[] dataSetStr = br.readLine().split(" ");
			int[] dataSet = new int[dataSetStr.length];
			for (int i = 0; i < dataSetStr.length; i ++) {
				dataSet[i] = Integer.parseInt(dataSetStr[i]);
			}

			// 一番大きい値が右端になるようにソート
			if (dataSet[0] > dataSet[1]) {
				int tmp = dataSet[0];
				dataSet[0] = dataSet[1];
				dataSet[1] = tmp;
			}
			if (dataSet[1] > dataSet[2]) {
				int tmp = dataSet[1];
				dataSet[1] = dataSet[2];
				dataSet[2] = tmp;
			}

			// 直角三角形であれば "YES", それ以外であれば "NO" を出力
			if (Math.pow(dataSet[0], 2) + Math.pow(dataSet[1], 2) == Math.pow(dataSet[2], 2)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}



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

int main() {
  int n,m;
  cin>>n;
  vector<string> get(n);  
  for(int i=0;i<n;i++){
    cin>>get.at(i);
  }
  cin>>m;
  vector<string> lost(m);
  for(int i=0;i<m;i++){
    cin>>lost.at(i);
  }
  
  
  int answer=0,count=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(get.at(i)==get.at(j)){
        count++;
      }
    }
    for(int j=0;j<m;j++){
      if(get.at(i)==lost.at(j)){
        count--;
      }
    }
    answer=max(answer,count);
    count=0;
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
# 横か縦か。各時点でn-2 or n-1C2
# str1だけ見ればよい

N = int(input())
txt = input()

pattern = []
j = 0

while j < N:
  if j == N-1 or txt[j] != txt[j+1]:
    pattern.append(1)
    j += 1
  else:
    pattern.append(2)
    j += 2


    
MOD = 10**9 + 7

ans = 3 if pattern[0] == 1 else 6
for j in range(1,len(pattern)):
  a,b = pattern[j-1:j+1]
  if (a,b) == (1,1):
    ans *= 2
  elif (a,b) == (1,2):
    ans *= 2
  elif (a,b) == (2,1):
    ans *= 1
  else:
    ans *= 3
  ans %= MOD

print(ans)

Measured memory_bytes: 3064
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define MAXN 10000005


void print_vec(vll a)
{
	cout << "start printing the vector\n";
	for (ll i = 0; i < a.size(); i++)
		cout << a[i] << " ";
	cout << "\n";
}
void print_mat(vector<vll> a)
{
	cout << "start printing the matrix\n";
	for (ll i = 0; i < a.size(); i++)
	{
		for (ll j = 0; j < a[i].size(); j++)
		{
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i = 2; i < MAXN; i++)
		spf[i] = i;
	for (int i = 4; i < MAXN; i += 2)
		spf[i] = 2;

	for (int i = 3; i * i < MAXN; i++)
	{
		if (spf[i] == i)
		{
			for (int j = i * i; j < MAXN; j += i)
			{
				if (spf[j] == j)
					spf[j] = i;
			}
		}
	}
}

ll getFactorization(int x)
{
	int org = x;
	int prev = -1;
	ll out  = 1;
	ll count  = 0;
	while (x != 1)
	{
		if (spf[x] == prev)
		{
			count++;
		}
		else
		{
			out *= (count + 1);
			count = 1;
			prev = spf[x];
		}
		//ret.push_back(spf[x]);
		x = x / spf[x];
	}
	if (count > 0)
		out *= (count + 1);
	//cout << out << " " << org << "\n";
	return out * org;
}



void solve()
{
	int p;
	sieve();
	cin >> p;
	ll out = 0;
	for (ll i = 1; i <= p; i++)
	{
		out += getFactorization(i) ;
	}
	cout << out << "\n";
}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 42704
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        for (int i = 0; i < n; i++) list[i] = sc.nextInt();
        
        int min = Integer.MAX_VALUE;
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (min >= list[i]) {
                count++;
                min = list[i];
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 65860
#include<stdio.h>

int main(){
  int x, y, r=0;

  scanf("%d %d", &x, &y);
  
  while(1){  
    if(x % y == 0) break;
    r = x % y;
    x = y;
    y = r;  
  }
  printf("%d\n", y);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <string>
using namespace std;
int main()
{
    long int n, ans=0;
    string a;
    cin >> n;
    map <string,int> s;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        sort(a.begin(),a.end());
        ans+=s[a]++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  string s;
  int cnt_b = 0, cnt_e = 0, cnt_both = 0, ans = 0;
  REP(i, n) {
    cin >> s;
    if (s[0] == 'B' && s[s.size() - 1] == 'A') {
      cnt_both++;
    } else {
      if (s[0] == 'B') cnt_b++;
      if (s[s.size() - 1] == 'A') cnt_e++;
    }
    REP(j, s.size() - 1) {
      if (s[j] == 'A' && s[j + 1] == 'B') ans++;
    }
  }
  if (cnt_both > 0) {
    ans += cnt_both - 1;
    if (cnt_e > 0) {
      ans++;
      cnt_e--;
    }
    if (cnt_b > 0) {
      ans++;
      cnt_b--;
    }
  }

  ans += min(cnt_e, cnt_b);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 3050
#define int long long

using namespace std;
const ll INF = 1e18L+5;
int n,k;
int a[205];
int dp[100009];

bool fun(int stones){
   if(stones<=0){
      return dp[stones]=0;
   }
  // bool ok=false;
  if(dp[stones]!=-1) return dp[stones];
  else{
   for(int k=0;k<n;k++){

        if(stones>=a[k]){
           if(!fun(stones-a[k])){
            return dp[stones]=1;
           }

        }

   }
   return dp[stones]=0;//dp[stones]=
  }

}



int32_t main(){
   jio;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    //int res=fun(n);
    //cout<<res<<endl;
    memset(dp,-1,sizeof(dp));
    if(fun(k)){ //taro 1; ziro 0
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }


    return 0;


}


Measured memory_bytes: 4224
package main

import "fmt"

func main() {
	var N int64
	fmt.Scan(&N)
	s := fmt.Sprintf("%v", N)

	var n int64 = 0
	for _, x := range s {
		n += int64(x) - 0x30
	}

	if N%n == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
H, W = map(int, input().split())
h, w = map(int, input().split())
ans = H*W
if h*W<ans:
    ans -= h*W
    if (H-h)*w<ans:
        ans -= (H-h)*w
        print(ans)
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 3060
#include<stdio.h>

int main(int argc, char* argv[])
{
  int h, w, i, j;
  scanf("%d %d", &h, &w);  

  while((h != 0)||(w != 0)){
    for(i = 0; i < h; i++){
      for(j = 0; j < w - 1; j++){
        printf("#");
      }
      printf("#\n");
    }
    printf("\n");
    scanf("%d %d", &h, &w);
  }
  return(0);
}

Measured memory_bytes: 588
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True):
   del phU[-2]
   try:
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 del phL[0]
 del phL[-1]
 ph = phU + phL
 return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1])

Measured memory_bytes: 33192
/*

 */

#include<bits/stdc++.h>

using namespace std;
const int maxN = 300;
const int INF = 1e8;
 
int n,m,st,fn;
int cap[maxN][maxN],f[maxN][maxN],d[maxN],ptr[maxN];

void input()
{
  cin>>n>>m;
  //cin>>st>>fn;
  st=1;
  fn=n;
  for(int i=1;i<=m;i++)
    {
      int k1,k2,val;
      
      cin>>k1>>k2>>val;
      //g[k1].push_back(k2);
      //g[k2].push_back(k1);
      k1++;k2++;
      cap[k1][k2]+=val;
      //cap[k2][k1]+=val;
    }
}
bool bfs() {
  //int qh=0, qt=0;
  queue<int> q;
  //q[qt++] = st;
  q.push(st);
  memset (d, -1, (n+10) * sizeof d[0]);
  d[st] = 0;
  while (q.size()>0) {
    int v = q.front();
    q.pop();
    for (int to=1; to<=n; ++to)
      if (d[to] == -1 && f[v][to] < cap[v][to]) {
	q.push(to);
	d[to] = d[v] + 1;
      }
  }
  return d[fn] != -1;
}
 
int dfs (int v, int flow) {
  if (!flow)  return 0;
  if (v == fn)  return flow;
  for (int & to=ptr[v]; to<=n; ++to) {
    if (d[to] != d[v] + 1)  continue;
    int pushed = dfs (to, min (flow, cap[v][to] - f[v][to]));
    if (pushed) {
      f[v][to] += pushed;
      f[to][v] -= pushed;
      return pushed;
    }
  }
  return 0;
}
 
int dinic() {
  int flow = 0;
  for (;;) {
    if (!bfs())  break;
    memset (ptr, 0, (n+10) * sizeof ptr[0]);
    while (int pushed = dfs (st, INF))
      flow += pushed;
  }
  return flow;
}
int main()
{
  input();
  int MaxFlow=dinic();
  cout<<MaxFlow<<endl;
  return 0;
}

Measured memory_bytes: 3324
#!/usr/bin/env python3
n, x, y = map(int, input().split())
a = abs
d = [0] * n
for i in range(1, n+1):
    for j in range(i + 1, n+1):
        d[min(j-i, a(x-i)+a(y-j)+1, a(x-j)+a(y-i)+1)] += 1
print(*d[1:], sep="\n")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int N, M, V, P;
	scanf("%d%d%d%d", &N, &M, &V, &P);
	vector<int> A(N);
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	sort(A.begin(), A.end(), greater<int>());
	int lo = P, hi = N;
	while (lo < hi) {
		int m = (lo + hi) >> 1;
		int mx = A[m] + M;
		ll sum = 0;
		bool bad = false;
		for (int i = P - 1; i < N; ++i) {
			if (i != m) {
				int amt = min(M, mx - A[i]);
				if (amt < 0) bad = true;
				sum += amt;
			}
		}
		if (!bad && (ll)M * (V - P) <= sum) lo = m + 1;
		else hi = m;
	}
	printf("%d\n", lo);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}


int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll x;cin >> x;
  int n_digit = 0;
  int n_2[10];
  n_2[0] = 1;
  rep(i,9) n_2[i+1] = 2*n_2[i];

  ll x_ = x;
  while(x_){
    ++n_digit;
    x_/=10;
  }
  ll ans = 0;
  rep(i,n_digit){
    x_ = x%10;
    ll n_10 = 1;
    rep(j,i+1){
      int check = 1;
      if(j==i)check = 0;
      //cout << n_10 SP x_ SP n_2[n_digit-(j+1+check)] << endl;
      ans +=  n_10*x_*n_2[n_digit-(j+1+check)];
      n_10*=10;
    }
    x/=10;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256