akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int n;
	cin >> n;
	n %= 10;
	if(n == 3)
		cout << "bon\n";
	else if(n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon\n";
	else
		cout << "hon\n";
	
	
	return 0;
}






Measured memory_bytes: 3644
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return (x * y) // gcd(x, y)

n = int(input())
A = [int(i) for i in input().split()]
copyA = A.copy()

for i in range(n - 1):
    A[i + 1] = lcm(A[i], A[i + 1])
    
m = A[-1] - 1
ans = 0
for i in range(n):
    ans += m % copyA[i]
    
print(ans)

Measured memory_bytes: 13172
/*This is the solution from Ling2Feng1, no matter AC or not.*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>
using namespace std;
int n,k,ans;
int a[200032],num[200032];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		num[a[i]]++;
	}
	sort(num+1,num+n+1);
	reverse(num+1,num+n+1);
	for(int i=1;i<=k;i++) ans+=num[i];
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
// Shift-JIS（シフトジス）

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

int N;
vector<long long> A(100000);
vector<long long> memoL(100000);
vector<long long> memoR(100000);

int gcd(int m, int n)
{
    if (n == 0)
        return abs(m);
    return gcd(n, m % n);
}

int L(int i)
{
    if (i == 0)
        return 0;
    if (memoL[i] != 0)
        return memoL[i];
    return memoL[i] = gcd(L(i - 1), A[i - 1]);
}

int R(int i)
{
    if (i == N + 1)
        return 0;
    if (memoR[i] != 0)
        return memoR[i];
    return memoR[i] = gcd(R(i + 1), A[i]);
}

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int ans = 0, M;

    for (int i = 0; i < N; i++)
    {
        M = gcd(L(i), R(i + 1));
        if (ans < M)
            ans = M;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5760
N,X,Y = gets.split.map(&:to_i)

z = Y-X-1
x,z1,z2,y = X,(z+1)/2,z/2,N-Y+1

L = lambda{|n| lambda{|k| [0,n-k].max } }
C = lambda{|n| lambda{|k| 2*k<n ? n-4 : 2*k==n ? k-2 : 0 } }

plus = [L[x+y],C[z+2],L[x+z1],L[x+1+z2],L[z2+1+y],L[z1+y]]
minus = [L[x],L[z1],L[x+1],L[1+z2],L[z2+1],L[1+y],L[z1],L[y]]

p N
puts (2...N).map{|k|
	plus.sum{|f|f[k]} - minus.sum{|f|f[k]}
}


Measured memory_bytes: 14388
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
  long long x = a*b;
  
  if(a<b){
    long long tmp = a;
    a = b;
    b = tmp;
  }
  
  long long r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  return x/b;
}


int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long lcm = gcd(c,d);
  
  if(c == 1 || d == 1){
    cout << 0 << endl;
    return 0;
  }
  
  long long b_c,b_d,b_cd,a_c,a_d,a_cd;
  a_c = (a-1)/c;
  a_d = (a-1)/d;
  a_cd = (a-1)/lcm;
  b_c = (b/c)-a_c;
  b_d = (b/d)-a_d;
  b_cd = (b/lcm)-a_cd;
  long long count = (b-a+1) - b_c - b_d + b_cd;
  cout << count << endl;
 
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
        PriorityQueue<Integer> sizes = new PriorityQueue(Collections.reverseOrder());
              
        for(int i = 0; i < n; i++) {
          sizes.add(Integer.parseInt(sc.next()));
        }
        
        int ans = 0;
        for(int i = 0; i < k; i++) {
          ans += sizes.poll();
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

struct Pos {
    int x, y;
    constexpr Pos() : Pos(0, 0) {}
    explicit constexpr Pos(int x, int y) : x(x), y(y) {}
};
constexpr bool operator==(const Pos& a, const Pos& b) { return a.x == b.x && a.y == b.y; }
constexpr bool operator!=(const Pos& a, const Pos& b) { return !(a == b); }
constexpr Pos operator+(const Pos & a, const Pos & b) { return Pos(a.x + b.x, a.y + b.y); }

int main() {

    int H, W;
    std::cin >> H >> W;

    std::queue<Pos> q;
    const std::array<Pos, 4> Dir = { { Pos(0,1),Pos(1,0),Pos(0,-1),Pos(-1,0) } };

    std::vector<std::vector<char>> A(H, std::vector<char>(W));
    for (auto& row : A)for (auto& elem : row)std::cin >> elem;

    std::vector<std::vector<int>> memo(H, std::vector<int>(W, 3000));

    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
            if (A[h][w] == '#') {
                memo[h][w] = 0;
                q.emplace(w, h);
            }
        }
    }

    while (!q.empty()) {
        Pos now = q.front();
        q.pop();
        for (auto& dir : Dir) {
            Pos next = now + dir;
            if (next.x < 0 || W <= next.x || next.y < 0 || H <= next.y)continue;
            if (memo[now.y][now.x] + 1 < memo[next.y][next.x]) {
                memo[next.y][next.x] = memo[now.y][now.x] + 1;
                q.push(next);
            }
        }
    }

    int ans = -1;
    for (auto& row : memo)
        for (auto& elem : row)
            ans = std::max(ans, elem);

    std::cout << ans << std::endl;
}

Measured memory_bytes: 13456
// Hint: Don't look, No need, Let'em Play.

#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    string s[4] = {"AC", "WA", "TLE", "RE"};
    map<string,int> mp;
    for (auto &it: s) mp[it];
    int n;
    cin >> n;
    while (n--) {
        string ok;
        cin >> ok;
        mp[ok]++;
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
}

signed main() {
    fast;
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int h, w;
    cin >> h >> w;
    int a, b;
    cin >> a >> b;
    int ans[1010][1010] = {};

    rep(i, h) rep(j, w) {
        if ((i >= b && j < a) || (i < b && j >= a)) ans[i][j] = 1;
    }

    rep(i, h) {

        rep(j, w) {
            cout << ans[i][j];
        }
        cout << endl;
    }



    return 0;
}


Measured memory_bytes: 5248
//Md. Shajibul Islam..
//East West University, CSE Department'19

#include<bits/stdc++.h>
using namespace std;
#define FAST       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i,n)        for(int i=0;i<n;i++)
#define CASE_PRINT       cout<<"Case "<<C<<": "
#define ll               long long
#define ld               long double
#define Pi               2*acos(0.0) // acos(-1.0)

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

   int ac=0,tle=0,wa=0,re=0;

    while(n--)
    {
        string s;cin>>s;

        if(s=="AC")ac++;
        if(s=="TLE")tle++;
        if(s=="WA")wa++;
        if(s=="RE")re++;
    }

        cout<<"AC x "<<ac<<endl;
        cout<<"WA x "<<wa<<endl;
        cout<<"TLE x "<<tle<<endl;
        cout<<"RE x "<<re<<endl;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int pr(int a){
    if(a==2) return 1;
    if(a==1||a%2==0){
        return 0;
    }
    for(int i=3;i<=sqrt(a);i+=2){
        if(a%i==0) return 0;
    }
    return 1;
}
int main(){
    int x,co=0;
    cin>>x;
    int y[x];
    for(int i=0;i<x;i++) cin>>y[i];
    for(int i=0;i<x;i++){
        co+=pr(y[i]);
    }
    cout<<co<<endl;
}



Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
//#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int s, w;
	cin >> s >> w;
	if (s <= w)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}


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

int main(){
  vector<tuple<int,int,int>> mp;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int c,s,f;
    cin >> c>>s>>f;
    mp.push_back(make_tuple(c,s,f));
  }
  for(int j=0;j<n-1;j++){
    int t=0;
  	for(int i=j;i<n-1;i++){
    	int x,y,z;
    	tie(x,y,z)=mp[i];
  		if(y-t>0)
    		t += y-t+x;
  		else if(t%z==0)
    		t += x;
        else
            t += z-t%z+x;
  	}
    cout << t << endl;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

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

	vector<int> H(n);
	for (int i = 0; i < n; i++)
		cin >> H[i];
	sort(all(H));

	int ans = 1001001001;
	for (int i = 0; i+k-1 < n; i++)
	{
		int dif = H[i+k-1] - H[i];
		ans = min(ans, dif);
	}
	cout << ans << endl;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;

const int mod = 1e9+7;
const int oo = 1e9+7;

vector<string> split(const string &);


int main() {
    
    vi antennas(5);
    for(int i = 0; i < 5; ++i) scanf("%d",&antennas[i]);
    int k; scanf("%d",&k);
    
    //sort(antennas.begin(), antennas.end());
    
    if(antennas[4]-antennas[0] <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    return 0;
}




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

int main(){
  int N, A, j, count_a=0, count_min=0;
  cin >> N;
  for (int i=0; i<N-1; i++){
    cin >> A;
    j = A;
    count_a = 0;
    while (j%2 == 0){
      count_a++;
      j /= 2;      
    }
    if ( i==0 ) count_min = count_a;
    if (count_a <= count_min) count_min = count_a;
  }
  cout << count_min << endl;
}


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

using namespace std;

string s;

int main() {
  cin >> s;
  int sol = 0;
  char last_char = '\0';
  bool last_two = false;
  for (int i = 0; i < s.size(); i++) {
    if (last_two) {
      sol++;
      last_char = s[i];
      last_two = false;
    } else {
      if (s[i] == last_char) {
        if (i < s.size() - 1) {
          sol++;
          last_two = true;
        }
        i++;
      } else {
        sol++;
        last_char = s[i];
        last_two = false;
      }
    }
  }
  cout << sol << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j;
    double a,b;
    while(1){
        double x = 0;
        double y = 0;
        a = 0;
        b = 0;
        cin >> n;
        if(n==0)break;
        int s[n];
        for(i=0;i<n;i++){
            s[i] = 0;
        }
        for(i=0;i<n;i++){
            cin >> s[i];
        }
        for(j=0;j<n;j++){
            x += s[j];
            y += s[j]*s[j];
        }
        a = (double)x/(double)n;
        b = (double)y/(double)n;
        cout << fixed << setprecision(10) << sqrt(b-(a*a)) << endl;
        
    }
    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;
typedef pair<Point, double> Circle;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

namespace std{
    bool operator<(const Point &a, const Point &b){
        return !equals(a.X, b.X) ? a.X < b.X : a.Y < b.Y;
    }
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

double arg(Vector p){
    return atan2(p.Y, p.X);
}

Vector polar(double a, double r){
    return Point(cos(r) * a, sin(r) * a);
}

pair<Point, Point> getCrossPoints(Circle c1, Circle c2){
    double d = abs(c1.first - c2.first);
    double a = acos((c1.second * c1.second + d * d - c2.second * c2.second) / (2 * c1.second * d));
    double t = arg(c2.first - c1.first);
    return make_pair(c1.first + polar(c1.second, t + a), c1.first + polar(c1.second, t - a));
}

pair<Point, Point> getTangents(Circle c1, Point p1){
    Circle c2 = Circle(p1, sqrt(norm(c1.first - p1) - c1.second * c1.second));
    pair<Point, Point> p2 = getCrossPoints(c1, c2);
    if(p2.second < p2.first) swap(p2.first, p2.second);
    return p2;
}

int main(){
    double px, py; cin>>px>>py;
    Point p1 = {px, py};
    double cx, cy, r; cin>>cx>>cy>>r;
    Circle c1 = {Point(cx, cy), r};

    pair<Point, Point> p = getTangents(c1, p1);
    printf("%.10f %.10f\n%.10f %.10f", p.first.X, p.first.Y, p.second.X, p.second.Y);
}


Measured memory_bytes: 3692
N, Y = map(int,input().split())
yukichi,ichiyou,hideyo=-1,-1,-1
N_next,N_2next,Y_next,Y_2next=-1,-1,-1,-1

for i in range(N+1):
    flag = 0
    yukichi = N-i
    N_next = N - yukichi
    Y_next = Y-10000*yukichi
    if Y_next == 0 and N_next==0:
        flag = 1
        ichiyou,hideyo=0,0
    elif Y_next > 0 and N_next>0:
        for j in range(N_next+1):
            ichiyou = N_next-j
            N_2next = N_next - ichiyou
            Y_2next = Y_next-5000*ichiyou
            if Y_2next == 0 and N_2next==0:
                flag=1
                hideyo=0
                break
            elif Y_2next > 0 and N_2next>0:
                hideyo = N_2next
                Y_remain = Y_2next - 1000*hideyo
                if Y_remain == 0:
                    flag=1
                    break
    if flag == 1:
        break
    yukichi,ichiyou,hideyo=-1,-1,-1
print('%d %d %d' %(yukichi,ichiyou,hideyo))

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

int main(){
  char c; cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel";
  }
  else {
    cout << "consonant";
  }
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner("9 ..##..###");
		int n = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		String str = sc.next();
		char c[] = str.toCharArray();
		PrintWriter out = new PrintWriter(System.out);
		int numofb = 0;
		for (int i = 0; i < n; i++)
		{
			if(c[i]=='#')
			{
				numofb++;
			}
		}
		int numofw=n-numofb;
		int ans;
		if(numofw < numofb)
		{
			ans = numofw;
		}
		else
		{
			ans = numofb;
		}
		int lsb =0;
		int rsw =numofw;
		for (int i = 0; i < n-1; i++)
		{
			if(c[i]=='#')
			{
				lsb=lsb+1;
				rsw=rsw+0;
			}
			else
			{
				lsb=lsb+0;
				rsw=rsw-1;
			}
			if(ans > lsb+rsw)
			{
				ans = lsb+rsw;
			}
		}

		out.println(ans);
		//out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 29576
k, a, b = map(int, input().split())
biscuits = 1
if a + 2 >= b:
    #全てビスケットでいい
    print(1 + k)
else:
    #お金に交換する方がいい
    ans = 0
    change = 0
    if k >= a+1:
        ans += b
        k -= a + 1
    else:
        print(1+k)
        exit()
    change = max(0, k//2)
    ans += change * (b - a) + (k % 2)
    print(ans)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long a,b[100005],c[100005],ans,mins,maxs,YN,anss;
int main()
{
	cin>>a;
	for(int s=0;s<a;s++)
	{
		cin>>b[s];
	}
	sort(b,b+a);
	maxs=a-1;
	if(a%2==1)
	{
		c[a/2]=b[0];mins=1,YN=1;
		for(int s=a/2-1,k=a/2+1;s>=0;s--,k++)
		{
			if(YN==1)c[s]=b[maxs--],c[k]=b[maxs--];
			else c[s]=b[mins++],c[k]=b[mins++];
			YN=!YN;
		}
		for(int s=1;s<a;s++)
		{
			ans=ans+abs(c[s]-c[s-1]);
		}
		c[a/2]=b[a-1];mins=0,maxs=a-2,YN=0;
		for(int s=a/2-1,k=a/2+1;s>=0;s--,k++)
		{
			if(YN==1)c[s]=b[maxs--],c[k]=b[maxs--];
			else c[s]=b[mins++],c[k]=b[mins++];
			YN=!YN;
		}
		for(int s=1;s<a;s++)
		{
			anss=anss+abs(c[s]-c[s-1]);
		}
		ans=max(anss,ans);
	}
	else
	{
		for(int s=a/2-1,k=a/2;s>=0;s--,k++)
		{
			if(YN==1)c[s]=b[maxs--],c[k]=b[mins++];
			else c[s]=b[mins++],c[k]=b[maxs--];
			YN=!YN;
		}
		for(int s=1;s<a;s++)
		{
			ans=ans+abs(c[s]-c[s-1]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  int c = 0;
  V<string> s(n);
  for (auto&& e : s) {
    cin >> e;
    c += count(begin(e), end(e), '#');
  }
  if (!c) return cout << -1 << '\n', 0;
  int res = 0;
  int mn = 1e9;
  for (int j = 0; j < n; ++j) {
    c = 0;
    for (int i = 0; i < n; ++i) c += s[i][j] == '#';
    res += c < n;
    if (c) {
      mn = min<int>(mn, count(begin(s[j]), end(s[j]), '.'));
    }
    mn = min<int>(mn, count(begin(s[j]), end(s[j]), '.') + 1);
  }
  res += mn;
  cout << res << '\n';
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <list>
#include <map>

using namespace std;
#define lf double
#define ll long long int
#define map unordered_map
#define f(i, n) for (ll i = 0; i < n; i++)

ll s(string c)
{
    f(i, c.length())
    {
        if ((i + 1) % 2 == 0 && c[i] == 'R')
            return 0;
        if ((i + 1) % 2 != 0 && c[i] == 'L')
            return 0;
    }
    return 1;
}

int main()
{
    // ios::ios_base::sync_with_stdio(0);
    // ll tc;
    // cin >> tc;

    string c;
    cin >> c;
    printf("%s", s(c) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,t,c=0;
    cin >> n;
    t=n;
    while(t>0){
        c+=t%10;
        t/=10;
    }
    if(n%c==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
a = A*12.5
b = B*10
c = max(a, b)//1

for i in range(10):
  if ((c+i)*0.08)//1 == A and ((c+i)*0.1)//1 == B:
    print(int(c+i))
    exit()

print(-1)

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


using namespace std;


using ll = long long;


mt19937 mt(736);


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	ll k;

	cin >> n >> k;

	vector<int> arr(n);

	for (auto &it : arr)
	{
		cin >> it;
		it--;
	}

	vector<vector<int>> pos((int) 2e5);

	for (int i = 0; i < arr.size(); i++)
		pos[arr[i]].push_back(i);

	int curr = 0, p = 0;

	do
	{
		auto nxt = lower_bound(pos[arr[p]].begin(), pos[arr[p]].end(), p);

		if (++nxt == pos[arr[p]].end())
		{
			nxt = pos[arr[p]].begin();
			curr++;
		}

		auto np = *nxt + 1;

		if (np == n)
		{
			np = 0;
			curr++;
		}

		if (curr >= k)
			break;
		p = np;
	} while (p != 0);

	if (p == 0 && curr < k)
		k %= curr;

	curr = 0;
	p = 0;

	do
	{
		auto nxt = lower_bound(pos[arr[p]].begin(), pos[arr[p]].end(), p);

		if (++nxt == pos[arr[p]].end())
		{
			nxt = pos[arr[p]].begin();
			curr++;
		}

		auto np = *nxt + 1;

		if (np == n)
		{
			np = 0;
			curr++;
		}

		if (curr >= k)
			break;
		p = np;
	} while (p != 0);


	vector<bool> used((int) 2e5);
	vector<int> s;

	for (int i = p; i < n; i++)
	{
		auto it = arr[i];

		if (used[it])
		{
			while (used[it])
			{
				used[s.back()] = false;
				s.pop_back();
			}
		}
		else
		{
			used[it] = true;
			s.push_back(it);
		}
	}

	for (auto it : s)
		cout << it + 1 << ' ';
	cout << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << setprecision(4) << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 14200
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()
N = len(S) + 1

ans = np.zeros(N,dtype=int)
cnt = 0
for i, c in enumerate(S, start=1):
    if c == '<':
        cnt += 1
    else:
        cnt = 0
    ans[i] = cnt
for i, c in enumerate(S[::-1], start=1):
    if c == '>':
        cnt += 1
    else:
        cnt = 0
    ans[~i] = max(cnt, ans[~i])
print(ans.sum())


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

using namespace std;
const long long MOD=1e9+7;
long long n, k;

long long calc_sm(long long i){
  return (i*(i+1)/2)%MOD;
}

long long calc(int i){
  return (calc_sm(n) - calc_sm(n-i) - calc_sm(i-1)+1 + MOD) %MOD;
}

int main(){
  cin >> n >> k;
  long long sm=0;
  for(int i=k;i<=n+1;i++){
    sm = (sm + calc(i)) %MOD;
  }
  cout << sm << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	set<string>memo;
	string w;
	cin>>w;
	char last=w[w.size()-1];
	memo.insert(w);
	int f=1;
	for (int i = 1; i < n; ++i)
	{
		cin>>w;
		if (last!=w[0])
		{
			f=0;
		}
		last=w[w.size()-1];
		if (memo.count(w)>0)
		{
			f=0;
		}
		memo.insert(w);
	}
	if (f)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
<?php
$n = int();
for($i = 0; $i < $n; $i++){
    fscanf(STDIN,"%s%d", $a[], $b[]);
}
$str = str();
$sum = 0;
$flag = false;
for($i = 0; $i < $n; $i++){
    if($flag)$sum+=$b[$i];
    if($a[$i] == $str)$flag = true;
}
echo $sum;

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 4728
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  double ans=0;
  rep(i,n) ans+=(double)1/v[i];
  cout<<setprecision(10)<<(double)1/ans<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,a,b,ans=0,c[1000]={};
  cin >> n >> a >> b;
  for(int i=0; i<n; i++) {
    cin >> c[i];
    if(a>c[i]||c[i]>=b) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , k;

int main() {
    fast_io;

    cin >> n >> k;
    if(k > (n - 1) * (n - 2) / 2)   return cout << -1 << endl , 0;

    k = (n - 1) * (n - 2) / 2 - k;
    cout << k + n - 1 << endl;
    for(ll i = 2 ; i <= n ; i++)    cout << 1 << sep << i << endl;

    for(ll i = 2 ; i <= n ; i++){
        for(ll j = i + 1 ; j <= n ; j++){
            if(k == 0) break;
            cout << i << sep << j << endl;
            k--;
        }
    }

    return 0;
}
/*

*/


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

