akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 998244353;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

long long power(long long x, long long n, long long mod = MOD) {
    if (n == 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    if (a[0] != 0) {
        cout << 0 << endl;
        return;
    }
    VI d(n);
    REP(i,0,n) d[a[i]]++;
    if (d[0] > 1) {
        cout << 0 << endl;
        return;
    }
    RREP(i,0,n) {
        if (d[i] == 0) continue;
        RREP(j,0,i) if (d[j] == 0) {
            cout << 0 << endl;
            return;
        }
        break;
    }
    LL ans = 1;
    REP(i,1,n) {
        ans = (ans * power(d[i-1], d[i])) % MOD;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 1408
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__ )
#else
#define debug(...)
#endif
#define MEM(x,y) memset(x, y,sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
vector<int> vec;
int a[999999 + 10];
void init(){
	memset(a,0,sizeof a);
	for (int i = 2;i <=  999999 + 9;++i){
		if (a[i] == 0){
			vec.push_back(i);
			for (int j = i + i;j <=  999999 + 9;j += i){
				a[j] = 1;
			}
		}
	}
}
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int n;
	init();
	while(scanf("%d",&n) != EOF){
		int ans = upper_bound(vec.begin(), vec.end(),n) - vec.begin();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }
    
    const int di[] = {-1, 0, 1, 0};
    const int dj[] = {0, -1, 0, 1};
    const int INF = 1001001001;

    vector<vector<int>> distance(h, vector<int>(w, INF));
    queue<pair<int, int>> que;
    auto update = [&](int i, int j, int x){
        if(distance[i][j] != INF){
            return;
        }
        distance[i][j] = x;
        que.emplace(i, j);
    };
    update(0, 0, 1);

    while(!que.empty()){
        int i = que.front().first;
        int j = que.front().second;
        que.pop();
        rep(direction, 4){
            int ni = i + di[direction];
            int nj = j + dj[direction];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w){
                continue;
            }
            if(s[ni][nj] == '#'){
                continue;
            }
            update(ni, nj, distance[i][j]+1);
        }
    }

    int cnt = 0;
    rep(i, h){
        rep(j, w){
            if(s[i][j] == '.'){
                cnt++;
            }
        }
    }
    if(distance[h-1][w-1] == INF){
        cout << -1 << endl;
    }
    else{
        cout << cnt - distance[h-1][w-1] << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector< int> v(n);
    for(int &i: v) cin >> i;
    int res = 0;
    for(int i = 0; i < n; ++i) 
        for(int j = i + 1; j < n; ++j)
            res = max(res, abs(v[i] - v[j]));

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  ll N, M, L;
  cin >> N >> M >> L;
  vector<ll> A(M), B(M), C(M);
  rep(i, M) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;
    B[i]--;
  }
  ll Q;
  cin >> Q;
  vector<ll> s(Q), t(Q);
  rep(i, Q) {
    cin >> s[i] >> t[i];
    s[i]--;
    t[i]--;
  }

  vector<vector<ll>> d(N, vector<ll>(N, LINF));
  rep(i, M) {
    if (L < C[i])
      continue;
    d[A[i]][B[i]] = C[i];
    d[B[i]][A[i]] = C[i];
  }
  rep(i, N) {
    d[i][i] = 0;
  }

  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        chmin(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  vector<vector<ll>> hokyu(N, vector<ll>(N, LINF));
  rep(i, N) {
    rep(j, N) {
      if (i == j)
        hokyu[i][j] = 0;
      else if (d[i][j] <= L)
        hokyu[i][j] = 1;
    }
  }
  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        chmin(hokyu[i][j], hokyu[i][k] + hokyu[k][j]);
      }
    }
  }

  rep(q, Q) {
    ll temp = hokyu[s[q]][t[q]];
    if (temp == LINF)
      cout << -1 << endl;
    else
      cout << temp - 1 << endl;
  }
}

Measured memory_bytes: 4352
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>

using namespace std;

typedef vector<vector<char>> Graph;
typedef vector<vector<int>> Dist;
typedef pair<int, int> P;
Graph graph;

