akhauriyash/Code-Regression huggingface dataset:
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = uint64_t;

int main(int, const char**)
{
    ll a, b, n;
    cin >> a >> b >> n;
#if 0
    for(ll i = 0; i < n; ++i)
    {
        auto v = (a * i / b) - (a * (i / b));
        printf("x: %ld, v: %ld\n", i, v);
    }
#endif
    auto x = min(b - 1, n);
    auto v = (a * x / b) - (a * (x / b));
    cout << v << endl;
    return 0;
}


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

int N, X[1<<18], Y[1 << 18];
char D[1 << 18];

void Rotate(){
    for(int i = 1; i <= N; i++){
        int cx = Y[i], cy = 200000 - X[i], cz;
        if(D[i] == 'U') cz = 'R';
        if(D[i] == 'R') cz = 'D';
        if(D[i] == 'D') cz = 'L';
        if(D[i] == 'L') cz = 'U';
        X[i] = cx, Y[i] = cy, D[i] = cz;
    }
}

vector<pair<int, char>> V1[1 << 19];
vector<pair<int, char>> V2[1 << 19];

int solve_01(){
    int Answer = (1 << 24);
    for(int i = 0; i <= 500000; i++) V1[i].clear();
    for(int i = 1; i <= N; i++){
        if(!(D[i] == 'R' || D[i] == 'U')) continue;
        V1[X[i] + Y[i]].push_back(make_pair(X[i], D[i]));
    }
    for(int i = 0; i <= 500000; i++){
        sort(V1[i].begin(), V1[i].end());
        for(int j = 0; j < (int)V1[i].size() - 1; j++){
            if(!(V1[i][j].second == 'R' && V1[i][j + 1].second == 'U')) continue;
            Answer = min(Answer, V1[i][j + 1].first - V1[i][j].first);
        }
    }
    return Answer * 10;
}

int solve_02(){
    int Answer = (1 << 24);
    for(int i = 0; i <= 500000; i++) V2[i].clear();
    for(int i = 1; i <= N; i++){
        if(!(D[i] == 'L' || D[i] == 'R')) continue;
        V2[Y[i]].push_back(make_pair(X[i], D[i]));
    }
    for(int i = 0; i <= 500000; i++){
        sort(V2[i].begin(), V2[i].end());
        for(int j = 0; j < (int)V2[i].size() - 1; j++){
            if(!(V2[i][j].second == 'R' && V2[i][j + 1].second == 'L')) continue;
            Answer = min(Answer, V2[i][j + 1].first - V2[i][j].first);
        }
    }
    return Answer * 5;
}

int main(){
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> X[i] >> Y[i] >> D[i];

    int FinalAns = (1 << 24);
    for(int t = 1; t <= 4; t++){
        int val1 = solve_01(); FinalAns = min(FinalAns, val1);
        int val2 = solve_02(); FinalAns = min(FinalAns, val2);
        Rotate();
    }
    if(FinalAns == (1 << 24)) cout << "SAFE" << endl;
    else cout << FinalAns << endl;

}

Measured memory_bytes: 42720
let inputString = '';

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
process.stdin.on('end', function() {
  const inputArr = inputString.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

  const result = countingSort(inputArr[1].split(' ').map(s => Number(s)), MAX_K);
  console.log(result.join(' '));
});

const MAX_K = 10000;
const countingSort = (arr, maxNum) => {
  const C = Array(maxNum + 1).fill(0);

  for (let j=0; j<arr.length; j++) {
    C[arr[j]]++;
  }

  for (let i=1; i<=maxNum; i++) {
    C[i] = C[i] + C[i-1];
  }

  const B = Array(arr.length);
  for (let j=arr.length-1; j>=0; j--) {
    const value = arr[j];
    const freqOfLessOrEqual = C[value];
    const index = freqOfLessOrEqual - 1;
    B[index] = value;
    C[value]--; // for duplicated numbers
  }

  return B;
};


