akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

ll X, Y, A, B, C;

vector<ll> make_imos(vector<ll> v) {
    const int N = v.size();
    vector<ll> res(N + 1, 0);
    sort(v.begin(), v.end(), greater<ll>());
    rep(i, N)res[i + 1] += res[i] + v[i];
    return res;
}

ll delicious(
    const vector<ll>& p,
    const vector<ll>& q,
    const vector<ll>& r,
    const ll alpha,
    const ll beta
) {
    ll score = 0;
    score += p[alpha];
    score += q[beta];

    ll alpha2 = X - alpha;
    ll beta2 = Y - beta;
    ll gamma = alpha2 + beta2;
    if (C < gamma)return -INFL;

    score += r[gamma];
    return score;
}

int main()
{
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    rep(i, A)cin >> p[i];
    rep(i, B)cin >> q[i];
    rep(i, C)cin >> r[i];

    p = make_imos(p);
    q = make_imos(q);
    r = make_imos(r);

    ll res = 0;
    rep(alpha, min(X, A) + 1) {
        ll alpha2 = X - alpha;
        if (alpha2 + max(Y - B, 0ll) > C) {
            continue;
        }
        ll betaL = 0, betaR = min(Y, B) + 1;
        while (betaR - betaL > 2) {
            ll betaMidL = (betaL * 2 + betaR) / 3;
            ll betaMidR = (betaL + betaR * 2) / 3;

            ll vl = delicious(p, q, r, alpha, betaMidL);
            ll vr = delicious(p, q, r, alpha, betaMidR);
            if (vl > vr)betaR = betaMidR;
            else betaL = betaMidL;
        }
        REP(beta, betaL, betaR) {
            maxch(res, delicious(p, q, r, alpha, beta));
        }
    }
    output(res);
    return 0;
}


Measured memory_bytes: 4192
# ALDS1_3_B: Queue

# A simple queue.
class Queue
  def initialize(capacity)
    @queue = Array.new capacity
    @head = @num = 0
  end

  def enq(item)
    raise 'Queue is full' if full?
    @num += 1
    tail = (@head + @num - 1) % @queue.size
    @queue[tail] = item
  end

  def deq
    raise 'Queue is empty' if empty?
    item = @queue[@head]
    @queue[@head] = nil
    @head = (@head + 1) % @queue.size
    @num -= 1
    item
  end

  def empty?
    @num == 0
  end

  def full?
    @num == @queue.size
  end
end

# A processor.
class CPU
  MAX_N_PROCESSES = 100000
  Process = Struct.new :name, :time

  def initialize(quantum)
    @quantum = quantum
  end

  def load_ps(n_ps)
    ps = Queue.new MAX_N_PROCESSES
    n_ps.times do
      input = gets.chomp.split
      process = Process.new input[0], input[1].to_i
      ps.enq process
    end
    ps
  end

  def run(ps)
    elapsed_time = 0

    until ps.empty?
      process = ps.deq
      if process.time <= @quantum
        elapsed_time += process.time
        puts "#{process.name} #{elapsed_time}"
      else
        elapsed_time += @quantum
        process.time -= @quantum
        ps.enq process
      end
    end
  end
end

# Run processes.
n_ps, quantum = gets.split.map &:to_i
cpu = CPU.new(quantum)
cpu.run cpu.load_ps(n_ps)

Measured memory_bytes: 15072
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const ll INF = 1001001001;
int main() {
    int n;
    ll w,weight[110],value[110];
    vector<vector<ll>>dp(110,vector<ll>(100100));
    cin >> n >> w;
    rep(i,n) cin >> weight[i] >> value[i];
    rep(i,110)rep(j,100100)dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n)rep(sum_v,100100) {
        if(sum_v>=value[i]) chmin(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i]);
        chmin(dp[i+1][sum_v],dp[i][sum_v]);
    }

    ll res = 0;
    rep(sum_v,100100) {
        if(dp[n][sum_v]<=w) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 87296
import heapq
import math

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

b = []
for ai in a:
    heapq.heappush(b, ai* -1)
# print(b)

for i in range(m):
    tmp = math.ceil(heapq.heappop(b)/2)
    heapq.heappush(b, tmp)
    # print(b)

print(sum(b) * -1)

Measured memory_bytes: 92184
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}


