akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.List

solve :: [[Bool]] -> [String] -> [String]
solve [] [] = []
solve (m:ms) (f:fs) = map snd (filter fst $ zip m f) : solve ms fs

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  fields <- replicateM h getLine
  let rows = elem '#' <$> fields
  let columns = elem '#' <$> transpose fields
  let marks = [[x && y | y <- columns] | x <- rows]
  mapM_ putStrLn $ filter (not . null) $ solve marks fields

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    ll N;
    cin>>N;
    ll sum =0;
    ll i=1;
    while(sum < N){
        sum += i;
        i++;
    }
    i--;
    ll change = (1+i)*i/2 - N;

    rep(j,1,i+1){
            if(change == j)continue;
            else cout<<j<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  char b;

  scanf("%c", &b);

  switch (b) {
  case 'A':
    printf("T\n");
    break;
  case 'T':
    printf("A\n");
    break;
  case 'G':
    printf("C\n");
    break;
  case 'C':
    printf("G\n");
    break;
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}

// ナップザック問題、複数選択可ナップザック問題
// wの合計がlimit_w以下となるvの最大値を求める
#define MAX_N (1000) // 魔法の数
#define MAX_W (10000+10000) // 最大体力+魔法の威力
int N, H;
int v[MAX_N];
int w[MAX_N];
// dp[i][j]:i番目の魔法までを使って、体力をj減らすときの最小魔力
int dp[MAX_N + 1][MAX_W + 1];

int main() {

	cin >> H >> N;
	int max_power = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i]; // v:威力 w:魔力
		max_power = max(max_power, v[i]);
	}

	Fill(dp, INF/2);
	for (int i = 0; i < N; i++) dp[i][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= H+max_power; j++) {
			//i番目が採用できるか否かを判定
			if (j < v[i]) { // 削る体力に対して魔法が強すぎる
				dp[i + 1][j] = dp[i][j]; // その魔法は使えない
			}
			else {
				//i番目が採用できるとき、iを使うケースと使わないケースのminを取る

				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - v[i]] + w[i]); // 個数制約なし(iを複数つかえる)
//				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); // 個数制約あり
			}
		}
	}

	int ans = INF / 2;
	for (int i = H; i <= H + max_power; i++) {
		if (dp[N][i] != INF/2) ans = min(ans, dp[N][i]);
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 78464
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, D);
    IN(ll, T);
    IN(ll, S);
    YES((D + S - 1) / S <= T);
}

Measured memory_bytes: 3624
<?php
fscanf(STDIN, "%d %d", $n, $x);
$ar = explode(" ", fgets(STDIN));

$rtn=1;
$p = 0;
foreach($ar as $v){
  $p+=$v;
  if($p<=$x) $rtn++;
}
echo $rtn."\n";

