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

int main() {
  int n,m;
  string a, b;
  int max = 0;
  map<string,int> counter;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    if(counter.find(a) == counter.end()){
      counter[a] = 1;
    }else{
      counter[a] += 1;
    }
  }
  cin >> m;
  for(int i=0; i<m; i++){
    cin >> b;
    if(counter.find(a) == counter.end()){
      counter[b] = -1;
    }else{
      counter[b] -= 1;
    }
  }
  for(pair<string,int> p: counter){
    if(p.second > max){
      swap(max, p.second);
    }
  }
  cout << max;
}


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

using namespace std;
#define PI 3.14159265359

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}



int main(){
    int i,r;
    //入力
    cin>>r;
    //処理
    //出力
    cout<<2*r*PI;
}

Measured memory_bytes: 3752
def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


# numpy and scipy are available for use
import numpy
import scipy
#https://atcoder.jp/contests/abc147/tasks/abc147_c
#HonestOrUnkind2


def best(bm):
    res = [-1] * N
    for i in range(N):
        if (bm & (1 << i) == 0):
            if (res[i] == 1):
                return -1

            res[i] = 0
            continue

        if (res[i] == 0):
            return -1

        res[i] = 1

        for x, y in ts[i]:
            #   print("%d %d %d" % (i, x, y))
            if res[x] == -1:
                res[x] = y
            elif res[x] != y:
                return -1

    cnt = 0

    for v in res:
        if v:
            cnt += 1

    return cnt


# reads a single line
N = gi()
ts = []

for i in range(N):
    ai = gi()
    ts.append([])
    for j in range(ai):
        x = gi() - 1
        y = gi()
        ts[i].append((x, y))

ans = 0
for bitmap in range(1 << N):
    ans = max(ans, best(bitmap))

print(ans)


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
	int n;

	cin >> n;

	vector<int> a(n);
	int m = 1000000;

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

		int num = 0;
		while (a[i] % 2 == 0){
			a[i] /= 2;
			num++;
		}
		m = min(m, num);
	}

	cout << m << endl;

	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// }}} End

inline vector<int> digit(unsigned long long n) {
  vector<int> ret;
  do { ret.push_back(n % 10); n /= 10; } while (n > 0);
  return ret;
}

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

  VAR(int, m, d);

  i64 res = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= d; ++j) {
      vector<int> d = digit(j);
      if (d[0] >= 2 && d[1] >= 2 && d[0] * d[1] == i) ++res;
    }
  }

  OUTL(res);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
               
using namespace std; 
               
