akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


# 区間updateと要素クエリ
class SegmentTree(object):

    def __init__(self, n, e, fn):
        self.fn = fn
        self.length = 1 << n.bit_length()
        self.data = [e] * (self.length * 2)

    # 区間[l, r)の値とxをfnで比較して更新する
    def update(self, l, r, x):  # O(logN)
        l += self.length
        r += self.length
        while l < r:
            if l & 1:
                self.data[l] = self.fn(self.data[l], x)
                l += 1
            if r & 1:
                self.data[r - 1] = self.fn(self.data[r - 1], x)
                r -= 1
            l //= 2
            r //= 2

    # i番目の要素の値を取得する
    def query(self, i):  # O(logN)
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.fn(ret, self.data[i])
        return ret

N, Q = MI()
STX = [tuple(MI()) for _ in range(N)]
D = [I() for _ in range(Q)]

seg = SegmentTree(Q, INF, min)
for S, T, X in STX:
    # [S - X, T - X) に出発する人[l番目の人, r番目の人)が影響を受ける
    l = bisect_left(D, S - X)
    r = bisect_left(D, T - X)
    seg.update(l, r, X)

for i in range(Q):
    ans = seg.query(i)
    if ans == INF:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 128476
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    string X; cin >> X;
    int n = X.size();
    int ans = X.size();

    int s_count = 0;
    rep(i,n){
        if(X[i] == 'S'){
            s_count++;
        }
        else{
            if (s_count >0){
                ans -= 2;
                s_count--;
            }
        }
    }

    cout << ans << endl;    

}

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