// ★升目探索のBFS グラフ外のバリアあり
int bfs(int start_x, int start_y) {

	Dist dist;
	dist.resize(graph.size());
	for (int i = 0; i < graph.size(); i++) {
		for (int j = 0; j < graph[0].size(); j++) {
			dist[i].push_back(-1);
		}
	}

	queue<P> que;  // キューを用意して、初期探索点をセット
	que.push(P(start_x, start_y));
	dist[start_x][start_y] = 0; // 初期点の距離を0
	int max_dist = 0;

	while (!que.empty()) { // BFSループ
		// ★★　この中で迂闊に break しないこと

		// キューの先頭のセルを取得
		P v = que.front(); que.pop();
		int x = v.first;
		int y = v.second;
		if (dist[x][y] > max_dist) max_dist = dist[x][y];

		// 取得したセルに対する処理

		// そのセルからつながるセルに処理を移行
		int H = graph.size();
		int W = graph[0].size();
		if (x + 1 < H) {
			if (dist[x + 1][y] == -1 && !(graph[x + 1][y] == '#')) { // 処理以降条件
				dist[x + 1][y] = dist[x][y] + 1;
				que.push(P(x + 1, y));
			}
		}
		if (x - 1 >= 0) {
			if (dist[x - 1][y] == -1 && !(graph[x - 1][y] == '#')) {
				dist[x - 1][y] = dist[x][y] + 1;
				que.push(P(x - 1, y));
			}
		}
		if (y + 1 < W) {
			if (dist[x][y + 1] == -1 && !(graph[x][y + 1] == '#')) {
				dist[x][y + 1] = dist[x][y] + 1;
				que.push(P(x, y + 1));
			}
		}
		if (y - 1 >= 0) {
			if (dist[x][y - 1] == -1 && !(graph[x][y - 1] == '#')) {
				dist[x][y - 1] = dist[x][y] + 1;
				que.push(P(x, y - 1));
			}
		}
	}

	return max_dist;
}


int main() {

	int H, W;
	cin >> H >> W;

	graph.resize(H);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char tmp;
			cin >> tmp;
			graph[i].push_back(tmp);
		}
	}

	int max_dist = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (graph[i][j] == '.') {
				//道の時にスタートとゴールを選べる
				int start_x = i;
				int start_y = j;
				max_dist = max(max_dist,bfs(start_x, start_y));
			}
		}
	}


	cout << max_dist << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 10000000

typedef long long ll;

int n, a;
vector<int> vi;

ll dp[110][1100];

int main(){
	cin >> n;
	REP(i, n){
		cin >> a;
		if (i == n - 1)continue;
		vi.push_back(a);
	}
	REP(i, vi.size()){
		if (i == 0){
			dp[i][vi[i]] = 1;
			continue;
		}
		REP(j, 21){
			if (j + vi[i] <= 20){
				dp[i][j + vi[i]] += dp[i - 1][j];
			}
			if (j - vi[i] >= 0){
				dp[i][j - vi[i]] += dp[i - 1][j];
			}
		}
	}
	cout << dp[vi.size() - 1][a] << endl;
}

Measured memory_bytes: 1624
nk = input().split()
n = int(nk[0])
k = nk[1]
l = []

for i in range(int(k)):
    num = int(input())
    sweet = input().split()
    for j in range(num):
        sw = int(sweet[j])
        l.append(sw)

l = list(set(l))

ass = len(l)

ans = n - ass

print(ans)

Measured memory_bytes: 9276
#include <iostream>
#include <cmath>

using namespace std;


