akhauriyash/Code-Regression huggingface dataset:
///   BISMILLAHIR RAHMANIR RAHEEM
///   ALLAH IS WATCHING ME
///   ALLAH save us from COVID-19.Amin.

///   █▀█─█──█──█▀█─█─█
///   █▄█─█──█──█▄█─█▄█
///   █─█─█▄─█▄─█─█─█─█

///   كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
///   Every soul shall taste death.


///   Author : Md Mehraj Hossain
///   Tag :

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
// order_of_key return number of elements less than x
// find_by_order return index.

using namespace std;
using namespace __gnu_pbds;

#define ull      unsigned long long
#define ll       long long
#define ld       long double
#define pb       push_back
#define MOHAMMAD ios::sync_with_stdio(0);cin.tie(0);
#define ses      "\n"
#define all(x)   (x).begin(), (x).end()
#define pi       2*acos(0.0)
#define AE       cout << fixed << setprecision(10);

string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

const ll MAXN=3e5+1;
const ll MOD = 1e9+7;

template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0)
        return 1;
    if(e%2==0)
    {
        ll t=bigmod(p,e/2,M);
        return (T)((t*t)%M);
    }
    return (T)((ll)bigmod(p,e-1,M)*(ll)p)%M;
}

template < class T > inline T modinverse( T a,T M )
{
    return bigmod( a,M-2,M );   // when M is prime;
}

typedef tree< ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/// Fast read.
template<class T>inline bool read(T &x)
{
    int c=getchar();
    int sgn=1;
    while(~c&&c<'0'||c>'9')
    {
        if(c=='-')
            sgn=-1;
        c=getchar();
    }
    for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())
        x=x*10+c-'0';
    x*=sgn;
    return ~c;
}


//***********************************************  The END **********************************************************************************************************************************

/////////////////////////////////////////////////////////////////////////////

 const ll N = 1e7;

 ll divisor[N + 1];
 void sieve(){
 for ( ll i = 1 ; i<=N ; ++i ){
     for ( ll k = i ; k<=N ; k+=i ){
         divisor[k]++;
     }
 }
 for ( ll i = 1 ; i<=N ; ++i ){
     divisor[i] = (i*divisor[i]);
     divisor[i]+=divisor[i-1];
 }
 }

////////////////////////////////////////////////////////////////////////////

//main function is here.........
int main()
{

    MOHAMMAD
   sieve();
   ll n;
   cin >> n;
   cout << divisor[n];
}

/*




  Alhamdulillah
*/



Measured memory_bytes: 81760
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	hlist := make([]int, n)
	for i := 0; i < n; i++ {
		hlist[i] = nextInt()
	}

	for i := n - 1; 0 < i; i-- {

		// 前が平らか減っていたらスルー
		if hlist[i-1] <= hlist[i] {
			continue
		}

		// 前が増えていても1減らしてOKならよし
		hlist[i-1]--
		if hlist[i-1] <= hlist[i] {
			continue
		} else {
			// 1減らしてもダメなら終わり。
			fmt.Println("No")
			return
		}

	}
	fmt.Println("Yes")

	//fmt.Println(n, hlist)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(){
  int N;
  cin >> N;
  if(int(int(N/1.08)*1.08)==N){
    cout << int(N/1.08) << endl;
  }else if(int((int(N/1.08)+1)*1.08)==N){
    cout << int(N/1.08)+1 << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
a,b=map(int,input().split())
x=0
if a>=b:
    x+=a
    a-=1
    if a>=b:
            x+=a
    else :
            x+=b
elif a<b:
    x+=b
    b-=1
    if a>=b:
            x+=a
    else :
            x+=b
print(x)   

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}


