akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];


int atcoder(){
    int n;
    cin>>n;
    Vi a(n),b;
    REP(i,0,n) cin>>a[i];
    REP(i,0,n){
        bool check = false;
        for(int i=(int)a.size()-1; i>=0; --i){
            if(a[i]==i+1){
                b.push_back(a[i]);
                a.erase(a.begin()+i);
                check=true;
                break;
            }
        }
        if(check) continue;
        else break;
    }
    if(b.size()==n){
        reverse(ALL(b));
        REP(i,0,n)cout<<b[i]<<ENT;
    }else{
        cout << -1 << ENT;
    }
    
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#define mod 1000000007

using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
	ll m=a,n=b;
	ll t;
	while(a%b!=0){
		t=b;
		b=a%b;
		a=t;
	}
	//最小公倍数 
	return m/b*n;
}

int main() {
	ll n;
	scanf("%lld",&n);
	ll a,b;
	scanf("%lld",&a);
	for(int i=2;i<=n;i++){
		scanf("%lld",&b);
		a=gcd(a,b);
	}
	printf("%lld",a);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int func(int,int,int);
int main(void)
{
	int y1,m1,d1,y2,m2,d2;
	int x1,x2;
	while(1)	{
		scanf("%d %d %d %d %d %d",&y1,&m1,&d1,&y2,&m2,&d2);
		if(y1<0 || m1<0 || d1<0 || y2<0 || m2<0 || d2<0)	break;
		x1=func(y1,m1,d1);
		x2=func(y2,m2,d2);
		printf("%d\n",x2-x1);
	}
	return 0;
}
int func(int y,int m,int d)
{
	int i,j,sum;
	int mo[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	sum=0;
	for(i=0;i<y;i++)	{
		sum+=365;
		if(i%400==0 || (i%100!=0 && i%4==0))	sum++;
	}
	for(i=1;i<m;i++)	{
		sum+=mo[i];
		if(i==2)	{
			if(y%400==0 || (y%100!=0 && y%4==0))	sum++;
		}
	}
	sum+=d;
	return sum;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	
	int a,b,c,d,ans=0;
	cin>>a>>b>>c>>d;
	if(a>b)ans+=b;
	else ans+=a;
	if(c>d)ans+=d;
	else ans+=c;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
A = [(p + 1) / 2 for p in P]
B = [0 for i in range(N)]
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i - 1] + A[i]
ans = 0
for i in range(K - 1, N):
    if i == K - 1:
        a = B[i]
    else:
        a = B[i] - B[i - K]
    if ans < a:
        ans = a
print(ans)


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


int main() {
  int N;
  cin>>N;
  vector<vector<long>> a(10,vector<long>(10));
  for(int i=1;i<=N;i++){
    int t=i;
    int b=i%10;
    while(t>9) t/=10;
    a[t][b]++;
  }
  long ans=0;
  for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) ans+=a[i][j]*a[j][i];
cout<<ans<<endl;
}


Measured memory_bytes: 3612
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

std::vector<std::pair<int64, int64>> prime_fact(int64 n){
  std::vector<std::pair<int64, int64>> result;
  for (int64 i = 2; i * i <= n; ++i){
    if (n % i != 0) continue;
    int cnt = 0;
    while (n % i == 0){
      n /= i; ++cnt;
    }
    result.emplace_back(i, cnt);
  }
  if (n != 1) result.emplace_back(n, 1);
  return result;
}

template<typename T> T gcd(T x, T y) {
  while (y > 0){
    T tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

template<typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0) return 0;
  else return x * y / gcd(x, y);
}


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

  int64 a, b; cin >> a >> b;
  int64 c = gcd(a, b);
  vector<pll> vec = prime_fact(c);
  cout << static_cast<int>(vec.size()) + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  int n;
  set<string> s;

  cin >> n;
  string str;
  for(ii=0;ii<n;ii++){
    cin >> str;
    s.insert(str);
  }

  cout << s.size() << endl;
  
  return 0;
}


