akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;

const int maxn = 101000;

int n,m,x;
int lt,rt,dis[maxn];
string S,S1,S2;

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	x=10000;
	n=read();
	cin>>S;
	
	for(int i=0;i<n;i++){
		if(S[i]=='('){
			++lt;
		}
		if(S[i]==')'){
			++rt;
		}
		dis[i]=lt-rt;
		x=min(x,dis[i]);
	}
	
//	for(int i=0;i<n;i++) printf("%d ",dis[i]); printf("\n");
	
	if(x>=0){ 
		cout<<S;
		for(int i=0;i<dis[n-1];i++){
			printf("%c",')');
		}
		printf("\n");
	}
	if(x<0){
		for(int i=0;i<(-1*x);i++) printf("%c",'(');
		cout<<S;
		for(int i=0;i<dis[n-1]-x;i++) printf("%c",')');
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result = 0;
		for (int i = A; i <= B; i++) {
			int digit1 = i / 10000;
			int digit2 = i / 1000 % 10;
			int digit4 = i / 10 % 10;
			int digit5 = i % 10;
			if (digit1 == digit5 && digit2 == digit4) {
				result++;
			}
		}
		System.out.println(result);
	}
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll h, w; cin >> h >> w;

  if(h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }

  if(h * w % 2) {
    cout << h * w / 2 + 1 << endl;
  } else {
    cout << h * w / 2 << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, k, ans = 1, i;
    scanf("%d", &n);
    getchar();
    scanf("%d", &k);

    for(i = 0; i < n; i++){
        if(ans * 2 > ans + k){
            ans += k;
        }
        else{
            ans *= 2;
        }
    }

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


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0)
			cout<<s[i];
		continue;
	}
	return 0;

}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int Month[50],Day[50],i,j,k,S=0,Total=0,Mod=0;
	int days[12]={0,31,29,31,30,31,30,31,31,30,31,30};
	for(i=0;i<50;i++){
		scanf("%d %d",&Month[i],&Day[i]);
		if(Month[i]==0) break;
	}
	for(j=0;j<50;j++){
		if(Month[j]==0) break;
		for(k=0;k<Month[j];k++){
			S+=days[k];
		}
		Total=S+Day[j];
		Mod=Total%7;
		switch(Mod){
			case 0: printf("Wednesday\n"); break;
			case 1: printf("Thursday\n"); break;
			case 2: printf("Friday\n"); break;
			case 3: printf("Saturday\n"); break;
			case 4: printf("Sunday\n"); break;
			case 5: printf("Monday\n"); break;
			case 6: printf("Tuesday\n"); break;
		}
		S=0;
	}
	return 0;
}

Measured memory_bytes: 584
import numpy as np
h,w,k=map(int,input().split())
trout=np.zeros((h,w))
cnt=0
for i in range(h):
  a=list(input())
  for j in range(w):
    if a[j]=="#":
      trout[i][j]=1
    else:
      trout[i][j]=0
for i in range(2**(h+w)):
  test=np.copy(trout)
  for j in range(h+w):
    if (i>>j)&1:
      if h+w-j>h:
        test[:,w-j-1]=0
      else:
        test[h+w-j-1,:]=0
  if test.sum()==k:
    cnt+=1
print(cnt)

