akhauriyash/Code-Regression huggingface dataset:
(let* ((n (read))
    (d (make-array n))
    (ans 0))
    (dotimes (i n)
        (setf (aref d i) (read))
    )

    (loop for i to (- n 2) do
        (loop for j from (+ i 1) to (- n 1)do
            (incf ans (* (aref d i) (aref d j)))
        )
    )

    (princ ans)
)

Measured memory_bytes: 24532
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	int n;
	int x,y,h,w;
	
	while(cin>>n,n!=0){
		long long sum=0;
		for(int i=0;i<n;i++){
		cin>>x>>y>>h>>w;
			int s=0;
			long long big = x+y+h;
			if(big<=60)
				s=600;
			else if(big<=80)
				s=800;
			else if(big<=100)
				s=1000;
			else if(big<=120)
				s=1200;
			else if(big<=140)
				s=1400;
			else if(big<=160)
				s=1600;
			else
				s=0;
			if(s!=0){
			if(w<=2)
			s=max(s,600);
			else if(w<=5)
			s=max(s,800);
			else if(w<=10)
			s=max(s,1000);
			else if(w<=15)
			s=max(s,1200);
			else if(w<=20)
			s=max(s,1400);
			else if(w<=25)
			s=max(s,1600);
			else
			s=0;
			}
			sum+=s;
		}
		
		cout<<sum<<endl;
		
	}
	
	
	
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  vector<int> S(3);
  int M=0;
  for(int i=0; i<3; i++){
    cin >> S[i];
    M = max(M,S[i]);
  }
  int sum=0;
  for(int i=0; i<3; i++){
    sum += M-S[i];
  }
  int ans = sum/2;
  if(sum%2 == 1){
    ans += 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	
	int d,m,n,t[101],h[101];
	while(1){
		int st=0,sh=0,mint=101;
		cin>>n>>m;
		if(n==0&&m==0)return 0;
		for(int i=0;i<n;i++)cin>>t[i];
		for(int i=0;i<m;i++)cin>>h[i];
		for(int i=0;i<n;i++)st+=t[i];
		for(int i=0;i<m;i++)sh+=h[i];
		d=st-sh;
		if(d%2!=0){cout<<-1<<endl;continue;}
		for(int i=0;i<n;i++)for(int j=0;j<m;j++){
			if(t[i]-h[j]==d/2&&t[i]<mint)mint=t[i];
		}
		if(mint<101)cout<<mint<<" "<<mint-d/2<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct node{
	struct node *left;
	struct node *right;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){//kに一致するノードを探す
	if (u == NIL){return NIL;}//なかた
	if (u->key == k){ return u; }//あた
	else if (u->key > k){
		return treeSearch(u->left, k);
	}
	else{
		return treeSearch(u->right, k);
	}
}

void treeDelete(Node z){
	Node tmp;

	if (z->left == NIL && z->right == NIL){//子なし
		if (z->parent->left == z){//zが親の左側に属していたら
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		free(z);
	}
	else if (z->left != NIL && z->right != NIL){//子2人
		tmp = z->right;//右側から最少を探す
		while (tmp->left != NIL){
			tmp = tmp->left;
		}
		z->key = tmp->key;
		treeDelete(tmp);		
	}
	else{//子1人
		if (z->left!=NIL){//左に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->left;
				z->left->parent = z->parent;
			}
			else{//zが親の右側にいたら
				z->parent->right = z->left;
				z->left->parent = z->parent;
			}
		}
		else{//右に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->right;
				z->right->parent = z->parent;
				free(z);
			}
			else{//zが親の右側にいたら
				z->parent->right = z->right;
				z->right->parent = z->parent;
			}
		}
	}
}

Node sss(int k, Node x){
	if (x == NIL){ return x; }//root
	if (k < x->key){
		if (x->left != NIL){
			return sss(k, x->left);
		}
		else{
			return x;
		}
	}
	else{
		if (x->right != NIL){
			return sss(k, x->right);
		}
		else{
			return x;
		}
	}
}

void insert(int k){
	Node y = sss(k,root);//入れるべき場所の親探し
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	z->parent = y;

	if (y == NIL){ root=z; }
	else if (y->key < k){//kが親キーより大きい
		y->right = z;
	}
	else{
		y->left = z;
	}
}

void inorder(Node u){
	if (u->left != NIL)
		inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL)
		inorder(u->right);	
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL)
		preorder(u->left);
	if (u->right != NIL)
		preorder(u->right);
}