Measured memory_bytes: 19252
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#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++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;




int main(){
    string s;
    int k;
    cin >> s >> k;
  	if(s == "z"){cout << "z" << endl;return 0;}
    vector<string> v;
    rep(i, s.size()){
        REP(j, 1, k){
            if(j > s.size())continue;
            v.push_back(s.substr(i, j));
        }
    }
    sort(ALL(v));
    int now = 1;
    vector<string> res;
    int cnt = 0;
    rep(i, v.size()){
      //cout << v[i] << endl;
        if(v[now] == v[i] && i != 0)continue;
        cnt++;
        now = i;
     // cout << cnt << " " << v[now] << endl;
        if(cnt == k)break;
    }
    cout << v[now] << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    if(a==0) cout << b/x + 1 << endl;
    else cout << b/x - (a-1)/x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
using namespace std;
ll n, A;
ll calc(int k) {
	ll tmp = ceil(pow(n, 1.0 / (k + 1)));
	ll ave = 1, ret = A * k + tmp * (k + 1); rep(i, 1, k + 1) ave *= tmp;
	while (ave / tmp * (tmp - 1) >= n) -- ret, ave = ave / tmp * (tmp - 1);
	return ret;
}
int main() {
	scanf("%lld%lld", &n, &A); ll ans = n;
	rep(i, 1, 50) ans = min(ans, calc(i));
	printf("%lld\n", ans); 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N;
//---------------------------------------------------------------------------------------------------
#define yes "Yes"
#define no "No"
string solve() {
    rep(d4, 0, 101) rep(d7, 0, 101) if (d4 * 4 + d7 * 7 == N) return yes;
    return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

if a >= b:
    thres = 0
else:
    thres = b // a

sub = []
for i in range(n-1):
    tmp = x[i+1] - x[i]
    sub.append(tmp)

count = 0
for i in range(n-1):
    if sub[i] <= thres:
        count += sub[i] * a
    else:
        count += b
print(count)

Measured memory_bytes: 14228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word = s.next();
        boolean flag = false;
        for(int i=0;i<word.length()-1;i++){
            if(word.charAt(i)==word.charAt(i+1)){
                flag = true;
                break;
            }
        }
        if(flag) System.out.println("Bad");
        else System.out.println("Good");
    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25232
# Square869120Contest #4 B - Buildings are Colorful!　

import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))


def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see == target:
        return cost

    # 端まで探索したとき
    if i == len(a):
        return float('inf')

    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i + 1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see + 1, i=i + 1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)

    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    can_see += 1
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i + 1)
    # print('cost2', cost2)

    return min(cost1, cost2)


print(dfs(a[0], cost=0, target=K, can_see=1, i=1))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#define MAX 100

typedef struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
}Node;

Node *root, *NIL;

void insert(int);
void inorder(Node *);
void preorder(Node *);

int main(){
    int m,i,k;
    char com[MAX];

    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&k);
            insert(k);
        }else if(com[0]=='p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }   
    return 0;
}

void  insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else x = x->right;
        }

     z->parent = y;//insertした値の親を設定する
     if(y==NIL){  //親がない場合insertした値がそのままroot
         root = z;
     }else {
         if(z->key < y->key){
             y->left = z;
         }else {
             y->right = z;
         }
         }
     }

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}



