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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> ab(n);
  using pll = pair<ll, ll>;
  map<ll, vector<ll>> mp;
  for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
  for (int i = 0; i < n; i++) {
    mp[ab[i].first].push_back(ab[i].second);
  }
  priority_queue<ll> q;
  ll ans = 0;
  for (int i = 0; i < m; i++) {
    for (auto &v : mp[i + 1]) q.push(v);
    if (q.size()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vector{
    double x, y;
};
using namespace std;

int main()
{
    uint X, K=1, pos;
    cin >> X;
    pos = X;
    while (pos % 360 != 0)
    {
        pos += X;
        K++;
    }
    cout << K << endl;
    return 0;
}


Measured memory_bytes: 3628
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]


#True : 負の経路が存在する
def find_negative_loop(n,w,es):
    #負の経路の検出
    #n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
    d = [float("inf")] * n
    d[0] = 0 
    #この始点はどこでもよい
    for i in range(n-1):
        for j in range(w):
            e = es[j]
            if d[e[1]-1] > d[e[0]-1] - e[2]:
                d[e[1]-1] = d[e[0]-1] - e[2]
    neg=[False]*n
    for i in range(n):
        for j in range(w):
            e=es[j]
            if d[e[1]-1] > d[e[0]-1] - e[2]:
                d[e[1]-1] = d[e[0]-1] - e[2]
                neg[e[1]-1]=True
            if neg[e[0]-1]==True:
                neg[e[1]-1]=True
    return (d,neg)


#############################
ans=find_negative_loop(n,m,abc)
if ans[1][-1]==True:
    print("inf")
else:
    print(-ans[0][-1])

Measured memory_bytes: 68824
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
    string s;
    cin >> s;
    cout << s << (s.back() == 's' ? "es" : "s");
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define ll long long
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define Outerloop int q;cin>>q;while(q--)
#define Mod 1000000007
int N=100005;
vector<int> v[100005];
int  visited[100005],dp[100005];
int solve(int n)
{
	if(dp[n]!=0) return dp[n];
	dp[n]=1;
	visited[n]=1;
	for(auto x:v[n])
	{
			visited[x]=1;
			dp[n]=max(dp[n],1+solve(x));
	}
	return dp[n];
}
    int32_t main()
    {
	 int n,m;
	 cin >> n >> m;
	 
	 
	 f(i,0,m)
	 {
	 	int x,y;
	 	cin >> x >> y;
	 	v[x].push_back(y);
	 }
	 
	 
	 int ans=0;
	 f(i,1,n+1)
	 {
	 	ans=max(ans,solve(i)-1);
	 }
		cout<<ans;
    return 0;
    }

Measured memory_bytes: 8576
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)1e5 + 777;
int a[MAXN], ord[MAXN], n;
int tree[2 * MAXN];

void update(int pos, int val) {
	pos += n;

	if(val > tree[pos]) {
		tree[pos] = val;

		for(; pos > 1; pos /= 2) {
			tree[pos / 2] = max(tree[pos], tree[pos ^ 1]);
		}
	}
}

int get(int l, int r) {
	l += n;
	r += n + 1;
	int rez = 0;

	while(l < r) {
		if(l & 1) {
			rez = max(rez, tree[l++]);
		}

		if(r & 1) {
			rez = max(rez, tree[--r]);
		}

		l /= 2;
		r /= 2;
	}

	return rez;
}

void solve() {
	cin >> n;

	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		ord[i] = a[i];
	}

	sort(ord, ord + n);

	for(int i = 0; i < n; ++i) {
		a[i] = lower_bound(ord, ord + n, a[i]) - ord;
	}

	int best = 0;

	for(int i = n - 1; i >= 0; --i) {
		int val = 1 + get(0, a[i]);
		best = max(best, val);
		update(a[i], val);
	}

	cout << best << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

long long Q = 1000000007;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  
  vector<char> A = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 
                   'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 
                   'z', 'x', 'c', 'v', 'b', 'n', 'm'};
  vector<int> B(30, 0);
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 26; j++) 
    {
      if (S.at(i) == A.at(j)) B.at(j)++;
    }
  }
  
  long long ans = 1;
  for (int i = 0; i < 26; i++)
  {
    ans = ans * (B.at(i) + 1) % Q;
  }
  ans = (ans - 1) % Q;
  
  cout << ans << endl;
}

