akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+(pll a, pll b) { return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e18;

ll n, m;

ll matrix[22][1ll << 22];
ll dp[22][1ll << 22];
vector<ll> masks[22];

void solve() {
    masks[0].push_back(0);
    cin >> n;
    fori(i, (1ll << n)){
        ll c = 0;
        fori(j, n) if(i & 1ll << j) ++c;
        masks[c].push_back(i);
    }
    forI(i, n) forI(j, n) cin >> matrix[i][j];
    dp[0][0] = 1;
    forI(i, n){
        forI(j, n){
            if(!matrix[i][j]) continue;
            for(ll mask: masks[i]){
                if(mask & 1ll << (j - 1)){
                    dp[i][mask] = (dp[i][mask] + dp[i - 1][mask & (~(1ll << (j - 1)))]) % mod;
                }
            }
        }
    }
    ll w = 0;
    fori(i, 1 << (n + 1)){
        w += dp[n][i];
        w %= mod;
    }
    cout << w;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //stress();
    solve();
}

Measured memory_bytes: 391200
n = int(input())
s = input()
r,g,b =0,0,0
ls = len(s)
for i in range(ls):
    if s[i]=='R':
        r+=1
    elif s[i]=='G':
        g+=1
    elif s[i]=='B':
        b+=1
cnt =0
for j in range(1,ls-1):
    for i in range(j):
        k = 2*j-i
        if k<ls:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                cnt+=1
print(r*g*b-cnt)


Measured memory_bytes: 9116
fn main() {
    let s = read_string();
    let mut sc = Scanner::new(&s);

    let x: usize = sc.next();

    let mut a = vec![false; x+1];

    a[1] = true;

    for b in 2..x+1 {
        let mut v = b*b;
        while v<=x {
            a[v] = true;
            v = v*b;
        }
    }

    for i in (1..x+1).rev() {
        if a[i] {
            println!("{}", i);
            break;
        }
    }
}

// 以下、たなこふ先生からぱくったやつ (´･_･`)

struct Scanner<'a> {
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Scanner<'a> {
    fn new(s: &str) -> Scanner {
        Scanner {
            iter: s.split_whitespace(),
        }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        let s = self.iter.next().unwrap();
        s.parse().unwrap()
    }
}

fn read_string() -> String {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    buf
}


Measured memory_bytes: 4352
def alphabeta(a, X, Z, W, alpha, beta):
    if len(a) == 0:
        return abs(Z-W)
    if X:
        for i in reversed(range(len(a))):
            Z = a[i]
            alpha = max(alpha, alphabeta(a[i+1:len(a)], not X, Z, W, alpha, beta))
            if alpha >= beta:
                return beta
        return alpha
    else:
        for i in reversed(range(len(a))):
            W = a[i]
            beta = min(beta, alphabeta(a[i+1:len(a)], not X, Z, W, alpha, beta))
            if alpha >= beta:
                return alpha
        return beta

N, Z, W = tuple(map(int, input().split()))
a = list(map(int, input().split()))
print(alphabeta(a, True, Z, W, 0, 2e9))

Measured memory_bytes: 3188
#include<stdio.h>

int H, A[500000 + 1];

void maxHeapify(int i){
  int l, r, largest, temp;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i])         largest = l;
  else                              largest = i;

  if(r <= H && A[r] > A[largest])   largest = r;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  int i;

  for(i = H / 2; i >= 1; i--){
    maxHeapify(i);
  }
}