Measured memory_bytes: 240460
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);

	 	StringTokenizer st = new StringTokenizer(bf.readLine());
	 	int n = Integer.parseInt(st.nextToken());
	 	int m = Integer.parseInt(st.nextToken());
	 	long k = Long.parseLong(st.nextToken());
	 	StringTokenizer st1 = new StringTokenizer(bf.readLine());
	 	StringTokenizer st2 = new StringTokenizer(bf.readLine());
 		LinkedList<Long> array1 = new LinkedList<Long>();
 		LinkedList<Long> array2 = new LinkedList<Long>();
 		for(int i = 0;i<n;i++){
 			array1.add(Long.parseLong(st1.nextToken()));
 		}
 		array1.add(Long.MAX_VALUE/2);
 		for(int i = 0;i<m;i++){
 			array2.add(Long.parseLong(st2.nextToken()));
 		}
 		array2.add(Long.MAX_VALUE/2);
 		
 		ArrayList<Long> prefix1 = new ArrayList<Long>();
 		prefix1.add(0L);
 		long sum = 0;
 		for(long i : array1){
 			sum+=i;
 			prefix1.add(sum);
 		}
 		ArrayList<Long> prefix2 = new ArrayList<Long>();
 		prefix2.add(0L);
 		sum = 0;
 		for(long i : array2){
 			sum+= i;
 			prefix2.add(sum);
 		}
 	
 		int i = 0;
 		int max = 0;
 		while(i < prefix2.size() && prefix2.get(i) <=k){
 			long left = k-prefix2.get(i);
 			int index = lowerBoundS(prefix1, left, 0, array1.size());
 			max = Math.max(index+i, max);
 			i++;
 		}
 		
	 	out.println(max);
 		
 		out.close();
 		
 		
 		
 	}
	//last index of integer less than or equal to target
		public static int lowerBoundS(ArrayList<Long> array, long target, int l, int r){
			if (array.size() == 1)
				return 0;
			int mid = -1;
			while (l<r){
				mid = (l+r)/2;
				if (array.get(mid)<= target && (mid + 1 >= array.size() || array.get(mid+1) > target))
					return mid;
				else if (array.get(mid) <= target)
					l = mid+1;
				else
					r = mid;
			}
			return mid;
			
		
		}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 82208
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = new int[2];
            input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int ans = input[0] - (2 * input[1]);
            if (ans >= 0)
            {
                Console.WriteLine(ans);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int K;
	cin >> K;

	int odd = 0;
	int even = 0;
	for (int i = 1; i <= K; i++)
	{
		if (i % 2 == 0) even++;
		else odd++;
	}

	cout << even * odd;

	return 0;
}


Measured memory_bytes: 3656
package main

import (
	"fmt"
)

type xy struct {
	x int
	y int
}

type pq struct {
	p int
	q int
}

