akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <time.h> //for clock
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

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

    int count0 = 0;
    int count1 = 0;
    for(i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            count0++;
        }else{
            count1++;
        }
    }

    cout << min(count0, count1) * 2 << endl;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> pii;
typedef long long int ll;

int n,a,b,q,k;
ll c;
ll depth[100000] ={0};

typedef struct{int to;ll cost;} edge;
vector<edge> tree[100000];

void dfs(int v,int p, ll d){
  depth[v] = d;
  for(int i = 0;i<tree[v].size();i++){
    if(tree[v][i].to == p) continue;
    dfs(tree[v][i].to, v, d + tree[v][i].cost);
  }
}

int main(){
  scanf("%d", &n);
  REP(i,n-1){
    scanf("%d %d %lld",&a,&b,&c);
    a--;b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }
  scanf("%d %d",&q,&k);
  k--;
  dfs(k,-1,0);
  REP(i,q){
    int x,y;
    scanf("%d %d",&x,&y);
    x--;y--;
    printf("%lld\n",depth[x]+depth[y]);
  }
}


Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    string s;
    cin >> n >> s >> k;
    char moji = s[k-1];
    REP(i,s.length()){
        if(s[i]==moji)cout << s[i];
        else cout << "*";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll x, k, d;
    cin >> x >> k >> d;

    if (abs(x / d) + 1 <= k)
    {
        if ((k - x / d) % 2 == 0)
        {
            cout << abs(abs(x) - abs(d) * abs(x / d)) << endl;
        }
        else
        {
            cout << abs(abs(x) - abs(d) * (abs(x / d) + 1)) << endl;
        }
    }
    else
    {
        cout << abs(x) - abs(d) * k << endl;
    }
}


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


int main(){
    int N;
    cin >> N;
    int T[N];
    int A[N];
    for(int i=0; i<N; i++){
        cin >> T[i] >> A[i];
    }

    long long currentT=T[0], currentA=A[0];
    for(int i=1; i<N; i++){
        long long nextT=T[i], nextA=A[i];
        if(nextT < currentT || nextA < currentA){
            long long scale = max(currentT/nextT,currentA/nextA);

            nextT = T[i]*scale;
            nextA = A[i]*scale;
            if(nextT < currentT || nextA < currentA){
                scale++;
                nextT = T[i]*scale;
                nextA = A[i]*scale;
            }
        }
        currentT = nextT;
        currentA = nextA;
    }
    cout << (currentT + currentA) << '\n';
}


Measured memory_bytes: 3172
/*
 * ARC097_C.cpp
 *
 *  Created on: May 14, 2018
 *      Author: 13743
 */

#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
using namespace std;
typedef long long llong;

#define PB push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define REP(i, n) FOR(i,0,n)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

int code[25000];
bool used[25000];

int powI(int x, int n) {
	int ans = 1;
	while(n--) {
		ans *= x;
	}
	return ans;
}

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

	char str[5010];
	int K;
	cin >> str;
	cin >> K;

	int sLen = strlen(str);
	REP(i, sLen) {
		REP(j, 5) {
			REP(k, j+1) {
				if(i+k < sLen) {
					code[5*i+j] += (str[i+k]-'a'+1)*powI(50, 4-k);
				}
			}
		}
	}
	int minI = -1;
	while(K--) {
		int minS = 1<<30;
		REP(i, 5*sLen) {
			if(!used[i] && code[i]<minS) {
				minS = code[i];
				minI = i;
			}
		}
		REP(i, 5*sLen) {
			if(code[i] == minS) {
				used[i] = true;
			}
		}
	}
	int s = minI / 5;
	int t = minI % 5;
	REP(i, t+1) {
		if(s+i < sLen) {
			cout << str[s+i];
		}
	}
	cout << endl;
}


Measured memory_bytes: 384
//ツ姪「ツ妥ィツ閉カツづ可個セツづュツづェツつスツ津環づィツづ可偲?堕閉つキツづゥツつセツつッ
#include <iostream>
using namespace std;

int f(int x){
  return x * x;
}

