akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n),b;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        if(i==0)b.push_back(a[i]);
        else{
            if(b.back()==a[i])continue;
            b.push_back(a[i]);
        }
    }
    int res=1;
    bool up=(b[0]<b[1]);
    for(int i=1;i<b.size();i++){
        if((b[i]>b[i-1]&&up)||(b[i]<b[i-1]&&!up))continue;
        res++;
        up=(b[i]<b[i+1]);
    }
    cout<<res<<endl;
}

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

const int INF = 1000000000;
const int INI = 0;
int n, a[101010], b[101010], c[101010], dp[101010][3];

int main(){
  //入力
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  //dp配列の初期化
  rep(i, n) dp[i][0] = dp[i][1] = dp[i][2] = INI;
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  
  //dp本体
  for(int i = 0; i < n - 1; i++){
    //dp[i + 1][後] = max(遷移先, dp[i][前] + 後[i + 1])
    dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1]);
    dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + a[i + 1]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1]);
    dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + b[i + 1]);
    dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1]);
    dp[i + 1][2] = max(dp[i + 1][2], dp[i][1] + c[i + 1]);
  }
  //rep(i, n){cerr << dp[i][0] <<" "<< dp[i][1] <<" "<< dp[i][2] << endl;}
  
  //出力
  int res = dp[n - 1][0];
  res = max(dp[n - 1][1], res);
  res = max(dp[n - 1][2], res);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double b;
    ll a;
    cin>>a>>b;
    ll temp=(b*100)+0.5;
    ll ans=a*temp;
    ans/=100;
    cout<<ans<<"\n";
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
long  double discal(long  double x1,long  double y1,long  double x2, long  double y2)
{
    return pow(pow(x2-x1,2)+pow(y2-y1,2),0.5);
}

 
int main() {
    long long int n,i,j;
    long  double avg,sum=0;
    cin>>n;
    long  double arr[n][2];
    for(i=0;i<n;i++)
    cin>>arr[i][0]>>arr[i][1];
    for(i=0;i<(n-1);i++)
    {
        for(j=i+1;j<n;j++)
        sum+=discal(arr[i][0],arr[i][1],arr[j][0],arr[j][1]);
    }
    avg=(2*sum)/n;
    cout<<fixed<<setprecision(10)<<avg;
    
}
    


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

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    int N; cin >> N;
    vector<pii> R, B;
    rep(i, N) {
        int a, b; cin >> a >> b;
        R.pb(mp(a, b));
    }
    rep(i, N) {
        int c, d; cin >> c >> d;
        B.pb(mp(c, d));
    }
    sort(all(R));
    sort(all(B));

    vector<bool> r(N, false);
    int ans = 0;

    rep(i, N) {
        int c, d; tie(c, d) = B[i];
        int k = -1, maxy = -1;
        rep(j, N) {
            int a, b; tie(a, b) = R[j];
            if (a >= c) break;
            if (b >= d) continue;
            if (r[j]) continue;
            if (b > maxy) {
                k = j;
                maxy = b;
            }
        }
        if (k != -1) {
            ans++;
            r[k] = true;
        }
    }

    cout << ans << endl;

}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
 int n,m;
 cin>>n>>m;
 cout<<n/m+n%m<<endl;
 return 0;   
}

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

int main (){
    int X,N;
    cin >> X >> N;
    vector<int> list(110,0);
    for(int i = 0;i < N;i++)cin >> list.at(i);
    if(N ==0){
        cout << X << endl;
        return 0;
    }
    bool checkm = 1;
    bool checkp = 1;
    int ans = 0;
    
    for(int i = 0; i < 110 ;i++){
        checkm = 1;
        checkp = 1;
        for(int j = 0;j < N;j++){
            if(X - i == list.at(j) ){
                checkm = 0;
                
            }
            if(X + i == list.at(j) ){
                checkp = 0;
                
            }
        }

        if(checkm){
            ans = X - i;
            break;
            }
        else if(checkp){
            ans = X + i;
            break;
            }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3620
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let a: usize = read().unwrap();
    println!("{}", n * n - a);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var inp = RIs;
			if(inp[1] == 100) Out((inp[1] + 1) * (int)Math.Pow(100, inp[0]));
			else Out(inp[1] *(int)Math.Pow(100, inp[0]));
		}
	}
}