int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}

Measured memory_bytes: 19364
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << c + b - d << " " << d + c - a << " " << a + b - d << " " << b + c - a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> d;
    rep(i, k){ int tmp; cin >> tmp; d.push_back(tmp);}

    int n_max = 1;
    for (int i = 0; i < to_string(n).size(); i++)
    {
        n_max *= 10;
    }
    n_max *= 10;
    //cout << n_max << endl;

    for (int i = n; i < n_max; i++)
    {
        string s = to_string(i);
        bool isvalid = true;
        for (int j = 0; j < s.size(); j++)
        {
            bool isok = true;
            for (auto dnum: d)
            {
                if (s[j]-'0' == dnum){
                    isok = false;
                }
            }
            if (!isok) {
                isvalid = false;
            }                        
        }
        if (isvalid) {cout <<i << endl; return 0;} 
    }
    
}



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b, c, n, x, y;
  cin >> a >> b >> c;
  // cin >> a >> b >> c;
  if (c <= b && c >= a)
    Yes();
  else
    No();
  return 0;
}

Measured memory_bytes: 3588
N,K = map(int,input().split())
S = input()

#評価
res = 0
for i in range(N):
    if S[i] == "L":
        if i == 0:
            continue
        if S[i-1] == "L":
            res += 1
    if S[i] == "R":
        if i == N-1:
            continue
        if S[i+1] == "R":
            res += 1
#K回の操作
for _ in range(K):
    if res < N-2:
        res += 2
    elif res == N-2:
        res += 1
    else:
        break
print(res)

Measured memory_bytes: 3316
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e18;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const double pi=acos(-1);


ll a[203040];
ll b[203040];
int main(){
    TB
    int n;
    cin>>n;
    fd(n){
        cin>>a[i];
        b[a[i]]++;
    }//deg(b[1])
    ll ans=0;
    fd(n+1){
        //deg(i)
        if(b[i]) ans+=((b[i]*(b[i]-1)/2));
        //deg(ans)
    }
    ll tmp;
    fd(n){
        tmp=ans;
        tmp-=((b[a[i]]*(b[a[i]]-1)/2));
        b[a[i]]--;
        tmp+=((b[a[i]]*(b[a[i]]-1)/2));
        b[a[i]]++;
        cout<<tmp<<'\n';
    }
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

ll N;

int main(){
    cin >> N;
    double SQ = sqrt(N);
    ll ans = 0, n = N, i = 1;
    while(n > SQ){
        if(N / n == N / (n - 1) && N % n == 0) ans += n - 1;
        i++;
        n = N / i;
    }
    Print(ans);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
long long A[maxn], B[maxn];
int M(){
    int n;
    if(!(cin >> n)) return 0;
    map<int, int> qtd;
    for(int e = 0; e < n; e++){
        int x; cin >> x;
        qtd[x]++;
    }
    int m; cin >> m;
    bool ok = true;
    for(int e = 0; e < m; e++){
        int x; cin >> x;
        if(qtd[x] == 0) ok = false;
        else qtd[x]--;
    }
    if(ok)printf("YES\n");
    else printf("NO\n");
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 9600
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0565

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_A&lang=ja

process.stdin.resume();
process.stdin.setEncoding('utf8');


process.stdin.on('data', function (chunk) {
    let n = chunk.toString() // 文字列化する
        .split("\n") // \nで分割
        .map(x => Number(x))
        .filter(x => x !== 0);
    const a = n.slice(0, 3);
    const b = n.slice(3, 5);
    const data1 = Math.min.apply(null, a);  // → 9
    const data2 = Math.min.apply(null, b);  // → 1

    const ans = data1 + data2 - 50
    console.log(ans);

});


Measured memory_bytes: 15560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}


const int mod = 1000000007;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);


int main(){
    ll n;
    cin >> n;
    ll ans=0;
    rep(i,n){
        ll t;cin >> t;
        ans+=t-1;
    }
    cout << ans <<endl;
}

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

int main() {
    char ch;
    char alphabet[26];
    for (int i = 0; i < 26; i++) {
        alphabet[i] = 0;
    }

    while ( cin >> ch ) {
        if (ch >= 'A' && ch <= 'Z') {
            ch += 32;
        }

        alphabet[ch-'a'] += 1;
    }

    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a'+i, alphabet[i]);
    }

    return 0;
}


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

