akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n,i,a[100010],b[100010],c[100010];
  cin >> n;
  n++;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  ll sum=0;
  b[n-1]=a[n-1];
  for(i=n-2;i>=0;i--){
    b[i]=a[i]+sum+b[i+1];
  }
  sum=1;
  c[0]=1;
  for(i=1;i<n;i++){
    if(c[i-1]*2-a[i-1]*2<0){
      printf("-1\n");
      return 0;
    }
    if(c[i-1]*2-a[i-1]*2>b[i]){
      c[i]=b[i];
    }
    else{
      c[i]=c[i-1]*2-a[i-1]*2;
    }
  }
  ll ans=0;
  for(i=0;i<n;i++){
    ans+=c[i];
  }
  sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
  }
  if(ans<sum){
    printf("-1\n");
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef pair<int,int>P;
typedef vector<P>VP;
typedef vector<int>V;
V town[100001],cost[100001];
int d[100001];
bool flg[100001];
int main(void){
	int n,m,s;
	int f,t,c;
	int i,j;
	
	priority_queue<P,VP,greater<P> >que;
	P pp;
	int x,y;
	int b,bc;
	
	cin>>n>>m>>s;
	for(i=0;i<m;i++){
		cin>>f>>t>>c;
		town[f].PB(t);
		cost[f].PB(c);
	}
	
	fill(d,d+n,INT_MAX);
	fill(flg,flg+n,false);
	
	
	que.push(make_pair(0,s));
	while(!que.empty()){
		pp=que.top();	que.pop();
		x=pp.F;	y=pp.S;
		if(!flg[y]){
			d[y]=x;
			flg[y]=true;
			for(i=0;i<town[y].size();i++){
				b=town[y][i];
				bc=cost[y][i];
				if(!flg[b]){
					que.push(make_pair(x+bc,b));
				}
			}
		}
	}
	for(i=0;i<n;i++){
		if(d[i]==INT_MAX)	cout<<"INF"<<endl;
		else				cout<<d[i]<<endl;
	}
	return 0;
}
	
	


Measured memory_bytes: 18264
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,n,num;
    cin >> n;
    map<int, int> mp;
    for(i=0; i<n; i++){
        cin >> num;
        mp[num]+=1;
        if(mp[num]>1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdlib>
#include <map>
using namespace std;

int manhattan(int a, int b, int c, int d) {
    return abs(a - c) + abs(b - d);
}
int main(void) {
    int N,M;cin>>N>>M;
    int a[N],b[N],c[M],d[M];
    for (int i = 0; i < N; i++) {
        cin>>a[i];cin>>b[i];
    }
    for (int i = 0; i < M; i++) {
        cin>>c[i];cin>>d[i];
    }
    for (int i = 0; i < N; i++) {
        int mi = 1e9;
        int index;
        for (int j = 0; j < M; j++) {
            int cur = manhattan(a[i], b[i], c[j], d[j]);
            if (mi > cur) {
                mi = cur;
                index = j;
            }
            
        }
        cout << index + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    a = sorted(map(int, input().split()))[::-1]
    s = a[0]
    i = 1
    c = 2
    while c < n:
        s += a[i]
        c += 1
        if c < n:
            s += a[i]
            c += 1
        i += 1
    print(s)
main()


Measured memory_bytes: 32544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String line = s.nextLine();
		String result = "";
		for(int i = 0; i < line.length(); i ++){
			if(line.charAt(i)==','){
				result += ' ';
			}else{
				result += line.charAt(i);
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 10068
#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	#define PI 				acos(-1)
	#define mp				make_pair
	#define pb				push_back
	#define all(a)			(a).begin(), (a).end()
	#define sz(a)			a.size()
	#define srt(a)			sort(all(a))
	#define mem(a, h)		memset(a, (h), sizeof(a))
	#define f 				first
	#define s 				second
	#define MOD1			998244353
	#define fore(i, b, e)	for(int i = b; i < e; i++)
	#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
	int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

	using namespace std;
	using namespace __gnu_pbds;

	typedef long long 		ll;
	typedef unsigned long long 		ull;
	typedef pair<int, int>  ii;
	typedef vector<int>     vi;
	typedef vector<ii>      vii;
	typedef vector<ll>      vll;
	typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
	const int tam = 100010;
	const int MOD = 1e9+7;
	const double EPS = 1e-9;
	int tabla[2][2040][2040];
	int n;
	void calTab()
	{
		fore(k, 0, 2)
		{
			fore(i, 1, 2 * n + 1)
			{
				fore(j, 1, 2 * n + 1)
					tabla[k][i][j] += tabla[k][i-1][j] + tabla[k][i][j-1] - tabla[k][i-1][j-1];
			}
		}
	}
	int getSum(int bx, int by, int ex, int ey, int ta)
	{
		int res =  tabla[ta][min(ex, 2 * n)][min(ey, 2 * n)] - tabla[ta][min(ex, 2 * n)][by] - tabla[ta][bx][min(ey, 2 * n)] + tabla[ta][bx][by];
		if(ey > 2 * n)
		{
			res += tabla[ta][min(ex, 2 * n)][ey - 2 * n] - tabla[ta][bx][ey - 2 * n];
		}
		if(ex > 2 * n)
		{
			res += tabla[ta][ex - 2 * n][min(ey, 2 * n)] - tabla[ta][ex - 2 * n][by];
		}
		if(ex > 2 * n && ey > 2 * n)
		{
			res += tabla[ta][ex - 2 * n][ey - 2 * n];
		}
		return res;
	}
	int main()
	{
		ios::sync_with_stdio(0); cin.tie(0);
		//freopen("qwe.txt", "r", stdin);
		//freopen("asd.txt", "w", stdout);
		int can;
		cin>>can;
		cin>>n;
		int a, b;
		char ch;
		mem(tabla, 0);
		fore(i, 0, can)
		{
			cin>>a>>b>>ch;
			tabla[ch == 'B'][a % (2 * n) + 1][b % (2 * n) + 1]++;
		}
		int res = 0;
		calTab();
		fore(i, 0, n)
		{
			fore(j, 0, n)
			{
				res = max(res, getSum(i, j, i + n, j + n, 0) 
					+ getSum(i + n, j + n, i + 2 * n, j + 2 * n, 0)
					+ getSum(i, j + n, i + n, j + 2 * n, 1)
					+ getSum(i + n, j, i + 2 * n, j + n, 1));
				res = max(res, getSum(i, j, i + n, j + n, 1) 
					+ getSum(i + n, j + n, i + 2 * n, j + 2 * n, 1)
					+ getSum(i, j + n, i + n, j + 2 * n, 0)
					+ getSum(i + n, j, i + 2 * n, j + n, 0));
			}
		}
		cout<<res<<'\n';
		/*fore(k, 0, 2)
		{
			cout<<'\n';
			fore(i, 0, 2 * n + 1)
			{
				fore(j, 0, 2 * n + 1)
					cout<<tabla[k][i][j]<<' ';
				cout<<'\n';
			}
		}*/
		return 0;
	}

	// read the question correctly (is y a vowel? what are the exact constraints?)
	// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 32896
N,W=map(int,input().split())
MV=[list(map(int, input().split())) for _ in range(N)]
dp=[0]*(W+1)

for w,v in MV:
    for tw in range(W,w-1,-1):
        dp[tw]=max(dp[tw],dp[tw-w]+v)
        #print(dp,tw)

print(max(dp))

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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  
  if (x < r || W - r < x || y < r || H - r < y) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[55][55]={0},cnt[55][55]={0};
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  cnt[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=b;j++) dp[i][j]-=1000000000000000000;
  }
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=b;j++){
      dp[i+1][j]=dp[i][j];
      cnt[i+1][j]=cnt[i][j];
    }
    ll val;
    cin>>val;
    for(int j=0;j<b;j++){
      if(dp[i+1][j+1]<dp[i][j]+val){
        dp[i+1][j+1]=dp[i][j]+val;
        cnt[i+1][j+1]=cnt[i][j];
      }
      else if(dp[i+1][j+1]==dp[i][j]+val){
        cnt[i+1][j+1]+=cnt[i][j];
      }
    }
  }
  /*for(int i=0;i<n;i++){
    for(int j=0;j<=b;j++) cout<<dp[i][j]<<" ";
    cout<<endl;
  }*/
  ll max_v=dp[n][a],max_num=cnt[n][a];
  for(ll i=a;i<=b;i++){
    bool f=true;
    for(ll j=a;j<=b;j++){
      if(i==j) continue;
      if(dp[n][i]*j<dp[n][j]*i) {
        f=false;
        break;
      }
    }
    if(f){
      max_v=dp[n][i];
      max_num=i;
    }
  }
  cout<<fixed<<setprecision(10)<<(double)max_v/max_num<<endl;
  ll ans=0;
  for(int i=a;i<=b;i++){
    if(dp[n][max_num]*i==dp[n][i]*max_num) ans+=cnt[n][i];
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll N = pow(10,18);
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	ll n;cin>>n;
	ll prod = 1;
	bool flag = true;
	ll arr[n];
	bool z = false;
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		arr[i] = a;
		if(a==0){
			z = true;
		}
	}
	if(z==true){
		prod = 0;
	}
	else{
		for(int i=0;i<n;i++){
			if(prod>N/arr[i]){
				flag = false;
			}
			else{
				if(flag==true){
					prod *= arr[i];
				}
			}
		}
	}
	if(flag==false){
		prod = -1;
	}
	cout<<prod<<endl;
}

Measured memory_bytes: 4436
#include<stdio.h>
int main() {
	int a, b, c, d,i = 0;
	while (1) {
		scanf("%d %d", &a,&b);
		if (a == 0 && b == 0)break;
		if (a > b) {
			c = a;
			a = b;
			b = c;
		}
		printf("%d %d\n", a, b);
	}

}


Measured memory_bytes: 2688
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vi time(t+1);
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        time[l]++;
        time[r]--;
    }
    int ma = time[0];
    rep(i, t) {
        time[i+1] += time[i];
        chmax(ma, time[i+1]);
    }

    cout << ma << endl;
}


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


template <int mod>
struct ModInt {
  int val;
  int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  ModInt(int v = 0) : val(trim(v % mod)) {}
  ModInt(long long v) : val(trim(v % mod)) {}
  ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  ModInt operator*(const ModInt &oth) const { return 1LL * val * oth.val % mod; }
  ModInt operator/(const ModInt &oth) const {
    function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
      if (b == 0) return trim(x);
      return modinv(b, a - a / b * b, y, x - a / b * y);
    };
    return *this * modinv(oth.val, mod, 1, 0);
  }
  bool operator==(const ModInt &oth) const { return val == oth.val; }
  ModInt operator-() const { return trim(mod - val); }
  template<typename T> ModInt pow(T pw) {
    bool sgn = false;
    if (pw < 0) pw = -pw, sgn = true;
    ModInt ans = 1;
    for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
      if (pw&1) ans = ans * cur;
    }
    return sgn ? ModInt{1} / ans : ans;
  }
};
const int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