Measured memory_bytes: 25172
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll INF = 1e18;
typedef vector<vector<ll>> Matrix;
void warshall_floyd(Matrix& d) {
  ll n = SZ(d);
  REP(i,n) REP(j,n) REP(k,n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main(){
  ll N,M,R; cin >> N >> M >> R;
  vector<ll> r(R);
  REP(i,R){
    cin >> r[i]; 
    r[i]--;
  }
  sort(ALL(r));
  Matrix d = Matrix(N, vector<ll>(N,INF));
  REP(i,N) d[i][i] = 0; 
  REP(i,M){
    ll a,b,c; cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  warshall_floyd(d);
  ll ans = INF;
  do{
    ll dist = 0;
    REP(i,R-1){
      ll cv = r[i], nv = r[i+1];
      dist += d[cv][nv];
    }
    ans = min(ans,dist);
  }while(next_permutation(ALL(r)));
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();

  rep(i,n)cout<<"x";
}


Measured memory_bytes: 256
S = input()
T = input()

n = len(S)-len(T)+1
ans = []
for i in range(n):
    SS = list("?"*(i) + T + "?"*(n-i-1))
    flag = True
    for i in range(len(S)):
        if S[i]=="?" or S[i]==SS[i]:
            pass
        elif S[i]!="?" and SS[i]=="?":
            SS[i]=S[i]
        else:
            flag = False
    if flag:
        ans.append("".join(SS).replace("?","a"))

if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    char c;
    cin >> a >> c >> b;
    if(c == '+') cout << a + b << endl;
    else cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		double n,k;
		cin >> n >> k;
		ll i;
		double prob = 0;
		ll  nay = (ll)n;
		ll kay = (ll)k;
		F(i,1,nay+1)
		{
			double d = 1;
			double temp =(double) i;
			while((temp*d) < k)
			{
				d *= 2.0;
			}
			prob += (1/d);
			
		}
		prob /= n;
		cout << setprecision(9) << fixed<< prob << endl;
		
	}
	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef pair <int, int> ii;

const int MAXN = 1010;

int pset[MAXN];
int findset(int x){ if(x!=pset[x]) pset[x] = findset(pset[x]); return pset[x]; }
void unionset(int x, int y){ x = findset(x), y = findset(y); pset[x] = y; }
bool sameset(int x, int y){ return findset(x) == findset(y); }


int main(){
	
	int n; cin >> n;
	vector <int> p, q, v; int aux;
	
	rep(i, 0, n){
		cin >> aux;
		p.pb(aux);
		v.pb(i+1);
	}
	
	rep(i, 0, n){
		cin >> aux;
		q.pb(aux);
	}
	
	int a = -1, b = -1, c = 0;
	while(a==-1 || b==-1){
		if(p==v) a = c;
		if(q==v) b = c;
		next_permutation(v.begin(), v.end());
		c++;
	}
	
	cout << abs(a-b) << '\n';
	
	
	
	return 0;
}

Measured memory_bytes: 256
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    int n = Integer.parseInt(br.readLine());
    Node[] nodes = new Node[n];
    for (int i =0; i<n; i++) {
      nodes[i] = new Node(i);
    }
    for (int i=0; i<n-1; i++) {
      String[] s = br.readLine().split(" ");
      int a = Integer.parseInt(s[0])-1;
      int b = Integer.parseInt(s[1])-1;
      nodes[a].adj.add(b);
      nodes[b].adj.add(a);
    }
    LinkedList<Integer> q = new LinkedList<>();
    int nWhite = 1;
    int nBlack = 1;
    nodes[0].c = 2;
    nodes[n-1].c = 1;
    q.offer(0);
    q.offer(n-1);
    boolean[] visited = new boolean[n];
    visited[0] = true;
    visited[n-1] = true;
    // black goes first
    while (q.size()>0) {
      Node curr = nodes[q.poll()];
      for (int i:curr.adj) {
        if (!visited[i]) {
          nodes[i].c = curr.c;
          if (curr.c==2)
            nBlack++;
          else
            nWhite++;
          q.offer(i);
          visited[i] = true;
        }
      }
    }
    if (nBlack>nWhite) {
      System.out.println("Fennec");
    } else {
      System.out.println("Snuke");
    }
  }
}
class Node {
  int id;
  ArrayList<Integer> adj;
  // 0 no colour
  // 1 is white
  // 2 is black
  int c=0;
  public Node(int idd) {
    id = idd;
    adj = new ArrayList<Integer>();
  }
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000000000
const ll mod=1e9+7;

int main()
{
	int nT; nT=1; //cin>>nT;
	while(nT--)
	{
		int n,w; cin>>n>>w;
		ll a[n][2], dp[n][w+1]; 
		rep(i,n) rep(j,2) cin>>a[i][j];
		rep(i,n) rep(j,w+1) dp[i][j]=0; 

		rep(i,w+1) if(i>=a[0][0]) dp[0][i]=a[0][1];
		
		for(int i=1; i<n; i++)
		rep(j,w+1)
		{
			dp[i][j]=dp[i-1][j];
			if(j-a[i][0]>=0) dp[i][j]=max(dp[i][j], a[i][1]+dp[i-1][j-a[i][0]]);			
		}
		cout<<dp[n-1][w];
		//cout<<endl; rep(i,n) { rep(j,w+1) cout<<dp[i][j]<<' '; cout<<endl; }
	}
	return 0;
}


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

typedef pair<int,int> p;

int main()
{
	ios::sync_with_stdio(false);
	
	int n,res=0;
	cin>>n;
	set<p> a,b;
	
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		a.insert(make_pair(x,y));
	}
	
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		b.insert(make_pair(x,y)); 
	}
	
	for(set<p>::iterator it=b.begin();it!=b.end();it++)
	{
		set<p>::iterator jt=a.begin(),x;
		x=a.end();;
		
		for(;jt!=a.end()&&jt->first<it->first;jt++)
		{
			if(jt->first<it->first&&jt->second<it->second)
			{
				if(x==a.end()||x->second<jt->second)
				{
					x=jt;
				}
			}
		}
		
		if(x!=a.end())
		{
			res++;
			a.erase(x); 
		}
	}
	
	cout<<res<<endl;
	return 0;
}

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