// templates -------------------------------------

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

// --------------------------------------

int a, p;

void input()
{
  cin >> a >> p;
}

void solve()
{
  cout << (a*3 + p) / 2;
}

int main()
{
  input();
  solve();
  return 0;
}

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

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int n;
int m;

bool bfs (Vec<Vec<PII> > table, int i) {
    Vec<int> dist(n, INF);
    dist[0] = 0;
    stack<PII> st;
    int len = table[0].size();
    for (int loop = 0; loop < len; loop++) {
        if (table[0][loop].second != i) {
            st.push(make_pair(1, table[0][loop].first));
            dist[table[0][loop].first] = 1;
        }
    }

    while (!st.empty()) {
        int kyori = st.top().first;
        int point = st.top().second;
        len = table[point].size();
        st.pop();
        for (int loop = 0; loop < len; loop++) {
            if (dist[table[point][loop].first] > kyori + 1 && table[point][loop].second != i) {
                dist[table[point][loop].first] = kyori + 1;
                st.push(make_pair(kyori + 1, table[point][loop].first));
            }
        }
    }
    bool ans = true;
    for (int i = 0; i < n; i++) {
        if (dist[i] == INF) {
            ans = false;
        }
    }
    return ans;
}

int main(void) {
    cin >> n >> m;
    Vec<Vec<PII> > table(n);
    int a;
    int b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        a--; b--;
        table[a].push_back(make_pair(b, i));
        table[b].push_back(make_pair(a, i));
    }

    int count = 0;
    for (int i = 0; i < m; i++) {
        if (bfs(table, i) == false) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}



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

ll n,a[300005],zl[300005],zd[300005],p[300005],tr,rez=-10e16;
priority_queue<ll> l,d;

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

    cin>>n;
    for(ll i=1;i<=3*n;i++)
    {
        cin>>a[i];
        p[i]=p[i-1]+a[i];
    }

    for(ll i=1;i<=n;i++)
        l.push(-a[i]);
    tr=p[n];
    zl[n]=tr;
    for(ll i=n+1;i<=2*n;i++)
    {
        ll x=-l.top();
        tr-=x;
        l.pop();
        if(a[i]>x)
        {
            tr+=a[i];
            l.push(-a[i]);
        }
        else
        {
            tr+=x;
            l.push(-x);
        }
        zl[i]=tr;
    }
    for(ll i=3*n;i>2*n;i--)
        d.push(a[i]);
    tr=p[3*n]-p[2*n];
    zd[2*n+1]=tr;
    for(ll i=2*n;i>=n;i--)
    {
        ll x=d.top();
        tr-=x;
        d.pop();
        if(a[i]<x)
        {
            tr+=a[i];
            d.push(a[i]);
        }
        else
        {
            tr+=x;
            d.push(x);
        }
        zd[i]=tr;
    }
    for(ll i=n;i<=2*n;i++)
    {
        ll x=zl[i]-zd[i+1];
        //cout<<zd[i+1]<<endl;
        if(x>rez)
            rez=x;
    }

    cout<<rez<<endl;

    return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

vector<pi> a;
int A;

int dp[200];
int dfs(int now)
{
    if(dp[now]>=0) return dp[now];

    int ret=1;
    rep(i,A)
    {
        if(a[i].fi<a[now].fi && a[i].se<a[now].se)
        {
            ret=max(ret,1+dfs(i));
        }
    }

    return dp[now]=ret;
}