?>

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    while (1)
    {
        double dis;
        double a[10];
        char c;
        rep(i, 10)
        {
            cin >> a[i] >> c;
        }
        if (cin.eof())
            break;

        double s[11] = {};
        rep(i, 10) s[i + 1] = s[i] + a[i];

        dis = s[10];

        double v1, v2;
        cin >> v1 >> c >> v2;
        double x = v1 * dis / (v1 + v2);

        for (int i = 1; i <= 10; i++)
        {
            if (x <= s[i])
            {
                OP(i);
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3228
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);

  if(D[u]==0)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i,j,k;
  int n;
  int id,sib,child;
  int root=NIL;
  scanf("%d", &n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j=0,sib=NIL;j<k;j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



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

int main() {
	int N, k;
	cin >> N >> k;

	int n = 1;
	for (int i = 0; i < N; i++) {
		if (n * 2 < n + k) {
			n *= 2;
		}
		else {
			n += k;
		}
	}

	cout << n << endl;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n, m;
    cin >> n >> m;
    if(n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if((n*a)<=b)
    {
        cout<<(n*a)<<endl;
    }
    else
    {
        cout<<b<<endl;
    }
    return 0;
}


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

using namespace std;

const int N=1000000;
const int INF=1<<30;

int main(){
  static int dp[N];
  static int dpo[N];
  fill(begin(dp),end(dp),INF);
  fill(begin(dpo),end(dpo),INF);
  dp[0]=dpo[0]=0;
  for(int i=0;;i++){
    int q=i*(i+1)*(i+2)/6;
    if(q>N)break;
    for(int j=q;j<N;j++){
      dp[j]=min(dp[j],dp[j-q]+1);
      if(q%2){
	dpo[j]=min(dpo[j],dpo[j-q]+1);
      }
    }
  }
  for(int n;cin>>n,n;){
    cout<<dp[n]<<' '<<dpo[n]<<endl;
  }
}

Measured memory_bytes: 8972
#include<bits/stdc++.h>
#define INF 2147483640
using namespace std;
long long a[200005],b[200005];
int main()
{
	//freopen("out.txt","w",stdout);
	int n,m,k,ans=0;
	cin >> n >> m >> k;
	for(int i=1; i<=n; i++) {cin >> a[i]; a[i]=a[i]+a[i-1];}
	for(int i=1; i<=m; i++) {cin >> b[i]; b[i]=b[i]+b[i-1];}
	int j=m;
	for(int i=0; i<=n; i++)
	{
		if(a[i] > k) break;
		while(j > 0 && a[i] + b[j] > k) j--;
		ans=max(ans,i+j);
		//cout << i << ' ' << j << '\n';
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
while (true) {
  cin >> a >> b;
  if (a == 0 && b == 0) break;
  for (int i = 0; i < a; i++) {
  for (int j = 0; j < b; j++) cout << "#";
  cout << endl;
  }
  cout << endl;
}
}


Measured memory_bytes: 3064
A, B, C = input().split()
A = int(A)
B = int(B)
C = int(C)
K = input()
K = int(K)
z = 0
while B <= A:
    B = B * 2
    z = z + 1
while C <= B:
    C = C * 2
    z = z + 1
if K < z:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    // debg(K*D)
    // if(K*D<=X){
    X=abs(X);
    if(K<X/D){
        cout << X-K*D << endl;
    }else{
        ll r = X/D;
        ll kr = K-r;
        // debg(r)
        // debg(kr)
        if(kr%2==0){
            // cout << X-r*D << endl;
            cout << X%D << endl;
        }else{
            // cout << abs(X-r*D-D) << endl;
            cout << abs(X%D-D) << endl;
        }
    }
    return 0;
}
// 1000000000000000 1000000000000000 1000000000000000
// 1000000000000000

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9 + 7;

ll dp[5000010] = {0};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t != 0) {
        int n;
        ll arr[25][25] = {0};
        cin >> n;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                cin >> arr[i][j];
            }
        }
        dp[0] = (ll)1;
        for(int mask = 0; mask < (1 << n) - 1; mask++) {
            int i = __builtin_popcount(mask);
            // cout << i << " ";
            for(int j = 0; j < n; j++) {
                if(arr[i][j] && !(mask & (1 << j))) {
                    int m2 = mask ^ (1 << j);
                    dp[m2] = ( dp[m2] + dp[mask] ) % MOD;
                }
            }
        }
        // for(int i = 0; i < (1 << n); i++) {
        //     cout << dp[i] << " ";
        // }
        // cout << "\n";
        cout << dp[(1 << n) - 1] % MOD << "\n";
	    t--;
	}
	return 0;
}


Measured memory_bytes: 18688
from math import gcd
def main():
    n=int(input())
    A=list(map(int,input().split()))
    m=max(A)
    l=[0 for _ in range(m)]
    fp=True
    for a in A:
        l[a-1]+=1
    for i in range(2,m):
        cnt=0
        for j in range(i-1,m,i):
            cnt+=l[j]
            if cnt>1:
                fp=False
                break
    g=0
    fs=False
    for a in A:
        g=gcd(g,a)
    if g==1:
        fs=True

    if fp:
        print("pairwise coprime")
    elif fs:
        print("setwise coprime")
    else:
        print("not coprime")
if __name__=="__main__":
    main()

Measured memory_bytes: 220644
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	double a,b,c,degree,S;
	scanf("%lf %lf %lf",&a,&b,&degree);
	S = (0.5)*a*b*sin(M_PI*degree/180);
	c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
	printf("%.8lf\n",S);
	printf("%.8lf\n",a+b+c);
	printf("%.8lf\n",2*S/a);
}