int main(){
	int n;
	int e = 0;
	int a;

	cin >> n;

	for(int i=0; i<n; i++){
		cin >> a;
		if(a % 2 == 0)e++;
	}	
	cout << pow(3,n) - pow(2,e) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// x^n(mod M)
ll mpow(ll x, ll n, ll k) {
    ll ans = 1ll;
    while(n != 0){
        if (n&1) ans = ans*x%k;
        x = x*x%k;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    ll k; cin>>k;

    ll cur = 0;
    rep(i,2002000) {
        cur += (7ll*mpow(10ll, i, k))%k;
        cur %= k;
        if (cur == 0) {
            cout << i+1 << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<set>

using namespace std;

typedef pair<int, int> P;

int main(){
 set<P> s;
 int N, L;
	
 cin >> N >> L;
	
 int a[N];
	
 for(int i=0; i<N; i++){ cin >> a[i]; }

	
 for(int i=0; i<=N-1; i++){
 s.insert(P(a[i],i));
 if(0 <= i-L) s.erase(P(a[i-L], i-L));
 if(L <= i+1){ 
  P p = *s.begin(); 
  if(i != N-1){ cout << p.first << " "; }
  else{ cout << p.first<< endl; }
 }
 }

 return 0;
}



Measured memory_bytes: 11668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int a[100005];

int main()
{
	int N, L;
	cin >> N >> L;
	REP(i, N)
	{
		cin >> a[i];
	}

	int mi = -1;

	REP(i, N - 1)
	{
		if (a[i] + a[i + 1] >= L)
		{
			mi = i;
			break;
		}
	}

	if (mi == -1)
	{
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	REP(i, mi)
	{
		cout << i + 1 << endl;
	}
	for (int i = N - 2; i >= mi; i--)
	{
		cout << i + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k]-x[j][k])**2
        distance = distance**0.5
        if distance%1==0:
            cnt+=1
print(cnt)

Measured memory_bytes: 3064
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int N = sc.nextInt();
        if (N == 100){
            N += 1;
        }
        if(D == 0) {
            System.out.println(N);
        } else {
            System.out.println(N * (int)Math.pow(100, D));
        }
    }
}

Measured memory_bytes: 22868
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int N, K;
long double E[200005];
long double SUM[200005];

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

  cin >> N >> K;
  long double a;
  rep(i, N) {
    cin >> a;
    E[i] = (a+1)/2;
  }
  rep(i, K) {
   SUM[0] += E[i];
  }
  rep(i, N-K+1) {
    if (i==0) continue;
    SUM[i] = SUM[i-1] - E[i-1]+E[i+K-1];
  }
  long double mx = 0;
  rep(i, N-K+1) mx = max(mx, SUM[i]);
  cout << setprecision(7) << mx << "\n";
  return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define INF 1152921504606846976ll
using namespace std;
typedef long long ll;
int n;

int main(){
	cin >> n;
	vector<ll> a(n+1);
	rep(i, 0, n){
		cin >> a[i];
	}
	a[n] = INF;
	sort(a.begin(), a.end());
	ll s = 1;
	if(a[0] != 1) {
		cout << 1 << endl;
		return 0;
	}
	rep(i, 1, n+1){
		//cout << a[i] << " "<< s << endl;
		if(a[i] > s + 1){
			cout << s + 1 << endl;
			return 0;
		}
		s+=a[i];
	}
	cout << "unko\n";
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int k; cin >> k;
  vector<ll> ans;
  queue<ll> q;
  for (int i = 1; i<10; i++) q.push(i);
  while(!q.empty()) {
    if (ans.size() > k) break;
    ll n = q.front(); q.pop();
    ans.push_back(n);
    int f = n%10;
    if (f > 0) q.push(n*10+(f-1));
    q.push(n*10+f);
    if (f < 9) q.push(n*10+f+1);
  }
  COUT(ans[k-1]);
  return 0;
}

Measured memory_bytes: 5520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++){
			br.readLine();
			
			String[] tmpArray = new String[8];
			for(int j = 0; j < 8; j++){
				tmpArray[j] = br.readLine();
			}
			
			Board board = new Board();
			board.generateBoard(tmpArray);
			int x = Integer.parseInt(br.readLine());
			int y = Integer.parseInt(br.readLine());
			
			board.burn(x, y);
			board.print(i+1);
		}
		
		
		
	}

}

class Board {
	Tile[][] tiles = new Tile[8][8];
	
	public void generateBoard(String[] input){
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				Tile tmp;
				//System.out.println("i = "+i+" j = "+j);
				if(input[i].charAt(j) == '0'){
					tmp = new Tile(j, i, Tile.NONE);
				}
				else{
					tmp = new Tile(j, i, Tile.BOMB);
				}
				tiles[i][j] = tmp;
			}
		}
	}
	
	public void burn(int x, int y){
		ArrayDeque<Tile> queue = new ArrayDeque<Tile>();
		queue.push(tiles[y-1][x-1]);
		
		while(!queue.isEmpty()){
			Tile tmpTile = queue.poll();
			
//			System.out.println("Bomb "+tmpTile.x+" "+tmpTile.y+" fired");
			tmpTile.state = Tile.NONE;
			for(int i = Math.max(tmpTile.y-3, 0) ; i <= Math.min(tmpTile.y+3, 7) ; i++){
				if(tiles[i][tmpTile.x].state == Tile.BOMB){
					queue.push(tiles[i][tmpTile.x]);
				}
			}
			for(int i = Math.max(tmpTile.x-3, 0) ; i <= Math.min(tmpTile.x+3, 7) ; i++){
				if(tiles[tmpTile.y][i].state == Tile.BOMB){
					queue.push(tiles[tmpTile.y][i]);
				}
			}
		}
	}
	
	public void print(int num){
		System.out.println("Data "+num+":");
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				if(tiles[i][j].state == Tile.BOMB){
					System.out.print("1");
				}
				else{
					System.out.print("0");
				}
			}
			System.out.println();
		}
	}
}

