akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

namespace Flow {
    struct Edge {
        int to, capacity, cost, reverse;
        Edge(int to, int capacity, int cost, int reverse) :
            to(to), capacity(capacity), cost(cost), reverse(reverse) {}
    };
    template <int MaxN> class PrimalDual {
        int n = MaxN;
        vector<Edge> g[MaxN];
    public:
        void clear(int n) {
            this->n = n;
            for (int i = 0; i < n; ++i)
                g[i].clear();
        }
        void push(int from, int to, int capacity = 1, int cost = 0) {
            g[from].emplace_back(to, capacity, cost, g[to].size());
            g[to].emplace_back(from, 0, -cost, g[from].size() - 1);
        }
        pair<int, int> flow(int s, int t, int f = 1 << 30) {
            int flow = f, cost = 0;
            static int prevv[MaxN], preve[MaxN], dist[MaxN], h[MaxN];
            fill(h, h + n, 0);
            while (flow > 0) {
                fill(dist, dist + n, 1 << 30);
                dist[s] = 0;
                using P = pair<int, int>;
                priority_queue<P, vector<P>, greater<P>> q;
                for (q.emplace(0, s); q.size(); ) {
                    auto p = q.top();
                    q.pop();
                    int v = p.second;
                    if (dist[v] < p.first) continue;
                    for (auto& e : g[v]) {
                        int d = dist[v] + e.cost + h[v] - h[e.to];
                        if (e.capacity > 0 && dist[e.to] > d) {
                            dist[e.to] = d;
                            prevv[e.to] = v;
                            preve[e.to] = &e - &g[v][0];
                            q.emplace(d, e.to);
                        }
                    }
                }
                if (dist[t] == 1 << 30) break;
                for (int v = 0; v < n; ++v)
                    h[v] += dist[v];
                int d = flow;
                for (int v = t; v != s; v = prevv[v])
                    d = min(d, g[prevv[v]][preve[v]].capacity);
                flow -= d;
                cost += d * h[t];
                for (int v = t; v != s; v = prevv[v]) {
                    auto& e = g[prevv[v]][preve[v]];
                    e.capacity -= d;
                    g[v][e.reverse].capacity += d;
                }
            }
            return { f - flow, cost };
        }
    };
}

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    Flow::PrimalDual<202> pd;
    pd.clear(n + m + 2);
    for (int i = 0; i < n; ++i)
        pd.push(n + m, i);
    for (int i = 0; i < m; ++i)
        pd.push(i + n, n + m + 1);
    for (int i = 0; i < l; ++i) {
        int a, b;
        cin >> a >> b;
        pd.push(a, b + n);
    }
    cout << pd.flow(n + m, n + m + 1).first << endl;
    return 0;
}

Measured memory_bytes: 3396
#include <iostream>

using namespace std;

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

    string s; cin >> s;
    int n = s.size();
    for(int i = 0; i < n; ++i)
    {
        if(!(i & 1) && s[i] == 'L')
        {
            cout << "No";
            return 0;
        }
        if(i & 1 && s[i] == 'R')
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




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

	vector<ll> p(N + 1,0);
	repn(i, N) cin >> p[i];

	vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, INF));

	dp[0][0] = 0;
	
	repn(i, N) {
		dp[i][0] = dp[i - 1][0] + A;

		repn(j, i - 1) {
			if (p[i] > p[j]) { dp[i][j] = dp[i - 1][j] + A; }
			else { dp[i][j] = dp[i - 1][j] + B; }
		}

		rep(j, i) {
			if (p[i] > p[j]) { dp[i][i] = min(dp[i - 1][j], dp[i][i]); }
		}
	}

	ll ans = INF;
	rep(i, N + 1) {
		ans = min(ans, dp[N][i]);
	}

	cout << ans;
	
	
	system("PAUSE");
}


Measured memory_bytes: 196088
def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        # N = 4
        # numbers = [2, 5, 5, 2]
        N = 6
        a = [12, 22, 16, 22, 13, 12]

    except NameError:
        N = int(input())
        a = list(map(int, input().split()))

    counter = {}
    for i in range(N):
        if a[i] in counter:
            counter[a[i]] += 1
        else:
            counter[a[i]] = 1

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v
        if k-1 in counter:
            temp += counter[k-1]
        if k+1 in counter:
            temp += counter[k+1]
        if(temp > results):
            results = temp
            key = k

    print(results)
    # print(key)

C_Together()



