akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k;
int dat[100002];
int main(void){
  scanf("%d%d",&n,&k);
  int i,j;
  int no=0,ls=0,ans=0;
  bool lf=false,cf=false;
  while(n!=0){
    for(i=0;i<k;i++)scanf("%d",&(dat[i]));
    sort(dat,dat+k);
    dat[k]=100005;
    i=0;
    if(dat[i]==0){
      cf=true;
      i++;
      if(dat[i]!=1)lf=true;
    }
    while(i<k){
      j=i;
      while(j<k && dat[j+1]==dat[j]+1)j++;
      ls=no;no=j-i+1;i=j;
      if(cf&&lf){
	ans=ans<no+ls+1?no+ls+1:ans;
      }
      else{
	ans=ans<no?no:ans;
      }
      if(dat[j+1]==dat[j]+2)lf=true;
      i++;
    }
    printf("%d\n",ans);
    scanf("%d%d",&n,&k);
  }
  return 0;
}

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

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

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(C));
    ll ans = 0;
    REP(i, N) {
        ll a = lower_bound(ALL(A), B[i]) - A.begin();
        ll b = C.end() - upper_bound(ALL(C), B[i]);
        ans += a * b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main(){
int i=0,j,n,ch=0,k;
cin >> n;
string s[n];
  char l;
  j=0;
  cin >> s[i];
  l=s[i][s[i].size()-1];
  j++;
  for(i=1;i<n;i++){
    cin >> s[i];
    if(s[i][0]!=l)ch=1;
    l=s[i][s[i].size()-1];
    for(k=0;k<j;k++)if(s[i]==s[k])ch=1;
    j++;
  }
  if(ch)cout << "No" << endl;
  else cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cnt = 0;
		for(int i = a;i <= b;i++) {
			String s = String.valueOf(i);
			if((s.charAt(0) == s.charAt(4)) && (s.charAt(1) == s.charAt(3))) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
}

Measured memory_bytes: 26836
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,m,c=0;
    cin >> n;
    vector<int>t(n);
    vector<int>p(m);
    vector<int>x(m);
    for(int i=0;i<n;i++){
        cin >> t[i];
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> p[i];
        cin >> x[i];
    }
    for(int i=0;i<n;i++){
        c+=t[i];
    }
    int sum=c;
    for(int i=0;i<m;i++){
        c=c-t[p[i]-1]+x[i];
        cout << c << "\n";
        c=sum;
    }
}

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

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int count = 0;
    for (int i = 0; i < A + 1; i++)
    {
        for (int j = 0; j < B + 1; j++)
        {
            for (int k = 0; k < C + 1; k++)
            {
                if (500 * i + 100 * j + 50 * k == X)
                {
                    count++;
                }
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
#define pb push_back
#define INF 1e15

class SegTree {
public:
	int n;
	VL nodes;
	VL lazy;
	SegTree(VL a) {
		int size = a.size();
		n = 1;
		while(n < size) n *= 2;
		nodes.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1, 0);
		for (int i = 0; i < size; ++i) {
			nodes[i + n - 1] = a[i];
		}
		for (int i = size; i < n; ++i) {
			nodes[i + n - 1] = INF;
		}
		for (int i = n - 2; i >= 0; --i) {
			nodes[i] = min(nodes[i * 2 + 1], nodes[i * 2 + 2]);
		}
	}

	void eval(int k, int l, int r) {
		if(lazy[k] != 0) {
			nodes[k] += lazy[k];
			if(r - l > 1) {
				lazy[k * 2 + 1] += lazy[k];
				lazy[k * 2 + 2] += lazy[k];
			}
			lazy[k] = 0;
		}
	}

	void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
		if(r < 0) r = n;
		eval(k, l, r);
		if(r <= a || b <= l) return;
		if(a <= l && r <= b) {
			lazy[k] += x;
			eval(k, l, r);
		}else {
			add(a, b, x, k * 2 + 1, l, (l + r) / 2);
			add(a, b, x, k * 2 + 2, (l + r) / 2, r);
			nodes[k] = min(nodes[k * 2 + 1], nodes[k * 2 + 2]);
		}
	}

	ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
		if(r < 0) r = n;
		eval(k, l, r);
		if(r <= a || b <= l) return INF;
		if(a <= l && r <= b) {
			return nodes[k];
		}else {
			ll ml = get(a, b, k * 2 + 1, l, (l + r) / 2);
			ll mr = get(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(ml, mr);
		}
	}
};

int main(int argc, char **argv) {
	int n, q;
	cin >> n >> q;
	VL a(n, 0);
	SegTree st(a);
	VVL qu(q, VL(4));
	for (int i = 0; i < q; ++i) {
		cin >> qu[i][0];
		if(qu[i][0] == 0) {
			cin >> qu[i][1] >> qu[i][2] >> qu[i][3];
		}else {
			cin >> qu[i][1] >> qu[i][2];
		}

	}
	for (int i = 0; i < q; ++i) {
		if(qu[i][0] == 0) {
			st.add(qu[i][1], qu[i][2] + 1, qu[i][3]);
		}else {
			cout << st.get(qu[i][1], qu[i][2] + 1) << endl;
		}
//		for (int i = 0; i < st.nodes.size(); ++i) {
//			cout << st.nodes[i] << " ";
//		}
//		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 14776
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[500005];

void solve()
{
    scanf("%s", str);
    int n = strlen(str);
    vector<int> v;
    int i;
    int flag = 0;
    if(str[0]=='>') {
        v.push_back(0);
        flag = 1;
    }
    int cnt = 0;
    for (i = 0; i < n; i++) {
        if (str[i] == '<') {
            if (flag == 0) {
                cnt++;
            }
            else {
                v.push_back(cnt);
                cnt = 1;
                flag = 0;
            }
        }
        else {
            if (flag == 0) {
                v.push_back(cnt);
                cnt = 1;
                flag = 1;
            }
            else {
                cnt++;
            }
        }
    }
    v.push_back(cnt);
    if (v.size() % 2) {
        v.push_back(0);
    }
    ll s = 0;
    for (i = 0; i < (int)v.size(); i++) {
        s += ((ll)v[i] * (v[i] - 1) / 2);
        if(i%2) {
            s += MAX(v[i - 1], v[i]);
        }
    }

    printf("%lld\n", s);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1912
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll N, M, A, B;
  cin >> N >> M;

  vector<set<ll>> mem;
  vector<ll> res;
  res.reserve(N+1);
  mem.reserve(N+1);
  queue<ll> que;
  set<ll> counter;


  for (auto i = 0;i < N+1;i ++) {
    res.push_back(0);
    mem.push_back(set<ll>());
  }
  for (auto i = 0;i < M;i ++) {
    cin >> A >> B;
    mem[A].insert(B);
    mem[B].insert(A);
  }
  if (mem[1].size() == 0) {
    cout << "No" << endl;
    return 0;
  }
  ll sum = 0;
  que.push(1);
  counter.insert(1);
  while (!que.empty()) {
    auto n = que.front();
    que.pop();
    for (auto it = mem[n].begin();it != mem[n].end();it ++) {
      if (counter.find(*it) != counter.end()) {
        continue;
      }
      sum ++;
      res[*it] = n;
      counter.insert(*it);
      que.push(*it);
    }
  }
  if (sum == N - 1) {
    cout << "Yes" << endl;
    for (auto i = 2;i < res.size();i ++) {
      cout << res[i] << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main()
{
	int d;
	cin >> d;
	if(d == 25){
		printf("Christmas");
	}
	else if(d == 24){
		printf("Christmas Eve");
	} 
	else if(d == 23){
		printf("Christmas Eve Eve");
	} 
	else{
		printf("Christmas Eve Eve Eve");
	}
	return 0;
} 

Measured memory_bytes: 256
a = [[int(i) for i in input().split()] for _ in range(3)]
for i in range(int(input())):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0
 
ans = "No"
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == 0:
        ans = "Yes"
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = "Yes"
if a[2][0] == a[1][1] == a[0][2] == 0:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

struct Timer {
    chrono::system_clock::time_point start;
    int ms;
    Timer(int ms) : start(chrono::system_clock::now()), ms(ms) {}
    bool stop() {
        chrono::system_clock::time_point curr = chrono::system_clock::now();
        double t = static_cast<double>(chrono::duration_cast<chrono::microseconds>(curr - start).count() / 1000.0);
        return t > ms;
    }
};

using ulint = unsigned long long;
struct RandomNumberGenerator {
    mt19937_64 mt;
    RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    ulint operator()(ulint a, ulint b) { // [a, b)
        uniform_int_distribution<ulint> dist(a, b - 1);
        return dist(mt);
    }
    ulint operator()(ulint b) { // [0, b)
        return (*this)(0, b);
    }
    ulint operator()() { return mt(); }
};

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

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

    Timer t(1950);
    RandomNumberGenerator r();

    int d;
    cin >> d;
    vector<lint> c(26);
    for (int i = 0; i < 26; ++i) {
        cin >> c[i];
    }
    vector<vector<lint>> s(d, vector<lint>(26));
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            cin >> s[i][j];
        }
    }
    vector<lint> ret(d, -1);
    vector<lint> mx(d, -1);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            if (chmax(mx[i], s[i][j]))
                ret[i] = j;
        }
    }
    for (int i = 0; i < d; ++i) {
        cout << ret[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <time.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;

int n,a[maxn],b[maxn];

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  int l = 0, r = n-1;
  for(int i=n-1;i>=0;i--){
    if((n-i)&1)b[l++]=a[i];
    else b[r--]=a[i];
  }
  for(int i=0;i<n-1;i++)cout<<b[i]<<" ";
  cout<<b[n-1]<<endl;
  return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  ll a, b;
  cin >> a >> b;
  double c = double(a) / double(b);
  cout << a / b << " " << a % b;
  cout << fixed << setprecision(9) << " " << c << endl;
  return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
	int n;
	cin>>n;
	int mul = (n+1000-1)/1000;
	mul *= 1000;
	cout<<mul-n;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

    sort(a.begin(),a.end(),greater<int>());
    int alice=0;
    int bob=0;
    for(int i=0;i<n;i+=2) alice+=a[i];
    for(int i=1;i<n;i+=2) bob+=a[i];
    cout<<alice-bob<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <numeric>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(123456789012345678)


unsigned GetDigit(unsigned num) {
    return std::to_string(num).length();
}


int main(void){
	int N; cin >> N;
  if (N == 7 || N == 5 || N ==3) cout << "YES" << endl;
  else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  long s[A + 2], t[B + 2], x;
  for (int i = 1;i <= A;++ i) cin >> s[i];
  for (int i = 1;i <= B;++ i) cin >> t[i];
  s[0] = t[0] = -1e16;
  s[A + 1] = t[B + 1] = 1e16;
  for (int i = 0, mid, halfDiff;i < Q;++ i) {
    cin >> x;
    int mins = 0, maxs = A + 2, mint = 0, maxt = B + 2;
    while(halfDiff = maxs - mins >> 1) (s[mid = mins + halfDiff] < x ? mins : maxs) = mid;
    while(halfDiff = maxt - mint >> 1) (t[mid = mint + halfDiff] < s[mins] ? mint : maxt) = mid;
    long ans = abs(x - s[mins]) + abs(s[mins] - t[mint]);
    ans = min(ans, abs(x - s[mins]) + abs(s[mins] - t[maxt]));
    mint = 0;
    maxt = B + 2;
    while(halfDiff = maxt - mint >> 1) (t[mid = mint + halfDiff] < s[maxs] ? mint : maxt) = mid;
    ans = min(ans, abs(x - s[maxs]) + abs(s[maxs] - t[mint]));
    ans = min(ans, abs(x - s[maxs]) + abs(s[maxs] - t[maxt]));
    mins = mint = 0;
    maxs = A + 2;
    maxt = B + 2;
    while(halfDiff = maxt - mint >> 1) (t[mid = mint + halfDiff] < x ? mint : maxt) = mid;
    while(halfDiff = maxs - mins >> 1) (s[mid = mins + halfDiff] < t[mint] ? mins : maxs) = mid;
    ans = min(ans, abs(x - t[mint]) + abs(t[mint] - s[mins]));
    ans = min(ans, abs(x - t[mint]) + abs(t[mint] - s[maxs]));
    mins = 0;
    maxs = A + 2;
    while(halfDiff = maxs - mins >> 1) (s[mid = mins + halfDiff] < t[maxt] ? mins : maxs) = mid;
    ans = min(ans, abs(x - t[maxt]) + abs(t[maxt] - s[mins]));
    ans = min(ans, abs(x - t[maxt]) + abs(t[maxt] - s[maxs]));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int  long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */		
int n,p,d,a,x,i,cnt=0,pp,ans=0;	
int power(int a,int x){a%=p;
              int res=1;
		while(x>0){
		if(x&1)
		res=(res*a)%p;
		a=(a*a)%p;
                    x>>=1;  }
		return res;}
void solve()
{  string s; mii m;
   cin >> n >> p >> s;
   m[0]++;pp=0;cnt=0;
   if(p==2 || p==5)
   {
      for(i=0;i<n;i++)
      {
         if((s[i]-'0')%p==0)
         {
            ans+=i+1;
         }
      }
      cout << ans << endl;
      return ;
   }
  
   for(i=n-1;i>=0;i--)
   {  
      d=s[i]-'0';
      //a=cnt%(p-1);
      x=power(10,cnt)%p;
      //cout << pp <<" "<<x << " ";
      x=(x*d + pp);
      //cout<<x%p<<endl;
      m[(x%p)]++;
      pp=x%p;
      cnt++;
   }
   for(auto i:m)
   {  //cout << i.F<<" "<<i.S<<endl;
      
      ans+=(i.S * (i.S-1))/2;
   }
   cout << ans ;
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




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

if n % 2 == 0:
  dp = a[:2]
  for i in range(1, n // 2):
    dp = dp[0] + a[2*i], max(dp) + a[2*i+1]
else:
  dp = a[:3]
  for i in range(1, n // 2):
    dp = dp[0] + a[2*i], max(dp[:2]) + a[2*i+1], max(dp) + a[2*i+2]

print(max(dp))

Measured memory_bytes: 31544
#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;
int main()
{
    string str;
    cin >> str;
  int n, s;
  n = stoi(str);
  s = 0;
  for(auto c: str) {
    s += c - '0';
  }
  if(n % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
  
  

Measured memory_bytes: 256
import math

def rot60(s, t):
    v = t - s
    a = 1/2 + complex(0,(math.sqrt(3)/2))
    return v * a + s

def pr(p):
    x = p.real
    y = p.imag
    print('%.10f %.10f'%(x, y))

def dfs(p1, p2, n):
    if n == 0:
        return
    

    s = (p2 - p1) * (1/3) + p1
    t = (p2 - p1) * (2/3) + p1
    u = rot60(s, t)
    dfs(p1, s, n-1)
    pr(s)
    dfs(s, u, n-1)
    pr(u)
    dfs(u, t, n-1)
    pr(t)
    dfs(t, p2, n-1)
    
n = int(input())
s = (0 + 0j)
t = (100 + 0j)
pr(s)
dfs(s, t, n) 
pr(t)



Measured memory_bytes: 5724
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n = ri()
    r = n % 1000
    if r == 0:
        print (r)
    else:
        print (1000 - r)





mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 65004
module Main where

import Data.Functor

main :: IO ()
main =  do
  { is <- getLine
  ; if is == "-" then done
    else do
      { [m] <- getInts
      ; ss  <- loop m
      ; putStrLn $ foldl shuffle is ss
      } >> main
}

shuffle :: [a] -> Int -> [a]
shuffle xs h = case splitAt h xs of
  (ys,zs) -> zs ++ ys

done :: IO ()
done = return ()

loop :: Int -> IO [Int]
loop 0 = return []
loop m = do
  { [h] <- getInts
  ; hs  <- loop (m-1)
  ; return (h:hs)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 4068
import java.io.PrintWriter
import kotlin.comparisons.compareBy

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    val array = Array(M) {
        val (P, Y) = nextIntList()
        intArrayOf(P, Y)
    }
    val sorted = array.copyOf().sortedWith(compareBy({ it[0] }, { it[1] }))
    var curr = sorted[0][0]
    var count = 0
    for (a in sorted) {
        if (curr == a[0]) {
            a[1] = ++count
        } else {
            a[1] = 1
            count = 1
            curr = a[0]
        }
    }
    for (a in array) {
        pw.printf("%06d%06d\n", a[0], a[1])
    }
}


Measured memory_bytes: 133236
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
double dp[3000][3000];//现在在第i个，有j个朝上的概率
int main(){
	cin>>n;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		double x;
		cin>>x;
		for(int j=0;j<=i;j++)
			dp[i][j]=dp[i-1][j]*(double(1-x))+dp[i-1][j-1]*(double(x));
	}
	double ans=0.0;
	for(int i=(n/2+1);i<=n;i++)ans+=dp[n][i];
	printf("%.10f\n",ans);
	return 0;
}


Measured memory_bytes: 68864
x, y, a, b, c = map(int, input().split())

p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

X = p[:x] + q[:y] + r[:x+y]
X = sorted(X, reverse=True)

ans = sum(X[:x+y])
print(ans)


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S[3] = {"Sunny", "Cloudy", "Rainy"};

int main(){
  string now; cin >> now;
  for (int i = 0; i < 3; i++){
    if (S[i] == now){
      int next = (i + 1) % 3;
      cout << S[next] << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 3624
n = int(input())
s = input()
code = [0 for i in range(len(s))]
ans = ''
for i in range(len(s)):
    code[i] = ord(s[i]) + n
    if code[i] > 90:
        code[i] = (code[i] - 90) + 64
    ans += chr(code[i])
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int n;
long long h[100010], g[100010];

int main() {


	std::cin >> n;

	for (int i = 1; i <= n; ++i) {
		std::cin >> h[i];
		g[i] = 1000000000;
	}

	g[1] = 0;

	for (int i = 2; i <= n; ++i) {
		if (i == 2) {
			g[i] = g[i - 1] + std::abs(h[i - 1] - h[i]);
		}
		else {
			g[i] = std::min(g[i - 1] + std::abs(h[i - 1] - h[i]), g[i - 2] + std::abs(h[i - 2] - h[i]));
		}
	}
	std::cout << g[n] << std::endl;
	//system("pause");
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define VI vector<int>
#define PB(x) push_back(x)
#define SZ(x) end(x) - begin(x)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void CO(auto &a) {REP(i, SZ(a)) cout << i << ": " << a[i] << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n;	cin >> n;
	string s;	cin >> s;
	int cap = 0;
	REP(i,n){
		if (s[i] == 'R')	cap++;
		else				cap--;
	}
	if (cap > 0)	cout << "Yes" << endl;
	else			cout << "No" << endl;
return 0;
}


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

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

const ll MOD=1000000007LL;

ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }

//xのe丈の高速計算
ll POW(ll x, ll e) {
  //最初1
  ll v=1;
  //後処理は、xの二乗を取って、e/2する。
  //for (;something;)はwhile(something)に同じ
  for(; e; x=MUL(x,x), e>>=1) {
    //もしeが奇数なら、vにxをかける。
    if (e&1) v = MUL(v,x);
  }
  return v;
}


//a,b,c,d  1<->A, 2<->G, 3<->C, 4<->Tに対応?で、admissible出ない組み合わせがbad==true
inline bool bad(int a,int b,int c,int d){
    if (        b==1 && c==2 && d==3) return true;
    if (a==1         && c==2 && d==3) return true;
    if (        b==2 && c==1 && d==3) return true;
    if (        b==1 && c==3 && d==2) return true;
    if (a==1 && b==2         && d==3) return true;
    return false;
}


ll solve(int N) {
  //n のとき、a,b,c,dそれぞれ5通り試すの。
    ll dp[101][256][2];
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i=0;i<N;i++){
        for (int a=0;a<4;a++) for (int b=0;b<4;b++) for (int c=0;c<4;c++) for (int d=0;d<4;d++) {
            //何か5進法で表記しておるな？
            int abcd = ((a*4+b)*4+c)*4+d;
            for (int e=0; e<4; ++e) {
              //
                int bcde = ((b*4+c)*4+d)*4+e;
                //直前n-1でbadになるかどうかと、nでbadになるかどうかで4通りあるが、それぞれ
                //
                bool _bad = bad(b,c,d,e);
                for (int j=0;j<2;j++){
                    (dp[i+1][bcde][j || _bad] += dp[i][abcd][j]) %= MOD;
                }
            }
        }
    }
    ll ans = 0;
    for (int i=0;i<256;i++) {
        (ans += dp[N][i][1]) %= MOD;
    }
    return SUB(POW(4,N), ans);
}

int main() {
    int N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scanf("%d %d", &n, &l)

	s := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%s", &s[i])
	}

	sort.Strings(s)

	for i := 0; i < len(s); i++ {
		fmt.Printf("%s", s[i])
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
//#define DEBUG


int main(void)
{
  ll X;
  cin >> X;
  ll ot500,ot5;
  ot500 = X/500;
  ot5 = (X%500)/5;
  cout << ot500*1000 + ot5 * 5;
  
  return 0;
} 

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;

    long long longest=0;
    long long k,n;
    cin>>k>>n;

    vector<long long> arr;

    for(int i=0;i<n;i++) {
        long long num;
        cin>>num;
        arr.push_back(num);
    }

    for(int i=1;i<n;i++) {
        longest=max(longest,arr[i]-arr[i-1]);
    }

    longest=max(longest, arr[0]-(0-(k-arr[n-1])));

    cout<<k-longest<<endl;



}




Measured memory_bytes: 5332
/*****include*****/
#include <iostream>
#include <fstream>
#include <queue>

/*****マクロ定義*****/
#define START 0
#define EMPTY 10

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
char Field[1001][1001];
bool Visited[1001][1001];
int TimeF[1001][1001];

/*****その他関数置き場*****/
int bfs(int sx,int sy,int gx,int gy){
	queue<int> Qx;
	queue<int> Qy;
	int x_now;
	int y_now;
	int x_next;
	int y_next;
	int dx[] = {0,1,0,-1};
	int dy[] = {-1,0,1,0};
	Qx.push(sx);
	Qy.push(sy);
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			Visited[i][j] = false;
			TimeF[i][j] = 0;
		}
	}

	Visited[sy][sx] = true;
	TimeF[sy][sx] = 0;
	while(!(Qx.empty() && Qy.empty())){
		x_now = Qx.front();Qx.pop();
		y_now = Qy.front();Qy.pop();
		//cout << TimeF[y_now][x_now] << endl;
		if(x_now == gx && y_now == gy)	break;
		for(int i=0;i<4;i++){
			x_next = x_now + dx[i];
			y_next = y_now + dy[i];
			if(Field[y_next][x_next] == 'X' || Visited[y_next][x_next]);
			else{
				Qx.push(x_next);
				Qy.push(y_next);
				Visited[y_next][x_next] = true;
				TimeF[y_next][x_next] = TimeF[y_now][x_now] + 1;
			}
		}
	}
	return TimeF[gy][gx];
}
/*****main関数*****/
int main(){
	/*****変数置き場*****/
	int total_time = 0;
	char row[1001];
	int height;
	int width;
	int n;
	int x[] = {0,0,0,0,0,0,0,0,0,0};
	int y[] = {0,0,0,0,0,0,0,0,0,0};
	/*****ファイルオープン*****/	
	/*ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}*/
	
	/*****処理部*****/
	cin >> height >> width >> n;
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			Field[i][j] = 'X';
			Visited[i][j] = false;
			TimeF[i][j] = 0;
		}
	}
	for(int i=0;i<height;i++){
		cin >> row;
		for(int j=0;j<width;j++){
			Field[i+1][j+1] = row[j];
		}
	}
	/*for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cout << Field[i][j];
		}
		cout << endl;
	}*/
	for(int i=0;i<height+1;i++){
		for(int j=0;j<width+1;j++){
			switch (Field[i][j]){
			case 'S':
				x[START] = j;
				y[START] = i;
				break;
			case '1':
				x[1] = j;
				y[1] = i;
				break;
			case '2':
				x[2] = j;
				y[2] = i;
				break;
			case '3':
				x[3] = j;
				y[3] = i;
				break;
			case '4':
				x[4] = j;
				y[4] = i;
				break;
			case '5':
				x[5] = j;
				y[5] = i;
				break;
			case '6':
				x[6] = j;
				y[6] = i;
				break;
			case '7':
				x[7] = j;
				y[7] = i;
				break;
			case '8':
				x[8] = j;
				y[8] = i;
				break;
			case '9':
				x[9] = j;
				y[9] = i;
				break;
			}
		}
	}
	/*for(int i=0;i<10;i++){
		cout << x[i] << " ";
	}
	cout << endl;
	for(int i=0;i<10;i++){
		cout << y[i] << " ";
	}
	cout << endl;*/
	for(int i=0;i<n;i++){
		total_time += bfs(x[i],y[i],x[i+1],y[i+1]);
	}
	/*for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			cout << Visited[i][j];
		}
		cout << endl;
	}*/
	cout << total_time << endl;
	/*****処理終了後*****/
	/*fout.close();
	fin.close();*/
	//delete[] pField;
	//delete[] pVisited;
	return 0;
}

Measured memory_bytes: 7092
S = input() #文字列の取得
s = list(S) #文字列リストに変換

ans = 1
index = 1
before = s[0]

while index < len(s):
    if s[index] == before: #もし前の文字列と一致するなら
        if index == len(s)-1:
            break
        before = s[index]+s[index+1]
        ans += 1
        index += 2
    else:
        before = s[index]
        ans += 1
        index += 1

print(ans)

Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> z(n);
    for (int i = 0; i < k; i++) {
        int t;
        cin >> t;
        for (int j = 0; j < t; j++) {
            int f;
            cin >> f;
            z.at(f - 1) = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (z.at(i) == 0)ans++;
    }
    cout << ans << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    rep(i, n) {
        if (a[i] <= k) {
            k -= a[i];
            ans++;
        } else
            break;
    }

    if (k > 0 && ans == n)
        ans--;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  string s;cin>>s;
  for(int j=0;j<s.length()-1;++j) {
    int i = j+1;
    if(s[i]==s[j]) {
      pr("Bad");
      return 0;
    }
  }
  pr("Good");
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
place = 0
num = 1
while place <= n - 1:
    if a[place] == num:
        num += 1
        place += 1
    else:
        place += 1
if num == 1:
    print(-1)
else:
    print(n - (num - 1))

Measured memory_bytes: 26268
N = int(input())
a = []
for i in range(N):
    a += [int(input())]

temp = 1
pushed = set()
clear = False
while temp not in pushed:
    pushed.add(temp)
    temp = a[temp-1]
    if temp == 2:
        clear = True
        break

if clear:   print(len(pushed))
else:   print(-1)


Measured memory_bytes: 13220
import math as mt
a,b=map(int,input().split())
tem=max(a,b)
c=1
if a==b:
    print(a)
elif min(a,b)==1:
    print(max(a,b))
elif a%b==0 or b%a==0:
    print(max(a,b))
else:
        
    while 1:
        c+=1
        if (tem*c)%a==0 and (tem*c)%b==0:
            print(tem*c)
            break
        

Measured memory_bytes: 38768
#ダイクストラ法(単一始点最短路)　計算量O(|E|log|V|)
#V:頂点の集合 E:辺の集合
#負の辺が含まれるときはベルマンフォード法
import collections
import heapq

class Dijkstra():
    def __init__(self):
        self.e=collections.defaultdict(list)
    def add(self,u,v,d,directed=False):
        #0-indexedでなくても良いことに注意
        #u=from,v=to,d=cost
        #directed =Trueなら、有向グラフ
        if directed is False:
            self.e[u].append([v,d])
            self.e[v].append([u,d])
        else:
            self.e[u].append([v,d])
    def delete(self,u,v):
        self.e[u]=[_ for _ in self.e[u] if _[0]!=v]
        self.e[v]=[_ for _ in self.e[v] if _[0]!=u]
    def search(self,s):
        #:param s:始点
        #:return: 始点から各点までの最短経路
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))
        return d

#Saving Shuuk
n,m,s,t=map(int,input().split())
uvab=l=[list(map(int, input().split())) for i in range(m)]
#print(l)
graph1=Dijkstra()
graph2=Dijkstra()
for u,v,a,b in l:
    graph1.add(u,v,a)
    graph2.add(u,v,b)

result_a=graph1.search(s) #{2: 0, 1: 1, 4: 2, 3: 21})
result_b=graph2.search(t) #{3: 0, 1: 1, 4: 101, 2: 11})
ans_list=[float('inf')]   #[inf]

for i in range(n,0,-1):
    cur=result_a[i]+result_b[i]
    if cur>ans_list[-1]:
        cur=ans_list[-1]
    ans_list.append(cur)
#ans_list #[inf, 103, 21, 11, 2]

for i in range(len(ans_list[1:])):
    print(10**15-ans_list[-(i+1)])

Measured memory_bytes: 169340
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[300005][4];
int f[300005][4];

main()
{
    int n,k;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        cin>>a[i][j];
    }
    for(int i=1;i<=n;i++)
    {
        f[i][1]=max(f[i-1][2],f[i-1][3])+a[i][1];
        f[i][2]=max(f[i-1][1],f[i-1][3])+a[i][2];
        f[i][3]=max(f[i-1][2],f[i-1][1])+a[i][3];
      //  for(int j=i;j>=max(i-k,0LL);j--)
    //        f[i]=min(f[i],f[j]+abs(a[i]-a[j]));
    }
    cout<<max(max(f[n][1],f[n][2]),f[n][3]);

}


Measured memory_bytes: 10496
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
OutV = lambda x: print(*x, sep='\n')
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N, K = iInM()
P = iInLH()

P.sort()

ans = 0
for i in range(K):
    ans += P[i]

print(ans)

Measured memory_bytes: 62580
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    set<string> S;
    REP(i,N) {
        string s;
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;

}

Measured memory_bytes: 19152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll L;
  cin >> L;
  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];
  ll longest = -1;
  int point = -1;
  for (int i = 1; i < N; i++) {
    if (longest < a[i-1]+a[i]) {
      longest = a[i-1]+a[i];
      point = i;
    }
  }
  if (longest >= L) {
    cout << "Possible" << endl;
    for (int i = 1; i < point; i++) {
      cout << i << endl;
    }
    for (int i = N-1; i > point; i--) {
      cout << i << endl;
    }
    cout << point << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 1536
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int a[12][12];
    int n,m,x;
    in n>>m>>x;
    vector<int> c(n);
    rep(i,n)
    {
        in c[i];
        rep(j,m)
        {
            in a[i][j];
        }
    }
    int ans=INF;
    rep(s,1<<n)
    {
        int cost=0;
        vector<int> d(m);
        rep(i,n)
        {
            if(s>>i&1)
            {
                cost +=c[i];
                rep(j,m)
                {
                    d[j]+=a[i][j];
                }
            }
        }
        bool flag=true;
        rep(j,m)
        {
            if(d[j]<x)flag=false;
        }
        if(flag)ans=min(ans,cost);
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 3628
S = list(str(input()))
Q = int(input())
s1 = []#先頭
s2 = []#後方
b = []
num_rev = 0
for i in range(Q):
  a = list(map(str, input().split()))
  if len(a) == 1:
    num_rev += 1
  else:
    if (num_rev + int(a[1]))%2==0:
      s2.append(a[2])
    else:
      s1.append(a[2])
if num_rev % 2 == 0:
  s1 = list(reversed(s1))
  s1.extend(S)
  s1.extend(s2)
  print(''.join(s1))
else:
  s2 = list(reversed(s2))
  s2.extend(list(reversed(S)))
  s2.extend(s1)
  print(''.join(s2))

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

//#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

int dp[50001];

inline bool chmin(int &a, int b){
    if(a > b) a = b;
    return a > b;
}

signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> c(n);
    rep(i,m) cin >> c[i];
    
    rep(i,n+1) dp[i] = i;
    
    reps(coin,1,m){
        reps(yen,1,n){
            if(yen < c[coin-1]) continue;
            chmin(dp[yen], dp[yen-c[coin-1]] + 1);
        }
    }
    
    cout << dp[n] << endl;
}


Measured memory_bytes: 3296
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int S[]=new int[N];
		boolean key[]=new boolean[N];
		String ans="";
		for(int i=0;i<M;i++){
			int s=stdIn.nextInt()-1;
			int c=stdIn.nextInt();
			if(s==0&&c==0&&N>1){
				System.out.println(-1);
				System.exit(0);
			}
			if(key[s]&&S[s]!=c){
				System.out.println(-1);
				System.exit(0);
			}
			else{
				key[s]=true;
				S[s]=c;
			}
		}
		for(int i=0;i<N;i++){
			if(i==0&&S[i]==0&&key[i]==false&&N!=1){
				S[i]=1;
			}
			ans+=String.valueOf(S[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    rep(i, 0, N) cin >> L[i];
    function<int(int, int, int, int)> rec = [&](int i, int a, int b, int c) {
        if(i == N) {
            if(a && b && c) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
            return INF;
        }
        int res = rec(i + 1, a, b, c);
        chmin(res, rec(i + 1, a + L[i], b, c) + 10);
        chmin(res, rec(i + 1, a, b + L[i], c) + 10);
        chmin(res, rec(i + 1, a, b, c + L[i]) + 10);
        return res;
    };
    cout << rec(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define maxn 200010
#define ll long long
int a[maxn];
int main ()
{   int n;
   cin>>n;
    for(int i=1;i<=n;i++)
      cin>>a[i];
    int ans=a[1];
    ll sum=0;
    for(int i=2;i<=n;i++)
    {   if(ans<a[i]) ans=a[i];
        else
        {  sum+=ans-a[i];    
		}
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int x,a;
    cin >> x>>a;

    int ans = 0;
    if(a<=x)ans = 10;

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


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin >> s;
    int win = 0;
    REP(i,s.size()) if (s[i] == 'o') win++;
    if (15 - s.size() >= 8 - win) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b;
	cin>>a>>b;
	if(a>8||b>8){
		cout<<":(";
	}
	else{
		cout<<"Yay!";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int height = sc.nextInt();
		int width = sc.nextInt();
		
		char[][] board = new char[height][width];
		
		for (int i = 0; i < height; i++) {
			String sCurr = sc.next();
			for (int j = 0; j < width; j++) {
				board[i][j] = sCurr.charAt(j);
			}
		}
		
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				if (!(board[i][j] == '#')) {
					boolean iLess = false;
					boolean iMore = false;
					boolean jLess = false;
					boolean jMore = false;
					int tempVal = 0;
					if (i - 1 >= 0) {
						iLess = true;
					} 
					if (i + 1 < board.length) {
						iMore = true;
					}
					if (j - 1 >= 0) {
						jLess = true;
					}
					if (j + 1 < board[0].length) {
						jMore = true;
					}
					if (iLess) {
						if (board[i - 1][j] == '#') {
							tempVal++;
						}
					}
					if (iMore) {
						if (board[i + 1][j] == '#') {
							tempVal++;
						}
					}
					if (jLess) {
						if (board[i][j - 1] == '#') {
							tempVal++;
						}
					}
					if (jMore) {
						if (board[i][j + 1] == '#') {
							tempVal++;
						}
					}
					if (iLess && jLess) {
						if (board[i - 1][j - 1] == '#') {
							tempVal++;
						}
					}
					if (iLess && jMore) {
						if (board[i - 1][j + 1] == '#') {
							tempVal++;
						}
					}
					if (iMore && jLess) {
						if (board[i + 1][j - 1] == '#') {
							tempVal++;
						}
					}
					if (iMore && jMore) {
						if (board[i + 1][j + 1] == '#') {
							tempVal++;
						}
					}
					board[i][j] = Integer.toString(tempVal).charAt(0);
				}
			}
		}
		for (int i = 0; i < height; i++) {
			String printString = "";
			for (int j = 0; j < width; j++) {
				printString += board[i][j];
			}
			System.out.println(printString);
		}
	}
}


Measured memory_bytes: 21972