akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
    
    int d, i, sum=0;
    
    while (scanf("%d",&d) != EOF) {
        for (i=1; i<600/d; i++) {
            sum +=(i*d)*(i*d)*d;
        }
        printf("%d\n",sum);
        sum=0;
    }
    
    return 0;
    
}

Measured memory_bytes: 596
a = gets.to_i
b = gets.to_i
c = gets.to_i

1.upto(100) do |y|
  sum = a + c + y
  x = c - b + y
  z = a - b + y
  next if x < 1 or z < 1 or (x + c != z + y)

  h = sum - x - y
  k = sum - x - c
  j = sum - a - k
  next if j != (sum - c - h)

  puts "#{a} #{b} #{x}"
  puts "#{j} #{c} #{h}"
  puts "#{k} #{z} #{y}"
  break
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (100005)

using namespace std;

struct edge{ int nt,to,dis; }g[N<<1];

int head[N],dis[N],son[N],fa[N],sz[N],id[N],a[N],n,num;
ll ans;

il int gi(){
	RG int x=0,q=1; RG char ch=getchar();
	while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if (ch=='-') q=-1,ch=getchar();
	while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return q*x;
}

il void insert(RG int from,RG int to,RG int dis){
	g[++num]=(edge){head[from],to,dis},head[from]=num; return;
}

il void dfs(RG int x,RG int p){
        fa[x]=p,sz[x]=1; RG int v;
	for (RG int i=head[x];i;i=g[i].nt){
		v=g[i].to; if (v==p) continue;
		dis[v]=g[i].dis,dfs(v,x),sz[x]+=sz[v];
		ans+=2LL*g[i].dis*min(sz[v],n-sz[v]);
		son[x]=max(son[x],sz[v]);
	}
	son[x]=max(son[x],n-sz[x]); return;
}

il int cmp(const int &a,const int &b){ return son[a]<son[b]; }

int main(){
	n=gi();
	for (RG int i=1,u,v,w;i<n;++i)
	  u=gi(),v=gi(),w=gi(),insert(u,v,w),insert(v,u,w);
	dfs(1,0); for (RG int i=1;i<=n;++i) id[i]=i;
	sort(id+1,id+n+1,cmp);
	if (son[id[1]]==son[id[2]]){
	  if (fa[id[1]]==id[2]) ans-=dis[id[1]];
	  else ans-=dis[id[2]];
	} else{
	  RG int res=1<<30;
	  for (RG int i=head[id[1]];i;i=g[i].nt)
	    res=min(res,g[i].dis);
	  ans-=res;
	}
	cout<<ans; return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
//#define DEBUG


int main(void)
{
  unsigned long long  H,W;
  cin >> H >> W;
  unsigned long long  ret;
  if(H==1 || W==1)
  {
    ret = 1;
  }
  else if(H%2==1 && W%2==1)
  {
    ret = (H*W+1)/2;
  }else{
    ret = H*W/2;
  }
  cout << ret;
  
  return 0;
} 

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

int main(){
int n,a,b;
while(cin>>n){
if(n==0)break;
bool t[201],h[201];
for(int i=0;i<201;i++){t[i]=false; h[i]=false;}
for(int i=0;i<n;i++){
cin>>a;
t[a-1]=true;}
for(int i=0;i<2*n;i++)if(!t[i])h[i]=true;
a=n; b=n;
int c=0;
while(1){
for(int i=c;i<2*n;i++){
if(t[i]){t[i]=false; c=i; a--; break;}
if(i==2*n-1)c=0;}
if(a==0)break;
for(int i=c;i<2*n;i++){
if(h[i]){h[i]=false; c=i; b--; break;}
if(i==2*n-1)c=0;}
if(b==0)break;}
cout<<b<<endl<<a<<endl;}}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
int N,M,wa=0;
int count=0;
int A[1000];
cin >> N >> M;
    for(int i=0;i<N;i++){
    cin >> A[i];
    wa = wa+A[i];
    }
    for(int i=0;i<N;i++){
        if(wa<=4*M*A[i])
        count++;
    }
    if(count>=M)
    std::cout << "Yes" << std::endl;
    else
    cout<< "No"<< endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;

int main(void)
{
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)	printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1012
/* topological_sort_DFS.cpp

    verified: AOJ GRL_4_B Topological Sort
    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

/* topo_sort(G): グラフG をトポロジカルソート
    返り値: トポロジカルソートされた頂点番号
    計算量: O(|E|+|V|)
    返り値のサイズがグラフより小さければ閉路が存在する
    （大きなグラフではスタックオーバーフローの可能性があるので、dfsではなくbfsの方が良い）
 */
void dfs(const Graph &G, int v, vector<bool> &used, vector<int> &ans) {
    used[v] = true;
    for (auto e : G[v]) {
        if (!used[e.to]) {
            dfs(G, e.to, used, ans);
        }
    }
    ans.push_back(v);  // 帰りがけにpush_back
}
vector<int> topo_sort(const Graph &G) {  // bfs
    vector<int> ans;
    int n = (int)G.size();
    vector<bool> used(n, false);
    for (int v = 0; v < n; v++) {
        if (!used[v]) dfs(G, v, used, ans);
    }
    reverse(ans.begin(), ans.end());  // 逆向きなのでひっくり返す
    return ans;
}

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

    int V, E;
    cin >> V >> E;
    vector<int> s(E), t(E);
    for (int i = 0; i < E; i++) {
        cin >> s.at(i) >> t.at(i);
    }

    Graph G(V);
    for (int i = 0; i < E; i++) {
        G[s[i]].push_back({t[i]});
    }
    vector<int> sorted = topo_sort(G);

    for (auto v : sorted) {
        cout << v << endl;
    }

    return 0;
}



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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    ll res = 0;
    REP(i,n) {
        int a;
        cin >> a;
        while (a%2 == 0) {
            res++;
            a /= 2;
        }
    }
    cout << res << '\n';
    return 0;
}


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

