akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

	vector<vector<int>> asc( 26 );
	s += s;
	int n = s.size();
	for( int i = 0; i < n; i++ ) {
		int a = s[i] - 'a';
		asc[a].push_back( i + 1 );
	}
	vector<int> cnt( 26 );
	int nn = t.size();
	int j = -1;
	long long mul = 0;
	long long ans;
	for( int i = 0; i < nn; i++ ) {
		int a = t[i] - 'a';
		if( asc[a].size() == 0 ) {
			ans = -1;
			break;
		}
		if( j < 0 ) {
			j = asc[a][0];
		}
		else {
			auto it = upper_bound( asc[a].begin(), asc[a].end(), j );
			if( it == asc[a].end() ) {
				if( j >= n / 2 ) {
					mul++;
					j = asc[a][0];
				}
				else {
					ans = -1;
					break;
				}
			}
			else {
				j = *it;
			}
		}
		ans = mul * n + j;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1788
# -*- coding: utf-8 -*-

"""
参考：https://pitsbuffersolution.com/compro/atcoder/arc089d.php
　　　http://tutuz.hateblo.jp/entry/2018/06/20/212752
　　　https://paiza.hatenablog.com/entry/2014/05/28/%E3%82%82%E3%81%97%E5%A5%B3%E5%AD%90%E5%A4%A7%E7%94%9F%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9E%E3%81%AB%E3%80%8E%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0%E3%80%8F%E3%82%92%E5%9B%B3
　　　http://www.learning-algorithms.com/entry/2018/01/31/144519
　　　https://img.atcoder.jp/arc089/editorial.pdf
・2次元累積和
・0-indexedのまま行くか1-indexedにするか人によって色々で、
　それぞれに考慮する点があると思った。
・練習のために今度は0-indexedでやってみる。
"""

import sys
def input(): return sys.stdin.readline().strip()

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

# K*2の正方形を右下まで動かすので、K*4まで作っておく
B = [[0] * (K*4) for i in range(K*4)]
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    # 白に塗る条件はxかyにKずらして黒の条件にする(これで2色考えなくていい)
    if c == 'W':
        y += K
    # 循環するのでmod K*2でやる
    B[x%(K*2)][y%(K*2)] += 1

for i in range(K*4):
    for j in range(K*4):
        # K*2からはみ出る範囲も正しく累積和を出すため、K*2までの値を循環させる
        # 0-indexedなのでここはシンプル
        B[i][j] = B[i%(K*2)][j%(K*2)]

# 2次元累積和を取る
# 0-indexedなので、i, jがマイナスになる場合を考慮
for i in range(K*4):
    for j in range(K*4):
        if j > 0:
            B[i][j] += B[i][j-1]
for i in range(K*4):
    for j in range(K*4):
        if i > 0:
            B[i][j] += B[i-1][j]

# 2次元累積和に必要な4点の加減を行う
def get_sum(x1, y1, x2, y2, sm):
    # 右下は必ず足す
    res = sm[x2][y2]
    # 左下を引く
    if x1 > 0:
        res -= sm[x1-1][y2]
    # 右上を引く
    if y1 > 0:
        res -= sm[x2][y1-1]
    # 左上を足す
    if x1 > 0 and y1 > 0:
        res += sm[x1-1][y1-1]
    return res

ans = 0
for i in range(K*2):
    for j in range(K*2):
        # 1つ目の正方形
        tmp = get_sum(i, j, i+K-1, j+K-1, B)
        # 2つ目の正方形
        tmp += get_sum(i+K, j+K, i+K*2-1, j+K*2-1, B)
        ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 165852
n = int(input())
s = []
for i in range(n):
  text = ''.join(sorted(input()))
  s.append(text)

count = {}
for i in s:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1

sum = 0
for v in count.values():
  int(v)
  sum += (v*(v-1)//2)

print(sum)


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

#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;


int main(int argc, char const *argv[]){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c-(a-b)) << endl;
    return 0;
}

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

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

    //int a, b; //検討するべき変数はココ！なのでここを全探索する
    //a = 4 * x - y;
    //b = -2 * x + y;
	//下
    for(int turu = 0; turu < 101; turu++){
        for(int kame = 0; kame < 101; kame++) {
            if (2 * turu + 4 * kame == y && turu + kame == x) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

  	//cout << a << ' ' << b << endl;
    //if(a > 0 && b > 0) {
    //  cout << "Yes" << endl;
    //} else {
    //  cout << "No" << endl;
    //}
    return 0;
}

Measured memory_bytes: 3644
h, w = map(int, input().split())
if min(h, w) == 1:
    print(1)
    exit()
if h % 2 == 0 or w % 2 == 0:
    print(h * w // 2)
else:
    a = max(h, w)
    print(min(h, w) * (a // 2) + min(h, w)//2+1)

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

int main() {
	int n, a, b;
	int res = 0;
	cin >> n >> a >> b;



	for (int i = n; i >= 0; i--) {

		string st = to_string(i);
		int nl = st.length();

		int sum = 0;
		for (int j = 0; j<nl; j++) sum += st[j]-48;
		if (sum >= a && sum <= b)res += i;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;

    cin >> N;
    vector<long long> m(N, -1);
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        m[t-1] = i;
    }

    long long i = 0;
    long long max_count = 1;
    while (i < N - 1)
    {
        long long count = 1;
        while (i < N - 1 && m[i] < m[i + 1])
        {
            count++;
            i++;
        }
        max_count = max(max_count, count);
        i++;
    }

    cout << N - max_count << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std;
int main()
{
	char c;
	cin >> c;
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')
		cout << "vowel" << endl;
	else{
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll N, K; cin >> N >> K;
    vll x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];
    vector<pair<ll, ll>> horiz(N), vert(N);
    rep(i, N) horiz[i] = {x[i], y[i]}, vert[i] = {y[i], x[i]};
    sort(all(horiz)), sort(all(vert));
    rep(i, N) swap(vert[i].first, vert[i].second);

    ll minn = inf;
    for (ll l=0; l<N-1; l++) {
        for (ll r=l+1; r<N; r++) {
            ll left = horiz[l].first;
            ll right = horiz[r].first;
            for (ll b=0; b<N-1; b++) {
                if (!(vert[b].first >= left && vert[b].first <= right)) continue;
                for (ll t=b+1; t<N; t++) {
                    if (!(vert[t].first >= left && vert[t].first <= right)) continue;
                    ll bottom = vert[b].second;
                    ll top = vert[t].second;
                    ll count = 0;
                    rep(i, N) {
                        if (
                            left <= x[i] && x[i] <= right &&
                            bottom <= y[i] && y[i] <= top
                        ) count++;
                    }

                    if (count >= K) minn = min(minn, abs(top - bottom) * abs(right - left));
                }
            }
        }
    }
    cout << minn << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int p[200001];
    rep(i,n) cin >> p[i];
    int ans = n;
    
    int j = p[0];
    rep(i,n){
        if(p[i] > j) ans--;
        if(j > p[i]) j = p[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL a, b, c; cin >> a >> b >> c;
		if (a < c && c < b) cout << "Yes" << endl;
		else if (b < c && c < a) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

import sys

if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    sys.exit()


ANSLIST=[]


ANS=0
x=2
while ANS<=10**5:
   ANS= (1+x)*x//2
   ANSLIST.append(ANS)
   x+=1

if N in ANSLIST:
    print("Yes")
    x=ANSLIST.index(N)+2

    print(x+1)
    ANS=[[] for i in range(x+1)]


    LIST=[]
    y=1
    z=x
    while z>=0:
        LIST.append(y)
        y+=z
        z-=1

    #print(LIST)

    for j in range(x):
        for k in range(x-j):
            ANS[j].append(LIST[j]+k)
            ANS[j+k+1].append(LIST[j]+k)

    for i in range(x+1):
        print(x,end=" ")
        for j in range(x):
            print(ANS[i][j],end=" ")
        print()


else:
    print("No")


Measured memory_bytes: 53464
X,Y = map(int,input().split())

res = 0

if X == 1:
    res += 300000
elif X == 2:
    res += 200000
elif X == 3:
    res += 100000

if Y == 1:
    res += 300000
elif Y == 2:
    res += 200000
elif Y == 3:
    res += 100000

if (X == 1) & (Y == 1):
    res += 400000

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    map<char, long long> m;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        m[S[0]]++;
    }
    string S = "MARCH";
    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            for (int k = j+1; k < 5; k++) {
                ans += m[S[i]]*m[S[j]]*m[S[k]];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    static i64 MOD;
    i64 a;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y;
        y.a=n;
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>=MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
int_fast64_t modint::MOD=0;
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    modint a{};
    in>>n>>modint::MOD;
    vector<vector<modint>> dp(3*n+1,vector<modint>(n+1));
    dp[3*n][0]=1;
    iFr(i,3*n) fr(j,n+1){
            dp[i-1][j]+=dp[i][j];
            if(j<n){
                if(i>1) dp[i-2][j+1]+=dp[i][j]*(i-1);
                if(i>2) dp[i-3][j+1]+=dp[i][j]*(i-1)*(i-2);
            }
        }
    modint ans{};
    fr(j,n+1) ans+=dp[0][j];
    cout<<ans<<endl;

}


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

using namespace std;

using ll = long long;

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

  int n;
  cin >> n;

  vector<int> h(n), dp(n, int(1e9));
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }

  dp[0] = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (i + 2 < n) {
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
  }

  cout << dp[n - 1] << '\n';

  return 0;
}


Measured memory_bytes: 1024
n,m,q = list(map(int,input().split()))
abcd =  [list(map(int,input().split())) for i in range(q)]
 
 
def dfs(x,y,z,que):
    ret = 0
    if x == 0:
        for a,b,c,d in abcd:
            if que[b-1] - que[a-1]==c:
                ret+=d
        return ret
    for i in range(y,z+1):
        ret = max(ret,dfs(x-1,i,z,que + [i]))
    return ret
 
print(dfs(n,1,m,[]))

Measured memory_bytes: 9168
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k, c;
    cin >> n >> k >> c;
    string s; cin >> s;
    vector<int> ls, rs;
    for(int i = 0; i < n; i++){
        if(s[i] == 'o'){
            ls.push_back(i);
            i += c;
        }
    }
    printde(ls);
    if((int)ls.size() > k){
        return 0;
    }
    for(int i = n - 1; i >= 0; i--){
        if(s[i] == 'o'){
            rs.push_back(i);
            i -= c;
        }
    }
    sort(rs.begin(), rs.end());
    printde(rs);
    for(size_t i = 0; i < ls.size(); i++){
        if(ls[i] == rs[i]){
            cout << ls[i] + 1 << '\n';
        }
    }
}


Measured memory_bytes: 3444
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;
char maze[1001][1001];
int d[1001][1001];
bool pre[1001][1001];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;


int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, N, Y, Z, K;
	cin >> N;
	char s[11];
	ll ans = 0;
	ll A, B, AB;
	A = B = AB = 0;
	REP(i, 0, N) {
		cin >> s;
		REP(j, 0, strlen(s) - 1) {
			if (s[j] == 'A'&&s[j + 1] == 'B') {
				ans++;
			}
		}

		if (s[0] == 'B'&&s[strlen(s) - 1] == 'A') {
			AB++;
		}
		else if (s[0] == 'B') {
			B++;
		}
		else if (s[strlen(s) - 1] == 'A') {
			A++;
		}


	}
  ans+=fmin(A,B)+AB;
  if(A+B==0&&AB>0)
    ans--;
  output(ans);
	return 0;
}








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

using namespace std;
int main()
{
   int n,a[10000];
   cin>>n;
   for (int i = 0; i < n; i++) cin>>a[i];
   sort(a,a+n);
   cout<<a[n-1]-a[0];

   return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
k = m//n
ans = 1
i = 1
while i**2 <= m:
	if m%i==0:
		j = m//i
		if j <= k:
			print(j);exit()
		if i <= k:
			ans = max(ans,i)
	i += 1
print(ans) 


Measured memory_bytes: 2940
import Control.Monad (replicateM)
 
main :: IO ()
main = do
  [n,m] <- map (read :: String -> Int) . words <$> getLine
  am <- map (read :: String -> Int) <$> getNLine_ m
  print $ ans am n

ans :: [Int] -> Int -> Int
ans am n = (\(a,b,c) -> a) $ foldl func (0,1,1) (am ++ [n+1]) where
  func (a,b,k) l
    | k == l = (b,0,k+1)
    | otherwise = func (b,(a+b) `mod` (10^9+7),k+1) l

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine


Measured memory_bytes: 36220
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func Sqrt(x int) int {
	return int(math.Sqrt(float64(x)))
}

func Min(x ...int) int {
	min := x[0]
	for _, v := range x {
		if v < min {
			min = v
		}
	}
	return min
}

func main() {
	n := nextInt()

	a := []int{}
	for i:= 1; i<=Sqrt(n); i++ {
		if n % i == 0 {
			x := n/i
			a=append(a, (i - 1) + (x-1))
		}
	}
	fmt.Printf("%d", Min(a...))
	return
}


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

using namespace std;
using ll = long long int;

int main()
{
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  ll count = 0;
  for(int i = 0; i <= n; i++)
  {
    for(int j = 0; j <= n; j++)
    {
      int bz = n - r * i - g * j;
      if(bz % b != 0) continue;
      if(bz / b >= 0){
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 384
using System;

class Program
{
  static void Main(string[] args)
  {
    char[] cs = Console.ReadLine().ToCharArray();
    for (int i = 0; i < cs.Length; i++)
    {
      if (i % 2 == 0)
      {
        Console.Write(cs[i]);
      }
    }
    Console.WriteLine();
  }
}


Measured memory_bytes: 26064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    vector<char> S(N); rep(i, N) cin >> S[i];
    vector<int> count_B(N);
    int count = 0;
    rep(i, N) {
        if (S[i] == '#')  count ++;
        count_B[i] = count;
    }

    int ans = min(count_B[N - 1], N - count_B[N - 1]);

    rep(i, N - 1) {
        ans = min(ans, 2 * count_B[i] + N - 1 - i - count_B[N - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;

inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}


int main() {
	int N, D; cin >> N >> D;
	cout << ceileing(N, 2 * D + 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[N + 10];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll cnt0_mod4 = 0;
	ll cnt0_mod2 = 0;
  	ll cnt2_mod4 = 0;
	for (ll i = 0; i < N; i++) {
		if (a[i] % 4 == 0)
			cnt0_mod4++;
		if (a[i] % 2 == 0)
			cnt0_mod2++;
      	if(a[i]%4 == 2)
           cnt2_mod4++;
	}
	if (cnt0_mod2 == N)
      	cout<<"Yes"<<endl;
  	else if(cnt0_mod4+(cnt2_mod4)/2>=N/2)
      cout<<"Yes"<<endl;
	else
		cout << "No" << endl;
	}








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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int count = 0;

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

    while (1)
    {
        bool exist_add = false;
        for (auto &&i : A)
        {
            if (i % 2 == 1)
            {
                exist_add = true;
            }
        }

        if (exist_add)
            break;

        for (auto &&i : A)
        {
            i /= 2;
        }

        count += 1;
    }

    cout << count << endl;
}


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

int main(){
  int H, W, K; std::cin >> H >> W >> K;

  std::vector<std::string> s(H);
  for(int i = 0; i < H; ++i) std::cin >> s[i];

  int B = 0;
  for(int i = 0; i < H; ++i) B += std::count(s[i].begin(), s[i].end(), '#');


  int ans = 0;

  for(int i = 0; i < (1 << H); ++i){
    for(int j = 0; j < (1 << W); ++j){

      int c = B;
      
      for(int x = 0; x < H; ++x){
        for(int y = 0; y < W; ++y){
          if((i & (1 << x)) or (j & (1 << y))){
            if(s[x][y] == '#') --c;
          }
        }
      }

      if(c == K) ++ans;
    }
  }

  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 303, mo = 998244353, inv2 =(mo+1)/2;
const ll MOD=7LL*mo*mo;
inline void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
inline void sub(int &x, int y){x=x-y>=0?x-y:x-y+mo;}
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}
int b[N],n,k,len,f[N][N],pos[N],g[N][N],h[N][N];char s[N];
int main() {
	scanf("%s",s+1);len=strlen(s+1);read(k);
	int gs=0,cur=1;rep(i,1,len){
		if(s[i]=='0')cur++;else b[cur]++,pos[++gs]=cur;
	}
	//rep(i,1,cur)cerr<<b[i];cerr<<endl;
	int res=0,cnt1=0;rep(i,1,len)cnt1+=s[i]=='1';
	f[0][0]=1;
	rep(i,1,cur){
		static int dp[N][N];memcpy(dp,f,sizeof(f));
		memset(g,0,sizeof(g));
		memset(h,0,sizeof(h));
		rep(j,0,len)rep(k,0,len){
			g[j][k]=h[j][k]=dp[j][k];
			add(g[j][k],j&&k?g[j-1][k-1]:0),
			add(h[j][k],j?h[j-1][k]:0);
		}
		rep(j,0,len)if(pos[j]>=i){
			int lim=j;while(pos[j-lim+1]<i)lim--;
			rep(k,0,len){
				//rep(c,1,b[i]-1)if(j>=c&&k>=c&&c<=lim)add(f[j][k],dp[j-c][k-c]);//i<=pos[j-c+1]
				int tmp=min({b[i]-1,j,k,lim});
				if(1<=tmp)add(f[j][k],(g[j-1][k-1]-(j>=tmp+1&&k>=tmp+1?g[j-tmp-1][k-tmp-1]:0)+mo)%mo);
				//rep(c,max(b[i],1),len)if(j-c>=0&&k-b[i]>=0&&c<=lim)add(f[j][k],dp[j-c][k-b[i]]);
				if(max(b[i],1)<=min(lim,j)&&k-b[i]>=0&&j-max(b[i],1)>=0)
					add(f[j][k],(h[j-max(b[i],1)][k-b[i]]-(j-min(lim,j)-1>=0?h[j-min(lim,j)-1][k-b[i]]:0)+mo)%mo);
			}
		}
	}
	rep(i,0,len)if(cnt1-i<=k)add(res,f[cnt1][i]);cout<<res;
	return 0;
}


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

#define eb emplace_back
#define pb push_back
#define INF 1LL<<62
#define FLT_INF pow(10.0, 16)


using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A& v);
string to_string(const string& s) { return '"'+ s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C> string to_string(const tuple<A, B, C>& p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +  ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void reverse(vector<T>& val) {
  reverse(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T>
T pair_sum(pair<T, T>& val) {
  return val.first + val.second;
}


template <typename T>
T min(T a, T b, T c) {
  return min(min(a, b), c);
}

template <typename T>
T max(T a, T b, T c) {
  return max(max(a, b), c);
}


template <typename T>
T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

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

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

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \n", cur_n, m / 2 + 1);
*/

class mytask {
public:
  mytask() { }

  int solve() {

  string s;
  cin >> s;
  ll res = 0;
  ll i = 0;
  char last_char = ' ';
  while (i < s.size()) {
    if (last_char == s[i]) {
      last_char = ' ';
      if (i != s.size() - 1) {
        res+=1;
      }
      i+=2;
    } else {
      last_char = s[i];
      res+=1;
      i++;
    }
  }
  cout << res;


  return 0;

  }



};


int main() {

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

  auto task = mytask();
  task.solve();

  cout << endl;

  return 0;
}


Measured memory_bytes: 720
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

y=list(input())
for i in range(len(y)):
    if y[i]=="?":
        y[i]="D"

print("".join(y))

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

int main(){
  char s[2];

  scanf("%s", s);
  if(s[0] == 'a' || s[0] == 'i' || s[0] == 'u' || s[0] == 'e' || s[0] == 'o') printf("vowel\n");

  else printf("consonant\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());



signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s; cin >> s;
  int ans = INT_MAX;
  int n = s.size();
  int now = 0;
  rep(i, n) {
    if (i&1) {
      if (s[i] == '0') now++;
    } else {
      if (s[i] == '1') now++;
    }
  }
  chmin(ans, now);
  now = 0;
  rep(i, n) {
    if (i&1) {
      if (s[i] == '1') now++;
    } else {
      if (s[i] == '0') now++;
    }
  }
  chmin(ans, now);
  cout << ans << endl;
}


Measured memory_bytes: 512
n = int(input())
a = input()
al = len(a)

l = 0
r = al-1
cnt = 0
#print(a,al,l,r)
while True:
    if l >= r:
        break
    if a[l] == 'R':
        l += 1
        continue
    
    if a[r] == 'W':
        r += -1
        continue
    l += 1
    r += -1
    cnt += 1
    
print(cnt)

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


ac=0
wc=0
tc=0
rc=0

for i in range(N):
    s=input()

    if "AC"==s:
        ac+=1
    elif "WA"==s:
        wc+=1
    elif "TLE"==s:
        tc+=1
    elif "RE"==s:
        rc+=1

print("AC x "+str(ac))
print("WA x "+str(wc))
print("TLE x "+str(tc))
print("RE x "+str(rc))


Measured memory_bytes: 9200
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
//typedef pair<int,int>P;
#define INF 1000000009

typedef struct D{int s,e;}D;//(s,e]

int N,M,P,Q,R,x,y,res;

void Smov(stack<D> &s,stack<D> &d,int len)
{
	for(int c=0;c<len&&!s.empty();)
	{
		D now=s.top();s.pop();
		if(c+(now.e-now.s)>len)
		{
			D rev={now.s+(len-c),now.e};
			now.e=now.s+(len-c);
			s.push(rev);
		}
		c+=(now.e-now.s);
		d.push(now);
	}
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		stack<D>q,A,B,C;
		D tmp={1,N+1};
		q.push(tmp);
		scanf("%d%d%d%d",&M,&P,&Q,&R);
		for(int i=0;i<M;i++)
		{
			scanf("%d%d",&x,&y);
			Smov(q,A,x);
			Smov(q,B,y-x);
			Smov(q,C,INF);
			Smov(A,q,INF);
			Smov(B,q,INF);
			Smov(C,q,INF);
		}
		P--;Q--;res=0;
		for(int i=0;i<=Q;)
		{
			D tmp=q.top();q.pop();
			int len=tmp.e-tmp.s;
			if(i+len<P||i>Q)
			{
			}
			else
			{
				int s=i>P?tmp.s:tmp.s+(P-i);
				int e=i+len<Q?tmp.e-1:tmp.s+(Q-i);
				if(s<=R)
					res+=min(R,e)-s+1;
			}
			i+=len;
			
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1272
//18, 08, 2018, 09:03:53 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b;

    scanf("%d %d", &a, &b);

    int have = a + b - 1;

    printf("%d\n", a * b - have);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;

int count(int a,int c){
    if(a%2==0)
    return count(a/2,c+1);
    else
    return c;
}

int main(){
  int n; cin>>n;
  int num=1;
  int c=0;
  for(int i=1;i<=n;i++){
    if(i%2==0){
      int d=count(i,0);
      if(d>c){
        num=i;
        c=d;
      }
    }
  }
  cout<<num<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    long double a, b, x;
    cin >> a >> b >> x;
    
    long double V = a * a * b;
    long double ans;
    long double PI=3.14159265358979323846;

    if(V / 2 >= x){
        ans = atan((2.0 * x) / (a * b * b));

        ans = 90.0 - ans * (180.0 / PI);

        printf("%.16Lf\n", ans);
    }
    else{
        ans = atan((2.0 * (V - x)) / (a * a * a));

        ans = ans * (180.0 / PI);

        printf("%.16Lf\n", ans);
    }    



    return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{   
    int ans = 0;
    int n,d,x;
    cin >> n >> d >> x;
    v_int a(n+1);

    irep(i,n) {
        cin >> a[i+1];
    }
    
    irep2(i,1,n+1) {
        int day = 1;
        while(day <= d) {
            ans++;
            day += a[i];
        }

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



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

#define ll long long
#define N 100001
#define MX 1000000001
#define logg(a)(b) log(b)/log(a)
#define pb(x) push_back(x);
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define pi acos(-1)
#define flag bool fl=true;
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);

int main()
{

 ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll res1 = 0;
    res1 += min(a, k);
    k -= min(a, k);

    if (k == 0) {
        cout << res1 << endl;

    }
    else{
    k -= min(b, k);
    if (k == 0) {
        cout << res1 << endl;
    }
    else{

    res1 -= min(c, k);
    k -= min(c, k);
    cout << res1 << endl;
    }
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (ll i = (n); i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define FORR(i, m, n) for (ll i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  vector<ll> c(n, 0);
  FOR(i, 1, n) {
    c[i] = modpow(i, mod - 2);
    c[i] = (c[i] + c[i - 1]) % mod;
  }
  
  ll ans = 0;
  FOR(i, 1, n) {
    ll res = x[i] - x[i - 1];
    res = (res * c[i]) % mod;
    ans = (ans + res) % mod;
  }
  FOR(i, 1, n) {
    ans = (ans * i) % mod;
  }
  cout << ans << endl;






  
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    double n, k; cin >> n >> k;
    double ans = 0.0;
    for (int i = 1; i <= n; i++) {
        double tmp = 1.0/n;
        int now = i;
        while (now < k) {
            now *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
int main()
{
	int a, b;
	cin >> a >> b;
	if (b%a) cout << b - a << endl;
	else cout << a + b << endl;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))

cnt_arr = [dict() for _ in range(2)]

for i in range(n):
    cnt_arr[i % 2][v[i]] = cnt_arr[i % 2].get(v[i], 0) + 1

v_even = sorted(list(cnt_arr[0].items()), key=lambda x: x[1], reverse=True)[:2]  # [value, 出現数] * 2（上位2）
v_odd = sorted(list(cnt_arr[1].items()), key=lambda x: x[1], reverse=True)[:2]  # [value, 出現数] * 2（上位2）

keep = 0
flg = False
for even in v_even:  # [0]: 数値, [1]: 出現数
    for odd in v_odd:  # [0]: 数値, [1]: 出現数
        if even[0] != odd[0]:
            flg = True
            keep = max(keep, even[1] + odd[1])

ans = n - keep if flg else n // 2
print(ans)

Measured memory_bytes: 17564
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100100;
int i,j,k,n,m,ch,ff,X,Y,Z,Hn;
ll sum,ans;
struct cc {
	int a,b,c,z;
	bool operator < (const cc &n) const { return z<n.z;}
} A[N];
int H[N];
ll pre[N],suf[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void up(int x) {
	while (x>1 && H[x]<H[x>>1]) swap(H[x],H[x>>1]),x>>=1;
}
void down(int x) {
	while ((x<<1)<=Hn) {
		int k=x<<1;
		if (k<Hn && H[k|1]<H[k]) k|=1;
		if (H[k]<H[x]) swap(H[k],H[x]),x=k;
		else break;
	}
}
int main() {
	R(X);R(Y);R(Z);
	n=X+Y+Z;
	for (i=1;i<=n;i++) {
		R(A[i].a);R(A[i].b);R(A[i].c);
		A[i].z=A[i].a-A[i].b;
	}
	sort(A+1,A+n+1);
	Hn=0;
	sum=0;
	for (i=1;i<=n;i++) {
		sum+=A[i].b;
		int t=A[i].b-A[i].c;
		if (Hn<Y) {
			H[++Hn]=t;
			up(Hn);
		}
		else {
			if (t<H[1]) sum-=t;
			else {
				sum-=H[1];
				H[1]=t;
				down(1);
			}
		}
		pre[i]=sum;
	}
	Hn=0;
	sum=0;
	for (i=n;i;i--) {
		sum+=A[i].a;
		int t=A[i].a-A[i].c;
		if (Hn<X) {
			H[++Hn]=t;
			up(Hn);
		}
		else {
			if (t<H[1]) sum-=t;
			else {
				sum-=H[1];
				H[1]=t;
				down(1);
			}
		}
		suf[i]=sum;
	}
	for (i=Y;i+X<=n;i++) ans=max(ans,pre[i]+suf[i+1]);
	W(ans);puts("");
}

Measured memory_bytes: 3712
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Text.RegularExpressions;
using static System.Console;

namespace CsTest
{
    class Program
    {
        static void Main()
        {
            int N = AtCoder.ReadInt32();
            var S = Enumerable.Repeat(0, N).Select(_ => ReadLine()).ToArray();
            var sb = new StringBuilder();
            foreach (var c in Enumerable.Range(0, 26).Select(i => (char)('a' + i)))
            {
                int count = S.Select(s => CountChar(s, c)).Min();
                sb.Append(new string(c, count));
            }
            WriteLine(sb.ToString());
        }
        static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }

    public class AtCoder
    {
        public static int ReadInt32() => int.Parse(ReadLine());
        public static string[] ReadStringArray() => ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        public static int[] ReadInt32Array() => ReadStringArray().Select(s => int.Parse(s)).ToArray();
        public static long[] ReadInt64Array() => ReadStringArray().Select(s => long.Parse(s)).ToArray();
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int K;
	cin >> K;
	cout << (K / 2) * (K - K / 2) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,t,a[3010],b[3010];
	vector<P> vec;
	cin >> n >> t;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
		vec.emplace_back(a[i],b[i]);
	}
	sort(all(vec));
	for(int i = 0;i < n;i++){
		a[i] = vec[i].first;
		b[i] = vec[i].second;
	}
	int dp[3010][3010] = {};
	for(int i = 0;i <= n;i++){
		for(int j = 0;j < t;j++) dp[i][j] = -INF;
	}
	dp[0][0] = 0;
	int ans = -INF;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < t;j++){
			if(j + a[i] < t) chmax(dp[i + 1][j + a[i]],dp[i][j] + b[i]);
			else chmax(ans,dp[i][j] + b[i]);
			chmax(dp[i + 1][j],dp[i][j]);
		}
	}
	for(int i = 0;i < t;i++) chmax(ans,dp[n][i]);
	cout << ans << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	ll b;cin>>b;
  while(b!=0)
  {
    ll i;
    ll breadth=1;
    ll sn=b;
    for(i=100000;i>=3;i--)
    {
      if(i*(i+1)/2>=1000000000)continue;
      if(i%2==1&&b%i!=0)continue;
      if(i%2==0&&b%(i/2)!=0)continue;
      ll kn=b/i-(i-1)/2;
      if(kn<1)continue;
      if(b==(kn*2+i-1)*i/2)
      {
        breadth=i;
        sn=kn;
        break;
      }
    }
    if(breadth==1)
    {
      if(b%2==1)
      {
        breadth=2;
        sn=b/2;
      }
    }
    cout<<sn<<' '<<breadth<<endl;
    cin>>b;
  }
}



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

int N,K,T;

const int B = 100;
int from[200010/B+1], to[200010/B+1];
int val[200010/B*B+B];

void show(){
  return;
  for(int i = 0; i < N; ++i){
    cout << val[i] << ' ';
  }
  cout << endl;
  for(int i = 0; i < N/B; ++i){
    cout << from[i] << ' ';
  }
  cout << endl;
  for(int i = 0; i < N/B; ++i){
    cout << to[i] << ' ';
  }
  cout << endl;
}

void sync(int b){
  if(from[b] == -1) return;
  for(int i = b*B; i < (b+1)*B; ++i){
    if(val[i] == from[b]){
      val[i] = to[b];
    } else {
      val[i] = -2;
    }
  }
  from[b] = -1;
  to[b] = -1;
}

void naive(int l, int r, int x){
  for(int i = l; i < r; ++i){
    val[i] = (val[i] == x-1) ? x : -2;
  }
}

void exec(int l, int r, int x){
  if(l/B == r/B){
    sync(l/B);
    naive(l,r,x);
  } else {
    if(l%B){
      sync(l/B);
      naive(l, l-l%B+B, x);
      l = l-l%B+B;
    }
    if(r%B){
      sync(r/B);
      naive(r-r%B, r, x);
      r = r-r%B;
    }
    while(l+B <= r){
      // cout << "u" << l << endl;
      if(to[l/B] != -1){
	to[l/B] = (to[l/B] == x-1) ? x : -2;
      } else {
	from[l/B] = x-1;
	to[l/B] = x;
      }
      l += B;
    }
  }

  show();
}

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

  cin >> N >> K;
  cin >> T;

  memset(from, -1, sizeof from);
  memset(to, -1, sizeof to);

  while(N%B) ++N;

  for(int it = 0; it < T; ++it){
    int l,r,x;
    cin >> l >> r >> x;
    --l;
    exec(l,r,x);
  }

  for(int i = 0; i < N/B; ++i){
    sync(i);
  }
  show();

  cout << count(val, val+N, K) << endl;
}

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

n,k,q=map(int,input().split())

a=[]

for i in range(q):
    a.append(int(input()))
    
b=[k]*n
c=[-q]*n

for j in a:
    c[j-1]+=1

for l in range(n):
    if b[l]+c[l]<=0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 11220
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]

main :: IO ()
main = do
  n <- readLn :: IO Int
  hs <- readInts :: IO [Int]
  putStrLn . solve $ hs

solve :: [Int] -> String
solve hs = if isNothing $ foldM f 0 hs
           then "No"
           else "Yes"
  where
    f !prev !x = if prev == x
               then Just x
               else if prev <= x - 1
                    then Just (x - 1)
                    else Nothing

Measured memory_bytes: 4092