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

int main() {
  int n;
  cin >> n;
  
  vector<string> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  int count = 0;
  int count_tmp = 0;
  string tmp;
  list<string> lst;
  
  for(int i = 0; i < n; i++) {
    if (vec.at(i) != tmp) {
      if (count_tmp == count)
        lst.push_back(tmp);
      else if (count_tmp > count) {
        lst.clear();
        lst.push_back(tmp);
        count = count_tmp;
      }
      
      count_tmp = 0;
    }
    
    tmp = vec.at(i);
    count_tmp++;
  }
  
  if (count_tmp == count)
        lst.push_back(tmp);
  else if (count_tmp > count) {
        lst.clear();
        lst.push_back(tmp);
        count = count_tmp;
  }
  
  for (list<string>::iterator itr = lst.begin(); itr != lst.end(); itr++) {
    cout << *itr << endl;
  }
  
  return 0;
}

Measured memory_bytes: 20480
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(-1, -N - 1, -1):
  a, b = AB[i]
  m = (a + ans) % b
  if m != 0:
    ans += b - m

print(ans)

Measured memory_bytes: 89460
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum=0;
    scanf("%d",&n);
    int a[n+1],b[n+1];
    for(int i=0; i<n; i++)scanf("%d",&a[i]);
    for(int y=0; y<n; y++)scanf("%d",&b[y]);
    for(int i=0; i<n; i++)
    {
        if(a[i]>b[i])
            sum+=(a[i]-b[i]);
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

int N,A,B,num_A,num_B;
bool check[NUM];
vector<int> G[NUM];

bool recursive(int side_A,int side_B){

	if(num_A == N/2 && num_B == N/2)return true;

	for(int i = 0; i < G[side_A].size(); i++){

		if(check[G[side_A][i]])continue;
		check[G[side_A][i]] = true;

		num_A++;
		for(int k = 0; k < G[side_B].size(); k++){

			if(check[G[side_B][k]])continue;
			check[G[side_B][k]] = true;

			num_B++;
			if(recursive(G[side_A][i],G[side_B][k]))return true;

			check[G[side_B][k]] = false;
			num_B--;
		}
		check[G[side_A][i]] = false;
		num_A--;

	}
    return false;
}


int main(){

	scanf("%d %d %d",&N,&A,&B);
	A--;
	B--;
	num_A = num_B = 1;

    for(int i = 0; i < N; i++)check[i] = false;

    check[A] = true;
    check[B] = true;

    int from,to;

    for(int loop = 0; loop < N-1; loop++){
    	scanf("%d %d",&from,&to);
    	from--;
    	to--;
    	G[from].push_back(to);
    	G[to].push_back(from);
    }

    if(N%2 != 0){
        printf("No\n");
        return 0;
    }

    int num_3 = 0;
    for(int i = 0; i < N; i++){
    	if(G[i].size() >= 4){
    		printf("No\n");
    		return 0;
    	}
    	if(G[i].size() == 3){
    		num_3++;
    		if(num_3 > 2){
    			printf("No\n");
    			return 0;
    		}
    	}
    }

    if(recursive(A,B)){
    	printf("Yes\n");
    }else{
    	printf("No\n");
    }
}



Measured memory_bytes: 12704
using System;

namespace B
{
    class Merge
    {
        public int count = 0;

        public void merge(ref int[] A, int left, int mid, int right)
        {
            int i, j=0, k;
            int n1 = mid - left;
            int n2 = right - mid;
            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];
            for (i = 0; i < n1; i++)
            {
                L[i] = A[left + i];
            }
            for (i = 0; i < n2; i++)
            {
                R[i] = A[mid + i];
            }
            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;
            i = 0;
            for (k = left; k < right; k++)
            {
                if (L[i] <= R[j])
                {
                    A[k] = L[i];
                    i++;
                    count++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                    count++;
                }
            }
            
        }

        public void mergeSort(ref int[] A, int left, int right)
        {
            if (left+1<right)
            {
                int mid = (left + right) / 2;
                mergeSort(ref A, left, mid);
                mergeSort(ref A, mid, right);
                merge(ref A, left, mid, right);
            }
        }
    }

    class B
    {
        static void Main(string[] args)
        {
            Merge sort = new Merge();
            string input;
            string[] input2 = new string[20000];
            int n, i;
            input = Console.ReadLine();
            n = int.Parse(input);
            int[] S = new int[n];
            input2 = Console.ReadLine().Split(' ');
            for (i = 0; i < n; i++)
            {
                S[i] = int.Parse(input2[i]);
            }

            sort.mergeSort(ref S, 0, n);
            for (i=0; i<n-1; i++)
            {
                Console.Write(S[i]+" ");
            }
            Console.WriteLine(S[n-1]);
            Console.WriteLine(sort.count);
        }
    }
}