int main() {
	//cout<<"GfG!";
	long long int x[5];
	cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
	for (int i = 0; i < 5; i++)
	    if (x[i] == 0)
	    {
	        cout<<i+1;
	        break;
	    }
	return 0;
}

Measured memory_bytes: 3592
from collections import defaultdict

def solve():
    N = int(input())
    d = defaultdict(int)
    c = 0
    for _ in range(N):
        a = ''.join(sorted(list(input())))
        if a in d:
            c += d[a]
            d[a] += 1
        else:
            d[a] = 1
    return c

print(solve())

Measured memory_bytes: 18192
use std::io::{stdin, BufRead, BufReader};

fn main() {
    let mut primes: Vec<bool> = Vec::with_capacity(1000000);

    for _ in 0..1000000 {
        primes.push(true);
    }
    primes[0] = false;
    primes[1] = false;
    for i in 2..1000000 {
        if primes[i] {
            let mut j = i + i;
            while j < primes.len() {
                primes[j] = false;
                j += i;
            }
        }
    }
    let input = BufReader::new(stdin());
    for line in input.lines() {
        let n: usize = line.unwrap().trim().parse::<usize>().unwrap() + 1;
        let mut c = 0;
        for i in 2..n {
            if primes[i] {
                c += 1;
            }
        }
        println!("{}", c);
    }
}