Measured memory_bytes: 3116
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

  using i8 = std::int_fast8_t;
  using i32 = std::int_fast32_t;
  using i64 = std::int_fast64_t;
  using u8 = std::uint_fast8_t;
  using u32 = std::uint_fast32_t;
  using u64 = std::uint_fast64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { ++i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  struct revrep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { --i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) noexcept {
    return a < b ? b - a : a - b;
  }
  template <class T> void chmin(T& a, const T& b) noexcept {
    if (b < a)
      a = b;
  }
  template <class T> void chmax(T& a, const T& b) noexcept {
    if (a < b)
      a = b;
  }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }

} // namespace n91

#include <algorithm>
#include <iostream>
#include <numeric>
#include <utility>

namespace n91 {

  void main_() {
    /*
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //*/
    const usize m = scan<usize>();
    std::vector<u64> d(m), c(m);
    u64 sum = 0;
    u64 dig = 0;
    for (const usize i : rep(0, m)) {
      std::cin >> d[i] >> c[i];
      sum += d[i] * c[i];
      dig += c[i];
    }
    std::cout << (sum - 1) / 9 + dig - 1 << std::endl;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 3328
N = int(input())
 
L = list(map(int, input().split()))
L.sort()
ret = 0
if N >= 3:
  for i in range(N - 2):
    for j in range(i + 1, N - 1):
      if L[i] != L[j]:
        for k in range(j + 1, N):
          if L[i] != L[k] and L[j] != L[k] and L[i] + L[j] > L[k]:
            ret += 1
print(ret)

Measured memory_bytes: 9208
a = []
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    a.append([H, W])
for i in range(len(a)):
    b = a[i]
    if b[0] == 1:
        print('#' * b[1])
    elif b[0] == 2:
        print('#' * b[1])
        print('#' * b[1])
    elif b[1] == 1:
        for j in range(0, b[0]):
            print('#')
    else:
        print('#' * b[1])
        for j in range(1,b[0]-1):
            print('#'+'.'*(b[1]-2)+'#')
        print('#' * b[1])
    print('')


Measured memory_bytes: 5624
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int ans = 1000;
    for (int i = 0; i < 26; i++) {
        char c = 'a' + i;

        int mx = 0;
        int cnt = 0;
        for (int j = 0; j < s.size(); j++) {
            if (s[j] == c) {
                mx = max(mx, cnt);
                cnt = 0;
            } else {
                cnt++;
            }
        }
        mx = max(mx, cnt);

        ans = min(ans, mx);
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
using namespace std;

#define N 107
#define INF 10000007

typedef pair<int, int> P;

int main() {
	int n;
	string s;
	int cost[N];
	string go[N];
	map<string, int> label;
	vector<string> lstr;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> s;
		if(s=="goto") {
			cin >> s;
			go[i] = s.substr(0, s.length()-1);
		}else {
			label[s.substr(0, s.length()-1)] = i;
		}
	}
	priority_queue<P, vector<P>, greater<P> > q;
	for(int i=0; i<n+1; ++i) cost[i] = INF;
	q.push(P(0, 0));
	cost[0] = 0;
	while(!q.empty()) {
		int li = q.top().second, c = q.top().first; q.pop();
		if(cost[li] < c) continue;
		//cout << li << " " << c << endl;
		if(!go[li].empty()) {
			int jmp = label[go[li]];
			if(cost[li] < cost[jmp]) {
				cost[jmp] = cost[li];
				q.push(P(cost[jmp], jmp));
			}
			if(cost[li] + 1 < cost[li+1]) {
				cost[li+1] = cost[li] + 1;
				if(li!=n) q.push(P(cost[li+1], li+1));
			}
		}else {
			if(li+1 <= n && cost[li] < cost[li+1]) {
				cost[li+1] = cost[li];
				if(li!=n) q.push(P(cost[li+1], li+1));
			}
		}
	}
	cout << cost[n] << endl;
	return 0;
}

Measured memory_bytes: 1232
<?php

$input = readline();

$parts = explode(" ", $input);

$K = $parts[0];

$S = $parts[1];


if ($S == 3 * $K)
{
    echo "1" . "\n";
    die();
}

$total = 0;
for ($i = 0; $i <= $K; $i++)
{
    $balance = $S - $i;
    
    for ($j = 0; $j <= $K; $j++)
    {
        $balance_2 = $balance - $j;
         
        if ($balance - $j < 0)
            break;
        else if ($balance_2 > $K)
        {
            continue;
        }
        else
        {
            $total++;
        }

    }
    
}

echo $total . "\n";

Measured memory_bytes: 3832
//abc114_c.cpp
//Sun Dec  2 20:52:42 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
int n;
vector<int> sgscan;

ll sgsnum(ll sgs){
	if (sgs*10+7<=n){
		sgscan.push_back(sgs*10+7);
		sgsnum(sgs*10+7);
	}
	if (sgs*10+5<=n){
		sgscan.push_back(sgs*10+5);
		sgsnum(sgs*10+5);
	}
	if (sgs*10+3<=n){
		sgscan.push_back(sgs*10+3);
		sgsnum(sgs*10+3);
	}
}


int main(){
	cin >> n;

	sgsnum(0);

	int ans = 0;
	for(int i=0;i<sgscan.size();i++){
		int temp = sgscan[i];
		unordered_map<int,int> sgsmap;
		while (temp>0){
			sgsmap[temp%10]++;
			temp=temp/10;
		}
		if (sgsmap[7]&&sgsmap[5]&&sgsmap[3]){
			ans++;
		}
	}

	cout << ans <<  endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
const int M = 105;
const int mod = 1e9 + 7;
int n, num[N], d;
string snum;

int add(int x, int y) {
	if (x + y >= mod) {
		return x + y - mod;
	}
	return x + y;
}

/* TOP DOWN 
int mem[N][M][2];
bool vis[N][M][2];

int dp(int i, int m, bool border) {
	if (i == n) {
		return m ? 0 : 1;
	}
	if (vis[i][m][border]) {
		return mem[i][m][border];
	}
	vis[i][m][border] = true;

	int lv = border ? num[i] : 9;

	int ans = 0;
	for (int j = 0; j <= lv; j++) {
		bool nb = border && j == lv;
		ans = add(ans, dp(i + 1, (m + j) % d, nb));
	}

	return mem[i][m][border] = ans;
}
*/

int dp[N][M][2];

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

	cin >> snum >> d;
	n = snum.size();

	for (int i = 0; i < n; i++) {
		num[i] = snum[i] - '0';
	}

	dp[n][0][1] = 1;
	dp[n][0][0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		for (int m = 0; m < d; m++) {
			for (int border = 0; border < 2; border++) {
				int lv = border ? num[i] : 9;

				for (int j = 0; j <= lv; j++) {
					int nb = border && (j == lv);
					dp[i][m][border] = add(dp[i][m][border], dp[i + 1][(m + j) % d][nb]);
				}
			}
		}
	}

	cout << (mod + dp[0][0][1] - 1) % mod << '\n';

	return 0;
}


Measured memory_bytes: 11916
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 5121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[210000];
int ans[110000][3];
int sz[110000];
pair<int,int > q[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int L=b+a*2;
	int M=b+(b+a*2-1);
	M-=(a-1)/2;
	if(L<M){
		printf("-1\n");return 0;
	}
	for(int i=0;i<a*2;i++)p[i]=min(a*2-1-i,i);
	
	int n=(a-1)/2;
	int z=(n+1)/2*2;
	for(int i=0;i<z/2;i++){
		swap(p[i],p[z-1-i]);
	}
	int y=1+(n/2*2);
	for(int i=0;i<y/2;i++){
		swap(p[z+i],p[z+y-1-i]);
	}
	for(int i=0;i<a*2;i++){
		if(sz[p[i]])ans[p[i]][1]=i+b;
		else{
			sz[p[i]]=1;
			ans[p[i]][0]=i+b;
		}
	}
	for(int i=0;i<a;i++)q[i]=make_pair(ans[i][0]+ans[i][1],i);
	std::sort(q,q+a);
	for(int i=0;i<a;i++)ans[i][2]=b+a*2+i;

	for(int i=0;i<a;i++)printf("%d %d %d\n",ans[q[i].second][0],ans[q[i].second][1],ans[i][2]);
}

Measured memory_bytes: 5248
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	int h[100];
	gi(N);
	fi(N){
		gi(h[i]);
	}

	fi(N){
		flag = 0;
		fj(i){
			if(h[i] < h[j]){
				flag = 1;
				break;
			}
		}
		if(!flag) ret++;
	}

	ans(ret);

	wait();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int a, b;
	while(cin >> a >> b)
	{
		if(!a && !b)
		{
			break;
		}
		int back = b - a;
		int count1000 = back / 1000;
		back %= 1000;
		int count500 = back / 500;
		back %= 500;
		int count100 = back / 100;
		cout << count100 << " " << count500 << " " << count1000 << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		PrimeNumberGenerator pg = new PrimeNumberGenerator();
		int n = sc.nextInt();
		int a[] = new int[n];
		int a2[] = new int[n];

		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			a2[i] = a[i];
		}

		int count[] = new int[1_000_001];
		boolean pc = true;
		for(int i = 0; i < n; i++){
//			System.out.println("i = "+i);
			if(pg.isPrime(a[i])){
				if(count[a[i]] > 0){
//					System.out.println(a[i] + " already appeared");
					pc = false;
					break;
				}
				else {
					count[a[i]]++;
				}
			}

			else {
				int div = 2;
				boolean firstCheck = true;
				while(a[i] > 1){
					if(a[i] % div == 0){
						if(firstCheck && count[div] > 0){
//							System.out.println(div + " already appeared");
							pc = false;
							break;
						}
						else {
							a[i] /= div;
							count[div]++;
							firstCheck = false;
						}
					}
					else {
						div++;
						firstCheck = true;
					}
				}

				if(!pc){
					break;
				}
			}
		}

		if(pc) {
			System.out.println("pairwise coprime");
			return;
		}

		int result = a2[0];

		for(int i = 1; i < n; i++){
			result = gcd(a2[i], result);
		}

		if(result == 1){
			System.out.println("setwise coprime");
		}
		else {
			System.out.println("not coprime");
		}
	}