int main(){
  int d;

  while(cin >> d){
    int sum = 0;

    for(int i = d; i <= 600 - d; i += d){
      int h = f(i);
      sum += h * d;
    }

    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (n, k) = readListOfInt() 
    val l = readListOfInt().sortedDescending()
    val sum = l.slice(0 until k).sum()
    println(sum)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 36012
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int nums[3];
    cin >> nums[0] >> nums[1] >> nums[2];
    sort(nums,nums+3);
    
    cout << nums[0] << " " <<nums[1] << " " << nums[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3152
import sys
from collections import deque
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [A, B] = string_to_int(inputs[0])
    trees = [0]
    for i in range(1, 1000):
        trees.append(trees[i-1] + i)

    diff = B - A
    return trees[diff] - B


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3692
S = raw_input()
P = raw_input()
no_flg = True
count = S.count(P[0])
start = 0
for c in range(count):
    i = 1
    if c > 0:
        start = S[(start+1):].index(P[0]) + (start+1)
    else:
        start = S[start:].index(P[0])
    for p in P[1:]:
        if S[(start+i) % len(S)] != p:
            break
        i += 1
    if i == len(P):
        print 'Yes'
        no_flg = False
        break
if no_flg:
    print 'No'

Measured memory_bytes: 6424
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	var D, X int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &D, &X)

	as := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &as[i])
	}

	ans := X
	for _, a := range as {
		ans = ans + (D-1)/a + 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
    int H, W, N, sum;
    scanf ("%d %d %d", &H, &W, &N);
    if (H > W){
    	sum = N/H ;
    N%H >0 ? printf("%d", sum+1) : printf("%d",sum);
	}
	else  {
		sum = N/W ;
	N%W > 0? printf("%d", sum+1) : printf("%d",sum);
	}
   return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    sort(s.begin(),s.end());
    if ( s == "abc" )ans ="Yes";
    else ans = "No";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned int ui;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=200005;
int n,par[N],col[N],cnt[2][N];
namespace dsu
{
	int father[N];
	void init()
	{
		for (int i=1;i<=n;++i)
		{
			father[i]=i;
		}
	}
	
	int getfather(int x)
	{
		return father[x]==x ? x : father[x]=getfather(father[x]);
	}
}

struct cmp
{
	bool operator () (const int &x,const int &y)
	{
		ll tmp1=(ll)cnt[0][x]*cnt[1][y];
		ll tmp2=(ll)cnt[1][x]*cnt[0][y];
		if (tmp1==tmp2) return x<y;
		else return tmp1>tmp2;
	}
};

void init()
{
	read(n);
	for (int i=2;i<=n;++i)
	{
		read(par[i]);
	}
	for (int i=1;i<=n;++i)
	{
		read(col[i]);
	}
	dsu::init();
}

void solve()
{
	multiset <int,cmp> S;
	multiset <int,cmp>::iterator it;
	for (int i=1;i<=n;++i)
	{
		if (col[i]) cnt[1][i]=1,cnt[0][i]=0;
		else cnt[0][i]=1,cnt[1][i]=0;
		if (i>1) S.insert(i);
	}
	ll ans=0;
	for (int rnd=1;rnd<n;++rnd)
	{
		int x=*S.begin(); 
		S.erase(x);
		int y=dsu::getfather(par[x]);
		S.erase(y);
		//out(x); outln(y);
		ans+=(ll)cnt[1][y]*cnt[0][x];
		cnt[0][y]+=cnt[0][x]; cnt[1][y]+=cnt[1][x];
		dsu::father[x]=y;
		if (y>1) S.insert(y);
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	solve();
    return 0;
}


Measured memory_bytes: 16468
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	S, T := ReadString(), ReadString()
	L := LCM(N, M)
	g := GCD(N, M)
	ok := true
	for k := 0; k*(N/g) < N && k*(M/g) < M; k++ {
		a, b := k*(N/g), k*(M/g)
		if S[a] != T[b] {
			ok = false
			break
		}
	}
	if ok {
		fmt.Println(L)
	} else {
		fmt.Println(-1)
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}
func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2808
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	bool isUsed[101][101];
	for (int i = 0; i < 101; ++i)
	{
		for (int j = 0; j < 101; ++j)
		{
			isUsed[i][j] = false;
		}
	}
	int W, H, N;
	cin >> W >> H >> N;
	for (int i = 0; i < N; ++i)
	{
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1)
		{
			for (int j = 0; j < H; ++j)
			{
				for (int k = 0; k < x; ++k)
				{
					isUsed[j][k] = true;
				}
			}
		}
		else if (a == 2)
		{
			for (int j = 0; j < H; ++j)
			{
				for (int k = x; k < W; ++k)
				{
					isUsed[j][k] = true;
				}
			}
		}
		else if (a == 3)
		{
			for (int j = 0; j < W; ++j)
			{
				for (int k = 0; k < y; ++k)
				{
					isUsed[k][j] = true;
				}
			}
		}
		else if (a == 4)
		{
			for (int j = 0; j < W; ++j)
			{
				for (int k = y; k < H; ++k)
				{
					isUsed[k][j] = true;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (isUsed[i][j])
			{
				++ans;
			}
		}
	}
	cout << W * H - ans << endl;
}

int main()
{
	solve();
	return(0);
}

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

struct BSTNode {
	int key;
	BSTNode *lchild, *rchild, *parent;
	BSTNode(int k, BSTNode *p = nullptr, BSTNode *l = nullptr, BSTNode *r = nullptr) : key(k), lchild(l), rchild(r), parent(p)
	{}
};
typedef BSTNode* BSTree;

BSTree insert(BSTree& Root, int key)
{
	BSTree parent = nullptr;
	BSTree child = Root;
	while (child)
	{
		parent = child;
		if (key > child->key)
			child = child->rchild;
		else
			child = child->lchild;
	}
	child = new BSTNode(key, parent);
	if (!parent)
		Root = child;
	else if (parent->key > key)
		parent->lchild = child;
	else
		parent->rchild = child;
	return child;
}
void pre_order(BSTree T)
{
	printf(" %d", T->key);
	if (T->lchild)
		pre_order(T->lchild);
	if (T->rchild)
		pre_order(T->rchild);
}
void in_order(BSTree T)
{
	if (T->lchild)
		in_order(T->lchild);
	printf(" %d", T->key);
	if (T->rchild)
		in_order(T->rchild);
}
int main(void)
{
	char buf[10];
	int key, n;
	scanf("%d", &n);
	BSTree T = nullptr;
	while (n--)
	{
		scanf("%s", buf);
		if (*buf == 'i')
		{
			scanf("%d", &key);
			insert(T, key);
		}
		else
		{
			in_order(T);
			putchar('\n');
			pre_order(T);
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 26108
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int a = sc.nextInt();
        // スペース区切りの整数の入力
        int p = sc.nextInt();

        // 出力
        System.out.println((3 * a + p) / 2);

    }

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int h, w;
    cin >> h >> w;
    int a[h][w];
    bitset<25600> dp[w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) {
        int b;
        cin >> b;
        a[i][j] -= b;
        a[i][j] = abs(a[i][j]);
    }
    dp[0].set(12800 + a[0][0]);
    dp[0].set(12800 - a[0][0]);
    rep(i, h) rep(j, w) {
        if(i) dp[j] = (dp[j] << a[i][j]) | (dp[j] >> a[i][j]);
        if(j) dp[j] |= (dp[j - 1] << a[i][j]) | (dp[j - 1] >> a[i][j]);
    }
    int ans = 1e9;
    rep(i, 25600) if(dp[w - 1][i]) chmin<int>(ans, abs(12800 - i));
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
#define coa cout << ans << endl
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

int sumOfDigits(int x){
    int ret = 0;
    while(x){
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

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

    int ans = INT32_MAX;
    for(int a = 1; a < n; a++){
        int b = n - a;
        ans = min(ans, sumOfDigits(a) + sumOfDigits(b));
    }

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


Measured memory_bytes: 3604
if __name__ == "__main__":
    A, B, K = input().split()
    A = int(A)
    B = int(B)
    K = int(K)
    A = A - K
    if A < 0:
        B = B + A
        A = 0
    if B < 0:
        B = 0
    print(str(A) + " " + str(B))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, l, pos = -1;
    cin >> n >> l;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a.at(i);
    for (int i = 1; i < n; ++i) if (a.at(i) + a.at(i + 1) >= l) {
        pos = i;
        break;
    }
    if (pos < 0) cout << "Impossible\n";
    else {
        cout << "Possible\n";
        for (int i = 1; i < pos; ++i) cout << i << '\n';
        for (int i = n - 1; i > pos; --i) cout << i << '\n';
        cout << pos << '\n';
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; ++i) cin >> d.at(i); 
  sort(d.begin(), d.end(), greater<int>());
 
  int count = 1;

  for (int i = 0; i < N - 1; ++i) {
    if (d.at(i) > d.at(i + 1)) ++count; 
  }

  cout << count << endl;
  
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Collecting Balls (Easy Version)
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            var x = ReadLine();
            int distance = 0;

            foreach(var xi in x)
            {
                if (xi < Math.Abs(K - xi))
                {
                    distance += xi * 2;
                }
                else
                {
                    distance += Math.Abs(K - xi) * 2;
                }
            }

            Console.WriteLine(distance);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

#define INF 1000000000

using namespace std;

int dp[100010];
int nxt[100010];

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

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

    priority_queue<pi, vpi, greater<pi>> pq;
    pq.push(MP(dp[n], n));

    for(int i = n-1; i >= 0; i--) {
        if(s[i] == '1') continue;
        while(!pq.empty() && pq.top().S - i > m) {
            pq.pop();
        }
        if(pq.empty()) {
            cout << -1 << endl;
            return 0;
        }
        dp[i] = pq.top().F+1;
        nxt[i] = pq.top().S;
        pq.push(MP(dp[i], i));
    }

    for(int i = 0; i < n;) {
        cout << nxt[i] - i << " ";
        i = nxt[i];
        if(i == n) break;
    }
    cout << endl;
}


Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

template<typename T>
struct BIT {
	int n;
	vector<T>dat;
	BIT(int n = 0) {
		initialize(n);
	}
	void initialize(int temp) {
		n = temp;
		dat.resize(n);
		rep(i, 0, n)dat[i] = 0;
	}
	T sum(int i) {
		T s = 0;
		while (i >= 0) {
			s += dat[i];
			i = (i & (i + 1)) - 1;
		}
		return s;
	}
	T sum_between(int i, int j) {
		if (i > j)return 0;
		return sum(j) - sum(i - 1);
	}
	void plus(int i, T x) {
		while (i < n) {
			dat[i] += x;
			i |= i + 1;
		}
	}
	int lower_bound(T x) {
		if (sum(n - 1) < x)return -1;
		else if (sum(0) >= x)return 0;
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (sum(mid) >= x)ok = mid;
			else ng = mid;
		}
		return ok;
	}
};

ll bub(vector<ll>li){
	BIT<ll>bit(202020);
	reverse(all(li));
	ll ans = 0;
	for (int i = 0; i < li.size(); i++) {
		ans += bit.sum_between(0,li[i]-1);
		bit.plus(li[i],1);
	}
	return ans;
}

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

	string S;
	cin >> S;
	set<ll>st[26];
	ll N = S.size();
	for (int i = 0; i < N; i++)st[S[i] - 'a'].insert(i);
	ll cntodd = 0;
	for (int i = 0; i < 26; i++)cntodd += st[i].size()%2;

	if (cntodd >= 2) {
		puts(-1);
		return 0;
	}

	vector<ll>li(N, -1);
	ll cur = 0;
	for (int i = 0; i < N; i++) {
		int num = S[i] - 'a';
		if (li[i] == -1) {
			if (st[num].size() >= 2) {
				int fr = *st[num].begin();
				auto itr = st[num].end();
				itr--;
				int ba = *itr;
				li[fr] = cur;
				li[ba] = N - 1 - cur;
				st[num].erase(fr);
				st[num].erase(itr);
				cur++;
			}
			else {
				li[i] = N/2;
				st[num].erase(i);
			}
		}
	}
	

	puts(bub(li));

	return 0;
}


Measured memory_bytes: 11412
#include<iostream>
#include<vector>
#include<cstdio>
#include<iterator>
#include<string>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
#define MP make_pair
#define F first
#define S second
#define LL long long
#define INF	int(1e9)
typedef pair<int, int> P;
typedef pair<P, P> PP;
inline int in() {
	int temp;
	scanf("%d", &temp);
	return temp;
}
int n, ans, nma;
int a[100000], tree[100000];
vector<int>rpl[100001];
int dfs(int now, int sum)
{
	vector<int> ss;
	for (int i = 0; i < rpl[now].size(); i++) {
		ss.push_back(dfs(rpl[now][i], sum + 1));
	}
	sort(ss.begin(), ss.end());
	int size = ss.size();
	if (!size) {
		ss.push_back(sum);
		size = 1;
	}
	nma = ss[size - 1];
	for (int i = size - 2; i >= 0; i--)
	{
		nma = max(ss[i] + size - i - 1, nma);
	}
	ans = max(ans, nma);
	ss.clear();
	return nma;
}
int main()
{
	n = in();
	for (int i = 0; i < n - 1; i++)
	{
		a[i] = in();
		rpl[a[i]].push_back(i + 2);
	}
	dfs(1, 0);
	cout << ans << endl;
}

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

int N,K,X,Y;

int main(){
  cin >> N >> K >> X >> Y;
  int ans = 0;
  if(N <= K) ans = N*X;
  else ans = K*X + (N-K)*Y;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin >> n;
  ll sum[n + 1] = {};
  for(ll i = 0; i < n; i++){
    ll a;
    cin >> a;
    sum[i + 1] = sum[i] + a;
  }
  ll ans = 1145148931919810;
  for(ll i = 1; i < n; i++) ans = min(ans, (ll)abs(sum[i] - (sum[n] - sum[i])));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll 	 long long
#define pb push_back
#define mp make_pair
using namespace std;

#define mmm    ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {

int n, cnt=0; cin>>n;
int a[n+3],b[n+3];
for(int i=0; i<n; i++)
{
cin>>a[i]>>b[i];
}

for(int i=0; i<n-2; i++)
{
	if(a[i]==b[i])
	{
	    //cout<<a[i]<<" "<<b[i]<<endl;
		if (a[i+1]==b[i+1])
		{
			if(a[i+2]==b[i+2])
			
			{
				//cout<<i<<endl;
				cnt++;
				break;
			}
		}
	 } 
	
}

if(cnt) cout<<"Yes\n";
else cout<<"No\n";

    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    OP(pow(2, (int)log2(n)));
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"

// const ll mod = 1e9 + 7;
const ll mod = 998244353;
const ll sz = 1e6 + 5;
vector<ll> fac(sz, 1);

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 nCr(ll n, ll r) { return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod ); }
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; }
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    ll xx, yy;
    ll res = extended_gcd(b, a%b, xx, yy); x = yy; y = xx - yy * (a / b);
    return res;
}

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // for (ll i = 2; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;

    while(t--) {
        ll n, k;
        cin >> n >> k;
        
        vector<ll> dp(n+2, 0);
        dp[1] = 1;
        
        vector<pair<ll,ll>> arr(k);
        for (int i = 0; i < k; i++)
            cin >> arr[i].fi >> arr[i].se;
        
        ll sm = 0;
        for (auto p: arr) {
            if (p.fi + 1 <= n) {
                dp[1+p.fi] += 1;
                dp[1+p.fi] %= mod;
                dp[min(n, 1+p.se) + 1] -= 1;
                dp[min(n, 1+p.se) + 1] += mod;
                dp[min(n, 1+p.se) + 1] %= mod;
            }
        }
        for (ll i = 2; i <= n; i++) {
            sm = (sm + dp[i]) % mod;
            if (sm == 0)
                continue;
            
            for (auto p: arr) {
                if (i + p.fi <= n) {
                    dp[i+p.fi] += sm;
                    dp[i+p.fi] %= mod;
                    dp[min(n, i+p.se) + 1] -= sm;
                    dp[min(n, i+p.se) + 1] += mod;
                    dp[min(n, i+p.se) + 1] %= mod;
                }
            }
            
            // for (int i = 1; i <= n+1; i++)
            //     cout << dp[i] << " ";
            // cout << endl;
        }
        
        for (int i = 3; i <= n; i++)
            dp[i] = (dp[i] + dp[i-1]) % mod;
        
        cout << dp[n] << endl;
    }
    
	return 0;
}


