akhauriyash/Code-Regression huggingface dataset:
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < t.length(); i++) {
        cout << t[i];
    }

    for (int i = 0; i < s.length(); i++) {
        cout << s[i];
    }

    cout << endl;
    return 0;
}


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

using namespace std;

const int INF = numeric_limits<int>::max();
const int MAXN = 1e6 + 100;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const int P = 29;
const double PI = acos(-1);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define int int64_t

string s;

vector <int> h;
int step[MAXN];

int found(int l, int len) {
    int r = l + len - 1;
    int h1 = h[r];
    if(l == 0) {
        return h1;
    }
    return (h1 - (h[l - 1] * step[len]) % MOD + MOD) % MOD;
}

bool check(int len) {
    if(len >= s.size()) {
        return 0;
    }
    int l = 0;
    for (int l = 0; l < s.size(); ++l) {
        int r = l + len - 1;
        if(r >= s.size()) {
            break;
        }
        for (int l2 = r + 1; l2 < s.size(); ++l2) {
            int r2 = l2 + len - 1;
            if(r2 >= s.size()) {
                break;
            }
            if(found(l2, len) == found(l, len)) {
                return 1;
            }
        }
    }
    return 0;
}

signed main() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    step[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        step[i] = (step[i - 1] * P) % MOD;
    }
    int n;
    cin >> n;
    cin >> s;
    h.resize(n);
    h[0] = s[0];
    for (int i = 1; i < n; ++i) {
        h[i] = ((h[i - 1] * P) % MOD + s[i]) % MOD;
    }
    int l = 0, r = s.size() + 1;

    while(r - l > 1) {
        int m = l + (r - l) / 2;
        if(check(m)) {
            l = m;
        }
        else {
            r = m;
        }
    }
    cout << l;
    return 0;
}

Measured memory_bytes: 8192
// Problem : C - : (Colon)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Author : Ritbik Bharti

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define clr(a,x) memset(a,x,sizeof(a));
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define print(v) for(const auto itr:v){ cout << itr << ' ';} cout << endl;
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define mod 1e9

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL; 
double PI = acos(-1);
//#define PI 3.14159265358979323846264338327950L

int main(){
    fastIO

    int a,b,h,m;
    cin>>a>>b>>h>>m;
    
    long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);

	cout<<setprecision(20)<<sqrtl(rsq);


    return 0;
}

Measured memory_bytes: 4156
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        mp[x]++;
    }
    int a = begin(mp)->first, b = rbegin(mp)->first;
    bool f = true;
    if(b - a >= 2){
        f = false;
    }else{
        if(a == b){
            if(a != n - 1 && 2 * a > n){
                f = false;
            }
        }else{
            if(mp[a] >= b || 2 * (b - mp[a]) > mp[b]){
                f = false;
            }
        }
    }
    cout << (f? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <atcoder/all>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    dsu d(n);

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        d.merge(a, b);
    }

    cout << d.groups().size() - 1 << endl;
}

Measured memory_bytes: 8884
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  int max1 = 0;
  int max2 = 0;
  vector<int > a(n, 0);
  vector<int > b(n, 0);
  REP(i, n){
    cin >> a[i];
    b[i] = a[i];
    max1 = max(max1, a[i]);
  }
  sort(all(b));
  max2 = b[n -2];
  REP(i,n){
    if(a[i] == max1){cout << max2 << endl;}
    else{cout << max1 << endl;}
  }
}


Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll X;
    cin >> X;
    ll tmp=X,cnt=0;
    while(tmp!=0){
      cnt+=tmp%10;
      tmp/=10;
    }
    if(X%cnt==0)cout<<"Yes";else cout<<"No";
    return 0;
}


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

