akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int N, K;
char Str[700005];
void Read()
{
    cin >> N >> K;
    cin.get();
    cin.getline(Str + 1, 200005);
    for(int i = N + 1; i <= 3 * N; i++)
        Str[i] = 'A';
}
inline char Code(char ch, int rev)
{
    if(rev == 0)
        return ch;
    if(ch == 'A')
        return 'B';
    return 'A';
}
void Solve()
{
    int start = 1, times = 0, rev = 0;
    while(start <= N * 2 && times < K)
    {
        if(Code(Str[start], rev) == 'A')
            Str[start] = Code('B', rev), times++;
        else
        {
            ++start;
            rev = 1 - rev;
            if(rev == 1)
                Str[start + N - 1] = 'B';
            times++;
        }
    }
    if(times == K)
    {
        for(int i = start; i <= start + N - 1; i++)
            cout << Code(Str[i], rev);
        cout << "\n";
        return;
    }
    times = K - times;
    if(N % 2 == 1)
    {
        if(times % 2 == 0)
        {
            for(int i = 1; i <= N / 2; i++)
            cout << "AB";
        cout << "A";
        cout << "\n";
        }
        else
        {
            cout << "B";
            for(int i = 1; i <= N / 2; i++)
            cout << "BA";

        cout << "\n";
        }
    }
    else
    {
        for(int i = 1; i <= N / 2; i++)
            cout << "BA";
        cout << "\n";
    }
}
int main()
{

    Read();
    if(N == 1)
    {
        if(Str[1] == 'A')
        {
            if(K % 2 == 1)
        cout << "B\n";
        else
            cout << "A\n";

        }
        else
        {
            if(K % 2 == 1)
        cout << "A\n";
        else
            cout << "B\n";
        }
                return 0;
    }
    Solve();
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

template <class T>
class cumulativeSum
{
private:
    int n;
    vector<T> sum;
public:
    cumulativeSum(const vector<T>& a)
    {
        n = a.size();
        sum.assign(n+1, 0);
        for(int i=0; i<n; ++i)
            sum[i+1] = a[i] + sum[i];
    }
    T getSum(int x1, int x2)
    {
        x1 = max(x1, 0);
        x2 = min(x2, n);
        if(x1 >= x2)
            return 0;
        return sum[x2] - sum[x1];
    }
};

const long long INF = LLONG_MAX / 2;

long long tmp(const vector<long long>& a, int x)
{
    set<long long> s(a.begin(), a.end());

    long long ans = 0;
    while(!s.empty()){
        ans += *s.rbegin();
        s.erase(--s.end());
        if(s.empty())
            break;

        auto it = s.lower_bound(x);
        if(it == s.begin()){
            s.erase(it);
        }
        else{
            auto it2 = it;
            -- it2;
            if(it == s.end() || x - *it2 <= *it - x)
                s.erase(it2);
            else
                s.erase(it);
        }
    }

    return ans;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[n-1-i];

    if(n % 2 != 0){
        ++ n;
        a.push_back(0);
    }
    a.push_back(-INF);

    vector<long long> b(n);
    for(int i=0; i<n; i+=2)
        b[i] = a[i];
    cumulativeSum<long long> cs1(a), cs2(b);

    vector<long long> v(n/2+1);
    v[0] = INF;
    for(int i=1; i<=n/2; ++i)
        v[i] = (a[i] + a[2*i]) / 2;
    reverse(v.begin(), v.end());

    while(--q >= 0){
        int x;
        cin >> x;

        int i = lower_bound(v.begin(), v.end(), x) - v.begin();
        i = n / 2 + 1 - i;
        long long ans = cs1.getSum(0, i) + cs2.getSum(2*i, n);
        cout << ans << endl;
    }

    return 0;
}


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

int main(){
    long n;
    long cnt;
    cin >> n;
    vector<vector<long>> graph;
    vector<long> memo_ls(1<<n, 0);
    vector<long> input(n);
    bitset<21> tmp;
    graph.resize(n);
    for(int i=0; i< n; i++){
        for(int j=0; j<n; j++) {
            cin >> input[j];
        }
        graph[i] = input;
    }
    memo_ls[0] = 1;
    for(long long i=1; i<(1<<n); i++){
        tmp = i;
        cnt = -1;
        for(int ind: graph[tmp.count()-1]){
            cnt += 1;
            if(ind ==0){
                continue;
            }
            if(not ((i >> cnt) & 1)){
                continue;
            }
            if(i - (1<<cnt) < 0){
                continue;
            }
            memo_ls[i] += memo_ls[i - (1<<cnt)];
            memo_ls[i] %= ((long)pow(10,9)+(long)7);
        }
    }
    cout << memo_ls[(1<<n) - 1] << endl;
}


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

#define INF (1<<30)

int sum[201];

int main(){
	int n;	cin>>n;
	for(int i=0;i<n;i++){
		int x;	cin>>x;
		for(int y=-100;y<=100;y++){
			int j=y+100;
			sum[j]+=(x-y)*(x-y);
		}
	}

	int ans=INF;
	for(int i=0;i<201;i++){
		ans=min(ans,sum[i]);
	}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
import numpy as np
w, h, n, *Q = map(int, open(0).read().split())
B = np.ones((h, w), dtype=int)
for x, y, a in zip(Q[::3], Q[1::3], Q[2::3]):
    if a == 1:
        for i in range(x):
            B[:, i] = 0
    elif a == 2:
        for i in range(x, w):
            B[:, i] = 0
    elif a == 3:
        for i in range(y):
            B[i, :] = 0
    else:
        for i in range(y, h):
            B[i, :] = 0
print(np.sum(B))

Measured memory_bytes: 27172
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
dp=[0,abs(l[0]-l[1])]
for i in range(2,a):
  dp.append(min(abs(l[i]-l[i-1])+dp[i-1],abs(l[i]-l[i-2])+dp[i-2]))
print(dp[-1])

Measured memory_bytes: 20972
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, h[N], a[N];
ll dp[N];
set < pair <int, ll> > s;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> h[i];
   for (int i = 1; i <= n; i ++) cin >> a[i];
   s.in ({0, 0});
   for (int i = 1; i <= n; i ++) {
      dp[i] = (*(-- s.lb ({h[i], 0}))).S + a[i];
      s.in ({h[i], dp[i]});
      while (s.ub ({h[i], dp[i]}) != s.end () && (*(s.ub ({h[i], dp[i]}))).S <= dp[i]) s.erase (s.ub ({h[i], dp[i]}));
   }
   cout << *max_element (dp + 1, dp + n + 1);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 16640
import java.util.Scanner;



public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		long digitSum = 0;
		long digitNum = 0;
		for (int i=0;i<m;i++) {
			long d = sc.nextLong();
			long c = sc.nextLong();
			digitSum += d*c;
			digitNum += c;
		}
		
		System.out.println((digitSum-1)/9+digitNum-1);
	
	}
}