Measured memory_bytes: 26412
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int H, W, h, w;
  cin>>H>>W>>h>>w;
  if (H % h || W % w) {
    cout<<"Yes\n";
    REP (i, H) {
      REP (j, W) {
        if (i % h == 0 && j % w == 0) {
          cout<<1000 * (h * w - 1) - 1<<" ";
        } else {
          cout<<-1000<<" ";
        }
      }
      cout<<"\n";
    }
  } else {
    cout<<"No\n";
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6
#define DEKA 1000000007

using namespace std;

long gcd(long a,long b){
    if (a<b) return gcd(b,a);
    else {
        if (b==1) return 1;
        else if (b==0) return a;
        else return gcd(b,a%b);
    }
}

long lcm(long a,long b){
    return a*b/gcd(a,b);
}


long kosuu(long x,long y){
    long a=1;
    long ans=0;
    long z=y;
    while(x>=z){
        if(a%2==1) ans+=x/z;
        else ans-=x/z;
        a++;
        z=pow(y,a);
    }
    return ans;
}

int main(){
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    long ans1=(a-1)/c+(a-1)/d-(a-1)/lcm(c,d);
    long ans2=(b)/c+(b)/d-(b)/lcm(c,d);
    cout << b-ans2-a+1+ans1 << endl;
}




Measured memory_bytes: 256
def binom(n,r):
    if n<r:
        return 0
    if n<0:
        return 0
    if n==r:
        return 1

    result=1
    for i in range(r):
        result*=(n-i)
        result//=(i+1)

    return result


n=int(input())
count=[0 for _ in range(n)]
minus=[0 for _ in range(n)]
an=[int(c) for c in input().split()]
for i in range(n):
    count[an[i]-1]+=1

sum_=0
for i in range(n):
    sum_+=binom(count[i],2)
    minus[i]=binom(count[i]-1,1)

for i in range(n):
    print(sum_-minus[an[i]-1])


Measured memory_bytes: 28852
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int n = int(s.size())+1;
    vi r(n, 0), l(n, 0);

    rep(i, n-1) {
        if(s[i]=='<') r[i+1] = r[i]+1;
        else r[i+1] = 0;
        if(s[n-2-i]=='<') l[n-2-i] = 0;
        else l[n-2-i] = l[n-1-i]+1;
    }

    int res = 0;
    rep(i, n) {
        res += max(r[i], l[i]);
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8708
import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

inf = float('inf')


def rec(v):
    if used[v]:
        return dp[v]
    used[v] = True
    res = 0
    for u in es[v]:
        res = max(res, rec(u) + 1)
    dp[v] = res
    return res


n, m = map(int, input().split())

es = tuple(set() for _ in range(n))
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    es[x].add(y)

used = [False] * n
dp = [inf] * n

ans = 0
for i in range(n):
    ans = max(ans, rec(i))
print(ans)


Measured memory_bytes: 177084
#include<stdio.h>
#include<math.h>

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

class Point{
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x+p.x,y+p.y); }
  Point operator - (Point p) { return Point(x-p.x,y-p.y); }
  Point operator * (double a) { return Point(a*x,a*y); }
  Point operator / (double a) { return Point(a/x,a/y); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x*x+y*y; }
  
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }

};

typedef Point Vector;

double dot(Vector a,Vector b){
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a,Vector b){
  return a.x * b.y - a.y * b.x;
}

int main(){
  
  double x0,y0,x1,y1,x,y,cr;
  Point p0,p1,p2;
  Vector a,b;
  int q;
  
  scanf("%lf %lf %lf %lf",&x0,&y0,&x1,&y1);
  p0 = Point(x0,y0);
  p1 = Point(x1,y1);

  scanf("%d",&q);
  for(int i=0;i<q;i++){
    
    scanf("%lf %lf",&x,&y);
    p2 = Point(x,y);
    
    a = p1-p0;
    b = p2-p0;
    
    cr = cross(a,b);
    
    if(cr > EPS) puts("COUNTER_CLOCKWISE" );
    else if(cr < -EPS) puts("CLOCKWISE");
    else if(dot(a,b) < -EPS) puts("ONLINE_BACK");
    else if(a.abs()<b.abs()) puts("ONLINE_FRONT");
    else puts("ON_SEGMENT");
    
  }
  
  return(0);
}



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

int main() {
  int n;
  vector<int> A;
  cin >> n;
  rep (i, n) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  int sum = abs(A[0]) + abs(A[n - 1]);
  rep2 (i, 1, n) {
    sum += abs(A[i - 1] - A[i]);
  }
  vector<int> diffs;
  diffs.push_back(abs(A[0]) + abs(A[0] - A[1]) - abs(A[1]));
  rep2 (i, 1, n - 1) {
    diffs.push_back(abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1]) - abs(A[i - 1] - A[i + 1]));
  }
  diffs.push_back(abs(A[n - 1]) + abs(A[n - 1] - A[n - 2]) - abs(A[n - 2]));

  rep (i, n) {
    cout << sum - diffs[i] << endl;
  }
}