Measured memory_bytes: 76152
N = int(input())
T, A = map(int, input().split())
h = list(map(int, input().split()))

ans = 0
diff = float("inf")

for i, height in enumerate(h):
    temp = T - 0.006 * height
    if diff > abs(A - temp):
        diff = abs(A - temp)
        ans = i + 1

print(ans)


Measured memory_bytes: 9100
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <list>


constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr long long LONGINF = 1005000000000000000;
using namespace std;

using ll = long long;

class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};


int main() {

	string left = "qwertasdfgzxcvb";
	string right = "yuiophjklnm";
	
	while (1) {
		string s; cin >> s;
		if (s == "#") { return 0; }

		bool x;//true:right false:left

		if (left.find(s[0]) != -1) {
			x = false;
		}
		else {
			x = true;
		}

		int ans = 0;

		for (int i = 1; i < s.size(); i++) {
			if (x) {
				if (right.find(s[i]) != -1) {}
				else {
					x = false;
					ans++;
				}
			}
			else {
				if (left.find(s[i]) != -1) {}
				else {
					x = true;
					ans++;
				}
			}
		}
		cout << ans << endl;
	}

}


Measured memory_bytes: 3176
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    k = int(rl())
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            d = gcd(a, b)
            for c in range(1, k + 1):
                ans += gcd(c, d)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9184
<?php
# 入力
fscanf(STDIN, "%d", $n);
$p = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cnt = 0;
for ($i = 1; $i < $n - 1; $i++) {
    $arr = [$p[$i - 1], $p[$i], $p[$i + 1]];
    if ($p[$i] != max($arr) && $p[$i] != min($arr)) {
        $cnt++;
    }
}
echo $cnt.PHP_EOL;
?>

Measured memory_bytes: 4856
def eval_points(mid, term, re):
    if mid == -1 or term == -1:
        return 'F'
    sum = mid + term
    if sum >= 80:
        return 'A'
    elif sum >= 65:
        return 'B'
    elif sum >= 50 or re >= 50:
        return 'C'
    elif sum >= 30:
        return 'D'
    else:
        return 'F'
        

while True:
    mid, term, re = map(int, input().split())
    if mid == -1 and term == -1 and re == -1:
        break
    evaluation = eval_points(mid, term, re)
    print(evaluation)


Measured memory_bytes: 5600
import sys
K = int(input())

cnt = 0
num = 1
while True:
    flag = True
    s_num = str(num)
    diff = 0
    pos = 0
    pos_value = 0
    for i in range(len(s_num)-1, 0, -1):
        diff = int(s_num[i]) - int(s_num[i-1])
        if abs(diff) > 1:
            flag = False
            pos = i
            pos_value = int(s_num[i])
            break
    if flag:
        cnt += 1
    
    if cnt == K:
        print(num)
        sys.exit()
    
    if pos == 0:
#        print(flag, "1:", cnt, num, 1)
        num += 1
    elif diff < 0:
#        print(flag, "-:", cnt, num, (abs(diff) - 1) * (10**(len(s_num)-pos-1)))
        num += (abs(diff) - 1) * (10**(len(s_num)-pos-1))
    else:
        if pos_value != 9:
#            print(flag, "+:", cnt, num, (10 - pos_value - 1) * (10**(len(s_num)-pos-1)) )
            num += (10 - pos_value - 1) * (10**(len(s_num)-pos-1))
        else:
