akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		// 1行目数字、2行目文字
		String s = br.readLine();
		long lCount = Integer.parseInt(br.readLine());

		int iLen = s.length();

		StringBuilder sb = new StringBuilder();
		sb.append(s);
					//System.out.println(sb);
		
		char c;
		int iCharNo;
		int i;
		// 先頭から順に各文字を、'a'に変える
		for(i = 0; i<iLen; i++){
			c = sb.charAt(i);
			// a以外
			if (c > 'a') {
				iCharNo = Character.getNumericValue(c);
				//aに変える回数が残ってるなら、変える
				if(lCount >= (36 - iCharNo)){
					lCount = lCount - (36 - iCharNo);
					sb.setCharAt(i, 'a');
				}
			}
		}
			//	System.out.println("sb=[" + sb + "]");
			//	System.out.println("lCount=[" + lCount + "]");
		
		
		//26以上残っているなら、26を一単位として消す
		int iCount = (int)(lCount % 26);
				//System.out.println("iCount=[" + iCount + "]");
		
		// 残った回数を使い切る
		if (iCount > 0) {
			int n = iLen - 1;
			c = sb.charAt(n);
						//System.out.println("c=[" + c + "]");
			
			int k = Character.getNumericValue(c); // 10-35
			k = k - 10;  // 0-25
						//System.out.println("k=[" + k + "]");
			int j = (k + iCount);
						//System.out.println("j=[" + j + "]");
			j = (j % 26); // 0-25
			j = j + 10;
			char a = Character.forDigit(j, 36);
						//System.out.println("a=[" + a + "]");
			
			sb.setCharAt(n, a);
		}
		
		System.out.println(sb);

    }
}




Measured memory_bytes: 11476
N=input()
A=map(int, raw_input().split())
A.sort()


cur = 0
brk=0
for i in xrange(len(A)):
    v=A[i]
    if i !=0 and v > cur*2:
#        print "brk",i
        brk=i
    cur+=v

print len(A) - brk 
    