int main()
{
    int n,m;
    while(cin >>n,n)
    {
        a.clear();

        rep(i,n)
        {
            int h,r;
            scanf(" %d %d", &h, &r);
            a.pb(pi(h,r));
        }
        cin >>m;
        rep(i,m)
        {
            int h,r;
            scanf(" %d %d", &h, &r);
            a.pb(pi(h,r));
        }

        //n+m
        A=a.size();

        int ans=1;
        memset(dp,-1,sizeof(dp));
        rep(i,A) ans=max(ans,dfs(i));

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
typedef tuple<int,int,string> T;
int main() {
	int N,Q;
	while(cin>>N>>Q,N) {
		vector<T> v;
		for(int i=0;i<N;i++) {
			string name;
			int ey,wy;
			cin>>name>>ey>>wy;
			v.push_back(make_tuple(wy-ey+1,wy,name));
		}
		sort(v.begin(),v.end());
		for(int i=0;i<Q;i++) {
			int y;
			cin>>y;
			int idx=-1;
			for(int j=0;j<v.size();j++) {
				if(get<0>(v[j])>y) break;
				if(get<0>(v[j])<=y&&y<=get<1>(v[j])) {
					idx=j;
					break;
				}
			}
			if(idx==-1) {
				cout<<"Unknown"<<endl;
			}else {
				cout<<get<2>(v[idx])<<" "<<(y-get<0>(v[idx])+1)<<endl;
			}
		}
	}
}

Measured memory_bytes: 3048
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int length = 0;

		Integer l[] = new Integer[N];

		for (int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}

		Arrays.sort(l, Collections.reverseOrder());

		for (int i = 0; i < K; i++) {
			length += l[i];
		}
		System.out.println(length);
	}
}

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

using namespace std;

class DisjointSet {
	public:
		vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
      rank.resize(size, 0);
      p.resize(size, 0);
      for (int i = 0; i < size; ++i)
      {
        makeSet(i);
      }
    }

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }

    void link(int x, int y){
      if (rank[x] > rank[y])
      {
        p[y] = x;
      }else{
        p[x] = y;
        if (rank[x] == rank[y])
        {
          rank[y]++;
        }
      }
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    int findSet(int x){
      if(p[x] != x){
        p[x] = findSet(p[x]);
      }
      return p[x];
    }
};

int main(){
  int n, q;
  int com, x, y;
  cin >> n >> q;
  DisjointSet ds = DisjointSet(n);

  for (int i = 0; i < q; ++i)
  {
    cin >> com >> x >> y;
    if(com == 0){
      ds.unite(x, y);
    } else if( com == 1){
      if(ds.same(x, y)){
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }

}

Measured memory_bytes: 1280
from sys import setrecursionlimit, stdin
setrecursionlimit(10**6)
input = stdin.buffer.readline

def main():
    n, m = map(int, input().split())

    edges = [[] for _ in range(n)]
    for _ in range(m):
        x, y = map(int, input().split())
        edges[x-1].append(y-1)

    dp = [-1] * n
    def dfs(node):
        if len(edges[node]) == 0:
            dp[node] = 0
        else:
            max_len = 0
            for new_node in edges[node]:
                if dp[new_node] == -1:
                    dfs(new_node)
                if max_len < dp[new_node]:
                    max_len = dp[new_node]
            dp[node] = max_len + 1

    for node in range(n):
        if dp[node] == -1:
            dfs(node)

    print(max(dp))

main()

Measured memory_bytes: 117260
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

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

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 62

type Point struct {
	x, y int
}

type ByX []Point

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	X := make([]int, N)
	Y := make([]int, N)
	P := make([]Point, N)
	for i := 0; i < N; i++ {
		x, y := sc.nextInt(), sc.nextInt()
		X[i] = x
		Y[i] = y
		P[i] = Point{x, y}
	}
	sort.Ints(X)
	sort.Ints(Y)
	sort.Sort(ByX(P))
	ans := INF
	for y1 := 0; y1 < N; y1++ {
		for y2 := y1; y2 < N; y2++ {
			for x1 := 0; x1 < N; x1++ {
				count := 0
				idx := 0
				for x2 := x1; x2 < N; x2++ {
					for idx < len(P) && P[idx].x <= X[x2] {
						p := P[idx]
						if X[x1] <= p.x && Y[y1] <= p.y && p.y <= Y[y2] {
							count++
						}
						idx++
					}
					if count == K {
						x := max(1, X[x2]-X[x1])
						y := max(1, Y[y2]-Y[y1])
						//fmt.Fprintln(wtr, "equal K", X[x2], X[x1], Y[y2], Y[y1], x*y)
						if x*y < ans {
							ans = x * y
						}
						break
					}
				}
			}
		}
	}

	fmt.Fprintln(wtr, ans)
}


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

int main() {
  string S;
  cin >> S;

  int N = S.size();

  int diff_1 = 0;
  int diff_2 = 0;

  rep(i, N) {
    if (i % 2 == 0) {
      diff_1 += (S[i] - '0' == 0);
      diff_2 += (S[i] - '0' == 1);
    } else {
      diff_1 += (S[i] - '0' == 1);
      diff_2 += (S[i] - '0' == 0);
    }
  }

  cout << min(diff_1, diff_2) << endl;
}

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

int ds[200100], isFull[200100];

int get(int x)
{
  return ds[x] == x ? x : ds[x] = get(ds[x]);
}

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

  int n, h, w, r, c, a;
  vector<pair<int, int>> edges[100100];
  cin >> n >> h >> w;
  while (n--)
  {
    cin >> r >> c >> a;
    edges[a].push_back({r, c + h});
  }

  for (int i = 1; i <= w + h; i++)
    ds[i] = i;

  long long ans = 0;
  for (int a = 100000; a; a--)
    for (auto u : edges[a])
    {
      int x = get(u.first), y = get(u.second);
      if (x != y)
      {
        if (isFull[x] && isFull[y])
          continue;
        ds[x] = y;
        isFull[y] |= isFull[x];
        ans += a;
      }
      else if (!isFull[x])
      {
        ans += a;
        isFull[x] = 1;
      }
    }

  cout << ans << endl;
}


