akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int h,w;cin>>h>>w;
    vstr s(h);
    rep(i,h)cin>>s[i];

    int res=0;
    vvint l(h,vint(w,0)),r(h,vint(w,0)),u(h,vint(w,0)),d(h,vint(w,0));

    //l
    rep(i,h) l[i][0]=(s[i][0]=='#'?0:1);
    rep(i,h){
        range(j,1,w){
            if(s[i][j]=='#') l[i][j]=0;
            else l[i][j]=l[i][j-1]+1;
        }
    }

    //r
    rep(i,h) r[i][w-1]=(s[i][w-1]=='#'?0:1);
    rep(i,h){
        for(int j=w-2; j>=0; j--){
            if(s[i][j]=='#') r[i][j]=0;
            else r[i][j]=r[i][j+1]+1;
        }
    }


    //u
    rep(i,w) u[0][i]=(s[0][i]=='#'?0:1);
    rep(i,w){
        for(int j=1; j<h; j++){
            if(s[j][i]=='#') u[j][i]=0;
            else u[j][i]=u[j-1][i]+1;
        }
    }
    
    //d
    rep(i,w) d[h-1][i]=(s[h-1][i]=='#'?0:1);
    rep(i,w){
        for(int j=h-2; j>=0; j--){
            if(s[j][i]=='#') d[j][i]=0;
            else d[j][i]=d[j+1][i]+1;
        }
    }

    // rep(i,h){
    //     rep(j,w){
    //         cout<<d[i][j];
    //     }
    //     cout<<endl;
    // }

    rep(i,h){
        rep(j,w){
            int tmp=0;
            if(s[i][j]=='.'){
                tmp=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3;
                chmax(res,tmp);
            }
        }
    }
    cout<<res<<endl;
}

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

using namespace std;

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

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 3000;

ld memo[N][N];

int n;
ld arr[N];

ld solve(int idx, int head)
{
	if (idx == n)
		return head > (n / 2);

	ld &ret = memo[idx][head];
	if (ret == ret)
		return ret;

	return ret = solve(idx + 1, head + 1) * arr[idx]
			+ solve(idx + 1, head) * (1. - arr[idx]);
}

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

	cin >> n;
	rep(i, 0, n)
		cin >> arr[i];
	reset(memo, -1);

	cout << fixed << setprecision(9) << solve(0, 0) << endl;

	return 0;
}


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

int main() {
    int n, tsuyoi = 0;
    cin >> n;
    vector<bool> v(8, false);
    rep(i, n) {
        int a;
        cin >> a;
        if (a < 400) v[0] = true;
        else if (a < 800) v[1] = true;
        else if (a < 1200) v[2] = true;
        else if (a < 1600) v[3] = true;
        else if (a < 2000) v[4] = true;
        else if (a < 2400) v[5] = true;
        else if (a < 2800) v[6] = true;
        else if (a < 3200) v[7] = true;
        else tsuyoi++;
    }
    int cnt = 0;
    rep(i, SZ(v)) {
        if(v[i]) cnt++;
    }
    cout << max(cnt, 1) << " " << cnt + tsuyoi << endl;
    
}

Measured memory_bytes: 3612
require 'matrix'


n, m,  = gets.split.map(&:to_i)

a = n.times.map do
      gets.split.map(&:to_i)
    end

b = m.times.map do
      gets.split.map(&:to_i)
    end

ma = Matrix.rows(a)
mb = Matrix.rows(b)
mc = ma * mb

mc.row_vectors.each {|row| puts row.to_a.join("\s")}


Measured memory_bytes: 7644
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

struct Roadwork {
	int kin, dis, tim;
	bool operator < (Roadwork other) const {
		return tim > other.tim;
	}
};

int n, q;
vector<Roadwork> road;

int main(int argc, char const *argv[]) {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) {
		int s, t, x;
		scanf("%d%d%d", &s, &t, &x);
		road.push_back((Roadwork){ 1, x, s - x});
		road.push_back((Roadwork){ 0, x, t - x});
	}
	sort(road.begin(), road.end());
	multiset<int> ms;
	for (int i = 1; i <= q; ++i) {
		int d;
		scanf("%d", &d);
		while (!road.empty() && road.back().tim <= d) {
			if (road.back().kin == 1) {
				ms.insert(road.back().dis);
			} else {
				ms.erase(ms.find(road.back().dis));
			}
			road.pop_back();
		}
		printf("%d\n", ms.empty() ? -1 : *ms.begin());
	}

	return 0;
}