#            print(flag, "+:", cnt, num, (10 - pos_value ) * (10**(len(s_num)-pos-1)) )
            num += (10 - pos_value ) * (10**(len(s_num)-pos-1))
            if pos != len(s_num) - 1:
                num -=  int(s_num[pos+1:])
#    print("-:", cnt, num)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    int q; cin >> q;
    list<int> L;
    auto cursor = L.end();
    REP(i, q){
        int op; cin >> op;
        int d;
        switch(op){
            case 0:
                cin >> d;
                cursor = L.insert(cursor, d);
                break;
            case 1:
                cin >> d;
                if(d >= 0){
                    REP(i, d)
                        ++cursor;
                }else{
                    REP(i, -d)
                        --cursor;
                }
                break;
            case 2:
                cursor = L.erase(cursor);
        }
    }
    for(auto &a: L)
        cout << a << "\n";
    return 0;
}



Measured memory_bytes: 18632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {

	int th,ts,ah,as;
	cin >> th >> ts >> ah >> as;

	while (1) {
	  
		//Taka attack
		ah = ah - ts;
		if (ah <= 0) {
			cout << "Yes" << endl;
			break;
		}
		//Aoki
		th = th - as;
		if (th <= 0) {
			cout << "No" << endl;
			break;
		}
	}


	return 0;

}

Measured memory_bytes: 3504
#include <stdio.h>

int main(void){

  int n, a[100], i, j, minj, k, co = 0, coo;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  for(i = 0; i < n-1; i++){
    minj = i;
    coo = co;
    for(j = i; j < n; j++){
      if(a[j] < a[minj]){
	if(co == coo) co++;
	minj = j;
      }
    }
    k = a[i];
    a[i] = a[minj];
    a[minj] = k;
  }

  for(i = 0; i < n-1; i++){
    printf("%d ", a[i]);
  }
  printf("%d\n%d\n", a[n-1], co);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;
int n;

int main(){
	IOS
	cin >> n;
	for(int i=1;i<=9;i++){
		if(n%i){
			continue;
		}
		if(n/i<=9){
			cout << "Yes" << '\n';
			return 0;
		}
	}
	cout << "No" << '\n';
}


Measured memory_bytes: 3660
n = int(input())
s = input()
if n <= 2:
  print(0)
  quit()
r,g,b = 0,0,0
for i in range(n):
  r += 1*(s[i]=="R")
  g += 1*(s[i]=="G")
  b += 1*(s[i]=="B")
ans = r*g*b

for i in range(n-2):
  for j in range(i+1,n):
    l = [i,j,2*j-i]
    if l[2] >= n:
      break
    r,g,b = 0,0,0
    for k in l:
      r += 1*(s[k]=="R")
      g += 1*(s[k]=="G")
      b += 1*(s[k]=="B")
    if r*g*b == 1:
      ans -= 1
print(ans)

Measured memory_bytes: 68568
#include <iostream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
using namespace std;

int main() {
	int N;
  int V[21];
  int C[21];
  cin >> N;
  int i;
  rep(i,N)cin >> V[i]; 
  rep(i,N)cin >> C[i];
  int ans=0;
  rep(i,N){
   ans+=(V[i]>C[i] ? V[i]-C[i]:0);
  }
  cout << ans;
}


Measured memory_bytes: 256
N = int(input())
E = []
for n in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        E.append((n, x - 1, y))
ans = 0
for k in range((1 << N) - 1, -1, -1):
    status = [(k >> i) & 1 for i in range(N)]
    no_paradox = True
    for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] != yb):
            no_paradox = False
            break
    if no_paradox:
        ans = max(ans, sum(status))
print(ans)

Measured memory_bytes: 3064
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
use std::collections::VecDeque;
fn main() {
    input! {
    N:usize,
    M:usize,
    AB:[(Usize1,Usize1);M]
    }
    // 部屋iから繋がっている部屋のリスト
    let mut tonari: Vec<Vec<usize>> = vec![Vec::with_capacity(M); N];
    let mut ans: Vec<i32> = vec![-1; N];
    for (a, b) in AB {
        tonari[a].push(b);
        tonari[b].push(a);
    }
    //    for i in 0..N {
    //        println!("{}={:?}", i, tonari[i]);
    //    }
    let mut nexts: VecDeque<usize> = VecDeque::new();
    nexts.push_front(0);
    while let Some(i) = nexts.pop_back() {
        //        println!("{}={:?}", i, tonari[i]);
        for &j in tonari[i].iter() {
            if ans[j] == -1 {
                ans[j] = i as i32;
                nexts.push_front(j);
            }
        }
    }
    println!("Yes");
    for j in 1..N {
        println!("{}", ans[j] + 1);
    }
}


