akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

int update(std::vector<long long int> &seg_tree, long long int N, long long int index, long long int value);
long long int query(std::vector<long long int> &seg_tree, long long int N, long long int left, long long int right, long long I, long long int L, long long int R);


int main(){
  
  // read problem
  long long int N, tmp;
  std::vector<long long int> h, a;
  
  scanf("%lld", &N);
  h.push_back(0);
  a.push_back(0);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    h.push_back(tmp);
  }
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    a.push_back(tmp);
  }
  
  // prepare long long section
  long long int N_seg = 1 << 18;
  std::vector<long long int> seg_tree(2*N_seg-1);
  
  // solve problem
  std::vector<long long int> max_beauty(N+1);
  
  for(long long int i = 1; i <= N; i++){
    max_beauty[i] = query(seg_tree, N_seg, 0, h[i], 0, 0, N_seg) + a[i];
    update(seg_tree, N_seg, h[i], max_beauty[i]);
    //std::cerr << "i: " << i << " h[i] " << h[i] << " max_beauty: "<< max_beauty[i] << std::endl;
    //std::cerr << "query: " << query(seg_tree, N_seg, 0, h[i], 0, 0, N_seg) << std::endl;
  }

  std::cout << query(seg_tree, N_seg, 0, N_seg, 0, 0, N_seg);
  
  return 0;
}


int update(std::vector<long long int> &seg_tree, long long int N, long long int index, long long int value){
  
  // update the entry
  index += N-1;
  if(value > seg_tree[index]){
    seg_tree[index] = value;
  }
  
  // update the entries that represent range information
  while(index > 0){
    index = (index-1)/2;
    if(value <= seg_tree[index]){
      break;
    }
    else{
      seg_tree[index] = value;
    }
  }
  
  return 0;
}


// compute the query in the intersection of [left, right) and [L, R)
// [L, R) is for convenience in iteration. whole range is usually chosen when called in main function.
long long int query(std::vector<long long int> &seg_tree, long long int N, long long int left, long long int right, long long I, long long int L, long long int R){
  if(R <= left || right <= L){
    return 0;
  }
  if(left <= L && R <= right){
    return seg_tree[I];
  }
  else{
    long long int tmp1, tmp2;
    tmp1 = query(seg_tree, N, left, right,  2*I+1, L, (L+R)/2);
    tmp2 = query(seg_tree, N, left, right,  2*I+2, (L+R)/2, R);
    return std::max(tmp1, tmp2);
  }
}


Measured memory_bytes: 9584
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long 
ull sum=0;
ll dp[2][3001][3001];
int main()
{
    ll n;
    cin>>n;
    ll arr[n+1];
    for(int i=1;i<=n;++i)
    {
        cin>>arr[i];
        sum+=arr[i];
        dp[0][i][i]=arr[i];
        dp[1][i][i]=0;
    }
    for(int l=2;l<=n;++l)
    {
        for(int i=1;i<=n-l+1;++i)
        {
           // dp[0][i][i+l-1] = max(dp[0][i][i+l-1],max());
           // dp[1][i][i+l-1] = max(dp[1][i][i+l-1],min(arr[i] + dp[0][i+1][i+l-1], arr[i+l-1] + dp[0][i][i+l-2] ));
           //if(i==2 && l==2)
          //  cout<<arr[i]+ dp[1][i+1][i+l-1]<<" "<<arr[i+l-1]+ dp[1][i][i+l-2]<<endl;
            if(arr[i]+ dp[1][i+1][i+l-1]>arr[i+l-1]+ dp[1][i][i+l-2])
            {
                dp[0][i][i+l-1] = arr[i]+ dp[1][i+1][i+l-1];
                dp[1][i][i+l-1] = dp[0][i+1][i+l-1];

            }
            else
            {
               
                dp[0][i][i+l-1] =  arr[i+l-1]+ dp[1][i][i+l-2];
                dp[1][i][i+l-1] = dp[0][i][i+l-2];
                // if(i==2 && l==2)
              //  cout<<"OK"<< dp[0][i][i+l-1] <<" "<<  dp[1][i][i+l-1]<<endl;
            }
            
        }
    }
  
    cout<<dp[0][1][n]-dp[1][1][n];

}