Measured memory_bytes: 15340
#include<bits/stdc++.h>
#define LL long long
static const LL INF = 1<<50;

using namespace std;

int n,k,ans=1;
vector<string> s;
string num[11];
int t=0;
void cal(string sum,int depth,int bit){
    if(depth==k){
        s.push_back(sum);
        return;
    }
    for(int i=1;i<=n;++i){
        int b=1<<i;
        if(bit&b){
            int k=bit-b;
            cal(sum+num[i],depth+1,k);
        }
    }
}

int main(){
    while(1){
        int p=1;
        t=0;
        cin>>n>>k;
        if(n==0&&k==0)break;
        for(int i=1;i<=n;++i){
            p+=pow(2,i);
            cin>>num[i];
        }
        cal("",0,p);
        sort(s.begin(),s.end());
        for(int i=1;i<s.size();++i){
            if(s[i]!=s[i-1]){
                ans++;
            }
        }
        cout<<ans<<endl;
        ans=1;
        s.clear();
    }
}

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int NIL = 20000;
int dis[10];
int cost[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 >> cost[i][j];
        }
    }

    int arr[] = {0, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9);

    dis[1] = 0;
    for (int i=0;i<=9;i++){
        if(i!=1){
            dis[i] = NIL;
        }
    }
    do {
        int par = 0;
        for (int i=0;i<9;i++){
            if(i == 0){
                par += cost[arr[i]][1];
            }else {
                par += cost[arr[i]][arr[i - 1]];
            }
            if(dis[arr[i]] > par){
                dis[arr[i]] = par;
            }
        }
    } while (next_permutation(arr, arr + 9));
