akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
 
    int ans = 0;
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            for (int k = 0; k < j; k++) {
                if (l[k] != l[j] and l[i] != l[j] and
                    l[k] + l[j] > l[i]) {
                    ans++;
                }
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int h,w,n,c=0;
  cin>>h>>w>>n;
  int a[n],ans[h][w];
  r(i,n)cin>>a[i];
  r(i,h){
    if(i%2==0){
      r(j,w){
        if(a[c])ans[i][j]=c;
        else ans[i][j]=++c;
        a[c]--;
      }
    }else{
      for(int j=w-1;j>=0;j--){
        if(a[c])ans[i][j]=c;
        else ans[i][j]=++c;
        a[c]--;
      }
    }
  }
  r(i,h){
    r(j,w){
      if(j)cout<<' ';
      cout<<ans[i][j]+1;
    }cout<<endl;
  }
}

Measured memory_bytes: 384
import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def fix(a):
    mn = min(a) - 1
    return [x - mn for x in a]

def main():
    N = rl(int)
    p = srl(int)
    a = range(N)
    b = list(reversed(a))
    inc = [0] * (N+1)
    for i, v in enumerate(p[1:], 1):
        a[v-1] += i
        inc[v] += i
    s = 0
    for i in xrange(N):
        s += inc[i]
        a[i] += s
        b[i] -= s
    print " ".join(map(str, fix(a)))
    print " ".join(map(str, fix(b)))

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//user-defined hash table for pairs --------------------------------------------------------------------------------------------------
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else 
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------