int main(){
  int d; cin >> d;
  if(d == 25) cout << "Christmas" << "\n";
  else if(d == 24) cout << "Christmas Eve" << "\n";
  else if(d == 23) cout << "Christmas Eve Eve" << "\n";
  else if(d == 22) cout << "Christmas Eve Eve Eve" << "\n";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [[int(_) for _ in input().split()] for _ in range(2)]

candies_history_1 = []
candies_history_2 = []

candies_history_1.append(A[0][0])
candies_history_2.append(A[1][N - 1])

for i in range(1, N):
    candies_history_1.append(A[0][i] + candies_history_1[i - 1])
    candies_history_2.append(A[1][N - 1 - i] + candies_history_2[i - 1])

candies_history_2.reverse()

print(max([r1 + r2 for r1, r2 in zip(candies_history_1, candies_history_2)]))



Measured memory_bytes: 3064
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,ma,mb,a,b,c;

struct Drug{ int a,b,c; };
vector<Drug> l;

int dp[501][501][41];

signed main(){
    I(n);
    I(ma); I(mb);
    REP(i,n){
        I(a); I(b); I(c);
        l.pb(Drug({a,b,c}) );
    }
    REP(i,501) REP(j,501) REP(k,41) dp[i][j][k] = 1e+10;
    dp[0][0][0] = 0;
    REP(k,n){
        a = l[k].a;
        b = l[k].b;
        c = l[k].c;
        REP(i,501) REP(j,501){
            for (int ii=i,ij=j,ic=0; ii>=0 && ij>=0 && ic<=c; ii-=a, ij-=b, ic+=c){
                dp[i][j][k+1] = min(dp[i][j][k+1], dp[ii][ij][k] + ic);
            }
        }
    }
    int ret = 1e+10;
    for(int ii=ma,ij=mb; ii<501 && ij<501; ii+=ma,ij+=mb){
        ret = min(ret, dp[ii][ij][n]);
    }
    cout << (ret < 1e+9 ? ret : -1) << endl;


}


Measured memory_bytes: 80640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vector<vector<int>> g;
vector<int> d, f;

int dfs(int v, int t)
{
    // cout << v << " ";
    if (f[v] != INT32_MAX)
    {
        return f[v];
    }
    if (d[v] != INT32_MAX && f[v] == INT32_MAX)
    {
        return t - 1;
    }

    d[v] = min(d[v], t);

    int tt = t + 1;
    for (auto to : g[v])
    {
        if (v == to)
            continue;
        tt = max(tt, dfs(to, tt) + 1);
    }
    f[v] = min(tt, f[v]);

    return tt;
}

int main()
{
    int n;
    cin >> n;
    g = vector<vector<int>>(n, vector<int>());
    d = vector<int>(n, INT32_MAX);
    f = vector<int>(n, INT32_MAX);

    rep(i, n)
    {
        int k;
        cin >> k >> k;
        rep(j, k)
        {
            int t;
            cin >> t;
            t--;
            g[i].emplace_back(t);
        }
    }

    int t = 1;
    rep(i, n)
    {
        if (f[i] == INT32_MAX)
        {
            t = dfs(i, t) + 1;
        }
    }

    rep(i, n)
    {
        cout << (i + 1) << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> t;
  vector<P> ab;

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    ab.push_back(P(a, b));
  }

  sort(ab.begin(), ab.end());

  int dp[n + 1][6001];

  REP(i, n) {
    REP(j, 6001) {
      if(j - ab[i].first >= 0 && j - ab[i].first < t) {
        dp[i + 1][j] = max(dp[i][j - ab[i].first] + ab[i].second, dp[i][j]);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  int ans = 0;
  REP(i, 6001) ans = max(ans, dp[n][i]);

  cout << ans << endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  constexpr std::int64_t kModulus = 1'000'000'007;
  int S;
  std::cin >> S;
  std::vector<std::int64_t> counts(S + 1);
  counts[0] = 1;
  for (int i = 3; i <= S; ++i) {
    for (int j = 0; j + 3 <= i; ++j) {
      counts[i] += counts[j];
    }
    counts[i] %= kModulus;
  }
  std::cout << counts[S] << std::endl;
  return 0;
}


Measured memory_bytes: 3624
const mo=1000000007;
var
	n,m,i,j:longint;
	f:Array[0..600,0..600]of char;
begin
	readln(n,m);
	for i:=0 to n-1 do
	begin
		for j:=0 to m-1 do read(f[i,j]);
		readln;
	end;
	for i:=0 to n-1 do
	begin
		for j:=0 to m-1 do
		begin
			if j=0 then write('.')
			else if i and 1=0 then write('#')
			else if (i and 1<>0)and(j=m-1)then write('#')
			else if f[i,j]='#' then write('#')
			else write('.');
		end;
		writeln;
	end;
	writeln;
	for i:=0 to n-1 do
	begin
		for j:=0 to m-1 do
		begin
			if j=m-1 then write('.')
			else if i and 1<>0 then write('#')
			else if (i and 1=0)and(j=0)then write('#')
			else if f[i,j]='#' then write('#')
			else write('.');
		end;
		writeln;
	end;
end.

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

signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  map<int,int> co;
  rep(i,N){
    cin>>A[i];
    co[A[i]]=0;
  }
  int ans=0;
  rep(i,N){
    co[A[i]]+=1;
    co[A[i]+1]+=1;
    co[A[i]+2]+=1;
  }
  rep(i,N)ans=max(ans,co[A[i]]);
  cout<<ans<<endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	cout<<N-K+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INFTY 200000000000
long long dp[310][310];
vector<long long> a(310);
int b;
const double PI=3.1415926535897932;
int main(){
    double r;
    cin >> r;
    cout << 2*r*PI<<endl;
    return 0;
}

Measured memory_bytes: 3792
class Dice:
    # constructor
    def __init__(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes = {
            "top": eye1,
            "front": eye2,
            "right": eye3,
            "left": eye4,
            "back": eye5,
            "bottom": eye6
        }
    # setter
    def set_eyes(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes["top"] = eye1
        self.__eyes["front"] = eye2
        self.__eyes["right"] = eye3
        self.__eyes["left"] = eye4
        self.__eyes["back"] = eye5
        self.__eyes["bottom"] = eye6
    # getter
    def get_eyes(self, key):
        return self.__eyes[key]

    
    def N(self):
        self.set_eyes(
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("top"),
            self.get_eyes("back")
            )
    def S(self):
        self.set_eyes(
            self.get_eyes("back"),
            self.get_eyes("top"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("bottom"),
            self.get_eyes("front")
            )
        
    def E(self):
        self.set_eyes(
            self.get_eyes("left"),
            self.get_eyes("front"),
            self.get_eyes("top"),
            self.get_eyes("bottom"),
            self.get_eyes("back"),
            self.get_eyes("right")
            )
        
    def W(self):
        self.set_eyes(
            self.get_eyes("right"),
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("top"),
            self.get_eyes("back"),
            self.get_eyes("left")
            )
    
    def print_top(self):
        print(self.get_eyes("top"))
    

    def guess_right_from_top_front(self, top, front):
        key_top = None
        key_front = None
        keys = [ 
        "top", 
        "front", 
        "right", 
        "left", 
        "back", 
        "bottom"
        ]
        for key in keys:
            if top == self.get_eyes(key):
                key_top = key
            if front == self.get_eyes(key):
                key_front = key
        keys_for_top = [
            ["front", "right", "back", "left"],
            ["bottom", "right", "top", "left"],
            ["bottom", "back", "top", "front"],
            ["bottom", "front", "top", "back"],
            ["bottom", "left", "top", "right"],
            ["front", "left", "back", "right"]
        ]
        
        for i in range(6):
            if key_top == keys[i]:
                for j in range(4):
                    if key_front == keys_for_top[i][j]:
                        return keys_for_top[i][(j + 1) % 4]

eye1, eye2, eye3, eye4, eye5, eye6 = map(int, input().split())
q = int(input())
dice = Dice(eye1, eye2, eye3, eye4, eye5, eye6)
for _ in range(q):
    top, front = map(int, input().split())
    print(dice.get_eyes(dice.guess_right_from_top_front(top, front)))



Measured memory_bytes: 5792
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
cross(double x0, double y0, double x1, double y1, double x2, double y2)
{
	const double EPS = 1e-10;
	double ax = x1 - x0, ay = y1 - y0;
	double bx = x2 - x0, by = y2 - y0;
	double c = ax * by - ay * bx;

	if (c < -EPS)
		return -1;
	else if (c > EPS)
		return 1;
	else
		return 0;
}

int
main(int argc, char** argv)
{
	int i;

	while (true)
	{
		double x[4], y[4];
		int dir;

		if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) == EOF)
			break;

		dir = cross(x[0], y[0], x[1], y[1], x[2], y[2]);
		for (i = 1; i < 4; ++i)
		{
			if (cross(x[i], y[i], x[(i + 1) % 4], y[(i + 1) % 4], x[(i + 2) % 4], y[(i + 2) % 4]) != dir)
				break;
		}

		printf("%s\n", (i >= 4) ? "YES" : "NO");
	}

	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
	ll n;
    cin >> n;
    
    ll arr[n];
    for(ll i=0;i<n;i++) cin >> arr[i];
    ll money = 1000;
    ll stock = 0;
    ll flag = 0;
    for(ll i=0;i<n;i++)
    {
        if(i == 0)
        {
            if(i + 1 < n && arr[i] < arr[i + 1])
            {
                 stock = money/arr[i];
                money = money - stock * arr[i];
                flag = 1;
            }
           
              
        }
        else
        {
             if(flag ==1 && i  < n && arr[i] >= arr[i - 1])
            {
                while(arr[i] >= arr[i - 1] && i < n)
                {
                    i++;
                }
				i--;
                 money += stock * arr[i];
                    stock = 0;
                    flag = 0;
                continue;
            }

            if(flag == 0 && i < n && arr[i] <= arr[i - 1])
            {
                while(arr[i] <= arr[i - 1] && i< n)
                {
                    i++;
                }
                i--;
                 stock = money/arr[i];
                    money = money - stock * arr[i];
                    flag = 1;
                continue;
            }

        }        
    }
   // cout << money << endl;
    cout << money + stock * arr[n - 1]<< endl;
	return 0;
}

Measured memory_bytes: 3632
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,Q=map(int,input().split())
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b,c,d=map(int,input().split())
    edge[a-1].append((b-1,c,d))
    edge[b-1].append((a-1,c,d))

prv=[-1]*N
depth=[0]*N
dist=[0 for i in range(N)]
def dfs(v,pv):
    prv[v]=pv
    for nv,color,weight in edge[v]:
        if nv!=pv:
            depth[nv]=depth[v]+1
            dist[nv]=dist[v]+weight
            dfs(nv,v)

dfs(0,-1)

LV = (N-1).bit_length()
def construct(prv):
    kprv = [prv]
    S = prv
    for k in range(LV):
        T = [0]*N
        for i in range(N):
            if S[i] is None:
                continue
            T[i] = S[S[i]]
        kprv.append(T)
        S = T
    return kprv

kprv=construct(prv)

def lca(u, v):
    dd = depth[v] - depth[u]
    if dd < 0:
        u, v = v, u
        dd = -dd

    # assert depth[u] <= depth[v]
    for k in range(LV+1):
        if dd & 1:
            v = kprv[k][v]
        dd >>= 1

    # assert depth[u] == depth[v]
    if u == v:
        return u

    for k in range(LV-1, -1, -1):
        pu = kprv[k][u]; pv = kprv[k][v]
        if pu != pv:
            u = pu; v = pv

    # assert kprv[0][u] == kprv[0][v]
    return kprv[0][u]

query=[]
q=[[] for i in range(N)]
data={}
for i in range(Q):
    x,y,u,v=map(int,input().split())
    LCA=lca(u-1,v-1)
    query.append((x,y,u-1,v-1,LCA))
    q[u-1].append(x)
    q[v-1].append(x)
    q[LCA].append(x)

num=[0 for i in range(N)]
cdist=[0 for i in range(N)]

def dfsc(v,pv,color,weight):
    pn=num[color]
    num[color]+=1
    pd=cdist[color]
    cdist[color]+=weight
    for x in q[v]:
        data[(v,x)]=(0,0)
        data[(v,x)]=(num[x],cdist[x])

    for nv,ncolor,nweight in edge[v]:
        if nv!=pv:
            dfsc(nv,v,ncolor,nweight)

    num[color]=pn
    cdist[color]=pd



dfsc(0,0,0,0)

for x,y,u,v,LCA in query:
    d1=dist[LCA]-data[(LCA,x)][1]+data[(LCA,x)][0]*y
    d2=dist[u]-data[(u,x)][1]+data[(u,x)][0]*y
    d3=dist[v]-data[(v,x)][1]+data[(v,x)][0]*y
    print(d2-d1+d3-d1)

Measured memory_bytes: 193292
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
using namespace std;

void Onigiri()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  rep(i,0,n)
  cin>>a[i];
  int tot=accumulate(a,a+n,0LL);
  double mm=tot/(4.00*m);
  sort(a,a+n);
  int cnt=0;
  repr(i,n-1,0)
  {
    if(a[i]<mm)
      break;
    else cnt++;
  }

  if(cnt>=m)
    cout<<"Yes";
  else cout<<"No";
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ;
    cin >> N ;
    vector<ll> a;
    
    rep(i, N){
        ll inp;
        cin >> inp;
        a.pb(inp);
    }
    
    ll sum = a[0];
    rep(i, a.size()){
        if(i == 0) continue;
        sum ^= a[i];
    }
    
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    


    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
import sys
f = sys.stdin


while True:
    n, m = map(int, f.readline().split())
    if n == 0:
        break
    vegitables = sorted(map(int, f.readline().split()), reverse=True)
    discount = sum(vi for i, vi in enumerate(vegitables) if (i + 1) % m == 0)
    print(sum(vegitables) - discount)

Measured memory_bytes: 6784
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define rep(i,b,n) for(int (i) = (b) ; (i) < (n) ; (i) ++)
#define anin(ans) printf("%d\n",ans);

int main(void){
	int i,I,M,D,ans(0);
	scanf("%d %d",&M,&D);
	for(I = 2 ; I <= M ; I ++){
		for(i = 2 ; i <= D / 10 ; i ++){
			if(I % i == 0 && I / i + i * 10 <= D && I / i > 1 && I / i < 10){
				ans ++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	int n;	cin>>n;
	int _A=0, B_=0, B_A=0;
	int ans=0;
	for(int i=0;i<n;i++){
		string s;	cin>>s;
		for(int j=0;j+1<s.length();j++){
			if(s[j]=='A'&&s[j+1]=='B')ans++;
		}

		if(s[0]=='B'&&s[s.length()-1]=='A')B_A++;
		else if(s[0]=='B')B_++;
		else if(s[s.length()-1]=='A')_A++;
	}
	//printf("_A:%d\n",_A);
	//printf("B_:%d\n",B_);
	//printf("B_A:%d\n",B_A);
	if(B_A==0){
		ans+=min(_A,B_);
	}else if(_A==0 && B_==0){
		ans+=max(B_A-1,0);
	}else{
		ans+=min(_A,B_)+B_A;
	}

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


Measured memory_bytes: 256
N=int(input())
permu=list(map(lambda x:int(x),input().split()))
counter=0

for i in range(1,N-1):
    p=[]
    p.append(permu[i-1])
    p.append(permu[i])
    p.append(permu[i+1])
    p=sorted(p)
    if p[1]==permu[i]:
        counter+=1

print(counter)

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

int main()
{
	int i;
	cin >> i;
    if(i < 10){
    	cout << i << endl;
    	return 0;
	}else if(i < 100){
		cout << 9 << endl;
		return 0;
	}else if(i < 1000){
		cout << 10 + i - 100 << endl;
		return 0;
	}else if(i < 10000){
		cout << 909;
		return 0;
	}else if(i < 100000){
		cout << 910 + i - 10000 << endl;
		return 0;
	}else{
		cout << 90909 << endl;
		return 0;
	}
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    if 1 <= int(S[:2]) <= 12:
        if 1 <= int(S[2:]) <= 12:
            print('AMBIGUOUS')
        else:
            print('MMYY')
    else:
        if 1 <= int(S[2:]) <= 12:
            print('YYMM')
        else:
            print('NA')


if __name__ == '__main__':
    main()


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

string s, t;
int ls, lt;

string pro(int id)
{
    string x = s;
    for(int i = id, j = 0; j < lt; j++, i++){
        if(x[i] == '?')
            x[i] = t[j];
        else if(x[i] != t[j])
            return "0";
    }

    for(int i = 0; i < ls; i++){
        if(x[i] == '?')
            x[i] = 'a';
    }

    return x;
}

int main()
{
    cin >> s >> t;

    ls = s.size(), lt = t.size();

    vector<string> v;
    for(int i = 0; i <= ls - lt; i++){
        string x = pro(i);
        if(x != "0")
            v.Pb(x);
    }

    if(v.size() == 0)
        return cout << "UNRESTORABLE\n", 0;

    cout << *min_element(All(v)) << '\n';
    return 0;
}


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

int main(){
    int N;
    cin >>N;
    vector<int> P(N),Q(N);
    vector<int> R(N);

    for(int i=0;i<N;i++){
        cin >>P.at(i);
    }

    for(int i=0;i<N;i++){
        cin >>Q.at(i);
    }

    for(int i=0;i<N;i++){
        R.at(i) = i+1;
    }

    map<vector<int> ,int> mp;
    do
    {
        mp[R] = mp.size(); 
    } while (next_permutation(R.begin(),R.end()));
    
    int ans = abs(mp[P]-mp[Q]);
    cout <<ans<<endl;

}

Measured memory_bytes: 5248
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int r, D, x[20000];
	scanf("%d%d%d", &r, &D, &x[2000]);
	for (int i = 2001; i <= 2010; i++) {
		x[i] = r * x[i - 1] - D;
		printf("%d\n", x[i]);
	}
	return 0;
}

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

int calc(int x){
	int cnt = 0;
  	while(x % 100 == 0){
    	x /= 100;
      	cnt++;
    }
  	return cnt;
}

int main() {
    int d, n;
  	cin >> d >> n;
  	int cnt = 0, val = 0;
  	while(cnt < n){
    	val++;
      	if(calc(val) == d) cnt++;
    }
  	cout << val << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define go(i, a, n) for (ll i = a; i < n; i++)
#define gor(i, a, n) for (int i = n - 1; i >= a; i--)
#define show(x) cout << x << '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vpair vector<pair<ll, ll>>
#define vtuple vector<tuple<ll, ll, ll>>
#define ff first
#define ss second
#define mod 1000000007
#define memset(a, k) memset(a, k, sizeof(a))
#define answer(z, k) cout << "Case #" << z << ": " << k << endl;
auto t1 = chrono::high_resolution_clock::now();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ld r;
	cin>>r;
	cout<<fixed<<setprecision(20)<<(ld)2*M_PI*r<<endl;
	auto t2 = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
	clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
	return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
	
typedef int Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
//引数 g:隣接リスト,r:最小全域木の始点
//戻値 total:最小全域木の重み,T:最小全域木の辺集合
pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  int n = g.size();
  Edges T;
  Weight total = 0;
  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) );    //始め、-1とrを結ぶ辺があると考える
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();++f) if(!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}

//-----------------
int main()
{ 
    while(true){
        int i, a, b, n, m;
        Weight c;
        cin >> n >> m;
        if((n==0)&(m==0))break;
        Graph g(n);    //頂点数vの空隣接リストgを生成
        for(i=0; i<m; i++){
            cin >> a >> b >> c;    
            g[a].push_back(Edge(a, b, c));    //隣接リストgにsからtに向かう重さwの辺を追加
            g[b].push_back(Edge(b, a, c));
        }
        pair<Weight,Edges>ans=prim(g);
        cout << ans.first << endl;
    }
  
    return 0;
}



Measured memory_bytes: 2988
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] o = scan.next().split("");
		String[] e = scan.next().split("");
		String result = "";
		int len = e.length;

		for(int i=0; i<len; i++ ) {
			result += o[i]+e[i];
		}

		System.out.println( (o.length>e.length)? result+o[o.length-1] : result);
	}

}

Measured memory_bytes: 22100
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
	int X=s.nextInt();
    int Y=s.nextInt();
    int i=0;
    
	for(;i<=X;i++){
      int x=i;
      int y=X-i;
      if(2*x+4*y==Y){
        System.out.println("Yes");
        break;
      }
    }
    
    if(i==X+1)System.out.println("No");
  }  
}

Measured memory_bytes: 35744
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,k,i,b;
	int a[100];
	cin>>n>>k;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
	}
	b=0;
	for (i=0;i<n;i++)
	{
		if(abs(a[i]-0>=abs(a[i]-k)))
		{
			b=b+abs(a[i]-k)*2;
		}
		else
		{
			b=b+abs(a[i]-0)*2;
		}
	}
	cout<<b<<endl;
	return 0;
}

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