int main() {   
  int N;       
  cin >> N;    
  int A[N + 1]; 
               
  for (int i = 1; i <= N; i++) { 
    int a;     
    cin >> a;  
    A[a - 1] = i; 
  }            
  for (int j = 0; j < N; j++) { 
    cout << A[j] << ' '; 
  }            
  cout << endl;
  return 0;    
}              

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define N 100005
#define mod 1000000007
using namespace std;
int n,K;
int sze[N];
long long ans;
int head[N],id;
struct edge{
	int to,nxt;
}E[N<<1];
inline void add_edge(int a,int b){
	E[++id]=(edge){b,head[a]};
	head[a]=id;
}
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
void dfs(int x,int f){
	for(int i=head[x];i;i=E[i].nxt){
		int v=E[i].to;
		if(v==f)continue;
		ans=ans*max(0,K-sze[x]-1)%mod;sze[x]--;
		dfs(v,x);
	}
}
void dfs_init(int x,int f){
	int cnt=0;
	for(int i=head[x];i;i=E[i].nxt){
		int v=E[i].to;
		if(v==f)continue;
		dfs_init(v,x);cnt++;
	}
	sze[x]=cnt;
}
int main(){
	Rd(n);Rd(K);
	for(int i=1,a,b;i<n;i++){
		Rd(a);Rd(b);
		add_edge(a,b);
		add_edge(b,a);
	}
	dfs_init(1,0);
	ans=K;
	for(int i=head[1];i;i=E[i].nxt){
		int v=E[i].to;
		ans=ans*max(0,K-sze[1])%mod;sze[1]--;
		dfs(v,1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6144
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}

ll mul(ll a, ll b) {
	return mod(mod(a) * mod(b));
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int n, k; cin >> n >> k;
    vector<ll> pos, neg;
    for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		if (x > 0) {
			pos.push_back(x);
		} else {
			neg.push_back(x);
		}
	}
	ll ans = 1;
	if ((int) pos.size()) {
		if (k % 2) {
			sort(pos.begin(), pos.end());
			ans = mul(ans, pos.back());
			pos.pop_back();
			--k;
		}
		vector<ll> ok;
		sort(pos.begin(), pos.end(), greater<>());
		sort(neg.begin(), neg.end());
		for (int i = 0; i + 1 < (int) pos.size(); i += 2) {
			ok.push_back(pos[i] * pos[i + 1]);
		}
		for (int i = 0; i + 1 < (int) neg.size(); i += 2) {
			ok.push_back(neg[i] * neg[i + 1]);
		}
		if ((int) pos.size() % 2 && (int) neg.size() % 2) {
			ok.push_back(pos.back() * neg.back());
		}
		sort(ok.begin(), ok.end(), greater<>());
		for (int i = 0; i < (k / 2); ++i) {
			ans = mul(ans, ok[i]);
		}
		cout << ans << nl;
	} else {
		sort(neg.begin(), neg.end());
		if (k % 2) {
			reverse(neg.begin(), neg.end());
		}
		for (int i = 0; i < k; ++i) {
			ans = mul(ans, neg[i]);
		}
		cout << ans << nl;
	}
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 6664
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])
            result %= MOD

    return result


def solve(N: int, M: int, K: int):

    sx = (M*(M+1)*(M-1)//6) % MOD
    sx = (sx * N*N) % MOD
    sy = (N*(N+1)*(N-1)//6) % MOD
    sy = (sy * M*M) % MOD
    s = (sx + sy) % MOD
    s = (s*cmb(N*M-2, K-2)) % MOD
    print(s)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11540
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2)//split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 32)
	{
		solve(0, h-1, j, min(j+31, w-1), query(0, w-1, j, min(j+31, w-1)), 1);
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 724
r, c = map(int, input().split())
table = []
for i in range(r):
    row = list(map(int, input().split()))
    row.append(sum(row))
    table.append(row)

total_row = []
for col in range(c+1):
    column_sum = 0
    for row in range(r):
        column_sum += table[row][col]
    total_row.append(column_sum)
table.append(total_row)

for i in range(r+1):
    print(' '.join(map(str, table[i])))



Measured memory_bytes: 5684
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] readerstr = ReadLine().Split(' ');
        string[] readerstr2 = ReadLine().Split(' ');
        int price = int.Parse(readerstr[0]);
        int num = int.Parse(readerstr[1]);
        string hate = "";
        for(int i=0;i<num;i++){
            hate += readerstr2[i];
        }
        int ans = 0;
        while(ans == 0){
            string pricestr = price.ToString();
            int prileng = pricestr.Length;
            int pricetemp = price;
            int checker = -2;
            while(pricetemp > 0){
                int onetemp = pricetemp % 10;
                checker = hate.IndexOf(onetemp.ToString());
                if(checker >= 0){
                    break;
                }
                pricetemp/=10;
            }
            if(checker ==-1){
                ans = price;
            }
            price++;
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 13404
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, K):
    if K <= len(S) and S[:K].count('1') == K:
        return 1

    for c in S:
        if c != '1':
            return c


def main():
    S = read_str()
    K = read_int()
    print(slv(S, K))


if __name__ == '__main__':
    main()


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

int main(){
  double n;
  cin >> n;
  double ans=0;
  double tmp;
  for (int i=0; i<n; i++){
    cin >> tmp;
    ans += 1/tmp;
  }
  cout << setprecision(10);
  cout << fixed << 1/ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s;
        int num = 0;
        while((s=br.readLine())!=null){
            String[] str = s.split(" ");
            if(Integer.parseInt(str[0])<0 || Integer.parseInt(str[0])>1000000 ||
               Integer.parseInt(str[1])<0 || Integer.parseInt(str[1])>1000000){
                
                    continue;
            }
            num = Integer.parseInt(str[0]) + Integer.parseInt(str[1]);
            //System.out.println(str[0]+"\t"+str[1] + "\t"+num);
            int a = String.valueOf(num).length();
            System.out.println(a);
        }
         
         
    }
}

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3000 + 7;
int n, m;
int v[N][N];
LL dp[N][N][4];

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

	cin >> n >> m;
	int q; cin >> q;
	while(q--){
		int r, c, V;
		cin >> r >> c >> V;
		v[r][c] = V;
	}

	LL ans = 0;
	FOR(i, 1, n + 1) FOR(j, 1, m + 1) FOR(was, 0, 4){
		const auto& val = dp[i][j][was];
		setmax(dp[i + 1][j][0], val);
		setmax(dp[i][j + 1][was], val);
		if (was < 3) {
			setmax(dp[i + 1][j][0], val + v[i][j]);
			setmax(dp[i][j + 1][was + 1], val + v[i][j]);
		}
	}

	FOR(i, 0, N) FOR(j, 0, N) FOR(was, 0, 4)setmax(ans, dp[i][j][was]);
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


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