Measured memory_bytes: 94516
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		String s = sc.next(), t = sc.next();
		String ans = s + t;
		for (int i = 0; i <= n; i++) {
			String concat = s.substring(0, i) + t;
			if (concat.substring(0, n).equals(s)) {
				if (ans.length() > concat.length()) {
					ans = concat;
				}
			}
		}
		System.out.println(ans.length());
	}
}

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

const int N = 200010;
typedef long long ll;
typedef std::pair <ll, ll> pii;

struct jewel{
    ll value, id;
    bool ispair;
    
    bool operator < (const jewel &j)const{
        if (value != j.value){
            return value > j.value;
        }
        return ispair > j.ispair;
    }
};

std::vector <int> vec[N];

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0, c, v; i < n; ++ i){
        scanf("%d%d", &c, &v);
        vec[c].push_back(v);
    }
    std::vector <jewel> jewels;
    std::multiset <pii> singin, singout, doubin, doubout, tripout;
    for (int i = 1; i <= k; ++ i){
        std::sort(vec[i].begin(), vec[i].end(), std::greater <int>());
        ll x = vec[i][0] + vec[i][1];
        jewels.push_back({x, i, true});
        doubout.insert({x << 1, i});
        if ((int) vec[i].size() >= 3){
            tripout.insert({(x + vec[i][2]) << 1, i});
        }
        for (int j = 2, sz = vec[i].size(); j < sz; ++ j){
            jewels.push_back({vec[i][j] << 1, i, false});
        }
    }
    std::sort(jewels.begin(), jewels.end());
    puts("-1");
    long long ans = 0;
    for (int i = 2, j = 0, cnt = 0; i <= n; ++ i){
        ll value = jewels[j].value, id = jewels[j].id;
        int num = jewels[j].ispair ? 2 : 1;
        if (cnt + num <= i){
            cnt += num;
            ans += num * value;
            if (num == 1){
                auto u = singout.find({value, id});
                singin.insert(*u);
                singout.erase(u);
            }
            else{
                auto u = doubout.find({value << 1, id});
                doubin.insert(*u);
                doubout.erase(u);
                if ((int) vec[id].size() >= 3){
                    u = tripout.find({((ll) vec[id][0] + vec[id][1] + vec[id][2]) * 2, id});
                    tripout.erase(u);
                }
                for (int j = 2, sz = vec[id].size(); j < sz; ++ j){
                    singout.insert({vec[id][j] << 1, id});
                }
            }
            ++ j;
        }
        if (cnt == i){
            printf("%lld\n", ans >> 1);
            continue;
        }
        ll max = LLONG_MIN;
        if (!singout.empty()){
            max = std::max(max, (-- singout.end()) -> first);
        }
        if (!singin.empty() && !doubout.empty()){
            ll x = singin.begin() -> first;
            ll y = (-- doubout.end()) -> first;
            max = std::max(max, y - x);
        }
        if (!doubin.empty() && !tripout.empty()){
            ll x = doubin.begin() -> first;
            ll y = (-- tripout.end()) -> first;
            max = std::max(max, y - x);
        }
        if (max == LLONG_MIN){
            puts("-1");
            continue;
        }
        printf("%lld\n", (ans + max) >> 1);
    }
    return 0;
}

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