void dfs(int v, vector<vector<int>>& g, vector<bool>& visited, set<int>& path) {
  visited[v] = true;
  path.insert(v);
  for (int nv : g[v]) {
    if (!visited[nv]) {
      dfs(nv, g, visited, path);
    }
  }
}

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

  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i] -= 1;
  }

  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  int ans = 0;
  vector<bool> visited(n);
  for (int i = 0; i < n; ++i) {
    if (visited[i]) {
      continue;
    }
    set<int> path;
    dfs(i, g, visited, path);
    for (int x : path) {
      if (path.find(p[x]) != path.end()) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 18756
import itertools

N,M,Q = map(int, input().split())
AA = itertools.combinations_with_replacement(range(1,M+1), N)
abcd = [list(map(int, input().split())) for _ in range(Q)]

ans = -10**18
for A in AA:
    score = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c:
            score += d
    ans = max(ans, score)
print(ans)

Measured memory_bytes: 9136
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

from itertools import combinations

N = INT()
march = {}

for ini in "MARCH":
    march[ini] = 0
    
for _ in range(N):
    s = input()
    
    if s[0] in "MARCH":
        march[s[0]] += 1

ans = 0

for comb in combinations(march.values(), 3):
    tmp = 1
    for c in comb:
        tmp *= c
    
    ans += tmp
    
print(ans)

Measured memory_bytes: 74772
if __name__ == '__main__':
	N, M = map(int, input().split())
	lmax = 0
	rmin = N
	for _ in range(M):
		L,R = map(int, input().split())
		if L > lmax:
			lmax = L
		if R < rmin:
			rmin = R
	ans = rmin - lmax + 1
	if ans < 0:
		ans = 0
 
	print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	scanf("%i",&n);
	if(n==1) return 0*printf("1\n1\n");
	int sz=(n+3)/4*2;
	printf("%i\n",sz);
	for(i=0;i<sz;i++) for(j=0;j<sz;j++)
	{
		int out=(i+j)%sz;
		if(i&1) out+=sz;
		if(out>=n) out-=sz;
		printf("%i%c",out+1,j==sz-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 1152
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x=INT()
    flg=0
    for i in range(1,201):
        if x%i==0:
            temp=int(x/i)
            #print(str(temp)+'aaa')
            for k in range(201):
                a=k
                b=a-i
                ans=a**4+(a**3)*b+(a**2)*(b**2)+a*(b**3)+b**4
                if temp==ans:
                    print(a,b)
                    flg=1
                    break
        if flg==1:
            break
                    
                
if __name__ == '__main__':
    do()

Measured memory_bytes: 27152
/*input
4
1 1 1 3
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, a[5000005], minn = 1000000009, kt;
signed main(){
    cin >> n;
    for(int i = 0;i < n;++i)
    {
        cin >> a[i];
        minn = min(minn, a[i]);
    }
    for(int i = n-2;i >= 0;--i)
    {
        if(a[i] > a[i+1]) a[i]--;
    }
    for(int i = n-2;i >= 0;--i)
    {
        if(a[i] > a[i+1])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 1024
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k; cin >> k;
    string ans = "ACL";
    k--;
    while(k--){
        ans += "ACL";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

typedef long long ll;
#define pll pair<ll, ll>
#define REP(i, n) for(ll i=0; i<n; i++)
#define F first
#define S second

const ll MOD=1000000007;

ll mod_pow(ll x, ll n) {
    ll ret = 1;
    while(0 < n) {
        if((n % 2) == 0) {
            x *= x;
            x %= MOD;
            n /= 2;
        }else{
            ret *= x;
            ret %= MOD;
            --n;
        }
    }
    return ret;
}

ll nCr(ll n, ll r) {
    ll A = 1;
    ll B = 1;

    for(ll i=n-r+1; i<n+1; i++) {
        A = A * i % MOD;
    }
    for(ll i=1; i<r+1; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD-2);
    B %= MOD;

    return (A * B) % MOD;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll sum = mod_pow(2, n) - 1;
    ll hate1 = nCr(n, a) % MOD;
    ll hate2 = nCr(n, b) % MOD;

    if((sum - hate1 - hate2) % MOD < 0) cout << (sum - hate1 - hate2) % MOD + MOD << endl;
    else cout << (sum - hate1 - hate2) % MOD << endl;

    return 0;
}


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

int H,A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;

  for(int i=1; i<=H; i++) cin >> A[i];

  for(int i=H/2; i>=1; i--) maxHeapify(i);

  for(int i=1; i<=H; i++){
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 4944
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main() {
    int N;
    LL sum;

    cin >> N;

    sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i%3 == 0 || i%5 == 0) continue;
        sum += i;
    }

    cout << sum << endl;
}


Measured memory_bytes: 3636
import math
N = int(input())
s_dict = {}
ans = 0
for i in range(N):
    s = input()
    s = "".join(sorted(s))
    if s not in s_dict:
        s_dict[s] = 0
        s_dict[s] += 1
    else:
        ans += s_dict[s]
        s_dict[s] += 1
print(ans)

Measured memory_bytes: 17932
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

h,w = readInts()
c = []
for i in range(h):
	x = input()
	print(x)
	print(x)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  if (a == b && b == c) ans = 1;
  else if (a == b || b == c || c == a) ans = 2;
  else ans = 3;
  cout << ans << endl;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    a, b, t = list(map(int, input().rstrip('\n').split()))
    total = 0
    for i in range(1, t + 1):
        if i % a == 0:
            total += b
    print(total)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
//#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//using namespace atcoder;
typedef long long ll;
int main(){
  ll N,i,p,ans = 0;scanf("%lld",&N);
  map<ll,ll> mp;
  for(i=0;i<N;i++){
    scanf("%lld",&p);
    mp[p] = i;
  }
  map<ll,ll> big;
  big[-1] = big[-2] = big[N] = big[N+1] = -1;
  ll place,fl,fr,sl,sr;
  for(i=N;i>=1;i--){
    place = mp[i];
    auto right1 = big.upper_bound(place);
    auto right2 = right1;right2++;
    auto left1 = right1;left1--;
    auto left2 = left1;left2--;
    if(left1->second == -1) fl = 0;
    else if(left2->second == -1) fl = left1->first+1;
    else fl = left1->first-left2->first;
    fr = (right1->second == -1 ? N-place:right1->first-place);
    if(right1->second == -1) sr = 0;
    else if(right2->second == -1) sr = N-right1->first;
    else sr = right2->first-right1->first;
    sl = (left1->second == -1 ? place+1:place-left1->first);
    ans += i*(fl*fr+sl*sr);
    big[place] = 1;
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 16292
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int p[200005];
  for(int i=0;i<n;i++) cin >> p[i];
  int mi[200005];

  mi[0] = p[0];
  for(int i=1;i<n;i++){
    mi[i] = min(mi[i-1],p[i]);
  }

  int ans = 0;
  for(int i=0;i<n;i++){
    if(p[i] <= mi[i]) ans++;
  }

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

Measured memory_bytes: 1792
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    printf("%lld\n",max(a*b,c*d));
	return 0;
}

Measured memory_bytes: 256
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll N,A,B,C;
vector<ll> ln;
ll search_func(ll i,ll a,ll b, ll c, ll mp){
    if (i>=N){
        if(a<=0||b<=0||c<=0) return INT64_MAX;
        mp+=abs(A-a)+abs(B-b)+abs(C-c);
        return mp;
    }
    //a
    ll ret = search_func(i+1,a+ln[i],b,c,a>0?mp+10:mp);
    //b
    ret = min(search_func(i+1,a,b+ln[i],c,b>0?mp+10:mp),ret);
    //c
    ret = min(search_func(i+1,a,b,c+ln[i],c>0?mp+10:mp),ret);
    //使わない
    ret = min(search_func(i+1,a,b,c,mp),ret);
    return ret;
}

int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N>>A>>B>>C; 
    ln.resize(N);
    for(auto&& l:ln){
        cin>>l;
    }
    ll ans=search_func(0,0,0,0,0);
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    
    ll min_till_here = v[0],ans=0;
    
    for(ll i=0;i<n;i++)
    {
        if(v[i]<=min_till_here)
        {
            ans++;
            min_till_here = v[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
a,b,k=map(int,input().split())
lis=[]
if k<=abs(b-a+1):
    for i in range(a,a+k):
        lis.append(i)
    for j in range(b,b-k,-1):
        lis.append(j)
    lis=list(set(lis))
    lis.sort()
    for k in lis:
        print(k)
else:
    for i in range(a,b+1):
        print(i)
        


Measured memory_bytes: 3060
N = list(map(int, input()))
N = N[::-1] + [0]

count = 0

for i, n in enumerate(N):
  if n < 5:
    count += n
  elif n > 5:
    count += 10 - n
    N[i+1] += 1
  elif n == 5:
    if N[i+1] >= 5:
      N[i+1] += 1
    count += 5
    
print(count)

Measured memory_bytes: 28144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

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

	int dp[n];fill(dp,dp+n,inf);
	for(int i=0;i<n;i++){
		*lower_bound(dp,dp+n,a[i])=a[i];
		//for(int i=0;i<n;i++) cout<<dp[i]<<", ";
		//cout<<endl;
	}

	cout<<lower_bound(dp,dp+n,inf)-dp<<endl;
}


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

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

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

ll cmb(ll x, ll y){
    if(y>x||y<0) return 0LL;
    ll c = 1;
    for(ll i = 0LL; i < y; i++) {
        c *= (x-i)%mod;
        c %= mod;
        c *= pow(i+1,mod-2,mod);
        c%= mod;
    }
    return c;
}

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = ((cmb(c+d+2,d+1)-cmb(d+a+1,d+1))%mod - (cmb(b+c+1,b)-cmb(b+a,b))%mod)%mod;
    if(ans<0) ans+=mod;
    cout<<ans<<endl;
}

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

const int max_attempt=100000;

int main()
{
	srand(1);


	int d;
	cin >> d;

	vector<int> c(26+1);
	for (int i=1;i<=26;++i)
	{
		cin >> c[i];
	}

	vector<vector<int>> s(d+1,vector<int>(26+1));
	for (int i=1;i<=d;++i)
	{
		for (int j=1;j<=26;++j)
		{
			cin >> s[i][j];
		}
	}
	vector<int> t(d+1);
	for (int i=1;i<=d;++i)
	{
		// cin >> t[i];
		t[i]=rand()%26+1;
	}

#ifdef NEVER_DEFINED
	int m;
	cin >> m;
	vector<pair<int,int>> q(m);

	for (int i=0;i<m;++i)
	{
		int dd,qq;
		cin >> dd >> qq;
		q[i]=make_pair(dd,qq);
	}
#endif

	vector<int> last(26+1);
	vector<set<int>> hh(26+1);
	for (int i=1;i<=26;++i)
	{
		last[i]=0;
		hh[i].insert(0);
		hh[i].insert(d+1);
	}


	int64_t score=0;
	for (int i=1;i<=d;++i)
	{
		score+=s[i][t[i]];
		last[t[i]]=i;
		hh[t[i]].insert(i);
		for (int j=1;j<=26;++j)
		{
			score-=c[j]*(i-last[j]);
		}
		//cout << score << endl;
	}

	for (int i=0;i<max_attempt;++i)
	{
		//int dd=q[i].first;
		//int qq=q[i].second;
		int dd=rand()%d+1;
		int qq=rand()%26+1;
		int rr=t[dd];
		int prev_score=score;

		score-=s[dd][rr];
		score+=s[dd][qq];
		auto it=hh[rr].find(dd);
		auto prev=it;
		--prev;
		auto next=it;
		++next;
		score-=(dd-*prev)*(*next-dd)*c[rr];

		hh[rr].erase(dd);
		t[dd]=qq;

		hh[qq].insert(dd);
		it=hh[qq].find(dd);
		prev=it;
		--prev;
		next=it;
		++next;
		score+=(dd-*prev)*(*next-dd)*c[qq];

		//fprintf(stderr,"%d %lld %lld\n",i,prev_score,score);
		if (score<prev_score)
		{
			// get back to original
			t[dd]=rr;
			hh[rr].insert(dd);
			hh[qq].erase(dd);
			score=prev_score;
		}
	}

	//fprintf(stderr,"%lld\n",score);
	for (int i=1;i<=d;++i)
	{
		cout << t[i] << endl;
	}

}






Measured memory_bytes: 3724
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

struct Point
{
	long double x,y,c;
	Point() {}
	Point(long double x, long double y, long double c) : x(x),y(y),c(c) {}
	long double dist(Point a) {
		long double dx = a.x-x;
		long double dy = a.y-y;
		return std::sqrt(dx*dx+dy*dy);
	}
};

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<Point> points(n);
	for(auto&p:points) std::cin >> p.x >> p.y >> p.c;
	if(k==1) {
		print(0);
		return 0;
	}
	long double eps = 1e-10;
	long double l=0,r=3e5+1423;
	while(r-l>1e-8) {
		long double mid = (l+r)/(long double)2;
		std::vector<Point> inter=points;
		rep(i,n) rep(j,n) if(i!=j) {
			Point p0=points[i],p1=points[j];
			long double r0 = mid/p0.c;
			long double r1 = mid/p1.c;
			if(p0.dist(p1)>r1+r0) continue;
			if(p0.dist(p1)+r0<r1) continue;
			if(p0.dist(p1)+r1<r0) continue;
			long double a,h,d,x0,x1,y0,y1,x2,y2,x3,y3;
			x0=p0.x;y0=p0.y;x1=p1.x;y1=p1.y;
			d=std::sqrt(std::pow(x1-x0,2) + std::pow(y1-y0,2));
			a=(std::pow(r0,2)-std::pow(r1,2)+std::pow(d,2))/(2*d);
			h=std::sqrt(std::pow(r0,2)-std::pow(a,2));
			x2=x0+a*(x1-x0)/d;
			y2=y0+a*(y1-y0)/d;
			x3=x2+h*(y1-y0)/d;
			y3=y2-h*(x1-x0)/d;
			inter.emplace_back(x3,y3,0);
			x3=x2-h*(y1-y0)/d;
			y3=y2+h*(x1-x0)/d;
			inter.emplace_back(x3,y3,0);
		}
		int max = 0;
		for(auto p:inter) {
			int count = 0;
			rep(i,n) if(p.dist(points[i])<=mid/points[i].c+eps) count++;
			max = std::max(max,count);
		}
		if(max>=k) r=mid;
		else l=mid;
	}
	std::cout << std::setprecision(10) << r << ENDL;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

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

signed main(){
	int N;
	cin>>N;
	vint A(N);
	rep(i,N)cin>>A[i];

	int neg=0;
	rep(i,N){
		if(A[i]<0)neg++;
		A[i]=abs(A[i]);
	}

	int al=accumulate(all(A),0ll);
	if(neg&1){
		al-=*min_element(all(A))*2;
	}
	cout<<al<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    std::string S;
    std::cin >> S;
    long len=S.length();
    std::string temp1,temp2;
    temp1=S[0];
    long counter=1;
    for(long i=1; i<len;i++){
        temp2+=S[i];
        if(temp1!=temp2){
            counter++;
            temp1=temp2;
            temp2="";
        }
    }
    std::cout << counter << std::endl;
    return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define int long long
using namespace std ;
long long n , m ,t[ 200005 ][ 64 ] ;
signed main() {
    cin >> n >> m ;
    for( int i = 1 ; i <= n ; ++i )
        cin >> t[ i ][ 0 ] ;
    for( int j = 1 ; j <= 63 ; ++j )
        for( int i = 1 ; i <= n ; ++i ) 
        t[ i ][ j ] = t[ t[ i ][ j - 1 ] ][ j - 1 ] ;
    long long s = 1 ;
    for( int i = 63 ; i >= 0 ; --i ) {
        if ( m & ( 1ll << i ) ) s = t[ s ][ i ] ;
    }
    printf( "%lld\n" , s ) ;
    return 0 ;
}

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

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string N){
    int c = 0;
    REP(i, N.size()) { 
        char n = N[i];
        c += int(n - '0');
    }
    if (c % 9 == 0) { 
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string N;
    std::cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std; 

/*
const int P=998244353; 
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; } 
int mul(int a,int b){ return 1ll*a*b%P; } 
int power(int a,int k){
	int res=1; 
	for(;k;k>>=1,a=mul(a,a))if(k&1)res=mul(res,a); 
	return res;
}
*/

const int N=2e5+50; 

int n,a[N],fail; 
long long ans,sum[N];

void f(int l,int r,long long &mx,long long &mn){
	int p=lower_bound(sum+l+1,sum+r+1,sum[l]+(sum[r]-sum[l])/2)-sum;
	if(p==r){ fail=1; return; }
	cmax(mx,sum[p]-sum[l]); 
	cmin(mn,sum[p]-sum[l]);
	cmax(mx,sum[r]-sum[p]); 
	cmin(mn,sum[r]-sum[p]);
}
void g(int l,int r,long long &mx,long long &mn){
	int p=upper_bound(sum+l+1,sum+r+1,sum[l]+(sum[r]-sum[l])/2)-sum;
	--p;
	if(p==r){ fail=1; return; }
	cmax(mx,sum[p]-sum[l]); 
	cmin(mn,sum[p]-sum[l]);
	cmax(mx,sum[r]-sum[p]); 
	cmin(mn,sum[r]-sum[p]);
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
#endif
	scanf("%d",&n); 
	rep(i,1,n){
		scanf("%d",a+i); 
		sum[i]=sum[i-1]+a[i];
	}
	ans=1e18; 
	for(int mid=2;mid+2<=n;++mid){
		long long mx,mn;
		fail=0,mx=0,mn=1e18; 
		f(0,mid,mx,mn);
		f(mid,n,mx,mn); 
		if(!fail){ ans=min(ans,mx-mn);}
		fail=0,mx=0,mn=1e18; 
		f(0,mid,mx,mn);
		g(mid,n,mx,mn); 
		if(!fail){ ans=min(ans,mx-mn);}
		fail=0,mx=0,mn=1e18; 
		g(0,mid,mx,mn);
		f(mid,n,mx,mn); 
		if(!fail){ ans=min(ans,mx-mn);}
		fail=0,mx=0,mn=1e18; 
		g(0,mid,mx,mn);
		g(mid,n,mx,mn); 
		if(!fail){ ans=min(ans,mx-mn);}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define rep(i, n) for(int (i) = 0; (i) < (n) ; (i)++ )
#define prl(x) cout << (x) << endl

int main(void){
    int n, m, a, b; cin >> n >> m;
    vector<vi> g(n), ls(n, vi(n, 0));
    rep(i, m){
        cin >> a >> b; a--, b--; g[a].push_back(b);
        if (!ls[b][a]) ls[a][b] = 1;
        else {prl(2); prl(a + 1); prl(b + 1); return 0;}
    }


    vi rm(n, 0), vs(n, 0);
    auto update = [&](int src, map<int, int>& nxt, int undo){
        for (int to: g[src]){
            swap(rm[to], nxt[to]);
            if (!undo) rm[to] = 1;
        }
    };

    auto dfs = [&](auto dfs, int src, int rt) -> int{
        for (int to: g[src]) if (to != rt && vs[to]) return 0;
        if (ls[src][rt]) return vs[src] = 1;

        vs[src] = 1; map<int, int> nxt; int ok = 0;
        update(src, nxt, 0);

        for (int to: g[src])
            if (ok) break;
            else if (!nxt[to] && dfs(dfs, to, rt)) ok = 1;

        update(src, nxt, 1);
        return vs[src] = ok;
    };

    rep(i, n){
        rm.assign(n, 0); vs.assign(n, 0);
        if (dfs(dfs, i, i)){
            prl(count(vs.begin(), vs.end(), 1));
            rep(j, n) if (vs[j]) prl(j + 1);
            return 0;
        }
    }

    prl(-1);
    return 0;
}


Measured memory_bytes: 7836
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
    s, w := ScanInt(), ScanInt()
    if w>= s {
    	P("unsafe")
	} else {
		P("safe")
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string {in.Scan(); return in.Text() }
func ScanInt() int {i, _ := strconv.Atoi(ScanWord()); return i}
func ScanInt64() int64 {i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i}
func ScanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = ScanWord()}; return s}
func ScanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = ScanInt()}; return arr}
func ScanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = ScanInt64()}; return arr}

/*********************** Utils ***********************/

func S(v interface{}) string {return fmt.Sprintf("%v", v)}
func SArr(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func SArr64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func MnMx(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64 {return a / GCD(a, b) * b}
func GCD(a, b int64) int64 {if (a == 0) {return b}; return GCD(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func abs(x int64) int64 {if x < 0 {return -x}; return x}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
bool prime(int x){
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return 0;
    return 1;
}
int main(){
    int n;
    cin>>n;
    for(int i=11;n;i+=5){
        if(prime(i)){
            cout<<i<<endl;
            n--;
        }
    }
    return 0;
}

Measured memory_bytes: 256
r,c=map(int,input().split())

rc=[]
for i in range(r):
    rc1=[]
    rc1=input().split()
    rc1=[int(s) for s in rc1]
    rc.append(rc1)


for i in range(r):
    s=sum(rc[i])
    rc[i].append(s)


s=0
total=[]
for i in range(c+1):
    for j in range(r):
        s+=rc[j][i]
    total.append(s)
    s=0
rc.append(total)

for i in range(r+1):
    print(*rc[i])



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

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

int m, n;
int b[555];
int r[555];
int V;
vector<int> G[555+555];
int match[555+555];
int used[555+555];

inline int gcd(int a, int b)
{
  int t;
  while(b){
    t = a;
    a = b;
    b = t % b;
  }
  return a;
}

bool dfs(int v)
{
  used[v] = true;
  rep(i, G[v].size()){
    int u = G[v][i], w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int matching()
{
  int res = 0;
  rep(i, V) match[i] = -1;
  rep(v, V){
    if(match[v] < 0){
      rep(i, V) used[i] = 0;
      if(dfs(v)) res += 1;
    }
  }
  return res;
}

int main()
{
  while(cin >> m >> n, m){
    rep(i, m) cin >> b[i];
    rep(i, n) cin >> r[i];
    V = m + n;
    rep(i, V) G[i].clear();

    rep(i, m) rep(j, n) if(gcd(b[i], r[j]) > 1){
      G[i].push_back(j + m);
      G[m + j].push_back(i);
    }

    cout << matching() << endl;
  }

  return 0;
}

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

int main(){
    long long N;
    cin >> N;
    long long x,y,i;
    long long douplu, doumi, iplu, imi;
    douplu=-1000000000000000000;
    doumi=-1000000000000000000;
    iplu=-1000000000000000000;
    imi=-1000000000000000000;
    for(i=0; i<N; i++){
        cin >> x >> y;
        douplu=max(douplu,x+y);
        doumi=max(doumi,-x-y);
        iplu=max(iplu,x-y);
        imi=max(imi,-x+y);
    }
    long long ans=-1000000000000000000;
    ans=max(ans,douplu+doumi);
    ans=max(ans,iplu+imi);
    cout << ans << endl;
    system("pause");
    return 0;
}

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

using namespace std;

void test()
{
   int n,m;
   cin>>n>>m;
   
   cout<<(n*(n-1))/2 +(m*(m-1))/2;
}

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

    test();

    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  FOR(i, N) cin >> A[i];
  vector<ll> B(M), C(M);
  FOR(i, M) { cin >> B[i] >> C[i]; }
  sort(ALL(A));
  vector<int> index(M);
  FOR(i, M) index[i] = i;
  sort(ALL(index), [&](const int& l, const int& r) { return C[l] > C[r]; });
  int now = -1;
  FOR(i, M) {
    ll b = B[index[i]];
    ll c = C[index[i]];
    int bound = lower_bound(A.begin() + now + 1, A.end(), c) - A.begin();
    int nw = min(now + (int)b, bound - 1);
    FORIN(j, now + 1, nw + 1) { A[j] = c; }
    now = nw;
  }
  ll sum = accumulate(ALL(A), 0LL);
  print(sum);
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007;
int main(){
	string s; cin >> s;
	vector<int> f(13, 0), nf(13, 0);
	f[0] = 1;
	for(auto c : s){
		fill(nf.begin(), nf.end(), 0);
		if(c == '?'){
			for(int i = 0; i < 13; i++){
				for(int j = 0; j < 10; j++){
					int nw = i * 10 + j;
					nw %= 13;
					nf[nw] += f[i];
					if(nf[nw] >= mod) nf[nw] -= mod;
				}
			}
		} else {
			int j = c - '0';
			for(int i = 0; i < 13; i++){
				int nw = i * 10 + j;
				nw %= 13;
				nf[nw] += f[i];
				if(nf[nw] >= mod) nf[nw] -= mod;
			}
		}
		f = nf;
	}
	cout << f[5] << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <cmath>
#include <limits>

int gcd(int x, int y) {
    for(; x; y=y%x, std::swap(x,y)) {}
    return y;
}

bool is_prime(int x) {
    if(x<2) return false;
    if(x==2) return true;
    if(x%2==0) return false;
    int max{int(sqrt(double(x)))+1};
    for(auto i=3; i<max; i+=2) {
        if(gcd(x,i) != 1) return false;
    }
    return true;
}

int main() {
    int n{}, x{}, prime_count{};
    std::cin >> n;
    for(auto i=0; i<n; i++) {
        std::cin >> x;
        prime_count += is_prime(x) ? 1 : 0;
    }
    std::cout << prime_count << std::endl;
}



Measured memory_bytes: 3124
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = s <= w;
        String result = judge ? "unsafe" : "safe";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35460
#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);
    int n; cin >> n;
    V< V<int> > a(n, V<int>(n));
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
    vll suma(1 << n, 0);
    for (int state = 1; state < (1 << n); state++) {
        for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
            if ((state >> i & 1) && (state >> j & 1)) suma[state] += ll(a[i][j]);
        }
    }

    vll dp(1 << n);
    for (int state = 1; state < (1 << n); state++) {
        dp[state] = suma[state];
        for (int subset = state; subset > 0; subset = (subset - 1) & state) {
            chmax(dp[state], dp[subset] + dp[state ^ subset]);
        }
    }
    cout << dp.back() << '\n';
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    stringstream ss;
    string c = a + b; // "123456" "123" "456"
    ss << c; // ss "123456"
    int num;
    ss >> num;
    int sqrtNum = (int)sqrt(num); // 25 -> 5 26 -> 5 26 != 5 *5
    // printf("%d", sqrtNum);
    printf("%s", sqrtNum * sqrtNum == num ? "Yes" : "No");
}


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

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0){
				int out = stack.pop();
				System.out.println(out);
			}
			else{
				stack.push(n);
			}
		}


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

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n,k;
  int ans=0;
  cin>>n>>k;
  rep(i,n){
    int h;
    cin>>h;
    if(h>=k)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


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

bool isOdd(int x){
      int ans = 0;
      while(x > 0){
            ans++;
            x /= 10;
      }
      return 1 & ans;
}

int main(){
      int n;cin >> n;
      int ans = 0;
      for(int i = 0;i <= n;i++){
            if(isOdd(i))ans++;
      }
      cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#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 sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; string S; cin >> N >> S;
  int ans = 0;
  rep(i,N) if(S.substr(i,3)=="ABC") ans++;
  cout << ans << endl;
  return 0;
}


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

int main(){
  int H[10001];
  int n,key;

  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> H[i];
  }
  
  for(int i = 1;i < n + 1;i++){
    
    cout << "node " << i <<": ";
    cout << "key = " << H[i] << ", ";
    if(i / 2 >= 1) cout << "parent key = " << H[i / 2] << ", ";
    if(i * 2 <= n) cout << "left key = " << H[i * 2] << ", ";
    if(i * 2 + 1 <= n) cout << "right key = " << H[i * 2 + 1] << ", ";
    cout << endl;
  }
  
  return 0;
}
  



Measured memory_bytes: 3108
import sys
input = sys.stdin.readline

H,W,K = map(int,input().split())
mod = 1000000007
dp = [[0]*(W+2) for _ in range(H+1)]
dp[0][1]=1
for i in range(1,H+1):
    for j in range(1,W+1):
        x=0
        y=0
        z=0
        for k in range(2**(W-1)):
            tmp = format(k, "b")
            tmp = tmp.zfill(W-1)
            tmp += "0"
            tmp = list(tmp)
            Flag = True
            for l in range(len(tmp)-1):
                if tmp[l] == tmp[l+1] == "1" or (j>=2 and tmp[j-2] != "1"):
                    Flag = False
                    break
            if Flag:
                x+=1
        for k in range(2**(W-1)):
            tmp = format(k, "b")
            tmp = tmp.zfill(W-1)
            tmp += "0"
            tmp = list(tmp)
            Flag = True
            for l in range(len(tmp)-1):
                if tmp[l] == tmp[l+1] == "1" or (j>=2 and tmp[j-2] == "1") or (j>=1 and tmp[j-1] == "1"):
                    Flag = False
                    break
            if Flag:
                y+=1   
        for k in range(2**(W-1)):
            tmp = format(k, "b")
            tmp = tmp.zfill(W-1)
            tmp += "0"
            tmp = list(tmp)
            Flag = True
            for l in range(len(tmp)-1):
                if tmp[l] == tmp[l+1] == "1" or (j>=1 and tmp[j-1] != "1"):
                    Flag = False
                    break
            if Flag:
                z+=1   
        dp[i][j] += x*dp[i-1][j-1]+y*dp[i-1][j]+z*dp[i-1][j+1]
        dp[i][j] %= mod
print(dp[H][K]%mod)

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,i;
    cin >> n >> k;
    long long int arr[200005];
    for(i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    if(k>=n)
    {
        printf("0\n");
    }
    else
    {
        long long int sum=0;
        for(i=0;i<n-k;i++)
        {
            sum = sum + arr[i];
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1792