Measured memory_bytes: 16568
"use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function main(input) {
  var lines = input.split('\n');
  var s = parseInt(lines[0]);
  var memo = new Set();
  var a = s;
  var index = 1;

  while (true) {
    if (memo.has(a)) {
      console.log(index);
      return;
    }

    memo.add(a);
    index++;
    a = a % 2 === 0 ? a / 2 : 3 * a + 1;
  }
}

var P = 1e9 + 7;
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
    return parseInt(n);
  });
}
/**
 * Iterates over integers in [start, end).
 */


function* range(start, end) {
  for (var i = start; i < end; i++) {
    yield i;
  }
}
/**
 * Iterates over integers in [end, start) in desc order.
 */


function* rangeRev(start, end) {
  for (var i = start - 1; i >= end; i--) {
    yield i;
  }
}
/**
 * Runs a recursive function expressed as a generator function.
 */


function runRecursive(func) {
  // 最終結果を受け取るオブジェクトを用意
  var rootCaller = {
    lastReturnValue: null
  }; // 自前のコールスタックを用意

  var callStack = []; // 最初の関数呼び出しを追加

  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    args[_key - 1] = arguments[_key];
  }

  callStack.push({
    iterator: func.apply(void 0, args),
    lastReturnValue: null,
    caller: rootCaller
  });

  while (callStack.length > 0) {
    var stackFrame = callStack[callStack.length - 1];
    var iterator = stackFrame.iterator,
        lastReturnValue = stackFrame.lastReturnValue,
        caller = stackFrame.caller; // 関数の実行を再開

    var _iterator$next = iterator.next(lastReturnValue),
        value = _iterator$next.value,
        done = _iterator$next.done;

    if (done) {
      // 関数がreturnしたので親に返り値を記録
      caller.lastReturnValue = value;
      callStack.pop();
    } else {
      // 関数がyieldした（valueは再帰呼び出しの引数リスト）
      callStack.push({
        iterator: func.apply(void 0, _toConsumableArray(value)),
        lastReturnValue: null,
        caller: stackFrame
      });
    }
  }

  return rootCaller.lastReturnValue;
}


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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
//#define int long long
#define ll long long
#define endl "\n"
#define inf ULLONG_MAX
#define gcd __gcd
#define deb(x) cout << #x << " " << x << endl;
#define pr(x) cout << x << endl;

#define sz(a) ((ll)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())
#define cpres(c, val) (find(all(c), val) != (c).end())
#define dec greater<ll>()
#define sortv(x) sort(all(x))
#define revsortv(x) sort(all(x), dec)
#define com(x) ((x) * (x + 1) / 2)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define ed end()
#define bs binary_search // to find if an element is present or not in Ologn time, return a boolean
#define ub upper_bound   // to find an element strictly greater than the given no.
#define lb lower_bound   // lb(v,begin(), v.end(), n) gives the iterator

#define fo(n) for (ll i = 0; i < n; i++)
#define fo1(n) for (ll i = 1; i < n; i++)
#define fo2(i, n) for (ll i = 0; i < n; i++)
#define fo3(i, a, b) for (ll i = a; i < b; i++)
#define fors(a) cin >> a[i]
#define forp(a) cout << a[i] << " "
#define prv(a, n)  \
    fo(n) forp(a); \
    cout << endl;
#define fob(i, a, b) for (ll i = (b); i >= (a); i--)

typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef unordered_map<string, ll> umsl;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;

#define scan(v, n)   \
    vl v;            \
    fo(n)            \
    {                \
        ll item;     \
        cin >> item; \
        v.pb(item);  \
    }