Measured memory_bytes: 11320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll n;
  cin >> n;
  vec a(n+1);
  for(ll i=1;i<=n;i++) {
    ll tmp;
    cin >> tmp;
    a[tmp]=i;
  }
  set<ll> pre;
  pre.insert(0);
  pre.insert(n+1);
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    auto it=pre.upper_bound(a[i]);
    ans+=i*(*it-a[i])*(a[i]-*(--it));
    pre.insert(a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

//#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

#include<iostream>
#include<vector>
#include<queue>

using namespace std;

typedef struct Edge {
	int Cost;
	int To;
	Edge(int t,int c){
		Cost = c;
		To = t;
	}
	bool const operator<(Edge e) const {
		return Cost < e.Cost;
	}
}Edge;


class Dijkstra
{
public:
	Dijkstra(int n,bool dir);
	int I;
	int V;
	int E;
	vector<int> Cost;
	void AddPath(int f, int t, int c);
	bool PathExist(int t);
	void Run(int f);
private:
	bool isNonDir = true;
	int INF = 100000000;
	vector<vector<Edge>> Adj;
};

Dijkstra::Dijkstra(int n,bool dir)
{
	isNonDir = dir;
	I = n + 1;
	V = n;
	Adj.resize(I);

}


void Dijkstra::AddPath(int f, int t, int c)
{
	E++;
	Adj[f].push_back(Edge(t, c));
	if (isNonDir) Adj[t].push_back(Edge(f, c));
}

bool Dijkstra::PathExist(int t)
{
	return Cost[t] != INF;
}

void Dijkstra::Run(int f)
{
	//プライオリティキュー
	priority_queue<Edge> pq;
	//コストをしまう配列
	Cost.resize(I);
	for (int i = 0; i < I; i++)
	{
		Cost[i] = INF;
	}
	//スタート地点からスタート地点への距離は0
	Cost[f] = 0;
	//初期位置をエンキュー
	pq.push(Edge(f, 0L));

	//キューが空になるまで
	while (!pq.empty())
	{
		//先頭を取り出す
		auto cur = pq.top();
		pq.pop();

		//取り出したやつのコストがすでに決まってるやつより大きかったらバイバイ
		if (Cost[cur.To] < cur.Cost) continue;
		//隣接リストを探索
		for (int i = 0; i < (int)Adj[cur.To].size(); i++)
		{
			auto tmp = Adj[cur.To][i];
			//取り出した値を
			if (Cost[tmp.To] > cur.Cost + tmp.Cost) {
				Cost[tmp.To] = cur.Cost + tmp.Cost;
				pq.push(Edge(tmp.To, Cost[tmp.To]));
			}
		}
        }
}


void solve(int w,int h){
  int x;
  Dijkstra dij(w * h,true);
  rep(i,h*2-1){
    if(i%2==0){
      rep(j,w-1){
	cin>>x;
	if(x==0)dij.AddPath(i/2*w+j,i/2*w+j+1,1);
      }
    }else{
      rep(j,w){
	cin>>x;
	if(x==0)dij.AddPath(i/2*w+j,(i/2+1)*w+j,1);
      }
    }
  }

  dij.Run(0);
  /*
  rep(i,h){
    rep(j,w){
      cout<<dij.Cost[i*w+j]<<" ";
    }
    cout<<endl;
  }
  */
  if(dij.Cost[h*w-1]!=100000000)cout<<dij.Cost[h*w-1]+1<<endl;
  else cout<<0<<endl;
}

int main(){
  int h,w;
  while(cin>>w>>h){
    if(h==0&&w==0)break;
    solve(w,h);
  }
  return 0;
}



Measured memory_bytes: 3168
from collections import defaultdict

N, Q = map(int, input().split())

G = defaultdict(list)

for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

parents = [0] * (N + 1)
values = [0] * (N + 1)
values_sum = [-1] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x

# solve
values_sum[1] = values[1]

queue = [1]
while len(queue) > 0:
    p = queue.pop()
    for q in G[p]:
        if values_sum[q] == -1:
            values_sum[q] = values_sum[p] + values[q]
            queue.append(q)

print(*values_sum[1:])


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n)cin>>a[i];

    sort(all(a));

    rep(i,k){
        ans += a[i];
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n, d[105], ans = 0;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		scanf("%d", &d[i]);
	}
	d[0] = 0;
	sort(d + 1, d + 1 + n);
	for(int i = 1;i <= n;i++){
		if(d[i] != d[i - 1]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	int i=0,j=n-1,ans=0;
	while(i<j){
		debug(s);
		debug(i,j);
		while(i<j&&s[i]=='R')i++;
		while(j>i&&s[j]=='W')j--;
		if(i<j&&s[i]=='W'&&s[j]=='R'){
			swap(s[i],s[j]);
			ans++;
			i++,j--;
		}
	}
	cout<<ans<<endl;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	// cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int d = 0;
    set<int> s;
    for(int i = 0; i < k; i++){
        cin >> d;
        vector<int> A(n);
        for(int j = 0; j < d; j++){
            cin >> A[j];
            s.insert(A[j]);
        }
    }
    cout << n - s.size();

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
void output(int N,int A[]){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}
void changearray(int N,int A[]){
  int i,j,v;
   for(i=1;i<N;i++){
      v=A[i];
      j=i-1;
      while(j>=0 && A[j]>v){
	A[j+1]=A[j];
	j--;
      }
      A[j+1]=v;
      output(N,A);
   }
}

int main(){
  int i,j,N;
  int A[100];
    //input
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",&A[i]);
    
    output(N,A);
    changearray(N,A);
    
    return 0;
}





Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n;cin>>n;
  int ans=0;
  rep(i,n)ans+=(i+1)*(n-i);
  rep(i,n-1){
    int a,b;cin>>a>>b;
    if(a>b)swap(a,b);
    ans-=(a*(n-b+1));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


a,b,c,d = map(int, input().split())
cnt = 0
ansb1 = b // c
ansb2 = b // d
ansb12 = b // (c*d//(gcd(c,d)))
bb = (ansb1 + ansb2) - ansb12

ansa1 = (a-1) // c
ansa2 = (a-1) // d
ansa12 = (a-1) // (c*d//(gcd(c,d)))
aa = (ansa1 + ansa2) - ansa12
print((b-a+1)-(bb-aa))

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

W, H, N = list(map(int, input().split()))

x1, x2, y3, y4 = 0, W, 0, H

for i in range(N):
	x, y, a = list(map( int, input().split()))
	if a == 1:
		if x > x1:
			x1 = x
	elif a == 2:
		if x < x2:
			x2 = x
	elif a == 3:
		if y > y3:
			y3 = y
	else:
		if y < y4:
			y4 = y

w = x2 - x1
h = y4 - y3

if w > 0 and h > 0:
	print(w * h)
else:
	print(0)



Measured memory_bytes: 3064
def method(s):
    count=0
    ans=[]
    while count!=10:
        s=str(s**2).zfill(8)
        s=int(s[2]+s[3]+s[4]+s[5])
        ans.append(s)
        count +=1
    return ans
N=int(input())
for i in range(N):
    s=int(input())
    print("Case %d:"%(i+1))
    for j in range(10):
        print(method(s)[j])


Measured memory_bytes: 5592
import java.util.*

fun main(args: Array<String>) {
    val numbers = Numbers()
    (1..readLine()!!.toInt()).forEach {
        numbers.addValue(readLine()!!.toInt())

    }
    numbers.printValue()
}

class Numbers(private val digits: MutableMap<Int, DigitNumbers> = TreeMap()) {

    fun addValue(value: Int) {
        val digit = value.toString().length
        addValue(digit, value)
    }

    private fun addValue(digit: Int, value: Int) {
        val digitNumbers = digits[digit] ?: DigitNumbers()
        digitNumbers.addIfNeeded(value)
        digits[digit] = digitNumbers
    }


    fun printValue() {
        val values = mutableListOf<Int>()
        digits.values.forEach {
            values.addAll(it.values)
            if (values.size >= 3) {
                return@forEach
            }
        }

        println(values.flatMap { v -> values.filter { v != it }.map { "$it$v".toInt() }.toList() }.sorted()[2])
    }
}

class DigitNumbers(private val numbers: MutableList<Int> = mutableListOf()) {

    companion object {
        private const val LIMIT_VALUE = 3
    }

    val values: List<Int> get() = numbers

    fun addIfNeeded(value: Int) {
        if (numbers.size <= LIMIT_VALUE) {
            numbers.add(value)
        } else if (numbers.max()!! >= value) {
            numbers.add(value)
            numbers.sort()
            numbers.removeAt(numbers.size - 1)
        }
    }
}



Measured memory_bytes: 34916
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string src = "abcdefghijklmnopqrstuvwxyz";
    string w;
    cin >> w;

    for (auto ch : src) {
        int n = count(w.begin(), w.end(), ch);
        if (n % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3648
import string
numbers = "0123456789"
alphabets = string.ascii_letters # a-z+A-Zをロード
characters = numbers + alphabets

def base_cvt(value, n=2):
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n)
    idx = tmp%n
    result = characters[idx] + result
    return result

def main():
  n,k = map(int,input().split())
  if k==10:
    print(len(str(n)))
  else:
    nbr = base_cvt(str(n), k)
    print(len(str(nbr)))
    
if __name__ == '__main__':
    main()

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

int main() {
    int a[5],ans=0,last=6,last_=9;
    for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]%10==0) continue;
        if(a[i]%10<=last_){
            last_=a[i]%10;
            last=i;
        }
    }
    if(last==6){
        last=0;
    }
    for(int i=0;i<5;i++){
        if(i==last) continue;
        if(a[i]%10==0) ans+=a[i];
        else ans+=a[i]+10-(a[i]%10);
    }
    ans+=a[last];
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1e18
using namespace std;
typedef long long ll;

int main(){
  int N;  cin >> N;
  string s;
  rep(i, 0, N){
    cin >> s;
    set<string> st;
    rep(j, 1, s.size()){
      string tmp1 = s.substr(0, j);
      string tmp2 = s.substr(j, s.size()-j);
      string tmp3 = s.substr(0, j);
      string tmp4 = s.substr(j, s.size()-j);
      reverse(tmp3.begin(), tmp3.end());
      reverse(tmp4.begin(), tmp4.end());
      st.insert(tmp1+tmp2);
      st.insert(tmp1+tmp4);
      st.insert(tmp2+tmp1);
      st.insert(tmp4+tmp1);
      st.insert(tmp3+tmp2);
      st.insert(tmp3+tmp4);
      st.insert(tmp2+tmp3);
      st.insert(tmp4+tmp3);
    }
    cout << st.size() << endl;
  }
  return 0;
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, A, B, ans;

int f(int n)
{
	int res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}
int main()
{
	in>>N>>A>>B;
	for(int i=1;i<=N;++i)
	{
		if(A<=f(i)&&f(i)<=B)
		{	ans+=i;}
	}
	out<<ans<<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	string s,a[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	int i;
	cin>>s;
	for(i=0;i<7;i++)
	if(a[i]==s){
		cout<<7-i;
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())

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

    // solution comes here
    string S;
    cin >> S;

    ll N=S.size(), ans1=0, ans2=0;
    rep(i, N) (S[i] == '0' + i%2) ? ans1++ : ans2++;

    cout << min(ans1, ans2) << nl;
}

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

int main(){
	int N, Y, x, y, z;
	
	cin >> N >> Y;  
	
	for (x=0; x<=Y/10000; x++)    //2000
	  for (y=0; y<=Y/5000; y++)   //4000
	  {
	  	    z = N - x - y;
	    	if (z>=0 && x*10000+y*5000+z*1000==Y)
	    	{
	    		cout << x << " " << y << " " << z;
	    		return 0;
	    	}
	  }
	
	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue> 
#include<stack>
#include<cstdio>

using namespace std;

int a[251];
int parent(int i){
	return i/2;
}
int left(int i){
	return i*2;
}
int right(int i){
	return i*2 +1;
}

int main(){
	
	int h;
	cin>>h;
	
	for(int i=1; i<=h; i++){
		scanf("%d", &a[i]);
	}
	
	for(int i=1; i<=h; i++){
		printf("node %d: key = %d, ",i,a[i]);
		
		if(parent(i) > 0){
			printf("parent key = %d, ",a[parent(i)]);
		}
		if(left(i) <= h){
			printf("left key = %d, ",a[left(i)]);
		}
		if(right(i) <= h){
			printf("right key = %d, ",a[right(i)]);
		}
		
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1252
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int union_tree[600];
int union_find(int now) {
    if (union_tree[now] == now) return now;
    return union_tree[now] = union_find(union_tree[now]);
}
int union_merge(int a, int b) {
    a = union_find(a);
    b = union_find(b);
    if (a == b) return 0;
    union_tree[a] = b;
    return 1;
}

int color[60000];

void solve(){
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> inputs;
    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        inputs.push_back(make_tuple(c, a, b));
    }
    sort(ALL(inputs));
    REP(i, n) {
        union_tree[i] = i;
    }
    int ans = 0;
    REP(i, m) {
        color[i] = union_merge(get<1>(inputs[i]), get<2>(inputs[i]));
        ans += color[i] * get<0>(inputs[i]);
    }
    pair<int, int> go = mp(0, 0);
    REP(i, m) {
        if (color[i] == 0) continue;
        REP(q, n) {
            union_tree[q] = q;
        }
        int cnt = 0;
        REP(q, m) {
            if (i == q)continue;
            cnt += union_merge(get<1>(inputs[q]), get<2>(inputs[q])) * get<0>(inputs[q]);
        }
        int ok = 1;
        REP(q, n) {
            if (union_find(q) != union_find(0)) {
                ok = 0;
            }
        }
        if (ans != cnt || ok == 0) {
            go.first++;
            go.second += get<0>(inputs[i]);
        }
    }
    cout << go.first << " " << go.second << endl;
}

#undef int
int main() {
    init();
    solve();
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, m;
    cin >> n >> m;

    cout << (n * (n - 1) / 2) + (m * (m - 1) / 2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
 	int i;	
  	long long j,x,k,d,x2,y;
  	long long ans = 0;
  
  scanf("%lld %lld %lld",&x,&k,&d);
  if(x<0){
   x=x*(-1); 
  }
  
  if(x>=k*d && log10(k)+log10(d)<=16){
   printf("%lld\n",x-k*d);
    return 0;
  }

  
  y=x/d;
  x2=x%d;
  if((k-y)%2==1){
    printf("%lld\n",(x2-d)*(-1));
    return 0;
  }else{
    printf("%lld\n",x2);
    return 0;
  }
  
  
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 2380
N = int(input())
length_list = [int(x) for x in input().split()]

all_length = sum(length_list)

half_length = all_length / 2
before_sum = 0
after_sum = 0
for ax in length_list:
    if before_sum+ax < half_length:
        before_sum += ax
        continue
    else:
        after_sum = before_sum + ax
        break
before_diff = all_length - before_sum 
after_diff = all_length - after_sum

if before_diff - before_sum < after_sum - after_diff:
    print(before_diff - before_sum)
else:
    print(after_sum - after_diff)

Measured memory_bytes: 26060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
template< typename T >
size_t LIS(const vector< T > &a, bool strict) {
  vector< T > lis;
  for(auto &p : a) {
    typename vector< T >::iterator it;
    if(strict) it = lower_bound(begin(lis), end(lis), p);
    else it = upper_bound(begin(lis), end(lis), p);
    if(end(lis) == it) lis.emplace_back(p);
    else *it = p;
  }
  return lis.size();
}
int main() {
    vl A;
    cin >> n;
    rep(i, n) { cin >> x;
        A.push_back(x);
    }

    cout<<LIS(A,true)<<endl;
}




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


int main(){
  ll H,W;
  cin>>H>>W;
  
  ll a[H][W];
  rep(i,H){
   rep(j,W){cin>>a[i][j];}
  }
 ll ans=0;
  
  vector<ll> Y1;
  vector<ll> X1;
  vector<ll> Y2;
  vector<ll> X2;
  
  rep(i,H){
    rep(j,W-1){
      if(a[i][j]%2==1){
          Y1.push_back(i+1);
          X1.push_back(j+1);
          Y2.push_back(i+1);
          X2.push_back(j+2);
          ans++;
          a[i][j+1]++;
      }
    }
  }
  
  rep(i,H-1){
    if(a[i][W-1]%2==1){
          Y1.push_back(i+1);
          X1.push_back(W);
          Y2.push_back(i+2);
          X2.push_back(W);
      ans++;
      a[i+1][W-1]++;
    }
  }
  
  cout<<ans<<endl;
  rep(i,ans){
   cout<<Y1[i]<<" "<<X1[i]<<" "<<Y2[i]<<" "<<X2[i]<<endl;
  }


}


Measured memory_bytes: 9276
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

int n = 1407;
int k = 38;

vector<int> ans[1500];

int nxt = 1;

int main()
{
    printf("%d %d\n", n, k);
    for (int i = 1; i <= k; i++) {
        ans[1].push_back(nxt);
        for (int j = (i - 1) * (k - 1) + 2; j < i * (k - 1) + 2; j++) {
            ans[j].push_back(nxt);
        }
        nxt++;
    }
    for (int i = 0; i < k - 1; i++) {
        for (int j = 0; j < k - 1; j++) {
            int cur = i; int curoff = 2;
            //bool has_2 = false; bool has_1371 = false;
            for (int l = 1; l <= k; l++) {
                //if (curoff + cur == 2) has_2 = true;
                //if (curoff + cur == 1371) has_1371 = true;
                ans[curoff + (l == k ? (j - i + k - 1) % (k - 1) : cur)].push_back(nxt);
                cur += j - i + k - 1;
                cur %= k - 1;
                curoff += k - 1;
            }
            nxt++;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (ans[i].size() != k) abort();
        for (int j = 0; j < k; j++) {
            if (ans[i][j] > n) abort();
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3212
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

const lint dp_max = 80 * 160;
lint H, W;
lint lint_map[80][80][2];
bool dp[80][80][160*80];
bool visited[80][80];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> H >> W;
	REP(i, H) {
		REP(j, W) {
			cin >> lint_map[i][j][0];
		}
	}
	REP(i, H) {
		REP(j, W) {
			cin >> lint_map[i][j][1];
		}
	}
	dp[0][0][abs(lint_map[0][0][0] - lint_map[0][0][1])] = true;
	dp[0][0][abs(lint_map[0][0][1] - lint_map[0][0][0])] = true;
	queue<plint> que;
	que.push({ 0, 0 });
	while (!que.empty()) {
		plint curr = que.front(); que.pop();
		lint ny, nx;
		ny = curr.first + 1; nx = curr.second;
		if (ny < H && nx < W) {
			REP(i, 160 * 80) {
				if (!dp[curr.first][curr.second][i]) continue;
				dp[ny][nx][abs(i + lint_map[ny][nx][0] - lint_map[ny][nx][1])] = true;
				dp[ny][nx][abs(i - lint_map[ny][nx][0] + lint_map[ny][nx][1])] = true;
			}
			if (!visited[ny][nx]) que.push({ ny, nx });
			visited[ny][nx] = true;
		}
		ny = curr.first; nx = curr.second + 1;
		if (ny < H && nx < W) {
			REP(i, 160 * 80) {
				if (!dp[curr.first][curr.second][i]) continue;
				dp[ny][nx][abs(i + lint_map[ny][nx][0] - lint_map[ny][nx][1])] = true;
				dp[ny][nx][abs(i - lint_map[ny][nx][0] + lint_map[ny][nx][1])] = true;
			}
			if (!visited[ny][nx]) que.push({ ny, nx });
			visited[ny][nx] = true;
		}
	}

	lint minv = dp_max;
	REP(i, 160 * 80) {
		if (!dp[H-1][W-1][i]) continue;
		chmin(minv, i);
	}
	cout << minv << endl;
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int a, b;
    while(cin >> a >> b){
        cout << to_string(a + b).size() << "\n";
    }
}


Measured memory_bytes: 3280
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=500005;
//const ll Mod=1000000007;
using namespace std;

string s;
int a[maxn];

int main()
{
    sync;
    cin>>s;
    int n=s.length()+1;
    int d=0;
    for(int i=0;i<n-1;i++)
    {
        if(s[i]=='<')
            d++;
        else
            d=0;
        a[i+2]=max(d,a[i+2]);
    }
    for(int i=n-2;i>=0;i--)
    {
        if(s[i]=='>')
        {
            d++;
        }
        else
            d=0;
        a[i+1]=max(d,a[i+1]);
    }
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=1ll*a[i];
//        cout<<a[i]<<' ';
    }
//    cout<<endl;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 2844
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n; cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    set<string> se;

    rep(i,n){
        if(se.count(s[i])){
            cout << "No" << ln;
            return 0;
        }
        se.insert(s[i]);
    }
    rep(i, n-1){
        if(s[i].back()!=s[i+1][0]){
            cout << "No" << ln;
            return 0;
        }
    }
    cout << "Yes" << ln;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    s,p,r = map(int, input().split())
    t = input().rstrip()
    hasi = []

    res = 0
    for i in range(n):
        if t[i]=='r':
            a = r
            b = 'p'
        if t[i]=='s':
            a = s
            b = 'r'
        if t[i]=='p':
            a = p
            b = 's'
        if i<k:
            res += a
            hasi.append(b)
        else:
            if t[i]==t[i-k] and b in hasi[i-k]:
                hasi.append('x')
                continue
            else:
                res += a
                hasi.append(b)
    print(res)


if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   int N, M;
   cin >> N >> M;
   vector<int> X(M), Y(M);
   for (int i = 0; i < M; ++i) {
      cin >> X[i] >> Y[i];
      --X[i], --Y[i];
   }
   vector<vector<bool>> A(N, vector<bool>(N));
   for (int v = 0; v < N; ++v) {
      A[v][v] = true;
      for (int i = M - 1; i >= 0; --i) {
         if (A[v][X[i]] && A[v][Y[i]]) {
            fill(A[v].begin(), A[v].end(), true);
            break;
         } else if (A[v][X[i]]) {
            A[v][Y[i]] = true;
         } else if (A[v][Y[i]]) {
            A[v][X[i]] = true;
         }
      }
   }
   int ans = 0;
   for (int i = 0; i < N; ++i) {
      for (int j = i + 1; j < N; ++j) {
         bool flag = false;
         for (int k = 0; k < N; ++k) {
            flag |= (A[i][k] && A[j][k]);
         }
         ans += !flag;
      }
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())

par = [i for i in range(n)]
rank = [0 for i in range(n)]
diff_weight = [0 for i in range(n)]


def root(x):
    if par[x] == x:
        return x
    r = root(par[x])
    diff_weight[x] += diff_weight[par[x]]
    par[x] = r
    return par[x]

def issame(x, y):
    return root(x) == root(y)

def weight(x):
    root(x)
    return diff_weight[x]

def diff(x, y):
    return weight(y) - weight(x)

def merge(x, y, w):
    w += weight(x)
    w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y:
        return False
    if rank[x] < rank[y]:
        x, y = y, x
        w = -w
    if rank[x] == rank[y]:
        rank[x] += 1
    par[y] = x
    diff_weight[y] = w
    return True

for i in range(m):
    l, r, d = map(int, input().split())
    if issame(l-1, r-1):
        di = diff(l-1, r-1)
        if di != d:
            print("No")
            exit()
    else:
        merge(l-1, r-1, d)

print("Yes")

Measured memory_bytes: 10024
n, m, c = map(int,input().split())
B = list(map(int,input().split()))
A = [input().split() for l in range(n)]
cnt = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += int(A[i][j]) * B[j]
    if sum + c > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

bool check(const vector<int> &a) {
    for(const int &i : a)
        if(i % 2 == 0 && i % 3 != 0 && i % 5 != 0) return false;
    return true;
}

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

    int n; cin >> n;
    vector<int> a(n);
    for(int &i : a) cin >> i;
    cout << (check(a) ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[205000];
vector<int>v[205000];
int main()
{
   	int n,m;
   	memset(s,-1,sizeof(s));
   	cin>>n>>m;
  	while(m--){
  		int u,v1;
  		cin>>u>>v1;
  		v[u].push_back(v1);
  		v[v1].push_back(u);
	} 
	queue<int>que;
	s[1]=0;
	for(int i=0;i<v[1].size();i++)
	{
		que.push(v[1][i]);
		s[v[1][i]]=1;	
	}
	while(!que.empty()){
		int p=que.front();
		que.pop();
		for(int i=0;i<v[p].size();i++)
		{
			int g=v[p][i];
			if(s[g]==-1)
			{
				s[g]=p;
				que.push(g);
			}
		}
	}
	int flag=1;
	for(int i=2;i<=n;i++)
	{
		if(s[i]==-1){
			flag=0;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++){
			cout<<s[i]<<endl;
		}
	}else{
		cout<<"No"<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 13416
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
s=i()
for i in range(math.ceil(len(s)/2)):
  if not (s[2*i]=="R" or s[2*i]=="U" or s[2*i]=="D"):
    print("No")
    sys.exit()
for j in range(len(s)//2):
  if not (s[2*j+1]=="L" or s[2*j+1]=="U" or s[2*j+1]=="D"):
    print("No")
    sys.exit()
print('Yes')

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

int main() {
  int n, x;
  cin >> n >> x;
  
  vector<int> vec(n);
  int sum = 0;
  
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  int left_x = x - sum;
  
  sort(vec.begin(), vec.end());
  int left_u = vec.at(0);
  
  cout << vec.size() + left_x / left_u << endl;
}

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

using namespace std;

bool comp1(pair<int, int> a, pair<int , int> b){
    return a.first < b.first;
}

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int> > a(N);

    for (int i = 0; i < N; i++) {
        int aa, b;
        cin >> aa >> b;
        a[i] = make_pair(aa, b);
    }

    sort(a.begin(), a.end(),comp1);


    unsigned long long res = 0;
    long long cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt += a[i].second;
        res += (long long)a[i].first * (long long)a[i].second;
        if (cnt > M) {
            for (int j = 0; cnt > M; j++) {
                res -= a[i].first;
                cnt--;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");

	var line1 = input[0].split(" ");
    var num = Number(line1[0]);
    var sel = Number(line1[1]);
    
    var data = input[1].split(" ");
    for(var i = 0; i < data.length; i++){
        data[i] = Number(data[i])
    }
    
    data.sort(function(a, b) {
        return (parseInt(a) > parseInt(b)) ? -1 : 1;
    });
    
    var sum = 0;
    for(var i =0; i<sel; i++){
        sum+=data[i]
    }
    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());

    double ans = v[0];
    for (int i = 1; i < n; i++) {
        ans = (ans + v[i]) / 2.0;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int A,B; cin>>A>>B;
  int r = 0;
  REP(i,2){
    if(A>B){ r += A; --A;}
    else{ r+= B; --B;}
  }
  cout << r << "\n";
}

Measured memory_bytes: 256
q=int(input())
el=[True for _ in range(10**5+1)]
el[0]=False
el[1]=False
temp=[0]*(10**5+1)
i=2
while i*i<=10**5+1:
    for j in range(2*i,10**5+1,i): el[j]=False
    i+=1
cnt=0
for i,val in enumerate(el):
    if val and el[(i+1)//2]:
        cnt+=1
    temp[i]=cnt

for i in range(q):
    l,r=map(int,input().split())
    print(temp[r]-temp[l-1])

Measured memory_bytes: 10808
def main():
	while True:
		n=int(input())
		if n==0:
			break
		ls=[int(input()) for i in range(n)]
		ls.sort()
		score_sum=sum(ls)-ls[0]-ls[n-1]
		print(int(score_sum//(n-2)))

if __name__=="__main__":
	main()



Measured memory_bytes: 5604
#include <iostream>
#include <map>

using namespace std;

const long long int MOD=1e9+7;
int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        mp[A]++;
    }
    
     bool flag=true;
     long long int cnt=N%2 ? 0 : 1;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(N%2==itr->first%2) {
            flag=false;
            break;
        } else {
            if(cnt!=itr->first) {
                flag=false;
                break;
            } else {
                if(cnt==0 && itr->second==1) {
                    cnt += 2;
                    continue;
                } else if(cnt!=0 && itr->second==2) {
                    cnt += 2;
                    continue;
                } else {
                    flag=false;
                    break;
                }
            }
        }
    }
    
    long long int ans;
    if(flag) {
        ans = 1;
        int counter=N/2;
        while(counter!=0) {
            ans *= 2;
            ans %= MOD;
            counter--;
        }
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3200
#include <stdio.h>
int A[500001];
void maxHeap(int);
int n;
int main(){
  int i;
  scanf("%d",&n);
  n++;
  for(i=1;i<n;i++) scanf("%d",&A[i]);
  for(i=n/2;i>0;i--) maxHeap(i);

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

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

void maxHeap(int i){
  int l,r,large,c;
  l=i*2;
  r=i*2+1;
  if(l<=n && A[l]>A[i]) large=l;
  else large=i;

  if(r<=n && A[r]>A[large]) large = r;
  if (large!=i){
    c=A[i];
    A[i]=A[large];
    A[large]=c;
    maxHeap(large);
  }


}

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

int N;
int a[100001];

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

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

    int cnt = 0, pfm = 1;
    for (int i = 1; i <= N; i++) {
        if (pfm == 2) break;
        pfm = a[pfm]; cnt++;
        if (i == N) cnt = -1;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long> R(n),L(n);
	long sum=0;
	for(int i=0;i<n;i++){
		cin >> R[i] >> L[i];
		sum+=L[i]-R[i]+1;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;
const string ABC = "ABC";

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

    vector<vector<ll>> dp(s.length() + 1, vector<ll>(4));

    for (int i = s.length(); i >= 0; i--) {
        for (int j = 3; j >=0; j--) {
            if (i == s.length()) {
                if (j == 3) {
                    dp[i][j] = 1;
                }
                else {
                    dp[i][j] = 0;
                }
            }
            else {
                if (j == 3) {
                    if (s[i] == '?') {
                        dp[i][j] =(3* dp[i + 1][j])%MOD_CONST;
                    }
                    else {
                        dp[i][j] = (dp[i + 1][j]) % MOD_CONST;
                    }
                }
                else {
                    int m1 = (s[i] == '?') ? 3 : 1;
                    int m2 = (s[i] == '?' || s[i] == ABC[j]) ? 1 : 0;

                    dp[i][j] = ((m1 * dp[i + 1][j]) % MOD_CONST + m2 * dp[i + 1][j + 1]) % MOD_CONST;

                }
            }
        }
    }
    cout << dp[0][0] << endl;
}  



Measured memory_bytes: 7424
import Data.List
main=do
    [n,x]<-map read.words<$>getLine::IO[Int]
    as<-sort.map read.words<$>getLine::IO[Int]
    print $ f 0 x as
f c 0 [] = c
f c _ [] = c-1
f c x (a:as)
    | a<=x = f (c+1) (x-a) as
    | otherwise = c

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int a, b;
  cin >> a >> b;

  if(a > b){
    swap(a, b);
  }

  for(int i = 0; i < b; i++){
    cout << a;
  }
  cout << endl;



  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := readint()
	M := readint()
	if N == M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 640