mint dp[22][1<<21];
vector<int> SZ[22];


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  dp[0][0] = 1;
  int n; cin >> n;
  for (int S = 0; S < (1<<n); ++S) SZ[__builtin_popcount(S)].push_back(S);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int a; cin >> a;
      if (a) {
        for (auto S : SZ[i]) if ((S&(1<<j)) == 0) {
          dp[i + 1][S^(1<<j)] = dp[i + 1][S^(1<<j)] + dp[i][S];
        }
      }
    }
  }
  cout << dp[n][(1<<n) - 1].val << '\n';
}


Measured memory_bytes: 190400
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;
	static int[] par, dep, ch;

	static void solve() {
		int c=ir.next().compareTo(ir.next());
		out.println(c>0?">":c<0?"<":"=");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

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

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

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

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

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21204
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
signed main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
    vector<pii> ans;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans.pb({a[i],i});
    }
    sort(all(ans));
    for(auto it:ans)
        cout<<it.second<<" ";
}

Measured memory_bytes: 3312
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#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, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	REP(i, INF) {
		if (i % 2 == 0) {
			c -= b;
			if (c <= 0) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		if (i % 2 == 1) {
			a -= d;
			if (a <= 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
}


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

long long N, K;

int main() {
	cin >> N >> K;

	long long ret = 1, cnt = 1;
	while (true) {
		long long nex = (ret + K - 1) / K;
		if (ret + nex > N) {
			cout << cnt << endl;
			return 0;
		}
		ret += nex;
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int n;
    cin>>n;
    int b[3]={0};
    rep(i,n){
        int a;
        cin>>a;
        if(a%4==0){
            b[2]++;
        }
        else if(a%2==0){
            b[1]++;
        }
        else{
            b[0]++;
        }
    }
    if(b[1]==0){
        if(b[0]>b[2]+1){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
    else{
        if(b[0]>b[2]){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}

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

int main(){
  long n,m;
  long kekka = 1;
  cin >> n >> m;
  if(abs(n - m) >= 2){
    cout << 0 << endl;
  }
  else{
    for(long i = 1;i <= n;i++){
      kekka = (kekka*i) % 1000000007;
    }
    for(long i = 1;i <= m;i++){
      kekka = (kekka*i) % 1000000007;
    }
    if(n == m){
      cout << 2*kekka % 1000000007 << endl;
    }
    else{
      cout << kekka << endl;
    }
  }
}

Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const W = parseInt(args[0][0], 10)
	const H = parseInt(args[0][1], 10)
	const N = parseInt(args[0][2], 10)
	const t = args.slice(1, N + 1)
	const map = new Array(W)
	for (let i = 0; i < W; i++) map[i] = new Array(H).fill(false)

	for (let i = 0; i < N; i++) {
		const x = parseInt(t[i][0], 10)
		const y = parseInt(t[i][1], 10)
		const a = parseInt(t[i][2], 10)

		for (let j = 0; j < W; j++) {
			for (let k = 0; k < H; k++) {
				if (a === 1) {
					if (j < x) map[j][k] = true
				} else if (a === 2) {
					if (j >= x) map[j][k] = true
				} else if (a === 3) {
					if (k < y) map[j][k] = true
				} else {
					if (k >= y) map[j][k] = true
				}
			}
		}
	}

	let cnt = 0

	for (let i = 0; i < W; i++) {
		for (let j = 0; j < H; j++) {
			if (!map[i][j]) cnt++
		}
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 10828
#include<stdio.h>
int main(void){
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i%2==0&&j%2==0){
					printf("#");
				}else if(i%2==1&&j%2==1){
					printf("#");
				}else if(i%2==0&&j%2==1){
					printf(".");
				}else if(i%2==1&&j%2==0){
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1760
N = int(input())
D = [int(a) for a in input().split()]
X = [0] * 13

for d in D:
    X[d] += 1
if X[0] or max(X) >= 3 or X[12] >= 2:
    print(0)
else:
    ma = 0
    for i in range(1<<13):
        Y = [0]
        for j in range(13):
            if X[j] == 2:
                Y.append(j)
                Y.append(24-j)
            elif X[j] == 1:
                if i >> j & 1:
                    Y.append(j)
                else:
                    Y.append(24-j)
        Y = sorted(Y)
        M = len(Y)
        ma = max(ma, min([abs((Y[i] - Y[i-1]) % 24) for i in range(M)]))
    print(ma)


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int L, R;
    cin >> L >> R;

    if (R-L+1 >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    int ans = INT_MAX;
    for (int i=L; i<=R; ++i) {
        for (int j=i+1; j<=R; ++j) {
            ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
        }
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

int main(void){
    ll X;
    ll uresisa = 0;

    //標準入力
    cin >> X;

    do
    {
        if(X >= 500)
        {
            uresisa += 1000;
            X -= 500;
            //cout << X << endl;
            continue;
        }

        if(X >= 5)
        {
            uresisa += 5;
            X -= 5;
            continue;
        }
        
        

    } while (X > 5);
    
    cout << uresisa << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	lint N;
	cin >> N;
	int ans = 10000;
	int Z = 0;
	for (int i = 1; i <= sqrt(N); i++) {
		if (N % i == 0) {
			Z = to_string(N/i).size();
			ans = min(ans,Z);
		}
	}
	cout << ans << endl;
}




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

int main(){
  int x;
  cin >> x;
  int f=0;
  string s=to_string(x);
  for(int i=0;i<s.size();i++){
    f+=s.at(i)-48;
  }
  cout << ((x%f==0)?"Yes":"No") << endl;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

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

ll ngcd (vector<ll> a) {
    ll res = a[0];
for (int i = 1; i < a.size() && res != -1; i++) {
        res = gcd(a[i], res);
}
return res;
}

int main(){
    cin >> k;
    ll ans = 0;

    map<vector<ll>, int> mp;

    for(int i = 1; i <= k; i++){
        for(int j = 1; j<=k;j++){
            for(int l = 1; l <= k; l++){
                vector<ll> v = {i, j, l};
                // sort(all(v));
                // if (mp.find(v) == mp.end()){
                //     ll tmp = ngcd(v);
                //     mp[v] = tmp;
                //     ans += tmp;
                // } else {
                //     ans += mp[v];
                // }
                ans += ngcd(v);

            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		List<Integer> nums = new ArrayList<Integer>();
		for (int i=0; i<N; i++) {
			int c = sc.nextInt();
			nums.add(c);
		}

		Collections.sort(nums);

		int before = 0;
		int cnt = 0;

		for (int i=0; i<nums.size();i++) {
			if (nums.get(i) > before) {
				cnt +=1;
				before = nums.get(i);
			}
		}

		System.out.println(cnt);

	}

}


Measured memory_bytes: 23764
#include<stdio.h>

/*x,y?????§?°?????????\???????????\??????????????????????????????????????????????????¨???????????§??¬?´???°???????????¢??°*/
int gcd(int x, int y) {
	int temp;
	while (x) {
		if (y > x) {
			temp = x;
			x = y;
			y = temp;
		}
		else if (x >= y) {
			x = x%y;
		}
		
	}
		return y;
	
}

int main(void) {
	int x, y;
	scanf("%d %d", &x, &y);
	printf("%d\n", gcd(x,y));
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;
const int MAX_E = 45;
const int MAX_V = 10;
const int INF = INT32_MAX;
struct edge {int to, cost; };
typedef pair<int, int> P;
vector<edge> G[MAX_V];
vector<string> result;

int main() {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) break;
        int max_v = -1;
        for (int i = 0; i <= MAX_V; i++)G[i].clear();
        for (int i = 0; i < n; i++) {
            int from, to, cost;
            cin >> from >> to >> cost;
            edge e, e1;
            e.to = to;
            e.cost = cost;
            G[from].push_back(e);
            e1.to = from;
            e1.cost = cost;
            G[to].push_back(e1);
            max_v = max(max(max_v, from), to);
        }
        max_v++;

        int dps[max_v];
        for(int i = 0; i < max_v; i++) {
            int d[max_v];
            fill(d, d + max_v, INF);
            priority_queue<P, vector<P>, greater<P>> que;
            d[i] = 0;
            que.push(P(0, i));
            while(!que.empty()) {
                P p = que.top();
                que.pop();
                int v = p.second;
                if(p.first > d[v]) continue;
                for(int j = 0; j < G[v].size(); j++) {
                    edge e = G[v][j];
                    if(d[e.to] > d[v] + e.cost) {
                        d[e.to] = d[v] + e.cost;
                        que.push(P(d[e.to], e.to));
                    }
                }
            }


            int sum = 0;
            for(int j = 0; j < max_v; j++) {
                sum += d[j];
            }

            dps[i] = sum;
        }

        int min_i = 0;
        for(int i = 1; i < max_v; i++) {
            if(dps[min_i] > dps[i]) {
                min_i = i;
            }
        }

        result.push_back(to_string(min_i) + " " + to_string(dps[min_i]));
    }

    for(int i = 0; i < result.size(); i++) {
        cout << result[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3104
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, A: "List[int]"):
    highest = A[0]
    ans = 0

    if N>1:
        for i in range(1, N):
            if A[i]<highest:
                ans += highest - A[i]
            else:
                highest = A[i]

    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

void change(char &c){
    if (c=='L') c='R';
    else c='L';
}
int main() {
    READ(0);
    int n,k;cin>>n>>k;
    string s;cin>>s;
    int i=1;
    int ans=0;

    while(i<n){
        if (s[i]!=s[i-1]) {
            int j=i+1;
            while(j<n && s[j]==s[i]) ++j;
            ans += j-i;
            change(s[j-1]);
            i=j;
            if (--k==0) break;
        }else{
            ++ans;
            ++i;
        }
    }
    while(i<n){
        if (s[i]==s[i-1]) ++ans;
        ++i;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 512
def main():
    X, Y = map(int, input().split())

    ans = 0
    if 1 <= X <= 3:
        ans += 100000 * (4 - X)

    if 1 <= Y <= 3:
        ans += 100000 * (4 - Y)

    if X == 1 and Y == 1:
        ans += 400000
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9164
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

console.log(main().toString());


function main() {
    var n = +cin.shift();
    var primes = make_primes(Math.sqrt(n));
    if (n == 1) return 0;
    if (n == 2) return 1;
    let ans = 0;
    let p = 2;
    for (let k = 0; p < n; k++) {
        p = primes[k];
        //        while (primes[primes.length - 1] < n) {
        //           primes.push(next_prime(primes, n));
        //      }
        //console.log({p, primes});
        let e = 0;
        while (n % p == 0) {
            e++;
            n = n / p;
        }
        if (e == 0) continue;
        // x=9 なら 1+2+3+4以下なので、3回割れる。 < 2 **4
        // x=10なら 1+2+3+4なので、4回割れる
        let i = 1;
        let sum = 1;
        while (sum + i + 1 <= e) {
            //console.log(sum, i, e);
            sum = sum + i + 1;
            i++;
        }
        ans = ans + i;
    }
    if (n > 1) ans++;

    return ans;
}

function make_primes(max) {
    let primes = [2, 3];
    let flg;
    for (let x = 5; x <= max; x += 2) {
        flg = 0;
        for (let j = 0; primes[j] * primes[j] <= x; j++) {
            if (x % primes[j] == 0) { flg = 1; break; }
        }
        if (flg == 0) { primes.push(x); }
    }
    return primes;
}

function next_prime(primes, max) {
    let flg;
    for (let x = primes[primes.length - 1] + 2; x <= max; x += 2) {
        flg = 0;
        for (let j = 0; primes[j] * primes[j] <= x; j++) {
            if (x % primes[j] == 0) { flg = 1; break; }
        }
        if (flg == 0) { primes.push(x); return x; }
    }
    return primes;
}



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


void solve(long long N, long long K, std::vector<long long> H){
    if(K>=N){
        cout << 0<<endl;
        return;
    }
    long long ans=0;
    sort(H.rbegin(),H.rend());
    for(long long i =K;i<N;i++){
        ans += H[i];
    }
    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1792
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int64_t> A(N + 1);
  int64_t ASUM = 0;
  rep(i, N + 1) {
    cin >> A[i];
    ASUM += A[i];
  }
  if (N == 0) {
    if (A[0] == 1) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (A[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  int64_t answer = 1;
  int64_t prev = 1;
  for (int i = 1; i <= N; ++i) {
    int64_t current = min(prev * 2, ASUM);
    if (current < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    prev = current - A[i];
    ASUM -= A[i];
    answer += current;
  }
  cout << answer << endl;
  return 0;
}


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

int main(){
  int x;
  cin >> x;
  if(x>=400&&x<=599) cout << 8 << endl;
  else if(x>=600&&x<=799) cout << 7 << endl;
  else if(x>=800&&x<=999) cout << 6 << endl;
  else if(x>=1000&&x<=1199) cout << 5 << endl;
  else if(x>=1200&&x<=1399) cout << 4 << endl;
  else if(x>=1400&&x<=1599) cout << 3 << endl;
  else if(x>=1600&&x<=1799) cout << 2 << endl;
  else if(x>=1800&&x<=1999) cout << 1 << endl;
}

  

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  int ans = 0;
  for(int i=1; i<=N; ++i) {
    if(i <= 9) ++ans;
    else if(100 <= i && i <= 999) ++ans;
    else if(10000 <= i && i<= 99999) ++ans;
  }
  cout << ans << endl;
}

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

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

    long long h, w;
    cin >> h >> w;

    if(h == 1 or w == 1){
        cout << 1 << endl;
        return 0;
    }

    long long a = (w + 1) / 2;
    long long b = (h + 1) / 2;

    long long ans = a * b + ((w - a) * (h - b));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    string s;
    cin>>s;
    string fs="",ffs="";
    ll c[2]={0};
    rep(0,i,4){
        string s0=s.substr(i,1);
        if(fs==""){
            fs=s0;
            ++c[0];
        }else{
            if(ffs=="" && fs!=s0){
                ffs=s0;
                ++c[1];
            }else if(fs==s0){
                ++c[0];
            }else if(ffs==s0){
                ++c[1];
            }
        }
    }
    if(c[0]==2 && c[1]==2){
        cout<<"Yes";
        return 0;
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        BigInteger n = sc.nextBigInteger();
        BigInteger a = sc.nextBigInteger();
        BigInteger r = sc.nextBigInteger();

        BigInteger sum = a.add(r);
        BigInteger ans = n.divide(sum);
        BigInteger amari = n.remainder(sum);

        if (a.compareTo(amari)==-1) {
            System.out.println(a.multiply(ans).add(a));
        }else{
            System.out.println(a.multiply(ans).add(amari));
        }
    }
}


Measured memory_bytes: 23252
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
W = []
for _ in range(N):
  W.append(input())

res = len(W) == len(set(W)) and all(W[i][-1] ==W[i+1][0] for i in range(N-1))
print("Yes" if res else "No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;  

#define pb push_back
#define ll long long int
#define db double
#define SORTA(v) sort(v.begin(),v.end())
#define SORTD(v) sort(v.begin(),v.end(),greater<>())
#define endl '\n'
#define nod(N) floor(log10(N)) + 1
#define LB(a) lower_bound(a)
#define UB(a) upper_bound(a)
#define F first
#define S second
#define FOR(i,n) for(long long int i = 0;i<n;i++)
#define FOR1(i,n) for(long long int i=1;i<=n;i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REVERSE(s) reverse(s.begin(),s.end())
#define LBV(v,a) lower_bound(v.begin(),v.end(),a)
#define UBV(v,a) upper_bound(v.begin(),v.end(),a)
#define GCD(a,b) __gcd(a,b)
#define ITX(it,x1) for(auto it = x1.begin();it!=x1.end();it++)
#define I insert
#define VFIND(v1,val) find(v1.begin() , v1.end() , val )
#define VFILL(v1 , val)   std::fill(v1.begin(), v1.end(), val);
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define all(x) x.begin() , x.end() 

// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }
ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

const int MOD = 1e9 + 7;
long long int powxy(long long int x, long long int y) 
{
    if (y == 0) return 1;if (y%2 == 1) return (x*powxy(x, y-1))%MOD;
    long long int t = powxy(x, y/2);return (t*t)%MOD;
}
void DPM(map<ll,ll>m1)
{
    for(auto it = m1.begin();it!=m1.end();it++)
    {
        cout<<it->first<<" "<<it->second<<endl;
    }
    cout<<endl;
}
void DPV(vector<ll>v)
{
    FOR(i,v.size())cout<<v[i]<<" ";cout<<endl;
}
void DPS(set<ll>s1)
{
    for(auto it =s1.begin();it!=s1.end();it++)cout<<*it<<" ";cout<<endl;
}
void DPA(ll arr[],ll n){FOR(i,n)cout<<arr[i]<<" ";cout<<endl;}



ll dx[4] = { 0,0,1,-1 };
ll dy[4] = { 1,-1,0,0 };
string pos = "RLDU";


int main()
{
    FAST;
    ll i ,j , T = 1;
    // cin>>T;
    while(T--)
    {
        i=0;j=0;
        ll n; cin>>n;

        map<ll,ll>FACT;

        while(n % 2 == 0)
        {
            n /= 2; FACT[2]++;
        }

        for(i =3; i*i<=n ;i += 2)
        {
            while( n%i == 0)
            {
                n /= i; FACT[i]++;
            }
        }
        if( n!= 1)FACT[n]++;

        ll ans = 0 ;

        ITX(it,FACT)
        {
            ll count = 1;

            while(it->second >=count )
            {
                ans++; it->second -= count; count++;
            }
        }

        cout<<ans;

        
        
    }
}  



Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

struct M {
	int64_t l;
	int64_t r;
	int k;
};


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

	vector<M> ms(n);
	FOR_LT(i, 0, n) {
		int k, l, r; cin >> k >> l >> r;
		k--;
		ms[i] = { l, r, k };
	}

	vector<M> ls;
	vector<M> rs;
	FOR_LT(i, 0, n) {
		if (ms[i].l > ms[i].r) ls.push_back(ms[i]);
		else rs.push_back(ms[i]);
	}

	sort(ls.begin(), ls.end(), [](const auto& lhs, const auto& rhs) {
		return lhs.k > rhs.k;
	});
	sort(rs.begin(), rs.end(), [](const auto& lhs, const auto& rhs) {
		return lhs.k < rhs.k;
	});

	int ridx = n - 1;
	int lidx = 0;
	int rpos = 0;
	int lpos = 0;

	int64_t ans = 0;
	vector<int> as(n, -1);
	int cl = ls.size() - 1;
	//cout << ls.size() << " " << rs.size() << endl;
	{
		auto cmp = [](const M& lhs, const M& rhs) { return (lhs.l - lhs.r) > (rhs.l - rhs.r); };
		multiset<M, decltype(cmp)> cand(cmp);
		FOR_DW(i, cl, 0) {
			while (lpos != ls.size() && i <= ls[lpos].k) {
				cand.insert(ls[lpos]);
				lpos++;
			}

			if (!cand.empty()) {
				auto it = cand.begin();
				//cout << "l" << it->l << endl;
				ans += it->l;
				cand.erase(it);
			}
		}
		while (!cand.empty()) {
			auto it = cand.begin();
			//cout << "r2" << it->r << endl;
			ans += it->r;
			cand.erase(it);
		}
	}
	int cr = rs.size() - 1;
	{
		auto cmp = [](const M& lhs, const M& rhs) { return (lhs.r - lhs.l) > (rhs.r - rhs.l); };
		multiset<M, decltype(cmp)> cand(cmp);
		FOR_LE(i, 0, cr) {
			//cout << i << " " << rs[rpos].k << endl;
			while (rpos != rs.size() && cl + 1 + i > rs[rpos].k) {
				cand.insert(rs[rpos]);
				rpos++;
			}

			if (!cand.empty()) {
				auto it = cand.begin();
				//cout << "r" << it->r << endl;
				ans += it->r;
				cand.erase(it);
			}
		}
		while (rpos != rs.size()) {
			cand.insert(rs[rpos]);
			rpos++;
		}
		while (!cand.empty()) {
			auto it = cand.begin();
			//cout << "l2" << it->l << endl;
			ans += it->l;
			cand.erase(it);
		}
	}
	
	cout << ans << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int cases; cin >> cases;
	REP(cases) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 19328
N, K, Q = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(Q)]
s = [K - Q] * (N + 1)
for a in A:
    s[a] += 1
for i in range(1, N + 1):
    if s[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 10472
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<fstream>
#include<map>
#include<queue>
#include<stack>
using namespace std;
long long a,b,c;
int main(){
	cin>>a>>b>>c;
	if(a+b>=c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

min_W = 10000
for i in range(1,N):
  S1 = sum(W_list[:i])
  S2 = sum(W_list) - S1
  min_W = min(min_W, abs(S1 - S2))
  
print(min_W)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
	char a[26],l,i,b,j;
	scanf("%s",a);
	l=strlen(a);
	for(i=0;i<l;i++)
	{
		b=0;
		for(j=0;j<i;j++)
			if(a[j]==a[i])
			{
				b=1;
				break;
			}
			if(b==1)
				break;
	}
	if(b==1)
		printf("no\n");
	else 
		printf("yes\n");
	return 0;
}
			

Measured memory_bytes: 128
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
d = dict(sorted(c.items(), key=lambda x:x[0], reverse=True))

x = 0
y = 0
for k, v in d.items():
   if v >= 4:
      if x == 0:
         x = k
         y = k
         break
      elif y == 0:
         y = k
         break
   if v >= 2:
      if x == 0:
         x = k
      elif y == 0:
         y = k
         break

ans = x * y
print(ans)


Measured memory_bytes: 35488
base_row, base_cul = (int(i) for i in input().split())
row, cul = (int(i) for i in input().split())

all = base_row * base_cul

# print(all)

row_deli = row * base_cul

# print(row_deli)

col_deli = cul * base_row

# print(col_deli)

jufuku = row * cul

# print(jufuku)

# print(row_deli + col_deli - jufuku)

print(all - (row_deli + col_deli - jufuku))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <tuple>

class union_find {
  mutable std::vector<intmax_t> c;

public:
  union_find(size_t n): c(n, -1) {}

  size_t find(size_t v) const {
    if (c[v] < 0) return v;
    return (c[v] = find(c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (-c[u] > -c[v]) std::swap(u, v);
    c[v] += c[u];
    c[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) const { return find(u) == find(v); }

  size_t size() const { return c.size(); }
  size_t size(size_t v) const { return -c[find(v)]; }
};

template <typename T>
struct Edge {
  int to; T cap, cost; int rev;
  Edge(int t, T c, int r): to(t), cap(c), rev(r) {}
  Edge(int t, T ca, T co, int r): to(t), cap(ca), cost(co), rev(r) {}
};

template <typename T>
using Graph = std::vector<std::vector<Edge<T>>>;

using namespace std;

template <typename T>
struct Dinic {
  T INF = 1e9;
  int N;
  Graph<T> G;
  vector<int> level, iter;
  Dinic(int n): N(n) {
    G.resize(N);
    level.resize(N);
    iter.resize(N);
  }
  void add_edge(int from, int to, T cost) {
    G[from].push_back(Edge<T>(to, cost, G[to].size()));
    G[to].push_back(Edge<T>(from, 0, G[from].size()-1));
  }

  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> que; que.push(s);
    level[s] = 0;
    while (!que.empty()) {
      int temp = que.front(); que.pop();
      for (size_t i = 0; i < G[temp].size(); ++i) {
        Edge<T>& e = G[temp][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[temp] + 1;
          que.push(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f) {
    if (v == t) return f;
    for (int& i = iter[v]; i < (int)G[v].size(); ++i) {
      Edge<T>& e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        T d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  T max_flow(int s, int t) {
    T flow = 0, f;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      fill(iter.begin(), iter.end(), 0);
      while ((f = dfs(s, t, INF)) > 0) flow += f;
    }
  }
};

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  Dinic<int> g(n+n+2);
  int source = n + n, sink = source + 1;
  for(int i=0; i<n; i++) {
    g.add_edge(source, i, 1);
    g.add_edge(n+i, sink, 1);
  }
  
  std::vector<std::pair<size_t, size_t>> rs(m);
  for (size_t i = 0; i < m; ++i) {
    size_t x, y;
    scanf("%zu %zu", &x, &y);
    --x, --y;
    rs[i] = std::make_pair(x, y);
    g.add_edge(x, n+y, 1);
  }

  union_find uf(m);
  size_t min = m - g.max_flow(source, sink);
  size_t max = 0;

  for (size_t i = 0; i < m; ++i) {
    for (size_t j = 0; j < i; ++j) {
      if (rs[i].first == rs[j].first || rs[i].second == rs[j].second) {
        if (uf.unite(i, j)) ++max;
      }
    }
  }

  printf("%zu %zu\n", min, max);
}



Measured memory_bytes: 3024