Measured memory_bytes: 139776
# coding: utf-8
# Your code here!
n=int(input())
a=list(map(int,input().split()))
ans=0
flg=True

for i in range(1,32):
    for j in range(n):
        if a[j]%2==1:
            flg=False
        else:
            a[j]=int(a[j]/2)
    if flg==True:
        ans=i
print(ans)


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

int main() {
  int N, X; cin >> N >> X;
  int L[N]; for (int i = 0; i < N; i++) cin >> L[i];
  int count = 1, d = 0;
  for (int i = 0; i < N; i++) {
    d += L[i];
    if (d <= X) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
lst = list(map(int, input().split()))
print(" ".join(list(map(str, lst))))
for i in range(1, N):
    v = lst[i]
    j = i - 1
    while (j >= 0 and lst[j] > v):
        lst[j+1] = lst[j]
        j -= 1
    lst[j+1] = v
    print(" ".join(list(map(str, lst))))



Measured memory_bytes: 5596
//***___********* ___*****___****___***___*********//
/*  |   \  |   | |   |   |   \  |     |     |   |  **
/*  |   |  |   | |___|   |   _  |__   |___  |___|  **
/*  |   |  |   | |   \   |  | | |         | |   |  **
/*  |___/  |___| |    \  |__| | |___  ____| |   |  **
//*************************************************/
#include<bits/stdc++.h>
#define ff double
#define endl "\n"
#define M 1000000007
#define forever while(1)
#define ll long long
#define pb push_back
#define vi vector<long long>
#define mii map<int,int>
#define pii pair<int,int>
#define set_zero(arr) memset(arr,0,sizeof(arr))
#define test ll t;cin>>t;while(t--)
#include <ext/pb_ds/tree_policy.hpp>
#define REP(i,n) for(int i=0;i<(n);i++)
#include <ext/pb_ds/assoc_container.hpp>
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
bool comp(string a,string b){return a<b;}

int main()
{

long long n,k;
cin>>n>>k;


long long arr[n+10],sum=0,sum1=0;
for(int i=0;i<n;i++){
    cin>>arr[i];
    sum+=arr[i];
}
if(k>=n){
    cout<<0<<endl;
    return 0;
}
sort(arr+0,arr+n);
reverse(arr+0,arr+n);
for(int i=0;i<k;i++){
    sum1+=arr[i];
}
cout<<sum-sum1<<endl;
return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  ll n;
  double sqrt_n;

  cin >> n;
  sqrt_n = sqrt(n);

  int tmp_min = log10(n) + 1;
  repf(i ,1, sqrt_n + 1) {
    if(n % i != 0){
      continue;
    }
    ll a = i;
    ll b = n / a;


    int current_min = max(
      log10(a) + 1,
      log10(b) + 1
    );

    tmp_min = min(tmp_min, current_min);
  }

  cout << tmp_min << endl;
}

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

int main() {

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

  int n;
  cin >> n;

  vector<long long> a(n), fre(3e5, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    fre[a[i]]++;
  }

  long long ans = 0;
  for (int i = 0; i < 3e5; ++i) {
    ans += (fre[i] * (fre[i]-1)) / 2;
  }

  for (int i = 0; i < n; ++i) {
    int d = a[i];
    cout << ans - fre[d] + 1 << '\n';
  }
}


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

int main() {
    long long n;
    cin >> n;
    long long a[n];
    long long s[n+1];
    s[0]=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        s[i+1]=s[i]+a[i];
    }
    long long ans=0;
    sort(s,s+n+1);
    long long count=0;
    for(int i=1;i<=n;i++){
        if(s[i]==s[i-1]){
            count++;
        }
        else if(s[i]!=s[i-1]){
            count=0;
        }
        ans+=count;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<queue>
using namespace std;
#define max 502
#define aaa 2000000003

int main()
{
	int heep[max];
	int h;
	cin >> h;

	for (int i = 0; i < max; i++) {
		heep[i] = aaa;
	}

	for (int i = 1; i < h + 1; i++) {
		cin >> heep[i];
	}

	for (int i = 1; i < h + 1; i++) {
		cout << "node " << i << ": key = " << heep[i] << ", ";
		if (heep[i / 2] != aaa) cout << "parent key = " << heep[i / 2] << ", ";
		if (heep[i * 2] != aaa) cout << "left key = " << heep[i * 2] << ", ";
		if (heep[i * 2 + 1] != aaa) cout << "right key = " << heep[i * 2 + 1] << ", ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
import sys
import math

def distance(x1, y1, x2, y2):
	return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)	

#fin = open("test.txt", "r")
fin = sys.stdin

[x1, y1, x2, y2] = list(map(float, fin.readline().split()))

print("{0:.5f}".format(distance(x1, y1, x2, y2)))

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
   int a,b,cnt=0;
   cin >> a >> b;
   for(int i = a;i<=b;i++){
     string rn = to_string(i);
     reverse(all(rn));
     int n = stoi(rn);
     if(n == i) cnt++;
   }
   cout << cnt << endl;
}

Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 1e6 + 100, OO = 1e9 + 7, M = 1e9 + 7, P = 769, sq = 360, lg = 26;
typedef pair <int, int> pii;
int a[N];

int32_t main() {	
	int n;
	cin >> n;
	bool u = true;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x % 2 == 1)
			continue;
		if(x % 5 == 0 || x % 3 == 0)
			continue;
		u = false;
	}
	if(u)
		cout << "APPROVED" << endl;
	else
		cout << "DENIED" << endl;
	return 0;	
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

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

    int a, h;
    cin >> a >> h ;
    
    int s;
    for(int i = 0; i < h ; i++){
        cin >> s ;
        a -= s;
    }

    if(a < 0){
        cout << -1 << endl;
    } else {
        cout << a << endl;
    }
    
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
  int in;
  int n;
  scanf("%d",&n);
  for (int i = 0; i < n; i++){
    scanf("%d",&in);
    if(in%2==0){
      if(in%3==0||in%5==0){}
      else{
        printf("DENIED");
        return 0;       
      }
    }
  }
  printf("APPROVED");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> b(n-1); rep(i,n-1) cin >> b[i];
    vector<int> a(n); rep(i,n) a[i] = 0;
    a[n-1] = b[n-2];
    a[n-2] = b[n-2];
    for(int i=n-3;i>=0;i--){
        if(b[i] < a[i+1]) a[i+1] = b[i];
        a[i] = b[i];
    }
    int sum = 0;
    rep(i,n) sum += a[i];
    cout << sum << endl; 
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	int k,n,i,a[10001],b[10001];
	cin >> n;
	i = 1;
	while (i<= n) {
		cin >> a[i];
		i++;
	}
	k= 2;
	b[1] = a[n];
	cout << b[1];
	while(k<=n){
		b[k] = a[n + 1 - k];
		cout << " " << b[k];
		k++;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
    private static final String HEISEI = "Heisei";
    private static final String TBD = "TBD";

    public static String process(TestCase testCase) {
        final String S = testCase.S;
        final String[] parts = S.split("/");
        int year = Integer.parseInt(parts[0]);
        int month = Integer.parseInt(parts[1]);
        int day = Integer.parseInt(parts[2]);

        if (isTbd(year, month, day)) {
            return TBD;
        } else {
            return HEISEI;
        }
    }

    private static boolean isTbd(int year, int month, int day) {
        final boolean isAfterYear = year > 2019;
        final boolean isAfterMonth = year == 2019 && month > 4;
        final boolean isAfterDay = year == 2019 && month == 4 && day > 30;
        return isAfterYear || isAfterMonth || isAfterDay;
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        sc.close();
        return new TestCase(S);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final String S;

        public TestCase(String S) {
            this.S = S;
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A == 1 && B== 2)cout << 3 << endl;
    else if(A == 2 && B == 1)cout << 3 << endl;
    else if((A == 2 && B == 3) ||(A == 3 && B == 2))cout << 1 << endl;
    else if ((A == 3 && B == 1)||(A == 1 && B == 3))cout << 2 << endl;
    return 0;
}


Measured memory_bytes: 256
mod = 998244353
N, S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0 for i in range(S+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j] * 2
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])


Measured memory_bytes: 153156
num=int(input())
lineLength=[int(s) for s in input().split(" ")]
sortedLength=sorted(lineLength, reverse=True)
maxLength=int(sortedLength[0])
sumLength=0
for i in range(num-1):
  sumLength=sumLength+int(sortedLength[i+1])
if maxLength>=sumLength:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int r,g,b;
    scanf("%d %d %d",&r,&g,&b);
    if((100*r+10*g+b)%4==0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	char c;
	cin>>c;
	if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
		cout<<"vowel";
	else
		cout<<"consonant";
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



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

using namespace std;
using ll = long long;

vector<bool> primes() {
  vector<bool> ret(1e5 + 1);
  for (int i = 2; i <= 1e5; i++) {
    ret[i] = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        ret[i] = false;
        break;
      }
    }
  }
  return ret;
}

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

  auto p = primes();
  vector<int> a(1e5 + 1);
  for (int i = 2; i <= 1e5; i++) {
    a[i] = a[i - 1];
    if (p[i] && p[(i + 1) / 2])
      a[i]++;
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << a[r] - a[l - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 3576
###############################################################################

from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    xyhlist = intinl(n)

    for x_sample, y_sample, h_sample in xyhlist:
        if h_sample > 0:
            break

    for cx in range(101):
        for cy in range(101):
            h_ans = h_sample + abs(x_sample - cx) + abs(y_sample - cy)
            for x, y, h in xyhlist:
                if h != max(h_ans - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print('%d %d %d' % (cx, cy, h_ans))
                return


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin>>N;
  vector<float>a(N);
  vector<float>b(N);//a[i]の逆数
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    b[i]=(1/a[i]);
  }
  float inv_sum;
  for(int i=0;i<N;i++){
    inv_sum+=b[i];
  }
  float ans=(1/inv_sum);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
ll n , m ;
int main ()
{
  cin >> n >> m ;
  ll mn = min (n , m / 2 );
  ll ans = mn ;
  n -= mn ;
  m -= mn * 2 ;
  if (n == 0 )
  {
    ans += m / 4;
  }
  cout << ans <<"\n";
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int num[100001];
  int p,ans=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(num[i]==1) p=i;
  }
  cout<<(n+k-3)/(k-1)<<endl;
  return 0;
}


Measured memory_bytes: 640
n=gets.to_i
s=Array.new
m=0
for i in 1..n do
    v=gets.to_i
    s.push(v)
    case i
    when 1 then
    when 2 then m=s[1]-s[0]
          min=s.min
    else
          m=[m,s[i-1]-min].max
          min=[min,v].min
    end
end
p m

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    vector<int> A(s.size() + 1);
    for (int i = 0; i < s.size(); ++i)
        if (s.at(i) == '<')
            A[i + 1] = max(A[i + 1], A[i] + 1);

    for (int i = s.size() - 1; i >= 0; --i)
        if (s.at(i) == '>')
            A[i] = max(A[i], A[i + 1] + 1);

    long long ans = 0;
    for (int i = 0; i <= s.size(); ++i)
        ans += A[i];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5872
#include <iostream>
using namespace std;
int main(){
	int time;
	cin>>time;
	int h,m,s;
	
	h=time/3600;
	time=time-3600*h;
	m=time/60;
	time=time-m*60;
	s=time;
	
	
	cout<<h<<':'<<m<<':'<<s<<endl;
	
	
}


Measured memory_bytes: 3084
N = int(input())
n = int(N**0.5)
d = {}
for x in range(1, n+1):
    for y in range(1, n+1):
        for z in range(1, n+1):
            c = x**2+y**2+z**2+x*y+y*z+z*x
            if c not in d:
                d[c] = 1
            else:
                d[c]+=1
for i in range(1, N+1):
    if i not in d:
        print(0)
    else:
        print(d[i])

Measured memory_bytes: 11588
class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
        self.diff_weight = [0]*(n+1)  # 親ノードとのweightの差
    def root(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            r = self.root(self.par[x])
            self.diff_weight[x] += self.diff_weight[self.par[x]]
            self.par[x] = r
            return self.par[x]
    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.root(x) == self.root(y)
    def weight(self,x):
        r = self.root(x)  # 経路圧縮
        return self.diff_weight[x]
    def diff(self,x,y):
        return self.weight(y) - self.weight(x)
    def unite(self,x,y,w):  # x,yの属するグループの併合
        w += self.weight(x)
        w -= self.weight(y)
        x = self.root(x)
        y = self.root(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
            w = -w
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x
        self.diff_weight[y] = w

import sys

sys.setrecursionlimit(10**7)
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
G = UnionFind(N)
for i in range(M):
    L,R,D = LI()
    if G.same_check(L,R):
        if G.diff(L,R) != D:
            print('No')
            exit()
    else:
        G.unite(L,R,D)

print('Yes')

Measured memory_bytes: 122912
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int a, b, ans = 0;
  cin >> a;
  for(int i = 0; i < N - 1; i++){
    cin >> b;
    if(a == b){
      ans++;
      b = -1;
    }
    a = b;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> h(n + 1, 0);
    for(int i = 1; i <= n; i++) cin >> h[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 1LL << 60));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < n - k; j++) {
            for(int k = 0; k < i; k++) {
                dp[i][j + 1] = min(dp[i][j + 1], dp[k][j] + max(0LL, h[i] - h[k]));
            }
        }
    }
    ll ans = 1LL << 60;
    for(int i = n - k; i <= n; i++) {
        ans = min(ans, dp[i][n - k]);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 4440
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let i1:String = read();
    let i2:String = read();
    let s = i1.chars().collect::<Vec<char>>();
    let t = i2.chars().collect::<Vec<char>>();
    let div = s.len() - t.len() + 1;
    let ans = (0..div).filter_map(|i| check(&s,&t,i)).min().unwrap_or("UNRESTORABLE".to_string());
    println!("{}",ans);
}
fn check(s:&Vec<char>,t:&Vec<char>,start:usize) -> Option<String>{
    let mut cp_s = s.clone();
    for i in 0..t.len(){
        if s[i + start] != '?' && s[i+ start] != t[i] {return None;}
    }
    for i in 0..t.len(){
        if cp_s[i + start] == '?' {
            cp_s[i + start] = t[i]; 
        }
    }
    for i in 0..cp_s.len() {
        if cp_s[i] == '?' {
            cp_s[i] = 'a';
        }
    }
    Some(cp_s.into_iter().collect::<String>())
}

Measured memory_bytes: 4352
import heapq
n,k = map(int,input().split())
L = []
for i in range(n):
    t,d = map(int,input().split())
    L.append([d,t])
L.sort()
ans = []
cur = [0]*n
heap = []
var = 0
for i in range(k):
    if cur[L[n-i-1][1]-1] == 0:
        ans.append(L[n-i-1][0])
        cur[L[n-i-1][1]-1] = 1
        var += 1
    else:
        heapq.heappush(heap, L[n-i-1])
temp = 0
for i in range(len(ans)):
    temp += ans[i]
for i in range(len(heap)):
    temp += heap[i][0]
temp += var**2
now = temp
for i in range(n-k):
    if len(heap) != 0:
        a = heapq.heappop(heap)
        if cur[L[n-k-i-1][1]-1] == 0:
            cur[L[n-k-i-1][1]-1] = 1
            now -= var**2
            now -= a[0]
            var += 1
            now += var**2
            now += L[n-k-i-1][0]
            temp = max(temp, now)
        else:
            heapq.heappush(heap, a)
print(temp)


Measured memory_bytes: 21688
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };
 