int bubbleSort(int X[], int Y){
  int cn = 0;
  bool num =1;
  int i,j;

  for(i=0;num; i++){
    num =0;
    for(j=Y-1;j>=i+1;j--){
      if(X[j]<X[j-1]){
	swap(X[j],X[j-1]);
	num = 1;
	cn++;
      }
    }
  }
  return cn;
}

int main(){
  int deta[100],N,cn;
  int i;
  cin >> N;

  for(i=0;i<N;i++){
    cin >> deta[i];
  }
  cn = bubbleSort(deta,N);


  for(i=0;i<N;i++){
    if(i) {
      cout<<" ";
    }
    cout << deta[i];
  }
    cout << endl;
    cout << cn <<endl;

    return 0;
  }



Measured memory_bytes: 3112
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 1000000007;

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> v(n);
  cin >> v;
  vector<int> ways(n + 1);
  ways[0] = 3;
  int ans = 1;
  for (int x : v) {
    ans = ans * (ll)ways[x] % P;
    ways[x] = (ways[x] + P - 1) % P;
    ways[x + 1] = (ways[x + 1] + 1) % P;
  }
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

int binary_search(std::vector<int> &S, int n)
{
  int l = 0, r = S.size();
  int c;
  // ^^ (l,r] de tansaku

  while (l < r)
  {
    c = (l + r )/2;
    if( n == S[c] )
      return true;
    else if( n < S[c] )
      r = c;
    else 
      l = c+1;
  }

  return false;
}