Measured memory_bytes: 5028
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main(){
    let i1:i32  = read();
    let i2:i32 = read();
    let mut ori = 1;
    for i in 0..i1 {
        match ori <= i2 {
            true => ori *= 2,
            false => ori += i2,
        }
    }
    println!("{}",ori);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

typedef long long ll;

bool is_success(std::vector< ll >& vh, ll cnt, ll a, ll b)
{
  std::vector< ll >::iterator it;
  ll x = 0;
  for (it = vh.begin(); it != vh.end(); it++) {
    ll z = std::max(0LL, *it - b * cnt);
    x += (z + a - b - 1) / (a - b); // sample code から得たテクニック
  }

  bool judge = false;
  if (x <= cnt) {
    judge = true;
  }

  //std::cout << cnt << " x:" << x << " judge:" << judge << std::endl;
  return judge;
}

int solve(std::vector< ll >& vh, ll a, ll b)
{
  ll lb = 0;
  ll ub = *std::max_element(vh.begin(), vh.end());
  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2;
    if (is_success(vh, mid, a, b)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }

  return ub;
}

int main(int argc, char* argv[])
{
  ll n, a, b;
  std::cin >> n >> a >> b;
  std::vector< ll > vh(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> vh[i];
  }

  std::cout << solve(vh, a, b) << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=200010;
 
int n,c[maxn],num[maxn];
bool vis[maxn];
char s[maxn];
vector<int>v[30];
void modify(int x,int k){for(int i=x;i<=n;i+=lowbit(i))c[i]+=k;}
int query(int x){int ans=0;for(int i=x;i>=1;i-=lowbit(i))ans+=c[i];return ans;}
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)num[s[i]-'a']++,v[s[i]-'a'].push_back(i);
    int ok=0;
    for(int i=0;i<26;i++){
        if(num[i]%2)ok++;
    }
    if(ok>1){printf("-1");return 0;}
    for(int i=1;i<=n+1;i++)modify(i,1);
    ll ans=0;
    for(int i=1;i<=n;i++)if(!vis[i]){
        int c=s[i]-'a';
        int x=v[c].back();
        if(i==x){
            ans+=(query(n)-query(i))/2;
        }
        else{
            ans+=(query(n)-query(x));
        }
        modify(i,-1);modify(x,-1);
        vis[i]=vis[x]=1;
        v[c].pop_back();
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int a,b;
  cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  } else {
    cout << b - a << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <array>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long;
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;



int main()
{
	int i, j, k;
	string s;
	cin >> s;
	for (i = 0; i < (int)s.length(); i += 2){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

const bool operator<(pair<ll,ll> pa1 , pair<ll,ll> pa2) {
  return pa1.second > pa2.second;
}

int main(){
  ll t;
  cin >> t;
  ll k,l,r;
  rep(_,t){
    ll n;
    cin >> n;
    ll sum = 0;
    vector<pair<ll,ll>> vec1;
    vector<pair<ll,ll>> vec2;
    rep(i,n){
      cin >> k >> l >> r;
      k--;
      if(l >= r){
        vec1.emplace_back(make_pair(k,l-r));
        //vec1.emplace_back(make_pair(l-r,k));
        sum += r;
      }else{
        if(k+1 != n){
          vec2.emplace_back(make_pair(k+1,r-l));
        }
        //vec2.emplace_back(make_pair(r-l,k));
        sum += l;
      }
    }
    ll len1 = vec1.size();
    ll len2 = vec2.size();
    sort(all(vec1));
    sort(all(vec2));

    priority_queue<ll> pq;
    ll piv = 0;
    ll num = 0;
    rep(i,n){
      while(piv != len1 && vec1[piv].first == i){
        pq.push(-vec1[piv].second);
        piv++;
        num++;
      }
      //cout << num << " " << i+1 << endl;
      while(num > i+1){
        pq.pop();
        num--;
      }
    }
    while(!pq.empty()){
      sum -= pq.top();
      pq.pop();
    }

    piv = len2-1;
    num = 0;
    rep_rev(i,n){
      while(piv != -1 && vec2[piv].first == i){
        pq.push(-vec2[piv].second);
        piv--;
        num++;
      }
      while(num > n-i){
        pq.pop();
        num--;
      }
    }
    while(!pq.empty()){
      sum -= pq.top();
      pq.pop();
    }
    cout << sum << endl;
  }
}


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

bool check(long long N, const vector<string> &S) {
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			if(S[i][j] != S[j][i]) {
				return false;
			}
		}
	}
	return true;
}

void solve(long long N, vector<string> S){
	int res = 0;
	for(int k = 0; k < N; ++k) {
		if(check(N, S)) {
			res += N;
		}
		for(int i = 0; i < N; ++i) {
			S[i] = S[i].substr(1) + S[i].substr(0, 1);
		}
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<string> S(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> S[i];
	}
	solve(N, S);
	return 0;
}



Measured memory_bytes: 640
n=int(input())
w=[]
f=0
for i in range(n):
    w.append(input())
for i in range(n-1):
    if w[i][len(w[i])-1]==w[i+1][0]:
        f+=1
for i in range(n):
    if w.count(w[i])==1:
        
        f+=1
print("Yes" if f==2*n-1 else "No")
            


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n,k;
    cin>>n>>k;
    Array used(n,false);
    REP(i,k){
        ll d;
        cin>>d;
        REP(i,d){
            ll a;
            cin>>a;
            a--;
            used[a]=true;
        }
    }
    ll con=0;
    REP(i,n) if(!used[i]) con++;
    cout<<con<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

bool binary_search(const vector<int>& s, const int t) {
    int left = 0, right = (int)s.size();
    while(right > left) {
        int mid = (left + right) / 2;
//        cout << left << " " << right << " " << mid << endl;
        if(s[mid] == t) return true;
        else if(s[mid] > t) right = mid;
        else left = mid + 1;
    }

    return false;
}

int main(){
    int n, q;
    cin >> n;

    vector<int> s(n);
    for (auto i = 0; i < n; i++) cin >> s[i];

    cin >> q;
    vector<int> t(q);
    int ans = 0;
    for (auto i = 0; i < q; i++) {
        cin >> t[i];
        ans += binary_search(s, t[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a,b,c,d,e;
    	cin>>a>>b;
    	c=a+b;
    	d=a-b;
    	e=a*b;
     
    	if(c>=d and c>=e)
    		cout<<c<<"\n";
    	else if(d>=c and d>=e)
    		cout<<d<<"\n";
    	else
    		cout<<e<<"\n";
    return 0;
     
    }

Measured memory_bytes: 256
h,w=map(int,input().split())
tmp=h*w
tmp_2=h*w
tmp_3=h*w
tmp_4=h*w
for i in range(1,h):
    half_h=h-i
    area_1=i*w
    area_2=half_h//2*w
    area_3=(half_h-(half_h//2))*w
    ans=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans<tmp:
        tmp=ans
for j in range(1,w):
    half_w=w-j
    area_1=h*j
    area_2=(half_w//2)*h
    area_3=(half_w-half_w//2)*h#バグはここ
    ans_2=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_2<tmp_2:
        tmp_2=ans_2
for i in range(1,h):
    half_w=w//2
    area_1=i*half_w
    area_2=i*(w-half_w)
    area_3=(h-i)*w
    ans_3=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_3<tmp_3:
        tmp_3=ans_3
for j in range(1,w):
    half_h=h//2
    area_1=h*j
    area_2=(w-j)*half_h
    area_3=(w-j)*(h-half_h)
    ans_4=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_4<tmp_4:
        tmp_4=ans_4
print(min(tmp,tmp_2,tmp_3,tmp_4))


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
#define foreach(i,v) for(int i=0;i<(int)v.size();i++)

const int N=55;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
char mz[N][N];
int con[N][N],on[N][N],off[N][N];
int pre[N][N],dis[N][N];
int tl[N*N];
struct point
{
    int x,y;
    point(){}
    point(int _x,int _y)
    :x(_x),y(_y){}
};
point task[1010];
vector<int> load;
queue<point> q;
int n,m;
int T=0;
void bfs(int sx,int sy,int ex,int ey)
{
    while(!q.empty()) q.pop();
    memset(pre,-1,sizeof(pre));
    memset(dis,-1,sizeof(dis));
    dis[sx][sy]=0;
    q.push(point(sx,sy));
    while(!q.empty())
    {
        point u=q.front(); q.pop();
        int x=u.x, y=u.y;
        if(x==ex && y==ey) break;
        for(int d=0;d<4;d++)
        {
            int nx=x+dx[d], ny=y+dy[d];
            if(nx<0 || nx>=n || ny<0 || ny>=m) continue;
            if(dis[nx][ny]!=-1 || mz[nx][ny]=='#') continue;
            dis[nx][ny]=dis[x][y]+1;
            pre[nx][ny]=x*m+y;
            q.push(point(nx,ny));
        }
    }
    int ntl=0;
    for(int x=ex,y=ey;pre[x][y]!=-1;)
    {
        int t=pre[x][y];
        tl[ntl++]=t;
        x=t/m; y=t%m;
    }
    for(int i=ntl-1;i>=0;i--) load.push_back(tl[i]);
}
int main()
{
    int q;
    while(~scanf("%d%d%d",&n,&m,&q))
    {
        for(int i=0;i<n;i++) scanf("%s",mz[i]);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++) scanf("%d",&con[i][j]);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++) scanf("%d",&on[i][j]);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++) scanf("%d",&off[i][j]);
        for(int i=0;i<q;i++) scanf("%d%d",&task[i].x,&task[i].y);
        load.clear();
        for(int i=1;i<q;i++) bfs(task[i-1].x,task[i-1].y,task[i].x,task[i].y);
        load.push_back(task[q-1].x*m+task[q-1].y);
        memset(pre,-1,sizeof(pre));
        int ans=0;
        foreach(i,load)
        {
            int l=load[i];
            int x=l/m, y=l%m;
            if(pre[x][y]==-1)
            {
                ans+=on[x][y];
                ans+=off[x][y];
            }
            else
            {
                int tmp=(i-pre[x][y])*con[x][y];
                tmp=min(on[x][y]+off[x][y],tmp);
                ans+=tmp;
            }
            pre[x][y]=i;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 10980
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(long long A, long long B){
    cout << A * B << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

#define mod 1000000007
#define all(x) (x).begin(), (x).end()

const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll GetDigit(ll num) {return log10(num)+1;}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];

    ll allsum = 0;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        allsum += a[i];
        ans += abs(a[i]);
    }

    ll suma = 0, sumb = 0;
    for(ll i = 0; i < n-1; i++){
        suma += a[i];
        sumb = allsum - suma;
        //cout << suma << " " << sumb << endl;
        ans = min(ans, abs(suma - sumb));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<"\n"
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define in insert
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    // ll t;
    // cin>>t;
    // while(t--){
    	
        
    // }
   ll n,m;
   cin>>n>>m;
   ll sum=0;
   ll ar[n];
   rep(i,0,n){
   	ll a;cin>>a;
   	ar[i]=a;
   	sum+=a;
   }
   sort(ar,ar+n,greater<>());
   ll  p = ceil((double)sum/(4*m));
   if(ar[m-1]>=p){
   		cout<<"Yes";
   		return 0;
   }
   cout<<"No";
   return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

const ll mx=200101;

void answer(vector<ll> &A){
    set<ll> S;
    vector<ll> ret;
    for(auto &I:A){
        if(S.count(I)){
            while(ret.back()!=I){S.erase((ll)ret.back()); ret.pop_back();}
            S.erase((ll)ret.back()); ret.pop_back();
        }
        else{
            ret.push_back(I);
            S.insert(I);
        }
    }
    cout<<ret<<endl;
}

const pll err={-1,-1};

void cul(ll n,ll k,vector<ll> &ans,const vector<vector<ll>> &num,const vector<ll> &A,ll idx,ll shuu,ll d=0){
    vector<pll> cnt(n,err);
    auto las=[&](ll idx,ll shuu)->void{
        while(shuu<k){
            ans.push_back(A[idx]);
            shuu+=(idx+1)/n;
            idx=(idx+1)%n;
        }
        answer(ans);
    };
    if(d==10){las(idx,shuu);}
    
    while(cnt[idx]==err){
        cnt[idx]={idx,shuu};
        ll nx=*(upper_bound(num[A[idx]].begin(),num[A[idx]].end(),idx));
        shuu+=(nx+1)/n;
        if(shuu>=k){
            las(cnt[idx].F,cnt[idx].S);
            return;
        }
        idx=(nx+1)%n;
    }
    ll shuuki=shuu-cnt[idx].S;
    k-=cnt[idx].S;
    k%=shuuki;
    cul(n,k,ans,num,A,cnt[idx].F,0,d+1);
}

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> A(n);
    cin>>A;
    vector<vector<ll>> num(mx);
    vector<ll> ans;
    for(int i=0;i<n;i++){num[A[i]].push_back(i);}
    for(int i=0;i<n;i++){num[A[i]].push_back(n+i);}
    const pll err={-1,-1};
    vector<pll> cnt(n,err);
    ll idx=0,shuu=0;
    cul(n,k,ans,num,A,idx,shuu);
    
    
    
    return 0;
}


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

int main(){
    int H, W, K; cin >> H >> W >> K;
    string s[H];
    int ans = 123123123; 
    for (int i = 0; i < H; i++){
        cin >> s[i];
    }

    for (int i = 0; i < (1 << (H - 1)); i++){
        int popCount = __builtin_popcount(i);
        int blockCount[popCount + 1];
        fill(blockCount, blockCount + popCount + 1, 0);
        int id = 0;
        bool reset = true;
        bool cont = false;
        int cnt = popCount;
        
        while (id < W){
            int block = 0;
            for (int j = 0; j < H; j++){
                if (i & (1 << (j - 1))) block++;
                if (s[j][id] == '1') blockCount[block]++;
            }
            bool clear = true;
            for (int j = 0; j < popCount + 1; j++){
                if (K < blockCount[j]){
                    clear = false;
                    if (reset){
                        cont = true;
                        break;
                    }else{
                        fill(blockCount, blockCount + popCount + 1, 0);
                        reset = true;
                        cnt++;
                        id--;
                        break;
                    }
                }
            }
            if (clear) reset = false;
            if (cont) break;
            id++;
        }
        if (!cont) ans = cnt < ans ? cnt : ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 1000000
char p[N];
long long dp[10001];
int main(void)
{
    int i, j;
    for (i=2; i<N; ++i) p[i]=1;
    for (i=2; i*i<N; ++i) if (p[i])
        for (j=2*i; j<N; j+=i) p[j]=0;

    dp[1]=2;
    j=2;
    for (i=3; i<N; ++i) if (p[i]) {
        dp[j]=dp[j-1]+i;
        j++;
        if (j>10000) break;
    }

    while (scanf("%d", &j), j) printf("%lld\n", dp[j]);
    return 0;
}

Measured memory_bytes: 0
sum = []
A,B,M = map(int, input().split())
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]

sum.append(min(a_l) + min(b_l))

for m in range(M):
    coupon = []
    coupon = [int(x) for x in input().split()]

    sum.append(a_l[coupon[0]-1] + b_l[coupon[1]-1] - coupon[2])

print(min(sum))

Measured memory_bytes: 18148
from sys import stdin
input = stdin.readline

N = int(input())

b = False
cnt = 0
for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        cnt += 1
        if cnt == 3:
            b = True
    else:
        cnt = 0

if b == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9024
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        A: i64,
        B: i64,
        C: i64,
        mut K: i64,
    }

    let mut ans: i64 = 0;
    let mut t: i64 = 0;

    t = min(A, K);
    ans += t;
    K -= t;

    t = min(B, K);
    K -= t;

    t = min(C, K);
    ans -= t;

    println!("{}", ans);
}


Measured memory_bytes: 2128
#include <stdio.h>

int main () {
	char str[105];
	for (int i = 0; str[i] != '\0'; i++) {
		scanf("AtCoder %s Contest", &str[i]);
		if ( str[i] >= 'A' && str[i] <= 'Z') {
			printf("A%cC\n", str[i]);
		}
		else {
			continue;
		}
	}
	return 0;
}

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

#define REP(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;

// constexpr ll mod = 1e9+7;

int N, M;
vector<vector<int>> g;

int main(){
  cin >> N >> M;
  g.resize(N);
  REP(i, M){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> from(N, -1);
  queue<int> que;
  que.push(0);
  from[0] = 0;
  while(!que.empty()){
    int v = que.front(); que.pop();
    for(auto nv : g[v]){
      if(from[nv] != -1) continue;
      from[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  FOR(i, 1, N){
    cout << from[i]+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 10160