akhauriyash/Code-Regression huggingface dataset:
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
ll gc(ll a, ll b){
    if(b == 0) return a;
    return gc(b, a % b);
}
ll lcm(ll a, ll b){
    return (a * b) / gc(a, b);
}
string s, t;
bool check(ll len){
    ll n = s.size();
    ll m = t.size();
    map<ll, char> mp;
    for(ll i = 0; i < n; i++){
        ll idx = i * (len / n) + 1;
        mp[idx] = s.at(i);
    }
    for(ll i = 0; i < m; i++){
        ll idx = i * (len / m) + 1;
        if(!mp.count(idx)){
            mp[idx] = t.at(i);
        }else{
            if(mp[idx] != t[i]){
                return false;
            }
        }
    }
    return true;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n, m;
    cin >> n >> m;
    cin >> s >> t;
    ll d = lcm(n, m);
    ll lo = 0, hi = 1e9;
    while(hi - lo > 1){
        ll mid = lo + hi >> 1;
        if(check(mid * d)) hi = mid;
        else lo = mid;
    }
    if(hi == 1e9){
        cout << -1;
    }else{
        cout << hi * d;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main(){
  int N;
  int ans = 0;
  cin >> N;
  vector<int> vec(N);
  
  for (int i =0;i<N;i++){
   cin >> vec.at(i); 
  }
                
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i= 0;i<N;i++){
   if(i%2 == 0){
     ans += vec.at(i);
   }else{
     ans -= vec.at(i);
   }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,q;
bool r;
string s,sa;

int main(){
    q=-1;
    cin>>s>>sa;
    n=s.size();
    m=sa.size();
    for(int i=0;i<n-m+1;i++){
        r=true;
        for(int j=0;j<m;j++){
            r=r and (s[j+i]==sa[j] or s[j+i]=='?');
        }
        if(r)q=i;
    }
    if(q==-1){
        C "UNRESTORABLE" E;
    }
    else{
        for(int i=0;i<n;i++){
            if(i<q or i>=q+m){
                if(s[i]=='?')C 'a';
                else C s[i];
            }
            else{
                C sa[i-q];
            }
        }
        cout<<endl;
    }
    
    
}

Measured memory_bytes: 256
def insertionSort(A,N):
    print(' '.join([str(a) for a in A]))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(' '.join([str(a) for a in A]))

def run():
    N = int(input())
    A = [int(i) for i in input().split()]
    insertionSort(A,N)

if __name__ == '__main__':
    run()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
    ll keta(ll n){
        ll res = 0;
        while(n){
            res += n % 10;
            n /= 10;
        }
        return res;
    };
int main(){
    ll N,A,B;
    ll ans = 0;
    cin >> N >> A >> B;
    rep(i,N + 1){
        if(keta(i) >= A && keta(i) <= B){
            ans += i;
            //cout << i << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
map<size_t, int> words;

int main(){
	string S;
	int N;
	cin >> N;
	ll count = 0;
	for (int i = 0; i < N; i++) {
		cin >> S;
		sort(S.begin(), S.end());
		count += words[hash<string>()(S)]++;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second

int n;
int a[300000];
deque<int> b;
int main(){
	cin >> n;
	REP(i,n) {
		cin >> a[i];
	}

	bool f = true;
	REP(i,n) {
		if(f) {
			b.pb(a[i]);
		}else{
			b.push_front(a[i]);
		}
		f = !f;
	}

	if(f) {
		REP(i,n) {
			cout << b[i] << " ";
		}
	}else{
		RREP(i,n) {
			cout << b[i] << " ";
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py[90001];
int d[90001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<s1[0]<<s2[1]<<s3[2]<<endl;
}


Measured memory_bytes: 384
/// You just can't beat the person who never gives up
/// ICPC next year


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
void offset(vector<int>&a,int x) {
    for(int i = 0; i < sz(a);i++) {
        a[i] = x;
    }
}
struct cmp {
    bool operator() (const pair<int,int>& lhs, const pair<int,int>& rhs) const {
        return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
    }
//for map<pii,int>
};


// auto cmp = [](pair<int,int>a,pair<int,int>b) {if(a.first==b.first)return a.second>b.second;
//      else return a.first > b.first;
//  };
//  multiset<pair<int,int>,decltype(cmp)>fc(cmp);
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
    return sqrt(1. * pow(x-z,2) + 1. * pow(y-w,2));
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    //unordered_map<long long, int, custom_hash> safe_map;
};

const int MAXN = 2e5+ 10;

#define int long long
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss > p2.ss;
}
int32_t main() {
    fio
    string s ;
    cin >> s;
    cout << string(s.size(),'x') << endl;

    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 3796
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, K) = Read2Longs();
            var h = new long[N];
            for (var i = 0; i < N; i++)
            {
                h[i] = ReadLong();
            }
            h = h.OrderBy(x => x).ToArray();
            var min = h[K - 1] - h[0];
            for (var i = 1; i < N - K + 1; i++)
            {
                var sa = h[K + i - 1] - h[i];
                if (sa < min)
                {
                    min = sa;
                }
            }
            return min;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 36808
#include <bits/stdc++.h>
using namespace std;
int x,y;
long long f[111111]={1LL};
int main(){
    cin>>x>>y;
    if(x>y)swap(x,y);
    if(y-x>1){
        cout<<0;
        return 0;
    }
    for(int i=1;i<=y;i++){
        f[i]=f[i-1]*i;
        f[i]%=1'000'000'007;
    }
    if(y==x){
        cout<<2*f[x]*f[y]%1'000'000'007;
    }
    else{
        cout<<f[x]*f[y]%1'000'000'007;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

bool ok=true;
ll n,m;
ll visit[100010]={};
pair<ll,ll> p[100010];
V<ll> s,t,v[100010],c[100010];
vector<ll> ans;

// 連結成分に対して全域木から構成
int f(int x, int par_edge){
	int sum=t[x];
	// 行き
	rep(i,v[x].size()){
		ll y = v[x][i];
		if(visit[y]==0){
			visit[y]=visit[x]+1;
			sum += f(y,c[x][i]);
		}
	}
	sum%=2;
	// 帰り　親の辺を切るかどうか
	if(sum==0){
		return 0;
	}else{
		ans.push_back(par_edge);
		return 1;
	}
}

void init(){
	cin>>n>>m;
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		p[i]={a,b};
	}
	p[n]={0,0};  // 番兵
	p[n+1]={1e9+1,0};  // 番兵
	sort(p,p+n+2);
	reg(i,0,n+1){
		s.push_back(p[i].first);
		t.push_back(p[i].second);
	}
	reg(i,0,n){  // 差分化
		if(t[i]!=t[i+1]){
			t[i]=1;
		}else{
			t[i]=0;
		}
	}
	// cerr<<"===S==="<<endl;
	// print(s);
	reg(i,1,m){
		ll l,r;
		cin>>l>>r;
		auto itr = prev(upper_bound(s.begin(), s.end(), r));  // 右端
		auto itl = prev(lower_bound(s.begin(), s.end(), l));  // 左端
		ll ri=itr-s.begin();
		ll li=itl-s.begin();
		// cerr<<li<<","<<ri<<endl;
		if(li>=ri)continue;
		v[ri].push_back(li);
		v[li].push_back(ri);
		c[ri].push_back(i);
		c[li].push_back(i);
	}
}

int main(void){
	init();
	reg(i,0,n){  // 番兵がいるので
		if(visit[i]==0){
			visit[i]=1;
			if(f(i,-1)!=0)ok=false;
		}
	}
	if(ok){
		sort(ans.begin(),ans.end());
		cout<<ans.size()<<endl;
		print(ans);
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 30428
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int count[30];
	for (int i = 0; i < 30; i++) {
		count[i] = 0;
	}
	int n;char s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		count[s - 'A']=1;
	}
	int ans = 0;
	for (int i = 0; i < 30; i++) {
		if (count[i] == 1) {
			ans++;
		}
	}
	if (ans == 3) {
		cout << "Three" << endl;
	}
	else if (ans == 4) {
		cout << "Four" << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(){
    int N,K;
    cin>>N>>K;

    vector<int> snuke(N,0);

    for(int i=0; i<K; i++){
        int d;
        cin>>d;
        for(int j=0; j<d; j++){
            int a;
            cin>>a;
            a--;
            snuke[a]++;
        }
    }

    int cnt = 0;

    for(int i=0; i<N; i++){
        if(snuke[i] == 0) cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

void visit(int);
int G[101][101];
int d[101],f[101],color[101],time,n;

void visit(int v){
  int i;
  color[v]=1;
  d[v]=++time;
  for(i=0;i<n;i++){
    if(G[v][i]==1){
      if(color[i]==0) visit(i);
    }
  }
  color[v]=2;
  f[v]=++time;
}

int main(){

  int i,j,v1,v2,m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    color[i]=0;
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }

  time=0;

  for(i=0;i<n;i++){
    scanf("%d%d",&v1,&m);
    for(j=0;j<m;j++){
      scanf("%d",&v2);
      G[v1-1][v2-1]=1;
    }
  }

  for(i=0;i<n;i++){
    if(color[i]==0) visit(i);
  }

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

Measured memory_bytes: 636
N,A,B=input().split()
ANS=int(N)//(int(A)+int(B))
ANS=ANS*int(A)
if(int(N)%(int(A)+int(B))<=int(A)):
   ANS=ANS+(int(N)%(int(A)+int(B)))
else:
   ANS=ANS+int(A)
print(ANS)

Measured memory_bytes: 3060
S = input()
# print(S)
# print(len(S))
list = []
for i in range(len(S)):
    if(S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T"):
        list.append(i)
# print(list)
NUM = []
for j in range(len(list)):
    num = 1
    for k in range(j,len(list)-1):
        # print("k:",k)
        # print("list[j+1]:",list[j+1], "list[j]:", list[j])
        # print("list[k+1]:",list[k+1], "list[k]:", list[k])
        if(list[k+1] - list[k] == 1):
        # if(list[j+1] - list[j] == 1):
            num += 1
            # print("k1:",k)
        else:
            NUM.append(num)
            # print("NUM1:", NUM)
            break
    else:
        NUM.append(num)
        # print("NUM2:", NUM)

# print("NUM3:",NUM)
if(len(NUM) == 0):
    print(0)
else:
    print(max(NUM))



Measured memory_bytes: 3064
#include <stdio.h>

/*
  出す数字は1から順に3の倍数もしくは十進の桁の中に3があるか否か
  nまで
*/ 
int
chk_inc3 (int x)
{
        while (x) {
                if (x % 10 == 3) return 1;
                x /= 10;
        }
        return 0;
}

void
call (int n)
{
        int i, tmp;
        
        for (i = 1; i <= n; i++)
                if ((i % 3 == 0) || chk_inc3(i))
                        printf(" %d", i);
}

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

        scanf("%d", &n);
        call(n);
        printf("\n");
        return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i <= A; i++) {
			for(int j = 0; j <= B; j++) {
				for(int k = 0; k <= C; k++) {
					if(i*500+j*100+k*50 == X) cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
ll N;
void SOLVE(vector<deque<ll>>&X,vector<ll>&x,vector<ll>&ans,int a){
  ll i;
  REP(i,X.at(a).size())if(X.at(a).at(i)!=x.at(a)){
    x.at(X.at(a).at(i))=a;
    ans.at(X.at(a).at(i))+=ans.at(a);
    SOLVE(X,x,ans,X.at(a).at(i));
  }
}
signed main(){
  ll Q,i,a,b;cin>>N>>Q;
  vector<ll>ans(N,0),oya(N);
  vector<deque<ll>>KI(N,deque<ll>());
  REP(i,N-1){
    cin>>a>>b;
    KI.at(a-1).push_back(b-1);
    KI.at(b-1).push_back(a-1);
  }
  REP(i,Q){
    cin>>a>>b;ans.at(a-1)+=b;
  }
  SOLVE(KI,oya,ans,0);
  REP(i,N)cout<<ans.at(i)<<endl;
  return 0;
}

Measured memory_bytes: 158592
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でｂの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main (){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=a;i<=min(a+k-1,b);i++){
        cout<<i<<endl;
    }
    for(int i=max(a+k,b-k+1);i<=b;i++){
        cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdint>
using namespace std;

const uint64_t kP = 1000000007;

uint64_t mmul(uint64_t a, uint64_t b, uint64_t p) {
  return ((a % p) * (b % p)) % p;
}

uint64_t mpow(uint64_t a, uint64_t e, uint64_t p) {
  uint64_t ret = 1;
  uint64_t m = a;
  while (e) {
    if (e & 1) {
      ret = (ret * m) % p;
    }
    m = (m * m) % p;
    e >>= 1;
  }
  return ret;
}

uint64_t mdiv(uint64_t a, uint64_t b, uint64_t p) {
  return ((a % p) * mpow(b % p, p - 2, p)) % p;
}

void pathvec(vector<uint64_t> & vec, uint64_t h) {
  vec[0] = 1;
  for (uint64_t i = 1; i < vec.size(); ++i) {
    vec[i] = mdiv(mmul(vec[i-1], h + i, kP), i, kP);
  }
}

int main()
{
  uint64_t h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<uint64_t> low(w);
  vector<uint64_t> high(w);
  pathvec(low, a - 1);
  pathvec(high, h - a - 1);
  uint64_t ans = 0;
  for (uint64_t i = b; i < w; ++i) {
    ans = (ans + mmul(high[i], low[w - i - 1], kP)) % kP;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
INF = float("inf") #const

def main():
    n = int(input())
    ls = [list(map(int,input().split())) for _ in range(n)]
    #start ls[i][0] - ls[i][1]. goal ls[i][0] + ls[i][1]
    robot = [(ls[i][0] + ls[i][1],ls[i][0] - ls[i][1]) for i in range(n)]
    robot = sorted(robot,key = lambda x: x[0])
    #(goal,start)

    ans = 0; latest = -INF
    for i in range(n):
        if latest <= robot[i][1]:
            ans += 1
            latest = robot[i][0]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 43560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    map<int,int> mp;
    rep(i,n)mp[a[i]]++;
    int ans = 0;
    rep(i,n){
        int flag = 1;
        if(mp[a[i]]!=1)continue;
        if(a[i]==1){
            ans += 1;
            continue;
        }
        if(mp[1]>0)continue;
        for(int j=2;j*j<=a[i];j++){
            if(a[i]%j==0){
                if(mp[j]!=0)flag=0;
                if(mp[a[i]/j]!=0)flag=0;
            }
        }
        //if(flag==1)cout << a[i] << endl;
        ans += flag;
    }
    cout << ans << endl;
}

Measured memory_bytes: 32788
x,k,d=map(int,input().split())

k_min=abs(x//d)
if k_min>=k:
  k_min=k
if x>0:
  d_min=x-((k_min)*d)
else:
  d_min=x+((k_min)*d)

dk=k-k_min
if dk%2==0:
  print(abs(d_min))
else:
  print(min(abs(d_min+d),abs(d_min-d)))

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

typedef long in; 
 
int main() 
{
    in n,c;
    cin>>n>>c;
    
    in v[n+1],w[n+1],mak=1e15;
    
    for(in i=1;i<=n;i++)
    cin>>w[i]>>v[i];
    
    in maxval=1000*n;
    
    in dp[n+1][maxval+1];
    
    for(in i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    
    for(in j=0;j<=maxval;j++)
    {
        dp[0][j]=mak;
    }
    
    dp[0][0]=0;
    
    for(in i=1;i<=n;i++)
    {
        for(in j=0;j<=maxval;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=v[i])
            {
                if(dp[i-1][j-v[i]]!=mak)
                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
            }
        }
    }
    
    in ans=0;
        
    for(in i=1;i<=maxval;i++)
    {
        if(dp[n][i]<=c)
        {
            ans=i;
        }
    }
    
    cout<<ans;
		
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

vector<vector<int>> V;
int N, M, Q;


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    long long sum = 0;
    for (int i = 0; i < k; i++) sum += a[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define N 200005
#define M 1000000007
#define ll long long
#define ldb long double
#define pi acos(-1)
using namespace std;
ll n,k,l,r,a[N],b[N],ans,sum,ans1;
char s[N],t[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	b[0]=a[0];
	for(int i=1;i<n;i++)
	b[i]=(b[i-1]+a[i])%M;
	for(int i=1;i<n;i++)
	ans=(ans+a[i]*b[i-1])%M;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6652
#include<cstdio>
#include<cstdlib>
static const int MAX = 90001;
static const int N = 100000;

int main()
{
    int H, W, D, A, Q, L, R;
    int px[MAX], py[MAX], d[MAX];

    scanf("%d%d%d", &H, &W, &D);

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            scanf("%d", &A);
            px[A] = i;
            py[A] = j;
        }
    }

    for (int k = 1; k <= D; k++)
    {
        d[k] = 0;
    }
    for (int k = D + 1; k <= H * W; k++)
    {
        d[k] = d[k - D] + abs(px[k] - px[k - D]) + abs(py[k] - py[k - D]);
    }

    scanf("%d", &Q);

    for (int i = 1; i <= Q; i++)
    {
        scanf("%d%d", &L, &R);
        printf("%d\n", d[R] - d[L]);
    }

    return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    String a = sc.next();
    String b = sc.next();

      if (a.equals(b)){
      System.out.println("H");
      }
      else {
        System.out.println("D");
      }

  }
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;
    int count = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int sum = 500 * i + 100 * j + 50 * k;
                if (sum == X) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N, count[210], an = 0;
	scanf("%d", &N);
	for (int i = 1; i <= N; i += 2) {
		count[i] = 0;
		for (int j = 1; j <= N; j++) {
			if (i % j == 0) {
				count[i]++;
			}
		}
		if (count[i] == 8) {
			an++;
		}
	}
	printf("%d", an);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	ll ans = 1e18, sum = 0;
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	rep(i, n) sum += v[i];
	ll a = 0;
	rep(i, n - 1){
		a += v[i];
		ans = min(ans, abs(a - (sum - a)));
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(void){
  int row, col;
  std::cin >> row >> col;
  std::vector<std::vector<char>> table(row, std::vector<char>(col));
  std::vector<bool> rowB(row);
  std::vector<bool> colB(col);
  
  for(int i=0; i<row; i++){
    for(int j=0; j<col; j++){
      std::cin >> table.at(i).at(j);
      if(table.at(i).at(j) == '#') rowB.at(i) = colB.at(j) = true;
    }
  }
  
  for(int i=0; i<row; i++){
    if(rowB.at(i)){
      for(int j=0; j<col; j++){
        if(colB.at(j)){
          std::cout << table.at(i).at(j);
        }
      }
      std::cout << '\n';
    }
  }
  return 0;
}
      

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#define MAX 500005
 
int H, A[MAX + 1];

void maxHeapify(int i)
{
	int l, r, largest;
	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)
	{
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}
int main()
{
	cin >> H;
	for(int i = 1; i <= H; i++)
		cin >> A[i];
	
	for(int i = H/2; i >= 1; i--)
		maxHeapify(i);
	for(int i = 1; i <= H; i++)
		cout << " " << A[i];
		
	cout << endl;
	
	return 0; 
}



Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
 
int main() {

    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;

    rep(i,k) {
        if(a>=b) {
            b*=2;
        }
        else if(b>=c) {
            c*=2;
        }
    }
    
    if(a<b && b<c) {
        cout<<"Yes"<<endl;
    }
    else    cout<<"No"<<endl;

 return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[200010];
    rep(i, N) cin >> A[i];
    rep(i, N - K) {
        if(A[i] < A[i + K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4436
# https://atcoder.jp/contests/abc149/tasks/abc149_d


N, K = gets.split.map(&:to_i)
R, S, P = gets.split.map(&:to_i)
T = gets.chomp

#machine_hands = T.chars
player_hands = T.tr('rsp', 'prs').chars

score_by_hand = {'r' => R, 's' => S, 'p' => P}
score = 0
player_hands.each_with_index do |hand, index|
  if index - K > -1 and hand == player_hands[index - K]
    if index + K < player_hands.length
      dummy_hand = ('rsp'.chars - [hand, player_hands[index + K]]).first
    else
      dummy_hand = ('rsp'.chars - [hand]).first
    end
    player_hands[index] = dummy_hand
    next
  end
  score += score_by_hand[hand]
end

puts score


Measured memory_bytes: 15356
#include <stdio.h>

int main(){
    int dice_num[7];
    
    int i,j;
    for(i=1; i<=6; i++)
        scanf("%d", &dice_num[i]);
    getchar();
    
    int data_num;
    scanf("%d", &data_num);
    
    int right[7][7];
    right[1][2] = dice_num[3]; right[1][3] = dice_num[5]; 
    right[1][4] = dice_num[2]; right[1][5] = dice_num[4];
    right[2][1] = dice_num[4]; right[2][3] = dice_num[1]; 
    right[2][4] = dice_num[6]; right[2][6] = dice_num[3];
    right[3][1] = dice_num[2]; right[3][2] = dice_num[6]; 
    right[3][5] = dice_num[1]; right[3][6] = dice_num[5];
    right[4][1] = dice_num[5]; right[4][2] = dice_num[1]; 
    right[4][5] = dice_num[6]; right[4][6] = dice_num[2];
    right[5][1] = dice_num[3]; right[5][3] = dice_num[6]; 
    right[5][4] = dice_num[1]; right[5][6] = dice_num[4];
    right[6][2] = dice_num[4]; right[6][3] = dice_num[2]; 
    right[6][4] = dice_num[5]; right[6][5] = dice_num[3];
    
    int up, front;
    for(i=0; i<data_num; i++){
        scanf("%d %d", &up, &front);
        for(j=1; j<=6; j++){
            if(up == dice_num[j]) up = j;
            if(front == dice_num[j]) front = j;
        }
        printf("%d\n", right[up][front]);
    }
}



Measured memory_bytes: 2108
#include <iostream>
#define ll long long
using namespace std;

ll gcd(ll a, ll b){
	ll r = a%b;

	while(r > 0){
		a = b;
		b = r;
		r = a%b;
	}
	return b;
}

int main(){
	ll K;cin>>K;
	ll ans=0;
	ll check=0;

	for(int i=1;i<=K;i++){
		for(int j=1;j<=K;j++){
			check = gcd(i, j);
			for(int k=1;k<=K;k++){
				ans += gcd(check,k);
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

map<LP, ll> memo;

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    LP p(a, b);
    if(memo.find(p) != memo.end()) return memo[p];
    return memo[p] = gcd(b, a % b);
}

int main() {
    int N;
    cin >> N;
    ll ans;
    cin >> ans;
    rep(i, N - 1) {
        ll t;
        cin >> t;
        ans = ans / gcd(ans, t) * t;
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;

    double x = N / 1.08;
    int x_min = floor(x);
    int x_max = ceil(x);

    int x_tmp = x_min;
        
    while(x_tmp <= x_max){
        if (int(x_tmp*1.08)==N){
            cout << x_tmp << endl;
            return 0;
        }
        x_tmp += 1;
    }
    cout << ":(" << endl;
    return 0;

}

Measured memory_bytes: 3528
#include <stdio.h>

int main()
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if ((a <= c && c <= b) || (b <= c && c <= a)) {
		puts("Yes");
	}
	else {
		puts("No");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    mat a(N,vec(N));
    rep(i,N) rep(j,N) cin>>a[i][j];

    rep(k,N){
        rep(i,N){
            rep(j,N){
                if(a[i][j] > a[i][k] + a[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }
    }

    vp way((N-1)*N/2);
    ll id = 0;
    reps(i,1,N){
        rep(j,i){
            way[id++] = mp(a[i][j], i*N + j);
        }
    }
    sort(way.begin(), way.end());
    ll ans = 0;
    for(P p : way){
        int i = p.se/N, j = p.se%N;
        bool build = true;
        rep(k,N){
            if(k == i || k == j) continue;
            if(a[i][j] == a[i][k] + a[k][j]) build = false;
        }
        if(build) ans += a[i][j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(a>=b) b*=2,k--; 
	while(b>=c) c*=2,k--;
	k>=0?cout<<"Yes":cout<<"No";
	return 0;
}


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func main(){
    a := nextInt()
    b := nextInt()
    c := nextInt()
    if (a < b && b < c){
    	fmt.Printf("Yes\n")
    } else {
    	fmt.Printf("No\n")
    }
}

/* templates */

func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func Abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000

int main() {
	
	int N,M;
	cin>>N>>M;
	int S = 0;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		S+=A[i];
	}
	
	sort(A.rbegin(),A.rend());
	
	if(A[M-1]*4*M<S){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>

int main()
{
	int n;

	std::cin >> n;

	double x1,y1,x2,y2,x3,y3,xp,yp,r;

	for(int i=0;i<n;++i)
	{
		std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		xp = 1.0*((x1*x1+y1*y1)*(y2-y3)+(x2*x2+y2*y2)*(y3-y1)+(x3*x3+y3*y3)*(y1-y2))/(2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));

		yp = 1.0*((x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2))/(2*(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2)));

		double a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

		double b = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));

		double c = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));

		r = a*b*c/(sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)));

		printf("%.3f %.3f %.3f\n",xp,yp,r) ;
	}
}

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

int main() {
  int a, b, c;
  while(cin >> a >> b >> c) {
    int d = 0;
    for(int i = 1; i <= 10; ++i) {
      if(i == a || i == b || i == c) continue;
      d += ( a+b+i <= 20 );
    }
    if(2*d >= 7) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    unsigned long N;
    cin>>N;

    if(N%2==1){
        cout<<0<<endl;
        return 0;
    }

    unsigned long answer = 0;
    unsigned long pow5 = 10;
    for(int i=0; i<log(N)/log(5); ++i){
        answer += N / pow5;
        pow5 *= 5;
    }
    cout<<answer<<endl;

    return 0;
}




Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<pair<ll,ll>> r(n+2);
    rep(i,n+1)cin >> a[i];
    r[n].first = r[n].second = a[n];
    for(int i=n-1;i>=0;i--){
        r[i].first = (r[i+1].first+1)/2 + a[i];
        r[i].second = r[i+1].second + a[i];
    }
    if(r[0].first > 1){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll cur = 1;
    for(int i=0;i<=n;i++){
        ans += cur;
        cur -= a[i];
        cur = min(cur*2,(ll)r[i+1].second);
    }
    cout << ans << endl;
}

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

int main()
{
  int n,k;
 string s;
  cin >> n >> s >> k;
  
	char c = s[k-1];
  
  for (int i = 0;i < s.length(); i++)
  {
  	if (s[i] != c)
		s[i] = '*';
  }
  cout << s << endl;
}

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


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b>> c;
    if(a==b)
    {
        if(c!=a)
        {
            cout << "Yes" << endl;
        }else cout << "No" << endl;
    }else{
        if(c==a||c==b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    int N;
    cin >> N;
    
    bool flag = true;
    int t_prev = 0;
    int x_prev = 0;
    int y_prev = 0;

    for(int i = 0; i < N; i++){
        int t, x, y;
        cin >> t >> x >> y;
        
        int move = abs(x - x_prev) + abs(y - y_prev);
        if(move > t - t_prev ) flag = false;
        else{
            if ((t - t_prev - move) % 2 == 1){
                flag = false;
            }
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
plan = [0] + list(map(int,input().split())) + [0]
costs = []
for i in range(1,n+1):
    costs.append((abs(plan[i]-plan[i-1]),abs(plan[i]-plan[i+1]),abs(plan[i+1]-plan[i-1])))
total = 0
for i in range(1,n+2):
    total += abs(plan[i]-plan[i-1])
for cost in costs:
    print(total - cost[0] - cost[1] +cost[2])

Measured memory_bytes: 26016
import sys
N, Y = [int(v) for v in input().split()]
Y //= 1000
#10, 5, 1
for m in range(N + 1):
    for g in range(N + 1):
        s = N - (m + g)
        if s < 0:
            continue
        if m * 10 + g * 5 + s == Y:
            print(m, g, s)            
            sys.exit(0)
print(-1, -1, -1)


Measured memory_bytes: 2940
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(mut x: i64, mut y: i64) -> i64 {
    while y != 0 {
        let r = x % y;
        x = y; y = r;
    }
    x
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! { a: [i64] }
    let mut a = a;
    a.sort();
    let mut ans = 1;
    for (i, &a) in a.iter().enumerate() {
        ans = ans * gcd(a, i as i64) % 998244353;
    }
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<long long> a(n); REP(i, n) cin >> a[i];
  FOR(i, 1, n) a[i] += a[i-1];
  vector<long long> sum(n*(n+1)/2);
  int index = 0;
  REP(i, n) {
    sum[index] = a[i];
    ++index;
  }
  REP(i, n) {
    FOR(j, i+1, n) {
      sum[index] = a[j] - a[i];
      ++index;
    }
  }
  size_t inde = max_element(ALL(sum)) - sum.begin();
  int bit;
  for (bit = 0; sum[inde] >= (1LL<<bit); ++bit) {}
  long long ans = 0;
  vector<long long> temp(0);
  for (int i = bit-1; i >= 0; --i) {
    int ind = sum.size();
    REP(j, ind) {
      if (sum[j] & (1LL<<i)) {
        temp.push_back(sum[j]);
      }
    }
    if (temp.size() >= k) {
      sum = temp;
      ans += 1LL<<i;
    }
    temp.clear();
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5368
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s,t;
    cin>>s>>t;
    bool a=true;
    rep(i,s.size()){
        if(s.at(i)!=t.at(i)) a=false;
    }
    if(a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636