akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 本番では　
//     N = rR + gG + bB
// となることまでは簡単にわかって、数値r,g,bを固定してまわす方針も考えたが、
// なんとなく実行速度がやばそうな気がして、突っ込めなかった。
// しかし、冷静に考えると高々（3000)^2の　O(N^2)　で、オーダーは9000000　＝　9＊10^6　と問題なかった。

// 教訓として、全探索でいけそうなときは、とりあえずぶん回す方針をとることを考えるべきである
// ということを学んだ。

int main(){
    int R,G,B,N;
    int count = 0;
    cin >> R >> G >> B >> N ;
    for (int i = 0;i < N+1;i++){
        for (int j = 0;j < N+1;j++){
            int v = R*i + G*j ;
            if(N - v < 0)continue;
            if((N - v) % B == 0){
                count += 1;
               // cout << '(' << i << ',' << j << ',' << (N-v)/B << ')' << endl; 
               //確認用
            }
        }
    }
    cout << count << endl;
}
//2019 0512 AC 済み

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "bits/stdc++.h"
using namespace std;
#define endl '\n'
#define stop system("pause")
#define sz(x) (int)(x.size())
#define all(x) begin(x),end(x)
#define lla(x) x.rbegin(),x.rend()
using ll = long long;using vi = vector<int>;
#define debug(v) cout<<#v<<":";cout<<v<<endl
using pii = pair<int, int>;const int MX = 2e5 + 10;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,b) for(register int i=0,i##len=(int)(b);i< i##len;++i)
#define rpp(i,b) for(register int i=1,i##len=(int)(b);i<=i##len;++i)
template <typename T> istream& operator>>(istream &is,vector<T> &v) {for(auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template <typename T> ostream& operator<<(ostream &os,const vector<T> &v) {for(auto i = begin(v);i!=end(v);i++) os<<*i<<(i==end(v)-1?"\n":" ");return os;}
template<typename T>inline void rd(T &s){s=0;T t=1,k=getchar();for(;k<'0'||k>'9';k=getchar())if (k=='-')t=-1;for(;k>='0'&&k<='9';k=getchar())s=(s<<1)+(s<<3)+(k^48);s*=t;}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



vector<ll>ans;
ll q[(int)1e7];
void pre()
{
    int l=1,r=0;
    rpp(i,9) q[++r]=i;
    while(l<=r)
    {
        ll x=q[l++];
        if(x>1e11) break;
        ans.push_back(x);
        q[++r]=x*10+(x%10);
        if(x%10!=0) q[++r]=x*10+(x%10-1);
        if(x%10!=9) q[++r]=x*10+(x%10+1);
    }
    sort(all(ans));
}
signed main()
{
    pre();
    int k;cin>>k;
    cout<<ans[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 22892
/*
      author : nishi5451
      created: 11.08.2020 00:13:27
*/

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


int main(){
    int x;
    cin >> x;
    if(x<1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define sci(x) scanf("%d",&x)
#define scs(s) scanf("%s",s)
#define scc(c) scanf("%c",c)
#define scd(d) scanf("%lf",&d)
#define scld(ld) scanf("%Lf",&ld)
using namespace std;

//********************************************
//Error tracking
#define show(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}
//********************************************

const int mod = 1000000007;
const int NMAX = 3005;

int n, m, dp[2][NMAX][2];
//dp[i][j] = number of conf to remain with j reds after i steps (0 / 1 is step)

int Mod(int x)
{
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;

	return x;
}

int main()
{
    //freopen("input","r",stdin);
   // freopen("output","w",stdout);
    cin.sync_with_stdio(false);
    
    int i, j;
    cin >> n >> m;
   	for (i = 0; i <= n; i++) dp[0][i][0] = 1;

   	bool ok = 1;
   	for (i = 1; i <= m; i++, ok = 1 - ok)
   	{
   		//clean
   		for (j = 0; j <= n; j++)
   			for (int l = 0; l <= 1; l++) 
   				dp[ok][j][l] = 0;

   		for (int conf = 0; conf < 4; conf++) //the conf for two blocks
   		{
   			int red1 = 0, blue1 = 0, red2 = 0, blue2 = 0;
   			if (conf & 1) blue1 = 1;
   			else red1 = 1;
   			if (conf & 2) blue2 = 1;
   			else red2 = 1;
   			for (j = 0; j <= n; j++) //step from which we come
   				for (int l = 0; l <= 1; l++)
	   				if (red1 <= j && blue1 <= (n - j)) //good
	   				{
	   					int val = j + 1 - red1 - red2;
	   					int ls = l;
	   					if ((j == 1 && red1 == 1) || (j == 0 && blue1 == 1))//special op
	   						ls = 1;
	   					dp[ok][val][ls] = Mod(dp[ok][val][ls] + dp[1 - ok][j][l]);
	   				}
   		}
   	}

   	int sol = 0;
   	for (i = 0; i <= n; i++) sol = Mod(sol + dp[1 - ok][i][1]);

   	cout << sol << "\n";
    return 0;   
}

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll n;
ll a[maxs];
vector<ll> tree[maxs];
ll ans[maxs];
vector<ll> v;

void dfs(ll s,ll p){
    ll pos = lower_bound(v.begin(),v.end(),a[s]) - v.begin();
    ll tmp = v[pos];
    v[pos] = a[s];
    ans[s] = lower_bound(v.begin(),v.end(),oo) - v.begin();
    for(auto d : tree[s]){
        if(d!=p){
            dfs(d,s);
        }
    }
    v[pos] = tmp;
}

void solve(){
    
    cin >> n;
    for(ll i=0;i<n;i++)
        cin >> a[i];
    
    for(ll i=0;i<n-1;i++){
        ll s,d;
        cin >> s >> d;
        s--;d--;
        tree[s].pb(d);
        tree[d].pb(s);
    }
    v.resize(n,oo);
    dfs(0,-1);

    for(ll i=0;i<n;i++){
        cout << ans[i] << endl;
    }

}

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

Measured memory_bytes: 30388
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,p,ans=1145141919;
	cin>>n>>m>>p;
	vector<int>V;
	while(m--){
		int t;cin>>t;
		V.push_back(t);
	}
	sort(V.begin(),V.end());
	V.push_back(V[0]);
	for(int i=0;i+1<V.size();i++){
		int t=n-V[i+1]+V[i]-(V[i+1]<=V[i]?n:0);
		int a=V[i]-p+(V[i]<p?n:0);
		int b=p-V[i]+(V[i]>p?n:0);
		ans=min(ans,t+min(a,b));
		a=V[i+1]-p+(V[i+1]<p?n:0);
		b=p-V[i+1]+(V[i+1]>p?n:0);
		ans=min(ans,t+min(a,b));
	}
	cout<<ans<<"00"<<endl;
	return 0;
}


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

int main(){
  int X,N;
  cin >> X >> N;
  set<int> s;
  for(int i=0;i<N;i++){
    int p;
    cin >> p;
    s.insert(p);
  }
  for(int i=0;;i++){
    if(!s.count(X-i)){
      cout << X-i << endl;
      return 0;
    }
    if(!s.count(X+i)){
      cout << X+i << endl;
      return 0;
    }
  }
  return 0;
}


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

class UnionFind {
public:
    vector<int> uni;
    UnionFind(int s) : uni(s, -1) {}
    int root(int a) {
        return uni[a] < 0 ? a : uni[a] = root(uni[a]);
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] = uni[a] + uni[b];
        uni[b] = a;
        return true;
    }
    bool isConnect(int a, int b) {
        return root(a) == root(b);
    }
    int size(int a) {
        return -uni[root(a)];
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.connect(a, b);
    }
    set<int> st;
    rep(i, N) st.insert(uf.root(i));
    cout << st.size() - 1 << '\n';
    return 0;
}


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

constexpr int INF=1e9;

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		vector<tuple<int,int,int>> es;
		for(int i=0;i<m;i++){
			int u,v,w; cin>>u>>v>>w; u--,v--;
			es.emplace_back(u,v,w);
		}
		vector<vector<int>> dp(n,vector<int>(n,INF));
		for(int i=0;i<n;i++)
			dp[i][i]=0;
		for(auto e:es){
			int u,v,w; tie(u,v,w)=e;
			dp[u][v]=dp[v][u]=w;
		}
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
		int res=0;
		for(auto e:es){
			int u,v,w; tie(u,v,w)=e;
			bool used=false;
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					if(dp[i][j]==dp[i][u]+w+dp[v][j]||dp[i][j]==dp[i][v]+w+dp[u][j])
						used=true;
			res+=!used;
		}
		cout<<res<<endl;
	}
}


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

int main()
{
    int N,M;
    cin >> N >> M;
    for(int i = M/N ; i >= 0; i--)
    {
        if(M%i == 0)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>

using namespace std;

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

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

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

const int N=2e6+5;
const int oo=1e9+7;

int n;
string s,t;

int h[N];


int Tree [N+10];

void update(int idx, ll x,int n)
{
    // Let, n is the number of elements and our queries are
    // of the form query(n)-query(l-1), i.e range queries
    // Then, we should never put N or MAX in place of n here.
    assert(idx>=1);
    while(idx<=n)
    {
        Tree[idx]+=x;
        idx+=(idx&-idx);
    }
}

int query(int idx)
{
    ll sum=0;
    while(idx>0)
    {
        sum+=Tree[idx];
        idx-=(idx&-idx);
    }
    return sum;
}

int val(int idx)
{
    return query(N ) - query(idx-1);
}

int now  = 1 ;


int solve()
{
    if(s==t)
        return 0;
    s="#"+s;
    t="#"+t;

    vector<int > x;
    for(int i=1; i<=n; i++)
    {
        if(i>1 and t[i]==t[i-1])
            continue ;
        x.push_back(i);
    }
    reverse(ALL(x));



    int ss = n;
    int ret =1;

    for(int tt: x)
    {
        while(ss >=1 )
        {
            if(ss<=tt and s[ss] == t[tt])
                break;
            else
            {
                ss--;
                now++;
            }
        }
        if(ss>=1)
        {
            if(ss!=tt)
            {
//                for(int i= ss; i<tt; i++)
//                    h[i] =h[i+1] + 1;
//                h[tt]++;
//                ret = max(ret,  h[tt] + 1);

                int old = val(now-(tt-ss));
                now--;
                update(now , 1 , N);
//                assign_index( now - (tt-ss), old + 1 );
                ret =max(ret, old + 2);

//                assert(old+2 == h[tt]+1);

            }
            ss--;
            now++;
        }
        else
            return -1;
    }
    return ret;
}

int32_t main()
{
    FastIO;
    cin>>n>>s>>t;
    cout<<solve()<<"\n";
}


Measured memory_bytes: 13552
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  const ll MAX = 100;

  ll n; cin >> n;
  ll mat[MAX][MAX];
  rep(i, n)rep(j, n) cin >> mat[i][j];

  vector<bool> mst(n, false);
  ll ans = 0;
  mst[0] = true;
  priority_queue<tuple<ll, ll, ll>> pq;
  for (int i = 1; i < n; i++) {
    if (mat[0][i] != -1) pq.emplace(-mat[0][i], 0, i);
  }

  ll w, f, t;
  rep(i, n-1) {
    while(1) {
      tie(w, f, t) = pq.top(); pq.pop();
      if (mst[f] && !mst[t]) break;
    }
    // debug3(-w, f, t);
    ans += mat[f][t];
    mst[t] = true;

    for (int j = 0; j < n; j++) {
      if (t != j && mat[t][j] != -1) pq.emplace(-mat[t][j], t, j);
    }
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N);
    REP(i, M) {
        ll a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    vector<ll> dist(N, -1);
    vector<ll> next(N, 1e8);
    queue<ll> que;
    dist[0] = 0;
    que.push(0);
    ll v = 0;
    while (!que.empty()) {
        v = que.front();
        que.pop();
        for (ll nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v]+1;
            if (next[nv] > dist[v]+1) next[nv] = v;
            que.push(nv);
        }
    }

    bool can = true;
    FOR(i, 1, N) if (dist[i] == -1) can = false;
    if (can) cout << "Yes\n";
    else cout << "No\n";
    FOR(i, 1, N) {
        cout << next[i]+1 << "\n";
        //cout << i << ": " << dist[i] << ": " << next[i] << "\n";
    }
}


Measured memory_bytes: 13728
#include<iostream>

using namespace std;

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	if (k == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i * m + j * n - 2 * i * j == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int D, T, S;
	cin >> D >> T >> S;
	int t = (D + S - 1) / S;
	puts([&] {
		return t <= T;
	}() ? "Yes": "No");
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, X, M;
  cin >> N >> X >> M;
  

  int now = X;

  vector<int> used(M, -1);
  used[now] = 0;

  
  int cnt = 1;
  int loop = 1;
  REP(i, N){
    now = (now*now)%M;
    if(used[now] != -1){
      loop = cnt-used[now];
      break;
    }
    used[now] = cnt++;
  }

  N -= used[now];
  cnt = (N)/loop;

  int ans = 0;
  REP(i, M){
    if(used[i] == -1) continue;
    if(used[i] < used[now]) ans += i;
    else{
      ans += cnt*i;
      if(used[i]-used[now] < N%loop) ans += i;
    }
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3984
n,p=map(int,input().split())
ans=1
if(n==1):
    print(p)
    exit()
cnt=0    
s=int(pow(p,1/n))+1
for i in range(s,1,-1):
    q=p
    cnt=0
    while(q>0):
        if(q%i!=0):
            break
        cnt+=1
        q=int(q/i) 
        #print(q)     
    #print(cnt,i)      
    if(cnt>=n):
        ans=i
        break    
print(ans)        



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

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int main()
{
    int n, m, x;
    int c[12];
    int a[12][12];
    cin >> n >> m >> x;
    rep(i, n) {
        cin >> c[i];
        rep(j, m) {
            cin >> a[i][j];
        }
    }

    int learn[12] = { 0.0 };
    int money = 0;
    int ans = INF;
    for (int bit = 1; bit < (1 << n); bit++) {
        rep(i, m) learn[i] = 0;
        money = 0;
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                rep(j, m) learn[j] += a[i][j];
                money += c[i];
            }
        }
        bool is_ok = true;
        rep(i, m) {
            if (learn[i] < x) is_ok = false;
        }
        if (is_ok) ans = min(ans, money);
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
const double pi=3.141592653589793;

vector<P> seg;
ll n=1;
void update(ll i,ll x){
    i=n+i-1;
    seg[i].first=x;
    while(i>0){
        i=(i-1)/2;
        if(seg[i*2+1].first<seg[i*2+2].first){
            seg[i].first=seg[i*2+1].first;
            seg[i].second=seg[i*2+1].second;
        }
        else{
            seg[i].first=seg[i*2+2].first;
            seg[i].second=seg[i*2+2].second;
        }
    }
}
P solve(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return P(inf,-1);
    if(a<=l&&r<=b)return seg[k];
    P c1=solve(a,b,k*2+1,l,(l+r)/2);
    P c2=solve(a,b,k*2+2,(l+r)/2,r);
    return min(c1,c2);
}
vector<P> dd; //頂点の番号、深さ
vi f,dis;
vector<vector<PP>> v; //頂点の番号、色、長さ
void dfs(int i,int depth,int dist,int p){
    if(f[i]==inf)f[i]=dd.size();
    if(dis[i]==inf)dis[i]=dist;
    dd.eb(i,depth);
    for(auto x:v[i]){
        if(p==get<0>(x))continue;
        dfs(get<0>(x),depth+1,dist+get<2>(x),i);
        dd.eb(i,depth);
    }
}
vi ans,sum,num;
vector<vector<PPP>> query;
void dfss(int i,int p){
    for(auto t:query[i]){
        ans[get<3>(t)]+=(dis[i]-sum[get<0>(t)]+num[get<0>(t)]*get<1>(t))*get<2>(t);
    }
    for(auto x:v[i]){
        if(p==get<0>(x))continue;
        sum[get<1>(x)]+=get<2>(x);
        num[get<1>(x)]++;
        dfss(get<0>(x),i);
    	sum[get<1>(x)]-=get<2>(x);
    	num[get<1>(x)]--;
    }
}
int main(){
    ll N,q;cin>>N>>q;
    ans=vi(q);
    sum=vi(N-1);
    num=vi(N-1);
    f=vi(N,inf);
    dis=vi(N,inf);
    v=vector<vector<PP>>(N);
  	query=vector<vector<PPP>>(N);
    rep(i,N-1){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        a--;b--;
        v[a].eb(b,c,d);
        v[b].eb(a,c,d);
    }
    dfs(0,0,0,-1);
    ll t=dd.size();
    while(n<t)n*=2;
    while(dd.size()!=n)dd.eb(inf,inf);
    seg=vector<P>(n*2-1,P(inf,-1));
    rep(i,n)seg[i+n-1]=P(dd[i].second,i);
    for(int i=n-2;i>=0;i--)seg[i]=min(seg[i*2+1],seg[i*2+2]);
    rep(i,q){
        ll x,y,a,b;cin>>x>>y>>a>>b;
        a--;b--;
        ll ai=f[a],bi=f[b];
        if(ai>bi)swap(ai,bi);
        ll lca=dd[solve(ai,bi+1,0,0,n).second].first;
        query[a].eb(x,y,1,i);
        query[b].eb(x,y,1,i);
        query[lca].eb(x,y,-2,i);
    }
    dfss(0,-1);
  for(int x:ans)cout<<x<<endl;
}

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

int main(){
    int count=0;
    string S;
    cin >> S;
    for(int i=0;; i++){	
	if(S[i]=='\0'){
	    count+=15-i;
	    break;
	}
	if(S[i]=='o'){
	    count++; 
	}
    }
    if(count >=8)
	cout<<"YES"<<endl;
    else
	cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long P = 1000000007;

class C {
public:
  int n;
  vector<long long> fac, inv, facInv;
  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = 1;
    fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = 1;
    facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  long long comb(int N, int K) {
    if (N == 0 || K == 0 || K == N)
      return 1;
    if (N < K || K < 0 || N < 0)
      return 0;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
};

long long mul(long long a, long long b) { return (a * b) % P; }

long long add(long long a, long long b) { return (a + b) % P; }

int main() {
  int n;
  cin >> n;
  C c(2000001);
  if (n == 2) {
    cout << 1 << endl;
  } else if (n == 3) {
    cout << 4 << endl;
  } else {
    long long ans = 0;
    vector<long long> dp(2000001);
    dp[0] = dp[1] = 0;
    for (int i = 2; i < n; i++) {
      dp[i] = mul(c.comb(i - 1, n - 1 - i), mul(c.fac[i], c.fac[n - i - 1]));
    }
    for (int i = 1; i < n; i++) {
      ans = add(ans, mul(i, (dp[i] - dp[i - 1] + P) % P));
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 62720
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  x, y, a, b, c = map(int, input().split())
  p = list(map(int, input().split()))
  q = list(map(int, input().split()))
  r = list(map(int, input().split()))
  p.sort(reverse=True)
  q.sort(reverse=True)
  r += p[:x] + q[:y]
  r.sort(reverse=True)
  ans = sum(r[:x+y])
  print(ans)
  

if __name__ == '__main__':
  main()

Measured memory_bytes: 24652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n,m;
    cin >> n >> m;
    ll sum = 0;
    for(ll i = 0;i < m;i++){
        ll x;
        cin >> x;
        sum += x;
    }
    if(sum > n){
        cout << -1 << endl;
    }
    else{
        cout << n-sum << endl;
    }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
template<class val_t>
class TreeArray {
    val_t* a;
    int maxn;
public:
    TreeArray():a(NULL),maxn(0){}

    ~TreeArray()
    {
        delete[](a);
    }
    void Init(size_t siz) 
    {
        delete[](a);
        maxn = siz;
        a = new val_t[siz + 8];
        refresh();
    }
    void refresh()
    {
        for(int i=0;i<=maxn;++i)
            a[i] = 0;
    }
    int lowbit(int x)
    {
        return x & (-x);
    }
    void modify(int x,val_t add)
    { 
        while(x<=maxn) 
        {     
            a[x]+=add;   
            x+=lowbit(x);
        }
    }
    val_t get_sum(int x)
    { 
        val_t ret=0;
        while(x) 
        {      
            ret+=a[x];  
            x-=lowbit(x);  
        } 
        return ret;
    }
};


int N,Q;
string S;


int main(){
    cin>>N>>S>>Q;
    TreeArray<int> trees[26];
    for(int i=0;i<26;++i)
        trees[i].Init(N+7);
    S = '0'+S;
    for(int i=1;i<=N;++i)
    {
        trees[S[i]-'a'].modify(i,1);
    }
    while(Q--)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            int pos;
            char c;
            cin>>pos>>c;
            trees[S[pos]-'a'].modify(pos,-1);
            trees[c-'a'].modify(pos,1);
            S[pos] = c;
        }else
        {
            int l,r;
            cin>>l>>r;
            int cnt = 0;
            for(int i=0;i<26;++i)
            {
                if(trees[i].get_sum(r) - trees[i].get_sum(l-1) > 0)
                    cnt++;
            }
            cout<<cnt<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 53784
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
struct edge{int to;ll cost;};
typedef pair<ll,int> P;
const ll INF=1000000000000LL;
const ll MOD=1000000007LL;
const ll MAX=100010;
int main(){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
	return 0;
}



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

typedef long long ll;

const ll MOD = 1e9+7;

ll ModPow(ll base,ll exp,ll mod){
  ll ret = 1;
  base %= mod;
  while(exp>0){
    if(exp&1) ret = (ret*base)%mod;
    base = (base*base)%mod;
    exp >>= 1;
  }
  return ret;
}

ll ModInv(ll base,ll mod){
  return ModPow(base,mod-2,mod);
}

ll Comb(ll n, ll r,ll *fct,ll *fct_inv){
  return fct[n]*(fct_inv[r]*fct_inv[n-r]%MOD)%MOD;
}

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

  ll fct[5001];
  fct[0] = fct[1] = 1;
  for(ll i=2; i<=n; fct[i]%=MOD,i++)
    fct[i] = fct[i-1]*(i%MOD);

  ll fct_inv[5001];
  for(ll i=0; i<=n; i++)
    fct_inv[i] = ModPow(fct[i],MOD-2,MOD);

  for(ll i=0; i<k; i++)
    cout << (Comb(k-1,i,fct,fct_inv)*Comb(n-k+1,i+1,fct,fct_inv))%MOD << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 1e5+1;
const ll mod = 1e9+7;


int main(){

    FASTIO;
    PRECISION;

    int n,m;
    cin>>n>>m;

    if(n%2){
        int a = 1, b = n-1;
        while(m){
            cout<<a<<" "<<b<<"\n";
            a++;
            b--;
            m--;
        }
    }else{
        int a = 1, b = n-1;
        int done = false;

        while(m--){

            if(!done && b-a<=n/2){
                done = true;
                b--;
            }
            cout<<a<<" "<<b<<"\n";

            b--;
            a++;
        }
    }

}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam -1];
#define range(n) for(int i = 0; i < n; i++)
#define maxn 100000
#define mod 1000000007
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
int n, m, a, b, c;
int li[200010];
int dp[200010];
int ultim[200010];
int prox[200010];

int main(){
    sc("%d\n", &n);
    memset(li, 0, sizeof li);
    memset(dp, 1, sizeof dp);
    memset(ultim, -1, sizeof ultim);
    memset(prox, -1, sizeof prox);
    li[0] = -1;
    int j = 1;
    for(int i = 1; i <= n; i++) {
        sc("%d", &a);
        if (a != li[j-1]) {
            li[j++] = a;
        }
    }
    dp[j] = 1;
    j--;
    //pr("j: %d\n", j);
    for(int i = j; i >= 1; i--) {
        //pr("prox[%d]: %d", i, ultim[li[i]]);
        //pr("ultim[%d]: %d", li[i], i);
        prox[i] = ultim[li[i]];
        ultim[li[i]] = i;
        //pr("prox[%d]: %d", i, prox[i]);
        //pr("\n");
    }
    for(int i = j; i >= 1; i--) {
        int a = dp[i+1];
        int b = ((prox[i] == -1) ? 0 : dp[prox[i]]);
        //pr("prox[%d]: %d, a: %d, b: %d\n", i, prox[i],a ,b);
        dp[i] = (a+b) % 1000000007;
    }
    pr("%d\n", dp[1]);
 	return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
using namespace std;
int n,cut=0,k=400000,k_1=0,che[400000]={},sum[400000]={};
char a[400000]={};
int main(){
    scanf("%d",&n);
    scanf("%s",a);
    for(int i=0;i<n;i++){
        if(a[i]=='W') che[i]=0;
        else if(a[i]=='E') che[i]=1;
    }
    sum[0]=che[0];
    for(int i=1;i<n;i++){
        sum[i]=sum[i-1]+che[i];
    }
    while(cut<n){
        int l=cut-sum[cut-1];
        int r=sum[n-1]-sum[cut];
        if(cut==0) l=0;
        else if(cut==(n-1))r=0;
        k_1=r+l;
        if(k>k_1) k=k_1;
        cut++;
    }
    printf("%d",k);
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
int n, a[nmax];
unordered_map<int,int>mp;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        mp[a[i]] = i;
    }
    sort(a+1,a+n+1);
    int ans = 0;
    for (int i=n;i>=1;--i){
        int poz = mp[a[i]];
        if (abs((i-poz)%2) == 1){
            ++ans;
        }
    }
    cout<<ans/2<<'\n';
    return 0;
}


Measured memory_bytes: 4900
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;

ll dp[100][400];

int dp1[16002][3]={};
int dp2[16002][3]={};
ll c[200001]={};
int main() {
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	char chr1[]="abcdefghijklmnopqrstuvwxyz";
	char chr2[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for(int i=0;i<26;++i){
		if(s1[0]==chr1[i])cout<<chr2[i];
	}
	for(int i=0;i<26;++i){
		if(s2[0]==chr1[i])cout<<chr2[i];
	}
	for(int i=0;i<26;++i){
		if(s3[0]==chr1[i])cout<<chr2[i];
	}
	cout<<endl;
//	int ls=s.length();
//
//	int m=0;
//	int a1=0;
//	int a2=0;
//	int a3=0;
//	int a0=0;
//	bool flg=true;
//	for(a1=1;(s[a1]==s[a1-1])&&(a1<ls);a1++);
//	m=a1-a0;
//	for(a2=a1+1;(s[a2]==s[a2-1])&&(a2<ls);a2++);
//	m=max(a2-a1,a1-a0);
//	if(a2==ls)flg=false;
//	for(a3=a2+1;a3<ls;a3++){
//		for(;(s[a3]==s[a3-1])&&(a3<ls);a3++);
//		m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//		a0=a1;
//		a1=a2;
//		a2=a3;
//	}
//	if(flg)m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]
ansmin = 2
ansmax = 2
for x in a:
  ansmin = x*((ansmin+x-1)//x)
  ansmax = x*(ansmax//x)+x-1
  if ansmin>ansmax:
    print(-1)
    exit()
print(ansmin,ansmax)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF=1e9;
const ll MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int w;
int p = 4280;

void solve() {
    int sum = 0;
    sum += 1150;
    sum += max(0, min(10, w - 10)) * 125;
    sum += max(0, min(10, w - 20)) * 140;
    sum += max(0, w - 30) * 160;

    cout << 4280 - sum << endl;
}

int main() {
    while(cin>>w) {
        if(w == -1) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll m=in(),d=in();
    ll cnt=0;
    for(ll i=1;i<=m;++i){
        for(ll j=1;j<=d;++j){
            ll d1=j%10,d10=j/10;
            if(d1>=2&&d10>=2&&d1*d10==i)++cnt;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

A = np.array(list(readline().rstrip()),np.int32)-ord('0')
B = np.array(list(readline().rstrip()),np.int32)-ord('0')

N = len(A)

if np.count_nonzero(B)==0:
    if np.count_nonzero(A)==0:
        print(0)
    else:
        print(-1)
    exit()

def F(A,B):
    # 終了位置が右シフトしている場合
    # まず、B[0]=0となるようにシフト
    shift = np.where(B)[0][0]
    A = np.roll(A,-shift)
    B = np.roll(B,-shift)
    B2 = np.tile(B,2)
    # 自身の左右にある1の位置
    x = np.arange(N) * B; np.maximum.accumulate(x,out=x); left=x
    x = (N*(1-B) + np.arange(N)*B)[::-1]; np.minimum.accumulate(x,out=x); right = x[::-1]
    left = np.concatenate([left,left+N])
    right = np.concatenate([right,right+N])
    opt = 10**18
    for n in range(N+1):
        # 右にn回動かす
        diff = (A != B2[n:n+N]) # 書き換えるもの
        change_cost = np.count_nonzero(diff)
        move_left = np.maximum(0,np.arange(N) - np.maximum(left[:N],left[n:n+N]))
        move_left[~diff] = 0
        move_right = np.maximum(0,np.minimum(right[:N],right[n:n+N])-np.arange(n,n+N))
        move_right[~diff] = 0
        ind = (move_left)>0
        L=move_left[ind]; R=move_right[ind]
        I = np.lexsort((R,L)); L=L[I]; R=R[I]
        x = np.zeros(N,np.int32) # 左移動回数ごとの右移動回数
        x[L-1] = R
        x = x[::-1]; np.maximum.accumulate(x,out=x); x=x[::-1]
        move_cost = n + 2*(np.arange(N)+x).min()
        cost = move_cost + change_cost
        if opt > cost:
            opt = cost
    return opt

x = F(A,B)
A = A[::-1]; B = B[::-1]
y = F(A,B)
A = A[::-1]; B = B[::-1]
answer = min(x,y)
print(answer)

Measured memory_bytes: 14576
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int[] ans = new int[3];
        
        ans[0] = A + B;
        ans[1] = A - B;
        ans[2] = A * B;
        
        int max = -100000000;
        for(int i = 0; i < 3; i++){
            max = Math.max(max, ans[i]);
        }
        
        System.out.println(max);
    }
}


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

ll solve(const int N, vector<pair<int, int>> v) {
  sort(v.begin(), v.end());
  v.emplace_back(N+1, 0);
  priority_queue<int, vector<int>, greater<>> q;
  int idx = 0;
  for (int i = 0; i <= N; i++) {
    while (v[idx].first == i) q.push(v[idx++].second);
    while (i < q.size()) q.pop();
  }
  ll res = 0;
  while (q.size()) {
    res += q.top();
    q.pop();
  }
  return res;
}

int main() {
  int T; cin >> T;
  while (T--) {
    ll res = 0;
    int N; cin >> N;
    vector<pair<int, int>> l, r;
    for (int i = 0; i < N; i++) {
      int K, L, R; cin >> K >> L >> R;
      res += min(L, R);
      if (L >= R) l.emplace_back(K, L - R);
      else r.emplace_back(N - K, R - L);
    }
    res += solve(N, move(l)) + solve(N, move(r));
    cout << res << endl;
  }
}
      


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    set<string> s;
    for(int i=0;i<n;i++)
    {
        string ss;
        cin >> ss;
        s.insert(ss);
    }
    db(s.size())

    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


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

    for(int i = 1; i <= n; i++){
        int cnt = 0;
        for(int x = 1; x <= 100; x++){
            for(int y = 1; y <= 100; y++){
                for(int z = 1; z <= 100; z++){
                    int sum = x*x + y*y + z*z + x*y + y*z + z*x;
                    if(sum > i) break;
                    if(i == sum) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }


    return 0;
}


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

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        int S = 0;
        int nCpy = N;
        while(nCpy != 0)
        {
            int res;
            nCpy = Math.DivRem(nCpy, 10, out res);
            S += res;
        }

        if (N % S == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b,c;
  cin>>a>>b>>c;
  int mx = max({a,b,c});
  if(mx * 2 == a + b + c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
	int N, M, K;
	cin >> N >> M;
	int a;
	vector<vector<int>> A(N, vector<int>(M));

	for (int i = 0; i < N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> a;
			A[i][a-1] = 1;
		}
	}
	int count = 0;
	for (int i = 0; i < M; i++) {
		int t = 0;
		for (int j = 0; j < N; j++) {
			if (A[j][i] == 1) t++;
		}
		if (t == N) count++;
	}
	cout << count << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> dp(n, vector<int>(3, 0));
  
  for(int i=0; i<n; i++){
    int a, b, c;
    cin >> a >> b >> c;
    if(i==0){
      dp[i][0] = a;
      dp[i][1] = b;
      dp[i][2] = c;
      continue;
    }
    dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a);
    dp[i][1] = max(dp[i-1][0] + b, dp[i-1][2] + b);
    dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c);
  }
  
  cout << max(max(dp[n-1][0],dp[n-1][1]), dp[n-1][2]) << endl;
  return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define pb(v) push_back(v)
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using P = pair<int ,int>;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;

int value[105], weight[105];
int dp[105][10050];

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

    int n, w; cin >> n >> w;
    rep(i, n) {cin >> value[i]; cin >> weight[i];}
    memset(dp, 0, sizeof(dp));

    rep(i, n) rep(j, w+1) {
        int vv = value[i], ww = weight[i];
        if (ww<=w && j>=ww) dp[i+1][j] = max(dp[i][j-ww]+vv, dp[i][j]);
        else dp[i+1][j] = dp[i][j];
    }

    cout << dp[n][w] << endl;
}


Measured memory_bytes: 7300
n = int(input())
a = list(map(int, input().split()))
y1 = sum(a) // n
y2 = y1 + 1
y3 = y1 - 1

ans = 200 ** 2 * 100
tmp1 = 0
tmp2 = 0
tmp3 = 0
for x in a:
    tmp1 += (x - y1) ** 2
    tmp2 += (x - y2) ** 2
    tmp3 += (x - y3) ** 2
ans = min(ans, tmp1, tmp2, tmp3)

print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	int N;
	int D[1000][2] = { 0 };
	int count = 0;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> D[i][0];
		cin >> D[i][1];
	}
	for (int i = 0;i < N-2;i++) {
		if (D[i][0] == D[i][1] && D[i + 1][0] == D[i + 1][1] && D[i + 2][0] == D[i + 2][1]) {
			count = 1;
		}
	}
	if (count) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
using namespace std;
typedef long long ll;

int main(void) {
	int N, K,i=0;
	cin >> N >> K;
	int mintime = (int)1e9+5;
	int x[100000];
	REP(i, N) { 
		cin >> x[i]; 
	}
	for (i = 0; i < N - K + 1;i++) {
		int l = x[i];
		int r = x[i + K - 1];
		mintime = min(mintime,min(abs(l)+abs(r-l),abs(r)+abs(r-l)));
	}
	cout << mintime << endl;
	return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
long gcd(long long x,long long y){
    if(x < y) swap(x,y);
    if(y == 0) return x;
    else return gcd(y,x%y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<long long> t(n);
    for(int i = 0; i < n; ++i) cin >> t[i];
    long long lcm = t[0];
    for(int i = 0; i < n; ++i){
        lcm = lcm/gcd(lcm, t[i])*t[i];
    }
    cout << lcm << endl;
    return 0;
}

Measured memory_bytes: 3672