Measured memory_bytes: 512
using System;
class Program
{
	static void Main(string[] args)
	{
    	// 整数の入力
		int a = int.Parse(Console.ReadLine());
      	bool result = false;
      
      	//計算
      	for(int i = 1; i < 10; i++)
        {
          for(int j = 1; j < 10; j++)
          {
            if(i * j == a)
            {
              result = true;
            }
          }
        }
      	//判定
      	if(result)
        {
          Console.WriteLine("Yes");
        }
      	else
        {
          Console.WriteLine("No");
        }
	}
}


Measured memory_bytes: 13140
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll ans=INF;
		RANGE(v, -100, 101) {
			ll c=0;
			REP(i, N) c+=(v-A[i])*(v-A[i]);
			minUpdate(ans, c);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::fastout;
use proconio::input;
use proconio::marker::{Bytes, Chars, Usize1};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }
    let mut v = vec![0; n + 3];
    for i in 0..a.len() {
        let boss = a[i];
        v[boss] += 1;
    }
    println!(
        "{}",
        v.into_iter()
            .skip(1)
            .take(n)
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}


Measured memory_bytes: 16604
from sys import stdin
from collections import deque


# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
    graph = [[] for _ in range(num_nodes)]
    for val in data:
        x, y = val
        graph[x-1].append(y-1)
        if undirected:
            graph[y-1].append(x-1)
    return graph