Measured memory_bytes: 2168
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> M;
	map<pair<int, int>, int>m;
	vector<vector<int>>num(N + 4, vector<int>(5, -1));
	for (int i = 0; i < M; i++) {
		cin >> H >> W >> K;
		H++;
		W++;
		if (abs(W - H) <= 2) {
			num[H][W - H + 2] = K;
		}
		else {
			if (W > H)swap(W, H);
			auto it = m.find({ H,W });
			if (it != m.end() && it->second != K) {
				cout << 0 << endl;
				return 0;
			}
			m[{H, W}] = K;
		}
	}
	num[2][0] = num[2][1] = num[3][0] = num[N + 0][4] = num[N + 1][3] = num[N + 1][4] = 0;
	vector<vector<long long int>>dp(N + 4, vector<long long int>(1 << 7));
	dp[1][0] = 1;
	dp[1][32] = 1;
	dp[1][64] = 1;
	dp[1][96] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 1 << 5; j++) {
			//dp[i][j] %= MOD;
			bool flag = true;
			for (int k = 0; k < 5; k++) {
				if (num[i + 1][k] != -1 && ((j >> k) & 1) != num[i + 1][k]) {
					flag = false;
					break;
				}
			}
			if (!flag)continue;
			//cout << i << " " << j << endl;
			for (int k = 0; k < 1 << 7; k++) {
				if (!dp[i][k])continue;
				if (((k >> 4) ^ (k >> 5) ^ (j >> 1) ^ (j >> 2)) & 1)continue;
				if (((k >> 0) ^ (k >> 1) ^ (k >> 2) ^ (k >> 3) ^ (k >> 4) ^ (k >> 5) ^ (j >> 0) ^ (j >> 1) ^ (j >> 2)) & 1)continue;
			//	cout << i << " " << k << endl;
			//	cout << "dp[i][j] " << dp[i][k] << endl;
				dp[i + 1][(k >> 4) | ((j >> 1) << 3)] += dp[i][k];
				dp[i + 1][(k >> 4) | ((j >> 1) << 3)] %= MOD;
			//	cout << ((k >> 4) | ((j >> 1) << 3)) << endl;
			//	cout << dp[i + 1][(k >> 4) | ((j >> 1) << 3)] << endl;
			}
		}
	}
	long long int ans = 0;
	for (int i = 0; i < 1 << 7; i++) {
		ans += dp[N + 1][i];
		ans %= MOD;
	}
	for (int i = 2; i <= N + 1; i++) {
		for (int j = 0; j < 1 << 7; j++) {
		//	if (dp[i][j])cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	long long int bi = 0;
	if (N > 3)bi = (N-3) * (N - 2) / 2;
	//cout << bi - m.size() << endl;
	ans *= power(2, bi - m.size(), MOD);
	ans %= MOD;
	cout << ans << endl;
}

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

using namespace std;

int main(void){
  int n,m,s[400],l[400],p[400],w[400],dp[400];
  
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> s[i] >> l[i] >> p[i];
  
  cin >> m;
  for(int i=0;i<m;i++)cin >> w[i];
  
  fill(dp,dp+400,-1);
  dp[0]=0;

  for(int i=1;i<400;i++)
    for(int j=0;j<n;j++)
      for(int k=s[j];k<=l[j];k++)
	if(i-k>=0)dp[i]=max(dp[i],dp[i-k]+p[j]);
  
  for(int i=0;i<m;i++){
    if(dp[w[i]]<0){
      cout << -1 << endl;
      return 0;
    }
  }
    
  for(int i=0;i<m;i++)
    cout << dp[w[i]] << endl;
  
  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin d(n);
    rep(i,n)cin>>d[i];
    sort(all(d));
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
while true do
  a, b, c= gets.chomp.split(" ")
  num1 = a.to_i
  num2 = c.to_i
  if b == "?"
    return
  elsif b == "+"
    puts num1 + num2
  elsif b == "-"
    puts num1 - num2
  elsif b == "*"
    puts num1 * num2
  else
    puts num1 / num2
  end
end



Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool boo=true;
  cin >> N;
  vector<long long>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  for(int i=N-2; i>=0; i--){
    if(vec[i+1] < vec[i]){
      if(vec[i]-1 != vec[i+1]){
        boo=false;
      }
      else{
        vec[i]--;
      }
    }
  }
  if(boo){
    cout << "Yes" << endl;
    return 0;
  }
    cout<<"No"<<endl;
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B)
        cout << C << endl;
    else if (A == C)
        cout << B << endl;
    else
        cout << A << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String __[]) {
        Scanner sc = new Scanner(System.in);
        int arr[] = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
        Arrays.sort(arr);
        System.out.println(arr[0]==5&&arr[1]==5&&arr[2]==7?"YES":"NO");

    }
}