int main()
{
  
  int ans = 0;
  
  int n;
  std::cin >> n;
  std::vector<int> S( n );
  for( auto &si : S ){
    std::cin >> si;
  }
  
  int q, qi;
  std::cin >> q;  
  for( int i = 0; i < q; i++ ){
    std::cin >> qi;
    ans += binary_search( S, qi );
  }

  std::cout << ans << std::endl;

  return 0;
}


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

int main(){
    int n,ans=40;
    scanf("%d",&n);
    for(int i = 0;i < n;i ++){
        int a,x=0;
        scanf("%d",&a);
        while(a%2==0){
            x ++;
            a /= 2;
        }
        ans = ans<x?ans:x;
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

string S, T;

bool str_check(int si, int ti, int count) {
    if(count==T.size()) return true;
    
    if(S[si]==T[ti] || S[si]=='?') {
        return str_check(si+1, ti+1, count+1);
    } else {
        return false;
    }
}

int main() {
    cin >> S >> T;
    
    vector<string> T_ins;
    for(int s=0; s<S.size(); s++) {
        if(str_check(s, 0, 0)) {
            string prevT=S.substr(0, s);
            for(int p=0; p<prevT.size(); p++) {
                if(prevT[p]=='?') prevT[p]='a';
            }
            string nextT=S.substr(s+T.size(), S.size()-(s+T.size()));
            for(int n=0; n<nextT.size(); n++) {
                if(nextT[n]=='?') nextT[n]='a';
            }
            T_ins.push_back(prevT+T+nextT);
        }
    }

    // for(int i=0; i<T_ins.size(); i++) {
    //     cout << T_ins[i] << endl;
    // }

    if(!T_ins.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    
    sort(T_ins.begin(), T_ins.end());
    
    cout << T_ins[0] << endl;
    
    return 0;
    
}

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

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

using namespace std;

int main() {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long long int a_ans, b_ans, c_ans, d_ans, e_ans, f_ans;
    long long int a_amari, b_amari, c_amari, d_amari, e_amari, f_amari;
    long long int a_count, b_count, c_count, d_count, e_count, f_count;

    long long int temp;
    long long int temp_c = c, temp_d = d;
    if (temp_c < temp_d) {
        temp = temp_c;
        temp_c = temp_d;
        temp_d = temp;
    }
    long long int r;
    r = temp_c % temp_d;
    while (r!=0)
    {
        temp_c = temp_d;
        temp_d = r;
        r = temp_c % temp_d;
    }
    //cout << c*d/temp_d << "\n";


    a_ans = a / c;
    b_ans = b / c;
    c_ans = a / d;
    d_ans = b / d;
    e_ans = a / (c * d / temp_d);
    f_ans = b / (c * d / temp_d);

    a_amari = a % c;
    b_amari = b % c;
    c_amari = a % d;
    d_amari = b % d;
    e_amari = a % (c * d / temp_d);
    f_amari = b % (c * d / temp_d);

    if (a_amari != 0)a_count = a_ans + 1;
    else a_count = a_ans;
    if (c_amari != 0)c_count = c_ans + 1;
    else c_count = c_ans;
    if (e_amari != 0)e_count = e_ans + 1;
    else e_count = e_ans;

    b_count = b_ans;
    d_count = d_ans;
    f_count = f_ans;


    long long int ans;
    ans = (b - a + 1) - ((b_count - a_count + 1) + (d_count - c_count + 1) - (f_count - e_count + 1));

    cout << ans;
    


    return 0;
}

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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=1e5 +10, M=(ll)1e9+1 ;
const int mod =(ll)998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";



void work(){
	ll n,m;
	cin >> n >> m;
	vl a(n);
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}

	sort(a.rbegin(),a.rend());
	for(ll i=0;i<m;i++){
		if(4*m*a[i]<sum){
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
	return;
}

int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	}
return 0;
}


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

#define mod 1000000007

const int N=100005;
int cache[N];
int h[N];
int n,k;

int dp(int n)
{
    if(n==0)
        return 0;
    if(n<0)
        return 1e8;
    if(cache[n]!=-1)
        return cache[n];
    else
    {
        int s=1e9;
        for(int i=1;i<=k;i++)
        {
            cache[n]=min(abs(h[n]-h[n-i])+dp(n-i),s);
            s=cache[n];
        }
        return cache[n];
    }
}

signed main()
{
    memset(cache,-1,sizeof(cache));

    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>h[i];
    cout<<dp(n-1)<<endl;

    return 0;
}

Measured memory_bytes: 7808
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

//Book Index
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, List<Integer>> ref = new HashMap<String, List<Integer>>();
		PriorityQueue<String> q = new PriorityQueue<String>();
		while(sc.hasNext()){
			String s = sc.next();
			if(ref.containsKey(s)){
				ref.get(s).add(sc.nextInt());
			}
			else{
				q.add(s);
				List<Integer> list = new ArrayList<Integer>();
				list.add(sc.nextInt());
				ref.put(s, list);
			}
		}
		while(!q.isEmpty()){
			String s = q.poll();
			List<Integer> list = ref.get(s);
			System.out.println(s);
			Collections.sort(list);
			boolean f = true;
			for(int v:list){
				if(!f)System.out.print(" ");
				f = false;
				System.out.print(v);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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; }

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

signed main(){
  int n;
  cin >> n;
  map<ll, ll> mll;
  rep(i,n){
    int a;
    cin >> a;
    mll[a]++;
  }
  ll ans = 0;
  ll now = 0;
  for (auto itr = mll.begin(); itr != mll.end(); itr++){
    // cout << (itr->first) << " " << (itr->second) << endl;
    if(itr == mll.begin()){
      now = (itr->first) * (itr->second);
      ans += itr->second;
    }else{
      if(now*2 >= (itr->first)){
        now += (itr->first) * (itr->second);
        ans += itr->second;
      }else{
        now += (itr->first) * (itr->second);
        ans = itr->second;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9840
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
 
#define N  100005

signed main()
{
      int n,k;
      cin>>n>>k;
      int arr[n];
      int i,j;
      int sum=0;
      for(i=0;i<=n-1;i++)
      {
      	  cin>>arr[i];
	  }
	  sort(arr,arr+n);
	  reverse(arr,arr+n);
	  for(i=k;i<=n-1;i++)
	  {
	  	sum+=arr[i];
	  }
	  cout<<sum<<endl;
}

Measured memory_bytes: 1920
from operator import add
from functools import reduce

k, n = map(int, input().split(' '))
aa = list(map(int, input().split(' ')))

dists = [aa[0] + k - aa[-1]]
for i in range(1, len(aa)):
    dists.append(aa[i] - aa[i - 1])

print(k - max(dists))


Measured memory_bytes: 26920
MINE = '#'
SPACE = '.'

h, w = gets.chomp.split(' ').map(&:to_i)
board = h.times.map { gets.chomp.chars }

def neighbors(board, i, j, h, w)
  max_h = h - 1
  max_w = w - 1
  [-1, 0, 1].map do |x|
    ix = i + x
    next if ix < 0 || ix > max_h
    [-1, 0, 1].map do |y|
      jy = j + y
      next if jy < 0 || jy > max_w
      board.fetch(ix, [])[j + y]
    end
  end.flatten
end

0.upto(h - 1).each do |i|
  0.upto(w - 1).each do |j|
    next if board[i][j] == MINE
    board[i][j] = neighbors(board, i, j, h, w).count(MINE)
  end
end

board.each do |line|
  puts line.join
end


Measured memory_bytes: 2300
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <bitset>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

struct PT {
	typedef long long T;
	T x, y;
	PT(T _x = 0, T _y = 0) : x(_x), y(_y){}
	PT operator +(const PT &p) const { return PT(x+p.x,y+p.y); }
	PT operator -(const PT &p) const { return PT(x-p.x,y-p.y); }
	PT operator *(T c)         const { return PT(x*c,y*c);     }
	T operator *(const PT &p)  const { return x*p.x+y*p.y;     }
	T operator %(const PT &p)  const { return x*p.y-y*p.x;     }
	//double operator !()        const { return sqrt(x*x+y*y);   }
	//double operator ^(const PT &p) const { return atan2(*this%p, *this*p);}
	bool operator < (const PT &p) const { return x != p.x ? x < p.x : y < p.y; }
	bool operator == (const PT &p)const { return x == p.x && y == p.y; }

	friend std::ostream& operator << (std::ostream &os, PT &p) {
		return os << p.x << ' ' << p.y;
	}
	friend std::istream& operator >> (std::istream &is, PT &p) {
		return is >> p.x >> p.y;
	}
};


int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	const int ms = 3030;
	auto go = [&](int a, int b) {
		std::bitset<ms> ans;
		ans[0] = 1;
		for(int i = a; i < ms; i++) {
			ans[i] = ans[i] || ans[i-a];
		}
		for(int i = b; i < ms; i++) {
			ans[i] = ans[i] || ans[i-b];
		}
		return ans;
	};
	int a, b, c, d, e, f;
	std::cin >> a >> b >> c >> d >> e >> f;
	auto water = go(a, b);
	auto sugar = go(c, d);
	PT ans(100*a, 0);
	for(int i = 1; i * 100 <= f; i++) {
		for(int j = 1; i * 100 + j <= f && e * i >= j; j++) {
			if(water[i] && sugar[j]) {
				PT cur(100 * i, j);
				if(cur % ans < 0) ans = cur;
			}
		}
	}
	ans.x += ans.y;
	std::cout << ans << '\n';
}

Measured memory_bytes: 256