Measured memory_bytes: 12688
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    int ans = 0;
    int cnt = 0;
    rep(i, S.size()) {
        if (S[i] == 'R') cnt++;
        else cnt = 0;
        ans = max(cnt, ans);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

vector<pair<ll, ll>> factorize(ll N) {
    vector<pair<ll, ll>> res;
    ll n = N;
    for (ll p = 2; p*p <= n; p++) {
        if (N%p != 0) continue;
        int count = 0;
        while (N%p == 0) {
        count++;
        N /= p;
        }
        res.push_back(make_pair(p, count));
    }
    if (N != 1) res.push_back(make_pair(N, 1));
    return res;
}

ll N;

ll solve() {
    vector<pair<ll, ll>> fs = factorize(N);
    ll ret = 0;
    FORE (f, fs) {
        int n = f.second;
        int c = 1;
        while (n >= c) {
            n -= c;
            ret++;
            c++;
        }
    }
    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    cout << solve() << endl;
}

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

enum COLOR{ WHITE=0, BLACK=1};
int n;
vector<pair<int,int>> adjlist[100000];
int color[100000];

void dfs(int v, int l) {
  if(l % 2 == 0) color[v] = WHITE;
  else color[v] = BLACK;
  for(auto [u, weight] : adjlist[v]) {
    if (color[u] != -1) continue;
    dfs(u, l + weight);
  }
}

signed main() {
  cin >> n;
  rep(i,n-1) {
    int u,v,w; cin >> u >> v >> w; u--; v--;// w%=2;
    adjlist[u].emplace_back(v,w);
    adjlist[v].emplace_back(u,w);
  }
  fill(color, color+n, -1);
  dfs(0, 0);
  rep(i, n) cout << color[i] << endl;
}


Measured memory_bytes: 11448
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int h,w,n,i,j;
    cin>>h>>w;
    cin>>n;
    int a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    int ans[h][w],ctr=0;
    for (i=0;i<h;i++)
    {
        if (i%2==0)
        {
            for (j=0;j<w;j++)
            {
                if (a[ctr])
                {
                    ans[i][j]=ctr+1;
                    a[ctr]--;
                }
                else
                {
                    ctr++;
                    ans[i][j]=ctr+1;
                    a[ctr]--;
                }
            }
        }
        else
        {
            for (j=w-1;j>=0;j--)
            {
                if (a[ctr])
                {
                    ans[i][j]=ctr+1;
                    a[ctr]--;
                }
                else
                {
                    ctr++;
                    ans[i][j]=ctr+1;
                    a[ctr]--;
                }
            }
        }
    }
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    int a,b;
    cin >> a>>b;
    if(b%a==0) cout << a+b << endl;
    else cout << b-a << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

vector<int> CreatePrimes(int n)
{
	bool* work = new bool[n+1];

	fill(work, work+(n+1), true);
	work[0] = work[1] = false;

	vector<int> res;
	res.push_back(2);
	for (int i = 4; i <= n; i += 2)
		work[i] = false;

	for (int i = 3; i <= n; i += 2)
	{
		if (work[i])
		{
			res.push_back(i);
			for (int j = 2*i; j <= n; j += i)
				work[j] = false;
		}
	}

	delete[] work;

	return res;
}


int main()
{
	vector<int> primes = CreatePrimes(110000);
	long s[10001];
	s[0] = 0;
	for (int i = 1; i <= 10000; ++i)
		s[i] = s[i-1] + primes[i-1];

	while (true)
	{
		int n;
		scanf("%d\n", &n);
		if (n == 0)
			break;
		printf("%d\n", s[n]);
	}

	return 0;
}

Measured memory_bytes: 0
import sys 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a = ni()
s = ns()

if a >= 3200:
        print(s)
else:
        print('red')

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#include <stdio.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

ll solve(string S) {
    int slen = (int) S.size();
    int alen = slen + 1;
    vector<ll> gts(alen, 0);
    vector<ll> lts(alen, 0);

    int count = 0;
    gts[0] = 0;
    for (int i = 1; i < alen; i++) {
        if (S[i - 1] == '<') {
            count++;
            gts[i] = count;
        } else {
            count = 0;
        }
    }

    count = 0;
    lts[alen - 1] = 0;
    for (int i = alen - 2; i >= 0; i--) {
        if (S[i] == '>') {
            count++;
            lts[i] = count;
        } else {
            count = 0;
        }
    }

    // for (int i = 0; i < alen; i++) {
    //     printf("[i] gts: %lld, lts: %lld\n", gts[i], lts[i]);
    // }

    ll acc = 0;
    for (int i = 0; i < alen; i++) {
        acc += max(gts[i], lts[i]);
    }
    return acc;
}

// 14:38
int main(void) {
    string S;
    cin >> S;
    cout << solve(S) << endl;
    return 0;
}


Measured memory_bytes: 9220
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,a,b=MI()
    p,r=divmod(n,(a+b))
    print(p*a+min(r,a))

main()

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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
        int d[10][10]; // 最短距離
        for(int i=0; i<m; i++){ // 重み配列で初期化
            for(int j=0; j<m; j++){
                d[i][j] = T[i][j];
            }
        }
        for(int k=0; k<m; k++){
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    if(d[i][j]>d[i][k]+d[k][j]){
                        d[i][j] = d[i][k]+d[k][j];
                    }
                }
            }
        }
        int twn;
        int min=INF;
        for(int i=0;i<m;i++){
            int sum=0;
            for(int j=0;j<m;j++){
                sum+=d[i][j];
            }
            if(min>sum){
                min=sum;
                twn=i;
            }
        }
        cout<<twn<<' '<<min<<endl;
	}
	return 0;
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
if(a>2*b) {
  cout << a-2*b << endl;
} else {
  cout << "0" << endl;
}
return 0;
}


Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;  