const ll INF = 0xFFFFFFFFFFFFFFFL;;
const ll N = 1e9 + 7;
void swap1(ll a,ll b){
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void solve()
{
ll n,k;
cin>>n>>k;
scan(a,n);
sort(all(a));
ll sum=0;
fo(k){
    sum=sum+a[i];
}
cout<<sum;
}



int32_t main(int32_t argc, char **argv)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif*/

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

    cerr << endl
         << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;
}

Measured memory_bytes: 3808
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <string.h>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);

using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<3*n*n<<endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

c= 0
d=0
s=sum(a)

for i in range(0,N):
  if c<s/2:
    c+=a[i]
  else:
    break

a.reverse()
for i in range(0,N):
  if d<s/2:
    d+=a[i]
  else:
    break

if c<d:
  print(c*2-s)
else:
  print(d*2-s)


Measured memory_bytes: 26764
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int maxn=100111;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int bit[maxn];
void add(int x,int v)
{
	for(;x<maxn;x+=x&-x)
	{
		bit[x]+=v;
		if(bit[x]>=mod)bit[x]-=mod;
	}
}
int query(int x)
{
	int ret=0;
	for(;x;x-=x&-x)
	{
		ret+=bit[x];
		if(ret>=mod)ret-=mod;
	}
	return ret;
}

int n,m,a[maxn],b[maxn],l[maxn],r[maxn],dp[maxn];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<=m;i++)scanf("%d",b+i);
	
	int cur=1;
	vector<pii> vs;vector<int> vy;
	for(int i=1;i<=n;++i)
	{
		if(a[i]<b[1]||a[i]>b[m])continue;
		while(b[cur]<a[i])cur++;
		l[i]=a[i]-b[cur-1];
		r[i]=b[cur]-a[i];
		vs.pb(mp(l[i],r[i]));
		vy.pb(r[i]);
	}
	vs.pb(mp(0,0));vy.pb(0);
	vs.pb(mp(inf,inf));vy.pb(inf);
	sort(vs.begin(),vs.end());vs.erase(unique(vs.begin(),vs.end()),vs.end());
	sort(vy.begin(),vy.end());vy.erase(unique(vy.begin(),vy.end()),vy.end());
	for(int i=0;i<(int)vs.size();i++)vs[i].ss=upper_bound(vy.begin(),vy.end(),vs[i].ss)-vy.begin();
	
	dp[0]=1;
	for(int i=0,nxt=0;i<(int)vs.size();i=nxt)
	{
		for(;nxt<(int)vs.size()&&vs[i].ff==vs[nxt].ff;nxt++);
		for(int j=i;j<nxt;j++)if(j)dp[j]=query(vs[j].ss-1);
		for(int j=i;j<nxt;j++)add(vs[j].ss,dp[j]);
	}
	printf("%d\n",dp[(int)vs.size()-1]);
	
	return 0;
}

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