int main(void)
{
    int A,B,C;
    cin>>A>>B>>C;
    if(C>=A&&C<=B)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	vector<int> data_a(n + 1, 0), data_b(m + 1, 0);
	vector<long long> data_a_sum(n + 1, 0), data_b_sum(m + 1, 0);
	rep(i, n) {
		cin >> data_a[i+1];
		data_a_sum[i+1] = data_a[i+1];
		if (i > 0)
			data_a_sum[i+1] += data_a_sum[i];
	}
	rep(i, m) {
		cin >> data_b[i+1];
		data_b_sum[i+1] = data_b[i+1];
		if (i > 0)
			data_b_sum[i+1] += data_b_sum[i];
	}

	int max = 0;
	int check = 0;
	for (int i = m; i > 0; i--) //机Bだけで読める最大の本
		if (data_b_sum[i] <= k) {
			check = i;
			break;
		}

	int j = 0;
	for (int i = check; i >= 0; i--) { //机Bの本を1冊づつ減らした時に読める合計本
		while (1) {
			//cout << "j=" << j << " i=" << i << endl; //確認用
			if (k < data_a_sum[j] + data_b_sum[i])
				break;
			if (i + j > max)
				max = i + j;
			if (j < n) 
				j++;
			else
				break;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 7996
A, B = map(int,input().split())
import math

def tax8(n):
  res = n*(8/100)
  res = math.floor(res)
  return res

def tax10(n):
  res = n*(1/10)
  res = math.floor(res)
  return res

def excluded(a, b):
  for i in range(1300):
    if ((tax8(i)) == a) and ((tax10(i)) == b):
      return i
  return -1

print(excluded(A,B))
  

Measured memory_bytes: 3064
import math
import sys
N=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
if p[-1]==N:
    cnt+=1
        # print(p[i],i+1)
print(cnt)


Measured memory_bytes: 53036
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		int minus = 0;
		int ideal = 0;
		int[] dq = new int[n];
		for ( int i = 0; i < n; i++ ) {
			int inp = in.nextInt();
			dq[i] = inp;
			if ( inp < 0 ) minus++;
			else ideal += inp;
		}
		in.close();

		// 全要素から自由に取捨選択できる場合
		if ( n + minus <= k ) {
			System.out.println(ideal);
			return;
		}

		int total = 0;
		for ( int l = 0; l < n; l++ ) {
			for ( int r = 0; r < n; r++ ) {
				int lr = l + r;
				if ( lr > k || lr > n ) break;

				PriorityQueue<Integer> pool = new PriorityQueue<>();
				for ( int i = 0; i < l; i++ ) {
					pool.add(dq[i]);
				}
				for ( int i = n - 1; n - r <= i; i-- ) {
					pool.add(dq[i]);
				}
				for ( int i = k - lr; 0 < i; i-- ) {
					if(!pool.isEmpty() && pool.peek() < 0) {
						pool.poll();
					}else {
						break;
					}
				}

				int temp = 0;
				for ( Integer i : pool ) {
					temp += i;
				}
				
				// System.out.println("l:" + l + " r:" + r + "   temp:" + temp );
				total = Math.max(total, temp);
			}
		}
		
		System.out.println(total);
	}
}

Measured memory_bytes: 22868
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var l = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        var res = 0;
        for (int i = 1; i < l.Length; i++)
        {
            for (int j = i - 1; j >= 0; j--)
            {
                if (l[j] * 2 <= l[i]) continue;
                var valid = j;
                var invalid = -1;
                while (valid - invalid > 1)
                {
                    var mid = (valid + invalid) / 2;
                    if (l[i] < l[mid] + l[j]) valid = mid;
                    else invalid = mid;
                }
                res += j - valid;
            }
        }
        Console.WriteLine(res);
    }
}