//    for (int i=0;i<=9;i++){
//        cout << i << " " << dis[i] << endl;
//    }
    ll ans = 0;
    for (int i = 0;i<h;i++){
        for (int j= 0;j<w;j++){
            int p;
            cin >> p;
            if(p == -1){
                continue;
            }else{
               ans += dis[p];
            }
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
//#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) + 1;
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
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 n, m;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    if(n==1)return cout<<1<<"\n",0;
    ll ans=0;
    int i=0;
    while(i<=n-1){
        int count=0;
        while(a[i]==a[i+1]){i++;if(i>n-1)break;}
        if(count==n-1){
            ans++;
        }
        if(i>n-1)break;
        if(a[i]>a[i+1]){
        while(a[i]>=a[i+1]){
            i++;
            count++;
            if(i>n-1)break;
        }
        }
        if(count){ans++;i++;};
        count=0;
        if(i>=n-1)break;
        if(a[i]<a[i+1]){
        while(a[i]<=a[i+1]){
            i++;
            count++;
            if(i>n-1)break;
        }
        }
        if(count){ans++;i++;};
        //cout<<i<<" "<<ans<<"\n";
    }
    cout<<ans<<"\n";
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

struct Node {
    int value;
    vector<Node*> connects;
};

int N, M;

int main(void)
{
    cin >> N >> M;
    vector<int> P(N + 1);
    REP(i, 1, N + 1) cin >> P[i];

    int ans = 0;

    // グラフを作る
    vector<vector<int>> connects(N + 1);

    rep(i, M) {
        int x, y;
        cin >> x >> y;

        connects[x].push_back(y);
        connects[y].push_back(x);
    }

    vector<int> searched(N + 1);
    vector<int> c(N + 1);
    for (int i = 1; i <= N; ++i) {
        if (searched[i] != 0) continue;
        stack<int> S;
        set<int> idxs;

        idxs.insert(i);
        S.push(i);
        searched[i] = 1;

        while (!S.empty())
        {
            int s = S.top();
            bool found = false;
            for(int k = c[s]; k < connects[s].size(); ++k) {
                int connect = connects[s][k];
                if (searched[connect] == 0) {
                    searched[connect] = 1;
                    S.push(connect);
                    c[s] = k + 1;
                    idxs.insert(connect);

                    found = true;
                    break;
                }
            }

            if (!found) {
                searched[s] = 2;
                S.pop();
            }
        }

        for(auto& idx : idxs) {
            if (idxs.find(P[idx]) != idxs.end()) ans++;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) ((v).begin()), ((v).end())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int x;
    cin >> x;
    if (x==0)
        cout << 1;
    else 
        cout << 0;
    return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(a, b);
  if (a == 13 && b == 1) {
    cout << "Bob" << endl;
  } else if (a == 1 && b == 13) {
    cout << "Alice" << endl;
  } else {
    if (a == b) cout << "Draw" << endl;
    else if (a > b) cout << "Alice" << endl;
    else cout << "Bob" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc161/tasks/abc161_d
// ABC161
// D - Lunlun Number

/*
Problem.
正の整数Xが以下の条件を満たすとき、Xはルンルン数である。
条件：隣り合う各桁の差の絶対値が1以下
Kが与えられ、
小さい方からK番目のルンルン数を求めよ。

Point.
解法１:queueを用いる方法 O(K)
想定解法
1,2,3,4,5,6,7,8,9をqueueに入れておいて、
front*10にfront%10-1,front%10,front%10+1を
追加していき、逐次cnt++していく。

解法２:dpを用いる方法 O(log K) ?
本番で解いた方法。複雑すぎて間に合わなかった。
dp[i][j]:最上位のi桁目がjであるルンルン数の数
dp[i][j] = dp[i][j-1] + dp[i][j] + dp[i][j+1]
累積和をとる変数accを用いて、
acc + dp[i][j] >= Kとなったら、最上位桁iはjと決定できる。
以降は、桁を一つずつ落として、
if acc + dp[i][j] >= K なら
  ans = ans * 10 + j;
  i--;
  j--;
else
  acc += dp[i][j];
  j++;
を最下位桁まで繰り返していく。
*/


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

ll solve(ll k){
  queue<ll> q;
  for(int i = 1; i < 10; i++){
    q.push(i);
  }
  ll num = 1;
  while(num < k){
    num++;
    ll t = q.front(); q.pop();
    if(t%10 > 0) q.push(t*10 + t%10-1);
    q.push(t*10 + t%10);
    if(t%10 < 9) q.push(t*10 + t%10+1);
  }
  return q.front();
}



// ll solve(ll k){
//   if(k < 10) return k;
//   vvll dp(10, vll(10, 0));
//   for(int i = 0; i < 10; i++) dp[0][i] = 1;
//   ll s = 9;
//   for(int i = 1; i < 10; i++){
//     for(int j = 0; j < 10; j++){
//       dp[i][j] = (j > 0) * dp[i-1][j-1] + dp[i-1][j] + (j < 9) * dp[i-1][j+1];
//       if(j == 0) continue;
//       if(s + dp[i][j] >= k){
//         ll ans = 0;
//         while(i+1){
//           if(s + dp[i][j] >= k){
//             ans = ans * 10 + j;
//             if(j > 0) j--;
//             i--;
//           }
//           else{
//             s += dp[i][j];
//             if(j < 9) j++;
//           }
//         }
//         return ans;
//       }
//       s += dp[i][j];
//     }
//   }
//   return 0;
// }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll k; cin >> k;
  cout << solve(k) << endl;
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 1792
using System;
class _0015
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string num1, num2, ans = "";
        for (int i = 0; i < n; i++)
        {
            num1 = Console.ReadLine();
            num2 = Console.ReadLine();
            ans = Sum(num1, num2);
            if (num1.Length > 80 || num2.Length > 80 || ans.Length > 80) Console.WriteLine("overflow");
            else Console.WriteLine(ans);
        }
    }
    public static string Sum(string str1, string str2)
    {
        string result = "";
        string spacer = "";
        int val;
        int inc = 0;
        if (str1.Length > str2.Length)
        {
            for (int i = 0; i < str1.Length - str2.Length; i++) spacer += "0";
            str2 = spacer + str2;
        }
        else if (str1.Length < str2.Length)
        {
            for (int i = 0; i < str2.Length - str1.Length; i++) spacer += "0";
            str1 = spacer + str1;
        }
        for (int i = 0; i < str1.Length; i++)
        {
            val = int.Parse(str1.Substring(str1.Length - i - 1, 1)) + int.Parse(str2.Substring(str2.Length - i - 1, 1)) + inc;
            inc = val / 10;
            val %= 10;
            result = val.ToString() + result;
        }
        if (inc > 0) result = inc.ToString() + result;
        return result;
    }
}

Measured memory_bytes: 5908
#include <stdio.h>
#define max(a,b) a > b ? a : b

int main(void){
	int m, money, age, n, i, j, k, sw, sub, mx;
	double rate, tmp;
	scanf("%d",&m);
	for(i = 0;i < m;i++){
		scanf("%d%d%d",&money,&age,&n);
		mx = 0x80000000;
		for(j = 0;j < n;j++){
			scanf("%d%lf%d",&sw,&rate,&sub);
			tmp = money;
			if(sw){
				for(k = 0;k < age;k++){
					tmp *= (1 + rate);
					tmp = (int)tmp;
					tmp -= sub;
				}
			}else{
				int sum = 0;
				for(k = 0;k < age;k++){
					sum += tmp * rate;
					tmp -= sub;
				}
				tmp += sum;
			}
			mx = max(mx,(int)tmp);
		}
		printf("%d\n",mx);
	}
	return 0;
}

Measured memory_bytes: 1060
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str1;
    string str2;
    string b;
    int count = 0,a;
    cin >> str1;
    while(true){
        b ="";
        cin >> str2;
        a = str2.size();
        if(str2=="END_OF_TEXT")break;
        for(int i =0;i<a;i++){
            b += tolower(str2[i]);
            }
        if(str1==b) count+=1;
    }cout << count <<endl;
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;

ll maxl(ll x, ll y) {
    if (x > y) return x;
    else return y;
}

int main(void){
    ll n, h;
    cin >> n >> h;
    vector<ll> a(n), b(n);
    vector<pair<ll, ll>> x(n*2);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        x[i] = make_pair(a[i], i);
        x[n + i] = make_pair(b[i], n + i);
    }
    
    sort(x.begin(), x.end());
    
    int use;
    for (int i = 2 * n - 1; i >= n - 1; i--) {
        if (x[i].second < n) {
            use = x[i].second;
            break;
        }
    }
    
    int ans = 0, num = 2 * n - 1;
    while (h > 0) {
        if (x[num].second >= n && x[num].second != n + use) {
            h -= x[num].first;
            ans++;
            num--;
        }
        else if (x[num].second == n + use) {
            num--;
            h -= b[use];
            ans++;
        }
        else if (x[num].second == use) {
            if (h <= 0) cout << ans << endl;
            else if (h % a[use] == 0) cout << ans + h / a[use] << endl;
            else cout << ans + h / a[use] + 1 << endl;
            return 0;
        }
        if (h <= 0) {
            cout << ans << endl;
            return 0;
        }
    }
    
    
}


Measured memory_bytes: 4992
#include <stdio.h>
int isprime(int);
int main(){
  int i,x,result=0,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    result+=isprime(x);
  }
  printf("%d\n",result);
  
  return 0;
}
int isprime(int x){
  int i;
  if(x==2)
    return 1;
  if(x<2 || x%2==0)
    return 0;

  i=3;
  while(i*i<=x){
    if(x%i==0)
      return 0;
    i+=2;
  }
  return 1;
}



Measured memory_bytes: 2104
N = int(input())
#S = list(input())

#N,K=map(int,input().split())
#A=list(map(int,input().split()))
B=list(map(int,input().split()))
#C=list(map(int,input().split()))

ans=0

A=[max(B) for i in range(N)]

for i,b in enumerate(B):
    if A[i] > b:
        A[i]=b
    if A[i+1] > b:
        A[i+1]=b

ans=sum(A)



print(str(ans))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define MOD 1000000007

typedef long long ll;

ll memo[1001][1001];
std::string grid[1001];

ll GRID(int h, int w)
{
	if((h <= 0) || (w <= 0) || (grid[h-1][w-1] == '#'))
	return 0;	
	else if((h == 1) && (w == 1))
	return 1;
	if(memo[h][w] != -1)
	return memo[h][w];
	ll ans = ((GRID(h-1, w)%MOD) + (GRID(h, w-1)%MOD))%MOD;
	memo[h][w] = ans;
	return ans;
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	memset(memo, -1, sizeof(memo));
	int h,w;
	std::cin>>h>>w;
	for(int i=0;i<h;i++)
	std::cin>>grid[i];
	ll ans = GRID(h, w)%MOD;
	std::cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=2e5+10;
const int mod=1e9+7;
char ans[MAX],in[MAX];
int main()
{
    while(scanf("%s",in)!=EOF)
    {
        int i,j=0;
        for(i=0;in[i];i++)
        {
            if(in[i]=='B')
            {
                if(j)
                    j--;
            }
            else
            {
                ans[j++]=in[i];
            }
        }
        ans[j]=0;
        puts(ans);
    }
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
bool line(int x1, int y1, int x2, int y2, int x, int y){
    return (x2 - x1) * (y - y1) > (y2 - y1) * (x - x1);
}

bool triangle(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y){
    return  line(x1, y1, x2, y2, x, y) == line(x1, y1, x2, y2, x3, y3) &&
            line(x2, y2, x3, y3, x, y) == line(x2, y2, x3, y3, x1, y1) &&
            line(x3, y3, x1, y1, x, y) == line(x3, y3, x1, y1, x2, y2);
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        int x1, y1, x2, y2, x3, y3, ax, ay, bx, by;
        scanf("%d%d%d%d%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3, &ax, &ay, &bx, &by);
        if(triangle(x1, y1, x2, y2, x3, y3, ax, ay) != triangle(x1, y1, x2, y2, x3, y3, bx, by)){
            printf("OK\n");
        }
        else{
            printf("NG\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] p = new boolean[105001];
		for (int i = 0; i <= 105000; i++) {
			p[i] = true;
		}
		for (int i = 2; i <= 325; i++) {
			for (int j = i * 2; j <= 105000; j += i) {
				p[j] = false;
			}
		}
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int c = 0;
			for (int i = 2; i <= 105000 && n > 0; i++) {
				if (p[i]) {
					n--;
					c += i;
				}
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 12000
s = input()[::-1]
ls = [word[::-1] for word in ["dream", "dreamer", "erase", "eraser"]]
i = 0
while s:
    word = ls[i]
    if s.find(word) == 0:
        s = s[len(word):]
        i = 0
    else:
        i += 1
        if i > 3:
            print("NO")
            break
else:
    print("YES")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ull = unsigned long long;
template<typename T> void Out(T x) { cout << x << endl; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ull N, K;
  cin >> N >> K;

  long long mini = N % K;
  cout << min(mini, (long long)abs(mini - (long long)K)) << endl;

}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,now,ans[1000][1000];

signed main() {
    cin >> n;
    int ns = (int)sqrt(n*2);
    if (n*2 != ns*(ns+1)) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << ns+1 << endl;
    rep(i,ns+1) {
        rep(j,i) ans[i][j] = ans[j][i-1];
        repo(j,i,ns) ans[i][j] = ++now;
    }
    rep(i,ns+1) {
        cout << ns << " ";
        rep(j,ns) cout << ans[i][j] << " ";
        cout << endl;
    }
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  string s;
  cin >> s;
  string ans="AC";
  if(s.at(0)!='A'){
    ans="WA";
  }
  ll is=0;
  for(int i=2;i<s.size()-1;i++){
    if(s.at(i)=='C'){
      is++;
    }
  }
  if(is!=1){
    ans="WA";
  }
  for(int i=1;i<s.size();i++){
    if(s.at(i)=='C'){
      continue;
    }
    if(!(s.at(i)>='a' && s.at(i)<='z')){
      ans="WA";
    }
  }
  cout << ans;
}

Measured memory_bytes: 3600
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_C
  * ?¨???????
  * ???????????´??° a, b ??¨?????????????????? op ?????????????????§???a op b ????¨??????????????????°?????????????????????????????????
  * ????????????????????? op ??????"+"(???)???"-"(???)???"*"(???)???"/"(???)???????????¨??????
  * ???????????§????????????????????´??????????°???°?????\??????????????¨????????????????¨????????????¨????????????
  * ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
  * a op b
  * op ??? '?' ?????¨??? ??\?????????????????????????????????????????±???????????????????????£????????????????????????
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" +"))
      .map { case Array(a, op, b) => (a.toInt, op, b.toInt) }
      .takeWhile { case (_, op, _) => op != "?" }
      .map {
        case (a, op, b) => op match {
          case "+" => a + b
          case "-" => a - b
          case "*" => a * b
          case "/" => a / b
        }
      }
      .foreach(println)
  }
}

Measured memory_bytes: 43820
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define rev(a) a.rbegin(),a.rend()
#define all(a) a.begin(),a.end()
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define debug(...) cerr<<" ["<<#__VA_ARGS__<<": "<<(__VA_ARGS__)<<"] ";
#define debugv(...) for(int i=0; i<size(__VA_ARGS__); i++) cerr<<" ["<<#__VA_ARGS__<<i<<": "<<(__VA_ARGS__)[i]<<"] ";
const int mod = 1e8;
const int inf = 1e9+5;
const int inf64 = 1e18+5;
//           -------"Where is your Pen and Paper?"-------
void solve(){
    string s,t;
    cin>>s>>t;
    int a=0;
    for(int i=0; i<size(s); i++){
        if(s[i]!=t[i]){
            a++;
        }
    }
    cout<<a;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
    int test;
    //cin>>test;
    test=1;
    //int cse=1;
    while(test--){
         //cout<<"Case #"<<cse<<": ";
         solve();
         cout<<endl;
         //cse++;
    }
    return 0;
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;
    }

    public static string Solve()
    {
        int N = ReadInt();
        int[] A = ReadInts();
        int minusCnt = 0;
        int minAbs = int.MaxValue;
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            int tmp = Math.Abs(A[i]);
            if (A[i] < 0) minusCnt++;
            if (tmp < minAbs) minAbs = tmp;
            ans += tmp;
        }
        if(minusCnt%2==1)
        {
            ans -= minAbs * 2;
        }
        return ans.ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 29020
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X,Y,Z;
    scanf("%d%d%d",&X,&Y,&Z);
    int ans=0;
    if(X==Y+2*Z){cout<<1<<endl;}
    else if(X<Y+2*Z){cout<<0<<endl;}
    else if(X>Y+2*Z){cout<<(X-(Y+2*Z))/(Y+Z)+1<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

int
main(int argc, char const *argv[])
{
    int64_t n;
    cin >> n;
    vector<tuple<int64_t, string, int64_t>> v(n);

    for (int64_t i = 0; i < n; ++i) {
	string s;
	int64_t u;
	cin >> s >> u;
	v[i] = make_tuple(i+1, s, u);
    }

    std::sort(
        v.begin(),
        v.end(),
        [](const tuple<int64_t, string, int64_t>& x, const tuple<int64_t, string, int64_t>& y){
	    return get<1>(x) < get<1>(y) || (get<1>(x) == get<1>(y) && get<2>(x) > get<2>(y));
	}
    );

    for (int64_t i = 0; i < n; ++i) {
	cout << get<0>(v[i]) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	string s;
	cin>>s;
	for(int i=0;i<(int)s.size();++i){
		if(i%2==0 && s[i]=='L'){
			cout<<"No\n";
			return ;
		} else if(i%2==1 && s[i]=='R'){
			cout<<"No\n";
			return ;
		}
	}
	cout<<"Yes\n";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)
	solve();
	return 0;
}


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

int a[3][3];

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

    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n, c = 0;
    cin >> n;
    vector<int> b(n);
    rep(i, n)
    {
        cin >> b.at(i);
        rep(j, 3) rep(k, 3)
        {
            if (a[j][k] != 0)
                if (b.at(i) == a[j][k])
                    a[j][k] = 0;
        }
    }
    rep(i, 3)
    {
        if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
        {
            ++c;
            break;
        }
        else if (a[0][i] == a[1][i] && a[1][i] == a[2][i])
        {
            ++c;
            break;
        }
        else if (a[0][0] == a[1][1] && a[1][1] == a[2][2])
        {
            ++c;
            break;
        }
        else if (a[0][2] == a[1][1] && a[1][1] == a[2][0])
        {
            ++c;
            break;
        }
    }
    if (c == 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    from collections import deque
    n,x,y=map(int,input().split())
    e=[[]for _ in range(n)]
    for i in range(n-1):
        e[i]+=i+1,
        e[i+1]+=i,
    e[x-1]+=y-1,
    e[y-1]+=x-1,
    a=[0]*n
    for s in range(n):
        d=[-1]*n
        d[s]=0
        q=deque([s])
        add,pop=q.append,q.popleft
        while q:
            v=pop()
            for w in e[v]:
                if d[w]<0:
                    d[w]=d[v]+1
                    add(w)
        for i in d:a[i]+=1
    print(' '.join(str(i//2)for i in a[1:]))
main()


Measured memory_bytes: 3944
n = int(input())
l = list(range(1,n+1))
fz = list(range(3,n+1,3))
bz = list(range(5,n+1,5))
fzbz = list(range(15,n+1,15))
a = sum(l)-sum(fz)-sum(bz)+sum(fzbz)
print(a)

Measured memory_bytes: 72188
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
s = set(a)
c = Counter(a)

if n%3 != 0:
  if s == {0}:
    print('Yes')
  else:
    print('No')
else:
  if len(c) > 3:
      print('No')
  elif len(c) == 3:
    a,b,q = list(s)
    if a^b == q and c[a] == n//3 and c[b] == c[q]:
      print('Yes')
    else:
      print('No')
  elif len(c) == 2:
    if not 0 in s:
      print('No')
    else:
      if c[0] == n//3:
        print('Yes')
      else:
        print('No')
  elif len(c) == 1:
    if s == {0}:
      print('Yes')
    else:
      print('No')

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

static int N=100;

int main()
{
  int i,l,j,k,n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for( i=1; i<=n; i++ )
    {
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for( i = 1; i <= n; i++ )
    m[i][i]=0;
  for( l = 2; l <= n; l++ )
    {
    for( i = 1; i <= n-l+1; i++ )
      {
      j = i+l-1;
      m[i][j]=1<<21;
      for( k = i; k <= j-1; k++ )
	{
	m[i][j]=fmin(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
 
  printf("%d",m[1][n]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2048
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int solve() {
    int N; cin >> N;
    if(N == 0) return 0;

    long double pw; cin >> pw;
    vector<long double> vw(N), pf(N), vf(N), th(N);
    for(int i=0; i<N; i++) {
        cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    }

    auto calc_cost = [&](long double x) {
        long double cost_sum = x * pw;
        for(int i=0; i<N; i++) {
            long double f = (th[i] - x * vw[i]) / vf[i];
            cost_sum += pf[i] * max(f, (long double)0.0);
        }
        return cost_sum;
    };

    long double ub = 1e10, lb = 0;
    for(int i=0; i<200; i++) {
        long double l = (lb * 2 + ub) / 3;
        long double r = (lb + 2 * ub) / 3;
        if(calc_cost(l) < calc_cost(r)) {
            ub = r;
        }
        else {
            lb = l;
        }
    }

    printf("%.12Lf\n", calc_cost(ub));
    return 1;
}

signed main() {
    while(solve());
    return 0;
}



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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

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

signed main ()
{
    fastio
    ll a , b ; cin >> a >> b ;
    if (a == 1 || b ==1 )
        cout << 1 << endl ;
    else
        cout << (a * b % 2 == 0 ? a * b / 2 : (a * b / 2 ) + 1 ) << endl ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include<stdio.h>
int main(){

int n,i;
scanf("%d",&n);
int a[n];
for(i=0; i<n; i++){
scanf("%d",&a[i]);
}
for(i=n-1; i>=0; i--){
    if(i==0){
        printf("%d\n",a[i]);
    }else{
         printf("%d ",a[i]);
    }
}
return 0;
}



Measured memory_bytes: 2064
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int c=0;
	rep(i,n)if(in[i]<0)c++;
	int s=0,mi=inf;
	rep(i,n)s+=abs(in[i]),cmin(mi,abs(in[i]));
	if(c%2){
		s-=mi*2;
	}
	cout<<s<<endl;
}











Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>

#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto &v : a) cin >> v;
    
    ll count = ceil(double(n - 1) / (k - 1));
    
    cout << count << endl;
    
    return 0;
}



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

using namespace std;

void solve() {
    int n, m; cin >> n >> m;
    vector<int> vt(n);
    int sm = 0;
    for (int i = 0; i < n; i++) {
        cin >> vt[i];
        sm += vt[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (4 * m * vt[i] >= sm)
            ans++;
    }
    cout << (ans >= m ? "Yes" : "No");
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 256
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

	string s;
	string ans;

	cin >> s;

	cout << s[0] << s.length() - 2 << s[s.length()-1] << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
x = n*0.5
s_list = list(s)
half = []
if n % 2 == 1:
    print("No")
else:
    for i in range(int(len(s_list)/2)):
        half.append(s_list[i])
    if half+half == s_list:
         print("Yes")
    else:
        print("No")
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	ll n,m;
	cin >> n >> m;

	vector<vector<ll>> to(n);
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	const ll INF = 1e9;
	vector<ll> res(n, INF);
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll now = q.front(); q.pop();

		for(ll next : to[now]){
			if(res[next] != INF) continue;
			res[next] = now;
			q.push(next);
		}
	}

	cout << "Yes" << endl;
	rep(i,n-1){
		cout << res[i+1] + 1 << endl;
	}
	return 0;
}

int main(){

	return mainsolve();
}

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

using namespace std;

const int N = 1e5 + 5;
const int M = 1e9 + 7;

int n, k;
int dp[N];
int lp[N];
int prime[N];

int fastpow(long long x, int y) {
    long long ret = 1;
    while (y > 0) {
        if (y & 1) ret = (ret * x) % M;
        y >>= 1;
        x = (x * x) % M;
    }
    return ret;
}

void upd(int& x, int y) {
    x = (x + y) % M;
    x = (x % M + M) % M;
}

int get(int x) {
    int ret = 0;
    for (int i = 1; i <= x; i++) {
        if (lp[i] != 1) continue;
        if (prime[i] % 2 == 0) {
            upd(ret, dp[x / i]);
        } else {
            upd(ret, -dp[x / i]);
        }
    }
    return ret;
}

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

    cin >> n >> k;
    iota(lp + 1, lp + 1 + k, 1);
    for (int i = 2; i <= k; i++) {
        if (prime[i]) continue;
        for (int j = i; j <= k; j += i) {
            prime[j]++;
            lp[j] /= i;
        }
    }
    for (int i = 1; i <= k; i++) {
        dp[i] = fastpow(i, n);
    }
    long long ans = 0;
    for (int i = 1; i <= k; i++) {
        long long cur = ((1LL) * i * get(k / i)) % M;
        ans = (ans + cur) % M;
    }
    cout << (ans % M + M) % M << '\n';

    return 0;
}

Measured memory_bytes: 4764
S = input()
N = len(S)

from collections import Counter

c = Counter(S)

items = sorted(c.items(), key=lambda x: x[1])

if N == 1:
    print('YES')
elif N == 2:
    if len(items) == 1:
        print('NO')
    else:
        print('YES')
else:
    if len(items) < 3:
        print('NO')
    else:
        min = items[0][1]
        max = items[-1][1]
        if max - min >= 2:
            print('NO')
        else:
            print('YES')


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

using namespace std;
using ll = long long;

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

    string s;
    int q;

    cin >> s >> q;

    int query, f;
    char c;
    string head, tale;
    bool rvs = false;

    for(int i = 0; i < q; ++i) {
        cin >> query;
        if(query == 1) {
            rvs = !rvs;
        } else {
            cin >> f >> c;
            if(rvs ^ f == 1) {
                head.push_back(c);
            } else {
                tale.push_back(c);
            }
        }
    }

    if(!rvs) {
        reverse(head.begin(), head.end());
        s = head + s + tale;
    } else {
        reverse(s.begin(), s.end());
        reverse(tale.begin(), tale.end());
        s = tale + s + head;
    }

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

using namespace std;

int n;
int m;
int star;
int d;
char bar[100][100];

bool solve() {
    int num[n];
    rep(i,n)num[i] = i+1;
    rep(i,d)rep(j,n-1){
        if(bar[i][j]=='1')swap(num[j],num[j+1]);
    }
    return num[star-1]==m;
}

int main(){
    while(cin>>n && n){
        cin>>m>>star>>d;
        rep(i,d)cin>>bar[i];
        if(solve()){
            cout<<0<<endl;
            goto END;
        }
        rep(i,d){
            rep(j,n-1){
                if((j==0 || bar[i][j-1]=='0') &&
                    bar[i][j]=='0' &&
                    (j+1==n-1 || bar[i][j+1]=='0')){
                    bar[i][j]='1';
                    if(solve()){
                        cout<<i+1<<" "<<j+1<<endl;
                        goto END;
                    }
                    bar[i][j]='0';
                }
            }
        }
        cout<<1<<endl;
    END:;
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<string, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    deque<int> deq;
    for (int i = 0; i < n; i++)
    {
        string com;
        cin >> com;
        if (com == "insert")
        {
            int x;
            cin >> x;
            deq.push_front(x);
        }
        else if (com == "delete")
        {
            int x;
            cin >> x;
            deque<int> tmp;
            while (!deq.empty())
            {
                if (deq.front() == x)
                {
                    deq.pop_front();
                    break;
                }
                else
                {
                    tmp.push_back(deq.front());
                    deq.pop_front();
                }
            }
            while (!tmp.empty())
            {
                deq.push_front(tmp.back());
                tmp.pop_back();
            }
        }
        else if (com == "deleteFirst")
        {
            deq.pop_front();
        }
        else
        {
            deq.pop_back();
        }
    }
    vector<int> res;
    while (!deq.empty())
    {
        res.push_back(deq.front());
        deq.pop_front();
    }
    printv(res);
}



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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int64_t n,m,sum=0; cin >> n >> m;
    rep(i,m){
        int64_t a;
        cin >> a;
        sum += a;
    }

    if(sum > n){
        cout << -1 << endl;
    }else{
        cout << n-sum << endl;
    }
}

Measured memory_bytes: 3636