int main() {
    int S;
    cin >> S;
    string T = "NA";
    int S_tho = S / 1000;
    int S_hun = (S - S_tho * 1000) / 100;
    int S_ten = (S - S_tho * 1000 - S_hun * 100) / 10;
    int S_one = S - S_tho * 1000 - S_hun * 100 - S_ten * 10;

    int top = S_tho * 10 + S_hun;
    int bottom = S_ten * 10 + S_one;

    if (bottom <= 12 && bottom > 0) {
        T = "YYMM";
    }

    if (top <= 12 && top > 0) {
        T = "MMYY";
    }

    if (top <= 12 && bottom <= 12 && top > 0 && bottom > 0) {
        T = "AMBIGUOUS";
    }

    cout << T << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int x, y;
	cin >> x >> y;

	if (x == 2 || y == 2) {
		cout << "No";
	}
	else if ((x == 4 || x == 6 || x == 9 || x == 11) &&
		(y == 4 || y == 6 || y == 9 || y == 11))
	{
		cout << "Yes";
	}
	else if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) &&
		(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))
	{
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x,n;
  cin>>x>>n;
  int p[n];
  int xx[201]={};
  rep(i,n){
    cin>>p[i];
    xx[p[i]]=1;
  }
  int now=INF,ans=n;
  rep(i,201){
    if(xx[i]==0){
      if(now>abs(x-i)){
	now=abs(x-i);
	ans=i;
      }
    }
  }
 
    cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 3648
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

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

show_flg=False
show_flg=True

from functools import reduce
ans=0
n=I()
a=LI()
ans=3**n-reduce(lambda x,y:x*y,[2-i%2 for i in a])
print(ans)




Measured memory_bytes: 39788
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    const int TMP = 1000;
    for(;;){
        int a,b,c,d,e,f;
        if(!(cin >> a >> b >> c >> d >> e >> f))
            return 0;
        int x = 10 * TMP * (c*e - b*f) / (a*e - b*d);
        int y = 10 * TMP * (c*d - a*f) / (b*d - a*e);
        int xSign = (x>=0? 1:-1);
        int ySign = (y>=0? 1:-1);
        x = abs(x);
        y = abs(y);

        if(x % 10 >= 5)
            x += 10;
        x /= 10;
        if(xSign == -1 && x > 0)
            cout << '-';
        printf("%d.%03d ", x/TMP, x%TMP);

        if(y % 10 >= 5)
            y += 10;
        y /= 10;
        if(ySign == -1 && y > 0)
            cout << '-';
        printf("%d.%03d\n", y/TMP, y%TMP);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a,b;
  cin>>a>>b;
  if(a>b) swap(a,b);
  int ans=b;
  ans+= max(a,b-1);
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(a+b>c+d) cout<<"Left";
  else if(a+b==c+d) cout<<"Balanced";
  else cout<<"Right";
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


bool min_u(int&m, int v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	vvi f;
	vvi used;
	int n;
	vi vx, vy;

	solve(int n) : n(n) {
		vx={0,1,0,-1};
		vy={1,0,-1,0};

		used.resize(n+2);
		for(auto&m:used) m.assign(n+2,0);
		f.resize(n+2);
		for(auto&m:f) m.assign(n+2,-1);

		for(int y=1;y<=n;y++)
		{
			for(int x=1;x<=n;x++)
			{
				int v=x-1;
				min_u(v, y-1);
				min_u(v, n-x);
				min_u(v, n-y);
				f[y][x]=v;
				used[y][x]=1;
			}
		}
	}
	int armin(int x, int y)
	{
		int v=n;
		for(int i=0;i<4;i++)
		{
			int nx=x+vx[i];
			int ny=y+vy[i];
			min_u(v, f[ny][nx]);
		}
		return v;
	}
	int remove(int x, int y)
	{
		int ret=f[y][x];

		used[y][x]=0;
		f[y][x]=armin(x, y);

		queue<pii> q;
		q.push(make_pair(x, y));
		while(!q.empty())
		{
			tie(x,y)=q.front();
			q.pop();
			for(int i=0;i<4;i++)
			{
				int nx=x+vx[i];
				int ny=y+vy[i];
				if(f[ny][nx]<0) continue;
				if(min_u(f[ny][nx], armin(nx, ny)+used[ny][nx]))
				{
					q.push(make_pair(nx,ny));
				}
			}
		}
		return ret;
	}
	int operator()(vi&p) {
		int ans=0;
		for(int t:p)
		{
			int x=(t-1)%n+1;
			int y=(t-1)/n+1;
			ans+=remove(x, y);
		}
		return ans;
	}
};


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi p(n*n);
		for(auto&mp:p) scanf("%d", &mp);

		printf("%d\n", solve(n)(p));
	}
	return 0;
}


Measured memory_bytes: 5660
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n,k;
cin>>n>>k;
ll a[n];
ll l=1,r=0;
ll ans=0;
for(ll i=0;i<n;i++)
{
cin>>a[i];
r=max(r,a[i]);
}
ans=r;
while(l<=r)
{
ll mid=l+(-l+r)/2;
ll c=0;
for(ll i=0;i<n;i++)
{
ll h=a[i]/mid-1;
ll g=h;
if(a[i]%mid!=0)
{
g++;
}
c+=g;
}
if(c<=k)
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
ll h=ans;
cout<<ans<<endl;
}




