akhauriyash/Code-Regression huggingface dataset:
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  let [mh,mw]=tnn(2),map=new Array(mh),save=new Array(mh)
  let start=[-1]
  let dh=[0,0,-1,1]
  let dw=[1,-1,0,0]
  for(let i=0;i<mh;i++){
    map[i]=ts().split('')
    save[i]=new Array(mw)
    save[i].fill(-1)
    // 開始位置探す
    if(start[0]==-1){
      for(let j=0;j<mw;j++){
        if(map[i][j]=='.'){
          start=[i,j]
          break
        }
      }
    }
  }
  // 縦,横,カウンタ
  let maxnum=0
  for(let j=0;j<mh;j++){
    for(let k=0;k<mw;k++){
      if(map[j][k]=='#')continue
      let stack=[[j,k,1]]
      save[j][k]=0
      while(stack.length>0){
        let [h,w,c]=stack.shift()
        if(save[h][w]>maxnum){
          maxnum=save[h][w]
        }
        for(let i=0;i<4;i++){
          if(h+dh[i]<0 || h+dh[i]>=mh || w+dw[i]<0 || w+dw[i]>=mw || map[h+dh[i]][w+dw[i]]=='#')continue
          if(save[h+dh[i]][w+dw[i]]==-1){
            stack.push([h+dh[i], w+dw[i], c+1])
            save[h+dh[i]][w+dw[i]]=c
          }
        }
      }
      for(let i=0;i<mh;i++){
        save[i].fill(-1)
      }
    }
  }
  to(maxnum)
}
main()


Measured memory_bytes: 10416
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)


int main(void){
  int a, b;
  scanf("%d %d", &a ,&b);
  if(b % a == 0){
    printf("%d", a + b);
  }else{
    printf("%d", b - a);
  }
}


Measured memory_bytes: 256
s = list(input())
n = int(input())

flag = 0
s1 = []
s2 = s
for i in range(n):
    Q = input()
    if Q[0] == "2":
        if Q[2] == "1":
            if flag == 1:
                s2.append(Q[4])
            else:
                s1.append(Q[4])
        else:
            if flag == 0:
                s2.append(Q[4])
            else:
                s1.append(Q[4])
    else:
        flag ^= 1
s2 = s1[::-1] + s2
print("".join(s2) if flag == 0 else "".join(s2[::-1]))