Measured memory_bytes: 6144
// ABC 113 B

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int main() {
  int n, t, a;
  cin >> n;
  cin >> t >> a;

  int ans = -1;
  float ref = INF;
  rep (i, n) {
    int h;
    cin >> h;
    float temp = abs(float(t - h * 0.006) - a);
    if (chmin(ref, temp)) {
      ans = i+1;
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> tii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef map<ll,ll> mi;
typedef map<pii,ll> mii;


#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define rep(i,a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define PI 3.141592653589793238

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    IOS

    int n,k;
    cin>>n>>k;
    int a[n+1]={0};
    bool ans=false;
    for(int i=0;i<k;i++)
    {
    	int x;
    	cin>>x;
    	if(x==n)
    	{
    		cout<<0<<endl;
    		ans=true;
    		break;
    	}
    	for(int j=0;j<x;j++)
    	{
    		int y;
    		cin>>y;
    		a[y]++;
    	}
    }

    int count=0;
    if(!ans)
    {
    	for(int i=1;i<n+1;i++)
    	{
    		if(a[i]==0)
    			count++;
    	}
    	cout<<count<<endl;
    }



    return 0;
}

Measured memory_bytes: 3652
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.math.BigInteger.*;
public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void debug(Object...os){
		System.err.println(deepToString(os));
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			if(n==0)return;
			p=0;
			Panel root = new Panel(sc.next());
			for(int i=0;i<n;i++){
				if(!root.go(sc.nextInt(), sc.nextInt())){
					System.out.println("OUT OF MAIN PANEL 1");
				}
			}
		}
	}
	int p;
	class Panel{
		String name;
		int x1,y1,x2,y2;
		ArrayList<Panel> cs = new ArrayList<Panel>();
		Panel(String t){
			String s = t.substring(p);
			int np = s.indexOf(">");
			name = s.substring(1, np);
//			p = np;
//			p++;
			int q = s.indexOf("<", np);
			String[] ns = s.substring(np+1, q).split(",");
			x1 = Integer.valueOf(ns[0]);
			y1 = Integer.valueOf(ns[1]);
			x2 = Integer.valueOf(ns[2]);
			y2 = Integer.valueOf(ns[3]);
			p += q;
			while(!t.substring(p).startsWith("</")){
				cs.add(new Panel(t));
			}
			p = t.indexOf(">",p) + 1;
		}
		boolean go(int x,int y){
			if(x1<=x&&x<=x2&&y1<=y&&y<=y2){
				boolean me = true;
				for(Panel p:cs){
					if(p.go(x, y))me=false;
				}
				if(me){
					System.out.println(name + " "+cs.size());
				}
				return true;
			}
			else return false;
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

typedef struct tag_cell
{
    char mark;
    int number;
} cell;

void BubbleSort(cell data[], int N);
void SelectionSort(cell data[], int N);

int main(void)
{
    int a, N;
    char c;
    string flag = "Stable";

    cin >> N;

    cell data_b[N];
    cell data_s[N];
    for(int i = 0; i < N; i++)
    {
        cin >> data_b[i].mark >> data_b[i].number;
        data_s[i].number = data_b[i].number;
        data_s[i].mark = data_b[i].mark;
    }

    BubbleSort(data_b, N);
    for(int i = 0; i < N; i++)
    {
        if(i) cout << " ";
        cout << data_b[i].mark << data_b[i].number;
    }
    cout << "\n" << "Stable" << "\n";

    SelectionSort(data_s, N);
    for(int i = 0; i < N; i++)
    {
        if(i) cout << " ";
        cout << data_s[i].mark << data_s[i].number;
        if(!(data_s[i].mark == data_b[i].mark && data_s[i].number == data_b[i].number))
        {
            flag = "Not stable";
        }
    }
    cout << endl;
    cout << flag << endl;    
    
    




    

    return 0;
}

void BubbleSort(cell data[], int N)
{
    int flag = 1;
    int i = 0;
    while(flag)
    {
        flag = 0;
        for(int j = N - 1; j >= i + 1; j--)
        {
            if(data[j].number < data[j - 1].number)
            {
                swap(data[j].number, data[j - 1].number);
                swap(data[j].mark, data[j - 1].mark);
                flag = 1;
            }
        }
        i++;
    }
}

void SelectionSort(cell data[], int N)
{
    for(int i = 0; i < N - 1; i++)
    {
        int minj = i;
        for(int j = i; j < N; j++)
        {
            if(data[j].number < data[minj].number)
            {
                minj = j;
            }
        }
        if(i != minj)
        {
            swap(data[i].number, data[minj].number);
            swap(data[i].mark, data[minj].mark);
        }
        
    }
}


Measured memory_bytes: 3208
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[510];
    rep(i,0,N) cin >> x[i];
    bool ok = true;
    vector<lpair> lp;
    rep(i,0,N){
        lp.push_back({x[i], i+1});
    }
    sort(lp.begin(), lp.end());
    ll res[500*500+10] = {};
    rep(i,0,N){
        ll num = lp[i].second;
        ll ps = lp[i].first;
        ll cnt = 0;
        rep(j,0,ps-1){
            if(res[j] == 0) cnt++;
        }
        if(cnt < num-1){
            ok = false;
            break;
        }
        ll n = num-1;
        ll idx = 0;
        while(n > 0){
            if(res[idx] == 0){
                res[idx] = num;
                idx++;
                n--;
            }else{
                idx++;
            }
        }
        res[ps-1] = num;
    }
    rrep(i,N-1,0){
        ll num = lp[i].second;
        ll ps = lp[i].first;
        ll cnt = 0;
        rrep(j,N*N-1,ps){
            if(res[j] == 0) cnt++;
        }
        if(cnt < N - num){
            ok = false;
            break;
        }
        ll n = N - num;
        ll idx = N*N-1;
        while(n > 0){
            if(res[idx] == 0){
                res[idx] = num;
                idx--;
                n--;
            }else{
                idx--;
            }
        }
        // res[ps-1] = num;
    }
    if(not ok){
        print("No");
        return 0;
    }
    vector<ll> amari;
    rep(i,0,N){
        ll num = lp[i].second;
        rep(j,0,N-num){
            amari.push_back(num);
        }
    }
    ll idx = 0;
    rep(i,0, N*N){
        if(res[i] == 0){
            res[i] = amari[idx];
            idx++;
        }
    }
    if(ok){
        print("Yes");
        printa(res, N*N);
        ll cnt[510] = {};
        ll prv = 0;
        rep(i,0,N){
            rep(j,prv,lp[i].first){
                cnt[res[j]]++;
            }
            prv = lp[i].first;
            if(cnt[lp[i].second] != lp[i].second || res[lp[i].first-1] != lp[i].second){
                exit(1);
            }
        }
    }else{
        print("No");
    }

    

}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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 long long INF = 1LL << 60;
const int inf = 1001001001;
const int mod = 1000000007;
using pint=pair<ll,ll>;
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
   }
   void init(ll sz_) {
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x) { // 根の検索
      while (par[x] != x) {
           x = par[x] = par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y) {
       x = root(x);
       y = root(y);
       if (x == y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x] < siz[y]) swap(x, y);
       siz[x] += siz[y];
       par[y] = x;
       return true;
  }
 
  bool same(ll x, ll y) { // 連結判定
       return root(x) == root(y);
  }
 
  ll size(ll x) { // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll 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が半分になる
}
 
ll com(ll n, ll k) {
   ll x = 1;
   for(int i=n-k+1; i<=n; i++) {
      x = x*i%mod;
   }
 
   ll y = 1;
   for(int i=1; i<=k; i++) {
       y = y*i%mod;
   }
   y = modpow(y, mod-2);
 
   return x*y%mod;
}
 
int main(){

    ll n,k;
    cin >> n >> k;
    ll a=(n/k);
    ll b=((n+k/2)/k);

    if(k%2!=0){
        cout << a*a*a << endl;
    }
    else{
        cout << a*a*a+b*b*b << endl;
    }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef pair<int,int> P;
typedef long long ll;

int X,Y;
vector<P> vs;
int main(){
	cin>>X>>Y;
	rep(i,X){
		int x;
		cin>>x;
		vs.pb(P(x,i));
	}
	rep(i,Y){
		int y;
		cin>>y;
		vs.pb(P(y,i+X));
	}
	sort(all(vs));
	int nowX=Y+1,nowY=X+1;
	ll ans=0;
	for(P p:vs){
		ll c=p.fs;
		int id=p.sc;
		bool isx=1;
		if(id>=X){
			id-=X;
			isx=0;
		}
		if(isx){
			ans+=c*nowX;
			nowY--;
		}else{
			ans+=c*nowY;
			nowX--;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int l,r,a,ans;
    in(l,r);
    a=r-l+1;
    if(a>=2019){
        out(0);
    }else{
        ans=2019*2019;
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++){
                ans=min(ans,(i%2019)*(j%2019)%2019);
            }
        }
        out(ans);
    }
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,long long>;
using ll = long long;
const auto INF =(ll)1e9;
int main(){
  int a, b;
  cin >> a >> b;
  auto s = b-a;

  auto ans =0;
  for (int i = 1; i < s; i++)
  {
    ans += i;
  }
  
  cout << ans -a;

  
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	a := map[int]int{}
	ans := 0
	prev := sc.NextInt()
	for i := 1; i < n; i++ {
		curr := sc.NextInt()
		if curr-1 == prev {
			a[curr-1] = 1
		}
		prev = curr

	}
	//	fmt.Printf("%+v\n", a) // output for debug

	for i := 0; i < n; i++ {
		ans += sc.NextInt()
	}

	//	fmt.Printf("%+v\n", ans) // output for debug

	for i := 1; i < n; i++ {
		tmp := sc.NextInt()
		if _, ok := a[i]; ok {
			ans += tmp
		}
	}
	fmt.Printf("%+v\n", ans) // output for debug

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	x := sc.Text()
	n, _ := strconv.Atoi(x)
	fmt.Println(n * (n + 1) / 2)
}


Measured memory_bytes: 640
import string
n = int(input())
ans = {'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,
      'm':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,
      'y':0,'z':0}
for i in range(n):
    if i == 0:
        st = input()
        for j in st:
            ans[j] += 1
    else:
        tmp = {'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,
      'm':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,
      'y':0,'z':0}
        st = input()
        for j in st:
            tmp[j] += 1
            
        for j in tmp:
            ans[j] = min(ans[j],tmp[j])

anser = ''
for d in string.ascii_lowercase:
    for j in range(ans[d]):
        anser += d
print(anser)

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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 main() {
    int n, x, t;
    cin >> n >> x >> t;
    int cnt = n/x;
    int rest = n%x;
    if(rest == 0) cout << cnt*t << endl;
    else cout << (cnt+1)*t << endl;
}

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

int main()
{
	ll N, K;

	cin >> N >> K;

	ll t = N % K;
	cout << min(t, K - t) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N;
string S[1000];
int level[1000];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> S[i];

    REP(i, 0, N) {
      level[i] = 0;
      while(S[i][level[i]] == '.') level[i]++;
    }

    REP(i, 1, N) {
      S[i][level[i] - 1] = '+';
      int k = N;
      REP(j, i + 1, N) {
        if(level[j] < level[i]) break;
        if(level[j] == level[i]) {
          k = j;
          break;
        }
      }
      if(k == N) continue;
      REP(j, i + 1, k) S[j][level[i] - 1] = '|';
    }

    REP(i, 0, N) {
      REP(j, 0, level[i]) {
        if(S[i][j] == '.') S[i][j] = ' ';
      }
    }

    REP(i, 0, N) cout << S[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3772