void test_case()
{  
    ll n,k,i,j;
    cin >>  n >> k;
    vector<ll> v(n);
    f(i,0,n)
        cin >> v[i];
    sort(all(v));
    ll tot = 0;
    f(i,0,k)
        tot += v[i];
    cout << tot << '\n';
}
 
int32_t main()
{
    IOS(); 
    
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3604
N = gets.chop.to_i
H = gets.chop.split.map(&:to_i)

1.upto(N-1) do |i|
  if H[i-1] - H[i] > 1
    puts 'No'
    exit
  elsif H[i-1] - H[i] == 1
    H[i] += 1
  end
end

puts 'Yes'



Measured memory_bytes: 9604
#include <iostream>

using namespace std;

using ll = long long;

ll sum(ll l, ll r, ll len)
{
    ll f = r / 3 - l / 3;
    ll b = r / 5 - l / 5;
    ll fb = r / 15 - l / 15;
    ll other = ((r - l) - (f + b - fb)) * len;
    return other + (f + b - 2 * fb) * 4 + fb * 8;
}

ll c(ll x)
{
    ll p = 1, len = 1;
    ll res = 0;
    while (p * 10 <= x) {
        res += sum(p - 1, p * 10 - 1, len);
        len++;
        p *= 10;
    }
    res += sum(p - 1, x - 1, len);
    return res;
}

int main()
{
    ll n;
    cin >> n;

    ll l = 0, r = n + 1;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (c(mid) < n) {
            l = mid;
        } else {
            r = mid;
        }
    }

    string s;
    for (ll i = l; i < l + 100; i++) {
        if (i % 15 == 0) {
            s += "FizzBuzz";
        } else if (i % 3 == 0) {
            s += "Fizz";
        } else if (i % 5 == 0) {
            s += "Buzz";
        } else {
            s += to_string(i);
        }
    }
    cout << s.substr(n - c(l) - 1, 20) << endl;
    return 0;
}