int n, k;
int w[100000], d[100000];

bool check(int x) {
	int num = 0;
	for (int i = 0; i < n; i++) {
		if (x < w[i]) continue;
		num += (x - w[i]) / d[i] + 1;
	}
	if (num >= k) return true;
	return false;
}

signed main() {
	int i;
	
	cin >> n >> k;
	for (i = 0; i < n; i++) cin >> w[i] >> d[i];
	
	int st = 0, ed = 2e+18;	//X in (st, ed]
	while (ed - st >= 2) {
		int mid = (st + ed) / 2;
		if (check(mid)) { ed = mid; }
		else { st = mid; }
	}
	cout << ed << endl;
	return 0;
}

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

const ll INF = 1ll << 60;
ll MOD = 998244353;

int main()
{

    int n;
    cin >> n;
    vector<int> d(n);

    REP(i, n)
    cin >> d[i];
    sort(d.begin(), d.end());

    int left = 0;
    int right = (int)d.size() - 1;

    int mid = left + (right - left) / 2;
    if (d[mid] == d[mid + 1])
    {
        //cout << d[mid] << " " << d[mid + 1] << endl;
        puts("0");
        return 0;
    }
    int diff = d[mid + 1] - d[mid];

    int ans = 0;
    cout << diff;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

int main(void){
    double N, M; cin >> N >> M;
    vector<double> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    
    double sum = 0;
    for(int i = 0; i < N; i++) sum += A[i];
    
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if (A[i] >= (sum / (4 * M))) cnt++;
    }
    
    if (cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;

void input() {
	cin>>N;
}

void solve() {
	int cnt=0;
	for(int i=0; i<N; i++) {
		int d,e; cin>>d>>e;
		if(d==e) cnt++;
		else cnt=0;

		if(cnt==3) {
			cout<<"Yes"<<endl;
			return;
		}
	}

	cout<<"No"<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int main(){
  long long n;
  cin >> n;
  long long a = 1;
  long long b = 1;
  long long c = 1;
  for(long long i = 1;i <= n;i++){
    a = a *10 % mod;
    b =b * 9 % mod;
    c =c * 8 % mod;
  }
  cout << ((a - 2 * b + c) % mod + mod) % mod << endl;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

vector<int> pr[2];

char buf[100010];
void get(vector<int>& v){
	scanf("%s", buf+1);
	int n = strlen(buf+1);
	v.resize(n+1, 0);
	for(int i=1; i<=n; ++i){
		v[i]=v[i-1]+1;
		if(buf[i]=='B') ++v[i];
	}
}

int main()
{
	get(pr[0]);
	get(pr[1]);
	int q;
	read(q);
	for(;q--;){
		int a,b,c,d;
		read(a,b,c,d);
		int u=pr[0][b]-pr[0][a-1];
		int v=pr[1][d]-pr[1][c-1];
		u%=3; v%=3;
		u=(u-v+9)%3;
		puts(u == 0 ? "YES" : "NO");
	}
    return 0;
}


Measured memory_bytes: 1408
#ifdef EPIQ_LOCAL
#define DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T> void debug2(T b, T e) { auto it=b; while (it != e) cerr << *it++ << " "; cerr << endl; }
#define TRACE(x) x
#else
#define debug(x)
template<typename T> void debug2(T b, T e) {}
#define TRACE(x)
#endif
#define mp(x, y) make_pair((x),(y))
#define pb(x) push_back(x)
#define eb emplace_back
#define forn(v, b, e) for (auto v = (b); v < (e); v++)
#define SZ(x) ((int)(x).size())
#define st first
#define nd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
const ld pi = acos(-1);
template<typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {os << "[" << p.first << "," << p.second << "]"; return os;}
template<typename T1, typename T2, typename T3>
ostream& operator<< (ostream& os, const tuple<T1,T2,T3>& t) {os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; return os;}

void solve() {
    int a, b, k;
    cin >> k >> a >> b;
    
    int t = (a + k - 1) / k * k;
    debug(t);
    if (a <= t && t <= b) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
}

int main()
{
    TRACE(clock_t _t1 = clock();)
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(12);

    solve();

    TRACE(cerr << "Time elapsed: " << (double)(clock() - _t1) / CLOCKS_PER_SEC << endl;)

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		int a = reader.nextInt();
		int b = reader.nextInt();
		int c = reader.nextInt();
		if ((a < b) && (b < c)){
			System.out.println("Yes");
		} else {System.out.println("No");}
	}
}

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

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

    int h, w, items;
    cin >> h >> w >> items;
    vector<vector<int>> grid(h, vector<int>(w));

    while (items--){
    	int r, c, val;
    	cin >> r >> c >> val;
    	--r, --c;
    	grid[r][c] = val;
    }

    vector<vector<vector<long long>>> dp(h, vector<vector<long long>>(w, vector<long long>(4, -1)));
    for (int row = 0; row < h; ++row){
    	for (int col = 0; col < w; ++col){
    		if (row == 0 && col == 0){
    			dp[row][col][0] = 0;
    			dp[row][col][1] = grid[row][col];
    		}
    		else{
    			if (row){
    				dp[row][col][0] = *max_element(dp[row - 1][col].begin(), dp[row - 1][col].end());
    				dp[row][col][1] = dp[row][col][0] + grid[row][col];
    			}
    			for (int k = 0; k <= 3; ++k){
    				if (col){
    					dp[row][col][k] = max(dp[row][col][k], dp[row][col - 1][k]);
    					if (k && dp[row][col - 1][k - 1] != -1){
    						dp[row][col][k] = max(dp[row][col][k],
    							dp[row][col - 1][k -1] + grid[row][col]);
    					}
    				}
    			}
    		}
    	}
    }

    cout << *max_element(dp[h - 1][w - 1].begin(), dp[h - 1][w - 1].end()) << '\n';
    return 0;
}

Measured memory_bytes: 671480
import java.util.Scanner;

/**
 * B - Easy Linear Programming
 * 1 が書かれたカードが A 枚、0 が書かれたカードが B 枚、−1 が書かれたカードが C 枚あります。
 * これらのカードから、ちょうど K 枚を選んで取るとき、取ったカードに書かれた数の和として、 ありうる値の最大値はいくつですか。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();

        long result = 0;


        if( k <= a ) {
            result = k;
        }
        else if( k <= a + b ) {
            result = a;
        }
        else if( k <= a + b + c ) {
            result = a - ( k - a - b );
        }

        System.out.println( result );

        sc.close();
    }
}


Measured memory_bytes: 35796
MOD = 1_000_000_007

FACT = [1]
(1..2000).each do |k|
  FACT << FACT[-1] * k % MOD
end

def exp(n, k)
  x = 1
  r = n
  while k > 0
    x *= r if k & 1 == 1
    r *= r
    x %= MOD
    r %= MOD
    k >>= 1
  end
  x
end

def inv(n)
  exp(n, MOD - 2)
end

def perm(n, k)
  n >= k ? FACT[n] * inv(FACT[n - k]) % MOD : 0
end

def comb(n, k)
  perm(n, k) * inv(FACT[k]) % MOD
end

n, k = gets.split.map(&:to_i)
p comb(n + k - 1, n)


Measured memory_bytes: 6900
//written by: rishav2416
#include <bits/stdc++.h>
#define ll long  long
#define lli long long int
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define arrinit(arr,n,k) for(ll c1=0;c1<n;c1++) arr[i]=k;
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define revrep(i,a,n) for(ll i=a; i>=n ; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define INF 1e18a



ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}


std::string str="All Good Till Here";

/////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    fastio
	ll tt,i,j,x=0;
	//cin>>tt;
  tt=1;
	while(tt--)
	{
    ll n,k;
    cin>>n>>k;
    ll d, a[n]={0};
    rep(i,0,k)
    {
      cin>>d;
      ll p[d];
      input(p,d);
      rep(j,0,d)
      a[p[j]-1]++;
    }
    rep(i,0,n)
    {
      if(a[i]==0)x++;
    }
    cout<<x<<"\n";
	}
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int A, B, C; cin >> A >> B >> C;
  int d = A-B;

  if(C<=d) {
    cout << 0 << endl;
  }
  else {
    cout << (C-d) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP priority_queue
#define heap(T) priority_queue<T,vector<T>,greater<T> > 
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=(1<<20)+5,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
const int BufferSize=1<<25;
char buffer[BufferSize],*Bufferhead,*Buffertail;
int Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T> inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	x=rev?-x:x;
	return 1;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,k,bits[N],f[2][N],dp[N],a[55][55];
inline int calc(int x){return bits[x&-x];}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d%d",&n,&m,&k);
	n--;clr(a,-1);
	for(int i=0;i<=n;i++)
		bits[1<<i]=i;
	for(int i=1;i<=k;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		b--;::a[a][b]=c;
	}
	dp[0]=1;
	for(int i=1;i<=m;i++){
		clr(f,0);
		for(int j=0;j<(1<<n);j++)
			f[0][j]=dp[j];
		for(int j=0;j<n;j++){
			clr(f[j+1&1],0);
			for(int k=0;k<(1<<n);k++){
				if(!f[j&1][k]) continue; 
				if(a[i][j]!=0) 	
					if(k>>j) ch(f[j+1&1][k^(1<<j)^(1<<calc(k>>j)+j)],f[j&1][k]); else ch(f[j+1&1][k^(1<<j)],f[j&1][k]);
				if(a[i][j]!=1&&!(k&(1<<j)))	ch(f[j+1&1][k],f[j&1][k]);
			}
		}
		for(int j=0;j<(1<<n);j++)
			dp[j]=f[n&1][j];
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++) ch(ans,dp[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 18688
#include<iostream>
using namespace std;
#include <deque>
#include <cstring>
deque<char> dq;
char s[100005];
int main() {
    cin >> s;
    int Q, DeTop = 0, ls = strlen(s);
    for(int i = 0; i < ls; i++)
        dq.push_back(s[i]);
    cin >> Q;
    while(Q--) {
        int T, F;
        char k;
        cin >> T;
        if(T == 1)
            DeTop = DeTop == 0 ? 1 : 0;
        else {
            cin >> F >> k;
            if(DeTop == 0) {
                if(F == 1)
                    dq.push_front(k);
                else
                    dq.push_back(k);
            } else {
                if(F == 1)
                    dq.push_back(k);
                else
                    dq.push_front(k);
            }
        }
    }
    if(DeTop == 0)
        while(!dq.empty())
            printf("%c", dq.front()), dq.pop_front();
    else
        while(!dq.empty())
            printf("%c", dq.back()), dq.pop_back();
    cout << endl;
    return 0;
}


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

using namespace std;
long sumstring(string s){
    long result = stoll(s);
    for(int i=1; i<s.length(); i++){
        result += stoll(s.substr(0,i))*pow(2, s.length()-i-1);
        result += sumstring(s.substr(i));
    }
    return result;
}
int main(){
    string s;
    cin >> s;

    long result = sumstring(s);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256