Measured memory_bytes: 14300
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
#define ALL(a)  (a).begin(),(a).end()
int n;
vector<int>c0(MAX,0),c1(MAX,0);
int main(){
    int temp;
    cin>>n;
    rep(i,n){
        cin>>temp;
        if(i%2==0){
            c0[temp]++;
        }
        else {
            c1[temp]++;
            }
    }
    pair<int,int>f0(0,0),s0(0,0),f1(0,0),s1(0,0);
    rep(i,MAX){
        if(f0.second<c0[i]){
            s0.first=f0.first;s0.second=f0.second;
            f0.first=i;f0.second=c0[i];
        }
        else if(s0.second<c0[i]){
            s0.first=i;s0.second=c0[i];
        }
        if(f1.second<=c1[i]){
            s1.first=f1.first;s1.second=f1.second;
            f1.first=i;f1.second=c1[i];
        }
        else if(s1.second<c1[i]){
            s1.first=i;s1.second=c1[i];
        }
    }
    int res=f0.second+f1.second;
    if(f0.first==f1.first)res=max(f0.second+s1.second,f1.second+s0.second);
    int ans=n-res;
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 1024
s = input()

# print(s)
n1 = s.index('A')
# print(n1)
# s = s[n:]

# print(s)
n2 = s.rindex('Z')
# n2 = len(s) - n2 - 1
# print(n2)
# s = s[:n + 1]

print(n2 - n1 + 1)

Measured memory_bytes: 3500
#include<iostream>
#include<vector>
#include <algorithm>

int main(){
  int W, H, N;
  std::cin >> W >> H >> N;
  std::vector<std::vector<int>> A(N, std::vector<int>(3));
  for(int i = 0; i < N; i++) std::cin >> A.at(i).at(0) >> A.at(i).at(1) >> A.at(i).at(2);
  int limitR = W, limitL = 0, limitU = H, limitD = 0;
  for(int i = 0; i < N; i++){
    if(A.at(i).at(2) == 1) limitL = std::max(limitL, A.at(i).at(0));
    else if(A.at(i).at(2) == 2) limitR = std::min(limitR, A.at(i).at(0));
    else if(A.at(i).at(2) == 3) limitD = std::max(limitD, A.at(i).at(1));
    else limitU = std::min(limitU, A.at(i).at(1));
  }
  if(limitR <= limitL || limitU <= limitD) std::cout << 0 << std::endl;
  else std::cout << (limitR - limitL) * (limitU - limitD) << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int i,j,k;
  int input;
  int cnt=0;
  int sum=0;

  int PofA=0,PofB=0,PofC=0,X;

  cin>>PofA;
  cin>>PofB;
  cin>>PofC;
  cin>>X;

  // 500円＊x +100円*y + 50円*z = SUM
  // となる(x,y,z)の組み合わせの個数を知りたい．
  //
  //全てのあり得る(x,y,z)の組み合わせを網羅する
  //そのうち500円＊x +100円*y + 50円*z = SUMとなった組み合わせの個数を出力する．
  
  
  

  
  for(int i=0;i<=PofA;i++){
    
    for(int j=0;j<=PofB;j++){
      
      for(int k=0;k<=PofC;k++){
        
        if(500*i+100*j+50*k==X) cnt++;
      }
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans = 0;
long long c[5];

void calc(int idx, vector<long long> v){
  if ( idx == 5){
    if ( v.size() == 3){
      ans += (v[0] * v[1] * v[2]) ;
    }
    return;
  }
  calc(idx+1, v);
  v.push_back(c[idx]);
  calc(idx+1, v);
}

int main(){
  int n;
  cin >> n;
  string march = "MARCH";
  string s;
  for ( int i = 0; i < 5; i++)c[i] = 0;

  for ( int i = 0; i < n; i++){
    cin >> s;
    for ( int j = 0; j < 5; j++){
      if ( s[0] == march[j]){
        c[j] += 1;
        break;
      }
    }
  }
  vector<long long> v;
  calc(0, v);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NMAX 20

int A[NMAX];
int n,q;

int judge(int i, int m){
	if(m == 0){
		return 1;
	}
	if(i >= n){
		return 0;
	}
	int c = judge(i + 1,m) || judge(i + 1, m - A[i]);
	return c;
}

int main(void){
	int i,m;
	scanf("%d" ,&n);
	for(i = 0; i < n; i++){
		scanf("%d" ,&A[i]);
	}
	scanf("%d" ,&q);
	for(i = 0; i < q; i++){
		scanf("%d" ,&m);
		if(judge(0,m) != 0){
			printf("yes\n");
		}
		else{
			printf("no\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=2e6+5;
const int mod=1e9+7;
int fac[N],ifac[N];
int x1,x2,x3,x4,x5,x6;
int y1,y2,y3,y4,y5,y6;

inline int nxi(FILE *fd=stdin){
	int x=0;
	char c;
	while((c=fgetc(fd))>'9'||c<'0');
	while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
	return x;
}

template <class T> inline int fpow(int x,T t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

void init(){
	fac[0]=1;
	for(int i=1; i<N; ++i){
		fac[i]=(lint)fac[i-1]*i%mod;
	}
	ifac[N-1]=fpow(fac[N-1],mod-2);
	for(int i=N-1; i; --i){
		ifac[i-1]=(lint)ifac[i]*i%mod;
	}
}

inline int C(const int x,const int y){
	assert(x>=y&&y>=0);
	return (lint)fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

int solve(const int sx,const int sy,const int tx,const int ty){
	int ans=0;
	//enters by (i,y3-1)
	for(int i=x3; i<=x4; ++i){
		const int sa=i-sx,sb=y3-1-sy;
		const int ta=tx-i,tb=ty-y3;
		ans=(ans-(lint)(i+y3)*C(sa+sb,sa)%mod*C(ta+tb,tb))%mod;
	}
	//enters by (x3-1,i)
	for(int i=y3; i<=y4; ++i){
		const int sa=x3-1-sx,sb=i-sy;
		const int ta=tx-x3,tb=ty-i;
		ans=(ans-(lint)(i+x3)*C(sa+sb,sa)%mod*C(ta+tb,tb))%mod;
	}
	//leaves by (i,y4+1)
	for(int i=x3; i<=x4; ++i){
		const int sa=i-sx,sb=y4-sy;
		const int ta=tx-i,tb=ty-y4-1;
		ans=(ans+(lint)(i+y4+1)*C(sa+sb,sa)%mod*C(ta+tb,ta))%mod;
	}
	//leaves by (x4+1,i)
	for(int i=y3; i<=y4; ++i){
		const int sa=x4-sx,sb=i-sy;
		const int ta=tx-x4-1,tb=ty-i;
		ans=(ans+(lint)(i+x4+1)*C(sa+sb,sa)%mod*C(ta+tb,ta))%mod;
	}
	return ans<0?ans+mod:ans;
}

int main(){
	init();
	x1=nxi(),x2=nxi(),x3=nxi(),x4=nxi(),x5=nxi(),x6=nxi();
	y1=nxi(),y2=nxi(),y3=nxi(),y4=nxi(),y5=nxi(),y6=nxi();
	int st_x[]={x1-1,x2,x2,x1-1};
	int st_y[]={y1-1,y1-1,y2,y2};
	int ed_x[]={x6+1,x5,x5,x6+1};
	int ed_y[]={y6+1,y6+1,y5,y5};
	int ans=0;
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			int res=solve(st_x[i],st_y[i],ed_x[j],ed_y[j]);
			ans=(ans+((i^j)&1?mod-res:res))%mod;
		}
	}
	/*
	for(int ix=x1; ix<=x2; ++ix){
		for(int iy=y1; iy<=y2; ++iy){
			for(int kx=x5; kx<=x6; ++kx){
				for(int ky=y5; ky<=y6; ++ky){
					ans+=solve(ix,iy,kx,ky);
				}
			}
		}
	}
	*/
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 15872
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, X);
    ll ans = 8 - (X - 400) / 200;
    OUT(ans);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

/*
    1-indexed であることに注意 !! 
*/
template <typename T>
struct BIT{
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a){
        T res = 0;
        for(int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b){
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x){
        if(k == 0) return;
        for(int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x){
        if(x <= 0) return T(0);
        int res = 0, k = 1;
        while(k < n) k <<= 1;
        for(; k > 0; k >>= 1){
            if(res + k <= n && dat[res + k] < x){
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

/*
    vector<long long> a(n) を座圧する場合 : 
    auto v = compress(a);
    auto m = dict(v);
    i番目の要素の取り出し方 : 
    m[a[i]]
*/
template<typename T>
vector<T> compress(vector<T> vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

template<typename T>
map<T, int> dict(vector<T> & vec){
    map<T, int> res;
    for(int i = 0; i < (int)vec.size(); i++){
        res[vec[i]] = i;
    }
    return res;
}

signed main(){
    int q;
    cin >> q;
    vector<int> Q(q);
    vector<ll> a(q), b(q);
    vector<ll> t;
    REP(i,q){
        cin >> Q[i];
        if(Q[i] == 1){
            cin >> a[i] >> b[i];
            t.emplace_back(a[i]);
        }
    }
    auto v = compress(t);
    auto m = dict(v);
    int n = m.size();
    BIT<int> bit(n);
    BIT<ll> bita(n);
    ll sum = 0;
    int cnt = 0;
    REP(i,q){
        if(Q[i] == 1){
            sum += b[i];
            bit.add(m[a[i]] + 1, 1);
            bita.add(m[a[i]] + 1, a[i]);
            cnt++;
        }else{
            int itr = bit.lower_bound((cnt + 1) / 2);
            ll x = v[itr - 1];
            cout << x << " " << sum - bita.sum(itr - 1) + x * bit.sum(itr - 1) + bita.sum(itr + 1, n + 1) - x * bit.sum(itr + 1, n + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15476
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {
	int sets;
	cin >> sets;
	for (int i = 0; i < sets; ++i) {
		int a, b, c, d, ca, ans = 0;
		cin >> a >> b >> c >> d >> ca;
		for (int j = 0; j < ca; ++j) {
			int n, m;
			cin >> n >> m;
			if (a <= n && n <= a + c && b <= m && m <= b + d) { ++ans; }
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3036
#include<bits/stdc++.h>
#define f first
#define s second
#define N 500009
#define M (L+R)/2
#define inf 999999999999
#define pb push_back
#define ll long long
using namespace std;

ll n,ans,sum,mod=1000000007;
ll dp[3005][3005];
string s;
int main(){
    
    cin>>n;
    cin>>s;
 
	dp[1][1]=1;
	
	for(int i=2;i<=n;i++){
		for(int j=1;j<=i;j++){
			if(s[i-2]=='<')
				dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%mod;
				else 
				dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+dp[i][j-1]+mod)%mod;
		}
	}
	
    	cout<<dp[n][n]<<endl;
    return 0;   
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

string ans = "aiueo";

void solve(string c){
	REP(i,5){
    if(c[0] == ans[i]){
      cout << "vowel" << endl; return;
    }
  }
  cout << "consonant" << endl;
}



int main(){	
	ios::sync_with_stdio(false);
	string c;
	cin >> c;
	solve(c);
	return 0;
}


Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  lst = [list(map(int, input().split())) for _ in range(n)]
  lp, lq, lr, lc = map(int, input().split())
  flag = True
  for s, p, q, r in lst:
    if p <= lp and q <= lq and r <= lr and 4 * p + 9 * q + 4 * r <= lc:
      print(s)
      flag = False
  if flag:
    print("NA")



Measured memory_bytes: 5972
L = gets.chomp
M = 10**9 + 7

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % M
      n >>= 1
    else
      ret = ret * x % M
      n -= 1
    end
  end
  ret
end

ans, c, l = 0, 0, L.length
L.split('').map.with_index{|c, i| c == '1' ? i : nil}.compact.each do |i|
  d = l - i - 1
  ans += mpow(3, d) * mpow(2, c)
  ans %= M
  c += 1
end
ans += mpow(2, c)
puts ans % M

Measured memory_bytes: 11260
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int A, B, C, D; cin >> A >> B >> C >> D;
  if(C == A+1) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;



int main() {
	int n, l;
	cin >> n >> l;
	vector<string>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	string ans ={};
	for (int i = 0;i < n;i++) {
		ans += a.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
N, M = [int(i) for i in input().split()]
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for r in range(M):
            for c in range(M):
                if A[i + r][j + c] != B[r][c]:
                   flag = False
                   break
        if flag:
            print("Yes")
            quit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	long long int ans = 0ll;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		if(i%3!=0&&i%5!=0)
		{
			ans = (long long int) ans + i; 
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3800
//問題URL
//
 
//解き方メモ
//
    
#include<iostream>
using namespace std;
 
int main(){
  int abc[3];
  int five_cnt=0;
  int seven_cnt=0;
 
  cin >> abc[0] >> abc[1] >> abc[2];
 
  for(int i=0;i<3;i++){
    if(abc[i] == 5){
      five_cnt++;
    } else if(abc[i] == 7){
      seven_cnt++;
    }
  }

  if(five_cnt == 2 && seven_cnt == 1){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//#define LOCAL_DEFINE
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0);cin.tie(0)
using ll = long long;
using ull = unsigned long long;

const int maxn = 2e6 + 10;
int pre[maxn];

int main() {
  fastio;
  string s;
  cin >> s;
  reverse(ALL(s));
  vector<int> mp(2019, 0); // residue -> cnt
  mp[0] = 1;
  int base = 1;
  int sum = 0;
  rep(i, s.size()) {
    sum = sum + (s[i] - '0') * base;
    sum %= 2019;

    mp[sum]++;

    base *= 10;
    base %= 2019;
  }

  ull ans = 0;
  for (auto a : mp) {
    ans += (a*(a-1))/2;
  }
  cout << ans << '\n';

  
  #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3744
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] li = new int[4];
        for(int i = 0; i < 4; i++){
            li[i] = Character.getNumericValue(s[i]);
        }
        if(li[0]+li[1]+li[2]+li[3] == 7)System.out.println(li[0]+"+"+li[1]+"+"+li[2]+"+"+li[3]+"=7");
        else if(li[0]+li[1]+li[2]-li[3] == 7) System.out.println(li[0]+"+"+li[1]+"+"+li[2]+"-"+li[3]+"=7");
        else if(li[0]+li[1]-li[2]+li[3] == 7) System.out.println(li[0]+"+"+li[1]+"-"+li[2]+"+"+li[3]+"=7");
        else if(li[0]-li[1]+li[2]+li[3] == 7) System.out.println(li[0]+"-"+li[1]+"+"+li[2]+"+"+li[3]+"=7");
        else if(li[0]+li[1]-li[2]-li[3] == 7) System.out.println(li[0]+"+"+li[1]+"-"+li[2]+"-"+li[3]+"=7");
        else if(li[0]-li[1]-li[2]+li[3] == 7) System.out.println(li[0]+"-"+li[1]+"-"+li[2]+"+"+li[3]+"=7");
        else if(li[0]-li[1]+li[2]-li[3] == 7) System.out.println(li[0]+"-"+li[1]+"+"+li[2]+"-"+li[3]+"=7");
        else if(li[0]-li[1]-li[2]-li[3] == 7) System.out.println(li[0]+"-"+li[1]+"-"+li[2]+"-"+li[3]+"=7");
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#define inf 1000000000

using namespace std;

string s;
int N;
int Hash[200005];
int table[1<<26];
int dp[200005];

int main(void)
{
	cin >> s;
	N = s.size(); 
	s = " " + s;
	
	for(int i = 1; i <= N; i++){
		Hash[i] = Hash[i-1] ^ (1 << (s[i]-'a'));
	}
	for(int i = 1; i <= N; i++) dp[i] = inf;
	for(int i = 1; i < (1<<26); i++) table[i] = inf;
	
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 26; j++){
			dp[i] = min(dp[i], table[Hash[i] ^ (1<<j)] + 1);
		}
		dp[i] = min(dp[i], table[Hash[i]] + 1);
		table[Hash[i]] = min(table[Hash[i]], dp[i]);
	}
	
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 264264
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int get(int x)
{
	int low=0,high=x,mid,ans=low;
	while(low<=high)
	{
		mid=(low+high)/2;
		if(mid*(mid+1)/2<=x)
		{
			ans=mid;
			low=mid+1;
		}
		else high=mid-1;
	}
	return ans;
}
int32_t main() {
    IOS;

        ll n,cnt=0;
        cin>>n;
        for(int i=2;i*i<=n;++i)
        {
        	if(n%i==0)
        	{
        		int val=0;
        		while(n%i==0){n/=i;++val;}
        		cnt+=get(val);
        	}
        }
        if(n!=1)++cnt;
        cout<<cnt;



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 3652
//written by NewbieChd
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxN = 200003, yyb = 1e9 + 7;
int fac[maxN], invFac[maxN];
inline int power(int x, int y) {
    int o = 1;
    while (y) {
        if (y & 1)
            o = 1ll * o * x % yyb;
        x = 1ll * x * x % yyb, y >>= 1;
    }
    return o;
}

int main() {
    int n, m, k, lim, i, ans = 0;
    scanf("%d%d%d", &n, &m, &k), k -= 2;
    lim = n * m - 2, fac[0] = 1;
    for (i = 1; i <= lim; ++i)
        fac[i] = 1ll * fac[i - 1] * i % yyb;
    invFac[lim] = power(fac[lim], yyb - 2);
    for (i = lim; i; --i)
        invFac[i - 1] = 1ll * invFac[i] * i % yyb;
    for (i = 1; i < n; ++i)
        ans = (1ll * i * (n - i) * m * m + ans) % yyb;
    for (i = 1; i < m; ++i)
        ans = (1ll * i * (m - i) * n * n + ans) % yyb;
    ans = 1ll * ans * fac[lim] % yyb * invFac[k] % yyb * invFac[lim - k] % yyb;
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> heights(N);
    for (int i = 0; i < N; i++)
        cin >> heights[i];

    sort(heights.begin(), heights.end());

    int min = INFINITY;
    for (int i = 0; i < N - K + 1; i++)
    {
        if ( min > abs(heights[i] - heights[i + K - 1]))
            min = abs(heights[i] - heights[i + K - 1]);
    }

    cout << min;

    return 0;
}


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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		long G = sc.nextLong() / 100;
		long[] p = new long[D];
		long[] c = new long[D];
		for (int i = 0; i < D; ++i) {
			p[i] = sc.nextLong();
			c[i] = sc.nextLong() / 100;
		}
		long ans = Long.MAX_VALUE / 3;
		for (int s = 0; s < 1 << D; ++s) {
			long sum1 = 0, sum2 = 0;
			for (int i = 0; i < D; ++i) {
				if ((s & (1 << i)) > 0) {
					sum1 += p[i];
					sum2 += p[i] * (i + 1) + c[i];
				}
			}
			if (sum2 >= G)
				ans = Math.min(ans, sum1);
			for (int j = 0; j < D; ++j) {
				if ((s & (1 << j)) > 0)
					continue;
				long res = p[j];
				long tmp1 = sum1, tmp2 = sum2;
				while (tmp2 < G && res > 0) {
					++tmp1;
					tmp2 += (j + 1);
					--res;
				}
				if (res == 0)
					tmp2 += c[j];
				if (tmp2 >= G)
					ans = Math.min(ans, tmp1);
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 23892
#include<stdio.h>

int main(){

int n;
int P[102]={};
while(1){
scanf("%d",&n);if(n==0)break;
for(int i=0;i<n;i++)
scanf("%d",&P[i]);

int s=0;
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(P[j]>P[j-1]){int t=P[j];P[j]=P[j-1];P[j-1]=t;}

for(int i=0;i<n;i++)
if(i!=0&&i!=n-1)s+=P[i];

s=s/(n-2);
printf("%d\n",s);
}
return 0;
}

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

using namespace std;

int main(void){
    
    int n;
    cin >> n;
    
    int max = 1;
    int max_count = 0;
    for(int i=1; i<=n; i++) {
        int count = 0;
        int num = i;
        for(;;) {
            if(count > max_count) {
                max_count = count;
                max = i;
            }
            
            if(num%2==0) {
                count++;
                num /=2;
            }
            else {
                break;
            }
        }
    }

    cout << max << endl;

    return 0;
    
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 4e18
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll ans,a,b,c,d,n;
map <ll,ll> p;

inline ll dfs(ll x)
{
	//cout<<x<<endl;
	if(x==0) return 0; if(p[x]) return p[x];
	if(x<inf/d) p[x]=x*d;
	ll tmp=inf;
	if(x%2!=0)
	{
		ll q=x%2; tmp=min(tmp,dfs(x/2)+a+q*d);
		tmp=min(tmp,dfs(x/2+1)+a+q*d);
	}
	else tmp=min(tmp,dfs(x/2)+a);
	if(x%3!=0)
	{
		ll q=x%3; tmp=min(tmp,dfs(x/3)+b+q*d);
		tmp=min(tmp,dfs(x/3+1)+b+(3-q)*d);
	}
	else tmp=min(tmp,dfs(x/3)+b);
	if(x%5!=0)
	{
		ll q=x%5; tmp=min(tmp,dfs(x/5)+c+q*d);
		tmp=min(tmp,dfs(x/5+1)+c+(5-q)*d);
	}
	else tmp=min(tmp,dfs(x/5)+c);
	if(x<inf/d) return p[x]=min(p[x],tmp); else return p[x]=tmp;
}

int main()
{
	int T=read();
	while(T--)
	{
		n=read(),a=read(),b=read(),c=read(),d=read(); p.clear(); p[1]=d;
		printf("%lld\n",dfs(n));
	}
	return 0;
}

Measured memory_bytes: 4624
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;
int n,m;
struct T
{
    int outOrder,year,pref,prefOrder;
}c[200000];

void init()
{
    cin>>n>>m;
    for (int i=1; i<=m; ++i)
    {
        c[i].outOrder=i;
        cin>>c[i].pref>>c[i].year;
    }
    


}
void work()
{
    sort(c+1,c+m+1,[](T a,T b){if (a.pref!=b.pref) return a.pref<b.pref; return a.year<b.year;});
    for (int i=1; i<=m; ++i)
    {
        if (c[i].pref!=c[i-1].pref) c[i].prefOrder=1;else c[i].prefOrder=c[i-1].prefOrder+1;
    }
    sort(c+1,c+m+1,[](T a,T b){return a.outOrder<b.outOrder;});
    for (int i=1; i<=m; ++i)
    {
        printf("%06d%06d\n",c[i].pref,c[i].prefOrder);
    }
}

int main()
{
    init();
    work();
    return 0;
}




Measured memory_bytes: 3072
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let v = buf.split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect::<Vec<_>>();

    let ans = if v.into_iter().sum::<u32>() <= 21 { "win" } else { "bust" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll n,k;
	ll res = 0;
	static ll isvisited[200001] = {};
	scanf("%lld", &n);
	scanf("%lld", &k);
	static ll a[200001] = {0};
	FOR(i, 1, n) {
		scanf("%lld", &a[i]);
	}
	ll cnt = 0;
	ll pos = 1;
	ll loop = 0;
	while (1) {
		if (k == cnt) {
			res = pos;
			break;
		}
		if (isvisited[pos]) {
			loop = cnt - isvisited[pos];
			k -= isvisited[pos];
			k %= loop;
			FOR(i, 1, k) {
				pos = a[pos];
			}
			res = pos;
			break;
		}
		isvisited[pos] = cnt;
		pos = a[pos];
		cnt++;
	}

	printf("%lld\n", res);
	return(0);
}

Measured memory_bytes: 6388
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    string s; cin >> s;
    sort(s.begin(), s.end());

    if(s=="abc") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<set>
#include <climits>
#include<map>
#include<string>
#include<math.h>
#include<stack>
using namespace std;
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ll long long 
#define so(v) sort(v.begin(),v.end())
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define test 0
// const ll md=1000000007;
// ll dp[N],vis[N];

int main()
{
    ll t=1,n;
    if(test==1) cin>>t;
    while(t--)
    {
        ll x;
        cin>>x;
        ll p=100;
        ll i;
        ll y=0;
        while(p<x)
        {
            y++;
            i=p/100;
            p=p+i;
        }
        cout<<y;
    }
}

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

using namespace std;

int n, k;
const int maxn = 1e5 + 5;

int win[maxn];
int a[maxn];

int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        scanf("%d", &a[i]);
    }
    win[0] = 0;
    for(int i = 1;i <= k;i++){
        for(int j = 1;j <= n;j++){
            if(i >= a[j] and !win[i - a[j]]){
                win[i] = 1;
            }
        }
    }
    if(win[k]){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int M,S;
bool chk[300030][2];
bool chk1[300030],chk2[300030];
ll ans;

struct data{
	ll x,y,c;
	bool operator<(const data &l)const{
		return c<l.c;
	}
}inp[300030];

priority_queue <pll, vector<pll>, greater<pll> >pq1;
priority_queue <pll> pq2;
priority_queue <ll> pq3;

bool compx(const data &a,const data &b){return a.x<b.x;}
bool compy(const data &a,const data &b){return a.y<b.y;}

int N, X;
ll cans;

int main(){
	scanf("%d%d%d", &X, &M, &S);
	N = X + M + S;
	rep(i, X+M+S) {
		int x, y, z; scanf("%d%d%d", &x, &y, &z);
		cans += x;
		inp[i].x = y - x;
		inp[i].y = z - x;
		inp[i].c = i;
	}
	int i;
	sort(inp,inp+N,compx);
	for(i=N-M-S;i<N;i++)ans += inp[i].x, chk[inp[i].c][0] = 1;
	sort(inp,inp+N,compy);
	for(i=N-M-S;i<N;i++)chk[inp[i].c][1] = 1;
	sort(inp,inp+N);
	for(i=0;i<N;i++){
		if(chk[i][0]&&chk[i][1]){
			pq2.push(pll(inp[i].y-inp[i].x,i));
			pq1.push(pll(inp[i].x,i));
		}
		else if(chk[i][0])pq1.push(pll(inp[i].x,i));
		else if(chk[i][1])pq3.push(inp[i].y);
	}
	pq1.push(pll(1e18,1)), pq2.push(pll(-1e18,1)), pq3.push(-1e18);
	for(i=0;i<S;i++){
		pll a = pq1.top(), b = pq2.top();
		while(chk1[a.Se])pq1.pop(), a = pq1.top();
		while(chk2[b.Se])pq2.pop(), b = pq2.top();
		ll c = pq3.top();
		if(b.Fi >= c - a.Fi)ans += b.Fi, pq2.pop(), chk1[b.Se] = 1;
		else{
			ans += c - a.Fi;
			pq3.pop(),pq1.pop();
			if(chk[a.Se][1])chk2[a.Se] = 1, pq3.push(inp[a.Se].y);
		}
	}
	printf("%lld\n",ans + cans);
	return 0;
}
/*

void solve(){
	scanf("%d%d", &N, &M);
	for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) scanf("%d", A[i]+j);
	int ans = N;
	for(int i=1;i<=N;i++) for(int j=1;j<=M+1;j++) chk[i][j] = 1;
	int p[330] = {};
	for(int i=1;i<=N;i++) p[i] = 1;
	rep(a, M) {
		for(int i=1;i<=M;i++) cnt[i] = 0;
		int mx = 0, mxi = -1;
		for(int i=1;i<=N;i++) if(mx < ++cnt[A[i][p[i]]]) {
			mx = cnt[A[i][p[i]]];
			mxi = A[i][p[i]];
		}
		ans = min(ans, mx);
		
		for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) if(A[i][j] == mxi) chk[i][j] = 0;
		for(int i=1;i<=N;i++) while(chk[i][p[i]] == 0) ++p[i];
		
	}
	printf("%d\n", ans);
}

int main(){
	int T = 1; // scanf("%d", &T);
	while(T--) {
		solve();
	}
	
	return 0;
}
 */


Measured memory_bytes: 9928
/*input
3
ABCA
XBAZ
BAD
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int a = 0, b = 0;
  vector <int> vec1, vec2, vec3, vec4, vec5, vec6;
  vector <string> vec;
  int ans = 0;
  char last;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    vec.pb(str);
    int m = str.size();
    if (str[0] == 'A' && str[m - 1] == 'A') {
      vec1.pb(i);
    }
    else if (str[0] == 'A' && str[m - 1] == 'B') {
      vec2.pb(i);
      for (int j = 1; j < m; j++) {
        if (str[j] == 'B' && str[j - 1] == 'A') {
          ans++;
        }
      }
    }
    else if (str[0] == 'B' && str[m - 1] == 'A') {
      vec3.pb(i);
    }
    else if (str[0] == 'B') {
      vec4.pb(i);
    }
    else if (str[0] == 'A') {
      vec5.pb(i);
      //debug(str);
      for (int j = 1; j < m; j++) {
        if (str[j] == 'B' && str[j - 1] == 'A') {
          ans++;
        }
      }
    }
    else if (str[m - 1] == 'A') {
      vec6.pb(i);
    }
    else {
      //debug(str);
      for (int j = 1; j < m; j++) {
        if (str[j] == 'B' && str[j - 1] == 'A') {
          ans++;
        }
      }
    }
  }
  string temp;
  int ind = 0;
  bool f = false;
  if (vec1.size()) {
    f = true;
    ind = vec1[0];
    vec1.erase(vec1.begin());
  }
  else if (vec6.size()) {
    f = true;
    ind = vec6[0];
    vec6.erase(vec6.begin());
  }
  if (f) {
    temp += vec[ind];
  }
  for (auto it : vec3) {
    temp += vec[it];
  }
  //debug(temp);
  int ss = vec4.size();
  for (auto it : vec1) {
    if (ss) {
      temp += vec[vec4[--ss]];
    }
    temp += vec[it];
  }
  for (auto it : vec6) {
    if (ss) {
      temp += vec[vec4[--ss]];
    }
    temp += vec[it];
  }
  //debug(ss);
  while (ss) {
    temp += vec[vec4[--ss]];
  }
  string str = temp;
  //debug(temp);
  for (int j = 1; j < str.size(); j++) {
    if (str[j] == 'B' && str[j - 1] == 'A') {
      ans++;
    }
  }

  cout << ans << endl;



  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h)cin >> s[i];
  vector<vector<bool>> is(h,vector<bool>(w,1));
  rep(i,h){
    bool ok = true;
    rep(j,w)if(s[i][j] == '#')ok = false;
    if(ok)rep(j,w)is[i][j] = false;
  }
  rep(i,w){
    bool ok = true;
    rep(j,h)if(s[j][i] == '#')ok = false;
    if(ok)rep(j,h)is[j][i] = false;
  }
  rep(i,h){
    bool ok = false;
    rep(j,w)if(is[i][j])cout << s[i][j],ok = true;
    if(ok)cout << endl;
  }






  

  return 0;
}

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

struct process
{
	string name;
	int    time;
};

struct finished
{
	string name;
	int    time;
};

queue<finished> RoundRobin(queue<process> X, int q)
{
	queue<finished> Y;
	int totaltime = 0;
	while(X.size() > 0){
		if(X.front().time <= q){
			totaltime += X.front().time;
			finished output;
			output.name = X.front().name;
			output.time = totaltime;
			X.pop();
			Y.push(output);
		}else{
			totaltime += q;
			X.front().time -= q;
			X.push(X.front());
			X.pop();
		}
	}
	return Y;
}

int main()
{
	int n, q;
	cin >> n;
	cin >> q;
	queue<process> Input;
	for(int i = 0; i < n; i++){
		process imput;
		cin >> imput.name >> imput.time;
		Input.push(imput);
	}
	queue<finished> Output = RoundRobin(Input, q);
	for(int i = 0; i < n; i++){
		cout << Output.front().name << " " << Output.front().time << endl;
		Output.pop();
	}
	return 0;
}

Measured memory_bytes: 5228
n = int(input())


def check(i):
    return T <= t*i and A <= a*i


T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    L = 1
    R = 10**18
    flag = 0
    while True:
        M = (L+R)//2
        if check(M):
            R = M
        else:
            L = M
        if flag:
            break
        if L == R-1:
            flag = 1
    T = t*R
    A = a*R


print(T+A)


Measured memory_bytes: 9160
#include<iostream>

int main(){

	int n, x;
	while (std::cin >> n >> x, n || x){
		int cnt = 0;

		for (int i = 1; i <= n - 2; i++){
			for (int j = i + 1; j <= n - 1; j++){
				for (int k = j + 1; k <= n; k++){
					if (i + j + k == x)cnt++;
				}
			}
		}

		std::cout << cnt << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  cin  >> N >> X;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);
  
  int cnt = 1;
  int lng = 0;
  for (int i = 0; i < N; i++) {
    lng += L.at(i);
    if (lng > X) break;
    cnt++;
  }
  
  cout << cnt << endl;
}


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

#define rep(i, n) for(int i=0; i < (int)n; i++)

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

int card[4][13];

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

  char mark;
  int number, tmp;
  rep(_, n) {
    cin >> mark >> number;
    if(mark == 'S') tmp = 0;
    if(mark == 'H') tmp = 1;
    if(mark == 'C') tmp = 2;
    if(mark == 'D') tmp = 3;
    card[tmp][number-1] = 1;
  }

  rep(i, 4*13) {
    if(card[i/13][i%13] == 0) {
      if(i/13 == 0) mark = 'S';
      if(i/13 == 1) mark = 'H';
      if(i/13 == 2) mark = 'C';
      if(i/13 == 3) mark = 'D';
      cout << mark << " " << i%13+1 << endl;
    };
  }
}



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

int main(){ 
  int n;
  cin >> n;
  vector<vector<int> > g(n);
  rep(i,n-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  vector<int> c(n);
  int sum = 0;
  rep(i,n) cin >> c[i], sum += c[i];
  sort(c.begin(), c.end(), greater<int>());
  sum -= c.front();
  queue<P> que;
  vector<P> res;
  que.push(make_pair(0,-1));
  int idx = 0;
  while (!que.empty()) {
    P ver = que.front(); que.pop();
    int u = ver.first, p = ver.second; 
    res.emplace_back(make_pair(u,c[idx]));
    idx++;
    for (auto v : g[u]) {
      if (v == p) continue;
      que.push(make_pair(v,u));
    }
  }
  sort(res.begin(), res.end());

  cout << sum << endl;
  for (auto e : res) {
    cout << e.second << " ";
  }
  cout << endl;
  return 0;
} 

Measured memory_bytes: 1280