/*
 * ||||


 */

Measured memory_bytes: 5124
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

long long inv[N];
long long fac[N];
long long finv[N];

void cominit(){
    fac[0] = fac[1] =1;
    finv[0] = finv[1] =1;
    inv[1] = 1;
    for(int i = 2; i < N; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i]= mod - inv[mod % i] * (mod / i) % mod;
        finv[i]= finv[i - 1] * inv[i] % mod;
    }
}

long long nCr(long long n , long long r){
    if(n == r)
        return 1;
    if(r == 0)
        return 1;
    if(n < r)
        return 0;
    if(n < 0 || r < 0)
        return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) %mod;
}

void add_self(int & ans , int add){
    long long tmp = ans;
    tmp += add;
    tmp %= mod;
    ans = tmp;
}

int main(){
    cominit();
    int n , k;
    scanf("%d%d" , &n , &k);
    int ans = 0;
    for(int i = 0; i <= min(n-1 , k); i++){
        add_self(ans , nCr(n , i) * nCr(n - 1 , n - i - 1) % mod);
    }
    printf("%d\n" , ans);
}


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

using namespace std;

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

	int n; cin >> n;
	vector<int> reg(n+2, 0);

	for(int i=1; i<=n; i++) 
		cin >> reg[i];

	int sum = 0;
	for(int i=0; i<=n; i++) 
		sum += (abs(reg[i+1] - reg[i]));
	
	for(int i=1; i<=n; i++) {
		int cont = sum;

		cont = cont - abs(reg[i+1] - reg[i]) - abs(reg[i] - reg[i-1]) + abs(reg[i+1] - reg[i-1]);
		cout << cont << "\n";
	}


	return 0;
}

Measured memory_bytes: 1664
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int n;
    cin >> n;
    vector<pair<Int, Int>> in(n);
    for (int i = 0; i < n; i++) {
        cin >> in[i].second >> in[i].first;
    }
    sort(in.begin(), in.end());

    bool ans = true;
    Int time = 0;
    for (int i = 0; i < n; i++) {
        time += in[i].second;
        if (in[i].first < time) {
            ans = false;
            break;
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 6368
import sys
input = sys.stdin.buffer.readline
n,q=map(int,input().split())
import heapq
S=[]
D=dict()
for i in range(n):
  s,t,x=map(int,input().split())
  S.append((1,x,max(0,s-x)))
  S.append((-1,x,max(0,t-x)))
  D[x]=False
S.sort(key=lambda x:x[2])
X=[]
cur=0
for i in range(q):
  d=int(input())
  while cur<2*n:
    a,b,c=S[cur]
    if c>d:
      break
    else:
      cur+=1
      if a==1:
        heapq.heappush(X,b)
        D[b]=True
      else:
        D[b]=False
  while X:
    ans=heapq.heappop(X)
    if D[ans]:
      print(ans)
      heapq.heappush(X,ans)
      break
  if not X:
    print(-1)

Measured memory_bytes: 72844
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    vector<ll> h(n);

    for (auto &i: h)
    {
        cin >> i;
    }

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

    ll min (1E+16);
    ll tmp (0);
    for (ll i=0; i<n-k+1; i++)
    {
        //cout << h[i] << " " << h[i+k-1] << endl;

        tmp = h[i+k-1] - h[i];     
        if (tmp < min)
        {
            min = tmp;
        }
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 1024
import time as ti


class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 50010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        self.queue[self.tail].name = name
        self.queue[self.tail].time = time
        self.tail = (self.tail + 1) % self.length

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        self.queue[self.head].name = ""
        self.queue[self.head].time = 0
        self.head = (self.head + 1) % self.length

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time, end_time_list):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head].forward_time(interval)
    if value <= 0:
        current_time += (interval + value)
        end_time_list.append([my_queue.queue[my_queue.head].name, current_time])
        # print my_queue.queue[my_queue.head].name, current_time
        my_queue.dequeue()

    elif value > 0:
        current_time += interval
        name, time = my_queue.queue[my_queue.head].name, \
                     my_queue.queue[my_queue.head].time
        my_queue.dequeue()
        my_queue.enqueue(name, time)

    return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1

end_time_list = []
current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time, end_time_list)