Measured memory_bytes: 13416
import java.util.Scanner;
import java.io.*;
 
class Main {
    public static void main(String[] args)throws IOException{ 
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(in);
                                                              
        while(true){
        String trump = reader.readLine();
            if(trump.equals("-")){
            break;
            }
 
            int m = Integer.parseInt(reader.readLine());
 
            for(int H = 0; H < m; H++){
                int h = Integer.parseInt(reader.readLine());
                String left = trump.substring(0, h);
                String right = trump.substring(h, trump.length());
                trump = right + left;
            }
            System.out.println(trump);
        }
    }
}

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

int main(){
  int dp[20][50001];
  int c[20];
  int n;
  int m;

  cin >> n >>m;
  for(int i=0;i<m;i++) cin>> c[i];
  sort(c,c+m);
  for(int i=0;i<m;i++){
    for(int j=0;j<=n;j++){
      if(i==0) dp[i][j] = j;
      else if(j==0) dp[i][j] = 0;
    }
  }

  for(int i=1;i<m;i++){
    for(int j=1;j<=n;j++){
      if(j>=c[i]) dp[i][j] = min(dp[i-1][j],dp[i][j-c[i]]+1);
      else dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[m-1][n]<<endl;
  return 0;
}

Measured memory_bytes: 5080
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,n,x,y,q;
    t=1;
    for(i=0;i<t;i++){
        cin>>n;
        lli a[n];
        lli s=0;
        map<lli,lli> mp;
        for(j=0;j<n;j++){
            cin>>a[j];
            mp[a[j]]++;
            s=s+a[j];
        }
          cin>>q;

for(j=0;j<q;j++){
            cin>>x>>y;
            if(mp[x]>0){
                s=s-(x*mp[x])+(y*mp[x]);
                mp[y]=mp[x]+mp[y];
                mp[x]=0;
            }
            cout<<s<<"\n";
        }
    }
}



Measured memory_bytes: 9976
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}