Measured memory_bytes: 15652
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss()
    print(max(len(set(S[:n]) & set(S[n:])) for n in range(N)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (k, a, b) = readLine()!!.split(' ').map(String::toLong)
    if (k == 1L) {
        println(2)
        return
    }
    var dp0 = 1L
    var dp1 = 2L
    var dp2 = 0L
    for (i in 2..k) {
        dp2 = dp1 + 1
        if (a <= dp0) {
            dp2 = Math.max(dp2, dp0 - a + b)
        }
        dp0 = dp1
        dp1 = dp2
    }
    println(dp2)
}


Measured memory_bytes: 38080
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rnr(i, a, b) for(int i = int(a); i >= int(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int getMultCnt(int mult, ll x) {
    int ret = 0;
    while(x % mult == 0 && x != 0) {
        x /= mult;
        ++ret;
    }
    return ret;
}

int main() {
    int n; cin >> n;
    double a[n];
    ll b[n];
    Pint c[n];
    int m[70][70];
    rep(i, 70) {
        rep(j, 70) {
            m[i][j] = 0;
        }
    }
    //m[(2'bai, 5'bai)]
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        b[i] = llround(a[i] * 1e9);
        int cnt2 = getMultCnt(2, b[i]);
        int cnt5 = getMultCnt(5, b[i]);
        c[i] = mp(cnt2, cnt5);
        m[c[i].first][c[i].second]++;
    }
    ll ans = 0;
    rep(i, n) {
        m[c[i].first][c[i].second]--;
        int reqCnt2 = max(0, 18 - c[i].first);
        int reqCnt5 = max(0, 18 - c[i].second);
        rng(cnt2, reqCnt2, 60) {
            rng(cnt5, reqCnt5, 30) {
                ans += m[cnt2][cnt5];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    long n,m;
    cin >> n >> m;
    long sum = 0;
    rep(i,m){
        long a;
        cin >> a;
        sum += a;
    }
    if(sum > n) cout << -1 << endl;
    else cout << n - sum << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int total = 0;
  	if (a + b > c * 2) {
    	if (x > y) {
    		if (a > c * 2) {
    	    	total = c * x * 2;
    	  	}
    		else {
    	    	total = c * y * 2+ a * (x - y);
    	  	}
    	} else {
    		if (b > c * 2) {
    	    	total = c * y * 2;
    	  	} else {
    	    	total = c * x * 2+ b * (y - x);
    	  	}
    	}
  	} else {
   		total = a * x + b * y; 
  	}
  	cout << total;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> K >> N;
  Vec(P,lli,N,0);
  Vec(Q,lli,N,0);
  rep(i,0,N)cin >> P[i];
  rep(i,0,N)Q[i]=K-P[i];
  sum=P[N-1]-P[0];
  rep(i,1,N){
    chmin(sum,P[N-i-1]+Q[N-i]);
  }
  Out(sum);
}

Measured memory_bytes: 3456
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
const int MOD=1e9+7;

struct modint {
    int val;
    modint inv() const{
        int tmp,a=val,b=MOD,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return modint(x);
    }
public:
    modint():val(0){}
    modint(ll x){if((val=x%MOD)<0)val+=MOD;}
    modint pow(ll t){modint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    modint& operator+=(const modint& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
    modint& operator-=(const modint& x){if((val+=MOD-x.val)>=MOD)val-=MOD; return *this;}
    modint& operator*=(const modint& x){val=(ll)val*x.val%MOD; return *this;}
    modint& operator/=(const modint& x){return *this*=x.inv();}
    bool operator==(const modint& x) const{return val==x.val;}
    bool operator!=(const modint& x) const{return val!=x.val;}
    bool operator<(const modint& x) const{return val<x.val;}
    bool operator<=(const modint& x) const{return val<=x.val;}
    bool operator>(const modint& x) const{return val>x.val;}
    bool operator>=(const modint& x) const{return val>=x.val;}
    modint operator+(const modint& x) const{return modint(*this)+=x;}
    modint operator-(const modint& x) const{return modint(*this)-=x;}
    modint operator*(const modint& x) const{return modint(*this)*=x;}
    modint operator/(const modint& x) const{return modint(*this)/=x;}
};

modint dp[2001][2001];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ls(n), lt(m);
  for (int i = 0; i < n; ++i) {
    cin >> ls[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> lt[i];
  }
  for (int i = 0; i <= n; ++i) {
    dp[i][0] = 1;
  }
  for (int i = 0; i <= m; ++i) {
    dp[0][i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[i+1][j+1] = dp[i+1][j];
      dp[i+1][j+1] += dp[i][j+1];
      if (ls[i] != lt[j]) { 
        dp[i+1][j+1] -= dp[i][j];
      }
      // cout << i << " " << j << " " << dp[i+1][j+1].val << endl;
    }
  }
  cout << dp[n][m].val << endl;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  int mx = 0, ans = 0;
  for (char c : s) {
    if (c == 'R') ++mx;
    else mx = 0;
    ans = max(mx, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
package main

import (
	"bufio"
	"fmt"
	"os"
)

var writer = bufio.NewWriter(os.Stdout)

func main() {
	var n int
	fmt.Scan(&n)

	max := 0
	sum := 0
	for i := 0; i < n; i++ {
		var l int
		fmt.Scan(&l)

		if max < l {
			max = l
		}
		sum += l
	}

	var ret string
	if max < sum-max {
		ret = "Yes"
	} else {
		ret = "No"
	}
	fmt.Fprintf(writer, "%s\n", ret)
	writer.Flush()
}


Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string s_) {
    auto N = s_.chomp.to!int();
    auto A = new int[N];
    auto B = new int[N];
    auto P = new int[N];
    foreach(i;0..N) {
        auto AB = readln.split.map!(to!int)();
        A[i]=AB[0];
        B[i]=AB[1];
        P[i]=A[i]+B[i];
    }
    bool p=false;
    long s=0;
    foreach(t;zip(P,A,B).sort!((t1,t2)=>t1[0]>t2[0])) {
        if(p) s-=t[2];
        else  s+=t[1];
        p=!p;
    }
    return s;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 4220
// ARC061E.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 8e5 + 200, INF = 0x3f3f3f3f;

int n, m, dist[MAX_N], ptot;
bool vis[MAX_N];
map<pair<int, int>, int> mp;

struct edge
{
    int to, nxt, weight;
};

vector<edge> G[MAX_N];

void addpath(int src, int dst, int weight) { G[src].push_back(edge{dst, 0, weight}); }

void addtube(int src, int dst, int weight)
{
    addpath(src, dst, weight), addpath(dst, src, weight);
}

void shortest_path(int src)
{
    memset(dist, 0x3f, sizeof(dist));
    priority_queue<pair<int, int> /**/> pq;
    pq.push(make_pair(0, src)), dist[src] = 0;
    while (!pq.empty())
    {
        int u = pq.top().second;
        pq.pop();
        if (vis[u])
            continue;
        vis[u] = true;
        for (int i = 0, siz = G[u].size(); i < siz; i++)
            if (dist[G[u][i].to] > dist[u] + G[u][i].weight)
                dist[G[u][i].to] = dist[u] + G[u][i].weight, pq.push(make_pair(-dist[G[u][i].to], G[u][i].to));
    }
}

int createId(pair<int, int> pr)
{
    if (mp.count(pr) > 0)
        return mp[pr];
    return mp[pr] = ++ptot;
}

int main()
{
    scanf("%d%d", &n, &m), ptot = n;
    if (m == 0)
        puts("-1"), exit(0);
    for (int i = 1, u, v, w; i <= m; i++)
    {
        scanf("%d%d%d", &u, &v, &w);
        addtube(createId(make_pair(u, w)), createId(make_pair(v, w)), 0);
        addtube(u, createId(make_pair(u, w)), 1), addtube(createId(make_pair(v, w)), v, 1);
    }
    shortest_path(1);
    if (dist[n] == INF)
        puts("-1");
    else
        printf("%d\n", dist[n] >> 1);
    return 0;
}

Measured memory_bytes: 68988
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> dp(n + 1, 0);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        dp[a[i]] = -1;
    }
    dp[0] = 1;
    for (int i = 0; i <= n; i++)
    {
        if (dp[i] == -1)
        {
            dp[i] = 0;
            continue;
        }
        if (i >= 1)
            dp[i] += dp[i - 1] % mod;
        if (i >= 2)
            dp[i] += dp[i - 2] % mod;
    }
    cout << dp[n] % mod << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}   

signed main()
{
    showoff;
    int n,ans = 0;
    cin >> n;
    FOR(i,1,n+1){
        FOR(j,1,n+1){
            FOR(k,1,n+1)ans += __gcd(k,__gcd(i,j));
        }
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s == "BBB" || s == "AAA")
        puts("No");
    else
        puts("Yes");
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var dx = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 };
        var dy = new int[] { 1, 1, 0, -1, -1, -1, 0, 1 };
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new char[h, w];
        var map2 = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                map[i, j] = s[j];
        }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (map[i, j] == '.') getNum(map, map2, i, j, dx, dy);
        putAns(map, map2);
    }
    public static void putAns(char[,] map, int[,] map2)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
            {
                if (map[i, j] == '#' && j == w - 1) Console.WriteLine('#');
                else if (map[i, j] == '#') Console.Write('#');
                if (map[i, j] != '#' && j == w - 1) Console.WriteLine(map2[i, j]);
                else if (map[i, j] != '#') Console.Write(map2[i, j]);
            }
    }
    public static void getNum(char[,] map, int[,] map2, int x, int y, int[] dx, int[] dy)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var count = 0;
        for (int i = 0; i < 8; i++)
        {
            var nx = x + dx[i];
            var ny = y + dy[i];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny] == '#') count++;
        }
        map2[x, y] = count;
    }
}



Measured memory_bytes: 13140
n,k = map(int,input().split())

li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append((a,b))


li.sort()
for i in range(n):
    a,b = li[i]
    
    if k > b:
        k -= b
    else:
        print(a)
        exit()


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

long long L[ 90 ];

int main()
{
int i;
int N;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;

	L[ 0 ] = 2;
	L[ 1 ] = 1;
	for( i = 2; i <= N; i++ )
		L[ i ] = L[ i - 1 ] + L[ i - 2 ];

	cout << L[ N ] << endl;

	return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int main(){
  int n;
  while(scanf("%d",&n) && n){
    int s[1000]={},sum=0;
    for(int i=0;i<n;i++){
      scanf("%d",&s[i]);
      sum += s[i];
    }
    double m = (double)sum / (double)n,ssum=0;
    for(int i=0;i<n;i++) ssum += pow((s[i]-m),2);
    printf("%.7f\n",sqrt(ssum/(double)n));
  }
}

Measured memory_bytes: 1072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}

int main() {
	int a, b, c; cin >> a >> b >> c;
	int x = a - b;
	cout << max(0, c - x) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 200000;
ll N, K;
ll a[MAX_N+1];
ll f[MAX_N+1];
ll c[MAX_N+10];

ll BIT[MAX_N+10], n;

ll sum(int i) {
  ll res = 0;
  while (i > 0) {
    res += BIT[i];
    i -= i & (-i);
  }
  return res;
}


void add(ll i, ll x) {
  while (i <= n) {
    BIT[i] += x;
    i += i & (-i);
  }
}

int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> a[i];
  n = N+1;

  vector<ll> v;
  v.push_back(0);
  for (int i = 1; i <= N; ++i) {
    f[i] = f[i-1] + a[i] - K;
    v.push_back(f[i]);
  }

  sort(all(v));

  for (int i = 0; i <= N; ++i) {
    ll t = lower_bound(all(v), f[i]) - v.begin();
    c[i] = t+1;
  }

  ll ans = 0;
  add(c[0], 1);
  for (int i = 1; i <= N; ++i) {
    ans += sum(c[i]);
    add(c[i], 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8176
#include<bits/stdc++.h>
#define N 1005
#define K 55
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;

signed main() {
    ios::sync_with_stdio(0); 
    cin.tie(NULL); cout.tie(NULL);
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int ans = (h2*60) + m2 - ((h1*60)+m1);
    ans -= k;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
/*
Atcoder AGC020C
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n,a[2005],s=0;;
bitset<4000005> f[2];

signed main()
{
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	for(int i=1;i<=n;i++)
		s += a[i];
	int o=0;
	f[o][0] = f[o][a[1]] = 1;
	for(int i=2;i<=n;i++)
	{
		o ^= 1;
		f[o] = f[o^1];
		f[o] |= f[o^1]<<a[i];
//		for(int j=0;j<=s;j++)cout<<f[o][j]<<' ';cout<<endl;
	}
	for(int j=(s+1)/2;j<=s;j++)
		if(f[o][j])
		{
			cout<<j<<endl;
			break;
		}
	
	return 0;
}

Measured memory_bytes: 5572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"; // cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;
using P = pair<int, int>;
#include <functional>

int main(void){
  	Cin(int, n);
  	Vec2(P, n, 0, a);
  	For(i, n-1){
  	    Cin(int, u, v, w); u --, v --;
  	    a[u].emplace_back(v, w);
  	    a[v].emplace_back(u, w);
  	}
  	
  	vector<int> c(n, -1);
  	function<void(int, int)> dfs = [&](int v, int f){
        if(c[v] != -1) return;
        c[v] = f;
        for(const auto &u : a[v]) dfs(u.first, (f + u.second) % 2);
    };
    dfs(0, 0);
    Couts(c);
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    char a, b;
    cin >> a >> b;
    if(a == 'H') {
        if(b == 'H') {
            cout << 'H' << endl;
        } else {
            cout << 'D' << endl;
        }
    } else {
        if(b == 'H') {
            cout << 'D' << endl;
        } else {
            cout << 'H' << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    string s;
    cin>>s;
    int n=s.size();
    map<char,int> m;
    for(int i=0; i<n; i++){
        m[s[i]]++;
    }
    int cnt=1e9;
    for(auto c:m){
        string s2=s;
        int cnt2=0;
        while(true){
            bool ok=true;
            for(int i=0; i<n-cnt2-1; i++){
                if(s2[i]!=s2[i+1]) ok=false;
            }
            if(ok){
                break;
            }

            string t=s2;
            for(int i=0; i<n-cnt2-1; i++){
                if(t[i+1]==c.first) s2[i]=t[i+1];
                else s2[i]=t[i];
            }
            cnt2++;
        }
        cnt=min(cnt,cnt2);
    }
    cout<<cnt<<endl;

}

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


int main(){
  while(true){
    string x;
    getline(cin, x);
    if(x == "0") return 0;
    int sum = 0;
    for(int i = 0; i < x.size(); i++){
      int a = x.at(i) - '0';
      sum += a;
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 3208
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 310 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

double dp[N][N][N] ;
int a[N] ;
int n ;

double dfs(int a, int b, int c) {
	if (a == 0 && b == 0 && c == 0) return 0 ; // 边界
	if (dp[a][b][c] >= 0) return dp[a][b][c] ;
	int sum = a + b + c ;
	double ans = 1.0 * n / sum ;
	if (a) ans += 1.0 * dfs(a - 1, b, c) * a / sum ;
	if (b) ans += 1.0 * dfs(a + 1, b - 1, c) * b / sum ;
	if (c) ans += 1.0 * dfs(a, b + 1, c - 1) * c / sum ;
	return dp[a][b][c] = ans ;
}

signed main(){
	ass(dp, -1) ;
	scanf("%d", &n) ;
	for (int i = 1, t; i <= n; i++) {
		scanf("%d", &t) ;
		a[t]++ ;
	}
	printf("%.10lf\n", dfs(a[1], a[2], a[3])) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


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

string s;

vector<int> a[30];

int main()
{
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++){
    if (s[i] == s[i + 1]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }

  for (int i = 0; i < s.size() - 2; i++){
    if (s[i] == s[i + 2]){
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;
}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H, W;

int main(){
  while(scanf("%d%d", &H, &W) && H+W){
    rep(i, H){
      rep(j, W) printf(i==0||i==H-1||j==0||j==W-1?"#":".");
      puts("");
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 1180
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp
    i += 1
end

N = line[0].to_i

def string_sort(s)
  a = []
  for i in 1..s.length do
    a.push(s[i-1])
  end
  a = a.sort
  result = ""
  for i in 1..s.length do
    result += a[i-1]
  end
  return result
end

a = []
for i in 1..N do
  a.push(string_sort(line[i]))
end
  
a = a.sort

count = 0
overlap = [1]
for i in 1..N-1 do
  if a[i-1] == a[i] then
    overlap[count] += 1
  else
    count += 1
    overlap[count] = 1
  end
end
  
result = 0
overlap.each do |i|
  result += i * (i-1) / 2
end

print result

Measured memory_bytes: 26600
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()

edges=[]
for i in range(N):
    for j in range(i+1, N):
        edges.append((i+1, j+1))

if K>(N-1)*(N-2)//2:
    print(-1)
    exit()
else:
    for i in range(K):
        edges.pop()

print(len(edges))
for u, v in edges:
    print(u, v)


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll w;
    cin>>w;
    ll a[n][2];
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[i][0] = x;
        a[i][1] = y;
    }
    ll dp[100000+1] = {};
    for(ll i=0;i<100001;i++)
        dp[i] = INT_MAX;
    dp[0] = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=100000;j>=1;j--)
        {
            if(j>=a[i][1]&&dp[j-a[i][1]]<INT_MAX)
            {
                dp[j] = min(dp[j],a[i][0]+dp[j-a[i][1]]);
            }
        }
    }
    ll ans = 0;
    for(ll i=0;i<=100000;i++)
    {
        if(dp[i]<=w&&dp[i]>=0)
            ans = max(ans,i);
    }
    cout<<ans<<endl;
}

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

typedef long long LL;

LL N, A, B;
LL h[100001];

int main() {
	cin >> N >> A >> B;
	for(int i = 0; i < N; i++)
		scanf("%lld", &h[i]);
	
	LL l = 0, r = 1e+9;
	while(l + 1 < r) {
		LL mid = (l + r) / 2;
		LL cnt = 0;
		for(int i = 0; i < N; i++){
			LL res = max((h[i] - B * mid), 0ll);
			res = (res + (A - B - 1)) / (A - B);
			cnt += res;
		}
		if(cnt <= mid)
			r = mid;
		else
			l = mid;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int a[10];
    for(int i = 1; i <= 5; i++)cin>>a[i];
    int k;
    cin>>k;
    bool flag = true;
    /*for(int i = 1; i <= 5; i++)
    {
        for(int j = i+1; j <= 5; j++)
        {
            int s = fabs(a[i]-a[j]);
            if(s > k)
            {
                flag = false;
                break;
            }
        }
    }*/
    if(a[5]-a[1]>k)flag=false;
    if(!flag){
        cout<<":("<<endl;
    }else
    {
        cout<<"Yay!"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 ll a, b, c;
 cin >> a >> b >> c;
 if((c-a-b>0)&&((a*a+b*b+c*c-2*a*c-2*b*c-2*a*b)>0)) cout << "Yes";
 else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;
const int SIZE=100005;
const double EPS=1e-6;

int a[SIZE],b[SIZE];

int main(){
	/*main function start*/
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=0;i<n+1;i++){
		scanf("%d",a+i);
	}
	for(int i=0;i<n;i++){
		scanf("%d",b+i);
	}
	for(int i=0;i<n;i++){
		int tmp=min(a[i],b[i]);
		a[i]-=tmp;
		b[i]-=tmp;
		ans+=tmp;
		tmp=min(a[i+1],b[i]);
		a[i+1]-=tmp;
		b[i]-=tmp;
		ans+=tmp;
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

int N;
ll a[20];

ll solve(int l, int r, ll x, ll y) {
    if (r - l <= 1) return 0;
    ll res = 1e16;
    lep(i, l + 1, r) chmin(res, solve(l, i, x, x + y) + solve(i, r, x + y, y) + (x + y) * a[i]);
    return res;
}

int main() {
    read(N);
    Rep(i, N) read(a[i]);
    printf("%lld\n", a[1] + a[N] + solve(1, N, 1, 1));
    return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let t = read::<usize>();
    for _ in 0..t {
        solve();
    }
}

fn solve() {
    let n = read::<usize>();
    let mut l_largers = vec![];
    let mut r_largers = vec![];

    let mut ans0 = 0;
    for _ in 0..n {
        let v = read_vec::<i64>();
        let (k, l, r) = (v[0] as usize - 1, v[1], v[2]);
        if l >= r {
            l_largers.push((k, l, r));
        } else {
            if k == n - 1 {
                ans0 += l;
            } else {
                r_largers.push((n - 2 - k, r, l))
            }
        }
    }
    l_largers.sort();
    r_largers.sort();
    let ans1 = solve_half(l_largers, false);
    let ans2 = solve_half(r_largers, true);
    debug!(ans1, ans2);
    let ans = ans0 + ans1 + ans2;
    println!("{}", ans);
}

fn solve_half(largeres: Vec<(usize, i64, i64)>, is_r: bool) -> i64 {
    let n = largeres.len();
    if n == 0 {
        return 0;
    }
    let mut heap = BinaryHeap::new();
    let mut dict = HashMap::new();
    for (k, l, r) in largeres {
        if k >= n {
            heap.push((l - r, k, l, r));
        } else {
            dict.entry(k).or_insert(vec![]).push((l, r));
        }
    }
    // debug!(dict);

    let mut ret = 0;
    for i in (0..n).rev() {
        if dict.contains_key(&i) {
            for &v in dict[&i].iter() {
                let k = i;
                let (l, r) = (v.0, v.1);
                heap.push((l - r, k, l, r));
            }
        }

        if let Some(top) = heap.pop() {
            ret += top.2;
        }
    }
    while let Some(top) = heap.pop() {
        ret += top.3;
    }

    ret
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12396
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include <map>
#include <set>

using namespace std;

#define REP(i,x) for(int i=0; i<(int)(x); i++)       // 0 <= i < x
#define REPS(i,x) for(int i=1; i<=(int)(x); i++)     // 0 < i <= x
#define RREP(i,x) for(int i=((int)(x)-1); i>=0; i--) // x > i >= 0
#define RREPS(i,x) for(int i=((int)(x)); i>0; i--)   // x >= i > 0
#define INF 100000000
#define MAX_N 100000

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

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main(void){
	int N;
    cin >> N;
    int ar[MAX_N] = {0};
    int temp;
    
    REP(i, N){
        cin >> temp;
        if(temp > N){
            ar[0]++;
        }else{
            ar[temp]++;
        }
    }

    int res = ar[0];
    REPS(i, N){
        if(ar[i] >= i){
            res += ar[i] - i;
        }else{
            res += ar[i];
        }
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b;
    cin>>a>>b;
    if(a>0)
    {
        cout<<"Positive"<<endl;
        return 0;
    }
    if(a<0&&b<0&&(b-a+1)%2==1)
    {
        cout<<"Negative"<<endl;
        return 0;
    }
    if(a<=0&&b>=0)
    {
        cout<<"Zero"<<endl;
        return 0;
    }
    cout<<"Positive"<<endl;
    return 0;
} 

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define CK(n, a, b) ((a) <= (n) && (n) < (b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;


int H;  //フィールドの高さ
int W;  //フィールドの幅
int start_y, start_x;    //開始座標
const int NODE_SIZE=25;
string S[NODE_SIZE];
int d[NODE_SIZE][NODE_SIZE];
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { -1, 0, 1, 0 };

int next_start_y, next_start_x;
int max_dist;
//幅優先探索 (フィールド: 配列/string)
void bfs_field() {

    queue<pair<int,int>> q; //<座標(y,x)>
    bool visited[NODE_SIZE][NODE_SIZE];
    REP(i,0,H)REP(j,0,W) visited[i][j] = false; // 初期位置を設定
    REP(i,0,H)REP(j,0,W) d[i][j] = -1;// 最後まで-1なら到達不可能
    q.push({start_y, start_x});  // 開始ノードを追加
    d[start_y][start_x] = 0; // 初期状態のコスト
    while(!q.empty()){
        int cur_y = q.front().first;
        int cur_x = q.front().second;
        int curStep = d[cur_y][cur_x];
        q.pop();
        if(visited[cur_y][cur_x]) continue;
        visited[cur_y][cur_x] = true;
		if(d[cur_y][cur_x] > max_dist){
			next_start_y = cur_y;
			next_start_x = cur_x;
			max_dist = d[cur_y][cur_x];
		}

        REP(k,0,4){
            int next_y = cur_y + dy[k];
            int next_x = cur_x + dx[k];

            if(!CK(next_y,0,H) || !CK(next_x,0,W)) continue;  //範囲外
            /* ここに問題ごとの条件 */
			if(S[next_y][next_x] == '#') continue;

			if(!visited[next_y][next_x]){     //未到達の座標だけpush.
                q.push({next_y, next_x});
                d[next_y][next_x] = d[cur_y][cur_x] + 1;
            }
        }
    }
}
int ans;
int main(){
	cin >> H >> W;
	REP(i,0,H){
		cin >> S[i];
	}
	REP(i,0,H){
		REP(j,0,W){
			if(S[i][j] == '.'){
				start_y = i;
				start_x = j;
				max_dist = 0;
				bfs_field();
				ans = max(ans, max_dist);
			}
		}
	}

	p(ans);

	return 0;
}

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

// ABC091 at 2018/03/17

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

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if ((A + B) < C) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        ArrayList<String> list1 = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            list1.add(sc.nextLine());
        }
        int M = sc.nextInt();
        ArrayList<String> list2 = new ArrayList<>();
        sc.nextLine();
        for (int j = 0; j < M; j++) {
            list2.add(sc.nextLine());
        }

        int cnt = 0;
        int max = 0;
        ArrayList<String> used = new ArrayList<>();
        for (String string : list1) {
            if (!used.contains(string)) {
                cnt = cul(string, list1, list2);
                if (max < cnt) {
                    max = cnt;
                }
                used.add(string);
            }
        }
        if (max < 0) {
            System.out.println(0);
        } else {
            System.out.println(max);
        }

    }
    private int cul(String target, ArrayList<String> list1, ArrayList<String> list2) {
        int cnt = 0;
        for (String string : list1) {
            if (target.equals(string)) {
                cnt++;
            }
        }
        for (String string : list2) {
            if (target.equals(string)) {
                cnt--;
            }
        }
        return cnt;
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

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

int main(){
	int x,y;
	cin>>x>>y;
	
	if(x==0){
		if(y>=0){
			cout<<y<<endl;
		}else{
			cout<<abs(y)+1;
		}
		return 0;
	}
	
	if(y==0){
		if(x<=0){
			cout<<abs(x)<<endl;
		}else{
			cout<<x+1<<endl;
		}
		return 0;
	}
	
	if(x>=0&&y>=0){
		if(x<=y){
			cout<<y-x<<endl;
		}else{
			cout<<x-y+2<<endl;
		}
	}else if(x<0&&y<0){
		if(x<=y){
			cout<<y-x<<endl;
		}else{
			cout<<x-y+2<<endl;
		}
	}else if(x>=0&&y<0){
		cout<<abs((-1)*x-y)+1<<endl;
	}else if(x<0&&y>=0){
		cout<<abs((-1)*x-y)+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256