Measured memory_bytes: 13396
#!/usr/bin/env python3
def solve(s, MOD=int(1e9 + 7)):
    k = 1
    a = 0
    ab = 0
    abc = 0
    for c in s:
        if c == 'A':
            a += k
        elif c == 'B':
            ab += a
        elif c == 'C':
            abc += ab
        else:
            abc = 3 * abc + ab
            ab = 3 * ab + a
            a = 3 * a + k
            k *= 3
        k, a, ab, abc = map(lambda x: x % MOD, [ k, a, ab, abc ])
    return abc % MOD
print(solve(input()))


Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
bool Is_p(string s){
    for(int i=0;i<s.size();i++){
        if(s[i]!=s[s.size()-i-1]) return 0;
    }
    return 1;
}
string s;
int n;
int main(){
    cin>>s;
    n=s.size();
    //cout<<s.substr(1,n-1);
    if(!Is_p(s)){
        cout<<"No";
        return 0;
    }
    string tmp;
    tmp=s.substr(0,(n-1)/2);
    if(!Is_p(tmp)){
        cout<<"No";
        return 0;
    }
    tmp=s.substr((n+3)/2-1,n);
    if(!Is_p(tmp)){
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}

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

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


int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,s.size()) ans += s[i] -'0';
  cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main()
{
    int A,B,C;
    cin>>A>>B>>C;
    if(A==5&&B==5&&C==7)
    {
        cout<<"YES";
    }
    else if(A==5&&B==7&&C==5)
    {
        cout<<"YES";
    }
    else if(A==7&&B==5&&C==5)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


Measured memory_bytes: 3632
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    int a, b;
    string str;
    cin >> a >> b >> str;
    if (str[a] != '-') {
        cout << "No" << endl;
        return;
    }
    rep(i, a+b+1) {
        if (!isdigit(str[i]) && i != a) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    solve();
	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	RSORT(a);
	map<LL, LL>M;
	LL c = 0;
	LL d = 0;
	FOR(i, 0, N) {
		M[a[i]]++;
		if (M[a[i]] == 2) {
			M[a[i]] = 0;
			if (!c)c = a[i];
			else if (!d)d = a[i];
		}
	}
	LL ans = c*d;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7296
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():

    N, M, K = map(int, input().split())

    uf = UnionFind(N)
    friends = [0 for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        uf.union(a, b)
        friends[a] += 1
        friends[b] += 1

    blocks = [0 for _ in range(N)]
    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c - 1, d - 1
        if uf.same(c, d):
            blocks[c] += 1
            blocks[d] += 1

    for i in range(N - 1):
        ans = uf.size(i) - 1 - friends[i] - blocks[i]
        print(str(ans) + " ", end="")

    ans = uf.size(N - 1) - 1 - friends[N - 1] - blocks[N - 1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 96544
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    string S, T;
    cin >> S >> T;
    T.insert(T.length(), S);
    cout << T << endl; 
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    rep(i,n) cin>>a.at(i);
    int64_t canwaru2=0;
    rep(i,n){
        while(a.at(i)%2==0){
            a.at(i)/=2;
            canwaru2++;
        }
    }
    cout<<canwaru2<<endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    
    const int nmax=50;
    char a[nmax][nmax],b[nmax][nmax];
    
    for(int y=0;y<n;y++){
        for(int x=0;x<n;x++){
            cin >>a[y][x];
        }
    }
    for(int y=0;y<m;y++){
        for(int x=0;x<m;x++){
            cin >>b[y][x];
        }
    }
    
    bool exist=false;
    
    for(int ly=0;ly<n;ly++){
        for(int lx=0;lx<n;lx++){
            if(ly+m-1>=n||lx+m-1>=n) continue;
            
            bool match=true;
            for(int y=0;y<m;y++){
                for(int x=0;x<m;x++){
                    if(a[ly+y][lx+x]!=b[y][x])match=false;
                }
            }
            if(match)exist=true;
        }
    }
    
    if(exist)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
        
    return 0;    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  long long X, A, B;

  cin >> X >> A >> B;

  if(A >= B){
    cout << "delicious" << endl;
  } else if(A+X >= B){
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

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

	ll x, y;
	cin >> x >> y;
	cout << (x % y == 0 ? -1 : x) << endl;
	return 0;
}


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

int main()
{
	int i;
	string s;
	list<char> l;
	list<char>::iterator it;
	getline(cin,s);
	while (getline(cin,s)) {
		l.clear();
		i = 0;
		l.push_back(s[0]);
		it = l.begin();
		while (++i<s.size()) {
			if (s[i++]=='<') {
				if (*(--it)++ != s[++i]) l.insert(it,s[i]);
				it--;
			} else if (s[i]=='>') {
				if (*(++it) != s[++i]) {
					l.insert(it,s[i]);
					it--;
				}
			}
		}
		for (it = l.begin(); it != l.end(); it++) cout<<*it;
		cout<<endl;
	}
	return 0;
}

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

int main() {
    string T; cin >> T;
    rep(i, T.length()) {
        if (T[i] != '?') cout << T[i];
        else cout << 'D';
    }
    cout << endl;
}


Measured memory_bytes: 3728
import heapq
n, m = map(int, input().split())
a = [-int(x) for x in input().split()]
heapq.heapify(a)
for i in range(m):
    x = - heapq.heappop(a)
    x = x//2
    heapq.heappush(a, -x)
print(-sum(a))

Measured memory_bytes: 86324
#include <stdio.h>
#include <string.h>
#include <string>
#include <set>

using namespace std;

void reverse(char str[],int s,int g){
	char tmp;
	for(int i = s;i < s + g - i;i++){
		tmp = str[i];
		str[i] = str[s + g - i];
		str[s + g - i] = tmp;
	}
}

int main(void){
	int i, j, k, l, m, n, sum;
	char str[73], tmp[73];
	scanf("%d%*c",&m);
	for(i = 0;i < m;i++){
		set<string> num;
		gets(str);
		n = strlen(str);
		for(j = 0;j < n - 1;j++){
			for(k = 0;k <= 7;k++){
				strcpy(tmp,str);
				if(1 & k)
					reverse(tmp,0,j); //　上側
				if(2 & k)
					reverse(tmp,j + 1,n - 1); // 下側
				if(4 & k){
					char ttmp[73];
					for(l = 0;l < n;l++)
						ttmp[l] = tmp[(l + j + 1) % n];
					ttmp[n] = '\0';
					strcpy(tmp,ttmp);
				}
				num.insert(tmp);
			}
		}
		printf("%d\n",num.size());
	}
	return 0;
}

Measured memory_bytes: 1152
/*
 *
 */
#include <cstdio>
#include <iostream>
#include <cmath>

#define INF ((ll)1e11 + 5)
typedef long long ll;
using namespace std;

// check whether f(b, n) == s exists or not.
bool check(ll b, ll n, ll s) {
    ll fbn = 0;
    while (n != 0) {
        fbn += n % b;
        n /= b;
    }
    return  fbn == s;
}

int main(){
    //freopen("d5.in", "r", stdin);
    ll n, s;
    cin >> n >> s;

    ll d = n - s;
    if (d < 0) {
        cout << -1 << endl;
    } else if (d == 0) {
        cout << n+1 << endl;
    } else { // n > s
        ll minB = INF;
        ll ub = (ll)sqrt((double) d) + 1LL;
        for (ll i = 1; i <= ub; ++i) {
            if (d % i == 0) {
                if (check(i + 1, n, s)) minB = min(minB, i + 1);
                if (check(d / i + 1, n, s)) minB = min(minB, d / i + 1);
            }
        }
        if (minB == INF) {
            cout << -1 << endl;
        } else {
            cout << minB << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int a, b, c;
  cin >> a >> b >> c;
  long long int x = 4*a*b;
  long long int y = (-a-b+c)*(-a-b+c);
  if(c < a+b){
    cout << "No" << endl;
    return 0;
  }
  if(x < y) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = nextInt(br.readLine()); // 1行目取得
        int[] h = nextIntArray(br.readLine()); // ２行目取得

        int[] dp = new int[N];
        dp[0] = 0;

        for(int i = 1; i < N; i++) {
            execute(i, h, dp);
        }
        System.out.println(dp[N-1]);
    }

    public static void execute(int i, int[] h, int[] dp) {
        if(i == 1) {
            dp[i] = Math.abs(h[i] - h[i-1]);
        } else {
            // i-1 or i-2 の小さい方を dp[i] に入れる
            int a = dp[i-1] + Math.abs(h[i] - h[i-1]);
            int b = dp[i-2] + Math.abs(h[i] - h[i-2]);
            if(a < b) {
                dp[i] = a;
            } else {
                dp[i] = b;
            }
        }
    }

    // 標準入力を文字列で取得
    public static String nextString(String line) {
        return line;
    }
    // 標準入力を文字列の配列で取得
    public static String[] nextStringArray(String line) {
        return line.split(" ");
    }
    // 標準入力を数値で取得
    public static int nextInt(String line) {
        return Integer.parseInt(line);
    }
    // 標準入力を数値の配列で取得
    public static int[] nextIntArray(String line) {
        String[] strArr = line.split(" ");
        int[] intArr = new int[strArr.length];
        for(int i = 0; i < strArr.length; i++) {
            intArr[i] = Integer.parseInt(strArr[i]);
        }
        return intArr;
    }

    // 文字列配列を数値配列に変換
    public static int[] strToInt(String[] s) {
        int[] arr = new int[s.length];
        for(int i = 0; i < s.length; i++) {
            arr[i] = Integer.parseInt(s[i]);
        }
        return arr;
    }
    // 文字列を数値に変換
    public static int strToInt(String s) {
        return Integer.parseInt(s);
    }
}


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

signed main(){
    int n ;
    cin>>n;
    int a,b,c;
    cin>>a>>b>>c;
    for(int i = 1 ; i < n ; i++){
        int tempa,tempb,tempc;
        cin>>tempa>>tempb>>tempc;
        tempa = tempa + max(b,c);
        tempb = tempb + max(a,c);
        tempc = tempc + max(b,a);
        a=tempa;
        b=tempb;
        c= tempc;
    }
    std::cout << max(a,max(b,c)) << std::endl;
	return 0;
}

Measured memory_bytes: 256
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
mod = 10**9+7

if K == 1:
    print(0)
    exit()

comb = Combination(1000000)

maxsum = 0
for i in range(N-1, K-2, -1):
    maxsum += A[i] * (comb(i, K-1) % mod)

minsum = 0
for i in range(N-K+1):
    minsum += A[i] * (comb(N-1-i, K-1) % mod)

print((maxsum - minsum) % mod)


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 2e5 + 41;

int n;
int a[MAX];
ld d[MAX];

void solve() {
	sort(a + 1, a + n * 2 + 1);
	reverse(a + 1, a + n * 2 + 1);
	ld ans = 0;
	fi(1, n * 2) {
		ld p = (ld) (n * 2 - i) / (n * 2 - 1);
		ans += p * a[i];
	}	
	printf("%.15Lf\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d", &n);
  fi(1, n * 2) {
  	scanf("%d", &a[i]);
  }
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   string S;
   cin >> S;
   string S2=S;
   sort(S2.begin(),S2.end());
   int cnt=0;
   for(int i=0;i<N;i++){
      if(S2[i]=='W') break;
      else if(S[i]=='W') cnt++;
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 3916
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c, x, y, i;
    long long ans = 1e18;
    
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
    
    for (i = 0; i <= max(x, y) * 2; i += 2) {
        long long sum = c * i;
        
        if (i / 2 < x) sum += a * (x - i / 2);
        if (i / 2 < y) sum += b * (y - i / 2);
        
        ans = min(ans, sum);
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
n_str = input()
n = int(n_str)
v_str = input().split()
c_str = input().split()
v = []
c = []
for i in range(n):
    v.append(int(v_str[i]))
    c.append(int(c_str[i]))
total = 0
for i in range(n):
    if v[i] > c[i]:
        total += v[i] - c[i]
print(total)

Measured memory_bytes: 3064
import math

def main():
  while True:
    line = input()
    lines = line.split(" ")
    n = int(lines[0])
    d = int(lines[1])
    break
  data = []
  count = 0
  for i in range(n):
    line = input()
    lines = line.split(" ")
    p = int(lines[0])
    q = int(lines[1])
    dist = math.sqrt(p**2+q**2)
    if dist <= d:
      count+=1
  print(str(count))

if __name__ == "__main__":
  main()

Measured memory_bytes: 9116
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		String[] group = {"a","c","a","b","a","b","a","a","b","a","b","a"};
		
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt()-1;
		int y = sc.nextInt()-1;
		
		if(group[x].equals(group[y])){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 19796
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
  int N, D, a;
  cin >> N >> D;
  a = D * 2 + 1;
  cout << (N+a-1) / a << endl;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
  int n,m;
  cin>>n>>m;
  VS s(n,"WA");
  VI cnt(n,0);
  int p,accnt=0,wacnt=0;
  string st;
  rep(i,m){
      cin>>p>>st;
      if(s[p-1]=="WA" && st=="WA"){
          cnt[p-1]++;
      }else if(s[p-1]=="WA" && st=="AC"){
          s[p-1]="AC";
          accnt++;
          wacnt+=cnt[p-1];
      }
  }
  cout<<accnt<<" "<<wacnt<<endl;


}



Measured memory_bytes: 6144
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		double g[100][100];
		rep(i, n) rep(j, n)
			scanf("%lf", &g[i][j]);
		
		double dp[100][100];
		fill(dp[0], dp[0]+n, 1.0);
		reps(i, 1, m){
			rep(j, n){
				dp[i][j] = 0.0;
				rep(k, n)
					dp[i][j] = max(dp[i][j], dp[i-1][k] * g[k][j]);
			}
		}
		
		printf("%.2f\n", *max_element(dp[m-1], dp[m-1]+n));
	}
	return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
 
using namespace std;
 
void AttackSurvival()
{
  int n;
  int k;
  int q;
  cin >> n >> k >> q;
  vector<int> p(n,k);
  for (int i = 0; i < q; i++) 
  {
    int a;
    cin >> a;
    p[a-1] += 1;
  }
  for (int i = 0; i < n; i++)
  {
    if (p[i] - q > 0) cout << "Yes" << endl;
    else  cout << "No" << endl;
  }
}
 
int main()
{ 
  AttackSurvival();
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			// 1???????????\???
			String str = br.readLine();
			// 2???????????\???
			str = br.readLine();
			String[] strs = str.split(" ");

			StringBuilder sb = new StringBuilder();
			for(int i=strs.length -1;i>=0;i--){
				sb.append(strs[i]).append(" ");
			}
			String mes = "";
			if(sb.length()>0){
				mes = sb.substring(0,sb.length()-1);
			}
			System.out.println(mes);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16900
#include <bits/stdc++.h>
long long a,b,c,x,y,t,ans=0;
void swap(long long &x,long long &y)
{
	long long t=x;
	x=y;
	y=t;
}
int main()
{
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
	if (x>y)
	{
		swap(x,y);
		swap(a,b);
	}
	if (c+c<=a+b)
	{
		ans=c*2LL*x;
		y-=x;
		if (y*2LL*c<y*b) ans+=y*2LL*c;
			else ans+=y*b;
	}
	else ans=a*x+b*y;
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

int main(void) {
  string S; cin >> S;

  if (S[2] == S[3] && S[5] == S[4]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(){
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	if(a+b>c+d){
      cout << "Left" << endl;
    }else if(a+b==c+d){
      cout << "Balanced" << endl;
    }else{
      cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
N=int(input())
l=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
l2=[0]*100010
for i in range(1,100010):
  mn=100000000000000000
  for x in l:
    if i-x>=0 and l2[i-x]<mn:
      mn=l2[i-x]+1
  l2[i]=mn
print(l2[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
#define mod 1000000007
#define maxn 100005
int dp[101][maxn];
int32_t main() {
    int n,W;
    cin>>n>>W;
    vi val(n+1),wt(n+1);
    for(int i=1;i<=n;i++)
    cin>>wt[i]>>val[i];
    for(int i=1;i<=n;i++)
    {
        for(int w=1;w<=W;w++)
        {
          if(wt[i]>w)
          dp[i][w]=dp[i-1][w];
          else
          {
            dp[i][w]=max(dp[i-1][w-wt[i]]+val[i],dp[i-1][w]);
          }
          
        }
    }
    cout<<dp[n][W];
    return 0;
}


Measured memory_bytes: 81572
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int f(int a,int b){
	if(a<b)return b;
	else return a;
}
int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n);
	rep(i,n)cin>>a[i];
	int max=0,max2=0;
	rep(i,n){
		if(max<a[i]){
			b[i]=a[i];
			max = a[i];
		}else{
			b[i]=max;
		}
		if(max2<a[n-1-i]){
			max2=a[n-1-i];
		}
		c[n-1-i]=max2;
	}
	cout<<c[1]<<endl;
	for(int i=1;i<n-1;i++){
		cout<<f(b[i-1],c[i+1])<<endl;
	}
	cout<<b[n-2]<<endl;





	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define rep(n) for(int i=0;i<(n);i++)
#define rep1(n) for(int i=1;i<=(n);i++)
#define all(n) n.begin(),n.end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define pb push_back
#define debug(x) cout<<#x<<"="<<x<<'\n'
ll arr[405];
ll pre[405];
ll dp[405][405];
int main(){
    	int n;
    	cin>>n;
    	memset(dp,0x3f,sizeof(dp));
    	for(int i=1;i<=n;i++){
        cin>>arr[i];
        pre[i] = pre[i-1] + arr[i];
    	}
    	for(int i=1;i<=n;i++)dp[i][i] = 0;
    	for(int i=1;i<=n-1;i++){
         dp[i][i+1] = pre[i+1] - pre[i-1];
    	}

    	for(int l=2;l<=n-1;l++){
        for(int i=1;i+l<=n;i++){
           int j = i+l;
           //debug(i);
           //debug(j);
           for(int k=i;k<=j-1;k++){
              dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pre[j]-pre[i-1]);
           }
           //cout<<dp[i][j]<<'\n';
        }
    	}

      cout<<dp[1][n]<<'\n';


}


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

//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

mt19937 rnd(time(0));

#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("lights.in", "r", stdin); freopen("lights.out", "w", stdout);
#define s second
#define f first
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define pii pair<int,int>

const ll INF = 1e18;
constexpr ll mod = 1e9 + 7;

ll x0r(ll x, ll y) { return (x | y) & (~x | ~y); }


void solve() {
    int a,b;
    cin>>a>>b;
    cout<<((a+b-1)/b)<<'\n';
}


signed main() {
    //ioss
    //clock_t time = clock();
    //if ((double) (clock() - time) / CLOCKS_PER_SEC > 0.96) {
    //file
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
vint v;
int foo(int a){
    auto it=lower_bound(ALL(v),a);
    it--;
    return *it;
}
void mainmain(){
    int n;
    int q;
    cin>>n>>q;
    v=vint(n);
    rep(i,n) cin>>v[i];
    sort(ALL(v));
    rep(i,q){
        int a;
        cin>>a;
        int ans=v[0]%a;
        int t=v[0];
        while(1){
            t=t/a*a+a;
            int x=foo(t);
            ans=max(ans,x%a);
            auto it=upper_bound(ALL(v),x);
            if(it==v.end()) break;
            t= *it;
        }
        cout<<ans<<endl;
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 2316
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;
const double eps = DBL_EPSILON;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    ll s = 0;
    vector<int> a(n);
    for (int& i : a) {
        cin >> i;
        s += i;
    }
    sort(all(a), greater<int>());
    for (int i = 0; i < m; i++) {
        if (a[i] * 4 * m < s) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<int> h(102);
int f(int,int);
int main(void)
{
	int ans;
	int n,count=0;
	vector<int> a(501);
	while(1){
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n+1;i++) cin >> h[i];

		for(int i=0;i<n-2;i++){
			if((h[i+3]-h[i+2])-(h[i+1]-h[i])!=0){
				ans=h[f(i,n)];
			}
		}
		a[count]=ans;
		count+=1;
		h.clear();
	}
	for(int i=0;i<count;i++) cout << a[i] << endl;
	return 0;
}
int f(int i,int n)
{
	int c=0,k;
	int a;
	vector<int> dh(102);
	for(int j=i;j<i+4;j++){
		for(k=0;k<n+1;k++){
			if(k==j) continue;
			dh[c]=h[k];
			c++;
		}
		a=dh[1]-dh[0];
		for(k=0;k<c-1&&a==dh[k+1]-dh[k];k++);
		if(k==c-1) return j;
		dh.clear();
		c=0;
	}
	return -1;
}

Measured memory_bytes: 1196
x,n = map(int,input().split())
p_li = list(map(int,input().split()))
p_li.sort()
if p_li.count(x) == 0:
    print(x)
    exit()
dum1 = x-1
dum2 = x+1
for i in range(n):
    if p_li.count(dum1) == 0:
        print(dum1)
        exit()
    if p_li.count(dum2) == 0:
        print(dum2)
        exit()
    dum1 -= 1
    dum2 += 1


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

int c[10][10];

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

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A;
            cin >> A;
            if (A < 0) continue;
            ans += c[A][1];
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++)cin >> p[i];
  sort(p.begin(),p.end());
  cout << p[n/2]-p[n/2-1] << endl;
}

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

int main () {
  int a, b, c, d;
  cin >> a;
  d = a%10;
  c = a%100/10;
  b = a%1000/100;
  a = a/1000;
  if ((a<=0 || a>=10)) {
    cout << "No" << endl;
  }
  else if ((a==b && b==c)||(b==c && c==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = [abs(x) for x in a]
    n = sum(map(lambda x: x < 0, a))

    # print(n)
    if n%2==0:
        print(sum(b))
    else:
        print(sum(b) - min(b)*2)


if __name__ == '__main__':
    main()

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

using namespace std;

int a;
int main(){
  int n; scanf("%d", &n); int cont = 0;
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    while(a%2==0){ a = a/2; cont++;}
  }
  printf("%d", cont);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>         // abs
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = min(a, b); i >= 1; i--) {
		if (a % i == 0 && b % i == 0) {
			k--;
			if (k == 0) {
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for i in range(N)]
import numpy as np
dp=np.zeros(W+1,dtype=np.int64)
for w,v in WV:
    dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
print(max(dp))

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
    string s; cin >> s;
    unordered_map<char, ll> m;
    modint res = 1;
    rep(i, s.size()){
        m[s[i]]++;
    }
    for(auto p: m){
        res = res*modint(p.second+1);
    }
    res = res - modint(1);

    cout << res.n << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4608