# BFS
def breadth_first_search(adj_list, start_node):
    N = len(adj_list)
    order = [-1] * N # a bfs ordering of each vertex
    parent = [-1] * N # parent of each vertex in the bfs search tree
    depth = [-1] * N # the depth of each vertex
    q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
    num = 0 # current ordering
    while len(q) > 0:
        v, p, d = q.popleft()
        if order[v] < 0: # visited v for the first time
            order[v] = num; parent[v] = p; depth[v] = d
            num += 1
            for u in adj_list[v]:
                if order[u] >= 0: continue
                q.append((u, v, d+1))
    return order, parent, depth


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    adj_list = get_adj_list(N, _data)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        _, _, depth = breadth_first_search(adj_list, i)
        for j in range(i, N):
            dist_cnt[depth[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)


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

int main() {
  int n, m; cin >> n >> m;
  vector<int> v1, v2;
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    if (a == 1) v1.push_back(b);
    else if (b == n) v2.push_back(a);
  }

  sort(v1.begin(), v1.end());
  for (int a : v2) {
    int i = lower_bound(v1.begin(), v1.end(), a) - v1.begin();
    if (i != v1.size() && v1[i] == a) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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

//[競プロのための高速フーリエ変換](https://www.creativ.xyz/fast-fourier-transform/)
// Cooley–Tukey FFT algorithm
const double PI=acos(-1);
vector<complex<double>> fft(vector<complex<double>> a, bool inverse = false) {
    int n = a.size();
    int h = 0; // h = log_2(n)
    for (int i = 0; 1 << i < n; i++) h++;
    // バタフライ演算用の配置入れ替え
    for (int i = 0; i < n; i++) {
        int j = 0;
        for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
        if (i < j) swap(a[i], a[j]);
    }
    // バタフライ演算
    for (int b = 1; b < n; b *= 2) {
        // 第 log_2(b) + 1 段
        // ブロックサイズ = b * 2
        for (int j = 0; j < b; j++) {
            // ブロック内 j 個目
            // 重み w = (1 の原始 2b 乗根の j 乗)
            complex<double> w =
                polar(1.0, (2 * PI) / (2 * b) * j * (inverse ? 1 : -1));
            for (int k = 0; k < n; k += b * 2) {
                // k を先頭とするブロック
                complex<double> s = a[j + k];         // 前
                complex<double> t = a[j + k + b] * w; // 後
                a[j + k] = s + t;                     // 前の更新
                a[j + k + b] = s - t;                 // 後の更新
            }
        }
    }
    // 逆変換時にサイズで割る調整
    if (inverse)
        for (int i = 0; i < n; i++) a[i] /= n;
    return a;
}
vector<complex<double>> fft(vector<double> a, bool inverse = false) {
    vector<complex<double>> a_complex(a.size());
    for(int i=0;i<a.size();i++)a_complex[i] = complex<double>(a[i], 0);
    return fft(a_complex, inverse);
}
// FFT による畳み込み O(N log N)
vector<double> convolve(vector<double> a, vector<double> b) {
    int s = a.size() + b.size() - 1; // 畳み込み結果のサイズ
    int t = 1; // FFT に使う配列のサイズ（2 の累乗）
    while (t < s) t *= 2;
    a.resize(t); // FFT するためにリサイズ
    b.resize(t); // FFT するためにリサイズ
    vector<complex<double>> A = fft(a);
    vector<complex<double>> B = fft(b);
    for (int i = 0; i < t; i++) {
        A[i] *= B[i]; // 畳み込み結果の FFT 結果を得る
    }
    A = fft(A, true); // IFFT で畳み込み結果を得る
    a.resize(s);      // 畳み込み結果を入れるためにリサイズ
    for (int i = 0; i < s; i++) a[i] = A[i].real(); // 実部が答え
    return a;
}

int main(){
  int N,M,K,L;cin>>N>>M>>K>>L;
  vector<string> B(N);
  for(int i=0;i<N;i++)cin>>B[i];
  string s;cin>>s;

  //解説の解法2
  vector<double> a(500000),b(500000,0);
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)a[i*M+j]=(B[i][j]=='X');
  //ここのMは2桁の数字のpairを一つの数字で持ちたい時の100倍とかと同じ感じ
  //M倍してないやつらより真に強いので実質2次元の情報量を持ってるイメージ
  int x=0,y=0;
  for(int i=0;i<L;i++){
    if(s[i]=='L')x--;
    if(s[i]=='R')x++;
    if(s[i]=='U')y--;
    if(s[i]=='D')y++;
    b[x+y*M]++;
  }
  auto ans=convolve(a,b);
  int fans=0;
  const double eps=0.000000001;
  for(auto p:ans)fans+=((int)(p+eps)>=K);
  cout<<fans<<endl;
}



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

long long a, b, c, d, e, t[101];
int main(){
        cin >> a >> b >> c >> d;
        for(int i = a; i < b; i++) t[i]++;
        for(int i = c; i < d; i++) t[i]++;
        for(int i = 0; i < 101; i++){
                if(t[i] == 2) e++;
        }
        cout << e;
}

Measured memory_bytes: 256
# ARC100D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


# import numpy as np
import bisect
n = int(input())
a = list(map(int, input().split()))
# a = np.array(list(map(int, input().split())))
ca = [None] * n #ca[i] = a0~aiの和
s = 0
for i,num in enumerate(a):
    s += a[i]
    ca[i] = s
# ca = a.cumsum()

def sub(l, start, end, init):
    if len(l)==0:
        return 0,0
    elif end-start==1:
        return 0,l[start]-init
    target = (init + l[end-1])/2
    i = bisect.bisect_right(l, target)
    p1 = (l[i]-init, l[end-1]-l[i])
    p2 = (l[i-1]-init, l[end-1]-l[i-1])
    if abs(p1[0] - p1[1]) < abs(p2[0] - p2[1]):
        return min(p1), max(p1)
    else:
        return min(p2), max(p2)
best = 10**15
for i in range(1,n):
    p1 = sub(ca, 0, i, 0)
    p2 = sub(ca, i, n, ca[i-1])
    nn = max(p1[1]-p2[0], p2[1]-p1[0], p1[1]-p1[0], p2[1]-p2[0])
#     print(p1,p2,nn)
    best = min(best, nn)
print(best)

Measured memory_bytes: 86592
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc153_b
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> input1 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            List<int> input2 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();



            string output = "No";
            if (input1[0] - input2.Sum() <= 0)
            {
                output = "Yes";
            }



            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 19296
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;

ll a,b,c,x,y;
int ans = 0, k[20];
int main(void)
{
	cin >> a >> b >> c >> x >> y;
	ll mi = min(x, y),ma=max(x,y),ans = 0;
	if (2 * c < a + b) {
		ll ans1 = 2 * c*mi; x -= mi; y -= mi;
		ans1 += a * x + b * y;
		ll ans2 = 2 * c*ma;
		ans = min(ans1, ans2);
	}
	else {
		ans = a * x + b * y;
	}
	ct(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
   string s , w="AC";
   cin>> s;
   if(s[0]!='A')
    {cout <<"WA";
    return 0 ; }
    int c= 0;
for(int i =1 ; i<s.size() ; i++)
{
    if(isupper(s[i]))
    {
        c++;

        if(i==1&&s[i]=='C'){
            w= "WA";
            }
            if(i==s.size()-1 &&s[i]=='C')
            {
            w="WA";

            }
    }
}
    if(c!=1)
         w="WA";


cout << w;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 200001;
const ll M = log2(N);

struct point {
    ll x, y, i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    if(n & 1) return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll ans = fast_exp(x, n / 2);
        return ans * ans % mod;
    }
}

ll BIT[N];

void update(int i, ll x, ll n)
{
    for(; i <= n; i++)
        BIT[i] += x;
}

ll query(ll x)
{
    ll sum = 0;
    while(x > 0)
    {
        sum += BIT[x];
        x = (x - 1) & x;
    }
    return sum;
}

int main()
{
    fast;
    int _ = 1;
    cin >> _;
    while(_--)
    {
        ll n, m, x, y, ans = 0;
        cin >> n;
        vector<int> f[n + 1];
        vector<int> b[n + 2];
        pll a[n + 1];
        for(int i = 1; i <= n; i++)
        {
            cin >> m >> x >> y;
            if(x > y)
            {
                ans += x;
                f[m].pb(i);
            }
            else
            {
                ans += y;
                b[m + 1].pb(i);
            }
            a[i] = {x, y};
        }
        set<pair<ll,ll>> s;
        for(int i = 1; i <= n; i++)
        {
            for(auto j:f[i])
                s.insert({a[j].ff - a[j].ss, j});
            while(s.size() > i)
            {
                ans -= s.begin() -> ff;
                s.erase(s.begin());
            }
        }
        s.clear();
        for(int i = n + 1; i >= 1; i--)
        {
            for(auto j:b[i])
                s.insert({a[j].ss - a[j].ff, j});
            while(s.size() > n - i + 1)
            {
                ans -= s.begin() -> ff;
                s.erase(s.begin());
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 27032
#include<iostream>
using namespace std;
int main(){
   int arr[100001],tmp,N,cnt=0;
   cin >> N;
   for(int i=0;i<N;i++)
     cin >> arr[i];
   for(int i=0;i<N;i++){
     if(arr[i] == i+1){
       if(i==0){
         tmp=arr[i];
         arr[i] = arr[i+1];
         arr[i+1] = tmp;
         cnt++;
       }else if(i==N-1){
         tmp=arr[i];
         arr[i] = arr[i-1];
         arr[i-1] = tmp;
         cnt++;
       }else{
         tmp=arr[i];
         arr[i] = arr[i+1];
         arr[i+1] = tmp;
         cnt++;
       }
     }
   }
  cout << cnt << endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/**************************contemporary declaration & definitions**************************/

/**************************define functions**************************/

/**************************main function below**************************/
int main(void) {

	ll A, B, C; cin >> A >> B >> C;
	if (C > A + B) {
		cout << 2 * B + A + 1 << endl;
	}
	else {
		cout << B + C << endl;
	}
	return 0;
}

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

int main(){
  int a, b, ans=0;
  cin >> a >> b;
  rep(i, 2){
      if(a>=b){
      ans+=a;
      a--;
    }
    else{
      ans+=b;
      b--;
    }
  }

  cout << ans << endl;
  

  return 0;
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}

ll const MOD=1e9+7;
int64_t modpow(int64_t x, int64_t n) {
  
  x = x%MOD;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
      return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int N;
  ll ans = 0, lcm=1;
  ll const mod =1e9+7;
  cin >> N;
  vector<ll> A(N);
  vector<ll> prime(1000000,0);

  // ######;
  rep(i,N) {
    cin >> A[i];
    for (auto t:prime_factorize(A[i])) {
      chmax(prime[t.first],t.second);
    }
  }
  rep2(i,2,1000000) {
    if (prime[i]) lcm*=modpow(i,prime[i]);
    lcm%=mod;
  }
  rep(i,N){
    ans += lcm*modinv(A[i])%mod;
    ans%=mod;
  }
  if (ans<0) ans+=mod;
  cout << ans << endl;
}

Measured memory_bytes: 8192
def main():
  p = 2019
  L, R = list(map(int, input().split()))
  
  if (R - L) >= p:
    ans = 0
    print(ans)
    
  else:
    L, R = L % p, R % p
    ans = 2019 ** 2
    for i in range(L, R + 1):
      for j in range(i+1, R+1):
        tmp = (i * j) % p
        if tmp < ans:
          ans = tmp
    print(ans)
    
main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int doit(int x)
{
printf("%d\n",x);
cout.flush();
string s;cin>>s;
if (s[0]=='V') exit(0);
return (s[0]=='F')+1;
}
int main()
{
scanf("%d",&n);
a[0]=doit(0);
int l=0,r=n-1;
for (;r-l>2;)
  {  
  int mid=l+r>>1;
  mid+=mid%2!=l%2;
  a[mid]=doit(mid);
  a[mid]!=a[l]?r=mid:l=mid;
  }
doit(l),doit(l+1),doit(l+2);
}

Measured memory_bytes: 852
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 5100000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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



ll t, a, n, x[100005], y[100005];
Pll num[100005];

int main() {

	cin >> n;
	rep(i, n) {
		cin >> x[i] >> y[i];
		num[i] = dmp(x[i] + y[i], i);
	}

	sort(num, num + n);
	reverse(num, num + n);

	rep(i, n) {
		if (i % 2 == 0)t += x[num[i].second];
		else a += y[num[i].second];
	}

	cout << t - a << endl;

	return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
using namespace std;
string days[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int zeller(int yeah,int month,int day)
{
  if(month <= 2)
    yeah--,month += 12;
  return (yeah + yeah/4 - yeah/100 + yeah/400 + (13 * month + 8) / 5 + day) % 7;
}

int main()
{
  int m,d;
  while(1)
    {
      scanf("%d %d",&m,&d);
      if(m+d == 0)break;
      int r = zeller(2004,m,d);
      cout << days[r] << endl;      
    }
  return 0;
}

Measured memory_bytes: 1208
A, B = (int(i) for i in input().split())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)

Measured memory_bytes: 38384
/**************** Geometrical Library ****************/

#include<cmath>
#include<vector>
#include<algorithm>

#define	EPS	1e-9

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(){}
	Circle(const Point &cc,double rr):c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

double dot(const Point &a,const Point &b){
	return a.x*b.x+a.y*b.y;
}

double cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}

double norm2(const Point &a){
	return dot(a,a);
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	for(int n;scanf("%d",&n),n;){
		static Point flag[401];
		flag[0]=Point(0,0);
		for(int i=1;i<=n;i++)	scanf("%lf%lf",&flag[i].x,&flag[i].y);

		int _1st=0,_2nd;
		int xmin=1<<30,ymin=1<<30;
		for(int i=1;i<=n;i++){
			if(flag[i].x<xmin || (flag[i].x==xmin && flag[i].y<ymin)){
				_2nd=i;
				xmin=(int)flag[i].x;
				ymin=(int)flag[i].y;
			}
		}

		static bool checked[401];
		for(int i=0;i<=n;i++)	checked[i]=false;
		checked[_1st]=checked[_2nd]=true;

		vector<int> ans;
		ans.pb(_1st);
		ans.pb(_2nd);
		for(int i=0;i<n-1;i++){
			int jopt;
			double minang=-1e9;
			for(int j=0;j<=n;j++){
				if(checked[j])	continue;
				Point v1=flag[_2nd]-flag[_1st],v2=flag[j]-flag[_2nd];
				double ang=dot(v1,v2)/(sqrt(norm2(v1))*sqrt(norm2(v2)));
				if(minang+EPS<ang
				||(abs(ang-minang)<EPS && norm2(v2)+EPS<norm2(flag[jopt]-flag[_2nd]))){
					jopt=j;
					minang=ang;
				}
			}
			ans.pb(jopt);
			checked[jopt]=true;
			_1st=_2nd;
			_2nd=jopt;
		}

		double len=0;
		for(int i=0;i<ans.size()-1;i++){
			len+=sqrt(norm2(flag[ans[i+1]]-flag[ans[i]]));
		}
		printf("%.1f\n",len);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 

void solve()
{
   ll n,w;
   cin>>n>>w;
   ll wei[n],val[n];
   f(i,0,n)
   {
      cin>>wei[i]>>val[i];
   }

   ll dp[n][w+1];
   f(i,0,w+1)
   {
      if(wei[0]>i)
      {dp[0][i] = 0;}
      else
      {
         dp[0][i] = val[0];
      }
      // cout<<dp[0][i]<<" ";
   }
   // cout<<"\n";
   f(i,1,n)
   {
      f(j,0,w+1)
      {
         if(wei[i]>j)
         {dp[i][j] = dp[i-1][j];}
         else
         {
            dp[i][j] = max(dp[i-1][j-wei[i]]+val[i],dp[i-1][j]);
         }
         // cout<<dp[i][j]<<" ";
      }
      // cout<<"\n";
   }
   cout<<dp[n-1][w];
}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 78336
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
using namespace std;

int main()
{
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;

	s[k - 1] -= ('A' - 'a');

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-08 00:42:09
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  int q; cin >> q;
  int rev = 0;
  for (int i = 0; i < q; ++i) {
    int op; cin >> op;
    if (op == 1) {
      rev ^= 1;
    } else {
      int f; char c; cin >> f >> c;
      if (f == 1) {
        if (rev & 1) {
          s += c;
        } else {
          s.insert(s.begin(), c);
        }
      } else {
        if (rev & 1) {
          s.insert(s.begin(), c);
        } else {
          s += c;
        }
      }
    }
  }

  if (rev & 1) reverse(all(s));

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

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

int jack(int x, int y){
  int k=0;
  rep(i,y){
    
    k=10*k+1;
  }
  x=k*x  ;
  return x;
}

int main() {
  int a,b;
  cin >> a >> b;
  if(a<b){
    int k=jack(a,b);
    cout << k << endl;
  }
  else{
    int h=jack(b,a);
    cout << h << endl;
  }
  

  return 0;

}



Measured memory_bytes: 3572
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int l=sc.nextInt();
		String ar[]=new String[n];
		for(int i=0;i<n;i++)
		ar[i]=sc.next();
		Arrays.sort(ar);
		StringBuilder sb=new StringBuilder();
		for(String s:ar)
		sb.append(s);
		System.out.println(sb.toString());
	}
}


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

/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/

int sc1() {int x; scanf("%d", &x); return x;}

long long sc2() {long long x; scanf("%lld", &x); return x;}



#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>


const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}

int n;
std::vector<int> adj[100005];
map<pair<int, int>, int>mp;
bool vis[100005];

void bfs(int s)
{
	vis[s] = 1;
	queue<pair<int, int>>qu;
	qu.push({s, 0});
	while (!qu.empty()) {
		int toe = qu.front().first;
		int col = qu.front().second;
		qu.pop();
		int ss = 1;
		for (int i = 0; i < (int)adj[toe].size(); i++) {
			if (!vis[adj[toe][i]]) {
				// cout<<toe<<" "<<adj[toe][i]<<endl;
				if (ss == col) ss++;
				int aa = min(toe, adj[toe][i]);
				int bb = max(toe, adj[toe][i]);
				mp[ {aa, bb}] = ss;
				// cout<<aa<<' '<<bb<<' '<<ss<<endl;
				vis[adj[toe][i]] = 1;
				qu.push({adj[toe][i], ss});
				ss++;
			}
		}
	}

	return;
}
int solve() {

	n = Int;
	std::vector<pair<int,int>> ed;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		ed.pb({min(u,v),max(u,v)});
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, (int)adj[i].size());
	}
	bfs(1);
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++){
		cout<<mp[{ed[i].first,ed[i].second}]<<endl;
	}


	return 0;
}




int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}

	return 0;




}




Measured memory_bytes: 13172
import math
from functools import reduce

tmp = input().split()
K = int(tmp[0])

SGCD = 0


def gcd(*numbers):
    return reduce(math.gcd, numbers)

# def gcd(a,b,c):
#     for ga in range(a+1)[1:]:
#         if a % ga == 0:
#             Ga = a/ga
#             if b % Ga == 0 and c % Ga == 0:
#                 return Ga
        
#         if ga > a/2:
#             return 1

for c in range(K+1)[1:]:
    for b in range(c+1)[1:]:
        for a in range(b+1)[1:]:
            if not a == b and not b == c:
                SGCD = SGCD + 6*gcd(a,b,c)
            elif a == b and not b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif not a == b and b == c:
                SGCD = SGCD + 3*gcd(a,b,c)
            elif a == b and b == c:
                SGCD = SGCD + gcd(a,b,c)

print(int(SGCD))

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

typedef vector<P> vp;
typedef greater<P> gp;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> B(M), C(M);
  REP(i, M) cin >> B[i] >> C[i];
  priority_queue<P, vp> que;
  ll ans = 0;
  REP(i, N) que.push(P(A[i], 1ll));
  REP(i, M) que.push(P(C[i], B[i]));
  int cnt = N;
  while (que.size()) {
    ll t = min(1ll * cnt, que.top().second);
    ans += t * que.top().first;
    cnt -= t;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

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

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

using namespace std;


int main()
{
    string s;
    cin >> s;
    for(int i=0;i<s.size();i+=2){
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<queue>
using namespace std;
int n,m,k,p;
long long ans;
priority_queue<int>q;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&k);
		q.push(k);
	}
	while(m--)
	{
		p=q.top();
		q.pop();
		q.push(p/2);
	}
	while(!q.empty())
	{
		ans+=q.top();
		q.pop(); 
	}
	printf("%lld",ans);
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

using gridcost = tuple<int, int, int>;

const int MAX_H = (int)(1e2 + 5);
const int MAX_W = (int)(1e2 + 5);

int h, w;
char s[MAX_H][MAX_W];

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

set<pair<int, int>> visited;

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; ++i) {
    scanf("%s", &(s[i]));
  }

  int white = 0;

  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    if (s[i][j] == '.') white += 1;
  }

  int length = -1;

  queue<gridcost> que;

  que.push(gridcost(0, 0, 0));
  // visited.insert(make_pair(0, 0));

  while (!que.empty()) {
    gridcost tmp = que.front();
    que.pop();

    int x = get<0>(tmp);
    int y = get<1>(tmp);
    int cost = get<2>(tmp);

    // printf("%d %d\n", x, y);

    if (visited.find(make_pair(x, y)) != visited.end()) continue;
    visited.insert(make_pair(x, y));

    if (x == (h - 1) && y == (w - 1)) {
      length = cost;
      break;
    }

    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if (s[nx][ny] == '#') continue;
      // if (visited.find(make_pair(nx, ny)) != visited.end()) continue;

      if (0 <= nx && nx < h && 0 <= ny && ny < w) {
        que.push(gridcost(nx, ny, cost + 1));
        // visited.insert(make_pair(nx, ny));
      }
    }
  }

  if (length == -1) {
    printf("%d\n", -1);
  }
  else {
    ans = white - (length + 1);
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
  int r, x, y, temp;

  while( scanf("%d %d", &x, &y) != EOF )
    {
      if(x<y)
	{
	  temp = x;
	  x = y;
	  y = temp;
	}
 
      while(y>0)
	{		
	  r = x % y;
	  x = y;
	  y = r;
	}
      printf("%d\n",x);
    }
  return(0);
}

