akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    write(a); puts("");
}
const int N=100005;
int n,tong[N],ans;
int main(){
    n=read();
    for(int i=1;i<=n;i++){
    	int t=read(); tong[t]++; tong[t+1]++; if(t)tong[t-1]++;
	}
	for(int i=0;i<N;i++)ans=max(ans,tong[i]);
	writeln(ans);
}

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

int main() {
  	int n, ans = 0;
  	cin >> n;
  	vector<int> p(n);
    for(int i = 0; i < n; i++) {
      	cin >> p[i];
        if(i + 1 != p[i]) ans++;
    }
    if(ans < 3) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}
  

Measured memory_bytes: 47128
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string S, T;

      cin >> S >> T;
      
      T.pop_back();
      

  if (S == T) {
    cout << "Yes" << endl;
    }

    else if (S != T) {
    cout << "No" << endl;
    }

    }

Measured memory_bytes: 3604
<?php
list($s) = strs();
echo max(((int) $s[0] - 1) + (strlen($s) - 1) * 9, digitSum($s));
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function digitSum($n)
{
    return array_sum(array_map('intval', str_split((string) $n)));
}


Measured memory_bytes: 16164
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

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

	LL N;

	cin >> N;

	vector<LL> A(N);
	vector<LL> wrk(N);

	for(LL i=0;i<N;i++){
		cin >> A.at(i);
	}

	wrk = A;
	sort(A.rbegin(),A.rend());

	for(LL i=0;i<N;i++){
		if(A[0] <= wrk[i]){
			cout << A[1] << endl;
		}else{
			cout << A[0] << endl;
		}
	}

	return 0;

}



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


def partition(a, p, r):
    x = ns[r]
    i = p - 1
    for j in range(p, r):
        if ns[j] <= x:
            i += 1
            ns[i], ns[j] = ns[j], ns[i]
    ns[i + 1], ns[r] = ns[r], ns[i + 1]
    return i + 1, ns


if __name__ == '__main__':
    n = int(input())
    ns = [int(e) for e in input().split()]
    # n = 12
    # ns = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
    r = len(ns) - 1
    idx, ns = partition(ns, 0, r)
    ns = [str(n) for n in ns]
    ns[idx] = '[{}]'.format(ns[idx])
    print(" ".join(ns))

Measured memory_bytes: 18384
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = scanInt()
	}

	sort.Ints(d)

	ans := d[n/2] - d[n/2-1]

	fmt.Println(ans)
	
}