int main(){
  int i;
  
  scanf("%d", &H);
  for(i = 1; i <= H; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap();

  for(i = 1; i <= H; i++)
    printf(" %d", A[i]);
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 2552
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  Vi v(5);
  VIN(v);
  IN(n);
  SORT(v);
  Yay(v[4]-v[0] <= n);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MN 100005
long long n,k,a[MN],b[MN],c[MN],K,ans=0,tc=0;
inline long long min(long long a,long long b){return a<b?a:b;}
inline long long max(long long a,long long b){return a>b?a:b;}
int main(){
//	freopen("b.in","r",stdin);
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		b[i]=b[i-1]; b[i]+=a[i];
		c[i]=c[i-1];
		if(a[i]>0){
			c[i]+=a[i];
			tc+=a[i];
		}
	}
	for(int i=k;i<=n;i++){
		ans=max(ans,tc-(c[i]-c[i-k]));// printf("%lld\n",ans);
		ans=max(ans,tc-(c[i]-c[i-k])+(b[i]-b[i-k]));// printf("%lld\n",ans);
	}
	printf("%lld",ans);
}

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

int main()
{
    int n, maxW;
    cin >> n >> maxW;
    vector<long long> weight(n);
    vector<long long> value(n);
    rep(i, n)
    {
        cin >> weight.at(i) >> value.at(i);
    }

    // i番目(0<=i<=n)までの品物の中から重さがwを超えないように選んだ時の、
    // 価値の最大値をdp[i+1][w]とする
    // ただし0番目は0
    vector<vector<long long>> dp(n + 1, vector<long long>(maxW + 1));
    rep(w, maxW + 1)
    {
        dp.at(0).at(w) = 0;
    }

    rep(i, n)
    {
        rep(w, maxW + 1)
        {
            if (w >= weight.at(i))
            {
                // weight.at(i)を足す前の最大値にvalue.at(i)を足した値と足さない状態の最大値と比較
                dp.at(i + 1).at(w) = max(dp.at(i).at(w - weight.at(i)) + value.at(i), dp.at(i).at(w));
            }
            else if (w < weight.at(i))
            {
                dp.at(i + 1).at(w) = dp.at(i).at(w);
            }
        }
    }
    cout << dp.at(n).at(maxW);
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


int main() {
	int n = ri();
	int k = ri();
	int r0 = n / 2;
	int r1 = n - r0;
	std::vector<std::pair<int, int> > a;
	if (n & 1) {
		for (int i = 0; i < r0; i++) a.push_back({k + i, k + i + r0 + r1 + r1});
		for (int i = r0; i < n; i++) a.push_back({k + i, k + i + r1});
	} else {
		for (int i = 1; i < r0; i++) a.push_back({k + i, k + i + r0 + r1 + r1 - 1});
		for (int i = r0; i < n; i++) a.push_back({k + i, k + i + r1});
		a.push_back({k, k + n + n - 1});
	}
	std::sort(a.begin(), a.end(), [] (auto i, auto j) { return i.first + i.second < j.first + j.second; });
	struct T {
		int a, b, c;
	};
	T res[n];
	for (int i = 0; i < n; i++) {
		if (i + k + n + n < a[i].first + a[i].second) {
			std::cout << -1 << std::endl;
			return 0;
		}
		res[i] = {a[i].first, a[i].second, i + k + n + n};
	}
	for (int i = 0; i < n; i++) std::cout << res[i].a << " " << res[i].b << " " << res[i].c << std::endl;
	return 0;
}


Measured memory_bytes: 4340
H, W = map(int, input().split())
masu = []
# masu.append(['.' * (W+2)])
# for i in range(H):
#     masu.append(['.' + input() + '.'])
# masu.append(['.' * (W+2)])

masu.append(['.' for i in range(W+2)])
for i in range(H):
    inputline = list(input())
    inputline.insert(0, '.')
    inputline.append('.')
    masu.append(inputline)
masu.append(['.' for i in range(W+2)])

bomap = masu
scan = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if masu[i][j] == '#':
            continue
        else:
            for x in range(i-1, i+2):
                for y in range(j-1, j+2):
                    if masu[x][y] == '#':
                        scan += 1
            bomap[i][j] = str(scan)
            scan = 0

bomap.pop(0)
bomap.pop(-1)
for line in bomap:
    line.pop(0)
    line.pop(-1)
    for chara in line:
        print(chara, end='')
    print()


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

int main()
{
  int n,m;
  int a[101][101],b[101],c[101]={0};
  cin >> n >> m;

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      c[i] +=a[i][j]*b[j];
    }
  }
  for(int i=0;i<n;i++){
    cout << c[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1196
import math
N = int(input())
T = []

def lcm(x, y):
    gc = math.gcd(x, y)
    ans = (x * y)//gc
    return ans

for i in range(N):
    T.append(int(input()))

    

if len(T) > 2:
    g = lcm(T[0],T[1])
    for i in range(3,N-1):
        g = lcm(g,T[i+1])
    print(g)
elif len(T) == 2:
    g = lcm(T[0],T[1])
    print(g)
else:
    print(T[0])

Measured memory_bytes: 9144
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i ++)
#define int long long
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

signed main() {
        int n;
        cin >> n;
        vector<int> a(n);
        int sum = 0;
        rep(i, n) { 
                cin >> a[i];
                sum += a[i];
        }
        int sum2 = 0;
        int ans = INFL;
        rep(i, n - 1) {
                sum2 += a[i];
                int other = sum - sum2;
                ans = min(ans, abs(sum2 - other));
        }
        cout << ans << endl;
        return 0;
}



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

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

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
    string s; cin>>s;
    int len=s.size();
    if(s[len-1]=='s') cout<<s<<"es"<<endl;
    else cout<<s<<'s'<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
#include <queue>
using namespace std;

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

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

    int maxcount = 0;
    int currentcount = 0;
    for(int i = 0; i < N - 1; ++i)
    {
        if(hs[i] >= hs[i + 1])
        {
            ++currentcount;
        }
        else
        {
            currentcount = 0;
        }
        if(currentcount > maxcount)
        {
            maxcount = currentcount;
        }
    }

    cout << maxcount;
}


Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)


