akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define N 500000
#define INFTY 2000000000

int cnt;
int n;

void merge(int*, int, int, int);
void merge_sort(int*, int, int);

int main(){

  int i, a[N];

  cnt = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&a[i]);
  
  merge_sort(a, 0, i);

  printf("%d",a[0]);

  for(i=1;i<n;i++)printf(" %d",a[i]);

  printf("\n%d\n",cnt);

  return 0;
}
void merge(int *a, int left, int mid, int  right){
  int n1, n2, i, k, j;
  int L[n], R[n];

  n1 = mid - left;
  n2 = right - mid;

  for(i=0;i<n1;i++)L[i] = a[left + i];
  
  for(i=0;i<n2;i++)R[i] = a[mid + i];

  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      a[k] = L[i];
      i = i+1;
      cnt++;
    }
    else{
      a[k] = R[j];
      j = j+1;
      cnt++;
    }
  }
}
void merge_sort(int *a, int left, int right){
  int mid;

  if(left+1<right){
    mid = (left + right)/2;
    merge_sort(a, left, mid);
    merge_sort(a, mid, right);
    merge(a, left, mid, right);
  }
}

Measured memory_bytes: 4516
package main

import (
        "fmt"
        "sort"
)

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        a := make([]int, m)
        b := make([]int, m)
        for i := 0; i < m; i++ {
                fmt.Scan(&a[i], &b[i])
        }
        sort.Sort(Sort{a, b})

        c := make([]bool, n+1)
        cnt := 0
loop:
        for i := 0; i < m; i++ {
                for j := b[i]; j > a[i]; j-- {
                        if c[j] {
                                continue loop
                        }
                }
                c[b[i]] = true
                cnt++
        }
        fmt.Println(cnt)
}

type Sort struct {
        a []int
        b []int
}

func (s Sort) Len() int           { return len(s.b) }
func (s Sort) Less(i, j int) bool { return s.b[i] < s.b[j] }
func (s Sort) Swap(i, j int)      { s.a[i], s.a[j], s.b[i], s.b[j] = s.a[j], s.a[i], s.b[j], s.b[i] }

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long D, long long X, std::vector<long long> A){
    LL ans = X;
    REP(i, N) ans += 1 + (D-1) / A[i];
    cout << ans << endl;
}

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


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

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

  ll X, Y, Z; cin >> X >> Y >> Z;
  cout << Z << ' ' << X << ' ' << Y << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string day[7] = {"SAT","FRI","THU","WED","TUE","MON","SUN"};
  string s;
  cin >> s;
  for(int i = 0; i < 7; i++){
    if(day[i] == s){
      cout << (i + 1) << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxN 1000001
#define mod 1000000007
#define maxLL 1000000000000000000
#define PI 3.14159265358979323846264338327950L
typedef long long ll;

bool compared(int a,int b){
	return a < b;
}

int cmp(const void *a,const void *b){
	return(*(int*)b - *(int*)a);
}

int GCD(int a,int b){
	return b?GCD(b,a%b):a;
}

int LCM(int a,int b){
	return a/__gcd(a,b)*b;
}

int main(){
	char a;
	cin>>a;
	if(a>='A' && a<= 'Z'){
		puts("A");
	}
	else{
		puts("a");\
	}
	return 0;
}

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

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
#define int ll


signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int x , k , d;
    cin >> x >> k >> d;
    x = abs(x); 
    int t = min(x / d, k);
    k -= t;
    x = x - t * d;

    if(k & 1)
        x = abs(x - d);
    cout << x << '\n';
    

    return 0;

}



Measured memory_bytes: 3624
#include <stdio.h>
#define max 101
#define INF 2147483647 /* INF は無限大を表す。*/
void matrixChainOrder(int *);/* 行列積の最適解を求める。*/
int minimum(int, int);
int n, data[max], m[max][max];
int main()
{
  int i;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) scanf("%d%d",&data[i-1],&data[i]);

  matrixChainOrder(data);

  printf("%d\n",m[1][n]);

  return 0;
}