Measured memory_bytes: 3252
use proconio::input;
use num::pow;

fn solve(x: i64) -> (i64, i64) {
    for i in 1..200 {
        for j in -200..200 {
            if pow(i, 5) - pow(j, 5) == x {
                return (i, j);
            }
        }
    }
    (0, 0)
}

fn main(){
    input!{
        x : i64
    };
    let res = solve(x);
    println!("{} {}", res.0, res.1);
}

Measured memory_bytes: 2136
//============================================================================
// Name        : Calc.cpp
// Author      : Roman
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <fstream>

using namespace std;


int main() {
	// ifstream cin ("/Users/shuffler/Documents/workspace/Calc/src/input.txt");
	// ofstream cout ("/Users/shuffler/Documents/workspace/Calc/src/output.txt");

	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	long long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0;
		return 0;
	}
	cout << min (a * b, min(b*c, a*c));
	return 0;
}



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

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

    vector<int> a;
    for (int i = 0; i < N; i++)
    {
        int aa;
        cin >> aa;
        a.push_back(aa);
    }

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

    int Alice_turn = (N - 1) % 2;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == Alice_turn)
        {
            ans += a.at(i);
        }
        else
        {
            ans -= a.at(i);
        }
    }
    cout << ans << endl;
}

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

class State{
public:
  int x, y, cost;
  State(int _x, int _y, int _cost){
    x = _x;
    y = _y;
    cost = _cost;
  }
};