string S;
ll N,K;

int main() {
    cin >> N >> K;
    cin >> S;
    if (S[K-1] == 'A') S[K-1] = 'a';
    if (S[K-1] == 'B') S[K-1] = 'b';
    if (S[K-1] == 'C') S[K-1] = 'c';
    cout << S << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
string key="keyence";
int main(){cout<<fixed<<setprecision(10);
		  string s;
           cin>>s;
           if(s==key){
            cout<<"YES"<<endl;
             return 0;
           }
          bool ans=false;
           int n=s.size();
           rep(i,0,n){//start
             rep(j,i,n){//end
               string h;
               reverse(all(s));
               h=s.substr(n-1-i);
               reverse(all(h));
               reverse(all(s));
               h+=s.substr(j);
               if(h==key)ans=true;
             }
           }
           YES(ans);
}



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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])



int main() {
    int N;
    string S;
    cin >> N >> S;
    long long R = 0;
    long long G = 0;
    long long B = 0;
    for(int j = 0; j < N; j++){
        if(S[j] == 'R'){
            R++;
        } else if (S[j] == 'G'){
            G++;
        } else {
            B++;
        }
    }
    long long count = 0;
    for(int j = 1; j < N-1; j++){
        int len = std::min(N-1-j, j);
        for(int p = 1; p <= len; p++){
            if(S[j-p] != S[j+p] && S[j] != S[j-p] && S[j] != S[j+p]){
                count++;
            }
        }
    }
    cout << R*G*B - count;
}

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

using namespace std;

