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

#define   ll    long long int

const ll inf = 3234566667LL;
vector<ll> v;

void solve(ll num)
{
    if (num > inf) {
        return ;
    }
    v.push_back(num);
    ll d = num % 10;
    solve(num * 10 + d);
    if (d >= 1) solve(num * 10 + (d - 1));
    if (d < 9) solve(num * 10 + (d + 1));
}

int main( )
{
    for (int i = 1; i < 10; i++) {
        solve(i);
    }
    sort(v.begin(), v.end());
    int n;
    cin >> n;
    cout << v[n - 1] << '\n';
    return 0;
}


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

int main(){
    int a[5];
    int k;


    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            if(a[j] - a[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b, count;
    
    cin >> a >> b;
    count = 0;
    if(a > b){
        count = count + a;
        a = a - 1;
    }else{
        count = count + b;
        b = b -1;
    }
    if(a > b){
        count = count + a;
    }else{
        count = count + b;
    }
    printf("%d\n", count);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        puts("ARC");
    }else{
        puts("ABC");
    }
    return 0;
}

Measured memory_bytes: 3620
class fenwick_tree():
    def __init__(self, n:int, mod:int = 0):
        self.__mod = mod
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        if(self.__mod == 0):
            self.__add_mod0(p,x)
        else:
            self.__add_mod(p,x)

    def __add_mod0(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def __add_mod(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            self.__data[p-1] %= self.__mod
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        if(self.__mod == 0):
            return self.__sum_mod0(r) - self.__sum_mod0(l)
        else:
            return self.__sum_mod(r) - self.__sum_mod(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s

    def __sum_mod(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            s %= self.__mod
            r -= r & -r
        return s

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))


Measured memory_bytes: 252904
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a, b,c; CI a >> b>>c;
	CO(a - b) % c EN;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  ivec x(n), y(m);
  REP(i, n) cin >> x[i];
  REP(i, m) cin >> y[i];

  sort(RALL(x));
  sort(ALL(y));

  if (x[0] < y[0] && X < Y && x[0] >= X && y[0] < Y) {
    print("No War");
  } else {
    print("War");
  }
  return 0;
}

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

//#if DEBUG && !ONLINE_JUDGE
    //#include "header.h"
//#else
    //#define debug(args...)
//#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
    return;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preprocess();
    int n; cin>>n;
    vi a(n+1), b(n);
    rep(i,0,n+1) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    lli ans = 0;
    rep(i,0,n) {
        if(a[i] + a[i+1] <= b[i]) {
            ans += a[i] + a[i+1];
            a[i+1] = 0;
        }
        else if(a[i] <= b[i]) {
            ans += b[i];
            a[i+1] -= b[i] - a[i];
        }
        else {
            ans += b[i];
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#ABC140D
N,K = map(int,input().split())
S = input()

p1 = p2 = cnt = 0
for i in range(N-1):
    if S[i] == 'L' and S[i+1] == 'R':
        p1 += 1
    if S[i] == 'R' and S[i+1] == 'L':
        p2 += 1
    if S[i] == 'R' and S[i+1] == 'R':
        cnt += 1
    if S[i] == 'L' and S[i+1] == 'L':
        cnt += 1
#print(cnt,p1,p2)
a1 = min(p1,p2,K)
ans = a1*2 + cnt
if K > a1:
    a2 = min(max(p1,p2)-a1,K-a1)
    ans += a2

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>

using namespace std;

int main(){
    string str;
    int n=0,ans=0;;

    cin >> str;

    for(int i=0;i<str.size();i++){
        if(str[i]=='S'){
            n++;
        }else if(str[i]=='T'){
            if(n==0){
                ans++;
            }else{
                n--;
            }
        }
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 644
import java.util.*
//import kotlin.math.*
 
private fun readString() = readLine()!! // string line
private fun readInt() = readString().toInt() // single int
private fun readLong() = readString().toLong()
private fun readStrings() = readString().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
 
val INF = 1000000000
 
fun main(args: Array<String>)
{
    var n = readInt()
	var m = 1
	for (i in 1..n) m *= 2
	var a = readInts().toTypedArray()
	var H = TreeMap<Int, Int>()
	for (x in a)
	{
		H.set(x, (H[x]?:0)+1)
	}
	
	var b = ArrayList<Int>()
	var x = H.lastKey()
	b.add(x)
	H.set(x, H[x]!!-1)
	if (H[x] == 0) H.remove(x)
	
	var ret = 0
	var s = 1
	for (k in 1..n)
	{
		for (i in 0..s-1)
		{
			var cur = H.lowerKey(b[i])
			if (cur == null)
			{
				print("No")
				return
			}
			b.add(cur)
			H.set(cur, H[cur]!!-1)
			if (H[cur] == 0) H.remove(cur)
		}
		s *= 2
	}
	
	print(if (ret == 0) "Yes" else "No")
}


Measured memory_bytes: 111096
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if(a<b) cout << "0" << endl;
  else{
    vector<int> vec(a);
  for(int i=0;i<a;i++){
   cin >> vec.at(i);
  }
    sort(vec.begin(), vec.end());
   long int count = 0;
    for(int j=0;j<a-b;j++){
    count += vec.at(j);
    }
  cout << count << endl;
    return 0;
  }
}

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

int main(){
    char a[2000000];
    int i=0;
    while(1){
        cin >> a[i];
        if(a[i]==NULL){
            break;
        }
        i++;
    }
 
    int len = strlen(a);
    long int sum=0;
    for(int  j=0;j<len;j++){
        sum +=a[j]-'0';
    }

    if(sum%9==0){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
}


Measured memory_bytes: 3780
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9) + 7


n,m=mdata()
Group = [i for i in range(n + 1)]
Nodes = [1] * (n + 1)

def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(x, y):
    if find(x) != find(y):

        if Nodes[find(x)] < Nodes[find(y)]:
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)

        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(m):
    x, y = mdata()
    Union(x, y)
d=dd(int)
for i in range(1,n+1):
    d[find(i)]+=1
out(max(d.values()))

Measured memory_bytes: 123824
# -*- coding: utf-8 -*-
import numpy as np

K = int(input())

a = np.ones(50).astype(np.int64)*(49) + (K)//50


if K%50 != 0:
    a[:K%50] += 51 - (K%50)
    a[K%50:] -= (K%50)
else:
    pass
                
result = "50\n{}".format(a[0])
for a_ in a[1:]:
    result += (" {}".format(int(a_)))
print(result)

Measured memory_bytes: 12504
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if (x-r < 0 || y-r <0 || x + r > W || y + r > H)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2112
N = int(input())
A = list(map(int,input().split()))
Odd = 0
Even = 0
for Ai in A:
    if Ai % 2 == 0:
        Even += 1
    else:
        Odd += 1
if Odd % 2 == 1:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 85552
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i=(a); i < (b); ++i)
#define pb push_back
#define fs first
#define sc second
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const double EPS = 1e-9;

struct unionfind { vi p; int c;
  unionfind(int n) : p(n, -1), c(n) { }
  int find(int x) { return p[x] < 0 ? x : p[x] = find(p[x]); }
  bool united(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) { int a = find(x), b = find(y);
    if(a == b) return; if(p[a] > p[b]) swap(a, b);
    p[a] += p[b]; p[b] = a; c--; return; }
  int size(int x) { return -p[find(x)]; } };

int main() {
    cin.sync_with_stdio(false);
    int n, m, ai, bi; cin >> n >> m;
    unionfind uf(n);
    rep(i,0,m) {
        cin >> ai >> bi;
        ai--; bi--;
        uf.unite(ai, bi);
    }
    cout << uf.c - 1 << '\n';
}


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

char map[20][20];
int W, H;
int sh, sw;
int dw[4] = {-1, 0, 1, 0};
int dh[4] = {0, 1, 0, -1};
int cnt;

void print_map(){
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << map[i][j];
    }
    cout << endl;
  }
}

void solve(int w, int h){
  map[h][w] = '#';
  cnt++;
  for(int i = 0; i < 4; i++){
    int nh = h + dh[i], nw = w + dw[i];
    if(0 <= nh && nh < H && 0 <= nw && nw < W && map[nh][nw] == '.') solve(nw, nh);
  }
  return;
}

int main(void){
  while(true){
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    cnt = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> map[i][j];
        if(map[i][j] == '@'){
          sh = i;
          sw = j;
        }
      }
    }
    solve(sw, sh);
    cout << cnt << endl;
  }
  return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){

    ll a,b  ;
    cin >>   a >> b;
    ll ans = max(a+b,a*b);
    ans = max(ans,a-b);

    cout <<  ans ;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect, bisect_left
from itertools import accumulate

def main():
    def check(x):
        count = 0
        for a in aaa:
            if x <= a:
                count += n
            else:
                count += n - bisect_left(aaa, x - a)
        return count >= m
    
    
    n, m = map(int, input().split())
    aaa = list(map(int, input().split()))
    aaa.sort()
    acc = [0] + list(accumulate(aaa))
    sum_a = acc[-1]
    
    l, r = 0, 200001
    while l + 1 < r:
        mid = (l + r) // 2
        if check(mid):
            l = mid
        else:
            r = mid
    
    # 合計がlより大きい組み合わせの和と組数を求める→Mに足りない分だけ合計がlの組を採用
    ans = 0
    count = 0
    for a in aaa:
        if l <= a:
            ans += sum_a + a * n
            count += n
        else:
            omit = bisect(aaa, l - a)
            if omit < n:
                ans += sum_a - acc[omit] + a * (n - omit)
                count += n - omit
    ans += l * (m - count)
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 56992
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N;
vector<vector<int> > g;

int dfs(int u,int p){
    int match = 0;
    REP(i, g[u].size()){
        if(g[u][i]==p)continue;
        int child = dfs(g[u][i], u);
        if(child<0)return -1;
        if(child==0){
            if(match)return -1;
            match = 1;
        }
    }
    return match;
}

int main(){
    cin >> N;
    g.assign(N, vector<int>());
    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << (dfs(0, -1)==1 ? "Second" : "First") << endl;
    return 0;
}


Measured memory_bytes: 7168
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int>;
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int a, b;
    cin >> a >> b;
    if(a > b)
    {
        swap(a, b);
    }
    while(b--)
    {
        cout << a;
    }
    cout << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

const ll MOD = 1e9+7;

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;

    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(){

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

    ll n, a, b; cin >> n >> a >> b;

    ll total = (mod_pow(2, n, MOD) + MOD - 1) % MOD;

    ll nca_numerator = 1;
    reps(i, n - a + 1, n + 1){
        nca_numerator = (nca_numerator * i) % MOD;
    }
    ll ncb_numerator = 1;
    reps(i, n - b + 1, n + 1){
        ncb_numerator = (ncb_numerator * i) % MOD;
    }

    ll nca_denominator = 1;
    reps(i, 1, a + 1){
        nca_denominator = (nca_denominator * i) % MOD;
    }
    ll ncb_denominator = 1;
    reps(i, 1, b + 1){
        ncb_denominator = (ncb_denominator * i) % MOD;
    }

    ll nca_denom_inverse = mod_pow(nca_denominator, MOD - 2, MOD);
    ll ncb_denom_inverse = mod_pow(ncb_denominator, MOD - 2, MOD);

    ll nca = (nca_numerator * nca_denom_inverse) % MOD;
    ll ncb = (ncb_numerator * ncb_denom_inverse) % MOD;

    ll ans = (total - nca - ncb + 2 * MOD) % MOD;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	map<string, int> W;
	W["SUN"] = 7;
	W["MON"] = 6;
	W["TUE"] = 5;
	W["WED"] = 4;
	W["THU"] = 3;
	W["FRI"] = 2;
	W["SAT"] = 1;
	string s; cin >> s;
	cout << W[s] << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
flg = True
even = []
for i in a:
    if i % 2 == 0:
        even.append(i)    
for i in even:
    if i % 3 == 0 or i % 5 == 0:
        flg = True
    else:
        flg = False
        break
        
if flg:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
//circle,cpp
#include<iostream>
using namespace std;

int main(){

	int W, H, x, y, r, X, Y;
	cin>>W>>H>>x>>y>>r;

	X=W-x-r;
	Y=H-y-r;
	
	if(x>=r && y>=r && X>=0 && Y>=0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3104
'''
Created on 2020/09/03

@author: harurun
'''
from dataclasses import *
@dataclass
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
  import sys
  pin=sys.stdin.readline

  N,M=map(int,pin().split())
  uf=UnionFind(N)
  for i in range(M):
    A,B=map(int,pin().split())
    A-=1
    B-=1
    uf.union(A, B)

  ans=0
  for j in range(N):
    ans=max(ans,uf.size(j))
  print(ans)
  return

main()

#解説AC


Measured memory_bytes: 15900
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0



x,k=LI()
ans=x%k
ans=min(ans,abs(ans-k),x)
print(ans)


    
    

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
  if(A.size() == n+1){
    int now = 0;
    rep(i, q){
      if(A[b[i]] - A[a[i]] == c[i])now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main(){

  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

  dfs(vector<int>(1, 1));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
MAX_X = 10 ** 5
buffer = 10 ** 3
prime_flags = [1 for _ in range(MAX_X + buffer)]

for i in range(2, MAX_X + buffer):
  num = i
  if prime_flags[num] == 0:
    continue
  while num + i < len(prime_flags):
    num += i
    prime_flags[num] = 0

X = int(input().strip())
for i, flag in enumerate(prime_flags[X:]):
  if flag == 1:
    print(X + i)
    break
    


Measured memory_bytes: 4632
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
using namespace std;

int main()
{
    fip;
    char ch;
    ll i=0,cnt=0,ans=0;
    bool flag1=false,flag2=false,flag3=false;
    string s;
    cin>>s;
    while(i!=s.length())
    {
        ch=s[i];
        if(ch=='A')
        {
            if(flag3)
            {
                cnt=1;
                flag3=false;
                flag1=true;
                flag2=false;
            }
            else
            {
                flag1=true;
                flag2=false;
                cnt++;
            }
        }
        else if(ch=='B')
        {
            if(flag1)
            {
                flag1=false;
                flag2=true;
            }
            else
            {
                flag2=false;
                cnt=0;
            }
            flag3=true;
        }

        else
        {
            if(flag2)
            {
                flag2=false;
                flag3=false;
                flag1=true;
                ans+=cnt;
            }
            else
            {
                flag3=true;
                flag1=false;
                cnt=0;
            }
        }
        i++;
    }
    cout<<ans;
    return 0;
}


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

int main(){
    int K; cin >> K;

    vector<int> s;
    s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << s[K - 1] << endl;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll h,w;cin>>h>>w;
  auto v=vec(h,w,(string)"");
  rep(i,0,h)rep(j,0,w)cin>>v[i][j];
  rep(i,0,h)rep(j,0,w){
    if(v[i][j]=="snuke"){
      cout<<(char)(j+'A')<<i+1<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int ans=0;
    int x=0;
    for(int i=0;i<n;)
    {
        int count=0;
        int ind=i;
        while(i<n&&s[i]==s[ind])
        {
            i++;
            count++;
        }
        ans+=(count-1);
        x++;
    }
    if(x%2!=0)
    {
        int req=x/2;
        if(req<=k)
            ans+=req*2;
        else
            ans+=k*2;
    }
    else
    {
        int req=x/2-1;
        if(req<=k)
        {
            ans+=req*2;
            k-=req;
            if(k>0)
                ans++;
        }
        else
            ans+=k*2;
    }
    cout<<ans;
}

Measured memory_bytes: 512
#![allow(unused_macros, unused_imports, dead_code)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(N : i32);
    let mut A : Vec<i32> = read_vec();

    A.sort();

    let mut ans = 0;
    for i in 0..N {
        let index = (N - i - 1) as usize;
        if index % 2 == 0 {
            ans += A[i as usize];
        } else {
            ans -= A[i as usize];
        }
    }
    println!("{}", ans);
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    vector<P> a(N);
    for(int i=0;i<N;i++){
        int b; cin >> b;
        a[i]={b,i+1};
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        cout << a[i].second << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for (int b = 1; b <= n; b++) {
        if (b - k <= 0)
            continue;
        sum += (n / b) * (b - k);
        sum += max((int)0, n % b - k + 1);
    }
    if (k == 0) {
        sum -= n;
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
    int i, j, k, N;
    string S;
    cin >> N;
    cin >> S;
    ll count[24] = {0};
    for(i=0; i<N; i++){
        count[S[i]-'A']++;
    }
    ll r = count['R'-'A'];
    ll g = count['G'-'A'];
    ll b = count['B'-'A'];
    ll c = 0;

    for(i=0; i<N-2; i++) {
        for (j = i + 1; j < N - 1; j++) {
            k = 2 * j - i;
            if ( k < N && S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
                c++;
            }
        }
    }
    cout << r*b*g-c << endl;
    return 0;
}

Measured memory_bytes: 3644
// Contest: AtCoder Beginner Contest 153 (https://atcoder.jp/contests/abc153)
// Problem: C: Fennec vs Monster (https://atcoder.jp/contests/abc153/tasks/abc153_c)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cpp_lib_nonmember_container_access >= 201411
#   define sz(x) ((int)size(x))
#else
#   define sz(x) ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define all(a)         (a).begin(),(a).end()
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __has_cpp_attribute(maybe_unused) >= 201603
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18;
//endregion }}}

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

    int n, k; cin >> n >> k;
    vi h(n);
    trav(hi, h) cin >> hi;
    sort(all(h));
    ll s = 0;
    rep(i, max(0, n - k))
        s += h[i];

    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

a_pre = A[0]
A_new = [a_pre]
for a in A[1:]:
    if a != a_pre:
        A_new.append(a)
    a_pre = a


minimum = []
maximum = []
N_ = len(A_new)
for i in range(N_):
    max_ = []
    min_ = []
    if i<N_-1:
        s = A_new[i] < A_new[i+1]
        max_.append(not s)
        min_.append(s)
    if i>0:
        s = A_new[i] < A_new[i-1]
        max_.append(not s)
        min_.append(s)
    maximum.append(all(max_))
    minimum.append(all(min_))


stock = False
M = 1000
S = 0
a_pre = None
for max_, min_, a in zip(maximum, minimum, A_new):
    if ~stock and min_:
        S = M // a
        a_pre = a
        stock = True
    if stock and max_:
        M += S * (a-a_pre)
        S = 0

print(M)


Measured memory_bytes: 9260
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

bool check(vi &a, int l, int k) {
    int cost = 0;
    for (auto x : a) {
        cost += (x-1)/l;
    }
    return cost <= k;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    for (auto &x : a)
        cin >> x;

    int l = 0, r = 1000000001;
    while ((r - l) > 1) {
        int mid = (l + r)/2;
        if (check(a, mid, k))
            r = mid;
        else
            l = mid;
    }
    cout << r << "\n";

}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases


Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in); 
        while(true){
            int n = scan.nextInt();
            if(n==0){ break; }
            double[] s = new double[n];
            int i = 0;
            double sum = 0;
            double sumHensa = 0; 
            double ans = 0;

            for(i=0;i<n;i++){
                s[i] = scan.nextDouble();
                sum += s[i];
            }

            double average = (double) sum / n;

            for(i=0;i<n;i++){
                sumHensa += (s[i] - average) * (s[i] - average);
            }

            ans = Math.sqrt( (double) sumHensa / n );
            System.out.println(ans);
        }
        
    }

}


Measured memory_bytes: 40160
#include<bits/stdc++.h>
using namespace std;
#define N 50

int st[N];

bool comp(int a, int b)
{
	return a > b;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	
	for(int i = 0; i < n; ++i)
		scanf("%d", st+i);
	
	sort(st, st+n, comp);
	
	int sum = 0;
	for(int i = 0; i < k; ++i)
		sum += st[i];
	printf("%d\n", sum);
}


Measured memory_bytes: 256
function main(input) {
  const s = input.split(" ");

  const A = parseInt(s[0], 10)
  const B = parseInt(s[1], 10)
  const T = parseInt(s[2], 10)

  console.log(Math.floor(T / A) * B);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
int m[(1 << 26)];
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    memset(m,-1, sizeof m);
    string s;cin >> s;
//    unordered_map<int, int> m;

    m[0] = 0;
    int xr = 0;
    FOR(i, s.length()){
        xr  ^= (1 << (s[i] - 'a'));
        int ans= 1e9;
        for(int bi  = 0; bi < 26; bi++){
            if(m[xr ^ (1 << bi)] != -1){
                ans = min(ans, m[(xr ^ (1 << bi))] + 1);
            }
        }
        if(ans <= s.length()){
            if(xr != 0)m[xr]=ans;
        }
    }
    if(xr == 0)cout << 1;
    else cout << m[xr];
}




Measured memory_bytes: 262992
import Foundation
let rd = readLine()!.split(separator: " ").map({Int($0)!})
let a = readLine()!.split(separator: " ").map({Int($0)!}).sorted().reversed()
let start = a.startIndex
let end = a.index(a.startIndex, offsetBy: rd[1])
let sumArr = Array(a[start..<end])
print(sumArr.reduce(0,+))

Measured memory_bytes: 13656
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
	map<string, set<int>> m;
	string name;
	int num;

	while (cin >> name >> num) {
		if (m.count(name)) {
			m[name].insert(num);
		} else {
			m[name] = set<int>();
			m[name].insert(num);
		}
	}

	for (auto &one : m) {
		cout << one.first << endl;
		for (auto &index : one.second) {
			cout << index << (index == *(one.second.rbegin()) ? '\n' : ' ');
		}
	}

	return 0;
}

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

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

int main() {
  int x;
  cin >> x;
  if(x>=30){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
 
  return 0;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  int x; cin >> x;
  if(x>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int n = sc.nextInt();
            if(n == 0) break;
            int MAX = 0;
            int MIN = 10000;
            int sum = 0;
            for(int i = 0; i < n; i++){
                int x = sc.nextInt();
                sum += x;
                if(x >= MAX) MAX = x;
                if (MIN >= x) MIN = x;;
            }
            int ans = (sum - MAX - MIN)/(n-2);
            System.out.println(ans);
        }
        sc.close();
        
    }
}



Measured memory_bytes: 28784
#include <iostream>
using namespace std;
int main() {
	int n;
	scanf("%d",&n);
	if(n%2==1){
		cout<<"No";
		return 0;
	}
	string s,s1="",s2="";
	cin>>s;
	for(int i=0;i<n/2;i++) s1+=s[i]; 
	for(int i=n/2;i<n;i++) s2+=s[i]; 
	if(s1==s2) cout<<"Yes";
	else cout<<"No";
	return 0; 
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;

#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)

template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
const ll MAXN = 1e18;
const ll SIZE = 6e6 + 6;
const ll MOD  = 1e9 + 7;


string s, t;


int main() { speedhack()

	cin >> s;
	cin >> t;
	t.pop_back();
	if (s == t)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int tree[100005];
int lb(int x){
	return (x&(-x));
}
int n,m,k;
struct Li{int l,r;}a[200005];
struct Que{int l,r,id;}q[200005];
int ans[200005];
bool cmp1(Li a,Li b){return a.r<b.r;}
bool cmp2(Que a,Que b){return a.r<b.r;}
void modify(int x,int y){for (int i=x;i<=n;i+=lb(i))tree[i]+=y;}
int query(int x){int ans=0;for(int i=x;i;i-=lb(i))ans+=tree[i];return ans;}
int main(){
	n=read(),m=read(),k=read();
	for (int i=1;i<=m;i++){a[i].l=read();a[i].r=read();}
	sort(a+1,a+1+m,cmp1);
	for (int i=1;i<=k;i++){q[i].l=read();q[i].r=read();q[i].id=i;}
	sort(q+1,q+1+k,cmp2);
	int j=1,tot=0;
	for (int i=1;i<=k;i++){
		while (j<=m&&a[j].r<=q[i].r){ modify(a[j].l,1); j++; tot++; }
		ans[q[i].id]=tot-query(q[i].l-1);
	}
	for (int i=1;i<=k;i++)
	printf("%d\n",ans[i]);
	return 0;
} 

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int lmax = 0;
    int rmin = 100000 + 100000;

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int l, r;
        cin >> l >> r;
        lmax = std::max(l, lmax);
        rmin = std::min(r, rmin);
    }

    int ans = 0;
    if(lmax <= rmin){
        ans = rmin - lmax + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
int n,h,w,a[10001];
int ans[100][100];
int main(){
	cin>>h>>w>>n;
	int x=0,y=0,d=1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		for(int j=1;j<=a[i];j++){
			ans[x][y]=i;
			x+=d;
			if(x==h||x==-1){
				y++;
				x-=d;
				d*=-1;
			}
		}
	}
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cout<<ans[i][j]<<(j==w-1?"\n":" ");
	
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vint h(n);
  rep(i,n){
    cin>>h[i];
  }
  vector<vector<int> > mi(n);
  int a,b;
  rep(i,m){
    cin>>a>>b;
    mi[a-1].push_back(b-1);
    mi[b-1].push_back(a-1);
  }
  int count=0;
  rep(i,n){
    int si=mi[i].size();
    int max=0;
    if(si==0){
      count++;
    }
    else{
      rep(j,si){
        int tmp=h[mi[i][j]];
        chmax(max,tmp);
      }
      if(max<h[i]){
        count++;
      }
    }
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 8740
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes"<<endl;
			return 0;
		 }
		 a-=d;
		 if(a<=0)
		 {
		 	cout<<"No"<<endl;
		 	return 0;
		  } 
	}
}

Measured memory_bytes: 3616