func main() {
	var N int
	fmt.Scan(&N)

	XY := make([]xy, 0, N)
	XYmapOrig := make(map[xy]int, N)

	for i := 0; i < N; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		x_y := xy{x, y}
		XY = append(XY, x_y)
		XYmapOrig[x_y] = 1
	}

	PQ := make([][]pq, N)
	PQmap := make(map[pq]int)

	for i := 0; i < N; i++ {
		PQ[i] = make([]pq, N)
		for j := 0; j < N; j++ {
			if i == j {
				continue
			}
			p := XY[i].x - XY[j].x
			q := XY[i].y - XY[j].y
			p_q := pq{p, q}
			PQ[i][j] = p_q
			PQmap[p_q]++
		}
	}

	ans := N
	for target := range PQmap {
		XYmap := make(map[xy]int, N)
		for k, v := range XYmapOrig {
			XYmap[k] = v
		}
		cnt := 0
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if i == j {
					continue
				}
				xy1 := XY[i]
				xy2 := XY[j]
				if _, ok := XYmap[xy1]; !ok {
					continue
				}
				if _, ok := XYmap[xy2]; !ok {
					continue
				}
				p_q := PQ[i][j]
				if p_q.p == target.p && p_q.q == target.q {
					cnt++
					xy1 := XY[i]
					xy2 := XY[j]
					delete(XYmap, xy1)
					delete(XYmap, xy2)
					for {
						xy1 = xy{xy1.x + target.p, xy1.y + target.q}
						if _, ok := XYmap[xy1]; ok {
							delete(XYmap, xy1)
						} else {
							break
						}
					}
					for {
						xy2 = xy{xy2.x - target.p, xy2.y - target.q}
						if _, ok := XYmap[xy2]; ok {
							delete(XYmap, xy2)
						} else {
							break
						}
					}
					break
				}
			}
		}
		for range XYmap {
			cnt++
		}
		if ans > cnt {
			ans = cnt
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
x, y = map(int, input().split())

if (x + y) % 3:
    print(0)
    exit()

n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
    print(0)
    exit()
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

N = 2 * 10 ** 6 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
    fact[i] = (fact[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(fact[a+b], fact[a]), fact[b])

print(comb(x, y))

Measured memory_bytes: 55660
from itertools import combinations
import numpy as np

h,w, k = [int(n) for n in input().split()]

temp2 = []
for i in range(h):
  temp= []
  for s in input():
    if s == '.':
      temp.append(0)
    else:
      temp.append(1)
  temp2.append(temp)
matrix = np.array(temp2)

comb_h = []
for i in range(h+1):
  for c in combinations(list(range(h)), i):
    comb_h.append(c)
comb_w = []
for i in range(w+1):
  for c in combinations(list(range(w)), i):
    comb_w.append(c)

cnt = 0
for h_seq in comb_h:
  for w_seq in comb_w:
    total = 0
    for h_item in h_seq:
      total += np.sum(matrix[h_item, w_seq])
    if total == k:
      cnt += 1
print(cnt)

Measured memory_bytes: 27272
from sys import stdin


def main() -> None:
    n = next_int()
    ans = 10 ** 9

    for i in range(n):
        a = next_int()
        ans = min(ans, calc(a))
    print(ans)


def calc(a: int) -> int:
    result = 0
    while a % 2 == 0:
        result += 1
        a //= 2
    return result


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

#define forn(n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

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

	string s, t;
	cin >> s >> t;

	forn(n){
		cout << s[i] << t[i];
	}
	
	cout << "\n";

	return 0;
}

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

int main() {
 	long long int X;
  	cin >> X;
  
  	long long int count = 100;
  	int res = 0;
  
  	while (count < X){
      	res++;
      	count = count / 100 + count;
    }
  
  	cout << res << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll SUM=a+b+c;
  ll MAX=max({a,b,c});
  if(SUM%2==MAX%2){
    co((3*MAX-SUM)/2)
  }
  else{
    co((3*(MAX+1)-SUM)/2)
  }
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll ans = 1;
    rep(i, N) {
        ans *= i+1;
        ans %= MOD;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
using namespace std ;

#define MAXN 100007
#define LOG 20

int n ;
int a[ MAXN ] ;
int len ;

int fw[ MAXN ][ LOG ] ;
int bw[ MAXN ][ LOG ] ;


void input ( ) {
    scanf ( "%d" , &n ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
    scanf ( "%d" , &len ) ;
}

void solve ( ) {
    int pos = 1 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        while ( pos < n && a[ pos + 1 ] <= a[ i ] + len ) { ++ pos ; }
        fw[ i ][ 0 ] = pos ;
    }
    pos = n ;
    for ( int i = n ; i >= 1 ; -- i ) {
        while ( pos > 1 && a[ pos - 1 ] >= a[ i ] - len ) { -- pos ; }
        bw[ i ][ 0 ] = pos ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j < LOG ; ++ j ) {
            bw[ i ][ j ] = bw[ bw[ i ][ j - 1 ] ][ j - 1 ] ;
        }
    }
    for ( int i = n ; i >= 1 ; -- i ) {
        for ( int j = 1 ; j < LOG ; ++ j ) {
            fw[ i ][ j ] = fw[ fw[ i ][ j - 1 ] ][ j - 1 ] ;
        }
    }
    int q ;
    scanf ( "%d" , &q ) ;
    while ( q -- ) {
        int x , y ;
        scanf ( "%d%d" , &x , &y ) ;
        int ans = 0 ;
        int h = x ;
        for ( int i = LOG - 1 ; i >= 0 ; -- i ) {
            
            if ( x < y && fw[ h ][ i ] < y ) {
                if ( fw[ h ][ i ] > 0 ) { 
                    ans += ( 1 << i ) ;
                    h = fw[ h ][ i ] ;
                }
            }
            else if ( y < x && bw[ h ][ i ] > y ) {
                ans += ( 1 << i ) ;
                h = bw[ h ][ i ] ;
            }
        }
        printf ( "%d\n" , ans + 1 ) ;
    }
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,T;
    cin >> N >> T;
    vector<int> c(N),t(N);
    vector<pair<int,int>> p(N);
    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
        p[i] = make_pair(t[i],c[i]);
    }
    sort(p.begin(),p.end());
    int cMin = 99999;
    for(int i = 0; i < N; i++){
        if(p[i].first <= T) cMin = min(cMin,p[i].second);
    }
    if(cMin == 99999){
        cout << "TLE" << endl;
        return 0;
    }
    cout << cMin << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int i, j, a, b, n, tate, yoko, s[400][400], t[200], y[200];
  scanf("%d", &n);
  while(n!=0){
    for(i=0;i<400;i++){
      for(j=0;j<400;j++){
        s[i][j]=0;
      }
      if(i<200){
      t[i]=0;
      y[i]=0;
      }
    }
    t[0]=200;
    y[0]=200;
    s[200][200]=1;
    for(i=1;i<n;i++){
      scanf("%d %d", &a, &b);
      if(b==0){
        s[t[a]][y[a]-1]=1;
        t[i]=t[a];
        y[i]=y[a]-1;
      }else if(b==1){
        s[t[a]+1][y[a]]=1;
        t[i]=t[a]+1;
        y[i]=y[a];
      }else if(b==2){
        s[t[a]][y[a]+1]=1;
        t[i]=t[a];
        y[i]=y[a]+1;
      }else{
        s[t[a]-1][y[a]]=1;
        t[i]=t[a]-1;
        y[i]=y[a];
      }
    }

    yoko=0;
    for(i=0;i<400;i++){
      for(j=0;j<400;j++){
        if(s[i][j]==1){
          yoko++;
          break;
        }
      }
    }
    tate=0;
    for(i=0;i<400;i++){
      for(j=0;j<400;j++){
        if(s[j][i]==1){
          tate++;
          break;
        }
      }
    }
    printf("%d %d\n", tate, yoko);
    scanf("%d", &n);
  }

  return 0;
}

Measured memory_bytes: 1228
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W):
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce, lru_cache
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = a_int()
A = ints()
cnt = Counter(A)
'''
dp[i,j,k]...すべての寿司がなくなるまでの操作の期待値(寿司が1つ乗っている皿の数がi,2つがj,3つがk)

dp[i,j,k]= 1(操作回数)+ 
            i/N*(1つの皿が一つ減った場合の操作の期待値) + 
            j/N*(2つの皿が1つ減った場合の操作の期待値) + 
            k/N*(3つの皿が1つ減った場合の操作の期待値)+
            (1-i-j-k)/N * (0つの皿を選んでしまったときの期待値)

dp[i,j,k]= 1+ i/N * dp[i-1,j,k]+ 
            j/N*dp[i+1,j-1,k] + 
            k/N*dp[i,j+1,k-1]+
            (N-i-j-k)/N*dp[i,j,k]

dp[i,j,k]= N/(i+j+k) *
            (1+ i/N * dp[i-1,j,k]+ 
            j/N*dp[i+1,j-1,k] + 
            k/N*dp[i,j+1,k-1])
'''