int main()
{
	int N;
	int Y;

	cin >> N >> Y;
	
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N-i; j++){
			for(int k = 0; k <= N-i-j; k++){
				if(Y == 10000*i+5000*j+1000*k && N == i+j+k){
					cout << i << " " << j << " " << k << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    H,W,A,B = LMIIS()
    l1 = '0'*A + '1'*(W-A)
    l2 = '1'*A + '0'*(W-A)
    for i in range(B):
        print(l1)
    for i in range(H-B):
        print(l2)
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 65388
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

string s;
int n,k;

bool vIs0(int i){
  if((s[0]=='0' && i%2==0) || (s[0]=='1' && i%2==1))return true;
  else return false;
}

int main(){
  cin >> n >> k;
  cin >> s;
  vector<ll> v;
  bool Is0=true;
  ll length=0;
  if(s[0]=='1')Is0=false;
  rep(i,n){
    if(s[i]=='0' && Is0){
      length++;
    }
    else if(s[i]=='0' && !Is0){
      v.push_back(length);
      length=1;
      Is0=true;
    }
    else if(s[i]=='1' && Is0){
      v.push_back(length);
      length=1;
      Is0=false;
    }
    else if(s[i]=='1' && !Is0){
      length++;
    }
    if(i==n-1)v.push_back(length);
  }
  ll ans=0;
  ll sum[(int)v.size()]={};
  sum[0]=v[0];
  rep(i,v.size()-1){
    sum[i+1]=sum[i]+v[i+1];
  }
  for(int i=0;i<v.size();i++){
    ll subsum=0;
    int range=0;
    int m=(int)v.size()-1;
    if(i==0 && vIs0(i)){
      range=min(2*k-1,m);
      subsum=sum[range];
    }
    else if(i==0 && !vIs0(i)){
      range=min(2*k,m);
      subsum=sum[range];
    }
    else if(!vIs0(i)){
      int right=min(m,i+2*k);
      int left=i-1;
      subsum=sum[right]-sum[left];
    }
    ans=max(ans,subsum);
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 2164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		int a = 0;
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		sc.close();
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				a += d[i] * d[j];
			}
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 23892
package main

import (
	"fmt"
)

func main() {
	var a,b,c, k int
	fmt.Scan(&a,&b,&c,&k)


	for i := 0 ; i < k; i++ {
		if a >= b {
			b = b * 2
			continue
		}
		if b >= c {
			c = c *2
			continue
		}

	}
	if a < b && b < c{
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
	return

}


Measured memory_bytes: 1768
from collections import deque

def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]*n
	d = deque()
	h = len(b) // 2
	for i in range(1, n+1):
		if n % 2 == i % 2:
			d.appendleft(str(a[i-1]))
		else:
			d.append(str(a[i-1]))
	print(" ".join(d))
resolve()

Measured memory_bytes: 116948
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readline(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n, _ := strconv.Atoi(readline(scanner))
	str := strings.Split(readline(scanner), " ")
	hs := make([]int, n)
	for i, s := range str {
		hs[i], _ = strconv.Atoi(s)
	}
	count := 0
	for i := 0; i < n; i++ {
		visible := true
		for j := 0; j < i; j++ {
			if hs[j] > hs[i] {
				visible = false
				break
			}
		}
		if visible {
			count++
		}
	}
	fmt.Print(count)
}


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

int main() {
	// your code goes here
	long long int n = 0, m = 0, a = 0, b = 0, c = 0;
	cin >> n;
	vector<long long> s(n), t(n);
	for(int i = 0; i < n; i++){
		cin >> s.at(i);
		t.at(i) = s.at(i);
	}
	sort(t.begin(), t.end());
	for(int i = 0; i < n; i++){
		if(t.at(i) != s.at(i)){
			a++;
		}
	}
	//cout << a << endl;
	if(a == 0 || a == 2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
k, tmp = 0, K
while tmp > 0:
    tmp //= 2
    k += 1
tight = 0
untight = 0
for j in range(k)[::-1]:
    cnt0, cnt1 = 0, 0
    for a in A:
        if (a >> j) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    b = 2**j
    tmp = b * max(cnt0, cnt1)
    if (K >> j) & 1:
        if j == k-1:
            untight = b * cnt1
        else:
            untight = max(tight + b * cnt1, untight + tmp)
        tight += tmp
    else:
        tight += b * cnt1
        untight += tmp
ans = max(tight, untight)
for a in A:
    ans += (a >> k) << k
print(ans)

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


int main(){
  int H, A;
  cin >> H >> A;
  if (H%A == 0) cout << H/A << endl;
  else cout << H/A+1 << endl;
  return 0;
}


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

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }
  sort(v.begin(), v.end());

  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = (ans + v[i]) / 2.0;
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int N;
const int MAX_N = 5000;

int tree[MAX_N];

void bit_add(int pos, int val) {
    do  {
        tree[pos] += val;
        pos += (pos)&(-pos);
    } while (pos <= N);
}

int bit_read(int pos)  {
    int sum = 0;

    while (pos > 0) {
        sum += tree[pos]; pos = pos&(pos-1);
    }

    return sum;
}

int main()
{

    int n, k, q;
    cin >> n >> k >> q;

    N = n;

    vector<int> A(n + 1);

    for (int i=1; i<=n; i++) {
        cin >> A[i];
    }

    int good_left[n+1];
    int good_right[n+1];

    long long best = 1000000000000000000LL;

    for (int z=1; z<=n; z++) {
        long long y = A[z];
        memset(tree, 0, sizeof(tree));

        memset(good_left, 0, sizeof(good_left));
        memset(good_right, 0, sizeof(good_right));

        good_left[1] = 0;
        good_right[n] = 0;

        for (int i=2; i<=n; i++) {
            good_left[i] = (A[i-1] >= y ? good_left[i-1] + 1 : 0);
        }

        for (int i=n-1; i>=1; i--) {
            good_right[i] = (A[i+1] >= y ? good_right[i+1] + 1 : 0);
        }

        set<pair<int, int> > s;
        for (int i=1; i<=n; i++) {
            if (A[i] >= y) {
                s.insert({ A[i], i });
            }
        }

        int actual_ops = 0;
        long long x = y;

        for (int op=0; op<q && !s.empty(); op++) {

            auto current = s.begin();
            auto current_val = *current;

            s.erase(current);

            int val = current_val.first, index = current_val.second;

            int ok_left = good_left[index], ok_right = good_right[index];
            ok_left -= (bit_read(index) - bit_read(index - ok_left - 1));
            ok_right -= (bit_read(index+ok_right) - bit_read(index-1));

            if (ok_left + ok_right + 1 >= k) {
                //we can take this one
                x = val;
                bit_add(index, 1);

                actual_ops++;
                continue;
            }


            op--; //retry it
        }

        if (actual_ops == q)
            best = min(best, (x-y));
    }

    cout << best << endl;
    return 0;
}


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

int main () {
  int n, l;
  string s[100];
  cin >> n >> l;
  for (int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  string ans;
  for (int i = 0; i < n; i++) {
    ans += s[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;

    if (N%2 == 0) {
        print(0.5);
    } else {
        double ans = (((double)(N-1)/2) + 1) / N;
        cout << fixed << setprecision(10) << ans << endl;
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
n=int(input())
cntAC=0
cntWA=0
cntTLE=0
cntRE=0
for i in range(n):
    s=input()
    if s=="AC":
        cntAC+=1
    elif s=="WA":
        cntWA+=1
    elif s=="TLE":
        cntTLE+=1
    else:
        cntRE+=1
print("AC x %d" % cntAC)
print("WA x %d" % cntWA)
print("TLE x %d" % cntTLE)
print("RE x %d" % cntRE)

Measured memory_bytes: 9192
n, k, q = map(int, input().split())
a = []
for i in range(q):
  a.append(int(input()) - 1)
  
m = [0]*n
for i in a:
  m[i] += 1
for i in range(n):
  if m[i] - q + k > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 8592
N,M = map(int,input().split())
Fav = [list(map(int,input().split()))[1:] for i in range(N)]
Sum = 0
for i in range(M):
    Flag = True
    for j in range(N):
        if not i+1 in Fav[j]:
            Flag = False
    if Flag:
        Sum += 1
print(Sum)

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    vi a(5);
    rep(i,5){
        cin>>a[i];
        if(a[i]==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string a;
  cin >>a;
  
  cout << (a[2]==a[3] && a[4]==a[5]? "Yes":"No") << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 18;
const int L = 65600;
const int mo = 1e9+7;

int n,m;
int a[N];
int f[N][L];
LL js[L],inv[L];
int cnt[L];

LL dec(LL x,LL y){return x<y?x-y+mo:x-y;}
LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();m=get();
	fo(i,1,m)a[i]=get();
	js[0]=inv[0]=inv[1]=1;
	fo(i,1,1<<n)js[i]=js[i-1]*i%mo;
	fo(i,2,1<<n)inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	fo(i,2,1<<n)inv[i]=inv[i]*inv[i-1]%mo;
	f[m+1][0]=1;
	sort(a+1,a+1+m);
	fd(i,m,1){
		fo(j,0,(1<<n)-1)
		if (f[i+1][j]){
			fo(x,0,n-1)
			if (((1<<x)&j)==0&&(j+(1<<x)<=(1<<n)-a[i]+1)){
				f[i][j|(1<<x)]=add(f[i][j|(1<<x)],1ll*f[i+1][j]*(1<<x)%mo*js[(1<<n)-a[i]-j]%mo*inv[(1<<n)-a[i]-j-((1<<x)-1)]%mo);
			}
			f[i][j]=add(f[i][j],f[i+1][j]);
		}
	}
	fo(i,1,(1<<n)-1)cnt[i]=cnt[i-(i&-i)]+1;
	LL ans=0;
	fo(i,0,(1<<n)-1){
		LL v=f[1][i];
		v=v*js[(1<<n)-i-1]%mo;
		if (cnt[i]%2==0)ans=add(ans,v);else ans=dec(ans,v);
	}
	ans=ans*(1<<n)%mo;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    char s[2][3];
    rep(i,2) rep(j,3) cin >> s[i][j];
    rep(j,3){
        if(s[0][j]!=s[1][2-j]){
            puts("NO");
            return 0;
        } 
    }
    puts("YES");
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    string s; cin >> s;

    int west = 0;
    int east = count( ALL( s ), 'E' );
    int ans = INF;

    REP( i, N ){
        if( s[i] == 'E' ) east--;
        chmin( ans, east + west );
        if( s[i] == 'W' ) west++;
    }

    cout << ans << endl;
}


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

int mod = 1e9+7;

signed main(){
  
  int n;
  cin >> n;
  double ans = 0;
  while(n--){
    double x;
    string s;
    cin >> x >> s;

    if(s=="BTC")ans+=380000*x;
    else ans+=x;
  }
  cout << fixed << setprecision(8) << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=2000+10;
struct dong{
	int x,y;
	friend bool operator <(dong a,dong b){
		return a.x<b.x;
	}
} zlt;
priority_queue<dong> dl;
bool bz[maxn][maxn],pd[maxn];
int a[maxn],d[maxn];
int h[maxn],go[maxn*maxn],nxt[maxn*maxn];
int i,j,k,l,t,n,m,tot,now;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
void add(int x,int y){
	d[y]++;
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x){
	pd[x]=1;
	int i;
	fo(i,1,n)
		if (bz[x][i]&&!pd[i]){
			add(x,i);
			dfs(i);
		}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	fo(i,1,n-1)
		fo(j,i+1,n)
			if (gcd(a[i],a[j])>1) bz[i][j]=bz[j][i]=1;
	fo(i,1,n)
		if (!pd[i]) dfs(i);
	fo(i,1,n)
		if (!d[i]){
			zlt.x=a[i];
			zlt.y=i;
			dl.push(zlt);
		}
	fo(i,1,n){
		zlt=dl.top();
		dl.pop();
		now=zlt.y;
		printf("%d ",a[now]);
		t=h[now];
		while (t){
			d[go[t]]--;
			if (!d[go[t]]){
				zlt.x=a[go[t]];
				zlt.y=go[t];
				dl.push(zlt);
			}
			t=nxt[t];
		}
	}
}

Measured memory_bytes: 7168
S = input()
strs = list(S)

m = {}
l_s = len(strs)

for i in range(l_s+1):
    m[i] = {}
    for j in range(4):
        m[i][j] = 0

m[l_s][3] = 1

mod = 10**9+7
for i in range(l_s)[::-1]:
    s = strs[i]
    for j in range(4):
        m[i][j] = m[i+1][j]
    if s == 'A':
        m[i][0] += m[i+1][1]
    elif s == 'B':
        m[i][1] += m[i+1][2]
    elif s == 'C':
        m[i][2] += m[i+1][3]
    else:
        m[i][0] = m[i+1][0] * 3 + m[i+1][1]
        m[i][1] = m[i+1][1] * 3 + m[i+1][2]
        m[i][2] = m[i+1][2] * 3 + m[i+1][3]
        m[i][3] *= 3
    for j in range(4):
        m[i][j] = m[i][j] % mod
print(m[0][0] % mod)


Measured memory_bytes: 55708
a,m = map(int,input().split())
hl = [tuple(map(int,input().split())) for i in range(m)]
hl.sort()
l,r = -1,a+1
c = 0
for i in hl:
  l = i[0]
  r = min(r,i[1])
  if l >= r:
    c += 1
    r = i[1]
print(c+1)

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

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	
	int cost[100] = {};
	for (int i = 0; i < M; i++) {
		int A;
		cin >> A;
		cost[A] = 1;
	}
	
	int cost1 = 0, cost2 = 0;
	for (int i = 0; i < X; i++) {
		cost1 += cost[i];
	}
	for (int i = X + 1; i < N; i++) {
		cost2 += cost[i];
	}
	
	cout << min(cost1, cost2) << endl;
	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
X = int(input())

# A**5 - (A-1)**5 = X = 10**9(Xの最大) となるAが
# Aの最大値となる(それ以上Aが大きくなると、Xは上限値を超える)
# → 最大となるAは120

for A in range(-120, 120 + 1):
  for B in range(-120, 120):
    if A**5 - B**5 == X:
      print("{} {}".format(A, B))
      exit()

Measured memory_bytes: 63928
#include <iostream>
#include <string>
#include <vector>

void split( std::vector<std::string> &list, std::string string, std::string separator )
{
  auto separator_length = separator.length();
  if ( separator_length == 0 )
  {
    list.push_back( string );
  } else {
    auto offset = std::string::size_type( 0 );
    while( 1 )
    {
      auto pos = string.find( separator, offset );
      if( pos == std::string::npos )
      {
        list.push_back( string.substr( offset ) );
        break;
      }
      list.push_back( string.substr( offset, pos - offset ) );
      offset = pos + separator_length;
    }
  }
}

template<typename T>
T min( T a, T b )
{
  return ( a < b ) ? a : b;
}

template<typename T>
T max( T a, T b )
{
  return ( a > b ) ? a : b;
}

int main(void)
{
  int A, B, C;
  std::cin >> A >> B >> C;
  
  std::cout << max( C - ( A - B ), 0 ) << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

bool sort_by_second(pair<int, int>& a, pair<int, int>& b) {
    return a.second < b.second;
}

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

    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v[i] = make_pair(i, a);
    }

    sort(v.begin(), v.end(), sort_by_second);

    cout << v[0].first + 1;
    for (int i = 1; i < n; ++i)
        cout << ' ' << v[i].first + 1;
    cout << '\n';
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

vector<int> chk[300300]; int cnt[300300]; multiset<int> wow;
int N, M, K;

int main()
{
	scanf ("%d %d %d", &N, &M, &K);
	for (int i = 0; i < K; i++){
		int x, y; scanf ("%d %d", &x, &y); x--; y--;
		chk[x].push_back(y);
		cnt[y]++;
	}

	for (int i = 0; i < M; i++) wow.insert(cnt[i]);

	int a = 0;
	for (int i = 0; i < N; i++){
		for (auto& j : chk[i]){
			wow.erase(wow.find(cnt[j]));
			a = max(a, (int)chk[i].size() - 1 + cnt[j]);
		}
		if (!wow.empty()) a = max(a, (int)chk[i].size() + *(wow.end().operator--()));
		for (auto& j : chk[i]) wow.insert(cnt[j]);
	}

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


Measured memory_bytes: 34936
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let ch = read_as_string().bytes().collect::<Vec<u8>>()[0];
    let c: char = (ch+1) as char;
    println!("{}", c);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;


signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int k;
    cin >> n >> k;
    vec(p,n);
    input(p,n);
    Sort(p);
    int ans = 0;
    REP(i,k){
        ans += p[i];
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % 1000000007;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
ll mod = 1000000007;
int main() {
    ll n, m;
    cin >> n >> m;
    if(abs(n-m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    if(abs(n-m) == 1) {
        cout << fact(min(n,m))*fact(max(n,m))%mod << endl;
    }
    else {
        cout << fact(min(n,m))*2*fact(max(m,n))%mod << endl;
    }
    return 0;
}

Measured memory_bytes: 5136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){

   int a, b;
   cin >> a >> b;
   cout << (a-1)*(b-1) << endl;
   return 0;
}

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

two_num = 0
four_num = 0
another_num = 0

for i in a:
    if i % 4 == 0:
        four_num += 1
    elif i % 2 == 0:
        two_num += 1
    else:
        another_num += 1
if two_num >= 1:
    another_num += 1

if four_num + 1 >= another_num:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
using System;

namespace AtCoderBeginnerContest095
{
    class ABC095A
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = 700;
            foreach(char c in s)
            {
                if (c == 'o') n += 100;
            }
            Console.WriteLine(n);
        }
    }
}


Measured memory_bytes: 13140
import itertools
import math
from math import factorial

N,P = list(map(int, input().split()))
As = list(map(int, input().split()))

#奇数の袋、偶数の袋の個数を求める。
odd = 0
even = 0

for A in As:
    if(A % 2 == 0):
        even += 1
    else:
        odd += 1

#偶数の組み合わせを求める。
#偶数の組み合わせは0~N個のすべての組み合わせである。
even_combi = 0

for i in range(even+1):
    even_combi += math.factorial(even) // math.factorial(i) // math.factorial(even-i)

#print(even_combi)

#奇数の組み合わせを求める。
#奇数の組み合わせは、Pの値によって変わる。

#Pが0の時
odd_combi = 0

if(P == 0):
    for i in range(0,odd + 1,2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-i)

else:
    for i in range(1, odd + 1 , 2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-(i))

print(odd_combi*even_combi)

Measured memory_bytes: 9192
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let N = read!(usize);
    let A = read!(i64; N);

    let k = A.split(|&x| x == 0)
        .map(|a| a.iter().sum::<i64>() / 2)
        .sum::<i64>();
    println!("{}", k);
    return;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<int32_t mod>
struct ModInt{
	int32_t a;
	inline int32_t normalize(int64_t x){
		x%=mod;
		if(x<0)x+=mod;
		return x;
	}
	ModInt(const int64_t a=0):a(normalize(a)){}

	ModInt& operator+=(const ModInt &x){
		a+=x.a;
		if(a>=mod)a-=mod;
		return *this;
	}
	ModInt& operator-=(const ModInt &x){
		a-=x.a;
		if(a<0)a+=mod;
		return *this;
	}
	ModInt& operator*=(const ModInt &x){
		a=(int64_t)a*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt x){return ModInt(*this)+=x;}
	ModInt operator-(const ModInt x){return ModInt(*this)-=x;}
	ModInt operator*(const ModInt x){return ModInt(*this)*=x;}
	ModInt operator/(const ModInt x){return ModInt(*this)/=x;}
	bool operator==(const ModInt x){return a==x.a;}
	bool operator!=(const ModInt x){return a!=x.a;}

	ModInt operator-(){return ModInt(0)-ModInt(*this);}
	ModInt pow(int64_t ex)const{
		int64_t x=a;
		int64_t res=1;
		while(ex){
			if(ex&1)res=res*x%mod;
			x=x*x%mod;
			ex>>=1;
		}
		return ModInt(res);
	}
	ModInt inv()const{return pow(mod-2);}
};

template<int32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<int32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;

const int LIM=1000000;
mint fact[LIM];
mint inv[LIM];

mint C(int n,int k){
	if(n<0||k<0||n<k)return 0;
	return fact[n]*inv[k]*inv[n-k];
}

mint solve(int N,int M,int R){
	mint ans=0;
	for(int x=1;x<=R;x++){
		for(int k=0;x*k<=R;k++){
			mint tmp=C(N-M,k)*C(R-x*(M+k)+N,N);
			if(k&1)tmp*=-1;
			ans+=tmp;

			tmp=C(N-M,k)*C(R-x*(M+k)-M+N,N);
			if(k%2==0)tmp*=-1;
			ans+=tmp;
		}
	}
	ans*=C(N,M);
	ans=C(R+N,N)-ans;
	return ans;
}

signed main(){
	fact[0]=1;
	for(int i=1;i<LIM;i++)fact[i]=fact[i-1]*i;
	inv[LIM-1]=fact[LIM-1].inv();
	for(int i=LIM-2;i>=0;i--)inv[i]=inv[i+1]*(i+1);

	int N,M,L,R;
	cin>>N>>M>>L>>R;
	L--;

	cout<<(solve(N,M,R)-solve(N,M,L))<<endl;
	return 0;
}

Measured memory_bytes: 8064