Measured memory_bytes: 19924
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
#define N (1000000000+7)

int main(void) {
	ll n, k;
	cin >> n >> k;
	vector<ll>h(n);
	for (ll i = 0;i < n;i++)cin >> h[i];
	sort(h.begin(), h.end());
	ll ans = h[k - 1] - h[0];
	for (ll i = 1;i <= n - k;i++) {
		ans = min(ans, h[k - 1 + i] - h[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = []
for i in range(N) :
    a.append(int(input()))

index = 1
cnt = 0

for i in range(N):
    index = a[index - 1]
    cnt += 1
    if index == 2 :
        break
    if index == 1 :
        cnt = -1
        break
    if i == N - 1 :
        cnt = -1

print(cnt)


Measured memory_bytes: 7448
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	int K, A, B;
	cin >> K >> A >> B;

	for (int i = A; i <= B; ++i) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int count = 0;
    int ans = 0;
    for(int i=0;i<3;i++)
    {
        if(str[i]=='R')
        count++;
        else
        {
            ans = max(ans,count);
            count = 0;
        }
        
    }
    ans = max(ans,count);
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int max(int a, int b) {
	return (a > b) ? a : b;
}

int main() {
	int A, B, C, D, E;

	cin >> A >> B;

	C = A + B;
	D = A - B;
	E = A * B;

	cout << max(C, max(D, E)) << endl;

	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    long long c = 0;
    while(c < 1e10){
      c++;
    }
    cout << max(a+b,max(a-b,a*b));
    return 0;
}

Measured memory_bytes: 256
#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##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1e9
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    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
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 2e5+7;
 
  
int main()
{

    ll a;
    lscf(a);
    
    long double b;
    cin>>b;
    
    long double c=a*b;
    
    cout<<(ll)c<<endl;
    
    

}

Measured memory_bytes: 3792
#include<stdio.h>

int main(void)
{
	int gozen,gogo; 
	int sum,nin;
	char namae[16];
	int i;

	for(i=0;i<9;i++){
		scanf("%s %d %d",namae,&gozen,&gogo);
		nin=gozen+gogo;
		sum=gozen*200+gogo*300;
		printf("%s %d %d\n",namae,nin,sum);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1e9+7
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i= 0; i < n; i++) cin >> a[i];
	int dp[n + 2];
	for(int i= 0; i < n; i++) dp[i] = mod;
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);

	for(int i= 2; i < n; i++){
		for(int j= 1; j<= k; j++){
			int x = i - j;

			if(x < 0) break;
	//		cout<<x<<" dp["<<x<<"]"<<dp[x]<<endl;
			dp[i] = min(dp[i] , abs(a[i] - a[x]) + dp[x]);
		}
	}
	//cout<<endl;
	cout<<dp[n - 1];
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	int ans = 0, cnt = 0;
	rep(i, n - 1) {
		if (v[i] >= v[i + 1])
			cnt++;
		else
			cnt = 0;
		chmax(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
        int H, W;
    int i, j;
    
    while(scanf("%d %d\n", &H, &W) != "EOF"){
        if(H == 0 && W == 0) break;
        
        for(i = 0; i < H; i++) {
            for(j = 0; j < W; j++) {
                if (i == 0 || j == 0 || i == H-1 || j == W-1) {
                    printf("#");
                } else { 
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){
string u,t;
cin>>u>>t;
if((u[0]==t[2])&&(u[1]==t[1])&&(u[2]==t[0])){
    cout<<"YES"<<endl;
}
else{
    cout<<"NO"<<endl;
}

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N = 100100;
int p[N], n;
int main()
{
  cin >> n;
  for(int i = 1; i <= n; i++)
  {
    int v; cin >> v;
    p[v] = i;
  }
  for(int i = 1; i <= n; i++)
  {
    cout << p[i] << " ";
  }
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<int> x(n),mod(m),p(m);
    map<int,int> cnt[100010];
    REP(i,n){
        cin >> x[i];
        mod[x[i]%m]++;
        cnt[x[i]%m][x[i]/m]++;
        if(cnt[x[i]%m][x[i]/m]%2==0){
            p[x[i]%m]++;
        }
    }
    int ans=0,ad;
    REP(i,(m+2)/2){
        if(i==0){
            ad=mod[i]/2;
            ans+=ad;
            mod[i]-=ad*2;
        }else if(m%2==0&&i==m/2){
            ad=mod[i]/2;
            ans+=ad;
            mod[i]-=ad*2;
        }else{
            ad=min(mod[i],mod[m-i]);
            ans+=ad;
            mod[i]-=ad;
            mod[m-i]-=ad;
        }
    }
    REP(i,m){
        ans+=min(mod[i]/2,p[i]);
    }
    cout << ans <<endl;




    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N ;
  bitset<3> M(N);
  cout << M.count();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

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

using namespace std;

int n,nh;
char tr[10000][11];
int hit[10000],blow[10000];

char ans[11];
int gen(int i,char *s,bool *used){
	rep(j,nh){
		int h=hit[j],b=blow[j];
		rep(k,i) rep(l,n) if(s[k]==tr[j][l]) {
			if(k==l) h--;
			else     b--;
		}
		if(h<0 || b<0 || h+b>n-i) return 0;
	}

	if(i==n){ strcpy(ans,s); return 1; }

	int res=0;
	for(int c='0';c<='9';c++) if(!used[c]) {
		used[c]=true;
		s[i]=c;
		res+=gen(i+1,s,used);
		used[c]=false;
		if(res>=2) return res;
	}
	return res;
}

int main(){
	for(;scanf("%d%d",&n,&nh),n;){
		rep(i,nh) scanf("%s%d%d",tr[i],hit+i,blow+i);

		char s[11]={};
		bool used[128]={};
		printf("%s\n",gen(0,s,used)==1?ans:"NO");
	}

	return 0;
}

Measured memory_bytes: 756
#include <cstdio>
using namespace std;
int main(){
	int n, d, c=0, na;
	scanf("%d %d", &n,&d);
	na = n;
	while(na > 0){
			na -= (d*2 + 1);
			c++;
		
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int R, C, K; cin >> R >> C >> K;
    vector<vector<ll>> v(R+1, vector<ll>(C+1));
    int r, c;
    rep(i, K) {
        cin >> r >> c;
        cin >> v[r][c];
    }
    vector<vector<vector<ll>>> dp(R+1, (vector<vector<ll>>(C+1, vector<ll>(4))));
    rep(i, R) {
        rep(j, C) {
            ll mx = max({dp[i][j+1][0], dp[i][j+1][1], dp[i][j+1][2], dp[i][j+1][3]});
            dp[i+1][j+1][0] = max({dp[i+1][j+1][0], dp[i+1][j][0], mx});
            dp[i+1][j+1][1] = max({dp[i+1][j+1][1], dp[i+1][j][1], mx+v[i+1][j+1]});
            rep(k, 3) {
                dp[i+1][j+1][k+1] = max({dp[i+1][j+1][k+1], dp[i+1][j][k+1], dp[i+1][j][k]+v[i+1][j+1]});
            }
        }
    }
    cout << max({dp[R][C][0], dp[R][C][1], dp[R][C][2], dp[R][C][3]}) << endl;
}


Measured memory_bytes: 707116
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define bit(n) (1LL<<(n))
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    string a; cin >> a;
    int n = a.length();
    vv<int> nxt(n+1,vi(26,n));
    rrep(i,n){
        rep(j,26) nxt[i][j] = nxt[i+1][j];
        nxt[i][a[i]-'a'] = i;
    }
    vi dp(n+1,INF);
    vector<char> rec(n+1,'a');
    dp[n] = 1;
    rrep(i,n)rep(j,26){
        if(nxt[i][j] == n) {
            if(dp[i]>1){
                dp[i] = 1;
                rec[i] = 'a'+j;
            }
        } else if(dp[i]>dp[nxt[i][j]+1]+1){
            dp[i] = dp[nxt[i][j]+1]+1;
            rec[i] = 'a'+j;
        }
    }
    string res = "";
    int idx = 0;
    while(idx <= n){
        res += rec[idx];
        idx = nxt[idx][rec[idx]-'a']+1;
    }
    cout << res << '\n';
    

}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  priority_queue<P>que;
  rep(i,0,n)if(a[i]!=b[i])que.emplace(b[i],i);
  while(!que.empty()){
    auto p=que.top();
    que.pop();
    ll i=p.se;
    ll l=(i-1+n)%n;
    ll r=(i+1)%n;
    ll d=b[l]+b[r];
    //cout<<b[i] spa d<<endl;
    if(d>b[i]||a[i]>b[i]){
      judge=false;
      break;
    }
    if((b[i]-a[i])%d==0){
      res+=(b[i]-a[i])/d;
      b[i]=a[i];
    }
    else{
      res+=b[i]/d;
      b[i]=b[i]%d;
      if(b[i]<a[i]){
        judge=false;
        break;
      }
      que.emplace(b[i],i);
    }
    //debug(b,n);
  }
  ans(judge,res,-1);
  return 0;
}

Measured memory_bytes: 9712
import qualified Data.ByteString.Char8 as C
import Data.Maybe
  ( fromJust )
import Data.List
  ( findIndex, minimumBy )

main = do
  _ <- getLine
  [t,a] <- getParm
  hs    <- getParm  
  print . findIndex4Minimum $ map (f t a . toEnum) hs


getParm :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

f :: Int -> Int -> Int -> Double
f t a h = abs( (t'-h'*0.006) - a' )
  where
    t' = fromIntegral t -- toEnum t
    h' = fromIntegral h -- toEnum h
    a' = fromIntegral a -- toEnum a

findIndex4Minimum :: [Double] -> Int
findIndex4Minimum ws = snd . minimumBy c . zip ws $ [1..]
  where
    c x y = compare (fst x) (fst y)

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define cs(ans); cout<<setprecision(20)<<fixed<<ans<<endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int X[]={2,1,-1,-2,-2,-1,1,2}; 
int Y[]={1,2,2,1,-1,-2,-2,-1}; 
struct comp{
	bool operator()(const pair<int,int>&a,const pair<int,int>&b) const {
		if(a.first>b.first) return true;
		if(a.first<b.first) return false; 
		if(a.second<b.second) return true;
		return false;
	}
};	
void solve(){
	ll n,k;
	cin>>n>>k;
	vl vec(n);
	cin>>vec;
	ll ans=0;
	Sort(vec);
	for(int i=0;i<k;i++) ans+=vec[i];
	cout<<ans<<endl;
	
	

		
	
	
	
	
	
	
	
	
	
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i<n;i++)
#define nforn(i,n) for(ll i=n-1;i>=0;i--)
#define forne(i,n) for(ll i=1;i<=n;i++)
#define forse(i,s,e) for(ll i=s;i<e;i++)
#define all(v) v.begin(),v.end()
#define MOD 1000000007
#define d1(x) cerr <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
	// cin>>t;
	while(t--){
		ll n,k;
		cin>>n>>k;
		ll arr[n];
		forn(i,n) cin>>arr[i];
		sort(arr,arr+n,greater<int>());
		ll ans = 0;
		forse(i,k,n) ans += arr[i];
		cout<<ans<<"\n";
	}
}

Measured memory_bytes: 1792
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char

main :: IO ()
main = do
  [a, b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ if a < 10 && b < 10
    then a * b
    else -1

Measured memory_bytes: 380
using System;
using System.Linq;

class p{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int M = int.Parse(Console.ReadLine());
    int[] P = new int[M];
    int[] X = new int[M];
    
    for(int i = 0; i < M; i++){
      int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
      P[i] = input[0];
      X[i] = input[1];
    }
    
    int sum = T.Sum();
    for(int i = 0; i < M; i++){
      Console.WriteLine(sum - T[P[i] - 1] + X[i]);
    }
  }
}

Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int T1, T2;
        Int A1, A2;
        Int B1, B2;
        cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
        Int P = T1 * (B1 - A1);
        Int Q = T2 * (B2 - A2);

        if (P + Q == 0ll) {
            cout << "infinity" << endl;
            return;
        }
        if (P < 0) {
            P = -P;
            Q = -Q;
        }
        if (P + Q > 0) {
            cout << 0 << endl;
            return;
        }
//        if ((P >= 0 && Q >= 0) || (P <= 0 && Q <= 0)) {
//            cout << 0 << endl;
//            return;
//        }

        Int dec = -(P + Q);


        Int ans = 1ll * (P / dec + 1ll) * 2 - 1ll;

        if (P % dec == 0) ans--;
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
  bool operator<(const Card& rhs) const { return rank < rhs.rank; }
  bool operator!=(const Card& rhs) const { return rank != rhs.rank || suit != rhs.suit; }
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::cout << sep << cards[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void copy_cards(Card dst[], const Card src[], const unsigned int n)
{
  std::memcpy(dst, src, sizeof(dst[0])*n);
}

static bool is_equal_cards(const Card cards1[], const Card cards2[], const unsigned int n)
{
  //std::memcmp(cards1, cards2, sizeof(cards1)) == 0
  for (auto i = 0u; i < n; ++i) {
    if (cards1[i] != cards2[i]) {
      return false;
    }
  }
  return true;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (auto j = 0u; j < n-1; ++j) {
    for (auto i = n-1; i > j; --i) {
      if (cards[i] < cards[i-1]) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (auto i = 0u; i < n-1; ++i) {
    auto min_j = i;
    for (auto j = i+1; j < n; ++j) {
      if (cards[j] < cards[min_j]) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (auto i = 0u; i < n; ++i) {
    std::cin >> cards1[i];
  }
  copy_cards(cards2, cards1, n);
  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);

  if (is_equal_cards(cards1, cards2, n)) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
}

// eof

Measured memory_bytes: 3152
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: u64 = iter.next().unwrap().parse().unwrap();
    let x: u64 = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let iter = buf.split_whitespace();
    let mut sweets_number: Vec<u64> = Vec::new();
    for str in iter{
        sweets_number.push(str.parse::<u64>().unwrap());
    }

    println!("{}", solve(n, x, sweets_number))
}

fn solve(n: u64, x: u64, mut sweets_number: Vec<u64>) -> u64{
    let sum: u64 = sweets_number.iter().sum();
    if sum == x{
        return n;
    }
    if sum < x {
        return n -1;
    }

    sweets_number.sort();
    if sweets_number[0] > x {
        return 0;
    }

    let mut sweets_iter = sweets_number.iter();
    let mut counter = 0;
    let mut sum = 0;
    while sum <= x{
        counter += 1;
        let new = *(sweets_iter.next().unwrap());
        sum += new;
    }
    counter - 1
}


Measured memory_bytes: 4352
a=gets.split(" ").map{|e|e.to_i}
sum=Array.new(a[1],0)
a[0].to_i.times{
	l=gets.split(" ").map{|e|e.to_i}
	puts "#{l*" "} #{l.inject(:+)}"
	sum=[sum, l].transpose.map{|f|f.inject(:+)}
}
puts "#{sum*" "} #{sum.inject(:+)}"

Measured memory_bytes: 6120
#include <cstdio>
#include <map>
using namespace std;
typedef long long LL;
map<LL,int> f;
int c[405][4];
LL a[405];
LL Ch(LL x0,int x1,int x2,int x3){
	return x0<<30|x1<<20|x2<<10|x3;
}
void add(LL x,int v){
	for (int i=0;i<4;i++){
		x=(x>>10)+((x&1023)<<30);
		f[x]+=v;
	}
}
int main(){
	int n;
	scanf("%d\n",&n);
	for (int i=1;i<=n;i++){
		for (int j=0;j<4;j++)
			scanf("%d",&c[i][j]),a[i]=a[i]<<10|c[i][j];
		add(a[i],1);
	}
	LL ans=0;
	for (int i=1;i<=n-5;i++){
		add(a[i],-1);
		for (int j=i+1;j<=n;j++){
			add(a[j],-1);
			for (int k=0;k<4;k++){
				LL A[4];
				A[0]=Ch(c[i][0],c[j][k],c[j][(k+3)&3],c[i][1]);
				A[1]=Ch(c[i][1],c[j][(k+3)&3],c[j][(k+2)&3],c[i][2]);
				A[2]=Ch(c[i][2],c[j][(k+2)&3],c[j][(k+1)&3],c[i][3]);
				A[3]=Ch(c[i][3],c[j][(k+1)&3],c[j][k],c[i][0]);
				if (!f[A[0]]||!f[A[1]]||!f[A[2]]||!f[A[3]]) continue;
				LL cnt=1;
				for (int l=0;l<4;l++) cnt*=f[A[l]],add(A[l],-1);
				for (int l=0;l<4;l++) add(A[l],1);
				ans+=cnt;
			}
			add(a[j],1);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 20352