int w, h;
int t[100][100];
bool closed[100][100];

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

void solve(){
  queue<State> open;
  memset(closed, 0, sizeof(closed));
  open.push(State(0, 0, 0));

  while(!open.empty()){
    State st = open.front(); open.pop();
    if(closed[st.y][st.x]) continue;
    closed[st.y][st.x] = true;

    if(st.y == h - 1 && st.x == w - 1){
      cout << st.cost / 2 + 1 << endl;
      return;
    }

    for(int i = 0; i < 4; i++){
      int nx = st.x + dx[i];
      int ny = st.y + dy[i];

      if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] == 0){
        open.push(State(nx, ny, st.cost + 1));
      }
    }
  }

  cout << 0 << endl;
}

int main(){
  while(cin >> w >> h, w || h){
    w = w * 2 - 1;
    h = h * 2 - 1;

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(i % 2 == 0){
          if(j % 2 == 0){
            t[i][j] = 0;
          }
          else{
            int x;
            cin >> x;
            t[i][j] = x;
          }
        }
        else{
          if(j % 2 == 0){
            int x;
            cin >> x;
            t[i][j] = x;
          }
          else{
            t[i][j] = 1;
          }
        }
      }
    }

    /*
    for(int i = 0; i < h; i++){
      for(int j = 0; j <w; j++){
        cout<<t[i][j];
      }
      cout<<endl;
    }
    */

    solve();
  }
}