class Tile{
	static final int NONE = 0;
	static final int BOMB = 1;
//	static final int BURNED = 2;
	int state;
	int x;
	int y;
	
	public Tile(int x, int y, int state){
		this.state = state;
		this.x = x;
		this.y = y;
	}
}

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

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

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int dh[4] = { 0,1,0,-1 };
int dw[4] = { 1,0,-1,0 };
bool isin(const int H, const int W, int h, int w) {
	return 0 <= h && h < H && 0 <= w && w < W;
}

int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<bool>> A(H, vector<bool>(W));
	REP(i, H) {
		string s;
		cin >> s;
		REP(j, W)A[i][j] = s[j] == '#';
	}

	int res = 0;
	queue<pair<int, int>> q;
	vector<vector<bool>> went(H, vector<bool>(W, false));
	REP(i, H)REP(j, W) {
		if (A[i][j]) {
			q.push({ i,j });
			went[i][j] = true;
		}
	}
	while (true) {
		if (q.empty()) {
			cout << res - 1 << endl;
			return 0;
		}
		queue<pair<int, int>> next;
		while (!q.empty()) {
			auto pos = q.front(); q.pop();
			int h = pos.first;
			int w = pos.second;
			REP(dir, 4) {
				int nh = h + dh[dir];
				int nw = w + dw[dir];
				if (!isin(H, W, nh, nw))continue;
				if (went[nh][nw])continue;
				went[nh][nw] = true;
				next.push({ nh,nw });
			}
		}
		q = next;
		res++;
	}

	return 0;
}


Measured memory_bytes: 8960
N,M = map(int,input().split())
X = list(map(int,input().split()))

X.sort()

if N >= M:
    print(0)
    exit()

distance = []

for i in range(M-1):
    distance.append(abs(X[i]-X[i+1]))

distance.sort()

print(sum(distance)-sum(distance[M-N:]))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
int a[20],n;
map<pair<pair<int,int>,int>,int >m;
int dfs(int d,int x,int y){
  if(d==n){if(y<x)swap(x,y);return y-x;}
  if(m[mk(mk(x,y),d)])return m[mk(mk(x,y),d)];
  return (m[mk(mk(x,y),d)])=min(dfs(d+1,x+a[d],y),dfs(d+1,x,y+a[d]));
}
int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<dfs(0,0,0)<<endl;m.clear();
  }
}

Measured memory_bytes: 10560
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

struct edge
{
    int v,w,nxt;
}e[400050];

const long long INF=1e12;

int head[100050],ecnt;

void add(int u,int v,int w)
{
    e[++ecnt].v = v;
    e[ecnt].w = w;
    e[ecnt].nxt = head[u];
    head[u] = ecnt;
}

int N,M;
int l[200050],r[200050];
int d[200050];
long long dis[100005];
queue<int> que;
bool vis[100050],inq[100050];

bool spfa(int st)
{
    que.push(st);
    inq[st] = true;
    dis[st] = 0;
    long long curmax = 0,curmin = 0;
    while(!que.empty())
    {
        int u = que.front();
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dis[v] == INF)
            {
                dis[v] = dis[u] + e[i].w;
                curmax = max(curmax,dis[v]);
                curmin = min(curmin,dis[v]);
                if(curmax - curmin > 1000000000)
                    return false;
                vis[v] = 1;
                if(!inq[v])
                    que.push(v);
            }
            else if(dis[v] != dis[u] + e[i].w)
                return false;
        }
        inq[u] = false;
    }
    return true;
}

