akhauriyash/Code-Regression huggingface dataset:
class Node:
    def __init__(self, no):
        self.no = no
        self.parent = -1
        self.left = self.right = -1
    def postorder(self):
        global t
        L = []
        if self.left >= 0: L += t[self.left].postorder()
        if self.right >= 0: L += t[self.right].postorder()
        L.append(self.no)
        return L

def makeTree(parent, preList, inList):
    global t
    if preList == []:
        return -1
    root = preList[0]
    t[root].parent = parent
    index = inList.index(root)
    t[root].left = makeTree(root, preList[1:index+1], inList[:index])
    t[root].right = makeTree(root, preList[index+1:], inList[index+1:])
    return root

n = int(input())
t = [ Node(i) for i in range(n+1) ]
preList = list(map(int, input().split()))
inList = list(map(int, input().split()))
root = makeTree(-1, preList, inList)
print(*t[root].postorder())



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    forn(i, n) cin >> a[i];
    sort(allele(a));
    ll sum = 0;
    forn(i, n)
    {
        if(sum + a[i] > x) return cout << i, 0;
        sum += a[i];
    }
    cout << (sum == x ? n : n - 1);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, c, k) = readLine()!!.split(" ").map { it.toInt() }
    val t = Array(n) { readLine()!!.toInt()}.sorted()

    var ans = 0
    var bus = mutableListOf<Int>()

    for (i in 0 until n) {
        if (bus.size == c) {
            ans++
            bus.clear()
            bus.add(t[i])
        } else if (bus.isNotEmpty() && bus.get(0) + k < t[i]) {
            ans++
            bus.clear()
            bus.add(t[i])
        } else {
            bus.add(t[i])
        }
    }
    println(ans+1)
}

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