dp = np.full((N + 1, N + 1, N + 1), -1.0)
dp[0, 0, 0] = 0
from numba import njit
# @njit('(i8,i8,i8[:])',cache=True)


@njit('(i8,i8,i8,i8,f8[:,:,:])', cache=True)
def dfs(i, j, k, N, dp):
    if i < 0 or j < 0 or k < 0 or i == j == k == 0:
        return 0
    if dp[i, j, k] != -1:
        return dp[i, j, k]
    ret = 1
    ret += i / N * dfs(i - 1, j, k, N, dp)
    ret += j / N * dfs(i + 1, j - 1, k, N, dp)
    ret += k / N * dfs(i, j + 1, k - 1, N, dp)
    if (i + j + k) == 0:
        dp[i, j, k] = ret
        return ret
    dp[i, j, k] = N / (i + j + k) * ret
    return dp[i, j, k]


print(dfs(cnt[1], cnt[2], cnt[3], N, dp))


Measured memory_bytes: 323920
fn main(){let mut s=String::new();std::io::stdin().read_line(&mut s).unwrap();let s=s.trim();let q="keyence";if(0..7).any(|i|s.starts_with(&q[0..i])&&s.ends_with(&q[i..7])){println!("YES")}else{println!("NO")}}

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

int main(){
    long N,K,tmpa,tmpb;
    cin >> N >> K;
    vector<long> list(500001, 0);

    for (long i=0; i<N; i++){
        cin >> tmpa >> tmpb;
        list[tmpa] = list[tmpa] + tmpb; 
    }
    
    long cnt = 0;
    for(long i=0; i<500001; i++){
        cnt += list[i];
        if(cnt >= K){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int t;
int coin[4]={10,50,100,500};
int num[4];
int res[4];

int cmin=inf;
int indexs[4];

void dfs(int i,int* index){
	if(i==4){
		int sum=0;
		rep(j,4) sum+=coin[j]*index[j];
		if(sum<t)
			return;
		sum-=t;
		int ch[4];
		rep(j,4){
			ch[3-j]=sum/coin[3-j];
			sum-=(sum/coin[3-j]*coin[3-j]);
		}
		int cur=0;
		rep(j,4) cur+=(num[j]-index[j]+ch[j]);
		if(cur<cmin){
			cmin=cur;
			rep(j,4) res[j]=index[j];
		}
		return;
	}
	for(index[i]=0;index[i]<=num[i];++index[i]){
		dfs(i+1,index);
	}
	return ;
}

int main(void){
	bool first=true;
	while(cin >> t){
		if(t==0)
			break;
		if(first)
			first=false;
		else
			cout << endl;
		cmin=inf;
		rep(i,4) cin >> num[i];
		dfs(0,indexs);
		rep(i,4)if(res[i]!=0)
			cout << coin[i] <<" " << res[i] << endl;
	}
	return 0;
}

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

char heya[800][802];
char (*heya_)[802] = heya;
int h, w, k;

int main()
{
    cin >> h >> w >> k;
    {
        char tmp[5];
        cin.getline(tmp, 5);
    }
    for (int i = 0; i< h; i++) {
        cin.getline(heya[i], 802);
    }
    int sx, sy;
    for (int i = 0; i<h; i++) {
        for (int j = 0; j<w; j++) {
            if (heya[i][j] == 'S') {
                sx = j; sy = i;
            }
        }
    }
    heya[sy][sx] = '.';
    queue<pair<pair<int, int>, int>> q;
    q.push(make_pair(make_pair(sx, sy), 0));
    while (!q.empty()) {
        auto a = q.front();
        q.pop();
        int x = a.first.first, y = a.first.second, kk = a.second;
        if (heya[y][x] != '.') continue;
        heya[y][x] = 'S';
        if (kk < k) {
            if (x-1 >= 0) q.push(make_pair(make_pair(x-1, y), kk+1));
            if (y-1 >= 0) q.push(make_pair(make_pair(x, y-1), kk+1));
            if (x+1 < w) q.push(make_pair(make_pair(x+1, y), kk+1));
            if (y+1 < h) q.push(make_pair(make_pair(x, y+1), kk+1));
        }
    }
    int best = 99999999;
    for (int i = 0; i<h; i++) {
        for (int j = 0; j<w; j++) {
            if (heya[i][j] == 'S') {
                best = min(best, i);
                best = min(best, j);
                best = min(best, h - 1 - i);
                best = min(best, w - 1 - j);
            }
        }
    }
    if (best == 0) {
        cout << 1 << endl;
        return 0;
    }
    cout << (best-1)/k+2 << endl;
	return 0;
}


Measured memory_bytes: 896
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = []
    for i,ai in enumerate(ipt().split()):
        a.append(int(ai)-i-1)
    a.sort()
    b = a[n//2]
    ans = 0
    for i in a:
        ans += abs(i-b)
    print(ans)


    return

if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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 countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    string S;
    cin >> S;
    rep(i, S.length()) {
        cout << 'x';
    }
    return 0;
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

ll arr[MAX], cnt[MAX];

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

    ll a, b, n;
    ll sum = 0;

    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>arr[i];
        cnt[arr[i]]++;
        sum += arr[i];
    }

    int q;
    cin>>q;

    while(q--) {
        cin>>a>>b;
        if(!cnt[a]) {
            cout<<sum<<endl;
            continue;
        }
        sum -= 1LL * cnt[a] * a;
        sum += 1LL * cnt[a] * b;
        cnt[b] += cnt[a];
        cnt[a] = 0;

        cout<<sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int c[3][3];

int main()
{
	rep(i,3)rep(j,3)cin >> c[i][j];
	rep(i,2)
	{
		if(c[i][0]-c[i][1]!=c[i+1][0]-c[i+1][1])
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(c[i][2]-c[i][1]!=c[i+1][2]-c[i+1][1])
		{
			cout<<"No"<<endl;
			return 0;
		}
		
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int MAX = 4040404;

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum += A[i];
    
    /* ある値が存在するか=部分和問題をin-placeに
    dp[0] = true;
    for(int i = 0; i < N; ++i)
        for(int j = 0, j <= N*A; ++j)
            dp[j + A[i]] |= dp[j]; */

    // 高速化！！！
    // A[i]を加えるパターン(bitをA[i]左にシフト)とORをとることで、
    // A[i]を加えないパターンに対応
    bitset<MAX> dp;
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        // = 加えない || A[i]加算
        dp = (dp | (dp << A[i]));
    }

    /* 全部選ばないのは不適なので2^n-1通り、
    つまり中央値は大きい方半分のうちの最小値
    つまり、(S + 1)/2 以上の値の中での最小値 */
    ll ans;
    for (ans = (sum+1)/2; ans < MAX; ++ans) {
        if (dp[ans]) break;
    }
    cout << ans << endl;
}



Measured memory_bytes: 2304
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  size_t N, K;
  scanf("%llu %llu", &N, &K);

  set<string> s;
  for (size_t i=0; i<N; ++i) {
    char buf[1<<4];
    scanf("%s", buf);
    string P(buf);
    s.insert(P);
  }

  map<char, int> m;
  for (string t: s)
    ++m[t[0]];

  int res=0;
  while (true) {
    set<char> used;
    for (size_t i=0; i<K; ++i) {
      int max_=-1;
      char cur='@';
      for (auto u: m) {
        if (u.second>=max_ && !used.count(u.first)) {
          max_ = u.second;
          cur = u.first;
        }
      }
      if (max_ > 0) {
        used.insert(cur);
        --m[cur];
      } else {
        return !printf("%d\n", res);
      }
    }
    ++res;
  }
}


Measured memory_bytes: 1152
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

dic = {22:'Christmas Eve Eve Eve', 23:'Christmas Eve Eve', 24:'Christmas Eve', 25:'Christmas'}

print(dic[a])

Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define MP make_pair
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using vvec = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m,l;
    cin>>n>>m>>l;
    vector<int> dist[n];
    REP(i,n) dist[i].assign(n,INF);
    
    REP(i,n) dist[i][i] = 0;

    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        dist[a][b]=dist[b][a]=c;
    }
    
    REP(k,n){
      REP(i,n){
        REP(j,n){
          dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
        }
      }
    }

    rep(i,n){
        rep(j,n){
            if(dist[i][j]<=l) dist[i][j]=1;
            else dist[i][j]=INF;
        }
    }
    REP(k,n){
      REP(i,n){
        REP(j,n){
          dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
        }
      }
    }
    int q;
    cin>>q;
    rep(i,q){
        int s,t;
        cin>>s>>t;
        s--;t--;
        if(dist[s][t]==INF) cout<<-1<<endl;
        else cout<<dist[s][t]-1<<endl;
    }
}

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

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(A + B <= K){
    cout << "0 0";
    return 0;
  }
  if(A >= K){
    cout << A-K << " " << B;
  }
  else{
    cout << "0 " << A+B-K;
  }
}