void solve()
{
   int l,r,d;
   cin>>l>>r>>d;
   cout<<r/d-(l-1)/d<<endl;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
    
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); long sum = 0;
		long[] A = new long[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			sum += A[i];
		}
		long ans = Long.MAX_VALUE, sn_sum = 0;
		for(int i = 0; i < N - 1; i++) {
			sn_sum += A[i];
			ans = Math.min(ans, Math.abs(sn_sum - (sum - sn_sum)));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 76636
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        if (s.charAt(s.length() - 1) == 's') {
            s += "es";
        } else {
            s += "s";
        }
        String result = s;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 38436
class in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const my_iterator& begin(){return i;}const my_iterator& end(){return n;}};

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, d, x;
    cin >> n >> d >> x;
    vector<vector<int>> p(d, vector<int>(n));
    for(auto& v : p)
      for(auto& a : v)
        cin >> a;
    for(int i : in(d - 1)) {
        vector<int> dp(x + 1, 0);
        for(int j : in(n)) if(p[i][j] <= x) for(int k : in(p[i][j], x + 1))
          dp[k] = max(dp[k], dp[k - p[i][j]] + p[i + 1][j] - p[i][j]);
        x += dp[x];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3208
# ABC 117 C - Streamline
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
diff = [0]*(M-1)
for i in range(M-1):
    diff[i] = abs(X[i+1] - X[i])

diff.sort()
if N >= M:
    print(0)
else:
    diff = diff[0:M-N]
    print(sum(diff))

Measured memory_bytes: 13968
S=input()
TT=[[0]*10 for _ in range(10)]
N=int(S)

for i in range(1,N+1):
    ii=str(i)
    a=int(ii[0])
    b=int(ii[-1])
    TT[a][b]+=1
    
ans=0
for i in range(10):
    for j in range(10):
        ans+=TT[i][j]*TT[j][i]
        
print(ans)

Measured memory_bytes: 40428
#include <stdio.h>

int main() {
  int N,A,B;
  scanf("%d %d %d",&N,&A,&B);
  int max = (A >= B) ? B : A;
  int min = (A+B > N) ? ((A+B)-N) : 0;
  printf("%d %d\n",max,min);
  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  if (S.length() != T.length()) {
    cout << "No";
  }
  else {
    bool iwa = false;
    vector<bool>check(S.length());
    for (int i = 0; i < S.length(); i++) {
      check.at(i) = true;
      for (int j = 0; j < S.length(); j++) {
        if (S.at(j) != T.at((i + j) % S.length())) {
          check.at(i) = false;
        }
      }
      if (check.at(i)) {
        iwa = true;
      }
    }
    if (iwa) {
      cout << "Yes";
    }
    else {
      cout << "No";
    }
  }
}

Measured memory_bytes: 256
#coding: UTF-8

shuffle = []
while True:
    str = input()
    if str == '-':
        break
    m = int(input())
    for num in range(m):
        h = int(input())
        str = str[h:] + str[:h]
    shuffle.append(str)

for i in range(len(shuffle)):
    print(shuffle[i])


Measured memory_bytes: 5604
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x) // 2, input().split()))

    X = A[0]
    for i in range(1, N):
        a, b = X, A[i]
        X = a * b // gcd(a, b)
        if X > M:
            print(0)
            exit(0)

    for a in A:
        if (X // a) % 2 == 0:
            print(0)
            exit(0)

    print((M // X + 1) // 2)


if __name__ == '__main__':
    main()


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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	string s;
	cin >> s;
	if(s.back() == 's'){
		s += "es";
	}
	else{
		s += "s";
	}
	cout << s << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3644
fun main() = Thread(null, ::abc173a, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173a() {
    val n = readLine()!!.toInt()

    var payment = 0

    while (payment < n) payment += 1000

    val answer = payment - n

    println(answer)
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N, std::vector<std::string> S) {
  unordered_set<string> items;
  ll ret = 0;
  rep(i,N){
    if(items.find(S[i])==items.end()){
      items.insert(S[i]); ret++;
    }
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

void Main() {
  int n = read<int>();
  int m = read<int>();

  map<int, int> X;
  vi S(m);

  rep(i, n) {
    int x = read<int>();
    X[x]++;
    S[x%m]++;
  }

  int ans = 0;

  vector<vector<map<int, int>>> M2(m, vector<map<int, int>>(2));

  int zc = 0;
  int hc = 0;

  forr(xc, X) {
    int x = xc.fst;
    int c = xc.snd;
    if (c == 0) continue;

    if (x % m == 0) {
      zc += c;
    }
    else {
      if ((x % m) * 2 == m) hc += c;
      else M2[x%m][c%2][x] += c;
    }
  }

  ans += zc / 2;
  ans += hc / 2;

  rep(mo, 1, m) {
    int ta = m - mo;

    int sz1 = sz(M2[mo][1]);
    int sz2 = S[ta];

    int can = min(sz1, sz2);
    ans += can;
    S[mo] -= can;
    S[ta] -= can;

    /*
    cout<<"=========="<<endl;
    cout<<"mo: "<<mo<<endl;
    cout<<"ta: "<<ta<<endl;
    cout<<"sz1: "<<sz1<<endl;
    cout<<"sz2: "<<sz2<<endl;
    cout<<"can: "<<can<<endl;
    */

    {
      int a = 0;
      vi er;
      forr(xc, M2[mo][1]) {
        if (a++ == can) break;
        int x = xc.fst;
        int c = xc.snd;
        //cout<<"!!x: "<<x<<endl;
        if (c > 1) M2[mo][0][x] = c - 1;
        er.push_back(x);
      }
      forr(e, er) {
        M2[mo][1].erase(e);
      }
    }

    {
      int a = 0;
      while (a++ < can) {
        if (sz(M2[ta][1])) {
          auto xc = M2[ta][1].begin();
          int x = xc->fst;
          int c = xc->snd;
          if (c > 1) M2[ta][0][x] = c - 1;
          M2[ta][1].erase(x);
        }
        else {
          auto xc = M2[ta][0].begin();
          int x = xc->fst;
          //cout<<"?! x: "<<x<<endl;
          int c = xc->snd;
          if (c > 1) M2[ta][1][x] = c - 1;
          M2[ta][0].erase(x);
        }
      }
    }
  }

  //cout<<"ans: "<<ans<<endl;

  rep(mo, m) {
    rep(o, 2) {
      forr(xc, M2[mo][o]) {
        int x = xc.fst;
        int c = xc.snd;
        //cout<<"x: "<<x<<endl;
        //cout<<"c: "<<c<<endl;
        ans += c / 2;
      }
    }
  }
  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 23296
s=input()
n=len(s)
a=list(s[i] for i in range((n-1)//2))
b=list(s[i-1] for i in range((n+3)//2,n+1))
c=0
for i in range((n-1)//2):
    if a[i]==a[-i-1]==b[i]==b[-i-1]:
        c=c+1
print("Yes" if c==(n-1)//2 else "No")
   

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
    string k;
    cin>>k;
    for(int i=0;i<k.size();i++)
        if(k[i]=='7') {
            cout<<"Yes\n";
            return 0;
        }
    cout<<"No\n";
    return 0;
}

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

#define ll long long
#define ld long double
#define F first
#define S second

//#define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9+7;

void solve(){
	int k,n;
	cin >> k >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans = mod;
	for(int i = 0; i + 1 < n; i++){
		int r = a[i+1] - a[i];
		ans = min(ans,k - r);
	}		
	int r = (k - a[n-1] + a[0]);
	ans = min(ans,k-r);
	cout << ans << "\n";

}

int main(){
	//#ifndef ONLINE_JUDGE	
	//	freopen("in.txt","r",stdin);
	//	freopen("out.txt","w",stdout);
	//#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);		
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 1024
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()
if x[-1]>=y[0]:
  print("War")
else:
  print("No War")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long Long
using namespace std;

int main()
{
   int n,k;
   while(scanf("%d%d",&n,&k)!=EOF)
   {
       char a[n+5];
       cin>>a;
       a[k-1]=a[k-1]+32;
       cout<<a<<endl;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxn 5005
const int inf=1e9+7;
using namespace std;
inline int read(){
	int u=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){u=u*10+c-'0';c=getchar();}
	return u*f;
}

int L[maxn],R[maxn],a[maxn],b[maxn],q[maxn],G[maxn],ans=inf,n;
char c[maxn];
bool cmp(int x,int y){
	return R[x]<R[y];
}

int main(){
	scanf("%s",c+1);n=strlen(c+1);
	for(int i=1;i<=n;i++)a[i]=c[i]-'0',L[i]=R[i]=inf;
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)b[i]=c[i]-'0';
	int sa=0,sb=0;
	for(int i=1;i<=n;i++)sa|=a[i],sb|=b[i];
	if(!sb){
		if(!sa)puts("0");
		else puts("-1");
		return 0;
	}//for(int i=1;i<=n;i++)cout<<L[i]<<" "<<R[i]<<endl;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(b[j])L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
		}
	
	for(int i=1;i<=n;i++){
		int k=i,r=0,j;
		for(j=1;j<=n;j++){
			if(a[k]!=b[j])q[++r]=k;
			k%=n;k++;
		}
		sort(q+1,q+r+1,cmp);
	//	cout<<r<<endl;
		G[r+1]=0;
		for(k=r;k;k--)G[k]=max(G[k+1],L[q[k]]);//cout<<G[k]<<endl;
		for(k=0;k<=r;k++){
			//cout<<j<<endl;
		//	cout<<ans<<endl;
			ans=min(ans,(R[q[k]]+max((i-j+n)%n,G[k+1]))*2-(i-j+n)%n+r);
			ans=min(ans,(G[k+1]+max((j-i+n)%n,R[q[k]]))*2-(j-i+n)%n+r);
		}
	}	
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NMAX 2200
#define ll long long int

using namespace std;

struct coada{
    int x, y;
};
coada C[NMAX*NMAX];
ll ct, st, stlevel, ctlevel;
ll level[NMAX*NMAX];

ll uz[NMAX][NMAX];
ll coordx, coordy;
ll n, m, i, j, nrsel, levelaux, t;
char aux, caracter;

int dl[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

int main(){
    cin >> n >> m;
    cin.get(aux);
    for(i=1; i<=n; ++i){
        for(j=1; j<=m; ++j){
            scanf("%c", &caracter);
            if(caracter == '#'){
                coordx = i;
                coordy = j;
                C[ct].x = i;
                C[ct++].y = j;
                level[ctlevel++] = 1;
                uz[i][j] = 1;
                nrsel++;
                }
            }
        scanf("%c", &caracter);
        }
    if(nrsel == n*m){
        cout << "0\n";
        return 0;
        }
    st = 0; stlevel = 0;
    while(nrsel < n*m){
        coordx = C[st].x;
        coordy = C[st].y;
        for(t=0; t<=3; ++t){
            coordx += dl[t];
            coordy += dc[t];
            if(coordx >= 1 && coordx <= n && coordy >=1 && coordy <= m){
                if(uz[coordx][coordy] == 0){
                    uz[coordx][coordy] = 1;
                    nrsel++;
                    C[ct].x = coordx;
                    C[ct++].y = coordy;
                    levelaux = level[stlevel];
                    level[ctlevel++] = levelaux + 1;
                    }
                }
            coordx -= dl[t];
            coordy -= dc[t];
            }
        if(nrsel == n*m){
            cout << level[stlevel] << '\n';
            break;
            }
        ++st;
        ++stlevel;
        }
    return 0;
}


Measured memory_bytes: 38528
#include <stdio.h>
int bubblesort(int *,int);
void swap(int *,int *);
int main(){

  int A[101],i,j,n,count;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  count=bubblesort(A,n);
  
  for(j=0;j<n;j++){
    if(j==n-1)printf("%d\n",A[j]);
    else printf("%d ",A[j]);
  }
  printf("%d\n",count);

  return 0;
}
int bubblesort(int a[],int n){
  int i,j,flag,count=0;
  flag=1;
  while(flag){
    flag=0;
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	swap(&a[j],&a[j-1]);
	flag=1;
	count++;
	/*	for(i=0;i<n;i++)
	  printf("%d",a[i]);
	  printf("\n");*/
      }
      
    }
    
  }
  return count;
}

void swap(int *p,int *q)
{
  int tmp;

  tmp=*p;
  *p=*q;
  *q=tmp;
  
}



Measured memory_bytes: 2128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,x,y,ans;
int main(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++){
		scanf("%d",&y);
		if(i==1){
			ans=abs(x-y);
		}else{
			ans=__gcd(ans,abs(x-y));
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
long long ct[28];
int main(){
  string s;
  cin >> s;
  long long n = s.size();
  for(auto a : s){
    ct[a - 'a']++;
  }
  long long ans = 1 + n*(n - 1)/2;
  for(int i = 0;i < 28;i++){
    if(ct[i] >= 2){
      ans -= ct[i] * (ct[i] - 1) /2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
/**/
/*
 * 	Meet me on the battlefield
*/
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const int inf=1e9;
const int mod=1e9+7;
#define dpr(x) cout<<#x<<": "<<x<<endl
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int k,a,b;
void solve()
{
	cin>>k>>a>>b;
	if(b-a<=2||k<=a) {
		cout<<k+1<<endl;
	}
	else
	{
		int bis=a;
		k-=a-1;
		if(k&1)
			bis++;
		bis+=(k/2)*(b-a);
		cout<<bis<<endl;
	}
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
/**/


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

int main()
{
  int n;
  cin >> n;
  vector<string> s;
  string tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    s.push_back(tmp);
  }

  auto b = s[0].back();
  for (int i = 1; i < n; i++) {
    if (b == s[i].front()) {
      b = s[i].back();
      continue;
    }
    cout << "No" << endl;
    return 0;
  }

  int len = s.size();
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  if (len != s.size()) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
s= input()

now = s[0]
ans = 0
flg = 0
for i in range(1,len(s)):
    if flg == 0:
        if now == s[i]:
            pass
        elif now != s[i]:
            ans += 1
            flg = 1
            now = s[i]

    else:
        if now == s[i]:
            pass
        elif now != s[i]:
            ans += 1
            flg = 0
            now = s[i]
            
print(ans)

Measured memory_bytes: 3188
N = gets.to_i

Deliciousity = [*0...N].map{ gets.split.map &:to_i }

Deliciousity_sorted_by_sum = Deliciousity.sort_by{|d| -d.inject(0, :+)}

takahashi_point = 0
aoki_point = 0

for i in 1..N do
	if i.odd? then
		takahashi_point += Deliciousity_sorted_by_sum[i - 1][0]
	else
		aoki_point += Deliciousity_sorted_by_sum[i - 1][1]
	end
end

p takahashi_point - aoki_point


Measured memory_bytes: 15120
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n,k;
    cin >> n >> k;
    ll min=(k*(k-1))/2;
    ll max=(k*n)-min;

    ll ans=0;
    for (ll i=k;i<=n+1;i++)
    {
        ans=(ans+max-min+1)%mod;
        min=min+i;
        max=((i+1)*n)-min;
    }

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

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

class Dice {
public:
	Dice(int num[6]) {
		t = num[0];
		b = num[5];
		n = num[4];
		s = num[1];
		w = num[3];
		e = num[2];
	}
	void roll_e() {
		int temp = w;
		w = b;
		b = e;
		e = t;
		t = temp;
	}
	void roll_w() {
		for (int i = 0; i < 3; i++)roll_e();
	}
	void roll_n() {
		int temp = s;
		s = b;
		b = n;
		n = t;
		t = temp;
	}
	void roll_s() {
		for (int i = 0; i < 3; i++)roll_n();
	}
	void spin_left() {
		int temp = n;
		n = e;
		e = s;
		s = w;
		w = temp;
	}
	void setTop(int top) {
		for (int i = 0; i < 4; i++) {
			if (t == top)return;
			roll_e();
		}
		for (int i = 0; i < 3; i++) {
			roll_n();
			if (t == top)return;
		}
	}
	void setNum(int top, int front) {
		setTop(top);
		for (int i = 0; i < 4; i++) {
			if (s == front)return;
			spin_left();
		}
	}
	int t, b;
	int n, s, w, e;
};

int main() {
	int d[6];
	int n;
	int top[24];
	int front[24];

	for (int i = 0; i < 6; i++) {
		cin >> d[i];
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> top[i] >> front[i];
	}

	Dice dice(d);
	for (int i = 0; i < n; i++) {
		dice.setNum(top[i], front[i]);
		cout << dice.e << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
  
namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
          var str = Console.ReadLine();
          for(int a=str.Length-1;a!=-1;a--)
          Console.Write(str[a]);
          Console.WriteLine();
	  }
     }
}
          
          

Measured memory_bytes: 8692
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[334334];

int main(void){
	int n,i,j=1,ans=0;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=0; i<n; ++i){
		if(a[i]==j){
			++j;
		}else{
			++ans;
		}
	}
	cout << ((ans<n)?ans:(-1)) << endl;
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    sort(ALL(S));

    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) print("Yes");
    else print("No");
    
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
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; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head
int n;
double dp[310][310][310];

double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += n;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

// double rec(int a,int b, int c){
//   if (!(a >= 0 && b >= 0 && c >= 0)){ return 0.0;}
//   if (a == 0 && b == 0 && c == 0){  return 0.0;}
//   if (dp[a][b][c]  != -1) { return dp[a][b][c];}
//   double result = n;
//   result += rec(a-1,b,c) * a;
//   result += rec(a+1,b-1,c) * b;
//   result += rec(a,b+1,c-1) * c;
//   return dp[a][b][c] = result * (1.0/(a+b+c));
//   }


// int main() {
//     cin >> n;
//     int one = 0, two = 0, three = 0;
//     for (int i = 0; i < n; ++i) {
//         int a; cin >> a;
//         if (a == 1) ++one;
//         else if (a == 2) ++two;
//         else ++three;
//     }

//     // 初期化
//     memset(dp, -1, sizeof(dp));

//     // 答え
//     cout << fixed << setprecision(10) << rec(one, two, three) << endl;
// }
int main(){
  cin >> n;
  int A,B,C;
  A=B=C=0;
  for range(i,n){
    int a;
    cin >> a;
    if (a == 1){ A++ ;}
    else if (a == 2) { B ++ ;}
    else {C ++ ;}
  }
  memset(dp,-1,sizeof(dp));
  cout << fixed << setprecision(10) <<  rec(A,B,C) <<  endl ;
}

Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))
#define N 15

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);

int n, m, p[N], s[N][N], ans;

int main(){
    cin >> n >> m;
    for (int i=1; i<=m; i++){
        cin >> s[i][0];
        for (int j=1; j<=s[i][0]; j++) cin >> s[i][j];
    }
    for (int i=1; i<=m; i++) cin >> p[i];
    for (int st=0; st<(1<<n); st++){
        int bc = 0;
        for (int i=1; i<=m; i++){
            int cnt = 0;
            for (int j=1; j<=s[i][0]; j++)
                if ((1 << (s[i][j] - 1)) & st) cnt++;
            if (cnt % 2 == p[i]) bc++;
        }
        //cout << st << ' ' << bc << '\n';
        if (bc == m) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <utility>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  /*long long int cmin = A*X+B*Y;
  for (int i = 1; i < min(X,Y); i++) {
    cmin = min(cmin, A*(X-i)+B*(Y-i)+C*2*i);
  }
  cout << cmin << endl;*/
  long long int Ar[3];
  int n = min(X, Y); int x = max(X, Y);
  Ar[0] = A*X+B*Y;
  Ar[1] = A*(X-n)+B*(Y-n)+C*2*n;
  Ar[2] = C*2*x;
  cout << *min_element(Ar, Ar+3) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


int a[6];
signed main(){
  rep(i,5)cin >> a[i];
  int k;cin >> k;
  sort(a, a+5);
  if(a[4]-a[0] > k)cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}






Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double num1;
    cin>>num1;
    std::cout << std::fixed << std::showpoint;
    num1=3.14*2*num1;
    std::cout << std::setprecision(5);
    std::cout << num1 << std::endl;
    return 0;
}

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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

void Commit(int day, int contest, int& score, vector<int>& last) {
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

double lambda = 5.0; // 5.0 is better
int FindMaxProfitContest(int day, vector<int>& last) {
    double max_profit = -1e18;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;
        profit += s[day - 1][type];
        profit += lambda * c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int Greedy(int start_day, vector<int>& last) {
    int score = 0;
    vector<int> last_copy = last;
    for(int day = start_day; day <= D; day++) {
        int contest = FindMaxProfitContest(day, last_copy);
        Commit(day, contest, score, last_copy);
    }
    return score;
}

int FindMaxProfitContestWithPredict(int day, vector<int>& last) {
    double max_profit = -1e18;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;

        profit += s[day - 1][type];
        profit += lambda * c[type] * (day - last[type]);

        int tmp = last[type];
        last[type] = day;
        profit += Greedy(day + 1, last);
        last[type] = tmp;

        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int GetRand() {
    static mt19937 mt;
    return abs((int)mt());
}

int scoring() {
    vector<int> last(T, 0);
    int score = 0;
    REP(i, D) {
        score += s[i][ans[i]];
        last[ans[i]] = i + 1;
        REP(type, T) score -= c[type] * (i + 1 - last[type]);
    }
    return score;
}

void Climbing() {
    int Q = 140000;
    REP(climb, Q) {
        int day = GetRand() % D;
        int changed = GetRand() % T;
        int tmp = ans[day];
        int crt_score = scoring();
        ans[day] = changed;
        int cgd_score = scoring();
        if(cgd_score < crt_score) ans[day] = tmp;
    }
    return;
}

int main() {
    Input();
    int score = 0;
    vector<int> last(T, 0);
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContestWithPredict(day, last);
        ans.push_back(contest);
        Commit(day, contest, score, last);
    }
    Climbing();
    Output();
    // cerr << scoring() << endl;
    return 0;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n;
vector<int> e24(int c){
    int cnt=0;
    int i=0;
    vector<int> rtn(c);
    while(cnt<c){
        if(i%3){
            rtn[cnt]=i*2;
            cnt++;
        }
        i++;
    }
    return rtn;
}
vector<int> e6(int c){
    int cnt=0;
    int i=1;
    vector<int> rtn(c);
    while(cnt<c){
        rtn[cnt]=i*6;
        cnt++;
        i++;
    }
    return rtn;
}

vector<int> o3(int c){
    int cnt=0;
    int i=4;
    vector<int> rtn(c);
    while(cnt<c){
        if(i%2){
            rtn[cnt]=i*3;
            cnt++;
        }
        i++;
    }
    return rtn;
}
int main(){
    cin >> n;
    if(n>3){
        vector<int> res;
        
        res.push_back(3);
        res.push_back(9);
        n-=2;
        if(n<=10001){
            if(n%2!=0){
                res.push_back(6);
                n--;
            }
            vector<int> e = e24(n);
            REP(i,e.size()){
                res.push_back(e[i]);
            }
        }else if(n<=15000){
            vector<int> e=e24(10000);
            n-=10000;
            vector<int> e2=e6(n);
            REP(i,e.size()){
                res.push_back(e[i]);
            }
            REP(i,e2.size()){
                res.push_back(e2[i]);
            }
        }else{
            vector<int> e=e24(10000);
            REP(i,e.size()){
                res.push_back(e[i]);
            }
            n-=10000;
            if(n%2==0){
                vector<int> e2=e6(5000);
                REP(i,e2.size()){
                    res.push_back(e2[i]);
                }
                n-=5000;
            }else{
                vector<int> e2=e6(5000-1);
                REP(i,e2.size()){
                    res.push_back(e2[i]);
                }
                n-=5000-1;
            }
            vector<int> o=o3(n);
            REP(i,o.size()){
                res.push_back(o[i]);
            }
            
        }
        REP(i,res.size()){
            cout << res[i] << " ";
        }
        put("");
    }else{
        put("2 5 63");
    }
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;


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


    int n, k;
    cin >> n >> k;
	vector<int> p(n);
	for(int i = 0; i < n; ++i){
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	int sum = accumulate(p.begin(), p.begin() + k, 0);
    cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3556
fn main() {
    let _:usize = readln();
    let a:Vec<i32> = readln();
    let from = a.iter().min().unwrap();
    let to = a.iter().max().unwrap();
    println!("{}", to - from);
}

// --- template ---
pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int A,B,C,X,Y;

int main() {
    cin>>A>>B>>C>>X>>Y;
    if(A+B<=2*C) {
        cout<<X*A+Y*B;
        return 0;
    } else {
        int m = min(X,Y);
        int res = C*2*m;
        X-=m,Y-=m;
        if(X>0) {
            if(C*2 <= A) {
                res+=X*C*2;
            } else {
                res+=X*A;
            }
        } else if(Y>0) {
            if(C*2 <= B) {
                res+=Y*C*2;
            } else {
                res+=Y*B;
            }
        }
        cout<<res;
    }
}

Measured memory_bytes: 256
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(400<=x && x<=599) cout << "8" << endl;
    if(600<=x && x<=799) cout << "7" << endl;
    if(800<=x && x<=999) cout << "6" << endl;
    if(1000<=x && x<=1199) cout << "5" << endl;
    if(1200<=x && x<=1399) cout << "4" << endl;
    if(1400<=x && x<=1599) cout << "3" << endl;
    if(1600<=x && x<=1799) cout << "2" << endl;
    if(1800<=x && x<=1999) cout << "1" << endl;
    

}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<list>
#include<algorithm>
using namespace std;
 
int main() {
    list<int> L;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char s[15];
        int  x;
        scanf("%s", s);
        if (s[0] == 'i') {
            scanf("%d", &x);
            L.push_front(x);
        }
        else {
            if (s[6] == 'F') L.pop_front();
            else if (s[6] == 'L') L.pop_back();
            else if (s[0] == 'd') {
                scanf("%d", &x);
                for (list<int> ::iterator it = L.begin(); it != L.end(); it++) {
                    if (*it == x) {
                        L.erase(it);
                        break;
                    }
                }
            }
        }
    }
    int i = 0;
    for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        if (i++) printf(" ");
        printf("%d", *it);
    }
    puts("");
}

Measured memory_bytes: 34048
n,k=map(int,input().split())
kli=[i+1 for i in range(k)]
L=[]
for i in range(k):
    x=int(input())
    li=list(map(int,input().split()))
    for j in li:
        L.append(j)
L=set(L)
print(n-len(L))

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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 5005;
int dp[N][N], n, ans;
char s[N];

int solve(int l, int r, int lim)
{
	if (l > lim) return 0;
	if (r > n) return 0;
	if (dp[l][r] != -1) return dp[l][r];
	if (s[l] != s[r]) return dp[l][r] = 0;
	return dp[l][r] = 1 + solve(l + 1, r + 1, lim);
}

int main()
{
	n = read();
	memset(dp, -1, sizeof(dp));
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			ans = max(ans, solve(i, j, j - 1));
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 98048
#include <bits/stdc++.h>
using namespace std;
const int Mo=1000000007;
map <long long,int> f;
inline int solve(long long n) {
    if(f.count(n)) return f[n];
    return f[n]=((solve(n/2)+solve((n-1)/2))%Mo+solve((n-2)/2))%Mo;
}
int main() {
    f[0]=1,f[1]=2;
    long long n;
    cin>>n;
    cout<<solve(n);
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin>>a>>b>>c;
    cout << max(0, c-(a-b)) << "\n";
    return 0;
}


Measured memory_bytes: 256