int main(void){
  int n;cin >> n;
  int d[n];rep(i,n)cin >> d[i];
  sort(d,d+n);
  cout << d[n/2]-d[n/2-1] << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int a[2000010],b[2000010],c[2000010];

void countingSort(int MAX, int n){
  int i;
  for(i=0;i<=MAX;i++) c[i]=0;

  for(i=1;i<=n;i++) c[a[i]]++;

  for(i=1;i<=MAX;i++) c[i]+=c[i-1];

  for(i=n;i>=1;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }
}

int main(){
  int n;
  int i,MAX=0;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if(MAX<a[i]) MAX=a[i];
  }

  countingSort(MAX,n);

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

Measured memory_bytes: 17892
n=int(input())
d=list(map(int,input().split()))
ans=1
x=sorted(d)
acount=1
count=1
sd=set(x)
sd=list(sd)
s=0

for i in range(1,n-1):
  if x[i]==x[i+1]:
    acount+=1
  elif x[i]!=x[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(x)>1 and x[-1]!=x[-2]:
  ans*=count
elif len(x)>1 and x[-1]==x[-2]:
  ans*=(count**acount)

  
for i in range(len(sd)-1):
  if sd[i]+1!=sd[i+1]:
    s=1
    
if s==0:
  if d[0]==0 and x[1]!=0:
    print(ans%998244353)
  else:
    print(0)
else:
  print(0)

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    for(ll A = -1000; A <= 1000; A++) {
        for(ll B = -1000; B <= 1000; B++) {
            if(A*A*A*A*A-B*B*B*B*B == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include <string.h>

using namespace std;

int main(){
 int num=0;
  char day[3];
  cin>>day;
  if(strcmp(day,"SUN")==0){
    cout<<"7"<<endl;
  }else if(strcmp(day,"MON")==0){
    cout<<"6"<<endl;
  }else if(strcmp(day,"TUE")==0){
    cout<<"5"<<endl;
  }else if(strcmp(day,"WED")==0){
    cout<<"4"<<endl;
  }else if(strcmp(day,"THU")==0){
    cout<<"3"<<endl;
  }else if(strcmp(day,"FRI")==0){
    cout<<"2"<<endl;
  }else if(strcmp(day,"SAT")==0){
    cout<<"1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Item {
	int cost,weight;

	Item(int c,int w) {
		this.cost = c;
		this.weight = w;
	}
}

class Main {
	private static final int NOT_ADD = -1;

	public static void main (String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
 
		try {
			int count = 1;
			while (true) {
				int W = Integer.parseInt(br.readLine());
				if (W==0) break;

				int N = Integer.parseInt(br.readLine());
				Item item[] = new Item[N];
				for (int i=0;i<N;i++) {
					StringTokenizer st = new StringTokenizer(br.readLine(),",");
					int c = Integer.parseInt(st.nextToken());
					int w = Integer.parseInt(st.nextToken());
					item[i] = new Item(c,w);
				}
				int T[][] = new int[N][W+1];
				for (int i=0;i<N;i++) {
					for (int j=0;j<=W;j++) T[i][j] = NOT_ADD;
				}
				T[0][0] = 0;
				T[0][item[0].weight] = item[0].cost;
				for (int i=1;i<N;i++) {
					for (int k=0;k<=W;k++) T[i][k] = T[i-1][k];
					for (int k=item[i].weight;k<=W;k++) {
						if (T[i-1][k-item[i].weight]!=NOT_ADD&&T[i-1][k-item[i].weight]+item[i].cost>T[i][k]) {
							T[i][k] = T[i-1][k-item[i].weight]+item[i].cost;
						}
					}
				}
				int MaxCost = T[N-1][0];
				int MaxWeight = 0;
				for (int i=0;i<=W;i++) {
					if (MaxCost<T[N-1][i]) {
						MaxCost = T[N-1][i];
						MaxWeight = i;
					}
				}
				System.out.println("Case "+count+":");
				System.out.println((long)MaxCost);
				System.out.println(MaxWeight);
				count++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 36144
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 1e9 + 100;

template <typename T>
class SegmentTree {
	const int n;
	vector<vector<T>> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	SegmentTree(const vector<T>& data_) : n(size(data_.size())), data(n * 2)
	{
		for (int i = 0; i < (int)data_.size(); i++) {
			data[i + n].push_back(data_[i]);
		}
		for (int i = n - 1; i >= 0; i--) {
			merge(data[i * 2].begin(), data[i * 2].end(), data[i * 2 + 1].begin(), data[i * 2 + 1].end(), back_inserter(data[i]));
		}
	}
	void for_each(int l, int r, function<void(vector<T>&)> que) {
		l += n; r += n + 1;
		while (l < r) {
			if (l & 1) que(data[l++]);
			if (r & 1) que(data[--r]);
			l >>= 1; r >>= 1;
		}
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n, q;
	cin >> n;
	vector<tuple<int, int, int>> xy(n);
	vector<int> x(n);
	for (int i = 0, y; i < n; i++) {
		cin >> x[i] >> y;
		xy[i] = make_tuple(x[i], y, i);
	}
	sort(xy.begin(), xy.end());
	sort(x.begin(), x.end());
	vector<P> b(n);
	for (int i = 0; i < n; i++) {
		b[i] = { get<1>(xy[i]), get<2>(xy[i]) };
	}
	SegmentTree<P> st(b);
	int sx, sy, tx, ty;
	cin >> q;
	while (q--) {
		cin >> sx >> tx >> sy >> ty;
		int l = lower_bound(x.begin(), x.end(), sx) - x.begin();
		int r = upper_bound(x.begin(), x.end(), tx) - x.begin();
		vector<int> res;
		st.for_each(l, r - 1, [&](vector<P>& v) {
			int s = lower_bound(v.begin(), v.end(), P(sy, -INF)) - v.begin();
			int t = lower_bound(v.begin(), v.end(), P(ty, INF)) - v.begin();
			for (int i = s; i < t; i++) {
				res.push_back(v[i].second);
			}
		});
		sort(res.begin(), res.end());
		for (auto ans : res) {
			printf("%d\n", ans);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 142016
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    int X = N;
    int Y = 0;
    while(X > 0){
        Y += X % 10;
        X /= 10;
    }
    
    if(N % Y == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e18;
const int mod = 1e9 + 7;

signed main() {
    int A, B, K;
    cin >> A >> B >> K;
    int temp = K - A;
    if (temp < 0) {
        A = abs(temp);
        temp = 0;
    }
    else A = 0;
    B = max(0LL, B - temp);
    cout << A << " " << B << endl;
}


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

int main() {
    string S;
    cin >> S;
    for (ll i = 0; i < S.size(); i++) {
        for (ll j = i; j < S.size(); j++) {
            string t = S.substr(0, i) + S.substr(j);
            if (t == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

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

 using namespace std;
 int main() {
   int x, y;
   cin >> x >> y;
   if (x == 2 || y == 2) cout << "No" << endl;
   else if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12){
     if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) cout << "Yes" << endl;
     else cout << "No" << endl;
   }
   else if (x == 4 || x == 6 || x == 9 || x == 11){
     if (y == 4 || y == 6 || y == 9 || y == 11) cout << "Yes" << endl;
     else cout << "No" << endl;
   }
 }


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <numeric>

using namespace std;


class ListNode {
public:
    int val;
    ListNode *next;
    ListNode(int val) {
        this->val = val;
        this->next = NULL;
    }
};

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};



int main() {
  int a, b; cin >> a >> b;
  if ((a % 3 == 0) || (b % 3 == 0) || ((a + b) % 3 == 0)) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
#A - Kth Term
S = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(A[S-1])

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

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

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

const double eps = 1e-10;

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

const int64 mod = 1e9+7;

template<typename CommutativeMonoid>
class FenwickTree{
public:
	using value_structure = CommutativeMonoid;
	using value_type = typename CommutativeMonoid::value_type;
	using size_type = ::std::size_t;

private:
	::std::vector<value_type> tree;
	size_type N;
	
	static value_type calc(const value_type& a, const value_type& b){
		return value_structure::operation(a, b);
	}

public:
	FenwickTree(){}
	FenwickTree(const size_type& N):N(N+10), tree(N+11, value_structure::identity()){}
	FenwickTree(const FenwickTree& bit):tree(bit.tree), N(bit.N){}

	void update(size_type k, const value_type& diff){
		for(;k <= N;k += k & -k){
			tree[k] = calc(tree[k], diff);
		}
	}

	value_type query(size_type k) const { // sum of [1, k]
		value_type res = value_structure::identity();
		for(;k > 0;k -= k & -k){
			res = calc(res, tree[k]);
		}
		return res;
	}

	void updatez(size_type k, value_type v){ // 0-indexed
		update(k+1, v);
	}

	size_type search(const std::function<bool(value_type)>& f) const { // Find k :[0, k) -> True, [0, k-1) -> False
		if(f(value_structure::identity()))
			return 0;
		if(!f(query(N)))
			return N+1;
		value_type x = value_structure::identity();
		size_type k = 1, idx = 0;
		while(k <= N) k <<= 1;
		k >>= 1;
		for(;k > 0;k >>= 1){
			if((idx|k) <= N && !f(tree[idx|k]+x))
				x = calc(x, tree[idx |= x]);
		}
		return idx+1;
	}

	size_type size() const {return N;}
};

class v_monoid{
public:
	using value_type = int64;
	static const value_type identity(){ return 0; }
	static value_type operation(const value_type& a, const value_type& b){
		return a+b;
	}
};

int32 N;
vector<PLL> A;

int64 costb[2020][2020] = {}, costw[2020][2020] = {};
vector<vector<int64>> dp(2020, vector<int64>(2020, INF_LL));

int main(void){
	cin >> N; A.resize(2*N);
	FenwickTree<v_monoid> bitb(N), bitw(N);
	REP(i, 2*N){
		char c;
		cin >> c >> A[i].fs;
		A[i].sc = (c == 'W');
	}
	REP(i, 2*N){
		if(A[i].sc == 0) bitb.update(A[i].fs, 1);
		else bitw.update(A[i].fs, 1);
		REP(j, N+1){
			if (A[i].sc == 1) {
				costw[A[i].fs-1][j] = i-bitw.query(A[i].fs-1)-bitb.query(j);
			} else {
				costb[j][A[i].fs-1] = i-bitw.query(j)-bitb.query(A[i].fs-1);
			}
		}
	}
	dp[0][0] = 0;
	REP(i, N+1){
		REP(j, N+1){
			if (i > 0) chmin(dp[i][j], dp[i-1][j]+costw[i-1][j]);
			if (j > 0) chmin(dp[i][j], dp[i][j-1]+costb[i][j-1]);
		}
	}
	cout << dp[N][N] << endl;
}


Measured memory_bytes: 95872
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
vector<pair<lli, lli>> piyo;
vector<pair<pair<int, int>, int>> ans;
int dfs(lli, int);
bool verify(lli l)
{
    ans.clear();
    piyo.clear();
    int n = dfs(l - 1, 1);
    sort(ans.begin(), ans.end());
    vector<lli> dp(l, 0);
    dp[1] = 1;
    for (auto s : ans) {
        dp[s.first.second] += dp[s.first.first];
    }
    // cout << dp[n] + piyo.size() << endl;
    if (dp[n] + piyo.size() == l)
        return true;
}
int dfs(lli l, int dep)
{
    if (l == 0)
        return dep;
    if (l % 2 == 1) {
        ans.push_back(make_pair(make_pair(dep, dep + 1), 0));
        ans.push_back(make_pair(make_pair(dep, dep + 1), (l + 1) / 2));
        // piyo.push_back(make_pair(l - (l + 1) / 2 + 1, dep));

        dfs(l - (l + 1) / 2, dep + 1);
    } else {
        ans.push_back(make_pair(make_pair(dep, dep + 1), 0));
        ans.push_back(make_pair(make_pair(dep, dep + 1), (l + 2) / 2));

        piyo.push_back(make_pair(l - (l + 2) / 2 + 1, dep));
        // piyo.push_back((l + 2) / 2);
        dfs(l - (l + 2) / 2, dep + 1);
    }
}
int main()
{
    lli l;
    // piyo.clear();
    // ans.clear();
    //
    // for (int i = 1; i < 100000; i++) {
    //     if (!verify(i))
    // }
    cin >> l;
    int n = dfs(l - 1, 1);
    cout << n << " " << ans.size() + piyo.size() << endl;
    for (auto s : ans) {
        cout << s.first.first << " " << s.first.second << " " << s.second << endl;
    }
    for (auto s : piyo) {
        cout << s.second << " " << n << " " << s.first << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    long long int a;
    int b;
} drink;

int cmp(const void *p,const void *q){
    return ((drink*)p)->a-((drink*)q)->a;
}

int main(){
    int n,m;
    int i=0;
    long long int ans;
    scanf("%d %d",&n,&m);
    drink s[n];
    for(i=0;i<n;i++){
        scanf("%lld %d",&s[i].a,&s[i].b);
    }
        
    qsort(s,n,sizeof(drink),cmp);
    i=0;
    while(m>s[i].b&&m>0&&i<n){
        ans+=s[i].b*s[i].a;
        m-=s[i].b;
        i++;
    }
    ans+=m*s[i].a;
    printf("%lld",ans);
    return 0;
}   


Measured memory_bytes: 3324
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    l = I()
    r = l/3
    print(r*r*r)
    return


# Solve
if __name__ == "__main__":
    solve()


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

signed main(){
	int x, y;
	int g[13] = {-1, 0, 1, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0};
	scanf("%d%d", &x, &y);
	if(g[x] == g[y]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll n, a, b, c, d;
map<ll, ll> mp;

ll dfs(ll m) {
  if (m == 0) return 0;
  if (m == 1) return d;
  if (mp[m] != 0) return mp[m];
  ll res = INF;
  if (INF / d > m) chmin(res, d * m);
  ll l2 = m / 2 * 2, u2 = l2 + 2;
  chmin(res, abs(m - l2) * d + dfs(l2 / 2) + a);
  if (m % 2) chmin(res, abs(m - u2) * d + dfs(u2 / 2) + a);
  ll l3 = m / 3 * 3, u3 = l3 + 3;
  chmin(res, abs(m - l3) * d + dfs(l3 / 3) + b);
  if (m % 3) chmin(res, abs(m - u3) * d + dfs(u3 / 3) + b);
  ll l5 = m / 5 * 5, u5 = l5 + 5;
  chmin(res, abs(m - l5) * d + dfs(l5 / 5) + c);
  if (m % 5) chmin(res, abs(m - u5) * d + dfs(u5 / 5) + c);
  return mp[m] = res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int t;
  cin >> t;
  while (t--) {
    mp.clear();
    cin >> n >> a >> b >> c >> d;

    cout << dfs(n) << '\n';
  }




  
  return 0;
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	int a[n];
	int cnt = 0, res = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt += a[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] * 4 * m >= cnt) res++;
	}
	if (res >= m) cout << "Yes\n";
	else cout << "No\n";
 	return 0;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

K,S = map(int,input().split())

ans = 0
for i in range(K+1):
    for j in range(K+1):
        if K >= S-i-j >= 0:
            ans += 1
print(ans)


Measured memory_bytes: 5456
fun main() {
    var (x, n) = readLine()!!.split(" ").map{it.toInt()}
    var s = readLine()!!
    var p:List<Int>;
    if(s.isNotEmpty()) {
        p = s.split(" ").map { it.toInt() }


        var a = Array(101) { 0 }
        for (i in 0 until 101) {
            if (!p.contains(x - i)) {
                println(x - i)
                return
            }
            if (!p.contains(x + i)) {
                println(x + i)
                return
            }
        }
    } else {
        println(x)
    }
}

Measured memory_bytes: 35888
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.push_back(t);
    }
    sort(vec.begin(),vec.end(),greater<int>());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=vec[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

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

  int l;
  int d = 0;

  for(int i = 2; i <= n+1; i++){
    cin >> l;

    d += l;

    if(x == d || i == n+1){
      cout << i << endl;
      break;
    }

    if(x < d){
      cout << i - 1 << endl;
      break;
    }
  }

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n), b(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  long long cnt = 0;
  for(int i = 0; i < n; ++i){
    if(a[i] <= b[i]) cnt += (b[i] - a[i]) / 2;
    else cnt -= (a[i] - b[i]);
  }
  cout << (cnt >= 0 ? "Yes" : "No" ) << endl; 
}

Measured memory_bytes: 384
using System;

public class test
{
  static void Main(string[] args)
  {
    int k = int.Parse(Console.ReadLine());
    string s = Console.ReadLine();

    if ( s.Length > k )
    {
      var ss = s.Substring(0, k);
      Console.WriteLine(ss + "...");
    }
    else
    {
      Console.WriteLine(s);
    }
  }
}

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

using namespace std;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	
	string s;
	cin >> s;

	cout << s[0] << s.size() - 2 << s[s.size() - 1] << "\n";

	return 0;
}

Measured memory_bytes: 256
N = int(input())

count = 0

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(9 + min(N,999) - 100 + 1)
elif N < 10000:
    print(9 + 900)
elif N < 100000:
    print(9 + 900 + min(N , 99999) - 10000 + 1)
else:
    print(90909)

Measured memory_bytes: 3064
def main():
    n = int(input())
    s = 0
    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    for i in range(n):
        if v[i] > c[i]:
            s += v[i] - c[i]
    print(s)
    return 0

main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,k;
   cin>>n>>k;
   long long int a[n];
    long long int mod=1000000000+7;
   for(int i=0;i<n;i++)
      cin>>a[i];
    long long int count=0,c=0;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<i;j++)
       {
           if(a[i]<a[j])
           {
               count++;
           }
       }
   } 
   //int c=0;
   for(int i=0;i<n;i++)
   {
       for(int  j=0;j<n;j++)
       {
           if(a[i]<a[j])
           {
               c++;
           }
       }
   } 

  long long int p=((((k*(k-1))/2)%mod)%mod);
  p=p%mod;
  p=((p%mod)*(c%mod))%mod;
      count=((k%mod)*(count%mod))%mod+p;
   cout<<count%mod;

  

}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int read()
{  int f=1,x=0;
   char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x = x * 10 + ch - '0';
   return x*f;
}
int main()
{
      string s;
      cin >> s;
      cout << s[0] << s[1] << s[2];

      return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    if (n % 2 == 0) {
        cout << n/2*(n-1) << endl;
    } else {
        cout << (n-1)/2*n << endl;
    }
    return 0;
}


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

int main() {
  int d, n; cin >> d >> n;
  int ans = 1; REP(i, d) ans *= 100;
  if (n == 100) cout << ans * 101 << endl;
  else cout << ans * n << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, t;
  cin >> n >> t;
  std::vector<int> a(n, 0);
  std::vector<int> left_max(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    left_max[i] = std::max(left_max[i + 1], a[i + 1]);
  }
  int result   = 0;
  int max_gain = 0;
  for (int i = 0; i < n; i++) {
    int gain = left_max[i] - a[i];
    if (gain > 0 && gain > max_gain) {
      result   = 1;
      max_gain = gain;
    } else if (gain > 0 && gain == max_gain) {
      result++;
    }
  }
  cout << result << endl;

  return 0;
}


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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (2000006)
#define INF (1LL << 60)
const int MOD = (int)1e9 + 7;


signed main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++) cin >> d[i];
    sort(d.begin(),d.end());

    int ans=0;
    for(int i=0; i<=100000; i++){
        auto it = lower_bound(d.begin(),d.end(),i);
        int t = it - d.begin();
        //DEBUG(t);
        if(t == n/2) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()

v = sum(a)/2
t = 0
for i in range(len(a)):
	t+=a[i]
	if t>v:
		break
z1 = sum(a[:i])
k1 = sum(a[i:])
z2 = sum(a[:i+1])
k2 = sum(a[i+1:])
if abs(z1-k1)<abs(z2-k2):
	z = z1
	k = k1
else:
	z = z2
	k = k2

print(abs(z-k))


Measured memory_bytes: 33304
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if ab, cd := a+b, c+d; ab == cd {
		fmt.Println("Balanced")
	}else if ab > cd {
		fmt.Println("Left")
	}else {
		fmt.Println("Right")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main(){
    int w, sum;
    while (~scanf("%d", &w)) {
        if (!~w) break;
        sum = 1150;
        if (w > 30) sum += (w - 30) * 160 + 1400 + 1250;
        else if (w > 20) sum += (w - 20) * 140 + 1250;
        else if (w > 10) sum += (w - 10) * 125;

        printf("%d\n", 4280 - sum);
    }

    return 0;
}




Measured memory_bytes: 3148
#include<stdio.h>
int  main()
{
  char a[4],s,i,j;
  i=0;
  for(j=1;j<=4;j++)
    {
      scanf("%c",&a[j]);
    }
  if(a[1]=='1')
    {
      i=i+1;
    }
  if(a[2]=='1')
    {
      i=i+1;
    }
  if(a[3]=='1')
    {
      i=i+1;
    }

  printf("%d\n",i);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;

}

Measured memory_bytes: 3604
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

h,w,k = map(int, input().split())
board = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if board[i][j] == "S":
            sx, sy = i, j

from collections import deque
dxdy = [(0,1),(1,0),(0,-1),(-1,0)]
def bfs(sx, sy):
    q = deque()
    q.append((sx, sy))
    used = [[0]*w for i in range(h)]
    ans = float("inf")
    while q:
        x,y = q.pop()
        if used[x][y]:
            continue
        used[x][y] = 1
        tmp = -(-min(x, h-1-x, y, w-1-y)//k)
        ans = min(ans, tmp+1)
        for dx, dy in dxdy:
            nx = x + dx
            ny = y + dy
            if abs(nx-sx)+abs(ny-sy)>k:
                continue
            if 0<=nx<h and 0<=ny<w and board[nx][ny] == ".":
                if nx == 0 or nx == h-1 or ny == 0 or ny == w-1:
                    return 1
                if not used[nx][ny]:
                    q.append((nx,ny))
    return ans

ans = bfs(sx, sy)
print(ans)

Measured memory_bytes: 79216
import java.util.*;
 class Main {
	public static void main(String[] args){
		int a[]=new int[10];
		Scanner x=new Scanner(System.in);
		for(int i=0;i<10;i++){
			a[i]=x.nextInt();
		}
		Arrays.sort(a);
		x.close();
		for(int j=9;j>=7;j--)
			System.out.println(a[j]);
	}
	

}

Measured memory_bytes: 26300
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    list<ll> A;
    ll count = 0;
    cin >> N;
    rep(i, N) {
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }
    ll i = 0;
    for(auto iter = A.begin();iter != A.end();iter++) {
        if(*iter != i + 1) iter = A.erase(iter), iter--, count++;
        else i++;
    }
    if(A.size()) cout << count;
    else cout << -1;
    cout << endl;
    return 0;
}


Measured memory_bytes: 6528
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
     
    public class Program
    {
        public void Proc() {
            Reader.IsDebug = false;
            int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();

            int boxCount = inpt[0];
            int moveCount = inpt[1];

            int[] ballCount = (new int[boxCount]).Select(a=>1).ToArray();
            bool[] flags = new bool[boxCount];
            flags[0] = true;

            for(int i=0; i<moveCount; i++) {
                inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)-1).ToArray();
                ballCount[inpt[0]]--;
                ballCount[inpt[1]]++;
                if(flags[inpt[0]]) {
                    flags[inpt[1]] = true;                    
                }
                if(ballCount[inpt[0]]<=0) {
                    flags[inpt[0]] = false;
                }
            }
            int ans = flags.Count(a=>a);
            Console.WriteLine(ans);

        }



        public class Reader {
            public static bool IsDebug = true;
            private static System.IO.StringReader SReader;
            private static string InitText = @"




4 4
1 2
2 3
4 1
3 4





";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }

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

int main() {
  string S;
  cin >> S;

  bool direction[4] = {};
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N') direction[0] = true;
    else if (S[i] == 'W') direction[1] = true;
    else if (S[i] == 'S') direction[2] = true;
    else direction[3] = true;
  }

  if (direction[0] == direction[2] && direction[1] == direction[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int dp[101][10001];
int main(){
	int N,W,v[101],w[101];
	cin>>N>>W;
	for(int i=1;i<=N;i++)cin>>v[i]>>w[i];
	for(int i=0;i<=N;i++)dp[i][0]=0;
	for(int i=0;i<=W;i++)dp[0][i]=0;
	for(int i=1;i<=N;i++)for(int j=1;j<=W;j++){
		if(j>=w[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
		else dp[i][j]=dp[i-1][j];
	}
	cout<<dp[N][W]<<"\n";
	return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=200000;

int main() {
    string s;
    cin>>s;
    fori(4){
        s[i]-='0';
    }

    for(int i = 0; i < 16; i+=2){
        bool f[3];
        f[0]=16&(i<<1);
        f[1]=16&(i<<2);
        f[2]=16&(i<<3);
        int sum=s[0];
        forj(3){
            sum+=(f[j]?1:-1)*s[j+1];
        }
        if(sum==7){
            cout<<(int)s[0];
            forj(3){
                cout<<(f[j]?"+":"-")<<(int)s[j+1];
            }
            cout<<"=7";
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long int  mod  = 1000000007;
int main()
{
	ll n,i,c=0;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<s.size()-2;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
		{
			c++;
			i=i+2;
		}
	}
	cout<<c;
}


Measured memory_bytes: 3628
n, m = map(int, input().split())
a = []
b = []
c = []
checker = [0]*n
for _ in range(m):
    ai, bi = map(int, input().split())
    ci = list(map(int, input().split()))
    ci_int = 0
    for hako in ci:
        hako -= 1
        ci_int += 2**hako
        if checker[hako] == 0:
            checker[hako] = 1
    a.append(ai)
    b.append(bi)
    c.append(ci_int)
#print(a)
#print(b)
#print(c)
if sum(checker) != n:
    print(-1)
    exit()

dp = [[float("inf")]*(2**n) for _ in range(m+1)]
#dp[i][S]はi番目までのカギをいくつか使ってSになるようなコストの最小値
#Sは2進数で表現できる。例）１と３の箱が開けられる状態->0b101
dp[0][0] = 0
for i in range(m):
    for s in range(2**n):
        # i番目のカギを使用しない場合
        dp[i+1][s] = min(dp[i+1][s], dp[i][s])
        # 使用する場合
        dp[i+1][s | c[i]] = min(dp[i+1][s|c[i]], dp[i][s] + a[i])
print(dp[m][2**n-1])

Measured memory_bytes: 123904
"""
：余りの等しい物をカウントし、その累積和
：Aの余りとBの余り(mod 2019)が等しい場合
　A-Bは2019の倍数である
：計算量を抑えるため各項と１０の指数乗は分けて計算する
：
"""

import sys
input=sys.stdin.readline
s = input()[:-1][::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0

for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Measured memory_bytes: 68584
#include<stdio.h>


int main(){
	int a,b,c,d,e,f;
	d=4280;
	while(1){
		scanf("%d",&a);
		b=1150;
		if(a==-1)
		break;
		
		a-=10;
		if(a>0){
			a-=10;
			if(a>0){
				b+=1250;
				a-=10;
				if(a>0){
				b+=1400;
				b+=a*160;
				}
				else{
					a+=10;
					b+=a*140;
				}
			}
			else{
				a+=10;
				b+=a*125;
			}
		}
		
printf("%d\n",d-b);
	}
	
	return 0;
}
	
	

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

int main() {
	int n, a, b, s,sum = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		int t = i;
		s = 0;
		while (1) {
			if (t == 0) break;
			s += t % 10;
			t /= 10;
		}
		if (a <= s && s <= b) sum += i;
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main()
{
	int left=123, right=200;
	vector<vector<int>> vvlist;

	//0になるまで読み込む
	while (true) {
		vector <int> vlist;

		cin >> left >> right;
		if (left == 0 && right == 0) {
			break;
		}
		vlist.push_back(left);
		vlist.push_back(right);
		vvlist.push_back(vlist);
	}
	//swapする
	for (int i = 0; i < vvlist.size(); i++) {

		if (vvlist[i][0] > vvlist[i][1]) {
			swap(vvlist[i][0], vvlist[i][1]);
		}
	}

	//配列内の全ての要素をプリントする
	for (int i = 0; i < vvlist.size(); i++) {
		cout << vvlist[i][0]  << " " << vvlist[i][1] 
			 << endl;
	}
    return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod2 1000000007
using mint = modint<mod2>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;
int main() {
    cin>>N;
    vector<vm> dp(N + 1, vm(N + 1, 0));
    dp[0][0] = 1;
    rep(i, N + 1){
        rep(j, N + 1){
            if(i < j) continue;
            if(i != N) dp[i + 1][j] += dp[i][j];
            if(i >= j + 3) dp[i][i] += dp[i][j];
        }
    }
    cout<<dp[N][N]<<endl;
}

Measured memory_bytes: 34592
#include<bits/stdc++.h>
using namespace std;
int n,a,sum=0,i;
bitset<4000005> f;
int main(){
	scanf("%d",&n);
	f[0]=1;
	for(i=1;i<=n;i++) scanf("%d",&a),f|=f<<a,sum+=a;
	for(i=(sum+1)>>1;1;i++)
		if(f[i]){
			printf("%d\n",i);
			return 0;
		}
}

Measured memory_bytes: 1664
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V<int> ans(n + 1, 0);
    for (ll x = 1; x * x <= n; x++) {
        for (ll y = 1; y * y <= n; y++) {
            for (ll z = 1; z * z <= n; z++) {
                if (x * x + y * y + z * z + x * y + y * z + z * x <= n) {
                    ans[x * x + y * y + z * z + x * y + y * z + z * x]++;
                }
            }
        }
    }
    for (ll i = 1; i <= n; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int T; cin >> T;
	while(T--){
		ll N,A,B,C,D; cin >> N >> A >> B >> C >> D;
		map<ll,ll> mp;
		function<ll(ll)> f = [&](ll n){
			if(n==0) return 0LL;
			if(n==1) return D;
			if(mp.count(n)) return mp[n];
			ll res = 1e18;
			if(__int128(n)*D < res) res = n*D;
			V<ll> as = {2,3,5};
			V<ll> bs = {A,B,C};
			rep(_,3){
				ll a = as[_];
				ll b = bs[_];
				{
					ll x = n/a*a;
					chmin(res,f(x/a)+abs(n-x)*D+b);
				}
				{
					ll x = (n+a-1)/a*a;
					chmin(res,f(x/a)+abs(n-x)*D+b);
				}
			}
			return mp[n] = res;
		};
		cout << f(N) << endl;
	}
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<long long,long long>
#define mii         map<pii,long long>
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(long long i=a;i<b;i++)
#define repr(i,a,b) for(long long i=a;i>=b;i--)
#define int long long
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define io ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;

signed main()
{
	io;
	int n,x,t;
	cin >> n >> x >>t;
	if(x>=n) cout << t <<endl;
	else
	{
		int a = n/x;
		if(n%x!=0) a++;
		cout << t*a <<endl;
	}
}
 
	
		



Measured memory_bytes: 3648
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a = int(input())
    b = int(input())

    if a == b:
        print("EQUAL")
    elif a > b:
        print("GREATER")
    else:
        print("LESS")

if __name__=="__main__":
    main()

Measured memory_bytes: 9060
A , V = map(int,input().split())
B , W = map(int,input().split())
T = int(input())

if A > B:
    V = -V
    if W > 0:
        W = -W

if A < B and W < 0:
    W = -W

    
a = V * T + A
b = W * T + B

if a > b:
    if A < B:
        print("YES")
    else:
        print("NO")
elif a == b:
    print("YES")
    
elif a < b:
    if A < B:
        print("NO")
    else:
        print("YES")



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> coord;

int main(){
    ll r, d, x;
    cin >> r >> d >> x;

    ll res = x;
    for(ll i=0; i<10; i++){
        res = r*res - d;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256