Measured memory_bytes: 596
N = gets.to_i
S = N.times.map { gets.chomp }
M = gets.to_i
T = M.times.map { gets.chomp }

s_count = Hash.new { 0 }
t_count = Hash.new { 0 }

S.each do |s|
  s_count[s] += 1
end
T.each do |s|
  t_count[s] += 1
end

ans = 0
s_count.each do |s, c|
  point = c - t_count[s]
  ans = point if point > ans
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	a.assign(n,0);
	ll sum=0;
	map<ll,ll> m;
	for(ll i=0;i<n;i++) {
		cin>>a[i];
		m[a[i]]++;
		sum=sum+a[i];
	}
	ll q;
	cin>>q;
	ll x,y;
	while(q--){
		cin>>x>>y;
		if(m[x]){
			if(y>x) sum+=m[x]*(y-x);
			else sum=sum-m[x]*(x-y);
			ll temp=m[x];
			m.erase(x);
			m[y]+=temp;
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 8064
using System;
class Program
{
    static void Main(string[] args)
    {
        string ABHM = Console.ReadLine();
        string[] test = (ABHM.Split(" "));
        int     A = int.Parse(test[0]),
                B = int.Parse(test[1]);
        double  H = int.Parse(test[2]),
                M = int.Parse(test[3]);
        double C = 0.0, kaku = 0.0;
        kaku = Math.PI * 2 * (H / 12.0 + (M / 60.0) / 12.0 - M / 60.0);
        C = Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(kaku));
        Console.WriteLine(C);
    }
}


Measured memory_bytes: 18612
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9;
string s[50];
int h, w;
int memo[50][50][50][50];
int solve(int a, int b, int c, int d){
  if(memo[a][b][c][d]<INF) return memo[a][b][c][d];
  if(s[a][b]=='#' || s[c][d]=='#') return memo[a][b][c][d]=-1;
  if(a==c && b==d) return memo[a][b][c][d]=0;
  int ans=-1;
  if(s[a][b]>='a' && s[a][b]<='z' && s[c][d]>='A' && s[c][d]<='Z' && (s[a][b]-'a')==(s[c][d]-'A')){
    if((a+1==c && b==d) || (a==c && b+1==d)){
      return memo[a][b][c][d]=1;
    }
    int r=-1;
    if(a+1<=c-1) r=max(r, solve(a+1, b, c-1, d));
    if(a+1<=c && b<=d-1) r=max(r, solve(a+1, b, c, d-1));
    if(a<=c-1 && b+1<=d) r=max(r, solve(a, b+1, c-1, d));
    if(b+1<=d-1) r=max(r, solve(a, b+1, c, d-1));
    if(r>=0) ans=max(ans, r+1);
  }
  if(s[a][b]=='.'){
    if(a+1<=c) ans=max(ans, solve(a+1, b, c, d));
    if(b+1<=d) ans=max(ans, solve(a, b+1, c, d));
    return memo[a][b][c][d]=ans;
  }
  if(s[c][d]=='.'){
    if(a<=c-1) ans=max(ans, solve(a, b, c-1, d));
    if(b<=d-1) ans=max(ans, solve(a, b, c, d-1));
    return memo[a][b][c][d]=ans;
  }
  for(int i=a; i<=c; i++){
    for(int j=b; j<=d; j++){
      if(i==c && j==d) continue;
      int r1=solve(a, b, i, j);
      if(r1==-1) continue;
      int r2=-1;
      if(i+1<=c) r2=max(r2, solve(i+1, j, c, d));
      if(j+1<=d) r2=max(r2, solve(i, j+1, c, d));
      if(r2>=0) ans=max(ans, r1+r2);
    }
  }
  return memo[a][b][c][d]=ans;
}
int main()
{
	while(1){
      int h, w;
      cin>>h>>w;
      if(h==0 && w==0) return 0;
      for(int i=0; i<h; i++) cin>>s[i];
      for(int a=0; a<h; a++){
        for(int b=0; b<w; b++){
          for(int c=a; c<h; c++){
            for(int d=b; d<w; d++){
              memo[a][b][c][d]=INF;
            }
          }
        }
      }
      cout<<solve(0, 0, h-1, w-1)<<endl;
    }
	return 0;
}


Measured memory_bytes: 23272