using namespace std;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int L = A + B;
  int R = C + D;
  
  if (L == R){
    cout << "Balanced" << endl;
  }
  else if (L > R){
    cout << "Left" << endl;
  }
  else{
    cout << "Right" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;


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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s=="keyence"){
    cout << "YES" << endl;
    return 0;
  }

  for(int i=0;i<s.size();i++){
    for(int j=i;j<s.size();j++){
      string tmp = s;
      tmp.erase(tmp.begin()+i,tmp.begin()+j);
      if(tmp=="keyence"){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int cnt[N], a[N], n;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    priority_queue <ll> q;
    FOR(i, 1, (int)1e5)
        if(cnt[i] > 1)
        {
            q.push(cnt[i]);
        }
    ll res = 0;
    while(q.size() > 1)
    {
        ll a = q.top();
        q.pop();
        ll b = q.top();
        q.pop();
        if(a != b)
        {
            a -= (b - 1);
            q.push(a);
        }
        res += b - 1;
    }
    ll ans = n - 2 * res;
    if(!q.empty())
    {
        if(q.top() > 2)
        {
            if(q.top() & 1) ans -= q.top() - 1;
            else ans -= q.top();
        }
        else ans -= 2;
        cout << ans;
    }
    else
    cout << ans;
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define in auto&it
#define out auto it
#define fi first
#define se second
#define allr(x) (x).rbegin(),(x).rend()
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
const double pi = acos(-1);
#define err(x) cerr<<#x<<" = "<<x<<'\n';
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif
	fastio
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<Max(max(a*c,a*d),b*c,b*d);
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define P pair<ll, ll>
#define VI vector<ll>
#define int long long
using namespace std;

int n, m, d;

double solve() {
  if (d != 0 && 2 * d <= n - 1) {
    return ((2 * double(n) - 2 * double(d)) * (double(m) - 1) / double(n)) / double(n);
  } else {
    return (double(m) - 1) / double(n);
  }
}

signed main() {
  cin >> n >> m >> d;

  printf("%.10f\n", solve());
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

L, R, d = map(int, input().split())
print((R // d) - ((L - 1) // d))

Measured memory_bytes: 9468
<?php

    list($n, $m) = in_ints();

    $n_cnt = ($n * ($n - 1)) / 2;
    $m_cnt = ($m * ($m - 1)) / 2;
    
    out($n_cnt + $m_cnt);
    
    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }



Measured memory_bytes: 4856
#include <iostream>

using namespace std;

typedef long long ll;

ll n, p;
ll u = 1;

int main() {
	cin >> n >> p;
	if (n == 1) {
		cout << p << "\n";
		return 0;
	}
	for (ll k = 2; k*k <= p; k++) {
		int c = 0;
		while (p%k == 0) {
			c++;
			p /= k;
		}
		if (c/n == 0) continue;
		for (int i = 0; i < c/n; i++) u *= k;
	}
	cout << u << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    string s,p;
    cin >> s >> p;
    ll n=s.size();
    s += s;
    bool yes=false;
    rep(i,n) if(s.substr(i,p.size()) == p) yes=true;
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3224
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num*2];
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		shellSort(array, num);
		
		scanner.close();
	}

	public static int insertionSort( int[] array, int num, int g ,int count){ // N個の要素を含む0-オリジンの配列A
		int sub;
		int comp = 0;
		int i;
		
		for( i = 1; i <=  num - 1; i ++ ){
			sub = array[i];
			comp = i - g;
			while( -1 < comp && sub < array[comp] ){
				array[comp + g] = array[comp];
				comp = comp - g;
				count ++;
			}
			array[comp + g] = sub;
			
		}
		return count;
	}
	
	public static void shellSort(int[] array, int num){
		int cnt = 0;
		int m = 0;
		int[] arrayG = new int[100];
		for( int i = 0; i < 100; i ++ ){
			if( i == 0 ){
				arrayG[i] = num / 2 + 1;
			}else{
				arrayG[i] = arrayG[i-1] / 2 - 1;
			}
			
			if( arrayG[i] < 0 ){
				arrayG[i - 1] = 1;
				arrayG[i] = 0;
				m = i;
				
				break;
			}
			
		}
		for( int i = 0; i < m; ++i ){
			cnt = insertionSort(array, num, arrayG[i], cnt);
		}
		
		
		System.out.println(m);
		for(int cou = 0; cou < m; cou ++ ){
			System.out.print(arrayG[cou]);
			if( cou <= num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		System.out.println(cnt);
		for(int cou = 0; cou < num; cou ++ ){
			System.out.println(array[cou]);
		}
	}
	
}




Measured memory_bytes: 299332
#include <cstdio>
#include <cstring>
const int MAXN = 1001;
const int mo = 1e9+7;
typedef long long LL;
struct Matrix
{
	int d[2][2];
	Matrix()
	{
		memset(d, 0, sizeof(d));
	}
	Matrix(int a0, int a1, int a2, int a3)
	{
		d[0][0] = a0;
		d[0][1] = a1;
		d[1][0] = a2;
		d[1][1] = a3;
	}
	int* operator [] (const int idx)
	{
		return d[idx];
	}
	Matrix operator * (Matrix &s) const
	{
		Matrix res;
		for(int k,j,i=0; i<2; ++i)
			for(j=0; j<2; ++j)
				for(k=0; k<2; ++k)
					res[i][j] = (res[i][j] + LL(d[i][k]) * s[k][j]) % mo;
		return res;
	}
	Matrix operator ^ (LL y) const;
}I(1, 0, 0, 1);
Matrix Matrix::operator ^ (LL y) const
{
	Matrix res = I, x = *this;
	while (y)
	{
		if(y&1)
			res = res * x;
		x = x * x;
		y >>= 1;
	}
	return res;
}
char map[MAXN][MAXN];
int main()
{
	int N, M, i, j;
	LL K;
	scanf("%d%d%lld", &N, &M, &K);
	int a = 0, b = 0, c = 0, d = 0, cnt = 0;
	for(i=0; i<N; ++i)
	{
		scanf("%s", map[i]);
		for(j=0; j<M; ++j)
			if(map[i][j] == '#')
				++cnt;
			else
				map[i][j] = 0;
	}
	for(i=0; i<N; ++i)
	{
		if(map[i][0] && map[i][M-1])
			++a;
		for(j=1; j<M; ++j)
			if(map[i][j] && map[i][j-1])
				++b;
	}
	for(j=0; j<M; ++j)
	{
		if(map[0][j] && map[N-1][j])
			++c;
		for(i=1; i<N; ++i)
			if(map[i][j] && map[i-1][j])
				++d;
	}
	int A, B, C;
	if (a && c)
		A = 1, B = 0, C = 0;
	else if(!a && !c)
		A = cnt, B = 0, C = 0;
	else if(a && !c)
		A = cnt, B = b, C = a;
	else
		A = cnt, B = d, C = c;
	Matrix res = I, s(A, -B, 0, C);
	res = res * s ^ (K-1);
	printf("%d\n", ((res[0][0] + res[0][1]) % mo + mo) % mo);
}

Measured memory_bytes: 1280
H,W,K = map(int,input().split())
cnt = 0
d = [[0]*(W) for _ in range(H)]
h = [0]*H
w = [0]*W
for i in range(H):
    A = input()
    for j in range(len(A)):
        if A[j]=='#':
            cnt += 1
            d[i][j] = 1
            h[i] += 1
            w[j] += 1
ans = 0
for i in range(2**H):
    I = bin(i)[2:]
    I = I.zfill(H)
    for j in range(2**W):
        J = bin(j)[2:]
        J = J.zfill(W)
        tmp = cnt
        for k in range(len(I)):
            if I[k]=='1':
                tmp-=h[k]
        for l in range(len(J)):
            if J[l] =='1':
                tmp-=w[l]
        for k in range(len(I)):
            for l in range(len(J)):
                if I[k]=='1' and J[l]=='1':
                    tmp += d[k][l]
        if tmp ==K:
            ans += 1
print(ans)

                





Measured memory_bytes: 68848
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


class Program{
    public static void Main(){
        string S = Console.ReadLine();
        string T = Console.ReadLine();

        for(int i = 0; i < S.Length; i++){
            if(S == T){
                WriteLine("Yes");
                return;
            }
            else{
                string S_sub = S.Remove(0, 1);
                S = S_sub + S[0];
            }
        }
        WriteLine("No");
    }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li h, w, n;
li leftmost_obj[200200];

int main() {
    cin >> h >> w >> n;
    rep(i, 200200) {
        leftmost_obj[i] = INF;
    }
    rin{
        li x, y;
        cin >> x >> y;
        leftmost_obj[x] = min(leftmost_obj[x], y);
    }

    li high = 1;
    repp(i, 1, h) {
        if (leftmost_obj[i + 1] <= high) {
            cout << i << endl;
            return 0;
        }
        if (high < w && leftmost_obj[i + 1] > high + 1) {
            high++;
        }
    }
    cout << h << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

int main() {
    int H, W;
    cin >> H >> W;
    int cnt = 0;
    vector<vector<char>> G(H, vector<char>(W));
    vector<pint> flip;
    rep(i, H) {
        rep(j, W) {
            cin >> G[i][j];
            if (G[i][j] == '.')
                cnt++;
            else
                flip.push_back({i, j});
        }
    }

    ll ans = 0;
    int dx[4] = {1, 0, 0, -1};
    int dy[4] = {0, 1, -1, 0};
    while (cnt != 0) {
        vector<pint> A;
        rep(i, flip.size()) {
            for (int j = 0; j < 4; j++) {
                pint p = flip[i];
                int ny = p.first + dy[j];
                int nx = p.second + dx[j];
                if (ny < 0 || nx < 0 || ny >= H || nx >= W)
                    continue;
                if (G[ny][nx] == '#')
                    continue;
                G[ny][nx] = '#', cnt--, A.push_back({ny, nx});
            }
        }
        ans++;
        flip = A;
    }

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

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

int main() {
  string s;
  cin >> s;
  
  if (s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 3564
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array


void solve(){
    string n;
    cin >> n;
    int sum = 0;
    for(char c : n) sum += (int)c - 48;
    if(sum%9==0) cout << "Yes\n";
    else cout << "No\n";
}

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

    int TC = 1;
    while(TC--)
        solve();        
    
    return 0;
}



Measured memory_bytes: 3740
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int n;
	int max = 0;
	int a[2][100];
	int i, j;
	int sum[2] = { 0 };
	int sum0;
	scanf("%d", &n);
	for (i = 0; i < 2; ++i){
		for (j = 0; j < n; ++j){
			scanf("%d", &a[i][j]);
			sum[i] += a[i][j];
		}
	}
	sum0 = a[0][0] + sum[1];
	for (i = 0; i < n; ++i){
		if (sum0 > max)max = sum0;

		sum0 = sum0 - a[1][i] + a[0][i + 1];
	}
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 128
N,y=map(int,input().split())
m=0
for i in range(N+1):
  if m==-1:
    break
  for j in range(N-i+1):
    k=N-i-j
    if 10000*i+5000*j+1000*k==y:
      print(i,j,k)
      m=-1
      break
if m==0:
  print(-1,-1,-1)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2182>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(string& S){
    for(auto& c:S) c -= '0';
    ll res = 0;
    vector<vector<ll>> dp(S.length()+1,vector<ll>(11,0));
    if(S[0]!=0)dp[0][S[0]] = 1;
    
    for(int i = 1; i < S.length();i++){
        for(int j = 0; j < 11; j++){
            dp[i][(j*10+S[i])%11] += dp[i-1][j];
        }
        if(S[i]!=0) dp[i][S[i]]++;
    }
    for(int i = 0;i < S.length();i++){
        res += dp[i][0];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string S;
    while(true){
        cin >> S;
        if(S == "0") break;
        cout << solve(S) << endl;
    }
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  int k[n], s[n];
  string ss = "";
  rep(i, n) {k[i] = 1; s[i] = 0; ss = ss + 'a';}
  cout << ss << endl;
//  printf("%s", s);
  while (s[n-1] < n-1) {
    int p = n-1;
    while ((p > 0) && (k[p-1] <= s[p])) {
      s[p] = 0;
      p--;
    }
    s[p]++;
    for (int i = p; i < n; i++) k[i] = max(k[i-1], s[i]+1);
    //convert s to string
    ss = "";
    rep(i, n) {
      if (s[i] == 0) ss = ss + 'a';
      else if (s[i] == 1) ss = ss + 'b';
      else if (s[i] == 2) ss = ss + 'c';
      else if (s[i] == 3) ss = ss + 'd';
      else if (s[i] == 4) ss = ss + 'e';
      else if (s[i] == 5) ss = ss + 'f';
      else if (s[i] == 6) ss = ss + 'g';
      else if (s[i] == 7) ss = ss + 'h';
      else if (s[i] == 8) ss = ss + 'i';
      else if (s[i] == 9) ss = ss + 'j';
    }
    cout << ss << endl;
  }
  return 0;
}


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

const double PI=acos(-1.0);

int main()
{
    int i,j,k;
    int x,y;
    int n;
    cin>>n;
    for(n;n<1000;n++){
        k=n%10;
    for(x=1,i=n;i!=0;)
    {
        j=i%10;
        i/=10;
        if(k!=j){
              x=0;
               break;
        }
    }
    if(x==1){cout<<n<<endl;
    break;}
    }
  return 0;
}


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

int main() {
  int N, sum;
  cin >> N;
  sum = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += (r - l) + 1;
  }
  cout << sum << endl;
}

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

int abs (int a, int b) {
  return (a > b) ? (a - b) : (b - a);
}

int main () {
  int n;
  cin >> n;
  int h[n], dp[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    dp[i] = 10000000000;
  }
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= 2; j++) {
      if (i - j >= 0) {
        dp[i] = min(dp[i], dp[i - j] + abs(h[i], h[i - j]));
      }
    }
  }
  cout << dp[n - 1] << endl;
                    
      
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;
ll dp[100001][14];

signed main() {
    string S; cin >> S;
    rep(i,100001) rep(j,13) dp[i][j]=0;
    dp[0][0]=1;
    rep(i,S.size()){
        rep(j,10){
            if(j!=(int)S[i]-'0' && S[i]!='?') continue;
            rep(k,13){
                dp[i+1][(k*10+j)%13] += dp[i][k];
            }
        }
        rep(j,13){
            dp[i+1][j]%=1000000007;
        }
    }
    cout << dp[S.size()][5] << endl;
}

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

typedef long long ll;


int main(){
    int N;
    cin >> N;
    ll dp[N+1];

    for(int i = 0; i <= N; i++){
        dp[i] = i;
    }

    for(int i = 0; i < N; i++){
        // 1
        if(i+1 <= N){
            dp[i+1] = min(dp[i+1], dp[i] + 1);
        }
        // 6
        int add = 6;
        while(i+add <= N){
            dp[i + add] = min(dp[i+add], dp[i] + 1);
            add *= 6;
        }
        add = 9;
        while(i+add <= N){
            dp[i + add] = min(dp[i+add], dp[i] + 1);
            add *= 9;
        }
    }

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


Measured memory_bytes: 1024
N = gets.to_i
(t, a) = gets.split(/ /).map(&:to_i)
H = gets.split(/ /).map(&:to_i)

min = 99999999.9999
minX = nil

H.each_with_index do |x, i|
  b = ((t - x * 0.006) - a).abs
  if b < min
    min = b
    minX = i
  end
end

p minX + 1

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  char odd[] = {'R', 'U', 'D'};
  char even[] = {'L', 'U', 'D'};
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    bool ok = false;
    if(i % 2 == 0){
      for(int j = 0; j < 3; j++){
        if(s[i] == odd[j]){
          ok = true;
        }
      }
    }else{
      for(int j = 0; j < 3; j++){
        if(s[i] == even[j]){
          ok = true;
        }
      }
    }
    if(!ok){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}






Measured memory_bytes: 256
#include <algorithm>
#include <stack>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <utility>
#define MAX_N 100000+10

using namespace std;

typedef pair<int, int> PD;

PD pds[(MAX_N)*2];

bool visited[MAX_N];
int R,C,N;

bool isOnRim(int a,int b){
  return (a==0||a==R)||(b==0||b==C);
}

int transform(int x,int y){
  if(x==0) {
    return y;
  }
  if(y==C) {
    return C+x;
  }
  if(x==R) {
    return C+R+(C-y);
  }
  if(y==0) {
    return C+R+C+(R-x);
  }
  abort();
}

int main() {
  scanf("%d%d%d", &R, &C, &N);
  int it=0;
  for(int i=0;i<N;++i) {
    int x1,x2,y1,y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    //transform
    if(isOnRim(x1, y1) && isOnRim(x2,y2)) {
      pds[it].first = transform(x1,y1);
      pds[it].second=i;
      it++;
      pds[it].first = transform(x2,y2);
      pds[it].second=i;
      it++;
    } else {
      continue;
    }
  }
  fill(visited, visited+N, false);

  sort(pds,pds+it);

  stack<PD> stackPD;
  for(int i=0;i<it;++i) {
    if(visited[pds[i].second]) {
      PD pd=stackPD.top();
      if(pd.second==pds[i].second){
        stackPD.pop();
      }else{
        printf("NO");
        return 0;
      }
    }else{
      stackPD.push(pds[i]);
      visited[pds[i].second]=true;
    }
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb(a) push_back(a)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
using vP = vector<P>;
const int INF = 1001001001;

int main(){
    int n;
    cin>>n;
    
    vector<int64_t> a(n);
    //map<int,ll> m;
    rep(i,n)cin>>a[i], a[i]--;
    
    vector<int64_t> m(n,0);
    rep(i,n)m[a[i]]++;
    
    int64_t ans = 0;
    /*
    for(auto p: m){
        ans += p.second*(p.second-1)/2;
    }
    */
    
    rep(i,n)ans += m[i]*(m[i]-1)/2;
    
    for(int i=0; i<n; i++){
        cout << ans -( m[a[i]] - 1 ) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(void)
{
	int n,a,max,box,i,cnt;
	max=-1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		cnt=0;
	    box=i;
		while(box%2==0){
			box=box/2;
			cnt++;
		}
		if(cnt>max){
			max=cnt;
			a=i;
		}
	}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

int main(){
    int N; cin >> N;
    vector<int> a(N), b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    ll ans = 0;
    REP(i,29) {
        int cnt = 0;
        vector<int> b1, b2;
        REP(j,N) {
            if((b[j]>>i)&1) b1.push_back((b[j]&((1<<i)-1)));
            else b2.push_back((b[j]&((1<<i)-1)));
        }
        sort(all(b1));
        sort(all(b2));
        REP(j,N) {
            int x = (a[j]&((1<<i)-1)); 
            if((a[j]>>i)&1) {
                int t1 = b1.end() - lower_bound(all(b1),(1<<i)-x);
                int t2 = lower_bound(all(b2),(1<<i)-x) - b2.begin();
                cnt = (cnt+t1+t2)%2;
            }
            else {
                int t1 = lower_bound(all(b1),(1<<i)-x) - b1.begin();
                int t2 = b2.end() - lower_bound(all(b2),(1<<i)-x);
                cnt = (cnt+t1+t2)%2;
            }
        }
        // cout << cnt << endl;
        if(cnt) ans |= (1LL<<i);
    }
    //REP(i,10) cout << (15&((1<<i)-1)) << ' '; cout << endl;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  puts(b-a==c-b ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()

bool_list = [[True,True],[True,False],[False,True],[False,False]]

flag=False
for boo in bool_list:
    ans_list = list(boo)
    for i in range(1,N):

        if S[i]=="o":
            if ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
        else:
            if not ans_list[i]:
                if ans_list[i-1]:
                    ans_list.append(True)
                else:
                    ans_list.append(False)
            else:
                if ans_list[i-1]:
                    ans_list.append(False)
                else:
                    ans_list.append(True)
    
    if S[0]=="o":
        if ans_list[0]:
            if ans_list[1]:
                N_cand=True
            else:
                N_cand=False
        else:
            if ans_list[1]:
                N_cand=False
            else:
                N_cand=True
    else:
        if not ans_list[0]:
            if ans_list[1]:
                N_cand=True
            else:
                N_cand=False
        else:
            if ans_list[1]:
                N_cand=False
            else:
                N_cand=True
    
    if ans_list[0]==ans_list[N] and N_cand==ans_list[N-1]:
        flag=True
        break

if flag:
    ans=""
    for a in ans_list[:-1]:
        if a:
            ans+="S"
        else:
            ans+="W"
    print(ans)
else:
    print(-1)

Measured memory_bytes: 4996
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, a[200005] = {}, ans = 0;
bool exist[1000005] = {};

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	stable_sort(a, a + n);
	rep(i, n) {
		bool ok = true;
		if ((i > 0 && a[i] == a[i - 1]) || (i < n - 1 && a[i] == a[i + 1])) {
			exist[a[i]] = true;
			continue;
		}
		for (int j = 1; j * j <= a[i]; j++) {
			if (!(a[i] % j) && (exist[j] || exist[a[i] / j])) {
				ok = false;
				break;
			}
		}
		if (ok)ans++;
		exist[a[i]] = true;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{	
	int n, a, b;

	cin >> n;
	
	while (n > 0) {
		a = 0;
		b = 0;

		for (int i = 0; i < n; i++) {
			int pa, pb;
			cin >> pa >> pb;

			if (pa > pb)
				a += pa + pb;
			else if (pa < pb)
				b += pa + pb;
			else {
				a += pa;
				b += pb;
			}
		}
		cout << a << " " << b << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3088
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    double L;
    cin >> L;
    double K;
    K = (L/3.0)*(L/3.0)*(L/3.0);
    cout << fixed;
    cout << setprecision(12) << K << endl;
     
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] s = str.split(" ");

		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int c = Integer.parseInt(s[2]);

		int count = 0;
		if((0 < a) && (0 < b) && (0 < c) && (a <= 10000) && ( b <= 10000) && (c <= 10000)){
			while(a <= b){
				if((c % a)== 0){
					count++;
					a++;
				}else{
					a++;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24472
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let p: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut ans = 0;
    for p in p.windows(3) {
        if (p[0] < p[1] && p[1] < p[2]) || (p[0] > p[1] && p[1] > p[2]) {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for i in op:
        for j in op:
            for k in op:
                for ii in n:
                    m = [0,1,2,3]
                    m.remove(ii)
                    for jj in m:
                        l = [0,1,2,3]
                        l.remove(ii);l.remove(jj)
                        for kk in l:
                            o = [0,1,2,3]
                            o.remove(ii);o.remove(jj);o.remove(kk)
                            for ll in o:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0

Measured memory_bytes: 4340
#include <iostream>
#include <stdio.h>
#define llint long long

using namespace std;

llint n, m;
llint a[25], p[25];
double pro[1<<20];
llint num[1<<20], num2[1<<20]; 

void moebius_transform(llint a[], int n)
{
	int S = 1<<n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < S; j++){
			if(!(j&(1<<i))) a[j] -= a[j^(1<<i)];
		}
	}
}

void zeta_transform(llint a[], int n)
{
	int S = 1<<n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < S; j++){
			if(!(j&(1<<i))) a[j] += a[j^(1<<i)];
		}
	}
}

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

llint lcm(llint a, llint b)
{
	llint ret = a / gcd(a, b);
	if(ret >= m / b + 1) return m+1;
	return ret*b;
}

int main(void)
{
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> p[i];
	
	llint S = 1<<n;
	for(int i = 0; i < S; i++){
		llint l = 1;
		for(int j = 0; j < n; j++){
			if(i&(1<<j)){
				l = lcm(l, a[j]);
			}
		}
		num[i] = m / l;
	}
	moebius_transform(num, n);
	
	for(int i = 0; i < S; i++) num2[i] = num[i^(S-1)];
	zeta_transform(num2, n);
	for(int i = 0; i < S; i++) num[i] = m - num2[i];
	
	for(int i = 0; i < S; i++){
		double mul = 1;
		for(int j = 0; j < n; j++){
			if(i&(1<<j)) mul *= p[j]/100.0;
			else mul *= (100-p[j])/100.0;
		}
		pro[i] = mul;
	}
	
	double ans = 0;
	for(int i = 0; i < S; i++) ans += pro[i] * num[i];
	printf("%.11f\n", ans);
	
	return 0;
}


Measured memory_bytes: 27808
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define vel vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int n, k; cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var H, W int

func main() {
	fmt.Scan(&H, &W)
	reader := bufio.NewReaderSize(os.Stdin, 10000000)

	q := make([][]int, 0)
	m := make([][]int, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]int, W)

		for j := 0; j < W; j++ {
			if string(line[j]) == "#" {
				m[i][j] = 1
				q = append(q, []int{i, j})
			}
		}
	}
	fmt.Println(bfs(q, m) - 1)
}

func bfs(q [][]int, m [][]int) (ans int) {

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			y, x := q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == 0 {
				m[y+1][x] = 1
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == 0 {
				m[y-1][x] = 1
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == 0 {
				m[y][x+1] = 1
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == 0 {
				m[y][x-1] = 1
				q = append(q, []int{y, x - 1})
			}
		}

	}
	return
}

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

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

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


Measured memory_bytes: 133376
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int k = Integer.parseInt(input[1]);

        int remain = n - k;
        if (remain < 0) {
            System.out.println(0);
            return;
        }

        List<Long> hpList = new ArrayList<>();
        for (String hp : sc.nextLine().split(" ")) {
            hpList.add(Long.parseLong(hp));
        }

        Collections.sort(hpList);
        Collections.reverse(hpList);
        List<Long> remainedEnemies = hpList.subList(hpList.size() - remain, hpList.size());

        long sum = 0;
        for (Long remainedEnemy : remainedEnemies) {
            sum += remainedEnemy.intValue();
        }

        System.out.println(sum);
    }
}

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  int count=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int j=a[0];
  for(int i=0;i<n;i++){
    count++;
    if(j==2){
      cout<<count<<endl;
      break;
    }
    j=a[j-1];
    if(count==n){
      cout<<-1<<endl;
    }
  }
  }

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9+7
using namespace std;
typedef long long ll;


int main() {
  ll N, K;
  cin >> N >> K;
  
  vector<ll> h(N);
  for (int i = 0; i < N; i++) {
    ll t;
    cin >> t;
    h[i] = t;
  }
  
  vector<ll> c(N, INF);
  c[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= K && i+j < N; j++) {
      c[i+j] = min(c[i+j], c[i] + abs(h[i] - h[i+j]));
    }
  }

  cout << c[N-1] << endl;
  
  return 0;
}

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

int main(){
    ll n,k;
    std::cin >> n>>k;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        sum += a[i];
    }
    priority_queue<ll> divq;
    for (int i = 1; i <= sqrt(sum); i++) {
        if(sum%i==0){
            divq.push(i);
            divq.push(sum/i);
        }
    }
    
    while(!divq.empty()){
        ll d = divq.top();
        divq.pop();
        vector<ll> nowa(n);
        for (int i = 0; i < n; i++) {
            nowa[i] = a[i]%d;
        }
        sort(nowa.begin(),nowa.end());
        vector<ll> sumr(n+1);
        vector<ll> rsumr(n+1);
        sumr[0] = 0;
        rsumr[0] = 0;
        for (int i = 0; i < n; i++) {
            sumr[i+1] = sumr[i] + nowa[i]; 
            rsumr[i+1] = rsumr[i] + (d-nowa[i])%d;
        }
        for (int i = 0; i <= n; i++) {
            ll left,right;
            left = sumr[i];
            right = rsumr[n] - rsumr[i];
            if(left == right && left <= k){
                std::cout << d << std::endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>                                             
#include <queue>                                                
using namespace std;                                            
int main() {                                                    
  int n, q;                                                     
  cin >> n >> q;                                                
  queue< pair<string,int> > que;                                
  for (int i=0; i<n; i++) {                                     
    string name;                                                
    int t;                                                      
    cin >> name >> t;                                           
    que.push(make_pair<string,int>(name,t));                    
  }                                                             
  int count = 0;                                                
  while (!que.empty()) {                                        
    pair<string,int> p = que.front();                           
    que.pop();                                                  
    if (p.second<=q) {                                          
      count += p.second;                                        
      cout << p.first << " " << count << endl;                  
    } else {                                                    
      p.second -= q;                                            
      count += q;                                               
      que.push(p);                                              
    }                                                           
  }                                                             
  return 0;                                                     
}                                                               
                     

Measured memory_bytes: 6332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define COUT(a) cout << (a);
#define ENDL cout << "\n";
int main() {
    int a[4] = {0},tmp1,tmp2,count1=0,count2=0;
    for(int i=0;i<3;i++) {
        scanf("%d %d\n",&tmp1,&tmp2);
        a[tmp1-1]++;
        a[tmp2-1]++;
    }
    REP(i,4) {
        if(a[i] == 1) count1++;
        else if(a[i] == 2)count2++;
    }
    if(count1==2 && count2==2) COUT("YES")
    else COUT("NO")
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

    int a, b, x;

    cin >> a >> b >> x;

    if( a > x ){
        cout << "NO";
        return 0;
    }else{

        if( b < x - a ){
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, m = ns()
    e = [[] for _ in range(n)]
    root = [True for _ in range(n)]
    prnt_cnt = [0 for _ in range(n)]
    ans = [-1 for _ in range(n)]

    for _ in range(n - 1 + m):
        a, b = ns()
        a, b = a - 1, b - 1
        e[a].append(b)
        root[b] = False
        prnt_cnt[b] += 1

    root_idx = root.index(True)

    que = collections.deque([root_idx])

    while que:
        q = que.popleft()

        for ei in e[q]:
            ans[ei] = q
            prnt_cnt[ei] -= 1
            if prnt_cnt[ei] == 0:
                que.append(ei)

    for ansi in ans:
        print(ansi + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 100376