int main(){
	int x, y;
	cin >> x >> y;
	if (y < 2*x || (y - 2*x)%2==1) {
		cout << "No";
		return 0;
	}
	// a + b = x;
	// 2*a + 4*b = y;
	// 2b = y - 2*x;
	int b = (y-2*x)/2;
	if (x - b >= 0){
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3632
/*  ex4-3
    Rikuta  */

#include <stdio.h>

//プロトタイプ宣言
int snow_height(int west_remain_height,int east_remain_height);

int main(void){

    int west_remain_height,east_remain_height;

    //入力受け取り
    scanf("%d %d",&west_remain_height,&east_remain_height);

    //snow_height関数に入れて計算
    int ans =snow_height(west_remain_height,east_remain_height);

    //答えの出力
    printf("%d\n",ans);

    return 0;
}

//関数の定義
int snow_height(int west_remain_height,int east_remain_height){
    //snow_heightの計算
    int snow_height=(east_remain_height-west_remain_height-1)*(east_remain_height-west_remain_height)/2-west_remain_height;

    //snow_heightを返す
    return snow_height;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, P;
int A[75];
int odd, even;

ll C[300][300];

void comb_table(int N, int mod)
{
    for (int i=0; i<=N; i++) {
        for (int j=0; j<=i; j++) {
            if (j == 0 or j == i) {
                C[i][j] = 1LL;
            } else {
                C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
            }
        }
    }
}

signed main()
{
    cin >> N >> P;
    REP(i,N) {
        cin >> A[i];
        if (A[i] % 2 == 0) even++;
        else odd++;
    }

    comb_table(100, 1e18);

    ll ans = 0;
    if (P == 0) {
        for (int i=0; i<=odd; i+=2) {
            ans += pow(2, even) * C[odd][i];
        }
    } else {
        for (int i=1; i<=odd; i+=2) {
            ans += pow(2, even) * C[odd][i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

A.sort()
if A[0] == 0:
    print(0)
else:
    answer = 1
    for a in A:
        answer *= a
        if answer > 10 ** 18:
            print(-1)
            exit()
    print(answer)

Measured memory_bytes: 84400
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n, k = rl()
    A = rl()

    def check(L):
        cuts = 0
        for a in A:
            cuts += (a - 1) // L
            if cuts > k:
                return False
        return True

    lo = 0
    hi = max(A)
    if k == 0:
        print (hi)
        return

    while lo < hi - 1:
        mid = (lo + hi) // 2
        if check(mid):
            hi = mid
        else:
            lo = mid

    print (hi)
    return








mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 106136
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    ll K;
    cin >> K;
    map<ll, ll> cnt;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        cnt[a] += b;
    }

    ll res = 0;
    for (auto p : cnt) {
        K -= p.second;
        if (K <= 0) {
            res = p.first;
            break;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 4224
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！


def BELLMANFORD(point,n,d):
    cost=[1e18]*(n+1)
    cost[point]=0
    for i in range(n-1):
        for (nownode,nextnode,c) in d:
            if cost[nextnode]>cost[nownode]+c:  #infが定数なので論理が逆
                cost[nextnode]=cost[nownode]+c
    for (nownode,nextnode,c) in d:
        if cost[nextnode]>cost[nownode]+c:
            if nextnode==n:
                return "inf"
            cost[nextnode]=cost[nownode]+c
            
    return -cost[n]


def main():
    n,m=map(int,input().split())
    
    d=[]
    for i in range(m):
        a,b,c=map(int,input().split())
        d.append((a,b,-c))
    
    print(BELLMANFORD(1,n,d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 41708
#!/usr/bin/env python3
import sys
#input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

a0 = inn()
a1 = inn()
a2 = inn()
a = a0+a1+a2
n = int(input())
ban = [0,0,0,0,0,0,0,0,0]
for i in range(n):
    b = int(input())
    for j in range(9):
        if b == a[j]:
            ban[j] = 1


for i in [0,1,2]:
    t = ban[i]+ban[i+3]+ban[i+6]
    if t == 3:
        print("Yes")
        exit()
for i in [0,3,6]:
    t = ban[i]+ban[i+1]+ban[i+2]
    if t == 3:
        print("Yes")
        exit()
if (ban[0]+ban[4]+ban[8]) == 3 or (ban[2]+ban[4]+ban[6]) == 3:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  ll a;
  double b;
  cin >> a >> b;
  int c = round(b * 100);
  cout << (a*c) / 100 << endl;
  return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
N, T = map(int, input().split())
A = list(map(int, input().split()))

pre = 10 ** 18
diff_max = 0
diff_cnt = 0

for a in A:
    if a < pre:
        pre = a
        continue

    if a - pre > diff_max:
        diff_max = a - pre
        diff_cnt = 1
    elif a - pre == diff_max:
        diff_cnt += 1

# 高橋君はdiffmax*(T//2)の利益
# 取引できるのがdiffcnt箇所、これをつぶす
print(diff_cnt)

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    ll n, k, q;
    cin >> n >> k >> q;

    vector<ll> a(q);

    rep(i, 0, q) cin >> a[i], a[i]--; 

    vector<ll> hash(n, 0);

    rep(l, 0, q)
        hash[a[l]]++; 

    //rep(l, 0, n)
    //    cout << hash[l] << endl;

    rep(i, 0, n)
    {
        if ((k - q + hash[i]) > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 2176
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LIR(n)
    r = [(x+y,x-y) for x,y in p]
    mx = [float("inf"),float("inf")]
    my = [float("inf"),float("inf")]
    Mx = [-float("inf"),float("inf")]
    My = [float("inf"),-float("inf")]
    for X,Y in r:
        if X < mx[0]:
            mx = [X,Y]
        if Y < my[1]:
            my = [X,Y]
        if Mx[0] < X:
            Mx = [X,Y]
        if My[1] < Y:
            My = [X,Y]
    ans = 0
    for X,Y in r:
        x = (X+Y)//2
        y = (X-Y)//2
        for A,B in (mx,my,Mx,My):
            a = (A+B)//2
            b = (A-B)//2
            d = abs(x-a)+abs(y-b)
            if ans < d:
                ans = d
    print(ans)
    return

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


Measured memory_bytes: 122516
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define Maxn 100010
using namespace std;
int n,a[Maxn],x,k;
int main()
{
    cin>>n;
    for (int i = 0; i < n; i++)
        cin>>a[i];
    
    x = abs(a[0]);

    for (int i = 1; i < n; i++)
        x = x + abs(a[i] - a[i-1]);

    x+=abs(a[n-1]);

    //cout<<x<<endl;

    for (int i = 0; i < n; i++)
    {
        k = x;
        if(i == 0)
        {
            k = abs(k - abs(a[i]) - abs(a[i+1] - a[i]));
            k += abs(a[i+1]);
        }
        else
        {
            k = abs(k - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) );
            k += abs(a[i+1] - a[i-1]);
        }
        cout<<k<<endl;
    }

    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    string s[10];
    s[2]= s[4] = s[5] = s[7] = s[9] = "hon";
    s[0]= s[1] = s[6] = s[8] = "pon";
    s[3]="bon";
    cout << s[n%10];
    
}

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

using namespace std;

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

const int MOD = 998244353;

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    char a;
    cin >> a;
    if (a >= 'a' & a <= 'z') {
        cout << "a\n";
    } else {
        cout << "A\n";
    }
    
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int N_tmp = N;
  int  fN = 0;

  while (N>0) {
    fN += N%10;
    N /= 10;
  }
  
  cout << ((N_tmp%fN==0) ? "Yes" : "No") << endl;


}

  
  

Measured memory_bytes: 256
import sys
import numpy as np
from numba import njit, void, i8

def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items))

@njit(i8(i8, i8, i8, i8[:]), cache=True)
def calc(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = c
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    dp[0, 1, 0] = dp[1, 0, 0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k])
                if k > 0:
                    dp[i, j, k] = max(dp[i, j, k], dp[i, j, k-1])
                    dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k-1] + cell[i-1, j-1])
                if k == 1:
                    dp[i, j, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3]

if __name__ == "__main__":
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    if __file__=="test.py":
        f = open("./in_out/input.txt", "r", encoding="utf-8")
        read = f.read
        readline = f.readline

    main()


Measured memory_bytes: 467664
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
typedef long long ll;

using namespace std;

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

    int a[30] = {0};
    for (int i = 0; i < w.size(); i++){
	int x = int(w[i]-'a');
	a[x]++;
    }

    for (int i = 0; i < 26; i++){
	if (a[i]%2 == 0) continue;

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

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, S[201000], X[201000];
long long res;
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		S[i] = S[i - 1] + a;
		X[i] = X[i - 1] ^ a;
	}
	int pv = 0;
	for (i = 1; i <= n; i++) {
		while (S[i] - S[pv] != (X[i] ^ X[pv]))pv++;
		res+=i - pv;
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 1792
#include <iostream>
#include <numeric>

int main() {
    std::string input;
    std::cin >> input;

    auto result = std::accumulate(input.begin(), input.end(), 0, [](int result, char i) {
        return i == '1' ? result + 1 : result;
    });
    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  
  integer :: n, p,i,j,t,s = 0,big = -1
  read(*,*)n
  do i = 1, n
    read(*,*)p
    if (big < p) then
      big = p
    end if
    s = s + p
  end do
  write(*,*)s-(big/2)
end program main

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

#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;

int A, B, C, D, E, F;

int main() {
   cin >> A >> B >> C >> D >> E >> F;

   set<int> water, sugar;
   for (int i = 0; i < 33; i++) {
      for (int j = 0; j < 33; j++) {
         int w = A*100*i + B*100*j;
         if (w <= F) water.insert(w);
      }
   }

   for (int i = 0; i < 3333; i++) {
      for (int j = 0; j < 3333; j++) {
         int s = C*i + D*j;
         if (s <= F) sugar.insert(s);
      }
   }

   const double lim = (double)E / (100+E);
   double noudo = -1;
   int ans1 = 0, ans2 = 0;
   for (int w : water) {
      for (int s : sugar) {
         int sum = w + s;
         if (sum == 0) continue;
         double x = (double)s / sum;
         if (sum <= F && x <= lim && x > noudo) {
            noudo = x;
            ans1 = sum, ans2 = s;
         }
      }
   }
   printf("%d %d\n", ans1, ans2);

   return 0;
}

Measured memory_bytes: 384
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		
		InputStream input = System.in;
		Scanner in = new Scanner(input);
		int[] allInt = new int[5];
		for(int i = 0;i<5;i++) {
			allInt[i] = Integer.parseInt(in.next());
		}
		int[] total = new int[5];
		
		for(int i = 0;i<5;i++) {
			total[i] = 0;
			for(int j = 0;j<5;j++) {
				
				if(i == j) {
					total[i] += allInt[j];
				}else {
					total[i] += allInt[j]/10*10;
					int tmp = allInt[j]%10 == 0 ? 0 : 10;
					total[i] += tmp;
				}
				
			}
			
		}
		Arrays.sort(total);
		
		System.out.println(total[0]);
		
		
	}
}
	
	

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define fora(i,a,b) for(int i = a ; i<b ;i++)
typedef long long ll;
typedef int i;
typedef vector<i>vi;
typedef pair<i,i>pi;
int M[100010][4];
int dp[100010][4];

int g(int i,int sw){
    if(i < 0) return 0;
    int &r = dp[i][sw];
    if(r!=-1) return r;

    if(sw == 0){
        r = max( g(i-1 , 1) , g(i-1,2) ) + M[i][0];
    }
    else{
        if(sw == 1){
            r = max( g(i-1 , 0) , g(i-1,2) ) + M[i][1];
        }else{
            r = max( g(i-1 , 0) , g(i-1,1) ) + M[i][2];
        }
    }
    return r;

}
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin>>n){
        memset(dp,-1,sizeof dp);
        fora(i,0,n){
            cin>>M[i][0]>>M[i][1]>>M[i][2];
        }

        int a = g(n-1,0);
        a = max(a , g(n-1,1));
        a = max(a , g(n-1,2));
        cout<<a<<"\n";
    }

    return 0;
}

Measured memory_bytes: 11412
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 200000;

int cnt[MAXN+5];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int N, K;
    LL ans = 0;

    cin >> N >> K;
    for (int i = 0; i < K; i++) {
        cnt[i] = N / K;
        if (i != 0) cnt[i] += N % K >= i;
    }

    for (int a = 1; a <= N; a++) {
        int b = (K - a % K) % K;
        if ((b + b) % K == 0) {
            ans += (LL)cnt[b] * cnt[b];
        }
        // cout << a << " " << b << " " << c << " " << (LL)cnt[b] * cnt[c] << "\n";
    }

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


Measured memory_bytes: 1024
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
use std::collections::BTreeSet;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let q: usize = sc.read();

    let mut event = vec![];
    for _ in 0..n {
        let s: i64 = sc.read();
        let t: i64 = sc.read();
        let x: i64 = sc.read();
        event.push((s - x, true, x));
        event.push((t - x, false, x));
    }

    event.sort();
    let mut cur = 0;
    let mut set = BTreeSet::new();
    for _ in 0..q {
        let d: i64 = sc.read();
        while cur < 2 * n && event[cur].0 <= d {
            if event[cur].1 {
                set.insert(event[cur].2);
            } else {
                set.remove(&event[cur].2);
            }
            cur += 1;
        }
        if let Some(v) = set.range(-1..).next() {
            println!("{}", v);
        } else {
            println!("-1");
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 14484
N,M,X=list(map(int,input().split()))
l=[]
ans=float("INF")
for i in range(N):
   l.append(list(map(int,input().split())))
for i in range(2**N):
   counter=[0]*M
   temp=0
   for j in range(N):
      if ((i >> j) & 1):
         for k in range(1,1+M):
            counter[k-1]+=l[j][k]
         temp+=l[j][0]
   B=len([a for a in counter if a > X-1])
   if B == M:
      ans=min(ans,temp)
if ans==float("INF"):
   print(-1)
else:
   print(ans)

Measured memory_bytes: 9232
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        // hour
        double a = in.nextInt();
        // minute
        double b = in.nextInt();
        double h = in.nextInt();
        double m = in.nextInt();

        double totalMins = h * 60 + m;
        double aRadians = totalMins / (12 * 60) * 2 * Math.PI;
        Map.Entry<Double, Double> aPoint = new AbstractMap.SimpleEntry<>(Math.cos(aRadians) * a, Math.sin(aRadians) * a);
        double bRadians = m / 60 * 2 * Math.PI;
        Map.Entry<Double, Double> bPoint = new AbstractMap.SimpleEntry<>(Math.cos(bRadians) * b, Math.sin(bRadians) * b);

        double diffX = aPoint.getKey() - bPoint.getKey();
        diffX *= diffX;
        double diffY = aPoint.getValue() - bPoint.getValue();
        diffY *= diffY;
        out.println(Math.sqrt(diffX + diffY));
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll h, w, n;
  cin >> h >> w >> n;

  cout << (n % max(h, w) == 0 ? n / max(h, w) : n / max(h, w) + 1) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    int time = 0;
    string X;
    int num;
   vector<string> s(55);
   vector<int> t(55);

   cin >> N;
   for(int i=0;i<N;i++){
      cin >> s[i] >> t[i];
      
   }
   cin >> X;

   for(int i=0;i<N;i++){
     
       if(s[i] == X){
           num = i;
           break;
   }
       }

   

   for(int i=num+1;i<N;i++){
       time += t[i];
   }

    cout << time;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);

int main(){
    ll a, b; cin>>a>>b;
    rep(i, max(a, b)){
        cout<<min(a, b);
    }
    cout<<endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*GRAPH_TEMPLATE=============================================*/
template<typename T>
class Edge {
public:
    int srch; //searched?探索状態記録「null = -1」
    int to; //辺の行き先
    T cost; //辺の重み
    Edge(int t, T w) : srch(-1), to(t), cost(w) {}
    Edge(int src, int t, T w) : srch(src), to(t), cost(w) {}
};
template<typename T>
using W_Graph = vector<vector<Edge<T>>>;   //重み付きグラフ
using Graph = vector<vector<int>>;         //通常グラフ
template<typename T>
using Matrix = vector<vector<T>>;          //隣接行列(使わなさそう...)

/*FUNCs=================================================*/
template<class T>
vector<T> Dijkstra(W_Graph<T> &G, int s) {
    const auto inf = numeric_limits<T>::max();
    vector<T> min_dist(G.size(), inf);

    using P = pair<T, int>; //pair<dist_from_starting_point, index_of_node>
    priority_queue<P, vector<P>, greater<P>> que;
    min_dist[s] = 0;
    que.emplace(min_dist[s], s);  //starting_point 

    while(!que.empty()) {
        T dist;
        int index;
        tie(dist, index) = que.top();
        que.pop();
        if(dist > min_dist[index]) continue;

        for(auto &edge : G[index]) {
            auto new_dist = dist + edge.cost;
            //compare the length of each route and chenge min_dist[edge.to]
            if(new_dist >= min_dist[edge.to]) continue;
            min_dist[edge.to] = new_dist;
            que.emplace(min_dist[edge.to], edge.to);
        }
    }
    return min_dist;
}

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    W_Graph<ll> g(n);
    rep(i,n-1) {
        int a,b,c; cin >>a>>b>>c;
        --a;--b;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }
    int q,k; cin >> q >> k;
    --k;
    vec<PII> xy(q);
    rep(i,q) {
        cin >> xy[i].first >> xy[i].second;
        --xy[i].first;
        --xy[i].second;
    }

    //dijkstraでｋからの距離を前計算
    vll dist = Dijkstra<ll>(g, k);

    //query
    rep(i,q) {
        int x, y;
        tie(x,y) = xy[i];
        cout << dist[x] + dist[y] << endl;
    }
}

Measured memory_bytes: 11888
#!/usr/bin/env python3
import sys
from operator import itemgetter
import bisect


def solve(N: int, M: int, A: "List[int]", BC):
    A.sort()
    BC.sort(key=itemgetter(1), reverse=True)
    idx = 0
    i = 0
    for i in range(M):
        B, C = BC[i]
        nidx = idx+B if idx+B < len(A) else len(A)
        if A[nidx-1] < C:
            for j in range(idx, nidx):
                A[j] = C
            idx += B
        else:
            for j in range(idx, nidx):
                if A[j] < C:
                    A[j] = C
            break

    ans = 0
    for a in A:
        ans += a
    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    BC = []
    for _ in range(M):
        BC.append(list(map(int, input().split())))
    solve(N, M, A, BC)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41440
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort(key=lambda x: x[0])
tilt_map = {}

if N == 1:
    print(1)
else:
    for i in range(N):
        for j in range(i+1, N):
            a = xy[i]
            b = xy[j]
            tilt_x = a[0] - b[0]
            tilt_y = a[1] - b[1]
            if tilt_x == 0 and tilt_y < 0:
                tilt_y *= -1
            key = str(tilt_x) + ":" + str(tilt_y)
            if key in tilt_map:
                tilt_map[key] += 1
            else:
                tilt_map[key] = 1


    most_tilt = sorted(tilt_map.items(), key=lambda x: x[1], reverse=True)[0][1]
    print(N-most_tilt)

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

ll find(ll i,vector<ll> arr,vector<ll> profit,ll w){

  if(i<0||w<=0)return 0;
  if(mp[i][w]!=-1)return mp[i][w];
  if(arr[i]>w){
  	return mp[i][w]=find(i-1,arr,profit,w);
  }else{
  	return mp[i][w]=max(find(i-1,arr,profit,w-arr[i])+profit[i],find(i-1,arr,profit,w));
  }
  
  
}

int main(){

  ll n,w;
  cin>>n>>w;
  mp.clear();
  mp.resize(101,vector<ll>(100001,-1));
  vector<ll> arr(n),profit(n);
  for(int i=0;i<n;i++)
    cin>>arr[i],cin>>profit[i];
  cout<<find(n-1,arr,profit,w<100001?w:100000)<<endl;
  return 0;
  
}


Measured memory_bytes: 83264
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
out = 'U'*dy + 'R'*dx + 'D'*dy + 'L'*dx + 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D' + 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'
print(out)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll I,O,T,J,L,S,Z;
    cin>>I>>O>>T>>J>>L>>S>>Z;
    ll ans=O;

    if(I%2){
        if(L>0 and J>0 and I>0 and (L%2==1 or J%2==1)){
            ans+=3;
            L--;J--;
            I--;
        }
        ans+=2*(L/2);
        L-=2*(L/2);
        
        ans+=2*(J/2);
        J-=2*(J/2);
        
        ans+=2*(I/2);
        cout<<ans<<endl;
    }else{
        if(L>0 and J>0 and I>0 and L%2==1 and J%2==1){
            ans+=3;
            L--;J--;
            I--;
        }
        ans+=2*(I/2);
        ans+=2*(L/2);
        ans+=2*(J/2);
        cout<<ans<<endl;
    }
    return 0;
}



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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1)
    cout << 1 << endl;
  else
    cout << (H * W + 1) / 2 << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
n, d = map(int,input().split())
point = []
ans = 0
for i in range(n):
    point.append(list(map(int,input().split())))
for i in range(n+1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (point[i][k] - point[j][k])**2
        ans_dist = dist ** 0.5
        int_ans_dist = int(ans_dist)
        if ans_dist == int_ans_dist:
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    long long int a,b,c,d,lcm,t;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    int C=c;
    int D=d;
    while(C!=0&&D!=0){
        lcm=D;
        D=C%D;
        C=lcm;
    }
    lcm=c*d/lcm;
    t=b/c+b/d-b/lcm-(a-1)/c-(a-1)/d+(a-1)/lcm;
    printf("%lld\n",b-a+1-t);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
const ll INF = 1LL << 60;
const double PI = acos(-1.0);



int main() {
	string s;
	cin >> s;
	map<char, bool> dir;
	dir['N'] = false;
	dir['S'] = false;
	dir['E'] = false;
	dir['W'] = false;

	for (int i = 0; i < s.size(); i++) {
		dir[s[i]] = true;
	}

	cout << ((!(dir['N'] ^ dir['S']) && !(dir['E'] ^ dir['W'])) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int main(){
	int n;
	cin>>n;
	bool flag=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a%2==0&&a%3&&a%5)flag=1;
	}
	if(flag)cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl; 
	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
//const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[100001];

LL ans = -1;

void solve(){
	if(N==0){
		if(A[0]==1) ans = 1;
		return;
	}
	//深さiの、それぞれ考えられるノードの数の
	//最小値と最大値
	vector<LL> min_node(N+1);
	vector<LL> max_node(N+1);
	min_node[N] = A[N];
	max_node[N] = A[N];
	// for(int i=N-1;i>=0;i--){
	// 	min_node[i] = max(1LL + A[i],(min_node[i+1]+1LL)/2LL + A[i]);
	// 	max_node[i] = min(max_node[i+1] + A[i],1LL<<i);
	// 	if(min_node[i]>max_node[i]) return;
	// }
	for(int i=N-1;i>=0;i--){
		min_node[i] = (min_node[i+1]+1LL)/2LL + A[i];
		max_node[i] = max_node[i+1] + A[i];
	}
	if(min_node[0]>1) return;

	// for(int i=0;i<=N;i++){
	// 	printf("depth=%d:[%lld,%lld]\n",i,min_node[i],max_node[i]);
	// }

	LL allof_nodes = 1;
	LL prev_nodes = 1;
	for(int i=1;i<=N;i++){
		LL enable_nodes = (prev_nodes-A[i-1])*2LL;
		LL used_nodes = min(max_node[i],enable_nodes);
		//printf("d=%d:%lld\n",i,used_nodes);
		if(used_nodes<min_node[i]) return;
		allof_nodes += used_nodes;
		prev_nodes = used_nodes;
	}
	ans = allof_nodes;
}

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

    solve();

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

Measured memory_bytes: 5256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;
vvl a;
vl b,dp;

int main(){
	cin>>n;
	a=vvl(n,vl(n));
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	ll N=1<<n;
	b=vl(N);
	dp=vl(N,-INF);
	dp[0]=0;
	for(int i=0;i<N;i++) for(int j=0;j<n;j++) for(int k=0;k<j;k++) if(i&1<<j&&i&1<<k) b[i]+=a[j][k];
	for(int i=1;i<N;i++){
		int T=i;
		do{
			dp[i]=max(dp[i],dp[i-T]+b[T]);
			T=(T-1)&i;
		}while(T!=i);
	}
	cout<<dp[N-1]<<endl;
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
  int n;
  cin >> n;
  int a[n];
  REP(i,n) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i < n-1; i++) {
    if (a[i-1] < a[i] && a[i] < a[i+1]) {
      ans++;
    } else if (a[i-1] > a[i] && a[i] > a[i+1]) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main(int argc, char *argv[]){

  /* Regular */
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  
  // /* AOJ */
  // solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,n1,n2,A[100][100],j,d,i;

  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      A[i][j]=0;
    }
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&n1,&n2);
    for(j=0;j<n2;j++){
      scanf("%d",&d);
      A[i][d-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",A[i][j]);
      if(j != n-1) printf(" ");
      }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 644
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0 ;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

int prim() {
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for( int i = 0; i <n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1) {
  minv = INFTY;
  u = -1;
  for(int i = 0; i < n; i++){
    if(minv > d[i] && color[i] != BLACK){
      u = i;
      minv = d[i];
    }
  }
  if( u == -1)break;
  color[u] = BLACK;
  for( int v = 0; v < n; v++){
    if(color[v] != BLACK && M[u][v] != INFTY){
      if(d[v] > M[u][v]){
        d[v] = M[u][v];
        p[v] = u;
        color[v] = GRAY;
      }
    }
  }
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
  if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  cin >> n;

  for( int i = 0; i < n; i++){
    for(int j = 0; j <n;j++){
      int e; cin >>e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}

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

int main(){
string ma;
string sub;
cin>>ma>>sub;
ma=ma+ma;
int n=sub.size();
int a[100]={};
for(int i=0;i<(int)ma.size();i++){
if(ma[i]==sub[0]){
a[0]=1;
for(int g=1;g<n;g++){
if(ma[i+g]==sub[g]){a[g]=1; continue;}
for(int h=1;h<g;h++){a[h]=0;}
break;
}
if(a[n-1]==1){a[n]=1;}
}}
if(a[n]==0){cout<<"No"<<endl;}
else{cout<<"Yes"<<endl;}

return 0;
}


Measured memory_bytes: 3152
while True:
    v = map(int,raw_input().split())
    if v[0] == -1 and v[1] == -1 and v[2] == -1:
        break
    if v[0] * v[1] < 0:
        print 'F'
    else:
        s = v[0] + v[1]
        if s >= 80:
            print 'A'
        elif s >= 65:
            print 'B'
        elif s >= 50:
            print 'C'
        elif s >= 30:
            if v[2] >= 50:
                print 'C'
            else:
                print 'D'
        else:
            print 'F'

Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
        long long a1=0,b1=0;
        a1=a*b;
        b1=c*d;
        if(a1>=b1)
        {
            cout<<a1<<endl;
        }
        else
        {
            cout<<b1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
a=v[:A]
b=v[:B]
avg=sum(a)/A
print(avg)
c=[[0]*51 for _ in range(51)]
c[0][0]=1
for i in range(50):
  c[i+1][0]=1
  c[i+1][i+1]=1
  for j in range(i):
    c[i+1][j+1]=c[i][j]+c[i][j+1]
if a[0]==a[-1]:
  ans=0
  x=v.count(a[0])
  for i in range(A,B+1):
    if i<=x:
      ans+=c[x][i]
else:
  x=v.count(a[-1])
  y=a.count(a[-1])
  ans=c[x][y]
print(ans)

Measured memory_bytes: 9156
#include<bits/stdc++.h>
#define maxn 123456

using namespace std;
int n,s,a[maxn];

int main(){
    cin >> n >> s;
    for (int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int ans=0;
    for (int i=0;i<n;i++) if (s>=a[i]) ans++,s-=a[i];
    if (s&&ans==n) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 764