void matrixChainOrder(int *p)
{
  int i, l, j, k, q;

  for(i = 1 ; i <= n ; i++) m[i][i] = 0;

  for(l = 2 ; l <= n ; l++){
    for(i = 1 ; i <= n - l + 1 ; i++){
      j = i + l - 1;
      m[i][j] = INF;
      for(k = i ; k <= j - 1 ; k++){
	q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]; 
	m[i][j] = minimum(m[i][j],q); 
      }
    }
  }

}

int minimum(int x, int y)
{
  if(x <= y) return x;
  if(y < x) return y;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long P = sc.nextLong();
		if (N==1) {
			System.out.println(P);
			return ;
		}
		if (N>60) {
			System.out.println(1);
			return ;
		}
		long result =1;
		long now =2;
		long all=1;
		for (int i=0;i<N;i++) {
			all=all*now;
		}
		while (all<=P) {
			while (P%all==0) {
				result *=now;
				P/=all;
			}
			now++;
			all=1;
			for (int i=0;i<N;i++) {
				all=all*now;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 35488
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define lmt 600001
int _I(){int x; scanf("%d",&x); return x;}
bool prime[lmt+5];
vector< long > pp;
void seive(){
    //int i,j;
    pp.push_back(2);
    for(long i = 4; i <= lmt; i+=2) prime[ i ] = 1;
    for(long i = 3; i <= lmt; i+=2){
        if(!prime[ i ]){
            pp.push_back(i);
            for(long j = i*3; j <= lmt; j+=i<<1) prime [ j ] = 1;
        }
    }
    prime[0]=prime[1]=1;
}
long long ar[300005];
void Lipu_mira()
{
    int n = _I();
    ar[300001];
    for( int i = 0; i < 3*n ; i++) scanf("%lld", &ar[ i ]);
    sort(ar,ar+(3*n),greater< long long>());
    long long sum = 0;
    for(int i = 1,j=0; j < n; i+=2,j++){
        sum += ar[i];
    }
    cout<<sum<<"\n";
}
int main()
{
    //seive();
    //while(true)
    Lipu_mira();
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[5005][5005];

int main(int argc, char* argv[]) {
  ll n;
  cin >> n;
  string s;
  cin >> s;

  rrep(i, n, 1) rrep(j, i, 0) {
    if (i - j == 1 || i == n - 1) {
      dp[i][j] = s[i] == s[j];
      continue;
    }

    if (s[i] != s[j]) {
      dp[i][j] = 0;
      continue;
    }

    dp[i][j] = min<ll>(i - j, dp[i + 1][j + 1] + 1);
  }

  ll ans = 0;
  rep(i, 0, n) rep(j, 0, n) { chmax(ans, dp[i][j]); }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 193920
#include<iostream>
using namespace std;
int main(){
  long long int N = 0;
  long long int A = 0;
  long long int B = 0;
  int current = 0;
  int result = 10;
  int A_digit = 1;
  int B_digit = 1;
  cin >> N;
  for(long long int i=1; i*i<=N; i++){
    A = i;
    if(N % A != 0) continue;
    B=N/A;
    while(A/10!=0){
      A /= 10;
      A_digit++;
    }
    while(B/10!=0){
      B /= 10;
      B_digit++;
    }
    current = max(A_digit, B_digit);
    result = min(result, current);
    A_digit = 1;
    B_digit = 1;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 * x座標の大きい赤い点から順にy座標の小さい青い点とペアを作る
 * 赤:1000x+y, 青:x+1000yで座標を保存する
 */
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] red = new int[n];
		for (int i=0;i<n;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			red[i] = 1000*x + y;
		}
		int[] blue = new int[n];
		for (int i=0;i<n;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			blue[i] = x + 1000*y;
		}
		Arrays.sort(red);
		Arrays.sort(blue);
		
		int ans = 0;
		for (int i=n-1;i>=0;i--) {
			int rx = red[i]/1000;
			int ry = red[i]%1000;
			for (int j=0;j<n;j++) {
				int bx = blue[j]%1000;
				int by = blue[j]/1000;
				if (ry<by) {
					if (rx<bx) {
						ans++;
						blue[j] = 0;
						break;
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
/*  ex6_2
    hangan2020 */

#include <stdio.h>
#include <string.h>
//Intial string array length
#define IS 102

int main(void){
    char eng_str[IS] = {};
    int len, inbetween_no;

  	//Input character string (including new line)
    fgets(eng_str, IS, stdin);
    len = strlen(eng_str);
  
    inbetween_no = len - 3; // String length include new line at the end of string (thus -3)
    
  	//Print out in the followning order
    printf("%c%d%c\n", eng_str[0], inbetween_no, eng_str[len - 2]);

    return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int gcd(int a, int b) {
        if (a % b != 0) {
            return gcd(b, a % b);
        } else {
            return b;
        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int n = sc.nextInt();
        int x = sc.nextInt();

        System.out.println((n - 1) * (x - 1));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int N,M;
  cin >>N>>M;
  vector<pair<long long int,long long int>> mise(N);
  for(long long int i=0;i<N;i++){
    cin>>mise[i].first>>mise[i].second;
  }
  sort(mise.begin(),mise.end());
  long long int okane=0;
  long long int honsuu=0;
  for(long long int i=0;i<N;i++){
    if(honsuu+mise[i].second<=M){
       okane+=mise[i].first*mise[i].second;
      if(honsuu+mise[i].second==M){
        cout<<okane<<endl;
        return 0;
      }
    }else{
      okane+=mise[i].first*(M-honsuu);
      cout<<okane<<endl;
      return 0;
    }
    honsuu+=mise[i].second;
  }
  cout <<okane<<endl;
  return 0;
}

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

long long dp[3333][3333];

int main(){
	int N;
	cin >> N;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	
	for(int w=1;w<=N;w++){
		for(int l=0;l<=N-w;l++){
			int r=l+w-1;
			dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	}
	
	cout << dp[0][N-1] << endl;
	return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int maxn=300;
struct node{
    int x,y;
    node operator-(const node&p)const {
        return (node){x-p.x,y-p.y};
    }
    int operator*(const node&p)const {
        return x*p.y-y*p.x;
    }
}d[maxn];
int n,p[maxn];
bool check(node a,node b,node c){
    return ((b-a)*(c-a)==0);
}

int main(){
    scanf("%d",&n);
    if(n<=2) return puts("0"),0;
    
    for (int i=1; i<=n; i++)
        scanf("%d%d",&d[i].x,&d[i].y);
        
    p[0]=1;
    for (int i=1; i<=n; i++)
        p[i]=(p[i-1]*2)%mod;
    int cnt;
    long long ans=0;
    
    for (int i=1; i<n; i++)
        for (int j=i+1; j<n; j++){
            cnt=n-j;
            for (int k=j+1; k<=n; k++)
                if(check(d[i],d[j],d[k]))
                    cnt--;
            (ans+=1ll*p[n-j-cnt]*(p[cnt]-1)%mod)%=mod;
        }
    
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define mz 1000000007
#define pq priority_queue

struct Node
{
    int no;
    long long d;
    bool friend operator <(Node x1,Node x2)
    {
        return x1.d>x2.d;
    }
}temp;
struct Edge
{
    int u,v;
    long long d;
}es[2000005];
long long dp[2][100005];
long long dis[2][100005];
vector <int> vec[100005];
pq <Node> q;

void dij(int f,int s)
{
    Node now;
    temp.no=s;
    temp.d=0;
    dis[f][s]=0;
    dp[f][s]=1;
    q.push(temp);
    while(!q.empty())
    {
        now=q.top();
        q.pop();
        if(dis[f][now.no]==now.d)
        {
            for(int i=0;i<vec[now.no].size();i++)
            {
                if(es[vec[now.no][i]].d+dis[f][now.no]>dis[f][es[vec[now.no][i]].v])
                    continue;
                if(es[vec[now.no][i]].d+dis[f][now.no]<dis[f][es[vec[now.no][i]].v])
                {
                    temp.d=es[vec[now.no][i]].d+dis[f][now.no];
                    temp.no=es[vec[now.no][i]].v;
                    q.push(temp);
                    dis[f][temp.no]=temp.d;
                    dp[f][temp.no]=dp[f][now.no];
                }
                else
                {
                    dp[f][es[vec[now.no][i]].v]+=dp[f][now.no];
                    dp[f][es[vec[now.no][i]].v]%=mz;
                }
            }
        }
    }
}

int main()
{
    int n,m;
    int s,t;
    long long wtf,gg,tmd;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&s,&t);
    for(int i=1;i<=n;i++)
        dis[0][i]=dis[1][i]=200000LL*mz;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%lld",&es[i].u,&es[i].v,&es[i].d);
        es[i].d*=2;
        es[2000000-i].d=es[i].d;
        es[2000000-i].u=es[i].v;
        es[2000000-i].v=es[i].u;
        vec[es[i].u].push_back(i);
        vec[es[i].v].push_back(2000000-i);
    }
    dij(0,s);
    dij(1,t);
    gg=(dp[0][t]*(dp[0][t]-1))%mz;
    wtf=dis[0][t];
    for(int i=1;i<=n;i++)
    {
        if(dis[0][i]==wtf/2 && dis[1][i]==wtf/2)
        {
            tmd=(dp[0][i]*dp[1][i])%mz;
            gg=(gg-(tmd*(tmd-1))%mz+mz)%mz;
        }
    }
    for(int i=1;i<=m;i++)
    {
        if(dis[0][es[i].u]<wtf/2 && dis[1][es[i].v]<wtf/2 && dis[0][es[i].u]+es[i].d+dis[1][es[i].v]==wtf)
        {
            tmd=(dp[0][es[i].u]*dp[1][es[i].v])%mz;
            gg=(gg-(tmd*(tmd-1))%mz+mz)%mz;
        }
        if(dis[0][es[i].v]<wtf/2 && dis[1][es[i].u]<wtf/2 && dis[0][es[i].v]+es[i].d+dis[1][es[i].u]==wtf)
        {
            tmd=(dp[0][es[i].v]*dp[1][es[i].u])%mz;
            gg=(gg-(tmd*(tmd-1))%mz+mz)%mz;
        }
    }
    printf("%lld\n",gg);
	return 0;
}


Measured memory_bytes: 20468
#include<cmath>
#include<iostream>
using namespace std;
int n,m,a,maxx=0;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a;
		maxx=max(maxx,a);
	}
	if(maxx<=(n+1)/2)
	{
		cout<<0<<endl;
		return 0;
	}
	cout<<maxx*2-n-1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Vector2d> p = new ArrayList<>();
		for (int i=0; i<n; i++) {
			double x = sc.nextDouble();
			double y = sc.nextDouble();
			p.add(new Vector2d(x, y));
		}
		sc.close();
		System.out.println(solve(p));
	}

	static class Vector2d {
		Vector2d(Double x, Double y){
			this.x = x;
			this.y = y;
		}
		Double x;
		Double y;
		public String toString() {
			return String.format("%1$.10f %2$.10f", x, y);
		}
	}

	public static Vector2d sub(Vector2d v1, Vector2d v2){
		return new Vector2d(v2.x - v1.x, v2.y - v1.y);
	}

	public static int solve(List<Vector2d> p) {
		boolean ans = true;
		int s = p.size();
		for (int i=0; i<s; i++) {
			Vector2d a = sub(p.get(i), p.get((i+1)%s));
			Vector2d b = sub(p.get((i+1)%s), p.get((i+2)%s));
			ans = ans && ((a.x * b.y - a.y * b.x) >= 0);
		}
		return ans ? 1 : 0;
	}
}



Measured memory_bytes: 29000
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int a, b;
    char op;
    cin >> a >> op >> b;

    int ans;
    if(op == '+')
        ans = a + b;
    else
        ans = a - b;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
	ll n, m;
	cin >> n >> m;
	ll ok = 0, ng = 1000000000000ll;
	while(abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;
		if(n < mid) {
			;
		}
		ll tm = m - 2 * mid;
		if(n + tm / 2 >= mid){
			;
		}
		if(n + tm / 2 > mid){
			;
		}
		if(tm < 0){
			ng = mid;
		}else if(n + tm / 2 >= mid){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define mem(f, x) memset(f, x, sizeof(f))
#define INF 0x3f3f3f3f
using namespace std;
const int M = 13;
const int N = 13;
const int MAXN = 1e5+50;
ll m, n, x;
ll mp[N][N];
ll c[MAXN];
ll sum[N];
ll ans;

void DFS( int cur, ll tmp ){
    bool flag = 0;
    for( int i = 1; i <= m; i++ ){
        if( sum[i] > 0 ){
            flag = 1;
            break;
        }
    }
    if( !flag ){
        ans = min( ans, tmp );
        return;
    }
    for( int i = cur+1; i <= n; i++ ){
        for( int j = 1; j <= m; j++ )
            sum[j] -= mp[i][j];
        DFS( i, tmp+c[i] );
        for( int j = 1; j <= m; j++ )
            sum[j] += mp[i][j];
    }
}

int main( ){
    while( scanf( "%lld %lld %lld", &n, &m, &x ) != EOF ){
        for( int i = 1; i <= m; i++ )
            sum[i] = x;
        ans = INF;
        for( int i = 1; i <= n; i++ ){
            scanf( "%lld", c+i );
            for( int j = 1; j <= m; j++ )
                scanf( "%lld", *(mp+i)+j );
        }
        DFS( 0, 0 );
        if( ans == INF )
            printf( "-1\n" );
        else
            printf( "%lld\n", ans );
    }
    return 0;
}


Measured memory_bytes: 3820
#include <stdio.h>
int main(){
int h,w;
while(1){
scanf("%d",&h);scanf("%d",&w);
if(h==0&&w==0)break;

for(int i=1;i<=h;i++)
{

for(int k=1;k<=w;k++)
{
if(i==1)printf("#");
else if(i<h){
if(k==1)printf("#");
else if(k<w)printf(".");
else if(k==w)printf("#");
}
else if(i==h)printf("#");

}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
using System;
using System.Collections.Generic;
class Program
{
    //static int[] dp;
    //static decimal[,,] dp;
    //static decimal N;
    static void Main(string[] args)
    {
        // 入力
        //int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
        string S = Console.ReadLine();

        bool humiyasui = true;
        for (int i = 0; i < S.Length; i++)
        {
            if (i % 2 == 0 && S[i] == 'L')
            {
                humiyasui = false;
            }

            if (i % 2 == 1 && S[i] == 'R')
            {
                humiyasui = false;
            }
        }

        if (humiyasui)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }


}


Measured memory_bytes: 13140
from math import sqrt
n, d = map(int, input().split())
if d > 1:
  XX = [list(map(int, input().split())) for _ in range(n)]
else:
  XX = [[int(input())] for _ in range(n)]

print(
  sum(
    sqrt(sum((XX[i][k] - XX[j][k]) ** 2 for k in range(d))).is_integer()
	for i in range(n)
	for j in range(i + 1, n)
  )
)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            /*var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            Console.WriteLine("{0} {1}",a*b,(a+b)*2);
            Console.ReadLine();*/
            var a = int.Parse(Console.ReadLine());
            var b = a / 60;
            var c = b / 60;
            Console.WriteLine("{0}:{1}:{2}", c, b % 60, a % 60);


            

            
        }
    }
}

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
  vector<vector<int>> A(N, vector<int>(N - 1));
  rep(i, N) {
    rep(j, N - 1) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }

  int ans = 0;
  int finished = 0;
  vector<int> iter(N);
  queue<int> pq;
  rep(i, N) {
    pq.push(i);
  }

  while (finished < N) {
    ans++;
    vector<bool> play_on_the_day(N, false);
    bool ok = false;
    queue<int> nq;

    while (!pq.empty()) {
      int a = pq.front();
      pq.pop();
      if (iter[a] >= N - 1)
        continue;
      int b = A[a][iter[a]];
      if (iter[b] >= N - 1)
        continue;
      int c = A[b][iter[b]];

      if (a == c && !play_on_the_day[a] && !play_on_the_day[b]) {
        ok = true;
        nq.push(a);
        nq.push(b);
        play_on_the_day[a] = true;
        play_on_the_day[b] = true;
        iter[a]++;
        iter[b]++;
        if (iter[a] == N - 1)
          finished++;
        if (iter[b] == N - 1)
          finished++;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }

    pq = nq;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
// Problem : D - Handstand 2
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

vi digits(int x){
    vi ret;
    while(x){
        ret.pb(x%10);
        x /= 10;
    }
    reverse(all(ret));
    return ret;
}

void solve(){
    int n;
    cin>>n;
    vector<vi> cnt(10,vi(10));
    for(int i=1;i<=n;i++){
        vi v = digits(i);
        cnt[*v.begin()][*v.rbegin()]++;
    }
    int ans = 0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++) ans += cnt[i][j]*cnt[j][i];
    }
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  string S;cin >> S;
  bool ans = false;
  if(S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ans = true;
  if(S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ans = true;
  if(S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) ans = true;
  
  if(ans) puts("Yes");
  else puts("No");

	return 0;
}



Measured memory_bytes: 3628
//ProblemA

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

constexpr ll INF = (ll)(1e18);

//ProblemA
void Solve() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	if (abs(a - b) > INF) {
		cout << "Unfair" << endl;
	}
	else {
		cout << (k % 2 == 0 ? a - b : b - a) << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
vector<int> v(3);
for(int i=0;i<3;i++)cin>>v[i];
sort(v.begin(),v.end());
if(v[1]*2==v[0]+v[2])cout<<"YES";
else cout<<"NO";

}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,A[200000],B[200000]={0},ans=0;
  
    cin>>n;
  
    rep(i,n)
      cin>>A[i],B[A[i]]=i+1;
  
    set<ll> C;
  
    C.insert(0),C.insert(n+1);
  
    rep(i,n) ans+=(i+1)*(B[i+1]-(*--C.lower_bound(B[i+1])))*(*C.upper_bound(B[i+1])-B[i+1]),C.insert(B[i+1]);
    cout<<ans;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  string S;

  cin >> S;

  int ans = 0;
  for (int i=0; i*2<S.size(); i++) {
    ans += S[i] != S[S.size()-1-i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import math
def main():
    num       = [int(input()) for _ in range(5)]
    rand_up   = [math.ceil(i / 10) * 10 for i in num]
    diff      = [rand_up[i] - num[i] for i in range(5)]
    max_index = diff.index(max(diff))
    print(sum([num[i] if i == max_index else rand_up[i] for i in range(5)]))

main()

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
k  = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
    k+=1
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
s = sum(l)
print(s  if t == 1 or k%2==0 else s - 2*min(l))

Measured memory_bytes: 70160
def main():
    s = input()
    q = int(input())
    reverse = 0
    head = ""
    tail = ""
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            reverse = not(reverse)
        else:
            if (reverse^int(query[1]))&1:
                head += query[2]
            else:
                tail += query[2]
    s = head[::-1] + s + tail
    if reverse&1:
        print(s[::-1])
    else:
        print(s)
if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

fn solve() {
	let k = read!(usize);
	let v = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
	println!("{}", v[k-1]);
}


fn run() {
    solve();
}


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

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

const int MAXN=105,MAXW=101010;
ll N,W,pw[MAXN],pv[MAXN],dp[MAXW];

int main(){
//#ifdef Javier
//    freopen(".in", "r", stdin);
//#endif // Javier

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin>>N>>W;
    for(int i=1;i<=N;i++)
    {
        cin>>pw[i]>>pv[i];
    }

    for(int i=1;i<=N;i++)
    {
        for(int j=W;j>=pw[i];j--)
        {
            dp[j]=max(dp[j],dp[j-pw[i]]+pv[i]);
        }
    }

    cout<<dp[W];

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	string res(s.length(), 'x');
	cout << res << '\n';
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), a.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int N, M, s, c, cnt, num;
    cnt = num = 0;
    int check[3][10];
    m0(check);

    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> s >> c;
        if(N > 1 && s == 1 && c == 0) {
            cout << "-1" << endl;
            exit(0);
        } else {
            if(s == 1) {
                check[0][c] = 1;
            } else if(s == 2) {
                check[1][c] = 1;
            } else {
                check[2][c] = 1;
            }
        }
    }

    for(int i = 0; i < N; i++) {
        cnt = 0;
        for(int j = 0; j <= 9; j++) {
            if(cnt > 1) {
                cout << "-1" << endl;
                exit(0);
            } else if(check[i][j] == 1) {
                cnt++;
                num += j * pow(10, N - i - 1);
            }
        }
    }

    if(N == 3 && num < 100) {
        num += 100;
    } else if(N == 2 && num < 10) {
        num += 10;
    }

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int v[101],w[101];
int dp[100005];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,W;
    cin >> n >> W;
    rep(i,n)cin >> v[i] >> w[i];
    rep(i,100005){
        rep(j,n){
            if(i>=w[j])chmax(dp[i],dp[i-w[j]]+v[j]);
        }
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(void){
   int W, H, x, y, r;
   cin>>W>>H>>x>>y>>r;
   if(x-r<0||x+r>W||y-r<0||y+r>H) cout << "No";
   else cout << "Yes";
   cout<<endl;
   
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;


int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, 0, n) {
		int num;
		cin >> num;
		mp[num] = i+1;
	}
	for(auto i:mp) {
		cout << i.second << " ";
	}
	return 0;
}

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

int main() {
	int N;
	int d[110];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}

	int num[110] = { 0 };
	for (int i = 0; i < N; i++) {
		num[d[i]]++;
	}

	int ans = 0;
	for (int i = 1; i <= 100; i++) {
		if (num[i] > 0) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int T;
    cin >> T;
    auto comp = [](P a, P b) {
        return a.second < b.second;
    };
    rep(ti, T) {
        ll n;
        cin >> n;
        vector<P> l;
        vector<P> r;
        ll sum = 0;
        rep(i, n) {
            ll K, L, R;
            cin >> K >> L >> R;
            K--;
            if (L>=R) {
                sum += R;
                l.emplace_back(K, L-R);
            }
            else {
                sum += L;
                r.emplace_back(K, R-L);
            }
        }
        priority_queue<P, vector<P>, decltype(comp)> q1{comp};
        priority_queue<P, vector<P>, decltype(comp)> q2{comp};
        sort(whole(l));
        sort(whole(r));
        reverse(whole(l));
        int sl = l.size();
        int sr = r.size();
        int il = sl - 1;
        int ir = sl;
        int index = 0;
        ll ans = 0;
        rrep(i, il+1) {
            while (index<sl && l[index].first>=i) {
                q1.push(l[index]);
                index++;
            }
            if (!q1.empty()) {
                P now = q1.top();
                q1.pop();
                ans += now.second;
            }
        }
        index = 0;
        for (ll i=ir; i<n; i++) {
            while (index<sr && r[index].first<i) {
                q2.push(r[index]);
                index++;
            }
            if (!q2.empty()) {
                P now = q2.top();
                q2.pop();
                ans += now.second;
            }
        }
        
        
        
        
        ans += sum;
        //debug(sum);
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 9860
A=input()
B=input()
AA=A.split()
K=int(AA[0])
N=int(AA[1])
d=(B.split())
dis=[]
for i in range(N-1):
    dis.append(int(d[i+1])-int(d[i]))

dis.append(int(d[0])+(K-int(d[N-1])))

print(K-max(dis))

Measured memory_bytes: 21060
import sys
input = sys.stdin.readline
N=int(input())
S=input().strip()
"""dp=[[0]*(N+1) for _ in range(N+1)]
for i in range(N-1,-1,-1):
    for j in range(N-1,i,-1):
        if S[i]==S[j]:
            dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)
#print(dp)
ans=0
for i in range(N):
    for j in range(N):
        ans=max(ans,min(dp[i][j],j-i))
print(ans)
"""

def Z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0#最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        #i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

ans=0
for i in range(N):
    LCP=Z_algo(S[i:])
    #print(LCP)
    for j , l in enumerate(LCP):
        tmp=min(l,j)
        ans=max(ans,tmp)
print(ans)


Measured memory_bytes: 52588
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(row, col,  filler = 0) {
    return Array(row)
        .fill(filler)
        .map(() => Array(col).fill(filler));
}
// ---------------------------------------



function main() {
    let [n, w] = getArray(readline());
    const arr = [];
    const dp = create2DArray(n+1, w+1, 0)

    let c = n;


    while(c--) {
        arr.push(getArray(readline()));
    }

    function solve(n1, w1) {
        //console.log(n1, w1);
        if (n1 < 0 || w1 <= 0) {
            return 0;
        }
        if (dp[n1][w1]) {
            return dp[n1][w1];
        }
        if (w1 >= arr[n1][0]) {
            dp[n1][w1] = Math.max(arr[n1][1] + solve(n1 - 1, w1 - arr[n1][0]), solve(n1 - 1, w1));
        } else {
            dp[n1][w1] = solve(n1 - 1, w1);
        }
        return dp[n1][w1];
    }

    console.log(solve(n-1, w));
}

Measured memory_bytes: 211036
N, Y = map(int, input().split())
max_10000 = Y // 10000
max_5000 = (Y % 10000) // 5000
max_1000 = (Y % 5000) // 1000
mininum = max_1000 + max_5000 + max_10000
maximum = Y // 1000
n_10000 = -1
n_5000 = -1
n_1000 = -1
if (mininum) <= N and (maximum) >= N:
    diff = maximum - N
    for i in range(diff // 9, -1, -1):
        if (diff - i*9)%4 == 0:
            n_10000 = i
            n_5000 = (diff - i*9)//4
            n_1000 = N - n_10000 - n_5000
            break
print(n_10000, n_5000, n_1000)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

// ll stoll(string const& s){
//     ll res = 0;
//     rep(i,s.size()){
//         res*=10;
//         res+=s[i]-'0';
//     }
//     return res;
// }

ll input(){
    string s; cin>>s;
    size_t p=0;
    int sign = s[0]=='-' ? -1 : 1;
    if(sign==-1) s.erase(s.begin());
    while(p<s.size() && s[p]!='.') p++;
    while(s.size()-p < 6) s += '0';
    s.erase(s.begin()+p);
    dump(s);
    return sign*stoll(s);
}

int main(){
    int n; cin>>n;
    rep(_,n){
        ll x[2][2], y[2][2];
        rep(i,2){
            rep(j,2){
                x[i][j] = input();
                y[i][j] = input();
            }
        }
        ll dx1=x[0][0]-x[0][1], dy1=y[0][0]-y[0][1];
        ll dx2=x[1][0]-x[1][1], dy2=y[1][0]-y[1][1];
        dump(dx1,dx2,dy1,dy2);
        puts(dx1*dy2==dx2*dy1 ? "YES" : "NO");
    }
}

Measured memory_bytes: 1200
#include <stdio.h>
int main()
{
    int m,a,b;
    scanf("%d %d %d",&m,&a,&b);
    if(b-a-m>0)printf("%d\n",b-a-m);
    else {if(a-b-m>0)printf("%d\n",a-b-m);
    else printf("0\n");}
    return 0;
}

Measured memory_bytes: 128
A, B, C, D = list(map(int, input().split()))
# A, B, C, D = list(map(int, "46 4 40 5".split()))

while True :

    # Takahashi's trun
    C -= B
    if C <= 0 :
        print("Yes")
        break

    # Aoki's trun
    A -= D
    if A <= 0 :
        print("No")
        break

Measured memory_bytes: 9192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int c0[10], c1[10];

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    rep(i,9) scanf("%d", c0+i);
    rep(i,9) scanf("%d", c1+i);

    const unsigned all = 362880;
    unsigned wins = 0;
    // prev 固定
    sort(c1, c1 + 9);
    do {
      unsigned pt = 0;
      rep(i,9) if (c0[i] > c1[i]) pt += c0[i] + c1[i];
      if (pt > 85) ++wins;
    } while (next_permutation(c1, c1 + 9));
    double prob = (double)wins / all;
    printf("%.5f %.5f\n", prob, 1 - prob);
  }
  return 0;
}

Measured memory_bytes: 1236
n, t, a, *h = map(int, open(0).read().split())
ans = 0
diff_a = float('inf')
for i in range(n):
    if diff_a > abs(a - (t - h[i] * 0.006)):
        ans = i+1
        diff_a = abs(a - (t - h[i] * 0.006))
print(ans)

Measured memory_bytes: 3060