Measured memory_bytes: 944
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    ll ans = 1;
    for(ll i = 1; i <= n; i++) ans = ans * i % MOD;
    cout << ans << "\n";
    return 0;
}

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

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    string s;
    cin>>s;
    if(s.length()%2)
    {
        cout<<"No";
        return 0;
    }
    for(int i=0;i<s.length();i+=2)
    {
        if(s[i]=='h'&&s[i+1]=='i') continue;
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

ans = 10**12
for c in range(max(X,Y) + 1):
    cost = C*2*c
    a = max(0, X-c)
    b = max(0, Y-c)
    cost += A*a + B*b
    ans = min(cost, ans)
print(ans)

Measured memory_bytes: 3188
from itertools import takewhile
primes = [0, 0] + [1] * (2**15)
for i in range(2, 182):
    if primes[i]:
        for j in range(i*i, 2**15 + 2, i):
            primes[j] = 0

while True:
    n = int(input())
    if n == 0:
        break
    prime_values = [i for i in range(len(primes[:n])) if primes[i]]
    print(sum(n-p1 in prime_values for p1 in takewhile(lambda x: x < n//2+1, prime_values)))

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

int main(){
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i,n){
    cin >> x[i] >> u[i];
  }
  
  double y = 0;
  rep(i,n){
    if(u[i] == "JPY"){
      y += x[i];
    }
    if(u[i] == "BTC"){
      y += x[i] * 380000.0;
    }
  }
  cout << y << endl;
}

Measured memory_bytes: 256