Measured memory_bytes: 3624
import numpy as np
from itertools import product

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

CA = []

for i in range(N):
    CA.append(list(map(int, input().split())))

CA = np.array(CA)

C = CA[:, 0]
A = CA[:, 1:]

whole = np.array(list(product([0,1],repeat=N)), np.bool)

ans_tmp = []

for p in whole:
    score = A[p].sum(axis=0)
    ans_tmp.append(score[np.where(score>=X)].shape[0]==M)

pattern = whole[ans_tmp]

score = A[whole[1]].sum(axis=0)

ans = 10**15
for p in pattern:
    tmp = C[p].sum()
    if ans > tmp:
        ans = tmp

print(ans) if ans != 10**15 else print(-1)

Measured memory_bytes: 27660
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;

vector<vector<P> > V;
int N, M;
int dp[401];

int rec(int i){
    if(dp[i] != -1) return dp[i];
    int ret = 0;
    for(int j = 0; j < V[i].size(); j++){
        ret = max(ret, rec(V[i][j].first) + V[i][j].second);
    }
    
    return dp[i] = ret;
}

int main(void){
    // Your code here!
    cin >> N >> M;
    int a, b, c;
    V.resize(N);
    for(int i = 0; i < M; i++){
        cin >> a >> b >> c;
        V[a].push_back(make_pair(b, c));
    }
    
    
    for(int i = 0; i < N; i++){
        dp[i] = -1;
    }
    
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        ans = max(ans, rec(i));
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios_base::sync_with_stdio(false);
   long long int n;
   cin >> n;
   long long int x[86];
   x[0]=2;
   x[1]=1;
   for(long long int i=2;i<=n;i++){
       x[i]=x[i-1]+x[i-2];
   }
   cout << x[n] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int h, w, i, j;
    while (1) {
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) {
            break;
        }
        else if (h != 0 && w != 0) {
            for (i = 0; i < h; i++) {
                for (j = 0; j < w; j++) {
                    if ((i+j)%2 == 1) {
                        printf(".");
                    } else {
                        printf("#");
                    }
                }
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    vector<int> arr;
    int i = n;
    while (i--){
        int t;
        cin >> t;
        arr.push_back(t);
    }
    cout << n + (x - accumulate(arr.begin(),arr.end(),0)) / *min_element(arr.begin(),arr.end()) << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
l = []
for _ in range(M):
    a, b = map(int, input().split())
    *c, = map(int, input().split())
    l.append((a, c))

inf = 10**12
dp = [inf]*(2**N)
dp[0] = 0

for i in range(2**N):
    for cost, j in l:
        v = sum(map(lambda x:2**(x-1), j))
        dp[i|v] = min(dp[i|v], dp[i]+cost)

print(dp[2**N-1] if dp[2**N-1]!=inf else -1)

Measured memory_bytes: 45032
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define EPS (1e-10)
using namespace std;

double add(double a, double b)
{

    if (abs(a + b) < EPS * (abs(a) + abs(b)))
        return 0;
    return a + b;
}

struct P
{
    double x, y;
    P(){};
    P(double x, double y) : x(x), y(y) {}
    P operator+(P p)
    {
        return (P(add(x, p.x), add(y, p.y)));
    }
    P operator-(P p)
    {
        return (P(add(x, -p.x), add(y, -p.y)));
    }
    P operator*(double k)
    {
        return (P(k * x, k * y));
    }
    double dot(P p)
    {
        return add(x * p.x, y * p.y);
    }
    double det(P p)
    {
        return add(x * p.y, -y * p.x);
    }
};
bool on_seg(P p1, P p2, P q)
{
    return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}
P intersection(P p1, P p2, P q1, P q2)
{
    return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}
typedef P Vector;
//三辺の長さがそれぞれa,b,cの三角形の面積を求める
double heron(double a, double b, double c)
{
    double s = (a + b + c) / 2;

    return sqrt(s * (s - a) * (s - b) * (s - c));
}

// p1-p2の線分の長さを求める
double distPP(P p1, P p2)
{
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

// 線分p1-p2と点qの長さを求める
double distLP(P p1, P p2, P q)
{
    if ((p2 - p1).dot(q - p1) < 0.0)
    {
        return distPP(p1, q);
    }
    if ((p1 - p2).dot(q - p2) < 0.0)
    {
        return distPP(p2, q);
    }
    return abs((p2 - p1).det(q - p1) / distPP(p2, p1));
}

//線分p1-p2とq1-q2が交差しているならtrue、そうでないならfalse
bool isCrossed(P p1, P p2, P q1, P q2)
{
    P pi = intersection(p1, p2, q1, q2);
    return (on_seg(p1, p2, pi) && on_seg(q1, q2, pi));
}

//線分p1-p2とq1-q2の最小距離を求める
double distLL(P p1, P p2, P q1, P q2)
{
    if (isCrossed(p1, p2, q1, q2))
    {
        return 0.0;
    }
    else
    {
        return min({distLP(p1, p2, q1), distLP(p1, p2, q2), distLP(q1, q2, p1), distLP(q1, q2, p2)});
    }
}

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n;
    P a[n + 2];
    a[0] = P(0, 0);
    a[n + 1] = P(1000, 0);

    rep(i, n) cin >> a[i + 1].x >> a[i + 1].y;
    cin >> m;
    P b[m + 2];
    b[0] = P(0, 1000);
    b[m + 1] = P(1000, 1000);
    rep(i, m) cin >> b[i + 1].x >> b[i + 1].y;
    double ans = 101010.0;
    rep(i, n + 1) rep(j, m + 1)
    {
        ans = min(ans, distLL(a[i], a[i + 1], b[j], b[j + 1]));
    }
    cout << setprecision(16) << ans << endl;
    return 0;
}



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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	while(1)
	{
		c-=b;
		if(c<=0)
		{
			cout << "Yes";
			break;
		}
		a-=d;
		if(a<=0)
		{
			cout << "No";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	ll s = 0;
	rep(i, n) {
		cin >> a.at(i);
		s += a.at(i);
	}
	ll ans = 0;
	double k = m;
	rep(i, n) {
		if (a.at(i) >= (s / k) / 4) ans++;
	}
	if (ans >= m) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int a,b;
using namespace std;
int main(){
	scanf("%d%d",&a,&b);
	if(a>b) swap(a,b);
	if(a<=0&&0<=b) return puts("Zero"),0;
	if(a>0) return puts("Positive"),0;
	int len=(b-a+1);
	if(len&1) puts("Negative");
	else puts("Positive");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

  static int n, k, ans;
  static List<Integer> p;

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

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

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    k = Integer.parseInt(in[1]);

    in = br.readLine().split(" ");
    p = Arrays.stream(in).map(Integer::parseInt).sorted().collect(Collectors.toList());

    br.close();

    for (int i = 0; i < k; i++) {
      ans += p.get(i);
    }
    out.println(ans);

    out.flush();
  }
}


Measured memory_bytes: 34704
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<set>
using namespace std;
int before ,End;
int n, t;
int now;
int ans;
int main(){
	scanf("%d %d", &n, &t);
	scanf("%d",&End);
	for(int i = 2 ; i <= n ; i++){
		before = End;
		scanf("%d", &End);

		if(End - before > t)ans += t;
		else ans += End - before;
	}
	ans += t;
	printf("%d",ans);
}

Measured memory_bytes: 128
N, W = map(int,input().split())

dp = [[0]*(W+1) for i in range(N+1)]

#print(dp)

for i in range(N):
    w, v = map(int,input().split())
    for j in range(W+1):
        if j - w >= 0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
        else:
            dp[i+1][j] = dp[i][j]


print(dp[-1][-1])







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

using namespace std;

#define allof(x) (x).begin(), (x).end()

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

const int MAXN = 505;

int N, M, Q;

int tmp[MAXN];
int tot[MAXN];
vector<int> trains[MAXN];
vector<pii> queries[MAXN];
int out[100005];

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

    cin >> N >> M >> Q;

    for(int a = 1; a <= M; a++){
        int l, r;
        cin >> l >> r;
        trains[l].push_back(r);
    }

    for(int a = 1; a <= Q; a++){
        int p, q;
        cin >> p >> q;
        queries[p].push_back({q, a});
    }

    for(int a = N; a >= 1; a--){
        for(int i : trains[a]){
            tmp[i]++;
        }
        for(int b = a; b <= N; b++){
            tmp[b] += tmp[b - 1];
            tot[b] += tmp[b];
        }
        for(int b = 1; b <= N; b++){
            tmp[b] = 0;
        }

        for(pii p : queries[a]){
            out[p.second] = tot[p.first];
        }
    }

    for(int a = 1; a <= Q; a++){
        cout << out[a] << "\n";
    }
}


Measured memory_bytes: 3712
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

int main(){
    int n, a, b;
    while(scanf("%d", &n)!=EOF){
        if(n == 1){
            printf("Hello World\n");
            continue;
        }
        scanf("%d%d", &a, &b);
        printf("%d\n", a+b);
    }

    return 0;
}

Measured memory_bytes: 256
fun cToI(c: Char): Int {
  return c - '0'
}

fun main(args: Array<String>) {
  val s = readLine()!!
  val n = s.length
  val x1 = s.map(::cToI).sum()
  val x2 = cToI(s[0]) - 1 + 9 * (n - 1)
  println(Math.max(x1, x2))
}


Measured memory_bytes: 33716
def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    dx = [0, -1, 1, 0]
    dy = [-1, 0, 0, 1]
    flag = True

    for i in range(H):
        for j in range(W):
            if s[i][j] == ".":
                continue

            cnt = 0
            for k in range(4):
                x = j + dx[k]
                y = i + dy[k]
                if x >= 0 and x < W and y >= 0 and y < H:
                    if s[y][x] == "#":
                        cnt += 1

            if cnt == 0:
                flag = False

    if flag == True:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9084
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
T_my = ['?' for i in range(N)]
ans = 0
same_flag = 0
# 0:K個前が違う手
# 1:K個前が同じ手，かつ，勝っている
# 2:K個前が同じ手，かつ，負けている

for i in range(N):
  if i < K: # K回目までは常に勝てる
    if T[i] == 'r':
      ans += P
      T_my[i] = 'p'
    if T[i] == 's':
      ans += R
      T_my[i] = 'r'
    if T[i] == 'p':
      ans += S
      T_my[i] = 's'
  else:
    if T[i] == 'r':
      T_my[i] = 'p'
    if T[i] == 's':
      T_my[i] = 'r'
    if T[i] == 'p':
      T_my[i] = 's'
    if T[i] == T[i-K]:
      if T_my[i-K] == T_my[i]:
        T_my[i] = '?'
      else:
        if T[i] == 'r':
          ans += P
        if T[i] == 's':
          ans += R
        if T[i] == 'p':
          ans += S
    else:
      if T[i] == 'r':
        ans += P
      if T[i] == 's':
        ans += R
      if T[i] == 'p':
        ans += S
        
print(ans)

Measured memory_bytes: 4212
#include <iostream>
using namespace std;
int main()
{
	int H, W, i, j;
	while(1){
		cin >> H >> W;
		if(W == 0 & H == 0)
			break;
		
		for( i = 0; i < H; i++){
			for( j = 0; j < W; j++){
				if((i + j) % 2 == 0){
					cout << "#";
				}else{
					cout << ".";
				}
			}
				cout << endl;
			}
			cout << endl;
		}
	return 0;
}
	

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

using namespace std;

typedef long long ll;

double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  string s; read(s);
  if(s.substr(0, 4) == "YAKI") {
    print("Yes");
  }
  else {
    print("No");
  }
}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		long long h,w;
		cin >> h >> w;
		if (h==1 || w==1) cout << 1 << endl;
		else
		cout << (h*w+1)/2 << endl;
		return 0;  
}  


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define srep(i,j,n) for (int i = j; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll inf = 1001001001;
vector<ll> dp(100001,inf);
int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n)
    cin >> h[i];
    dp[0] = 0;
    rep(i,n){
        srep(j,1,k+1){
            if(i+j<n)
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 1792
if __name__ == "__main__":
    n = int(input())
    s = list()
    d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in range(n):
        s.append(input())

    for ss in s:
        if ss[0] in d.keys():
            d[ss[0]] += 1

    ans = 0
    for i in d:
        for j in d:
            for k in d:
                if i != j and i != k and j != k:
                    ans += d[i] * d[j] * d[k]

    print(ans//6)


Measured memory_bytes: 9808
#include <iostream>
#include <map>
#include <vector>
using namespace std;

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


  map <int, int, greater<int>> seen;

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    ++seen[x];
  }

  vector <long long> ans;
  for (auto it = seen.begin(); it != seen.end(); ++it) {
    if (ans.size() >= 2)
      break;
    if (it->second >= 4) {
      ans.push_back(it->first);
      ans.push_back(it->first);
    } else if (it->second >= 2) {
      ans.push_back(it->first);
    }
  }

  if (ans.size() < 2) {
    cout << 0 << endl;
  } else {
    long long answer = ans[0] * ans[1];
    cout << answer << endl;
  }
}


Measured memory_bytes: 4992
import heapq
N = int(input())
A = list(map(int, input().split()))+[0]*4
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
a, b = -10**18, -10**18
while True:
  x = heapq.heappop(A)
  if a == x:
    break
  else:
    a = x
while True:
  x = heapq.heappop(A)
  if b == x:
    break
  else:
    b = x
print(a*b)

Measured memory_bytes: 20360