for data in end_time_list:
    print data[0], data[1]

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


int main(){
    string s;
    cin >> s;
    
    bool flag1=false, flag2=true;
    int k=11;
    if(s[0]=='A'){
        for(int i=2; i<s.length()-1; i++){
            if(s[i]=='C'){
                flag1=true;
                k = i;
            }
        }
        for(int j=1; j<s.length(); j++){
            if(j != k){
                if(s[j]<'a' || s[j]>'z'){
                    flag2=false;
                }
            }
        }
    }
    if(flag1==true&&flag2==true){
        cout << "AC" << endl;
    }
    else
        cout << "WA" << endl;
}


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

res = 0
rem = 0

for i in range(N):
    mobs_rem = min(A[i], rem)
    A[i] -= mobs_rem
    mobs = min(A[i], B[i])
    rem = B[i] - mobs
    res += (mobs+mobs_rem)

res += min(A[N], rem)
print(res)


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

int main() {
    string S;
    cin >> S;

    if (S == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    
    for (int i = 0; i < S.size(); i++) {
        for (int j = i; j < S.size(); j++) {
            string t;
            for (int k = 0; k < S.size(); k++) {
                if (k >= i && k <= j) continue;
                t.push_back(S[k]);
            }
            if (t == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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

signed main(){
	string s;
	cin>>s;
	int cnt0=0;
	int n=s.size();
	rep(i,s.size()) cnt0+=s[i]=='0';
	cout<<2*min(n-cnt0,cnt0)<<endl;

	return 0;
}

Measured memory_bytes: 3748
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Feb  8 14:34:23 2020
//
package main

import "fmt"

const MOD = 1e9 + 7

var N int
var S string

func main() {
	fmt.Scan(&N, &S)
	ans := 0
	for i := range S {
		if i+2 < len(S) && S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C' {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define INF (ll)1e19
#define N 200005

using namespace std;

ll n, k, a[N], b[N], c, ans;

int main() {
    //freopen("txt.in", "r", stdin);
    //freopen("txt.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
    k++;
    for (int i = 30; i >= 0; i--)
    if (k & (1 << i)) {
        c ^= 1 << i;
        ll p = 0;
        for (int j = 1; j <= n; j++)
            if ((a[j] & c) == 0) p += b[j];
        ans = max(ans, p);
        c ^= 1 << i;
    }
    else c ^= 1 << i;
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  long long K;
  cin >> S >> K;
  vector<int> data(S.size());
  for (int i = 0; i < S.size(); i++) {
    data.at(i) = S.at(i) - '0';
  }
  int ans;
  for (int i = 0; i < S.size(); i++) {
    if(data.at(i) == 1 && i <= K - 1) {
      ans = 1;
      if (K - 1 == i) break;
    } else {
      ans = data.at(i);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
//const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,q;
	cin>>n>>q;
	vl x(n),y(n),z(n),r(n),a(n);
	for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i]>>r[i]>>a[i];
	for(int i=0;i<q;i++){
		ll res=0,sx,sy,sz,tx,ty,tz;
		cin>>sx>>sy>>sz>>tx>>ty>>tz;
		ll dx=tx-sx,dy=ty-sy,dz=tz-sz;
		for(int j=0;j<n;j++){
			if((x[j]-sx)*dx+(y[j]-sy)*dy+(z[j]-sz)*dz<0) continue;
			if(-(x[j]-tx)*dx-(y[j]-ty)*dy-(z[j]-tz)*dz<0) continue;
			ll gx=x[j]-sx,gy=y[j]-sy,gz=z[j]-sz;
			ll px=gy*dz-gz*dy,py=gz*dx-gx*dz,pz=gx*dy-gy*dx;
			if(px*px+py*py+pz*pz<=r[j]*r[j]*(dx*dx+dy*dy+dz*dz)) res+=a[j];
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3224
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
//using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 300005;
/*template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//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;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    int n;
    cin>>n;
    int v=n%1000;
    if(!v) cout<<v;
    else
  cout<<1000-v<<endl;
}



Measured memory_bytes: 3632