typedef long long ll;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
S = input()
l = []
a = 0
if S[0] == '1':
	a += 1
else:
	l.append(a)
	a += 1
for i in range(1, N, 1):
	if S[i] == S[i - 1]:
		a += 1
	else:
		l.append(a)
		a = 1
l.append(a)
if S[N - 1] == '0':
	l.append(0)
if (len(l) + 1) // 2 - K < 1:
	print(N)
else:
	ans = sum(l[0:2 * K + 1])
	n_ans = ans
	for k in range((len(l) - 1) // 2 - K):
		n_ans += l[2 * k + 2 * K + 1] + l[2 * k + 2 * K + 2] - l[2 * k] - l[2 * k + 1]
		ans = max(ans, n_ans)
	print(ans)

Measured memory_bytes: 4476
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

unsigned long max(unsigned long x, unsigned long y) {
    if(x > y) return x;
    return y;
}
unsigned long min(unsigned long x, unsigned long y) {
    if(x < y) return x;
    return y;
}

int main() {
    int N;
    scanf("%d", &N);
    int i;
    int *l = (int*)malloc(N * sizeof(int));
    for(i=0; i<N; i++) {
        scanf("%d", &l[i]);
    }
    qsort(l, N, sizeof(int), compare_int);

    int count = 0;
    int a, b, c;
    for(a=0; a<N; a++) {
        for(b=a+1; b<N; b++) {
            for(c=b+1; c<N; c++) {
                if(l[a] < l[b] + l[c] && l[b] < l[a] + l[c] && l[c] < l[a] + l[b]) {
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
    free(l);
    return 0;
}

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

#define INF 1e9
using namespace std;

int main() {

    int N, K; cin >> N >> K;

    vector<int> V(N);
    for (int i = 0; i < N; ++i) {
        cin >> V[i];
    }

    int ans = 0;

    //全探索
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K-i; ++j) {
            if (i + j > N) {
                continue;
            }

            int d = K - i - j; //捨てる宝石
            int value = 0; //この条件での宝石の価値
            vector<int> S; //持っている宝石

            //左の宝石を入れる
            for (int k = 0; k < i; ++k) {
                value += V[k];
                S.push_back(V[k]);
            }
            
            //右の宝石を入れる
            for (int l = N-j; l < N; ++l) {
                value += V[l];
                S.push_back(V[l]);
            }

            //宝石を価値順にソート
            sort(S.begin(), S.end());

            for (int m = 0; m < d; ++m) {
                //持っている宝石より捨てる宝石の方が多い場合
                if (m >= S.size()) {
                    continue;
                }

                //捨てる宝石の価値が正の場合
                if (S[m] > 0) {
                    continue;
                }

                value -= S[m];
            }

            ans = max(ans, value);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int a[N];
int main()
{   
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", a + i);
    int ans = 0x3f3f3f3f;
    for (int i = 0; i <= n - k; i++)
        ans = min(ans, min(abs(a[i]) + a[i + k - 1] - a[i], abs(a[i + k - 1]) + a[i + k - 1] - a[i]));
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
int main() 
{
     fast;
     ll n,w;
     cin>>n>>w;
     ll v[n],wt[n];
     ffor(i,0,n)
     cin>>wt[i]>>v[i];
     ll k[n+1][w+1];
     ffor(i,0,n+1)
     ffor(j,0,w+1)
     {
         if(i==0||j==0)
         k[i][j]=0;           
         else if(wt[i-1]<=j)
         {
           k[i][j]=max(k[i-1][j],v[i-1]+k[i-1][j-wt[i-1]]);
         }
         else
         {
             k[i][j]=k[i-1][j];
         }
     }
     cout<<k[n][w]<<endl;
    //  ffor(i,0,n+1)
    //  {ffor(j,0,w+1)
    //  cout<<k[i][j]<<" ";
    //  cout<<endl;}

}


Measured memory_bytes: 79232
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, v[100010],ans=0;
int main(){
	cin >> n;
	v[0] = 0; v[n+1] = 0;
	rep(i, n) { cin >> v[i+1];
	ans += abs(v[i] - v[i+1]);
	}
	ans += abs(v[n]);
	//cout << ans << endl;
	for (int i = 1; i <= n; ++i) {
		if (v[i - 1] <= v[i] && v[i] <= v[i + 1])cout << ans << endl;
		else if (v[i - 1] >= v[i] && v[i] >= v[i + 1])cout << ans << endl;
		else cout << ans - abs(v[i - 1] - v[i]) - abs(v[i + 1] - v[i]) + abs(v[i + 1] - v[i - 1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
//条件式 ? 真の場合の文 : 偽の場合の文
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換
//binary_search(all(p),x) bool型




int main(){

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(all(a));
    ll num = a.at(n-1)/2;
    auto key = lower_bound(all(a),num) - a.begin();
    ll ans;
    if(key == n-1) ans = a.at(n-2);
    else if(key == 0) ans = a.at(0);
    else ans = a.at(key) - num > num - a.at(key -1) ? a.at(key-1):a.at(key);
    cout << a.at(n-1) sp ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    string S;
    cin >> S;

    // cout <<"A"<<S[1][0]<<"C"<<endl;
    
    // if(A<B)
    // 	cout << 0<<endl;
    // else
    // 	cout <<10<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    if(S[0]=='a'||S[0]=='i'||S[0]=='u'||S[0]=='e'||S[0]=='o')
    	puts("vowel");
    else
    	puts("consonant");
    	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

int k, l, m, n;
const int M = 1e9 + 7;


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

    string s, t;
    cin >> s >> t;

    int n = s.size(), k = t.size();

    int num = 0, mi = M;
    rep(i, n - k + 1) {
        num = 0;
        rep(j, k) {
            if(s[i + j] != t[j]) num++;
        }
        mi = min(mi, num);
    }

    cout << mi << endl;
}

Measured memory_bytes: 3656
import java.util.Arrays;

public class Main {


  private static void solve() {
    int l = ni();
    int[] a = na(l);

    // 0:2way 1:1way
    long[][] dp = new long[l + 1][5];
    for (long[] v : dp)
      Arrays.fill(v, Long.MAX_VALUE / 2);
    Arrays.fill(dp[0], 0);

    for (int i = 1; i <= l; i++) {
      int v = a[i - 1];

      long z = v == 0 ? 2 : 0;
      long[] cost = new long[] {v, v % 2 + z, (v % 2) ^ 1, v % 2 + z, v};
      long min = Long.MAX_VALUE;
      for (int j = 0; j < 5; j++) {
        min = Math.min(dp[i - 1][j], min);
        dp[i][j] = min + cost[j];
      }
    }

    System.out.println(Arrays.stream(dp[l]).min().getAsLong());
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 58512
#include <bits/stdc++.h>
#define ll long long int
#define MOD1        1000000007
#define MOD2        998244353
#define PI          3.1415926535897932384626433832795
#define FILL(a, value) memset(a, value, sizeof(a))
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ASSERT(left,operator,right) { if(!((left) operator (right))){ std::cerr << "ASSERT FAILED: " << #left << #operator << #right << " @ " << __FILE__ << " (" << __LINE__ << "). " << #left << "=" << (left) << "; " << #right << "=" << (right) << std::endl; } }

#define rep01(k,n)      for (ll i=k; i<n; i++)
#define rep02(k,n)      for (ll j=k; j<n; j++)
#define rep03(k,n)      for (ll k=k; k<n; k++)
#define rep11(k,n)      for (ll i=k; i<=n; i++)
#define rep12(k,n)      for (ll j=k; j<=n; j++)
#define rep13(k,n)      for (ll k=k; k<=n; k++)
#define repIT(c,it)     for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define all(c)      c.begin(), c.end()

using namespace std;

const double pi = acos(-1.0);
const double eps = 1e-9;


void solve()
{
    /*
    I fear not the man who has practiced 10,000 kicks once,
    but I fear the man who has practiced one kick 10,000 times.
    */

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while(1)
    {
        c -= b;
        if(c <= 0)
        {
            cout << "Yes\n";
            return;
        }
        a -= d;
        if(a <= 0)
        {
            cout << "No\n";
            return;
        } 
        //cout << a << " " << c << "\n";
    }
}

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

    int t = 1;
    //cin >> t;
    while(t--)
        solve();

    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n , k , q;
	cin >> n >> k >> q;
	vector<int>v(n , k);
	for(int i=0;i<q;i++){
		int x;
		cin >> x;
		v[x-1]++;
	}
	for(int i=0;i<n;i++) v[i] = v[i]-q;
	for(int i=0;i<n;i++){
		if(v[i]>0) cout <<"Yes"<<'\n';
		else cout << "No"<<'\n';
	}
}

Measured memory_bytes: 1408
#include <stdio.h>

int main() {
    int N;
    int money=1000;
    scanf("%d",&N);
    
        N%=1000;
    if (N==0){
            money=0;
            printf("%d\n",money);
            return 0;
        }
    money-=N;
    printf("%d\n",money);
    return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

int substring(string s, string t, int m)
{    
    int i, k, j;
     for(i=m;i<s.length();i++)
    {   
        k=i;
       for(j=0;j<t.length();j++)
       {
           if(t[j]!=s[k]&&s[k]!='?')
           {
               break;
           }
           k++;
       }
       if(j==(t.length()))
       {
           return i;
       }
    }
    return -1;
}

int main()
{

     string s, t;
     cin>>s>>t;
     int l1=s.length();
     int l2=t.length();
     if(l1<l2)
     {
         cout<<"UNRESTORABLE"<<endl;
         return 0;
     }
     string ans="";
     string temp;
     bool is=false;
     for(int i=0;i<l1;i++)
     {   
         temp=s;
         int j=substring(temp, t, i);
      //   cout<<j<<endl;
         if(j!=-1)
         {
              for(int k=0;k<l2;k++)
              {
                 temp[j]=t[k];
                 j++;
              }
              for(int k=0;k<l1;k++)
              {
                  if(temp[k]=='?')
                  {
                      temp[k]='a';
                  }
              }
              if(ans.empty())
              {
                  ans=temp;
              }
              else
              {
                  ans=min(ans, temp);
              }
           //   cout<<ans<<endl;
              is=true;
         }
     }
     if(is)
     {
         cout<<ans<<endl;
     }
     else{
         cout<<"UNRESTORABLE"<<endl;
     }
    


    return 0; 
}

Measured memory_bytes: 3640
N = int(input())
W = [input() for _ in range(N)]

def main():
    c = ''
    for w in W:
        abort = c != '' and w[0] != c or W.count(w) > 1
        if abort == True:
            break
        c = w[len(w) - 1]

    print('No' if abort else 'Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<stdio.h>


int main(void){
 
 int a, b, d, r;
 double f;
 
  scanf("%d %d", &a, &b);
 
   d = a / b;
   r = a % b;
   f = 1.00000 * a / b;
    
    printf("%d %d %.5lf\n", d, r, f);
     
     return 0;
     
}
  
 
 
 



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T, typename E>
struct SkewHeap{
  typedef function<T(T, E)> F;
  typedef function<E(E, E)> G;
  SkewHeap *l,*r;
  T val;
  F &f;
  G &g;
  E add,e;
  
  SkewHeap(T val,F &f,G &g,E e):val(val),f(f),g(g),add(e),e(e){l=r=NULL;}
  
  void eval(){
    if(add==e) return;
    if(l) l->add=g(l->add,add);
    if(r) r->add=g(r->add,add);
    val=f(val,add);
    add=e;
  }
  
  T top(){
    return f(val,add);
  }
  
};

template<typename T, typename E>
SkewHeap<T, E>* meld(SkewHeap<T, E> *a,SkewHeap<T, E> *b){
  if(!a) return b;
  if(!b) return a;
  if(a->top() > b->top())  swap(a,b);
  a->eval();
  a->r=meld(a->r,b);
  swap(a->l,a->r);
  return a;
}

template<typename T, typename E>
SkewHeap<T, E>* pop(SkewHeap<T, E>* a){
  a->eval();
  auto res=meld(a->l,a->r);
  free(a);
  return res;
};

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    r[x]+=r[y];
    p[y]=x;
  }
};


struct Arborescence{
  using P = pair<int, int>;
  using Heap = SkewHeap<P, int>;
  Heap::F f=[](P a,int b){return P(a.first+b,a.second);};
  Heap::G g=[](int a,int b){return a+b;};
  
  struct edge{
    int from,to,cost;
    edge(){}
    edge(int from,int to,int cost):from(from),to(to),cost(cost){}
  };
  
  int n;
  UnionFind uf;
  vector<edge> edges;
  vector<Heap*> come;
  vector<int> used,from,cost;
  
  Arborescence(int n):n(n),uf(n),come(n,NULL),
		      used(n,0),from(n,-1),cost(n,-1){};

  void add_edge(int from,int to,int cost){
    edges.emplace_back(from,to,cost);
  }

  void input(int m,int offset=0){
    for(int i=0;i<m;i++){
      int u,v,c;
      cin>>u>>v>>c;
      add_edge(u+offset,v+offset,c);
    }
  }

  int build(int r){
    used[r]=2;
    for(int i=0;i<(int)edges.size();i++){
      edge &e=edges[i];
      come[e.to]=meld(come[e.to],new Heap(P(e.cost,i),f,g,0));
    }
    
    int res=0;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      int v=i;
      vector<int> l;
      while(used[v]!=2){
	used[v]=1;
	l.emplace_back(v);
	if(!come[v]) return -1;
	from[v]=uf.find(edges[come[v]->val.second].from);
	cost[v]=come[v]->top().first;
	come[v]=pop(come[v]);
	if(from[v]==v) continue;
	
	res+=cost[v];
	if(used[from[v]]==1){
	  int p=v;
	  do{
	    if(come[p]) come[p]->add-=cost[p];
	    if(p!=v){
	      uf.unite(v,p);
	      come[v]=meld(come[v],come[p]);
	    }
	    p=uf.find(from[p]);
	  }while(p!=v);
	}else{
	  v=from[v];
	}
      }
      for(int u:l) used[u]=2;
    }
    return res;
  }
  
};
//END CUT HERE
signed main(){
  int n,m,r;
  cin>>n>>m>>r;
  Arborescence G(n);
  G.input(m);
  cout<<G.build(r)<<endl;
  return 0;
}

/*
  verified on 2018/01/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_B&lang=jp
*/



Measured memory_bytes: 3248
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

vector<int>v[101];
map<string, int>mp;
int p[101];
string s[101];
signed main() {
	int N; cin >> N;
	REP(i, N) {
		cin >> s[i] >> p[i];
		mp[s[i]] = 1;
	}
	int cnt = 0;
	for (auto x : mp) {
		x.second = cnt;
		mp[x.first] = cnt;
		//pe(x.first); print(cnt); print(x.second);
		cnt++;
	}
	REP(i, N) {
		int pos = mp[s[i]];
		//print(pos);
		v[pos].pb(p[i]);
	}
	REP(i, N + 1) {
		if (v[i].size() > 0) {
			VSORT(v[i]); VREVERSE(v[i]);
			REP(j, v[i].size()) {
				REP(k, N) {
					if (mp[s[k]] == i && p[k] == v[i][j]) {
						print(k + 1);
					}
				}
				//print(v[i][j]);
			}
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,ans = 0,a[110],b[110];
	cin >> n;
	for(int i = 0;i < n - 1;i++) cin >> b[i];
	for(int i = 1;i < n - 1;i++) a[i] = min(b[i - 1],b[i]);
	a[0] = b[0];
	a[n - 1] = b[n - 2];
	for(int i = 0;i < n;i++) ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <map>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstdio>
#include <cstdlib>
#define inf 0x3f3f3f3f
#define INF 0x7fffffffffffffff
typedef long long ll;
const double PI=3.1415926535897931;
const long long mod=1e9+7;
using namespace std;
////////////////////////////////////////////
const int N=2e6+10;
ll a[N],k=0;
void dfs(ll i)
{
    if(i>1e10)
        return;
    k++;
    a[k]=i;
    for(ll j=0; j<=9; j++)
    {
        if(abs(i%10-j)<=1)
        dfs(i*10+j);
    }
}
int main()
{
    int n;
    cin>>n;
    for(ll i=1; i<=9; i++)
        dfs(i);
    sort(a+1,a+k+1);
    cout<<a[n]<<endl;
    return 0;
}








Measured memory_bytes: 1792
/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
using namespace std;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff
#define     PW2(a)          (long long)1<<a

long long arr[500005];

int main()
{
    long long i,j,k,l,m,n,o,p,q,r,tst,ans=0;
    vector<long long > vc;
    cin>>n>>m;
    p=0;
    for(i=0; i<n; i++)
    {
        cin>>k;
        vc.push_back(k);
    }
    sort(vc.begin(),vc.end());
    for(i=0; i<n-m; i++)
    {
        p+=vc[i];
    }

    cout<<p<<endl;



    return 0;
}


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

long long rmq[400000] = {};

int N, M;
tuple<int, int, long long> LRC[100000];

void update(int index, long long value){
  for(int idx = (1 << 17) + index - 1; idx > 0; idx /= 2){
    rmq[idx] = min(rmq[idx], value);
  }
}

long long query(int begin, int end, int node_idx, int node_b, int node_e){
  if(node_b >= end || node_e <= begin){
    return (1LL << 60);
  }
  if(begin <= node_b && node_e <= end){
    return rmq[node_idx];
  }

  long long vl = query(begin, end, node_idx * 2, node_b, (node_b + node_e) / 2);
  long long vr = query(begin, end, node_idx * 2 + 1, (node_b + node_e) / 2, node_e);
  return min(vl, vr);
}

int main(){
  for(int i = 0; i < 400000; i++){
    rmq[i] = (1LL << 60);
  }
  
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int l, r;
    long long c;
    cin >> l >> r >> c;
    LRC[i] = make_tuple(l, r, c);
  }
  sort(LRC, LRC + M);

  update(1, 0);
  for(int i = 0; i < M; i++){
    int l, r;
    long long c;
    tie(l, r, c) = LRC[i];
    // cout << l << ' ' << r << ' ' << c << endl;
    long long m = query(l, r + 1, 1, 1, (1 << 17) + 1);
    if(m != (1LL << 60)){
      update(r, m + c);
    }
  }

  /*
  for(int i = 1; i <= N; i++){
    cout << query(i, i + 1, 1, 1, (1 << 17) + 1) << endl;
  }
  */
  long long ans = query(N, N + 1, 1, 1, (1 << 17) + 1);
  if(ans == (1LL << 60)){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 4992
a = gets.to_i
b = gets.chomp.split(" ").map(&:to_i)

def div2(x)
  if x % 2 != 0 then
    0
  else
    div2(x/2) + 1
  end
end

cnt = 0
b.each do |n|
  cnt += div2(n)
end

puts cnt

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    int i,j,n,k;
    vector<int>vec;
    sf(n);
    rep0(i,n)
    {
        sf(k);
        vec.pb(k);
    }
    ll sum=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
            sum+=vec[i]*vec[j];
    }
    pf("%lld",sum);
}

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

int main()
{
    int x;
    bool br=true;
    scanf("%d", &x);

    for(int j=x; j<999999; j++){
		for(int i=2; i<=j/2; i++){
			if(j%i == 0){
				br = false;
				break;
			}
		}
		if(br==true){
			printf("%d", j);
			return 0;
		}
		br=true;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

double r;

int main() {
	cin >> r;
	cout << 2 * r * PI << endl;



	return 0;
}



Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int n, a[100007], b[100007], cnt, f[200007], aa[100007], bb[100007], ss[200007], tot;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int find(int x)
{
	if (f[x] == x)return x;
	else return f[x] = find(f[x]);
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
	{
		aa[i] = a[i] = read();
		a[n + 1] ^= a[i];
	}
	for (int i = 1; i <= n; i++)
	{
		bb[i] = b[i] = read();
		b[n + 1] ^= b[i];
	}
	aa[n + 1] = a[n + 1];
	bb[n + 1] = b[n + 1];
	n++;
	sort(aa + 1, aa + n + 1);
	sort(bb + 1, bb + n + 1);
	for (int i = 1; i <= n - 1; i++)
		if (aa[i] != bb[i])
		{
			cout << -1 << endl;
			return 0;
		}
	for(int i=1;i<=n;i++)
		if (a[i] != b[i] || i == n)
		{
			ss[++tot] = a[i];
			ss[++tot] = b[i];
			if (i != n)cnt++;
		}
	sort(ss + 1, ss + tot + 1);
	tot = unique(ss + 1, ss + tot + 1) - ss - 1;
	for (int i = 1; i <= tot; i++)
		f[i] = i;
	for (int i = 1; i <= n; i++)
		if (a[i] != b[i])
		{
			int x = lower_bound(ss + 1, ss + tot + 1, a[i]) - ss;
			int y = lower_bound(ss + 1, ss + tot + 1, b[i]) - ss;
			f[find(x)] = find(y);
		}
	for (int i = 1; i <= n; i++)
		if (f[i] == i)cnt++;
	cout << cnt - 1 << endl;
	return 0;
}

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

int main()
{
    ll n, ans = 0;
    vector<string> s;
    cin >> n;
    rep(i, n)
    {
        string tmp;
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        s.push_back(tmp);
    }
    sort(s.begin(), s.end());
    ll cnt = 0;
    rep(i, n - 1)
    {
        if (s[i].compare(s[i + 1]) == 0)
        {
            ans += cnt + 1;
            cnt++;
        }
        else
            cnt = 0;
    }
    // rep(i, n) cout << s[i] << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7472
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N; cin >> N;
	vector<ll> X(N), L(N);
	for(int i=0; i<N; i++) cin >> X[i] >> L[i];

	vector<pair<ll, int>> right(N);
	for(int i=0; i<N; i++) right[i] = {X[i]+L[i], i};
	sort(right.begin(), right.end());

	int ans = 0;
	ll x = -1e10;
	for(int i=0; i<N; i++){
		int r = right[i].first;
		int n = right[i].second;
		if(r-2*L[n]<x) continue;
		x = r;
		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
n = int(input())
sum_min = 100000
for i in range(1,n):
    i_sum = 0; j_sum = 0
    j = n-i
    i = str(i); j = str(j)
    for k in range(len(i)):
        i_sum += int(i[k])
    for k in range(len(j)):
        j_sum += int(j[k])
    tmp_sum  = i_sum + j_sum
    if sum_min >tmp_sum :
        sum_min = tmp_sum
print(sum_min)

Measured memory_bytes: 3064