Measured memory_bytes: 2048
#include<cstdio>
#include<algorithm>
using namespace std;
int a[400005];
int main()
{
	int k,n;
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	int ans=2147483640;
	for(int i=n+1;i<=2*n;i++)
	{
		a[i]=a[i-n]+k;
	}
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,a[i+n-1]-a[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, K;
    scan(N, K);
    vector<int> h(N);
    scan(h);
    int ans = 0;
    for (auto &&i : h) {
        if (K <= i)
            ans++;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  int N,K;
  int d;
  int check;
  int answer;
  cin >> N >> K;
  answer = N;
  vector<int> vec(N);
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      cin >> check;
      vec.at(check - 1) = 1;
    }
    d = 0;
  }
  for(int i = 0; i < N; i++){
    answer = answer - vec.at(i);
  }
  cout << answer;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 1e9 + 1
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=1000000007;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

int main(){
    /* 累積和 */
    int n, k;
    cin >> n >> k;

    ll ruiseki[n+1];
    ruiseki[0] = 0;

    REPN(i, 1, n+1) {
        ruiseki[i] = ruiseki[i-1] + i;
        //cout << ruiseki[i] << endl;
    }

    modint ans = 0;

    REPN(i, k, n+2) {
        /* i個選ぶとき */
        if(i == n+1) ans += 1;
        else ans += -(ruiseki[i-1]) + (ruiseki[n] - ruiseki[n-i]) + 1;
        //cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5180
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;

ll n, k, c;

ll modpow(ll x, ll e) {
  ll res = 1;
  while (e) {
    if (e & 1) res = res * x % MOD;
    x = x * x % MOD;
    e >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n >> k;
  vector<ll> table(k + 1);
  vector<bool> is_prime(k + 1, true);
  vector<ll> prime;

  for(int i = 1; i <= k; ++i) table[i] = modpow(k / i, n);
  // 現時点でそれぞれのiについて、gcdがiの倍数である数列の個数が入っている。
  
  // 素数を列挙する
  for (int i = 2; i <= k; ++i) {
    if (is_prime[i]) {
      prime.push_back(i);
      for (int j = i + i; j <= k; j += i) is_prime[j] = false;
    }
  }

  for (ll p: prime)
    for (int i = 1; i * p <= k; ++i) table[i] -= table[i * p];

  ll ans = 0;
  for (ll i = 1; i <= k; ++i) ans = (ans + i * table[i] % MOD) % MOD;
  cout << ans;
  return 0;
}



Measured memory_bytes: 4276
MOD = 10 ** 9 + 7
qTable = [[(j * i) % 13 for j in range(13)] for i in range(11)]

S = input()

C, tC, qi = [1] + [0] * 12, [0] * 13,  1

for i in range(len(S)):
    if S[-(i + 1)] == '?':
        tC = [0] * 13
        for j in range(10):
            q = qTable[j][qi]
            for c in range(13):
                tC[(c + q) % 13] += C[c]
    else:
        q = qTable[int(S[-(i + 1)])][qi]
        for c in range(13):
            tC[(c + q) % 13] = C[c]

    qi = qTable[10][qi]
    for c in range(13):
        C[c] = tC[c] % MOD

print(C[5] % MOD)


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n, m; cin >> n >> m;
        if (!n) break;
        vector<int> vv(m + 1);
        rep(i, 0, n) {
            int d, v; cin >> d >> v;
            vv[d] = max(vv[d], v);
        }
        int ans = 0;
        for (int i = 1; i <= m; i++) ans += vv[i];
        cout << ans << endl;
    }
}



Measured memory_bytes: 3196
import java.util.Scanner;

class Main {

	public static final String LIGHT = "light";
	public static final String FLY = "fly";
	public static final String BANTAM = "bantam";
	public static final String FETHER = "feather";
	public static final String WELTER = "welter";
	public static final String MIDDLE = "middle";
	public static final String HEAVY = "heavy";

	public static void main(String[] args) {

		Scanner scanner = null;
		try {
			scanner = new Scanner(System.in);
			while (scanner.hasNextDouble()) {
				double weight = scanner.nextDouble();

				System.out.println(getClassName(weight));
			}

		} finally {
			scanner.close();
		}
	}

	/**
	 * ????´????????§°?????????
	 *
	 * @param num
	 * @param flag
	 * @return
	 */
	public static String getClassName(double num) {
		StringBuilder sb = new StringBuilder();

		// light????????????
		if (isLight(num)) {
			sb.append(LIGHT);
			sb.append(" ");
		}
		if (num <= 51.00) {
			sb.append(FLY);
		} else if (num <= 54.00) {
			sb.append(BANTAM);
		} else if (num <= 57.00) {
			sb.append(FETHER);
		} else if (num <= 60.00) {
			sb.deleteCharAt(sb.length() - 1);
		} else if (num <= 69.00) {
			sb.append(WELTER);
		} else if (num <= 81.00) {
			sb.append(MIDDLE);
		} else {
			sb.append(HEAVY);
		}
		return sb.toString();
	}

	/**
	 * ????´????light???????????????????????????
	 *
	 * @param num
	 * @return
	 */
	public static boolean isLight(double num) {

		if (num <= 48.00 || (57.00 < num && num <= 64.00)
				|| (69.00 < num && num <= 75.00)
				|| (81.00 < num && num <= 91.00)) {
			return true;
		}
		return false;

	}

}

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

t=[]
for i in range(n):
  t.append(int(input()))
t.sort()

first=t[0]
people=1
count=1

for i in range(1,n):
  if people<c and t[i]-first<=k:
    people +=1
  else:
    first=t[i]
    people =1
    count+=1
print(count)    

Measured memory_bytes: 7384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 INF=1e9+1;

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
  long long n,k,num,min=3999999996990000001,y_length,y_min;
  cin >> n >> k;
  vector<pair<int,int>> p(n);
  for(int i=0;i<n;i++){
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  for(int r=0;r<n;r++){
    for(int l=r+k-1;l<n;l++){
      vector<int> tmp;
      for(int i=r;i<=l;i++){
        tmp.push_back(p[i].second);
      }
      sort(tmp.begin(),tmp.end());
      y_min = tmp[k-1] - tmp[0];
      for(int yr=0;yr<tmp.size();yr++){
        for(int yl=yr+k-1;yl<tmp.size();yl++){
          y_length = tmp[yl]-tmp[yr];
          y_min = (y_min<y_length)?y_min:y_length;
        }
      }
      num = y_min*(p[l].first-p[r].first);
      min = (num<min)?num:min;
    }
  }
  cout << min << endl;


}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll a,b; cin>>a>>b;
  cout << a*b <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    rep(i, 0, n)
    {
        int tmp;
        cin >> tmp;
        h[i] = abs(1000 * a - 1000 * t + 6 * tmp);
    }
    cout << distance(h.begin(), MN(h)) + 1 << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int N,M,K;
vector<pair<int,int>> AB;
vector<pair<int,int>> CD;

vector<int> par;
vector<int> rnk;
void init(int N){ rep(i,N) {par[i] = i; rnk[i] = 0;} }
int root(int x) {
  return par[x] == x? x : par[x] = root(par[x]);
  /*
  if(par[x]==x) return x;
  else return par[x] = root(par[x]);
  */
}
bool same(int x, int y) { return root(x) == root(y); }
void unite(int x, int y){
  x = root(x); y = root(y);
  if(x==y) return;

  if(rnk[x] < rnk[y]) par[x] = y;
  else{
    par[y] = x;
    if(rnk[x] == rnk[y]) rnk[x]++;
  }
}


int main(){
  cin >> N >> M >> K;
  AB.resize(M);
  rep(i,M){
    cin >> AB[i].first >> AB[i].second;
    AB[i].first--;
    AB[i].second--;
    if(AB[i].first>AB[i].second){
      int tmp = AB[i].first;
      AB[i].first = AB[i].second;
      AB[i].second = tmp;
    }
  }
  CD.resize(K);
  rep(i,K) {
    cin >> CD[i].first >> CD[i].second;
    CD[i].first--;
    CD[i].second--;
  }
  par.resize(N); rnk.resize(N);
  init(N);
  rep(i,M) {
    unite(AB[i].first,AB[i].second);
  }

  vector<int> ans(N);
  map<int,int> mp;
  rep(i,N){
    par[i] = root(i);
    mp[par[i]]++;
  }
  rep(i,N){
    ans[i] = mp[root(i)]-1;
  }
  rep(i,M){
    if(same(AB[i].first,AB[i].second)){
      ans[AB[i].first]--;
      ans[AB[i].second]--;
    }
  }
  rep(i,K){
    if(same(CD[i].first,CD[i].second)){
      ans[CD[i].first]--;
      ans[CD[i].second]--;
    }
  }
  rep(i,N){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

class DisjointSet{
public:
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    sz.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  int findSize(int x){
    return sz[findSet(x)];
  }
};

int N,M;
vector<int> A,B;

vector<int> g[100010];
vector<int> out;
vector<int> C,D;

void dfs(int now,int par){
    for(auto nex:g[now]){
        if(nex==par) continue;
        dfs(nex,now);
    }
    if(par==-1) return;

    if(out[now]%2){
        C.push_back(now);
        D.push_back(par);
        out[now]=0;
    }else{
        C.push_back(par);
        D.push_back(now);
        out[par]=(out[par]+1)%2;        
    }
}

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  rep(i,M) cin>>A[i]>>B[i];

  if(M%2){
      cout<<-1<<endl;
      return 0;
  }

  out.resize(N+1,0);
  DisjointSet us(N+1);
  for(int i=0;i<M;i++){
      A[i]--;B[i]--;
      if(us.same(A[i],B[i])){
          C.push_back(A[i]);
          D.push_back(B[i]);
          out[A[i]]++;
          out[A[i]]%=2;
      }else{
          us.unite(A[i],B[i]);
          g[A[i]].push_back(B[i]);
          g[B[i]].push_back(A[i]);
      }
  }

  dfs(0,-1);
  for(int i=0;i<C.size();i++) cout<<C[i]+1<<" "<<D[i]+1<<endl;


  return 0;
}


Measured memory_bytes: 14116
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int m,d;
    cin >> m >> d;
    int ans = 0;
    REP(i,1,m+1){
      REP(j,1,d+1){
        int tmp = j;
        int tn = tmp / 10;
        int on = tmp % 10;
        if(tn < 2 or on < 2) continue;
        if(tn * on == i) ans++;
      }
    }
    print(ans);
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if (A <= 9 && B <= 9) {
        cout << A * B << endl;
    }
    else {
        cout << -1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using sll = signed long long;
using ui = unsigned int;

auto ui_cast(sll s) {
	return static_cast<ui>(s);
}

template<class T>
class rec {
private:
	const T t;
public:
	rec(const T& t_) :t{ t_ } {}

	auto operator()(sll n, sll x)->sll {
		if (n == 0)
			return 1 <= x ? 1 : 0;

		auto idx = ui_cast(n) - 1;
		auto& e = t[idx];

		if (x <= e.first + 1)
			return this->operator()(n - 1, x - 1);
		else
			return
				e.second + 1
				+this->operator()(n - 1, x - 2 - e.first);
	}
};


int main() {
	sll n, x;
	std::cin >> n >> x;

	std::vector<std::pair<sll,sll>> apn;
	apn.resize(ui_cast(n));
	apn.front() = { 1,1 };
	
	for (ui i{ 1 }; i < ui_cast(n); ++i) {
		auto&e = apn[i];
		auto& pe = apn[i - 1];
		e.first = 2*pe.first+3;
		e.second = 2*pe.second+1;
	}
	rec<decltype(apn)> r{ apn };

	std::cout<<r(n, x)<<"\n";
	return 0;
}



Measured memory_bytes: 256
while True :
    a,op,b = map(str,raw_input().split())
    
    a = int(a)
    b = int(b)
    
    if op == "+" :
        print a + b
    elif op == "-":
        print a - b
    elif op == "*":
        print a * b
    elif op == "/":
        print a / b
    elif op == "?":
        break

Measured memory_bytes: 6336
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
	double a, b, c, d, s, l, h;
	cin >> a >> b >> c;
	c = c * M_PI / 180;
	d = sqrt(a * a + b * b - 2 * a * b * cos(c));
	l = a + b + d;
	s = 1.0 / 2.0 * a * b * sin(c);
	h = s * 2 / a;
	printf("%.6f\n%.6f\n%.6f\n", s, l, h);
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if(i*j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3556
def main():
    n = int(input())
    lst=[]

    for i in range(n):
        lst.append(int(input()))

    now = 1
    ans = 0
    for i in range(n):
        now = lst[now-1]
        ans +=1
        if now == 2:
            print(ans)
            exit()

    print(-1)

if __name__ == "__main__":
        main()


Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll x,y,ans=0;
    cin>>x>>y;
    while(x<=y)
    {
        ans++;
        x=x*2;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
a = [0]*3
n,a[0],a[1],a[2] = map(int,input().split())

l = []
for i in range(n):
  l += [int(input())]

def f(x):
  if len(x) == n:
    if not (0 in x and 1 in x and 2 in x):
      return 5000
    b = [0]*3
    c = -30
    for i in range(n):
      t = x[i]
      if t >= 0:
        b[t] += l[i]
        c += 10
    for i in range(3):
      c += abs(a[i]-b[i])
    return c
  else:
    return min(f(x+[-1]),f(x+[0]),f(x+[1]),f(x+[2]))
  
print(f([]))
  




Measured memory_bytes: 3064
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
void solve()
{
	int n;
	cin >> n;
	n%=10;
	if(n==2 || n==4 || n==5 || n == 7|| n== 9)
	{
		cout << "hon";
		return;
	}
	if(n == 3)
	{
		cout << "bon";
		return;
	}
	else cout << "pon";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORD(i,a,n) for(int i=n-1;i>=0;i--)
using namespace std;
 
 
int32_t main(){
 

    int n,wt,w[101],v[101];
    cin>>n>>wt;
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    int dp[n+1][wt+1];
    for(int i=0;i<=wt;i++)
    {
        dp[0][i]=0;
        dp[1][i]=0;
    }
    dp[1][w[1]]=v[1];

    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<=wt;j++)
        {
            if(j-w[i]>=0)
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    int ans=0;
    for(int i=0;i<=wt;i++)
       ans=max(ans,dp[n][i]);
   cout<<ans;

 
    return 0;
 
}


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

int N;

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

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

  int tmp = -1;
  int counter = 0;
  for(int i: d){
    if(i != tmp){
      tmp = i;
      counter++;
    }
  }
  cout<<counter<<endl;

  return 0;
}


Measured memory_bytes: 256
w=[]
for i in range(10):
    a=int(input())
    w.append(a)
    
w=sorted(w,reverse=True)
w=w[:3]
 
k=[]    
for j in range(10):
    a=int(input())
    k.append(a)
    
k=sorted(k,reverse=True)
k=k[:3]

print(sum(w),sum(k))


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

ll N, M, Q;

vector<ll>path[101010];
ll V[101010], D[101010], C[101010];
ll flg[101010][15];
ll ans[101010];

void dfs(ll v, ll d, ll c){
    if(flg[v][d])return;
    if(ans[v] == 0)ans[v] = c;
    flg[v][d] = c;
    if(d == 0)return;
    for(ll i = 0; i < path[v].size(); i++){
        ll to = path[v][i];
        if(flg[to][d - 1])continue;
        dfs(to, d - 1, c);
    }
}

int main(){
    
    cin >> N >> M;
    for(ll i = 0; i < M; i++){
        ll a, b;
        cin >> a >> b;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    cin >> Q;
    for(ll i = 1; i <= Q; i++)cin >> V[i] >> D[i] >> C[i];
    for(ll i = Q; i >= 1; i--)dfs(V[i], D[i], C[i]);
    for(ll i = 1; i <= N; i++)cout << ans[i] << endl;
    
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int k;
  cin >> k;

  queue<long long> q;
  for (int i = 1; i <= 9; ++i)  q.push(i);

  while (1) {
    --k;
    long long cur = q.front();
    q.pop();

    if (!k) {
      cout << cur << endl;
      break;
    }

    if (cur % 10) q.push(cur * 10 + cur % 10 - 1);
    q.push(cur * 10 + cur % 10);
    if (cur % 10 != 9) q.push(cur * 10 + cur % 10 + 1);
  }
}

Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int c = inp.nextInt();
        int aa[] = {a, b, c};
        Arrays.sort(aa);
        int ans = 0;
        for (int i = 1; i < 3; i++) {
            ans += (aa[i] - aa[i - 1]);
        }
        System.out.println(ans);
        inp.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define hashset unordered_set
#define hashmap unordered_map
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii;
template <typename T> inline vector<T> readvector(size_t size) {
  vector<T> res(size);
  for (size_t i = 0; i < size; ++i) {
    cin >> res[i];
  }
  return res;
}
template <typename T>
inline void printvector(vector<T> &arr, string sep = " ", string ends = "\n") {
  for (size_t i = 0; i < arr.size(); ++i) {
  }
}
inline int binPow(int x, int deg, int mod) {
  int ans = 1;
  for (int i = sizeof(x) * CHAR_BIT - 1; i >= 0; i--) {
    ans *= ans;
    ans %= mod;
    if (getbit(deg, i))
      ans *= x;
    ans %= mod;
  }
  return ans;
}
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;



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

  int h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;

  return 0;
}

Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

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

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

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

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

  string s; cin >> s;
  int a = (s[0]-'0')*10 + (s[1]-'0');
  int b = (s[2]-'0')*10 + (s[3]-'0');
  bool p = 0, q = 0;
  if(b >= 1 and b <= 12) p = 1;
  if(a >= 1 and a <= 12) q = 1;
  if(p and q) cout << "AMBIGUOUS" << endl;
  else if(p and !q) cout << "YYMM" << endl;
  else if(!p and q) cout << "MMYY" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll N;
    cin >> N;
    vector<ll> W(N);
    for(int i=0;i<N;i++){
        cin >> W[i];
    }
    vector<ll>csum(N);
    csum[0]=W[0];
    for(int i=1;i<N;i++){
        csum[i]=csum[i-1]+W[i];
    }
    ll ans=1LL<<60;
    for(int i=0;i<N;i++){
        ans=min(ans,llabs(csum[i]-(csum[N-1]-csum[i])));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//STN2
#include<iostream>
using namespace std;

void swap(int*, int*);

int main()
{
	int x = -1,y= -1;
	while(1)
	{
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;
		
		if(x > y)
			swap(&x, &y);
		cout << x << " " << y << endl;
	}
	
	return 0;
}

void swap(int *x, int *y)
{
	int z;
	z = *x;
	*x = *y;
	*y = z;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t n;
    std::cin >> n;

    std::vector<int64_t> values(n);
    for (auto& p : values) {
        std::cin >> p;
    }

    int64_t count = 0;
    for (int64_t i = 1; i < n-1; ++i) {
        if (values.at(i-1) <= values.at(i) && values.at(i) <= values.at(i+1)) count++;
        if (values.at(i-1) >= values.at(i) && values.at(i) >= values.at(i+1)) count++;
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define N 200005
int n,m; 
int a[N], b[N];
int main() {
scanf("%d", &n); 
map<int,int> cnt; 
for(int i=0; i<n; i++) scanf("%d", &a[i]), cnt[a[i]]++; 
scanf("%d", &m); 
for(int i=0; i<m; i++) {
	scanf("%d", &b[i]); 
	if (cnt[b[i]] == 0) { printf("NO\n"); return 0; } 
	cnt[b[i]]--; 
}
printf("YES\n"); 
	return 0; 
}

Measured memory_bytes: 11136
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	string sInput;
	cin >> sInput;
	if ((sInput[0] == sInput[1] && sInput[1] == sInput[2]) || (sInput[1] == sInput[2] && sInput[2] == sInput[3]))
		cout << "Yes\n";
	else
		cout << "No\n";
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;cin >> t;
    while(t--){
        int n;cin >> n;
        vector<ll> k(n),l(n),r(n);
        vector<vector<int>> a(n),b(n+1);
        REP(i,n){
            cin >> k[i] >> l[i] >> r[i];
            k[i]--;
            if(l[i]>r[i]){
                a[k[i]].push_back(i);
            }
            if(l[i]<r[i]){
                b[k[i]+1].push_back(i);
            }
        }
        priority_queue<pair<int,int>> pq,qp;
        vector<bool> f(n);
        ll sum=0;
        REPR(i,n){
            for(int x:a[i]){
                pq.push({l[x]-r[x],x});
            }
            if(pq.empty()){
                continue;
            }
            int p=pq.top().second;
            pq.pop();
            sum+=l[p];
            f[p]=true;
        }
        REP(i,n){
            for(int x:b[i]){
                qp.push({r[x]-l[x],x});
            }
            if(qp.empty()){
                continue;
            }
            int p=qp.top().second;
            qp.pop();
            sum+=r[p];
            f[p]=true;
        }
        REP(i,n){
            if(!f[i]){
                sum+=(l[i]>=r[i]?r[i]:l[i]);
            }
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 21944
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int x, A, y, B;
	cin >> x >> y >> A >> B;
	int C;
	cin >> C;
	vector<pair<int, int>> a;
	for (int i = 0; i < A; ++i) {
		int v;
		cin >> v;
		a.emplace_back(v, 0);
	}
	for (int i = 0; i < B; ++i) {
		int v;
		cin >> v;
		a.emplace_back(v, 1);
	}
	for (int i = 0; i < C; ++i) {
		int v;
		cin >> v;
		a.emplace_back(v, 2);
	}
	sort(a.rbegin(), a.rend());
	int cnt1 = 0, cnt2 = 0;
	int cnt = 0;
	ll answer = 0;
	for (int i = 0; i < A + B + C; ++i) {
		int type = a[i].second;
		if (type == 0) {
			if (cnt1 != x) {
				++cnt1;
				++cnt;
				answer += a[i].first;
			}
		} else if (type == 1) {
			if (cnt2 != y) {
				++cnt2;
				++cnt;
				answer += a[i].first;
			}
		} else {
			++cnt;
			answer += a[i].first;
		}
		if (cnt == x + y) {
			break;
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 6512
N,M = map(int,input().split())
PY = {n: [] for n in range(N + 1)}
ans = [0]*M
for i in range(M):
  p,y = map(int,input().split())
  PY[p].append((y, i))
for p,y in PY.items():
  y.sort()
  for j, (z, i) in enumerate(y):
    top_number = '0'*(6-len(str(p)))+str(p)
    under_number = '0'*(6-len((str(j+1))))+str(j+1)
    ans[i] = top_number + under_number
for i in range(M):
  print(ans[i])

Measured memory_bytes: 44448
n, k = map(int, input().split())
n_list = []
a_int_all = []
for i_n in range(1, n + 1):
    n_list.append(i_n)
for i in range(0, k):
    d_k = input()
    a_int_k = list(map(int, input().split()))
    a_int_all.extend(a_int_k)
n_only = set(a_int_all)
ans = n - len(n_only)
print(ans)

Measured memory_bytes: 9120
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 333
#else
#define SIZE 333
#endif

int N,M,L,Q;
int DP[SIZE][SIZE],DP2[SIZE][SIZE];

void solve() {
    cin>>N>>M>>L;
    REP(i,N)REP(j,N) {
        DP[i][j]=DP2[i][j]=LONG_LONG_MAX/2;
    }
    int a,b,c;
    REP(i,M) {
        cin>>a>>b>>c;
        a--;b--;
        DP[a][b]=c;
        DP[b][a]=c;
    }
    REP(k,N)REP(i,N)REP(j,N)chmin(DP[i][j], DP[i][k]+DP[k][j]);
    REP(i,N)REP(j,N) {
        if (DP[i][j]<=L) DP2[i][j] = 0;
    }
    REP(k,N)REP(i,N)REP(j,N)chmin(DP2[i][j], DP2[i][k]+DP2[k][j]+1);
    cin>>Q;
    int s,t;
    while(Q--) {
        cin>>s>>t;
        s--;t--;
        int ans = (DP2[s][t]==LONG_LONG_MAX/2) ? -1 : DP2[s][t];
        _PN(ans);
    }
}



Measured memory_bytes: 5208
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define rrep(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
    #define vec(n) vector<int>(n)
    #define vvec(m,n) vector<vector<int>> vec(m,vector(n))

  
  
    int main(){
      int n;
      cin >> n;
      auto a = vec(n);
      rep(i,n)cin >> a[i];

      int cnt = 0;
      rep(i,n){
        if(a[i]%2 == 1)cnt++;
      }

      if(cnt%2 == 0)cout << "YES" <<endl;
      else cout << "NO" <<endl;
      }
    


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int N=in.nextInt();
			if(N==0)
				return;
			int x[]=new int[N];
			int y[]=new int[N];
			x[0]=y[0]=1;
			for(int i=1;i<N;i++)
			{
				int pre=in.nextInt();
				int dir=in.nextInt();
				x[i]=x[pre]+(dir==0 ? -1 : dir==2 ? 1 : 0);
				y[i]=y[pre]+(dir==1 ? -1 : dir==3 ? 1 : 0);
			}
			Arrays.sort(x);
			Arrays.sort(y);
			System.out.println((x[N-1]-x[0]+1)+" "+(y[N-1]-y[0]+1));
		}
	}
}

Measured memory_bytes: 34280