void solve() {
    ll K; cin >> K;
    string S; cin >> S;
    ll len = S.size();

    if(len<=K){
        print(S);
    } else{
        print(S.substr(0,K)+"...");
    }
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=0;
	cin >>s;
	rep(i,s.size()){
		if(!(i%2)){
			cout<<s[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 512
use std::io;

fn next_vec() -> Vec<i64> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|n| n.parse().unwrap()).collect()
}

fn main() {
    let v = next_vec();
    let a = v[0];
    let b = v[1];
    println!("{:?}", (a + b) % 24);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL long long

using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int a=n/10;
        int b=n%10;
        if(a==9||b==9)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


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

int main()
{
  int k;
  string s;
  cin >> k >> s;
  if (s.length() <= k)
  {
    cout << s << endl;
  }
  else
  {
    cout << s.substr(0, k) << "..." << endl;
  }
}


Measured memory_bytes: 3552
n=int(input())
xyh=[]
for i in range(n):
    xyh.append(list(map(int,input().split())))
x0=xyh[0][0]
y0=xyh[0][1]
h0=xyh[0][2]
count=0
while h0==0:
    count+=1
    x0=xyh[count][0]
    y0=xyh[count][1]
    h0=xyh[count][2]
for x in range(101):
    for y in range(101):
        h=h0+abs(x-x0)+abs(y-y0)
        for i in range(n):
            if max(0,h-abs(x-xyh[i][0])-abs(y-xyh[i][1]))!=xyh[i][2]:
                break
            if i==n-1:
                print(x,y,h)
                quit()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

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

    long n;

    cin >> n;

    map<ll, long> table;
    map<ll, long>::iterator it;
    vector<ll> v;
    ll a;

    long i;

    for (i = 0; i < n; i++) {
        cin >> a;

        table[a]++;
    }

    for (it = table.begin(); it != table.end(); it++) {
        if (1 < it->second) {
            if (3 < it->second) v.push_back(it->first);

            v.push_back(it->first);
        }
    }

    sort(v.begin(), v.end(), std::greater<ll>());

    if (1 < v.size()) cout << v[0] * v[1] << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,i;
  string s;
  cin>>n;
  for(i=0;i<n;i++) {
    cin>>s;
    if (s=="Y") break;
  }
  if (s=="Y") cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/


/*
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
*/
//Unionfind ,Disjointset
vector<int> Parent;
    //Aがどのグループに属するか
int root(int A){
    if(Parent[A] < 0)return A;
    return Parent[A]=root(Parent[A]);
}
    //自分のグループの頂点数
int size(int A){
    return -Parent[root(A)];
}
    //AとBをくっつける
int connect(int A,int B){
        //AとBを直接ではなくAのrootとBのrootをくっつける
    A = root(A);
    B = root(B);
    if(A==B){
        return false;//すでにくっついている
    }
    if(size(A)<size(B)) swap(A,B);
        //Aのサイズ更新
    Parent[A]+=Parent[B];
        //Bの親をAに変更する
    Parent[B]=A;

    return true;
}

int main(){
    int n,m;
    cin >> n>>m;
    int p[n];
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    //cerr<<"p"<<endl;
    Parent=vector<int>(n,-1);
    rep(i,m){
        int x,y;
        cin >> x>> y;
        x--;y--;
        connect(x,y);
    }
    //cerr<<"connect"<<endl;
    int ans=0;
    rep(i,n){
        
        if(root(i)==root(p[i])){
            ans++;
        }
        
        //cerr<<root(i)<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair

int xs[128];
pair<int, pair<int, int> > bs[1024];

int main() {
    for (;;) {
        int n, m, a;
        scanf("%d%d%d", &n, &m, &a);
        if (n == 0 && m == 0 && a == 0) return 0;
        a--;
        rep (i, m) {
            int h, p, q;
            scanf("%d%d%d", &h, &p, &q);
            p--, q--;
            bs[i] = mp(h, mp(p, q));
        }
        sort(bs, bs+m);
        rep (i, n) xs[i] = i;
        rep (i, m) swap(xs[bs[i].second.first], xs[bs[i].second.second]);
        printf("%d\n", xs[a]+1);
    }
}

Measured memory_bytes: 1044
N = int(input())
W = [input() for i in range(N)]

ans = 'Yes'
last = ''

for i in range(N):
    for j in range(i):
        if W[i]==W[j]:
            ans = 'No'
            
for w in W:
    W_new = [i for i in w]
    if w!=W[0] and last!=W_new[0]:
        ans = 'No'
    last = W_new[-1]

print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
long long n;
void solve()
{
    vector < long long > a(n),b(n);
    long long i;
    for (i=0;i<n;i++)
        cin>>a[i];
    b=a;
    for (i=1;i<n;i++)
        if (i==1) b[i]=abs(a[i]-a[i-1]);
        else if (i==2) b[i]=abs(a[i]-a[i-2]);
        else b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    cout<<b[n-1]<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
// abc170_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x, ans = 0;
  for (int i = 1; i <= 5; ++i) {
    cin >> x;
    if (x == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
//打牌
int main(){
    string s[3];
    cin>>s[0]>>s[1]>>s[2];

    int c=0;
    char ans;
    while(s[c].size()>0){
        char C = s[c][0];
        s[c].erase(s[c].begin());
        switch(C){
            case 'a':
            c = 0;
            ans = 'A';
            break;
            case 'b':
            c = 1;
            ans = 'B';
            break;
            case 'c':
            c = 2;
            ans = 'C';
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
	string s,s1,s2;
	cin>>s1>>s2;
	s=s2+"_"+s1;
	static int next[1100000];
	memset(next,0,sizeof(next));
	next[0]=-1;
	for(int i=1;i<s.size();i++)
	{
		int j;
		for(j=next[i-1];s[j+1]!=s[i]&&j>=0;j=next[j]);
		next[i]=(s[j+1]==s[i]?j+1:-1);
	}
	for(int i=s2.size()+1;i<s.size();i++)
		if(next[i]+1==s2.size())
			printf("%d\n",i-s2.size()*2);
	return 0;
}

Measured memory_bytes: 9272
def main():
    import math
    pi=math.pi
    import sys
    A,B,H,M=list(map(int,sys.stdin.readline().split()))

    large_deg=((2*pi/12)*((H+M/60)%12))
    small_deg=((2*pi/60)*(M%60))

    deg=abs(large_deg-small_deg)

    if deg>=pi:
        deg=2*pi-deg
    print(math.sqrt(A**2+B**2-2*A*B*math.cos(deg)))
    

main()

Measured memory_bytes: 9512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func StrStdin() (stringInput string){
  sc.Scan()
  OneLineString := sc.Text()
  stringInput = strings.TrimSpace(OneLineString)
  return 
}

func IntStdin() (int, error){
  stringInput := StrStdin()
  return strconv.Atoi(stringInput)
}

// ?????????????l??????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
    stringSplited := strings.Split(stringTargeted, delim)

    for _, str := range stringSplited {
        if str != "" {
            stringReturned = append(stringReturned, str)
        }
    }

    return
}

// ?f???~?^??????????????X???C?X???��
func SplitStrStdin(delim string) (stringReturned []string) {
    // ???????1?s?��
    stringInput := StrStdin()
  
    // ???????
    // stringSplited := strings.Split(stringInput, delim)
    stringReturned = SplitWithoutEmpty(stringInput, delim)

    return
}

// ?f???~?^?????????????l?X???C?X???��
func SplitIntStdin(delim string) (intSlices []int, err error) {
    // ??????X???C?X???��
    stringSplited := SplitStrStdin(delim)
	
    // ?????X???C?X????
    for i := range stringSplited {
        var iparam int
        iparam, err = strconv.Atoi(stringSplited[i])
        if err != nil {
            return
        }
        intSlices = append(intSlices, iparam)
    }
    return
}

func main(){
  intlist := SplitStrStdin(" ")
  leng, _ := strconv.Atoi(intlist[0])
  min, _ := strconv.Atoi(intlist[1])
  max, _ := strconv.Atoi(intlist[2])

  result := 0
  
  for i:=1; i <= leng; i++{
    num := strings.Split(strconv.Itoa(i), "")
    
    keta_sum := 0
    for j := 0; j < len(num); j++ {
      tmp, _ := strconv.Atoi(num[j])
      keta_sum += tmp
    }
    if keta_sum <= max && keta_sum >= min {
      result += i
    }
  }
  
  fmt.Println(result)
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char const *argv[])
{
    unsigned long N, K, tmp;
    unsigned long result = 0;
    cin >> N >> K;
    vector<unsigned long> H;
    if (N <= K)
    {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        H.push_back(tmp);
    }
    sort(H.begin(), H.end());
    for (int j = 0; j < N - K; j++)
    {
        result += H[j];
    }
    cout << result << endl;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10;

int n;

long long a[N], b[N];

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i)
		gii(a[i], b[i]);
	long long add = 0;
	for (int i = n; i; --i)
	{
		a[i] += add;
		if (a[i] % b[i]) add += b[i] - a[i] % b[i], a[i] += b[i] - a[i] % b[i];
	}
	printf("%lld\n", add);
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n;
    cin >> n;
    map<ll, ll>m;
     for (ll i = 0; i < n; i++) {
        m[i] = 0;
    }
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        m[x]++;
    }
    vector<pair<ll, ll>>v;
    for (auto i = m.begin(); i != m.end(); i++) {
        v.push_back({i->first, i->second});
    }
    ll s = 0;
    for(ll i = 0; i < v.size(); i++) {
        if( v[i].first == (i) && v[i].second > 0) {
            if(v[i].second >= i)
            s += abs((i) - v[i].ss);
        else {
            s += v[i].ss;
        }
        }
    else if( v[i].first != (i)) {
            s +=  v[i].ss;
        }
    }

    cout << s << endl;
}



Measured memory_bytes: 19376
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}


int main(){
    int N,M;
    cin >> N >> M;

    int L[M];
    int R[M];

    int Lmax=0;
    int Rmin=N;

    FOR(i,M){
        cin >> L[i] >>R[i];
        if(L[i]>Lmax){
            Lmax=L[i];
        }
        if(R[i]<Rmin){
            Rmin=R[i];
        }


    }
    int ans;
    if(Rmin<Lmax){
        ans=0;
    }else{
        ans=Rmin-Lmax +1;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0;i < n - 2;i++){
        map<char,int> cnt;
        for (int j = 0;j < i + 1;j++){
            cnt[s[j]]++;
        }
            int count = 0;
            for (int k = i + 1;k < n;k++){
                if(cnt[s[k]] != 0){
                    count++;
                    cnt[s[k]] = 0;
                }
            }
        ans = max(ans,count);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	const int MAX = 1e6;
	vector<bool> sv(MAX + 1, true);
	sv[0] = sv[1] = false;
	for (int i = 2; i <= MAX; i++) if (sv[i]) {
		for (int j = i + i; j <= MAX; j += i) {
			sv[j] = false;
		}
	}
	int l, r;
	cin >> l >> r; ++r;
	vector<int> cnt(r - l), val(r - l);
	for (int i = l; i < r; i++) val[i - l] = i;
	for (int i = 2; i <= MAX; i++) if (sv[i]) {
		for (int j = (l + i - 1) / i * i; j < r; j += i) {
			while (val[j - l] % i == 0) ++cnt[j - l], val[j - l] /= i;
		}
	}
	for (int i = l; i < r; i++) cnt[i - l] += val[i - l] > 1;
	int res = 0;
	for (auto p : cnt) res += sv[p];
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
int main()
{
	SPEED
	int m, d, ones, tens;
	cin >> m >> d;
	int count = 0;
	if(d<10)
	{
		cout << 0;
	}
	else
	{
		for (int i = 1; i <= m; ++i)
		{
			for (int j = 10; j <= d; ++j)
			{
				ones = j%10;
				tens = j/10;
				if (ones*tens==i && ones>=2 && tens>=2)
				{
					count++;
					//cout << i << " " << j << '\n';
				}
			}
		}
		cout << count;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;
  cin>>n;
  int64 a[n];
  rep(i,n){
    cin>>a[i];
  }
  int ord0=0,ord1=0,ord2=0;
  rep(i,n){
    switch(a[i]%4){
      case 0:
        ord2++;
        break;
      case 2:
        ord1++;
        break;
      default:
        ord0++;
        break;
    }
  }
  int dec=0;
  if(ord1==0 && ord0<=ord2+1){
    dec=1;
  }
  if(ord1>=1 && ord0<=ord2){
    dec=1;
  }
  if(dec){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 1024