	static int gcd(int a, int b){
        int tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
}

class PrimeNumberGenerator {
    private final int N = 1000000;
    private boolean[] isPrime= new boolean[N + 1];

    public PrimeNumberGenerator() {
        Arrays.fill(isPrime, true);

        isPrime[0] = false;
        isPrime[1] = false;

        int limit = (int)Math.sqrt(N);
        for(int i = 2; i <= limit ; i++){

            if(isPrime[i] == false){
                continue;
            }

            for(int j = i * 2; j <= N; j += i){
                isPrime[j] = false;
            }
        }
    }

    public boolean isPrime(int index){
        return isPrime[index];
    }
}

Measured memory_bytes: 58280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for (int i=0; i<s.length()-1; i++){
            if (s.charAt(i) != s.charAt(i+1)){
                count++;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 25044
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Measured memory_bytes: 24092
#include <iostream>
#include <queue>
#include <cmath>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    
    int V[N];
    for(int i=0; i<N; i++){
        cin >> V[i];
    }

    long ans = 0;
    for(int ret=0; ret<K; ret++){
        for(int l=0; l<=K-ret; l++){
            if(l > N) break;
            int r = K-l-ret;
            if(r > N) break;
            priority_queue<int, vector<int>, greater<int>> q;
            for(int i=0; i<l; i++) q.push(V[i]);
            for(int i=0; i<r; i++) q.push(V[N-1-i]);
            for(int i=0; i<ret; i++){
                if(q.empty()) break;
                if(q.top() < 0) q.pop();
                else break;
            } 

            long t = 0;
            while(!q.empty()){
                t += q.top();
                q.pop();
            }

            if(t > ans) ans = t;

        }
    }

    cout << ans;

    return 0;
}

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

int main() {
	// your code goes here
	int m , n;
	cin>>m>>n;
	priority_queue<int> pq;
	vector<int> gra[n+1];
	for(int i = 0 ; i < m ; i++)
	{
	    int a , b;
	    cin>>a>>b;
	    if(n-a+1 > 0)
	    {
	        gra[n-a+1].push_back(b);
	    }
	}
	int ans = 0;
	for(int i = n ; i>=1 ; i--)
	{
	    for(auto x : gra[i])
	    {
	        pq.push(x);
	    }
	    if(!pq.empty())
	    {
	        ans += pq.top();
	        pq.pop();
	    }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5504
s = input()
t = input()

lens = len(s)
lent = len(t)
ans = 10000
for i in range(lens-lent+1):
    tmp = 0
    for j in range(lent):
        if(s[i+j] != t[j]):
            tmp += 1
    ans = min(tmp,ans)

print(ans)


Measured memory_bytes: 8944
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let ans = s.chars().filter(|&c| c == '1').count();

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main(void) {
  int A, B;
  cin >> A >> B;

  string S;
  cin >> S;

  int postal_code_number = A + B + 1;
  if (S.size() != postal_code_number) {
    cout << "No" << endl;
    return 0;
  }
  if (S[A] != '-') {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < postal_code_number; i++) {
    if (i != A && S[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, K; cin >> N >> K;
    vector<int>x(N);
    int ans = 0;
    rep(i, N) {
        cin >> x[i];
        ans += min(x[i], abs(x[i] - K));
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 3628
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template <class T>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const &vec) : cusum(vec.size() + 1) {
		for (int i = 0; i < (int)vec.size(); i++) cusum[i + 1] = cusum[i] + vec[i];
	}
	CuSum(const int N) : cusum(N + 1) {}
	void add(const int i, const T &x) { cusum[i + 1] += x; }
	void build() { for (int i = 0; i < (int)cusum.size() - 1; i++) cusum[i + 1] += cusum[i]; }

	// partial sum of 0-indexed [l, r)
	T operator()(int l, int r) {
		if (r < l || r < 0) {
			assert(0);
			return T(0);
		}
		else return cusum[r] - cusum[l];
	}
	// 0-indexed
	const T &operator[](int i) { return cusum[i + 1]; }
	T back() { return cusum.back(); }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	vector<lint> A(N);
	for (int i = 0; i < N; i++) cin >> A[i], A[i]--;
	CuSum<lint> cuA(A);

	map<lint, vector<lint>> mp;
	for (int i = 0; i <= N; i++) mp[cuA(0, i) % K].emplace_back(i);

	lint ans = 0;
	for (const auto &e : mp) {
		auto vec = e.second;
		for (int i = 0; i < vec.size(); i++) {
			ans += lower_bound(vec.begin(), vec.end(), vec[i] + K) - vec.begin() - i - 1;
		}
	}

	cout << ans << "\n";

	return 0;
}


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

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

  int n;
  cin >> n;
  map<string, ll> mp;
  rep(i, 0, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll ans = 0;
  for (auto m : mp) {
    ll x = m.second;
    x--;
    ans += (x * (x + 1)) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 11468
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

using Graph=vector<vector<int>>;

const int N_MAX=200100;
Graph G(N_MAX);


int main(){
    int N,Q;
    cin>>N>>Q;
    REP(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> table(N_MAX,0);
    REP(i,Q){
        int p,x;
        cin>>p>>x;
        p--;
        table[p]+=x;
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    
    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = table[0];
    que.push(0); // 0 を橙色頂点にする
    
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v=que.front();
        que.pop();
    
        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + table[nv];
            que.push(nv);
        }
    }
    REP(i,N){
        cout<<dist[i];
        if(i!=N-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
    

    

    
}

Measured memory_bytes: 17476
N, K = map(int, input().split())
v = list(map(int, input().split()))
w = v[::-1]

res = 0
for l in range(N+1):
    for r in range(N+1):
        if l+r > N or l+r > K:
            break
        x = sorted(v[:l] + w[:r])
        for i in range(l+r):
            if x[i] > 0 or i == K-l-r:
                res = max(res, sum(x[i:]))
                break
print(res)

Measured memory_bytes: 3064
import math


def ceil(a: int, b: int) -> int:
    '''a / b の切り上げを求める。
    '''
    n = a // b
    return n if n * b == a else n + 1


def atcodeer_and_election_report(N: int, ratios: list) -> int:
    t, a = ratios[0]

    for nt, na in ratios[1:]:
        # t <= nt * k and a <= na * k
        # を満たす最小の k を求めたい
        k = max(ceil(t, nt), ceil(a, na))
        t, a = nt * k, na * k

    return t + a


if __name__ == "__main__":
    N = int(input())
    ratios = [tuple(int(s) for s in input().split()) for _ in range(N)]
    ans = atcodeer_and_election_report(N, ratios)
    print(ans)


Measured memory_bytes: 3188
a, b, c, x, y = list(map(int, input().split()))
ans = 0
if a + b >= 2 * c:
    ans = 2 * c * min(x, y)
    if x == y:
        pass
    elif x > y and a < 2 * c:
        ans += a * (x - y)
    elif x < y and b < 2 * c:
        ans += b * (y - x)
    else:
        ans += 2 * c * abs(x - y)
else:
    ans = a * x + b * y
print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  auto pri=prime_table(1000000);
  V(int)psum(1000000,0);
  rer(i,1,1000000){
    psum[i]=psum[i-1]+pri[i];
  }
  while(cin>>n)pri(psum[n]);
}



Measured memory_bytes: 6648
#include <stdio.h>
int main(){
    int n,N=0,K=0;
    scanf("%d%d",&N,&K);
    if(N%2!=0){
        n=(N+1)/2;
    }else{
        n=N/2;
    }
    if(n>=K){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let x:Vec<i64> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    let y = x[2]-x[1];
    if y%2==0 {
        println!("Alice");
    } else {
        println!("Borys");
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

pair<int, int> bfs(const vector<vector<int>> &g, int s) {
	queue<int> que;
	que.push(s);

	vector<pair<int, int>> dist(g.size());
	for (int i = 0; i < g.size(); i++) {
		dist[i].first = i;
		dist[i].second = -1;
	}
	dist[s].second = 0;

	int now = s;
	while (!que.empty()) {
		now = que.front(); que.pop();
		for (auto next : g[now]) {
			if (dist[next].second != -1) {
				continue;
			}

			dist[next].second = dist[now].second + 1;
			que.push(next);
		}
	}

	return dist[now];
}

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

	int n;
	cin >> n;

	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	int u = bfs(g, 0).first;
	int diameter = bfs(g, u).second;
	if (diameter % 3 == 1) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
	return 0;
}


Measured memory_bytes: 14424
import sys
input = sys.stdin.readline
from heapq import heappop, heappush
INF = 10 ** 18

def dijkstra(n, s, g, mode):
    dist = [INF] * n
    dist[s] = 0
    hq = [(0, s)]
    while hq:
        d, v = heappop(hq)
        if dist[v] < d:
            continue
        for w, *a in g[v]:
            nd = d + a[mode]
            if dist[w] > nd:
                dist[w] = nd
                heappush(hq, (nd, w))
    return dist

def main():
    n, m, s, t = map(int, input().split())
    s -= 1
    t -= 1
    graph = [[] for _ in range(n)]
    for i in range(m):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        graph[u].append((v, a, b))
        graph[v].append((u, a, b))
    s_dist = dijkstra(n, s, graph, 0)
    t_dist = dijkstra(n, t, graph, 1)

    cost = float("inf")
    ans = [0] * n
    for i in range(n-1, -1, -1):
        cost = min(cost, s_dist[i] + t_dist[i])
        ans[i] = 10 ** 15 - cost
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Measured memory_bytes: 97552
N, L = map(int,input().split())
taste = [ L + i for i in range(N) ]

abs_min_taste = 9999
min_i = -1
for i in range(N):
    if abs_min_taste > abs(taste[i]):
        min_i = i
        abs_min_taste = abs(taste[i])

sum_taste = sum(taste)
ans = sum_taste - taste[min_i]
#print(N, L, taste, abs_min_taste, ans)
print(ans)

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int a, b, k;

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

	cin>>k>>a>>b;
	for(int i=1; i<=1000; i++){
		if(a <= k*i && k*i <= b){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";

	return 0;
}


Measured memory_bytes: 3652