int main(){
    int h,w;
    for(;;){
        scanf("%d %d",&h,&w);
        if(h==0 && w==0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0 || i==h-1 || j==0 || j==w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int H, W;

int main()
{
    while(1)
    {
        cin >> H >> W;
        if(H == W && H == 0) break;
        for(int i = 0;i < H;i++)
        {
            for(int j = 0;j < W;j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
<?php

$in = explode(' ', fgets(STDIN));
$N = $in[0];
$A = (int)$in[1];
$B = (int)$in[2];
$sum = 0;

for($i =0; $i <= $N; $i++){
  $X = str_split($i);
  $sum2 = 0;
  for($j = 0; $j < count($X); $j++) {
    $sum2 = $sum2 + (int)$X[$j];
  }

  if ($A <= $sum2 && $sum2 <= $B) {
    $sum = $sum + $i;
  }
}

echo $sum;

?>


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

string S;

signed main() {
    cin >> S;
    bool a = (S[0] == '0' && S[1] != '0') || (S[0] == '1' && (S[1] == '0' || S[1] == '1' || S[1] == '2'));
    bool b = (S[2] == '0' && S[3] != '0') || (S[2] == '1' && (S[3] == '0' || S[3] == '1' || S[3] == '2'));
    if (a && b) {
        cout << "AMBIGUOUS" << endl;
    }
    if ((!a) && b) {
        cout << "YYMM" << endl;
    }
    if ((a && (!b))) {
        cout << "MMYY" << endl;
    }
    if ((!a) && (!b)) {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	for (int i = 0; i <= N-1; i++) {
		int j = N-1 - i;
		//i回増やしてj回減らす

		bigint midmin = bigint(A) + bigint(C) * bigint(i);
		bigint midmax = bigint(A) + bigint(D) * bigint(i);

		bigint endmin = midmin - bigint(D) * bigint(j);
		bigint endmax = midmax - bigint(C) * bigint(j);

		if (endmin <= bigint(B) && bigint(B) <= endmax) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;



	return 0;
}





Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int a,b,c;
multiset<string> s;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	for (int i=0;i<a;i++)
	{
		s.insert("a");
	}
	for (int i=0;i<b;i++)
	{
		s.insert("b");
	}
	for (int i=0;i<c;i++)
	{
		s.insert("c");
	}
	multiset<string>::iterator it;
	while (s.size()!=1)
	{
		string x=*s.begin();
		string y=*s.rbegin();
		it=s.find(x);
		s.erase(it);
		it=s.find(y);
		s.erase(it);
		s.insert(x+y);
	}
	cout<<*s.begin()<<endl;
    return 0;
}
//直道相思了无益，未妨惆怅是清狂。
//——李商隐《无题》

Measured memory_bytes: 256
N = int(input())

inp = [[int(_) for _ in input().split()] for i in range(N)]
cx, cy, ct = 0, 0, 0

for t, x, y in inp:
    mv = abs(cx - x) + abs(cy - y)
    if mv + ct > t or (t - ct - mv) % 2 == 1:
        print('No')
        exit()
    cx, cy, ct = x, y, t

print('Yes')

Measured memory_bytes: 21108
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,p,sum=0,res=0,l=1;
  string s;
  cin>>n>>p>>s;
  map<ll,ll> m;
  if(p==2){
    for(ll i=n-1;i>=0;i--){
      ll x=ll(s[i]-'0');
      if(x%2==0)
        res+=i+1;
    }
    cout<<res;
    exit(0);
  }
  else if(p==5){
    for(ll i=n-1;i>=0;i--){
      ll x=ll(s[i]-'0');
      if(x==0||x==5)
        res+=i+1;
    }
    cout<<res;
    exit(0);
  }
  for(ll i=n-1;i>=0;i--){
    ll x=ll(s[i]-'0');
    sum+=((x%p)*l)%p;
    sum%=p;
    if(m.find(sum)==m.end())
      m.insert({sum,0});
    m[sum]++;
    l*=10;
    l%=p;
  }
  for(auto it=m.begin();it!=m.end();it++)
    res+=it->second*(it->second-1)/2;
  if(m.find(0)!=m.end())
    res+=m[0];
  cout<<res;
}

Measured memory_bytes: 1044
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N, A, B, C;
vector<int> ls;
vector<vector<char>> usages,usages2;
template <typename T>
void p(const vector<T>& xs) {
  cout<<xs.size()<<":";
  for(const auto& x:xs) cout<<x<<",";
  cout<<endl;
}
void add_usages(vector<char> usage) {
  if(usage.size()==N) { usages.push_back(usage); return; }
  vector<char> usage2;
  usage2=usage;
  usage2.push_back('A');
  add_usages(usage2);

  usage2=usage;
  usage2.push_back('B');
  add_usages(usage2);

  usage2=usage;
  usage2.push_back('C');
  add_usages(usage2);

  usage2=usage;
  usage2.push_back('D');
  add_usages(usage2);
}
void add_usages2() {
  for(auto usage:usages) {
    bool a = find(usage.begin(), usage.end(), 'A') != usage.end();
    bool b = find(usage.begin(), usage.end(), 'B') != usage.end();
    bool c = find(usage.begin(), usage.end(), 'C') != usage.end();
    if(a && b && c) usages2.push_back(usage);
  }
}
int f2(int a, int b, int c, int mp) {
  int mp_a = abs(A - a);
  int mp_b = abs(B - b);
  int mp_c = abs(C - c);
  return mp + mp_a + mp_b + mp_c;
}
int f(vector<char> usage) {
  int a, b, c, n_a, n_b, n_c; a=b=c=n_a=n_b=n_c=0;
  for(int i=0; i<usage.size(); ++i) {
    char x = usage[i];
    if     (x=='A') { a+=ls[i]; ++n_a; }
    else if(x=='B') { b+=ls[i]; ++n_b; }
    else if(x=='C') { c+=ls[i]; ++n_c; }
    else if(x=='D') {}
    else            { cout<<"err"<<endl; exit(0); }
  }
  int mp = 10 * (n_a-1 + n_b-1 + n_c-1);
  return f2(a, b, c, mp);
}
main () {
  cin>>N>>A>>B>>C;
  for(int n=1;n<=N;++n) {
    int l; cin>>l;
    ls.push_back(l);
  }
  add_usages(vector<char>());
  add_usages2();
  vector<int> mps;
  for(auto& usage:usages2) {
    int mp = f(usage);
    mps.push_back(mp);
  }
  int mi = *min_element(mps.begin(), mps.end());
  cout<< mi <<endl;
}

Measured memory_bytes: 6964
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<int> aa = a, bb = b;
  sort(aa.begin(), aa.end());
  sort(bb.begin(), bb.end());
  for (int i = 0; i < n; i++) {
    if (aa[i] > bb[i]) {
      cout << "No\n";
      return 0;
    }
  }
  vector<pair<int, int>> p;
  for (int i = 0; i < n; i++) p.emplace_back(b[i], a[i]);
  sort(p.begin(), p.end());
  map<int, vector<int>> pos;
  for (int i = 0; i < n; i++) {
    pos[p[i].second].push_back(i);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (p[i].first >= p[i].second) continue;
    int x = *prev(upper_bound(aa.begin(), aa.end(), p[i].first));
    int y = pos[x].back();
    pos[x].pop_back();
    pos[p[i].second].push_back(y);
    //cerr << p[i].second << " " << p[y].second << endl;
    swap(p[i].second, p[y].second);
    cnt++;
  }
  //cerr << cnt << endl;
  cout << (cnt < n - 1 ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 13684
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
long long int n,a,b;
scanf("%lld %lld %lld",&n,&a,&b);
if(a==0){
    printf("0\n");
}
else{
    long long int mod=(n)%(a+b);
    printf("%lld\n",(n/(a+b))*a+min(mod,a));
    }




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W, N; 
  cin >> H >> W >> N;

  map<pair<int, int>, int> m;
  while(N--){
    int x, y;
    cin >> x >> y;
    REP(i, 3) REP(j, 3){
      if(IN(1, x-i, H+2-3) && IN(1, y-j, W+2-3)) m[{x-i, y-j}]++;
    }
  }
  
  vector<int> ans(10, 0);
  for(auto p : m) ans[p.second]++;

  int sum = 0;
  REP(i, 10) sum += ans[i];
  ans[0] = (H-2)*(W-2)-sum;

  REP(i, 10){
    cout << ans[i] << "\n";
  }

  return 0;
}

Measured memory_bytes: 56576
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H = readline().decode('utf8').strip()
print(chr(ord(H) + 1))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; i++) {
        cin>>A[i];
    }
    int temp;
    ll sum = 0;
    int maxN = 0;
    for (int i = 0; i < N; i++) {
        maxN = max(maxN,A[i]);
        temp = maxN;
        sum += temp - A[i];
    }
    cout << sum;
}

Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            long n = int.Parse(Console.ReadLine());
            long sum = 0;
            for(long i = 1;i <= n; i++)
            {
                for(long j = 1;j <= n; j++)
                {
                    for(long k = 1;k <= n; k++)
                    {
                        sum += Gcd(k, Gcd(i, j));
                    }
                }
            }
            Console.WriteLine(sum);
        }

        public static long Gcd(long a, long b)
        {
            Func<long, long, long> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
    }

    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> node(n);
    for (int i = 0; i < n; i++) node[i] = i;
    int k = 1;
    while (pow(2, k) < n) k = k << 1;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            for (int p = 0; p < k; p++){
                if (((i >> p) & 1) != ((j >> p) & 1)){
                    cout << p + 1;
                    break;
                }
            }
            if (j != n - 1) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
const int Maxn=400000+10,Maxm=1000000+10;
int n,m,ans;
int a[Maxn];
bool c[Maxm];
bool vis[Maxn],flag[Maxn];
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
//	freopen("in.txt","r",stdin);
	n=read();
	for(int i=1;i<=n;++i) 
	a[i]=read(),m=max(m,a[i]);
	for(int i=1;i<=n;++i)
	{
		if(!c[a[i]])vis[i]=1;
		for(int j=a[i];j<=m;j+=a[i])
		c[j]=1;
	}
	memset(c,0,sizeof(c));
	for(int i=n;i;--i)
	{
		if(!c[a[i]])flag[i]=1;
		if(flag[i] && vis[i])++ans;
		for(int j=a[i];j<=m;j+=a[i])
		c[j]=1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5908
n = int(input())
s = input()
l = r = 0
for i in range(n):
  if s[i] == '(':
      l += 1
  else:
    if l > 0:
      l -= 1
    else:
      r += 1
for _ in range(r):
  s = "(" + s
for _ in range(l):
  s += ")"
print(s)

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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int color[9] = {};
	int a,n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a >= 3600)a = 3200;
		
		color[a / 400]++;
	}
	int mini = 0,maxi = 0;
	for(int i = 0; i < 8; i++){
		if(color[i])mini++;
	}
	maxi = mini + color[8];
	//maxi = min(maxi,8);
	mini = max(mini,1);
	cout << mini << " " << maxi << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;



int main(){
    int N;
    cin>>N;
    ll a;
    vector<ll> V;
    V.push_back(1);
    for(int i=0;i<N;i++){
        cin>>a;
        a*=(-1);
        int x=upper_bound(V.begin(),V.end(),a)-V.begin();
        if(V[x]==1){
            V[x]=a;
            V.push_back(1);
        }
        else V[x]=a;
    }
    cout<<(int)(V.size()-1)<<endl;
}


Measured memory_bytes: 1528
#include <stdio.h>
#include <string.h>
typedef long long ll;
int main() {
	char s[101];
	int k;
	scanf("%s%d", s, &k);
	int n = strlen(s), cnt = 1;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (i != n - 1 && s[i] == s[i + 1]) {
			cnt++;
		} else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans = ans * k;
	if (n == 1) {
		printf("%lld\n", (ll)n * k / 2);
		return 0;
	}
	if (s[0] == s[n - 1]) {
		int t = 1, h = 1;
		while (s[t] == s[0]) {
			t++;
			if (t == n) {
				printf("%lld\n", (ll)n * k / 2);
				return 0;
			}
		}
		while (s[n - h - 1] == s[n - 1]) {
			h++;
		}
		ans -= ((ll)(t / 2 + h / 2 - (t + h) / 2) * (k - 1));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vi t(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    ll ret     = 0;
    bool start = false;
    for (int i = 0; i < n; ++i) {
        if (start)
            ret += t[i];
        if (s[i] == x)
            start = true;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C')) !=-1 && int(a.rfind('F')) !=-1 && a.find('C') < a.rfind('F'))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
d = {
    'S': set([i for i in range(1,14)]),
    'H': set([i for i in range(1,14)]),
    'C': set([i for i in range(1,14)]),
    'D': set([i for i in range(1,14)])
}
for _ in range(int(input())):
    m, n = [i for i in input().split()]
    d[m].remove(int(n))

for m in ['S','H','C','D']:
    for i in d[m]:
        print(m, i)

Measured memory_bytes: 5604
import sys
from collections import defaultdict
from bisect import bisect_left
sys.setrecursionlimit(1000000)
input=sys.stdin.readline


N = int(input())
*a, = map(int, input().split())
d = defaultdict(list)
for _ in range(N-1):
    u, v = map(int, input().split())
    d[u].append(v)
    d[v].append(u)

INF = 10**20
l = [INF]*(N)
q = []
ans = [0]*(N+1)

def dfs(s, root):
    v = bisect_left(l, a[s-1])
    q.append((v, l[v]))
    l[v] = a[s-1]
    ans[s] = bisect_left(l, INF)

    for t in d[s]:
        if t==root:continue
        dfs(t, s)
    
    ba, bb = q.pop()
    l[ba] = bb

dfs(1, 0)
for i in range(1, N+1):
    print(ans[i])


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

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

    int i = 1, rezultat = 0;

    while(i <= n){
        int h;
        cin >> h;

        if(h >= k){
            rezultat = rezultat + 1;
      }
     i = i + 1;
    }

cout << rezultat << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;

int main(){
    int n,a,b;cin >> n>>a>>b;
    int diff = b-a;
    if(diff%2==0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

    int h, w;
    int i, j;

    while(1){
    
        cin >> h >> w;

        if(h == 0 && w == 0){
            break;
        }else{
            for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                    cout << "#";
                }
                cout << endl;
            }
            cout << endl;
        }
    }

    return 0;

}


Measured memory_bytes: 3080
#include<iostream>

using namespace std;

int main()
{
    int n,i,j,sum,x;
    cin>>n;
    sum=0;
    int t=0;
    for (i=1;i<=n;i++)
    {
        cin>>x;
        if (x%4==0) sum++;
        else if (x%2==0) t++;
    }
    if (t>1) 
    {
        n-=t;
        if (n%2) n++;
    }
    if (sum>=n/2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

public class HelloWorld
{
    static public void Main ()
    {
        var K = long.Parse(Console.ReadLine());
        
        var N = 50;
        var A = new long[N];
        var d = K%N;
        for(int i = 0;i < N;i++){
            if(i < N-d){
                A[i] = (N-1-d)+(K/N);
            }else{
                A[i] = N+(K/N);
            }
        }
        
        Console.WriteLine(N);
        Console.WriteLine(string.Join(" ",A));
     }            
}


Measured memory_bytes: 13268
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 998244353;
const int N = 2e3 + 10, M = 1e5 + 10;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

int res[N];

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 1; i < n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            int k;
            k = min(j - i, abs(i - x) + 1 + abs(y - j));
            res[k]++;
        }
    }
    for (int i = 1; i < n; i++)
        printf("%d\n", res[i]);
    return 0;
}


Measured memory_bytes: 256
arr = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    arr[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        print(' '+' '.join(str(x) for x in arr[b][f]))
    if(b < 3):
        print('#' * 20)

Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int v[200005];
int dp[200005][20];
int dp2[200005][20];
int seq[200005];

int lg(int x){ return 31 - __builtin_clz(x); }

int getmx(int l, int r){
	int lz = lg(r - l + 1);
	return max(dp[l][lz], dp[r - (1 << lz) + 1][lz]);
}

int getmn(int l, int r){
	int lz = lg(r - l + 1);
	return min(dp2[l][lz], dp2[r - (1 << lz) + 1][lz]);
}

int main() {
    int n,k;

    scanf("%d%d", &n, &k);

    for(int i = 0; i < n; i++) {
    	scanf("%d", &v[i]);
    	dp[i][0] = v[i];
    	dp2[i][0] = v[i];
    	seq[i] = (i == 0 or v[i] < v[i-1] ? 1 : seq[i-1] + 1);
    }

    for(int i = 1; i < 20; i++)
    	for(int j = 0; j <= n - (1<<i); j++) {
    		dp[j][i] = max(dp[j][i-1], dp[j + (1<<(i-1))][i-1]);
    		dp2[j][i] = min(dp2[j][i-1], dp2[j + (1<<(i-1))][i-1]);
    	}
    
    int ans = 1;
    int cur = getmx(0, k-1);
    bool jafoi = seq[k-1] == k;

    for(int i = k; i < n; i++) {
    	int mn = getmn(i-k, i-1);
    	if(v[i] < cur or v[i-k] > mn) {
    		if(seq[i] < k || !jafoi)
    			ans++;
    	}
    	jafoi |= seq[i] == k;
    	cur = getmx(i-k+1, i);
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 33024
#include<stdio.h>

int main(){
  int i, j, r, n, temp, index;
  int A[100001];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  r=n-1;
  i=0-1;
  for(j=0;j<r;j++){
    if(A[j]<=A[r]){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  index=i+1;
  for(i=0;i<n;i++){
    if(i==index) printf("[%d] ",A[i]);
  else if(i==n-1) printf("%d\n",A[i]);
  else printf("%d ",A[i]);
  }

  return 0;
}



Measured memory_bytes: 2172
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;

    bool restored = false;
    for (int i = S.length() - T.length(); i >= 0; i--) {
        bool f = true;
        for (int k = 0; k < T.length(); k++) {
            if (S[i+k] != '?' && S[i+k] != T[k]) {
                f = false;
                break;
            }
        }
        if (f) {
            restored = true;
            for (int k = 0; k < T.length(); k++) {
                S[i+k] = T[k];
            }
            break;
        }
    }

    if (!restored) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '?') {
            S[i] = 'a';
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.split('').map(&:to_i)
num = s[0,3]
n = s.size
i = 3

min = (753 - num.join('').to_i).abs
while i < n
  num.shift
  num << s[i]
  min = (num.join('').to_i - 753).abs if min >= (num.join('').to_i - 753).abs
  i += 1
end
puts min

Measured memory_bytes: 2044
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val t = sc.nextLine()
    if (t.startsWith(s) && t.length == s.length + 1) {
        println("Yes")
    } else {
        println("No")
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 35752
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  long long N;
  cin >> N;
  
  vector<long long> T(N,0);
  map<long long,long long> A;
  
  for(long long i=0; i<N; i++){
    cin >> T.at(i);
    A[T.at(i)+i]++;
  }
 
  long long count=0;
    
  for(long long i=0; i<N; i++){
    count+=A[i-T.at(i)];
  }
  cout << count << endl;
}

Measured memory_bytes: 27512
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
total_vote = 0
result = True
for a in A:
    total_vote += a
for m in range(M):
    if A[m] < (total_vote/(4*M)):
        result = False
if result:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 38384
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size)scanf("%d",&(name)[i])

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    print(e-a>k ? ":(":"Yay!");
    return 0;
}

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

using namespace std;

int main() {
	int n, m, a, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int temp = 0;
		for (int j = 0; j < m; j++) {
			cin >> a;
			temp += a;
		}
		ans = max(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    ll m;
    std::cin >> m;
    ll dsum = 0;
    ll sum = 0;
    for (int i = 0; i < m; i++) {
        ll d,c;
        std::cin >> d>>c;
        dsum += c;
        sum += d*c;
    }
    
    std::cout << dsum-1+(sum-1)/9 << std::endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();

            var N = int.Parse(ss[0]);
            var K = int.Parse(ss[1]);

            var prob = 0.0;

            for (int i = 1; i <= N; i++)
            {
                var point = i;
                var count = 0;
                while (point < K)
                {
                    point *= 2;
                    count++;
                }

                prob += (1.0 / N) * Math.Pow(0.5, count);
            }

            Console.WriteLine(prob);
        }
    }
}

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

// Range Minimum/Maximum Query: Semigroup
struct Element{
    ll value;
    bool isIdentity;
};
Element Identity = {0, true};
Element Operation(const Element &A, const Element &B){
    if(A.isIdentity) return B;
    if(B.isIdentity) return A;
    // return {min(A.value, B.value)};
    return {max(A.value, B.value)};
}

struct SegmentTree{
    int size; // number of leaves: power of two
    vector<Element> cbt; // complete binary tree

    // Initialize with Identity Element
    SegmentTree(int N){
        size = 1;
        while (size < N) size *= 2;
        cbt.resize(size * 2 - 1, Identity);
    }

    Element get(int i){
        i += size - 1;
        return cbt[i];
    }

    // Update i-th Leaf (0-indexed) to A
    void update(int i, const Element &A){
        i += size - 1;
        cbt[i] = A;
        while (i > 0){
            i = (i - 1) / 2;
            cbt[i] = Operation(cbt[i*2+1], cbt[i*2+2]);
        }
    }

    // Product of Interval [a, b) (0-indexed)
    Element query(int a, int b) {
        return query_rec(a, b, 0, 0, size);
    }

    Element query_rec(int a, int b, int k, int l, int r){
        // k is root of subtree [l, r)
        if(r <= a || b <= l) return Identity; // outside [a, b)
        if(a <= l && r <= b) return cbt[k]; // interior of [a, b)
        Element vl = query_rec(a, b, k*2+1, l, (l+r)/2);
        Element vr = query_rec(a, b, k*2+2, (l+r)/2, r);
        return Operation(vl, vr);
    }
};

int main() {
    int N;
    cin >> N;
    vector<int>cnt(N+1, 0);
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        cnt[A]++;
    }
    sort(cnt.begin(), cnt.end());
    SegmentTree tree(N+1);
    int sum = 0;
    // 取ることのできる回数でループ
    // Kに対して単調減少なので最大のKでセグ木に書き込む
    for (int i = 1; i <= N; ++i) {
        auto iter = lower_bound(cnt.begin(), cnt.end(), i);
        sum += cnt.end() - iter;
        int m = sum / i;
        tree.update(m, {i});
    }
    for (int i = 1; i <= N; ++i) {
        int ans = tree.query(i, N+1).value;
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 18432
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>

int main()
{
	int W, H, N;
	cin >> W >> H >> N;
	int minx = 0, miny = 0;
	for (size_t i = 0; i < N; i++)
	{
		int x, y, a;
		cin >> x >> y >> a;
		switch (a)
		{
		case 1:
			if (minx < x) minx = x;
			break;
		case 2:
			if (W > x) W = x;
			break;
		case 3:
			if (miny < y) miny = y;
			break;
		case 4:
			if (H > y) H = y;
			break;
		default:
			break;
		}
	}
	int h = (H - miny), w = (W - minx);
	if (h <= 0 || w <= 0) {
		cout << "0" << endl;
		return 0;
	}
	cout << (h*w) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long K, std::vector<long long> p){
  sort(p.begin(), p.end());
  ll ans = 0;
  rep(i,K)
    ans+=p[i];
  std::cout << ans << std::endl;
    
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}



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

using namespace std;

int main(){

    int arr[] = {1, 100, 10000, 1000000};
    int n, d;
    cin >> d >> n;
    int cnt = 1, idx = 0, prev = 0;
    while(idx < n ){
        if( cnt%arr[d] == 0 && cnt%arr[d+1] != 0 )
            prev = cnt, idx++;
        cnt++;
    }

    cout << prev << 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 k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    boolean goal = false;
    for (int i = a; i <= b; i++) {
      if (i % k == 0) {
        goal = true;
        break;
      }
    }
    if (goal) {
      System.out.println("OK");
    } else {
      System.out.println("NG");
    }
  }
}


Measured memory_bytes: 35828
W,H,N = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))
sur = [[1]*W for i in range(H)]
for i in range(N):
    if ls[i][2] == 1:
        for j in range(W):
            for k in range(H):
                if j < ls[i][0]:
                    sur[k][j] = 0
    if ls[i][2] == 2:
        for j in range(W):
            for k in range(H):
                if j >= ls[i][0]:
                    sur[k][j] = 0
    if ls[i][2] == 3:
        for j in range(W):
            for k in range(H):
                if k < ls[i][1]:
                    sur[k][j] = 0
    if ls[i][2] == 4:
        for j in range(W):
            for k in range(H):
                if k >= ls[i][1]:
                    sur[k][j] = 0
ans = 0
for i in range(H):
    ans += sur[i].count(1)
print(ans)

Measured memory_bytes: 9264
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi = 3.14159265358979323846264338327950288;
bool a[1000001];
int main() {
	string s;
	cin >> s;
	stack<char>t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'S')
			t.push('S');
		else if (s[i] == 'T'&&(t.empty()||t.top() == 'T'))
			t.push('T');
		else if (s[i] == 'T'&&t.top() == 'S')
			t.pop();
	}
	cout << t.size() << endl;
	cin >> s;
}

Measured memory_bytes: 644
N, K = map(int, input().split())

ans = 0

if N >= K:
    ans += (N - K + 1) / N
n = K - 1


tmp = 2
while n >= 1:
    a = 0
    if n == 1:
        a = 1 / tmp / N
    else:
        if n > N:
            if n % 2 == 1 and n // 2 < N:
                a = (N - n // 2) / tmp / N
            if n % 2 == 0 and n // 2 < N:
                a = (N - n // 2) / tmp / N
        else:
            a = (n - (n // 2)) / tmp / N
    tmp *= 2
    n //= 2
    ans += a
    #print(a)

print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){

    int A;
    int B;

    cin >> A >> B;

    if(A <= 5){
        cout << 0 << endl;
    }else if(A > 5 && A <= 12){
        cout << B/2 << endl;
    }else{
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	static int[][] visit=new int[51][51];
	static int H;
	static int W;
	public  static void main(String[] args) {
    	try (Scanner sc = new Scanner(System.in)) {
    		H=sc.nextInt();
    		W=sc.nextInt();
    		for(int i=0; i<H; i++) {
    			String str=sc.next();
    			for(int j=0; j<str.length(); j++) {
    				visit[i][j]=str.charAt(j)-'0';
    			}
    		}
    		for(int i=0; i<H; i++) {
    			for(int j=0; j<W; j++) {
    				if(i==0 && j==0) {
    					visit[i][j]=visit[i][j];
    				}
    				else if(i==0) {
    					visit[i][j]+=visit[i][j-1];
    				}
    				else if(j==0) {
    					visit[i][j]+=visit[i-1][j];
    				}
    				else {
    					visit[i][j]+=Math.min(visit[i-1][j], visit[i][j-1]);
    				}
    			}
    		}
    		System.out.println(visit[H-1][W-1]);
    	}
    }
}


Measured memory_bytes: 26472
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
// template<class T> T gabs(const T& x) { return max(x, -x); }
// #define abs gabs

#include <complex>

using Complex = complex<double>;


void fft_rec(vector<Complex>& f, int n, int ofs, double sign);

template<class A>
vector<Complex> fft_impl(const A& a, double k) {
    size_t n = 0;
    while ((1 << n) < a.size()) ++n;
    size_t m = 1 << n;
    vector<complex<double>> f(m);
    for (size_t i = 0; i < a.size(); ++i) {
        int rev = 0;
        for (size_t j = 0; j < n; ++j) {
            rev |= ((i >> j) & 1) << (n - j - 1);
        }
        f[rev] = a[i];
    }
    fft_rec(f, n, 0, k);
    if (k == 1) {
        for (size_t i = 0; i < m; ++i) {
            f[i] /= m;
        }
    }
    return f;
}

const double PI = acos(-1);
void fft_rec(vector<Complex>& f, int n, int ofs, double k) {
    int m = 1 << n;
    if (n >= 2) {
        fft_rec(f, n - 1, ofs, k);
        fft_rec(f, n - 1, ofs + (m >> 1), k);
    }
    for (int i = 0; i < (m >> 1); ++i) {
        int j = (m >> 1) + i;
        auto s = exp(k * 2i * PI * double(i) / double(m)),
             t = exp(k * 2i * PI * double(j) / double(m)),
             x = f[ofs + i],
             y = f[ofs + j];
        f[ofs + i] = x + s * y;
        f[ofs + j] = x + t * y;
    }
}

template<class A>
vector<Complex> fft(const A& a) {
    return fft_impl(a, -1);
}

template<class A>
vector<Complex> ifft(const A& a) {
    return fft_impl(a, 1);
}

int main() {
    i64 n, m;
    vector<i64> a;
    cin >> n >> m;
    read_n(a, n);

    vector<i64> c(200001);
    for (i64 x : a) c[x]++;

    auto f = fft(c);
    for (int i = 0; i < f.size(); ++i) {
        f[i] *= f[i];
    }
    auto g = ifft(f);

    i64 ans = 0;
    for (int x = 200000; x > 0; --x) {
        i64 cnt = min(m, i64(round(g[x].real())));
        m -= cnt;
        ans += x * cnt;
    }

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

Measured memory_bytes: 12800
def is_prime(x):
    if x == 1:
        return False
    flag = True
    for i in range(2,int(math.sqrt(x))+1):
        if x%i == 0:
            flag = False

    return flag

import math
X = int(input())

i=0
while 1:
    if is_prime(X+i):
        print(X+i)
        break
    i+=1

Measured memory_bytes: 39024