int main()
{
    for(int i = 1;i <= 100000; ++ i)
        dis[i] = INF;
    scanf("%d%d",&N,&M);
    for(int i = 1;i <= M; ++ i)
    {
        scanf("%d%d%d",&l[i],&r[i],&d[i]);
        add(l[i],r[i],d[i]);
        add(r[i],l[i],-d[i]);
    }
    for(int i = 1;i <= N; ++ i)
    {
        if(!vis[i])
        {
            vis[i] = 1;bool l = spfa(i);
            if(!l)
            {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

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

int main()
{
    int a, b, r, tmp;
    
    cin >> a >> b;
    
    if (a < b) { tmp = a; a = b; b = tmp; }
    
    while (b > 0) {
        r = a % b;
        a = b;
        b = r;
    }
    cout << a << endl;

    return 0; 
}


Measured memory_bytes: 3088
/* 
                     ... .
               xdM*"""*+"9M
            xM"             "M
          MP"                 "M
        ,M/|,                 \`4
      n"   /|/.          .\  \\``4
     d)    <~!-'        \^`\  `   n
     M"                           \
     M.          !: uu<            ;
     M@ @        !$$$$!:           r
       h?M  <.`.`t$$$$X".( /< xh   >
        "M <`:x~NX$$$$Ub>*cXW !X   L
         M `X!@k:$$$$$$$r $$$Lr    M
         M   '9$$$$$$$$$$$$$F"     4
         ~    ?$$$x$$$$$$$$P        M
        h      !$$$d%m@$$"f          L
        *        #$$$$$)$:>           ":,
         x      ` `#$R!$\!  :            "\._
          h   < < !..!JR  ~<<             -n.`\
       ..x**  < 'ouk!!$f~  <<   ...         ^*.;
   ....( !! << \NdC*$@$><~  << !!!:!!<.       "M
  xJ"<!!<!~<<<dNeRV$$$R    <<< !!!!!!:<:       `M
  M%<!!!! <<~:`(3$$$R?<<<<<<~< !!?!:<<<<<       M
  M<<!!!!' :<<:x$$$!!<<<<<<<<.!~:~<<<<<<<   k   M
 n!<<<!   <<<~<$$$?~ '<<<<<<:'.!`<<<<<~ ~  :|  /
 M<<<<   '  ~ <$$R?.  `<~   <'!<<< <<<< ~  ;/ z
 "<<<<<  : < <  M#!    <<   <<   <<<<<<h> / v'
  <<<<<>< <~<<   .uoN :<<<  <<  <<<<<<<:eVa
  <<<<<< '<<<    !$$$$<<<<<   :<<<<<<<<<<' )
  <<<<<` < <~     R$$$N      <<<<<<<<<<<<e~
  <<< <   `        $$$$$.    ~``~<<<<<< x"
  k<<<<            `$$$$$b   :<<<<`<<<<MC
  M<<<<             "$$$$$!<< :<`~<<!<d""
  f<<<<:             #$$$$!<<<<~<:<<<<M
 P<<<:<<~  :          #$$?~ <<   <`<<tM
 <<<<~:~`<<<<::        "`   `<     ~MJ>
 :<< ~:<<<<<::.                  ..<$f
 M  <<<<<<:!XN$$$bu.        ..uo$#3$!4M
  x  <<~  !!#$$$$$$$$$eiL.d$$$#\Le$!!XP
  '.       !!!!??#$$$$$$$$$$$****#?XMr
    `-.            ```~""!!!!!!XXnHC
       `-'\               '"*xd
*/

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

int main(){
  int p=0;
  int ans[15];
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); ++i)
  {
    if (s[i]=='0'){
      ans[p]=0;
      p++;
    }if (s[i]=='1')
    {
      ans[p]=1;
      p++;
    }if (s[i]=='B')
    {
      p--;
      if (p<0){
        p=0;
      }
    }
  }
  if (p<1)printf("");
  else{
    for (int i = 0; i < p; ++i)
    {
      cout<<ans[i];
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

struct edge {
  int to;
  ll cost;
  edge(int t, ll c): to(t), cost(c) {};
};

using P = pair<ll, int>;

vector<ll> d;
vector<int> par;
void dijkstra(int s, int N, vector<vector<edge>>& G) {
  priority_queue<P, vector<P>, greater<P>> que;
  d = vector<ll>(N, longinf);
  par = vector<int>(N, -1);
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;

    for(int i=0; i<(int)G[v].size(); i++) {
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        par[e.to] = v;
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; ll s; cin >> n >> m >> s;
  int mx = 10000;
  vector<int> U(m), V(m), A(m);
  vector<ll> B(m), C(n), D(n);
  rep(i, m) {
    cin >> U[i] >> V[i] >> A[i] >> B[i];
    U[i]--; V[i]--;
  }
  rep(i, n) cin >> C[i] >> D[i];
  vector<vector<edge>> G(n*mx);
  rep(i, m) {
    rep(j, mx) {
      if(j < A[i]) continue;
      G[U[i]*mx+j].push_back({V[i]*mx+j-A[i], B[i]});
      G[V[i]*mx+j].push_back({U[i]*mx+j-A[i], B[i]});
    }
  }
  rep(i, n) {
    rep(j, mx) {
      G[i*mx+j].push_back({i*mx+(int)min(j+C[i], (ll)mx-1), D[i]});
    }
  }
  dijkstra((int)min(s, (ll)mx-1), n*mx, G);
  rep(i, n) {
    if(i == 0) continue;
    cout << *min_element(d.begin()+i*mx, d.begin()+(i+1)*mx) << endk;
  }
  return 0;
}


Measured memory_bytes: 87640
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
M = a[0]
g = a[0]
for i in range(1,n):
    M = max(M,a[i])
    g = gcd(g,a[i])
if k <= M and k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16280
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, H := getInt(), getInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i], b[i] = getInt(), getInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	maxA := a[len(a)-1]
	ans := (H + maxA - 1) / maxA
	sum := 0
	pos := len(b) - 1
	cnt := 0
	for i := pos; i >= 0; i-- {
		sum += b[i]
		cnt++
		rest := max(0, H-sum)
		ans = min(ans, cnt+(rest+maxA-1)/maxA)
	}

	out(ans)
}


Measured memory_bytes: 5248
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
	
int main() {
	int n;
	vector<int> b;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int tmp;
		scanf("%d", &tmp);
		b.push_back(tmp);
	}
	int sum = b[0];
	for (int i = 1; i < n - 1; i++) {
		if (b[i - 1] < b[i]) {
			sum += b[i - 1];
		}
		else {
			sum += b[i];
		}
	}
	sum += b[n - 2];
	printf("%d\n", sum);
	return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
	vector<int64> M(5);
	REP(i, 5) cin >> M[i];
	int64 res = 0;
	sort(all(M));
	REP(i, 5) {
		res += M[i];
		if (M[i] % 10 != 0) res += 10-M[i]%10;
	}
	int64 maxi = 0;
	REP(i, 5) {
		if (M[i]%10 != 0)
			maxi = max(maxi, 10-M[i]%10);
	}
	cout << res-maxi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

// int gs[256][256];
bool used[256][256];

int main(){
	
	int n; cin >> n;
	vector<pair<int, int>> rot;
	vector<pair<int, int>> blau;

	for( int i = 0; i < n; ++i ){
		int a, b; cin >> a >> b;
		rot.emplace_back(a, b);
	}
	for( int i = 0; i < n; ++i ){
		int c, d; cin >> c >> d;
		blau.emplace_back(c, d);
		/*
		++gs[0][0]; ++gs[c][d];
		--gs[c][0]; --gs[0][d];
		*/
	}
	
	/*
	for( int j = 0; j <= 2*n; ++j ){
		for( int i = 0; i <= 2*n; ++i ){
			gs[i+1][j] += gs[i][j];
		}
	}
	for( int i = 0; i <= 2*n; ++i ){
		for( int j = 0; j <= 2*n; ++j ){
			gs[i][j+1] += gs[i][j];
		}
	}
	*/
	
	int ans = 0;
	
	sort( blau.begin(), blau.end(), []( const auto &x, const auto &y ){ return x.first < y.first; } );
	for( auto bp : blau ){
		vector<pair<int, int>> redcandy;
		for( auto rp : rot ){
			if( rp.first < bp.first && rp.second < bp.second && !used[rp.first][rp.second] ){
				redcandy.emplace_back( rp.first, rp.second );
			}
		}
		if( !redcandy.empty() ){
			sort( redcandy.begin(), redcandy.end(), []( const auto &x, const auto &y ){ return x.second > y.second; } );
			used[redcandy[0].first][redcandy[0].second] = true;
			++ans;
		}
	}
	
	cout << ans << endl;
	return 0;
}

	/*
	for( int i = 0; i <= 2*n; ++i ){
		for( int j = 0; j <= 2*n; ++j ){
			cout << gs[i][j];
		}
		cout << endl;
	}
	*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll> p(N);
    rep(i, N) cin >> p[i];

    sort(p.begin(), p.end(), greater<ll>());
    ll ans = p[0] / 2;
    reps(i, 1, N) { ans += p[i]; }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

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

	int X;

	cin >> X;

	int num = X / 100;
	int amari = X % 100;

	int a_num = amari / 5;
	if(a_num * 5 != amari) {
		a_num++;
	}

	if(a_num <= num) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
			
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,t;
  l = 2*i;
  r = 2*i+1;

  if(l<=H&&A[l] > A[i]) largest = l;
  else largest = i;
  if(r<=H&&A[r] > A[largest]) largest = r;

  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i,int key){
  int t;
  if(key <A[i]) return;
  A[i] = key;
  while(i>1&&A[i/2]<A[i]){
    t = A[i];
    A[i] = A[i/2];
    A[i/2] = t;
    i = i/2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H,key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}



Measured memory_bytes: 5668
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll M;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll sm=0,dsm=0;
	cin>>M;
	REP(i,M){
		ll d,c;
		cin>>d>>c;
		dsm+=c;
		sm+=d*c;
	}
	cout<<dsm-1+(sm-1)/9<<endl;
}

Measured memory_bytes: 256
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]

x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
else:
    xl = []
    for i in range(0, m-1):
        xl.append(x[i+1] - x[i])
    xl.sort(reverse = True)
    del xl[:n-1]
    print(sum(xl))

Measured memory_bytes: 13964
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

r2[a,b]=(a,b)
inf=maxBound`div`2
main=do
    [n,w]<-map read.words<$>getLine
    wvs<-UV.replicateM n $ r2.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f w wvs
f::Int->UV.Vector (Int,Int)->Int
f w wvs = UV.length $ UV.takeWhile(<=w) $ UV.foldl' p (UV.replicate 100000 inf) wvs where
    p v0 (wi,vi) = UV.zipWith min v0 (UV.replicate vi wi UV.++ UV.map (+wi) v0)


Measured memory_bytes: 4604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 300010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inv(ll a) {
    return modpow(a, mod-2);
}

ll fact[MAX_N];
ll invfact[MAX_N];

// main関数でinit()を呼び出してからComb()を使用する
void init() {
    fact[0] = 1;
    invfact[0] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inv(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}
 
int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
 
    init();
    
    ll ans = 0;
    for(ll i = b; i < w; i++) {
        ans += (Comb(h-a-1+i, h-a-1) * Comb(w+a-2-i, w-1-i))%mod;
        ans %= mod;
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static int gcm( final int n, final int m ) {

	if ( n < m ) {
	    return gcm( m, n );
	} else if( m == 0 ) {
	    return n;	    
	} else {
	    return gcm( m, n % m );
	}
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNextInt() ) {

	    final int n = stdin.nextInt();
	    final int m = stdin.nextInt();

	    System.out.println( gcm( n, m ) );
	    
	}	
    }    
}

Measured memory_bytes: 17208
n=int(input())
l=list(map(int,input().split()))
freq={}
for i in range(n):
	freq[l[i]]=0
for i in range(n):
	freq[l[i]]+=1
t=int(input())
sm=sum(l)
for i in range(t):
	a,b=map(int,input().split())
	if(a not in freq.keys()):
		print(sm)
	else:
		if(b not in freq.keys()):
			freq[b]=0
		#diff=abs(freq[b]-freq[a])
		sm=sm-a*freq[a]+b*freq[a]
		freq[b]+=freq[a]
		freq[a]=0
		print(sm)


Measured memory_bytes: 85344
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n];
    int s = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s += a[i];
    }
    // s /= 4;
    // s /= m;
    int x = 0;

    for(int i=0;i<n;i++){
        if(a[i] * 4ll * m >= s){
            x++;
        }
    }
    if(x >= m){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
    
}



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

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] ss = br.readLine().split(" ");

		int[] S = new int[n];

		for (int i = 0; i < n; i++) {
			S[i] = Integer.parseInt(ss[i]);
		}

		int q = Integer.parseInt(br.readLine());

		String[] qq = br.readLine().split(" ");

		int[] Q = new int[q];

		for (int i = 0; i < q; i++) {
			Q[i] = Integer.parseInt(qq[i]);
		}

		System.out.println(binarySearch(S, Q));

	}

	static int binarySearch(int[] nums, int[] key) {

		int i = 0;

		int count = 0;

		while (i != key.length) {

			int left = 0;

			int right = nums.length;

			while (left < right) {

				int mid = (left + right) / 2;

				if (nums[mid] == key[i]) {
					count++;
					break;
				} else if (nums[mid] > key[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			i++;

		}

		return count;

	}

}

Measured memory_bytes: 47636
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
//template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int di[4] = {0, 1, 0, -1};
const int dj[4] = {1, 0, -1, 0};

vector<long long> dijkstra(const vector<vector<pair<int, long long>>> &G, int s){
    struct RadixHeap {
        using P = pair<long long, int>;
        int bsr(long long x){ return (x == 0) ? -1 : 63-__builtin_clz(x); }
        vector<P> v[65];
        long long last, sz;
        RadixHeap() : last(0), sz(0) { }
        bool empty () { return (sz == 0); }
        void push(long long x, int u) { sz++; v[bsr(x^last)+1].emplace_back(x, u); }
        P pop () {
            if (!v[0].size()) {
                int i = 1;
                while (!v[i].size()) { i++; }
                last = min_element(v[i].begin(), v[i].end())->first;
                for (auto x : v[i]) { v[bsr(x.first^last)+1].emplace_back(x); }
                v[i].clear();
            }
            P res = v[0].back(); sz--; v[0].pop_back(); return res;
        }
    };
    const long long inf = INT64_MAX;
    vector<long long> ret(G.size(), inf); ret[s] = 0;
    RadixHeap rh; rh.push(ret[s], s);
    while (!rh.empty()) {
        long long dist; int node;
        tie(dist, node) = rh.pop();
        if (ret[node] < dist) continue;
        for (auto &e : G[node]) {
            int next_node; long long next_dist;
            tie(next_node, next_dist) = e;
            if (ret[next_node] > ret[node] + next_dist){
                ret[next_node] = ret[node] + next_dist;
                rh.push(ret[next_node], next_node);
            }
        }
    }
    return ret;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    vector<vector<pair<int, long long>>> G(H*W);
    for (int i = 0; i < H; i++) cin >> S[i];
    
    auto idx = [&](int i, int j) { return i * W + j; };
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') continue;
            for (int k = 0; k < 4; k++) {
                int s = i + di[k], t = j + dj[k];
                if (s < 0 || H <= s || t < 0 || W <= t) continue;
                if (S[s][t] == '#') continue;
                G[idx(i, j)].emplace_back(idx(s, t), 1);
            }
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '#') continue;
        vector<long long> dist = dijkstra(G, idx(i, j));
        for (int s = 0; s < H; s++) for (int t = 0; t < W; t++) {
            if (S[s][t] != '#') chmax(ans, dist[idx(s, t)]);
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll=long long;

int main(){
    const ll INF=1e9;
    ll n;
    cin >> n;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    vector<ll> dp(n,INF);
    dp[0]=0;
    for(int i=1;i<n;i++){
        if(i==1){
            dp[i]=abs(h[i]-h[i-1]);
            continue;
        }
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        //cout << dp[i] << endl;
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
// A - Haiku

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    int n,k,a;
    cin >> n >> k;
    int pos;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a==1) pos=i+1;
    }
    int ans = (n-pos)/(k-1) + (pos-1)/(k-1);
    int c = (pos-1)%(k-1) + (n-pos)%(k-1) + 1;
    if(c>k) ans += 2;
    else if(c!=1) ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string x;
    cin >> x;
    if(x[0]=='A')cout << 'T' << endl;
    if(x[0]=='T')cout << 'A' << endl;
    if(x[0]=='G')cout << 'C' << endl;
    if(x[0]=='C')cout << 'G' << endl;
    return 0;
}
 
 


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        RGBTriplets solver = new RGBTriplets();
        solver.solve(1, in, out);
        out.close();
    }

    static class RGBTriplets {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] strings = in.next().toCharArray();

            long r = 0;
            long g = 0;
            long b = 0;
            for (int i = 0; i < n; i++) {
                if (strings[i] == 'R') {
                    r++;
                }
                if (strings[i] == 'G') {
                    g++;
                }
                if (strings[i] == 'B') {
                    b++;
                }
            }
            long all = r * g * b;
            long sub = 0;
            for (int i = 0; i < n; i++) {
                char ci = strings[i];

                for (int j = i + 1; j < n; j++) {
                    char cj = strings[j];
                    if (ci == cj) {
                        continue;
                    }
                    int k = 2 * j - i;
                    if (n <= k) {
                        continue;
                    }

                    char ck = strings[k];
                    if (ci == ck || cj == ck) {
                        continue;
                    }
                    sub++;
                }
            }

            out.append(String.valueOf(all - sub));
        }

    }
}



Measured memory_bytes: 36488