void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int a[100010];
int b[100010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int p[100010];
    rep(i, N) cin >> p[i];
    int x[100010], y[100010];
    init(N);
    rep(i, M) {
        cin >> x[i] >> y[i];
        unite(x[i], y[i]);
    }
    //cout << endl;
    rep(i, N) {
        a[i + 1] = find(i + 1);
        b[p[i]] = a[i + 1];
    }
    int ans = 0;
    rep(i, N) {
        if (a[i + 1] == b[i + 1]) ans++;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long w,h,x,y;
	scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
	if (w&1&&h&1) printf("%lld.500000 ",w*h/2);
		else printf("%lld.000000 ",w*h/2);
	if (x*2==w&&y*2==h) puts("1");
		else puts("0");
		return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int x,n;
 cin>>x>>n;
 int x1=x;
 vector<int> vec(n);
for(int i=0;i<n;i++){
  cin>>vec.at(i);
}
sort(vec.begin(), vec.end());
for(int i=0;i<n;i++){
  if(vec.at(i)==x){
    x=x+1;
  }
}
int x2=x;
x=x1;
reverse(vec.begin(), vec.end());
for(int i=0;i<n;i++){
  if(vec.at(i)==x){
    x=x-1;
  }
}
if(x2-x1<x1-x){
  x=x2;
}

cout<<x<<endl;
 }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 510000;
const int MOD = 1e9;

const double PI=3.14159265358979323846;

/*
long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}*/

int length(vector<int> v, int u, int HW){
    if(v.size() == 0) return HW;
    if(v[0] > u) return v[0];
    if(v[v.size() - 1] < u) return HW - v[v.size()- 1] -1;
    else{
        int i = lower_bound(ALL(v), u)- v.begin();
        return v[i] - v[i-1] -1;
    }
}

int main(){
    ll a,b;
    cin >> N >> a >> b;
    ll tot = a + b;
    ll c = N/(a + b), r = N%(a+ b);
    cout << c * a + min(r, a);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int a[100005],n;
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
bool check(){
	int m=0;
	for (int i=1;i<=n;i++) m+=a[i]&1;
	if ((n-m)&1) return 1;
	if (m>1) return 0;
	int d=0;
	for (int i=1;i<=n;i++){
		a[i]^=a[i]&1;
		if (!a[i]) return 0;
		d=gcd(d,a[i]);
	}
	for (int i=1;i<=n;i++) a[i]/=d;
	return check()^1;
}
int main(){
	scanf("%d\n",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (check()) printf("First\n");
		else printf("Second\n");
}

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

#define ll long long int
#define pb push_back

int main()
{
    ll n,m,x,i,j,k,ans=LLONG_MAX,o;
    
    cin >> n >> m>>x;
    ll a[n][m];
    ll c[n];

    
    for(i=0;i<n;i++)
    {
        cin >> c[i];
        
        for(j=0;j<m;j++)
        cin >> a[i][j];
    }
    
    ll opsize = pow(2, n); 
    ll val[m]={0},cost=0,flag=0,temp=0;
    
    for (ll counter = 1; counter < opsize; counter++) 
    { 
        for(i=0;i<m;i++)
        val[i]=0;
        
        cost=0;
        flag=0;
        for (int j = 0; j < n; j++) 
        { 
            
            if (counter & (1<<j)) 
                {
                   cost+=c[j];
                    for(i=0;i<m;i++)
                        val[i]+=a[j][i];
                }
        } 
        
        for(i=0;i<m;i++)
        {
          
            if(val[i] < x)
             flag=1;
        }
        if(!flag)
        {
            ans=min(ans,cost);
            temp=1;
        }
        
    } 
     
     if(temp)
     cout << ans ;
     else
     cout << -1;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<ll>> d(310, vector<ll>(310,longinf));
  rep(i,m){
    int a,b,c; cin >> a >> b >> c; a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

  vector<vector<ll>> gas(n, vector<ll>(n,longinf));
  rep(i,n) gas[i][i] = 0;
  rep(i,n)rep(j,n)if(d[i][j]<=l) gas[i][j] = 1;
  rep(k,n)rep(i,n)rep(j,n) gas[i][j] = min(gas[i][j], gas[i][k]+gas[k][j]);

  int q; cin >> q;
  while(q--){
    int s,t; cin >> s >> t; s--; t--;
    ll ans = gas[s][t] - 1;
    if(ans>=longinf-1) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
        cout << "YES" <<endl;
    }else{
        cout << "NO" <<endl;
    }
}

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

const int mod = (int)1e9 + 7;
typedef long long ll;

ll dp[101][4][4][4];
int n;

void solve() {
	for (ll i = 3; i < n; i++) {
		for(int a = 0;a<4;a++)
			for(int g=0;g<4;g++)
				for(int c=0;c<4;c++)
					for (int d = 0; d < 4; d++) {
						if (a == 0 && c == 2 && d == 3)continue;
						if (a == 0 && g == 2 && d == 3)continue;
						if (g == 2 && c == 0 && d == 3)continue;
						if (g == 0 && c == 2 && d == 3)continue;
						if (g == 0 && c == 3 && d == 2)continue;
						dp[i][g][c][d] += dp[i - 1][a][g][c]%mod;
					}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < 4; i++)for (int j = 0; j < 4; j++)for (int k = 0; k < 4; k++)
		dp[2][i][j][k] = 1;
	dp[2][0][2][3] = dp[2][0][3][2] = dp[2][2][0][3] = 0;
	solve();

	ll sum = 0;
	for (int i = 0; i < 4; i++)for (int j = 0; j < 4; j++)for (int k = 0; k < 4; k++)
		sum += dp[n - 1][i][j][k];
	
	cout << sum%mod << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

enum EventType { End_rw, Person, Start_rw };

struct Event {
  EventType type;  // Start/End roadwork or Person walk
  int64_t t;  // Time of event
  int64_t x;  // Distance in the road
  int64_t inter; // Intercept
  
  Event(EventType _type, int64_t _t, int64_t _x) {
    type = _type;
    t = _t;
    x = _x;
    inter = t - x;
  }

  friend bool operator<(const Event &lhs, const Event &rhs) {
    if (lhs.inter == rhs.inter) {
      return lhs.type < rhs.type;
    }
    return lhs.inter < rhs.inter;
  }
};

int main() {
  
  int64_t n, q;
  std::cin >> n >> q;
  std::vector<Event> events;
  std::set<int64_t> activeBarriers;

  int64_t s, t, x;
  for (auto i=0; i < n; ++i) {
    std::cin >> s >> t >> x;
    events.emplace_back(Start_rw, 2*s-1, 2*x);
    events.emplace_back(End_rw, 2*t-1, 2*x);
  }

  int64_t d;
  for (auto i=0; i < q; ++i) {
    std::cin >> d;
    events.push_back(Event(Person, 2*d, 0));
  };

  std::sort(events.begin(), events.end());

  for (Event event:events) {
    if (event.type == Start_rw) {
      activeBarriers.insert(event.x);
    } else if (event.type == Person) {
      auto distance = activeBarriers.begin();
      if (distance == activeBarriers.end()) {
        std::cout << -1 << '\n';
      } else {
        std::cout << (*distance)/2 << '\n';
      }
    } else if (event.type == End_rw) {
      activeBarriers.erase(event.x);
    }
  }
  
  return 0;
}

Measured memory_bytes: 34404
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val (h, w) = intList()
    val n = readLine()?.toInt() ?: return
    val a = intList()

    buildString {
        val v = mutableListOf<String>()
        var isOdd = false
        repeat(n) { index ->
            val aa = a[index]
            val value = "${index + 1}"
            repeat(aa) {
                v.add(value)
                if (v.size == w) {
                    if (!isOdd) {
                        appendln(v.joinToString(separator = " "))
                    } else {
                        appendln(v.reversed().joinToString(separator = " "))
                    }
                    isOdd = !isOdd
                    v.clear()
                }
            }
        }
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 44752
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,k; cin >> n >> k;
  ll ans = 0;
  for(int b = 1; b <= n; b++){
    ans += max(0,b-k)*(n/b);
    if(k) ans += max(0,n%b-k+1);
    else ans += max(0,n%b-k);
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
int n;
ll qs = 1; 
ll pw[maxn];
vi eg[maxn];
bool fl[3][1005][1005];
int main() {
	for (int i = 0; i < 18; i++) qs *= 10;
	qs %= mod;
	pw[0] = 1;
	for (int i = 1; i < maxn; i++)
		pw[i] = pw[i - 1] * qs % mod;
	int n;
	cin >> n;
	ll mt = 1;
	vector<ll> u[3];
	for (int s = 0; s < 3; s++) {
		int m;
		cin >> m;
		for (int i = 1; i <= n; i++) eg[i].clear();
		for (int i = 0; i < m; i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			eg[u].pb(v), eg[v].pb(u);
		}
		set<int> x;
		for (int i = 1; i <= n; i++)
			x.insert(i);
		while (1) {
			ll cu = 0;
			if (!x.size()) break;
			set<int> y;
			while (x.size()) {
				int r = *(--x.end());
				cu = (cu + pw[r]) % mod;
				x.erase(r);
				for (auto v : eg[r]) {
					if (x.find(v) != x.end()) {
						y.insert(v);
						x.erase(v);
					}
				}
			} 
			u[s].pb(cu);
			x = y;
		}
	}
	ll ans = 0;
	for (int i = 0; i < u[0].size(); i++)
		for (int j = 0; j < u[1].size(); j++)
			for (int k = 0; k < u[2].size(); k++) {
				if (fl[0][i][j] || fl[1][j][k] || fl[2][k][i]) continue;
				fl[0][i][j] = fl[1][j][k] = fl[2][k][i] = 1;
				ll cur = u[0][i] * u[1][j] % mod * u[2][k] % mod;
				ans = (ans + cur) % mod;
			}
	cout << ans << endl;
	return 0;
}


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

int main(){
	char b;
	cin >> b;
	char ans;
	if(b=='A'){ ans = 'T';
	}else if(b=='T'){ ans = 'A';
	}else if(b=='C'){ ans = 'G';
	}else if(b=='G'){ ans = 'C';
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, a;
  scanf("%lld", &n);
  ll num = 0;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    while(!(a % 2)) a /= 2, num++;
  }
  printf("%lld", num);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10;
const int mod=1e9+7;
char g[N][N];
int dp[N][N];
int h,w;

int main(){
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>g[i][j];
            dp[j][0]=0;
        }
        dp[0][i]=0;
    }
    
    dp[1][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(g[i][j]!='#' and (i>1 or j>1)){
                dp[i][j]=(dp[i][j-1] + dp[i-1][j])%mod;
            }
        }
    }
    cout<<(dp[h][w])%mod<<'\n';
    return 0;
}

Measured memory_bytes: 8508
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	string direction;
	cin >> direction;
	bool n = false, w = false, s = false, e = false;
	for(auto &c : direction)
	{
		if(c == 'N') n = true;
		if(c == 'W') w = true;
		if(c == 'S') s = true;
		if(c == 'E') e = true;
	}
	cout << (n == s && w == e ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j,k;
    while(cin>>n,n){
        int data[16][17];
        for(i=0;i<n;i++){
            for(j=0;j<n+1;j++){
                cin>>data[i][j];
            }
        }
        //dp[?¨?????????¨?????????bit??¨???] = ???????????§???????°??????????
        //n??????bit?????????????????????bit??§n+1???????????§?????????????????¨???
        //?????????,dp[(1<<n)-1]??????????????????(??¨?????????????????£????????????)?¨????
        vector<int> dp(1<<n,99999999); 
        
        //?????????????????£??????????????°0???????????????
        dp[0]=0;
        
        //bit?????¶???????????¨?????\??????????????????
        for(i=0;i<(1<<n);i++){
            //?????¨??????????????¶?????????????¬??????¶??????????????????
            // ????????¨?????????????????????????????????????¬?????¨??????§??????????????§??????
            if(dp[i]==99999999) continue;
            
            //j??????j??????????????????????????§???????????¢???????????????????????????
            for(j=0;j<n;j++){
                //????????¢??????????????????????????????
                if((i&(1<<j))!=0) continue;
                
                //????????¢??????????????£?????¨???????????¨?????¶???i??????i|j?????¶??????????§???§??????
                //??????????????°???????????????????????????????????¢???????????¨?????????
                //?????????????????????time???mn_time??¨??????
                int mn_time=data[j][0];
                
                //?????????????????±????????????
                for(k=0;k<n+1;k++){
                    //?????????k??????????????????????????§???????????¢???????????????
                    //???????????????????????????
                    if((i&(1<<k))!=0){
                        //??????????????????????????????
                        mn_time=min(mn_time,data[j][k+1]);
                    }
                }
                int b=(i|(1<<j));
                dp[b]=min(dp[b],dp[i]+mn_time);
            }
        }
        cout<<dp[(1<<n)-1]<<endl;
    }
}


Measured memory_bytes: 3336
array = []
for i in range(5):
  array.append(int(input()))
  
ichi = list(map(lambda x: x%10,array))
ichi = list(map(lambda x: 10 if x==0 else x,ichi))

minichi = min(ichi)

sum = 0
for i in range(5):
  sum += ((array[i]+10-1)//10)*10

if minichi != 10:
  print(sum-10+minichi)
else:
  print(sum)


Measured memory_bytes: 3060
while line=gets
(m,f,r)=line.split().map(&:to_i)
  break if m==-1&&f==-1&&r==-1
  m=f=0 if m==-1 || f==-1
  case m+f
  when 80..100
    puts "A"
  when 65...80
    puts "B"
  when 50...65
    puts "C"
  when 30...50
    puts r >= 50 ? "C" : "D"
  else
    puts "F"
  end
end

Measured memory_bytes: 6100
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	int n;
	cin>>n;
	ll a[200000];
	for(int i=0; i<n; i++){
		cin>>a[i];
		a[i]-=((ll)i);
	}
	ll i0=-2e5, i3=1e9;
	while(1){
		if(i3-i0<=2){
			ll ans=1e15;
			for(ll b=i0; b<=i3; b++){
				ll s=0;
				for(int i=0; i<n; i++){
					s+=abs(a[i]-b);
				}
				if(s<ans) ans=s;
			}
			cout<<ans<<endl;
			return 0;
		}
		ll i1=i0+(i3-i0)/3, i2=i3-(i3-i0)/3;
		ll s1=0, s2=0;
		for(int i=0; i<n; i++){
			s1+=abs(a[i]-i1);
			s2+=abs(a[i]-i2);
		}
		if(s1>s2) i0=i1;
		else i3=i2;
	}
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a,b,c;
	cin >> a>>b>>c;
	if (c<a&&b<c||a<c&&c<b) {
		cout << "Yes" << endl;
	}
	
	
	else { cout << "No" << endl; }
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args ) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
    int j=0;
    int[] A=new int[N];
    for (int i=0;i<N;i++){
      A[i]=sc.nextInt();
    }
    for (int i=0;i<N;i++){
      if (i%2==0) {
        if (A[i]%2==1) {
          j=j+1;
        }  
      }  
    }
    System.out.println(j);
  }
}

Measured memory_bytes: 27156
#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);

ll n, m, q;
vector<ll> a(100), b(100), c(100), d(100);
ll ans = 0;

void bfs(vector<ll> x)
{
    for (ll i = *x.rbegin(); i <= m; i++)
    {
        if (x.size() == n)
        {
            ll res = 0;

            for (ll k = 0; k < q; k++)
            {
                if (c[k] == x[b[k]] - x[a[k]])
                {
                    res += d[k];
                }
            }

            ans = max(res, ans);

            return;
        }

        vector<ll> A = x;
        A.push_back(i);

        bfs(A);
    }
}

int main(void)
{
    cin >> n >> m >> q;

    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    for (int i = 1; i <= m; i++)
    {
        vector<ll> A = {i};
        bfs(A);
    }

    cout << ans << endl;
}


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

#define ll long long

using namespace std;

const int MAXN = 1e5 + 10;
const int MAXM = 1e5 + 10;
const int INF = 0x3fffffff;
const int MOD = 1e9 + 7;

int n, m, k;
int tot, cnt, ans;

int a[MAXN];

string s;

int main() {
	int T;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= k; i++) {
		ans += a[i];
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3772
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


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


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

def main():
  if(0 in A):
    print(0)
    return

  products = 1
  for a in A:
    products *= a
    if(products > 1000000000000000000):
      print(-1)
      return
  print(products)
  return

main()


Measured memory_bytes: 21644
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
#include<algorithm>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);
    int ans=0,id;
    int N,M;
    int a[52],b[520],c[52],d[52];

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,N){
        i==0?ans+=M:ans*=M-1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int N;
long long int num[100000];
long long int sum;
long long int order;
long long int mini, maxi;
long long int s;
long long int pl, mi;

int main() {
	cin >> N;
	mini = LLONG_MAX;
	maxi = 0;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		sum += num[i];
		maxi = max(maxi, num[i]);
		mini = min(mini, num[i]);
	}
	if (sum % (N*(N + 1) / 2)) {
		cout << "NO\n";
		return 0;
	}
	order = sum / (N*(N + 1) / 2);
	if (order*N < maxi) {
		cout << "NO\n";
		return 0;
	}
	if (order > mini) {
		cout << "NO\n";
		return 0;
	}
	pl = order%N;
	mi = (N - pl)%N;
	for (int i = 0; i < N; i++) {
		if (num[(i + 1) % N] > num[i]) {
			if ((num[(i + 1) % N] - num[i]) % N != pl) {
				cout << "NO\n";
				return 0;
			}
		}
		else if (num[(i + 1) % N] < num[i]) {
			if ((num[i] - num[(i + 1) % N]) % N != mi) {
				cout << "NO\n";
				return 0;
			}
		}
	}
	if (pl < 0 || mi < 0)cout << "NO\n";
	else cout << "YES\n";

	return 0;
}



Measured memory_bytes: 1152
n, k = map(int, input().split())
s = input()

joint = 0
cnt = 0
for i in range(1,n):
  if s[i - 1] == s[i] == 'L':
    cnt += 1

for i in range(n - 1):
  if s[i + 1] == s[i] == 'R':
    cnt += 1

for i in range(n-1):
  if s[i] != s[i + 1]:
    joint += 1
  
if joint % 2 == 0:
  cnt += min(2*k, joint)
else:
  if k <= joint // 2:
    cnt += k * 2
  else:
    cnt += joint

print(cnt)

Measured memory_bytes: 40560
def p(x):
 if x%2==0:return 0
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():print(sum(p(int(input())*2+1)for _ in[0]*int(input())))
if'__main__'==__name__:f()


Measured memory_bytes: 5996
S = list(input())
if len(S)==4:
    if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
        print('Yes')
    elif S[0]==S[2] and S[1]==S[3] and S[0]!=S[3]:
        print('Yes')
    elif S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int solve(int a[], int n, int k)
{
    int dp[n];
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    
    dp[0] = 0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=1; j<=k; j++)
        {
            if(i+j>=n) break;
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i+j]-a[i]));
        }

    }
    
    return dp[n-1];
}

int main()
{
    int n, k;
    cin>>n>>k;
    
    int a[n];
    for (int i=0;i<n;i++)
    cin>>a[i];
    
    int res = solve(a, n, k);
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
  int A, B, X;
  cin >> A >> B >> X;

  if(A > X){
    cout << "NO" << endl;
  }else{
    int B_;
    B_ = X-A;
    cout << (B >= B_ ? "YES" : "NO") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{char s[30];
int b,c;b=c=0;
cin>>s;
int a=strlen(s);
   for(int i=2;i<a-1;i++)
    if(s[i]=='C')b++;
    for(int i=0;i<a;i++)
        if(s[i]>='A'&&s[i]<='Z')c++;
   if(s[0]!='A'||b!=1||c!=2)cout<<"WA\n";
   else cout<<"AC\n";
    return 0;
}

Measured memory_bytes: 256