akhauriyash/Code-Regression huggingface dataset:
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
struct edge {
    int to;
    ll cost;
    edge(int t, ll c): to(t), cost(c) {};
};
vector<edge> g[100010];
ll d[100000];

void dijkstra(int s)
{
    priority_queue<LP, vector<LP>, greater<LP> > q;
    REP(i, N) d[i] = LINF;
    d[s] = 0;
    q.push(make_pair(0ll, s));
    while(!q.empty()){
        LP p = q.top(); q.pop();
        //cout << p.fi << " " << p.se << endl;
        ll v = p.se;
        if(p.first > d[v]) continue;
        for(edge &e: g[v]){
            //cout << v << " " << e.to << " " << e.cost << endl;
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                q.push(mp(d[e.to], e.to));
            }
        }
    }
}

void solve()
{
    //REP(i, N){
    //    for(edge &e: g[i]){
    //        cout << i << " " << e.to << " " << e.cost << endl;
    //    }
    //}
    //cout << endl;
    dijkstra(0);
    REP(i, N){
        if(d[i] % 2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
        //cout << "\t" << d[i] << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N-1){
        int u, v;
        ll w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].pb(edge(v, w));
        g[v].pb(edge(u, w));
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 8704
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

R, G, B, N = rl()
answer = 0
for r in range(N//R + 1):
    sum = r * R
    for g in range((N-sum)//G + 1):
        sum2 = sum + g * G
        if (N-sum2)%B == 0:
            answer += 1

print(answer)
#45


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, H, W;
    cin >> N >> H >> W;
    cout << (N+1-H) * (N+1-W) << "\n";
}

Measured memory_bytes: 256
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.substr(i, 2) == "AC") {
      cout << "Yes" << '\n';
      return;
    }
  }
  cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define for(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(i,0,n)
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())


const int MAX_H = 505;
const int MAX_W = 505;

int H, W;
char Field[MAX_H][MAX_W];

char Red[MAX_H][MAX_W];
char Blue[MAX_H][MAX_W];

signed main()
{
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            cin >> Field[i][j];
        }
    }

    memset(Red, '.', sizeof(Red));
    memset(Blue, '.', sizeof(Blue));
    
    rep(y,H) {
        Red[y][0] = '#';
        Blue[y][W-1] = '#';
        rep(x,W) {
            if(x < W-1) {
                if(y%2 == 0) {
                    Red[y][x] = '#';
                } else {
                    Blue[y][W-1-x] = '#';
                }
            }
            if(Field[y][x] == '#') {
                Red[y][x] = Blue[y][x] = '#';
            }
        }
    }



    rep(y,H) {
        rep(x,W) {
            cout << Red[y][x];
        }
        cout << endl;
    }
    cout << endl;

    rep(y,H) {
        rep(x,W) {
            cout << Blue[y][x];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1536
from fractions import Fraction
import math

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

p = Fraction(0, 1)
if K == 1:
    # 確定勝利
    print("1.0")
else:
    for i in range(1, N+1):
        # 出目i
        if i >= K:
            p += Fraction(1, N)
        else:
            n_win = math.ceil(math.log2(K / i))
            p += Fraction(1, 2**n_win * N)
    print(float(p))


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int s;
  cin >> s;

  set<int> st;
  st.insert(s);
  for(int i = 2;;++i, st.insert(s)) {
    if(s % 2 == 0) {
      s /= 2;
    }
    else {
      s = 3 * s + 1;
    }

    if(st.count(s)) {
      return cout << i << endl, 0;
    }
  }
}

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

using namespace std;

// 計算量の限界 10^8
// 最大値 int i=2147483647;//2^31-1

int main() {
    int64_t N, K;
    cin >> N >> K;

    // 考え方メモ
    // 具体例
    // (N, K) = (13, 4)
    // N = 13, 9, 5, 1, -3
    // r = 13 % 4 = 1
    // 抽象化
    // final N - K >= 0,  N == r
    // final N - K < 0, r - K == N -> N == r - K -> N == |r - K|

    int64_t r = N % K;
    int64_t res;

    res = min(r, abs(r - K));

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

Measured memory_bytes: 256
/* インクルードなど */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n;
  	cin >> n;
  	if (n==0) {
      	cout << 1 << endl;
    } else {
      	cout << 0 << endl;
    }
}
  

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
long long n,a[200005];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),a[i]-=i;
	sort(a+1,a+n+1);
	long long mid=a[(n+1)>>1],ans=0;
	for(int i=1;i<=n;i++) ans+=abs(a[i]-mid);
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    cout << s << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3664
'use strict'

const INF = 900719925474099;
function mapint(temp){
    return temp.split(' ').map((v)=>parseInt(v));
}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;

function Main(input){
    let temp = input.trim().split('\n');
    let n = parseInt(temp[0]);
    let p = mapint(temp[1]);

    let count = 0;
    for(let i=1;i<n-1;i++){
      let s = [p[i-1],p[i],p[i+1]]
      s.sort((a,b)=>b-a);
      if(s[1] == p[i]) count++;
    }

    console.log(count);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 21064
a = gets.to_s
b = a[0..1].to_i
c = a[2..3].to_i


if b <=  99 && c <= 12 && b <= 12 && c <= 99 && c != 0 && b != 0
  answer = 'AMBIGUOUS'
elsif b <=  99 && c <= 12 && c != 0
  answer =  'YYMM'
elsif b <= 12 && c <= 99 && b != 0
  answer = 'MMYY'
else answer = 'NA'
end

puts answer


Measured memory_bytes: 1788
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);

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

  sort(a, a + n);

  long long ans = 0;
  for (int i = n - 1 - k; i >= 0; i--) ans += a[i];

  printf("%lld\n", ans);
  return 0;
}

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

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

int main()
{
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> Ai;
    rep(i, N){
        int A;
        cin >> A;
        vector<pair<int, int>> tmp;
        rep(j, A){
            int x, y;
            cin >> x >> y;
            tmp.push_back(make_pair(x, y));
        }
        Ai.push_back(tmp);
    }

    int max = -1;
    for (int i = 0;i < (1 << N);i++){
        bool flag = false;
        rep(j, Ai.size()){
            vector<pair<int, int>> tmp_vec = Ai.at(j);
            if(!((1 << j) & i)){
                continue;
            }
            rep(k, tmp_vec.size()){
                pair<int, int> tmp_pair = tmp_vec.at(k);
                int x = tmp_pair.first;
                int y = tmp_pair.second;
                if(((1 << (x-1)) & i) != (y << (x-1))){
                    flag = true;
                    break;
                }
            }
        }
        if(!flag){
            unsigned int ui = i;
            ui = (ui & 0x55555555) + ((ui & 0xAAAAAAAA) >> 1);
            ui = (ui & 0x33333333) + ((ui & 0xCCCCCCCC) >> 2);
            ui = (ui & 0x0F0F0F0F) + ((ui & 0xF0F0F0F0) >> 4);
            ui = (ui & 0x00FF00FF) + ((ui & 0xFF00FF00) >> 8);
            ui = (ui & 0x0000FFFF) + ((ui & 0xFFFF0000) >> 16);
            if(max < ((int)ui)){
                max = ui;
            }
        }
    }
    cout << max << endl;
    /*
    rep(i, Ai.size()){
        vector<pair<int, int>> tmp_vec = Ai.at(i);
        rep(j, tmp_vec.size()){
            pair<int, int> tmp_pair = tmp_vec.at(j);
            cout << tmp_pair.first << ":" << tmp_pair.second << endl;
        }
    }
    */
}

Measured memory_bytes: 256
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int T;
	scan(T);
	rep(t,T){
		int N;
		scan(N);
		vll rakup[N],rakum[N+1];
		int ps=0,ms=0;
		ll ans=0;
		rep(i,N){
			int K;
			ll L,R;
			scan(K>>L>>R);
			K--;
			if(L>R){
				rakup[K].push_back(L-R);
				ans+=R;
				ps++;
			}
			else{
				rakum[K+1].push_back(R-L);
				ans+=L;
				ms++;
			}
		}
		priority_queue<ll> Q;
		brep(i,N){
			rep(j,rakup[i].size()){
				Q.push(rakup[i][j]);
			}
			if(i<ps&&(!Q.empty())){
				ans+=Q.top();
				Q.pop();
			}
		}
		priority_queue<ll> mQ;
		rep(i,N){
			rep(j,rakum[i].size()){
				mQ.push(rakum[i][j]);
			}
			if(i>=ps&&(!mQ.empty())){
				ans+=mQ.top();
				mQ.pop();
			}
		}
		prin(ans);
	}

	return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
	int a[100], b[100], c[100], d[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	for (int i = 0; i < n; i++) {
		int minv = abs(a[i] - c[0]) + abs(b[i] - d[0]);
		int check = 1;
		for (int j = 1; j < m; j++) {
			int current = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (minv > current) {
				minv = current;
				check = j + 1;
			}
		}
		cout << check << endl;
	}

	return 0;
}

Measured memory_bytes: 256
memo = []
while(True):
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        memo.append(a+b)
    elif op == "-":
        memo.append(a-b)
    elif op == "*":
        memo.append(a*b)
    elif op == "/":
        memo.append(int(a/b))
    elif op == "?":
        break
for i in range(len(memo)):
    print(memo[i])

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx = x2 - x1, dy = y2 - y1;
  int x3 = x2 - dy, y3 = y2 + dx;
  int x4 = x3 - dx, y4 = y3 - dy;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
def test():
    n = int(input())
    a = list(map(int,input().split()))
    b = {}
    for i,j in enumerate(a):
        b[j] = i+1
    c = sorted(b.keys())
    for i in c:
        print(b[i],end=" ")


if __name__ == "__main__":
    test()


Measured memory_bytes: 20704
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	int l, r, d, cnt = 0;
	scanf("%d%d%d", &l, &r, &d);
	for(int i=l; i<=r; i++)
		if(i % d == 0)
			cnt ++;
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int W, H, C;

	int max, sum, kaz, hen;

	kaz = 100001;

	cin >> W >> H >> C;

	sum = W*H;

	if (W < H)
	{
		max = W;
	}
	else
	{
		max = H;
	}

	for (int i = 1; i <= max; i++)
	{
		hen = (i*i);


		if (W%i==0 && H%i==0)
		{
			kaz = sum / hen;
		}
	}

	cout << C*kaz << endl;



	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

auto GCD(auto a, auto b) { //ユークリッドの互助法で最大公約数
    if(a % b == 0)return b;
    else return GCD(b, a % b);
}
auto LCM(auto a, auto b) { //GCDを使って最小公倍数を求める
    auto g = GCD(a, b);
    return (a / g) * b;
}


int main() {
    LL N,M;cin >> N >> M;
    string S,T;cin >> S >> T;
    LL g = LCM(N,M);

    map<LL,char> m;
    map<LL,int> c;
    bool ok = true;
    int s = g/N;
    rep(i,N){
        m[i*s] = S[i];
        c[i*s]++;
    }
    int t = g/M;
    rep(i,M){
        if(m[i*t] != T[i] && c[i*t] > 0){
            ok = false;
        }
    }

    if(ok)cout << g << endl;
    else cout << -1 << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> f(h);
  for (int i = 0; i < h; i++){
    cin >> f.at(i);
  }

  vector<int> x = {1, 0, -1, 0};
  vector<int> y = {0, 1, 0, -1};
  
  
  bool ans = true;
  
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (f.at(i).at(j) == '.'){
        continue;
      }
      else{
        bool t = false;
        for (int k = 0; k < 4; k++){
          int iy = i + y.at(k);
          int jx = j + x.at(k);
          if (iy < 0 || iy >= h){
            continue;
          }
          if (jx < 0 || jx >= w){
            continue;
          }
          if (f.at(iy).at(jx) == '#'){
            t = true;
            break;
          }
        }
        if (t == false){
          ans = false;
          break;
        }
      }
      if (ans == false){
        break;
      }
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// atcoder/abc152/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    string s, t;
    for (int i = 0; i < a; ++i) {
      s += '0' + b;
    }
    for (int i = 0; i < b; ++i) {
      t += '0' + a;
    }
    cout << min(s, t) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
s = input()
al = 'abcdefghijklmnopqrstuvwxyz'
cou = 10**7
for i in range(26):
  s1 = s
  s2 = s
  w = al[i]
  cou_now = 0
  while len(set(s2))!=1:
   # print(s2)
    cou_now += 1
    s1 = str("".join(s2))
    s2 = []
    for j in range(len(s1)-1):
      if s1[j]==w or s1[j+1]==w:
        s2.append(w)
      else:
        s2.append(s1[j])
  cou = min(cou,cou_now)
print(cou)
      
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s[maxn];
int n;
int L[maxn], R[maxn], par[maxn];
bool check(int mid)
{
	for(int i = 0; i <= n; ++i) L[i] = R[i] = par[i] = 0;
	L[n] = 0; R[n] = mid;
	for(int i = n - 1; ~i; --i)
	{
		if(s[i + 1] == '0')
		{
			L[i] = L[i + 1] + 1;
			R[i] = min(mid, R[i + 1] + 1);
			if(par[i + 1] && R[i + 1] == mid) R[i] = min(R[i], mid - 1);
		}
		else if(s[i + 1] == '1')
		{
			L[i] = max(0, L[i + 1] - 1);
			R[i] = R[i + 1] - 1;
			if(par[i + 1] && L[i + 1] == 0) L[i] = max(L[i], 1);
		}
		else
		{
			L[i] = max(0, L[i + 1] - 1);
			R[i] = min(mid, R[i + 1] + 1);
			if(par[i + 1])
			{
				if(L[i + 1] == 0) L[i] = max(L[i], 1);
				if(R[i + 1] == mid) R[i] = min(R[i], mid - 1);
			}
		}
		if(L[i] > R[i]) return 0;
		if(L[i] == R[i] || par[i + 1]) par[i] = 1;
	}
	return 1;
}
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int l = 1, r = n;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 16468
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

stdin = open(0)

N, A, B, C = map(int, stdin.readline().split())
S = stdin.read().split()

ans = [""] * N
def dfs(i, a, b, c):
    if a < 0 or b < 0 or c < 0:
        return

    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    if S[i] == "AB":
        ans[i] = "A"
        dfs(i + 1, a + 1, b - 1, c)

        ans[i] = "B"
        dfs(i + 1, a - 1, b + 1, c)

    elif S[i] == "BC":
        ans[i] = "B"
        dfs(i + 1, a, b + 1, c - 1)

        ans[i] = "C"
        dfs(i + 1, a, b - 1, c + 1)
    else:
        ans[i] = "A"
        dfs(i + 1, a + 1, b, c - 1)

        ans[i] = "C"
        dfs(i + 1, a - 1, b, c + 1)

dfs(0, A, B, C)
print("No")

Measured memory_bytes: 117544
N = int(input())
if N == 3:
    print(2, 5, 63)
    exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
    a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
    b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
    c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))



Measured memory_bytes: 41712
#include<bits/stdc++.h>
#define mod 1000000007
#define i9 111111112
#define i10 700000005
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int pl[21],pr[21],p[33],m,dp[10][32769],s0[31],s1[31];
void add(int&x,int y){x=x+y>=mod?x+y-mod:x+y;}
int _S[32769],_X[32769];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi()+2,q=gi();
	for(int i=1;i<=q;++i)p[++m]=pl[i]=gi(),p[++m]=pr[i]=gi()+1;
	std::sort(p+1,p+m+1);m=std::unique(p+1,p+m+1)-p-1;
	for(int i=1;i<=q;++i)pl[i]=std::lower_bound(p+1,p+m+1,pl[i])-p;
	for(int i=1;i<=q;++i)pr[i]=std::lower_bound(p+1,p+m+1,pr[i])-p;
	for(int i=1;i<=m;++i)s1[i]=1ll*(pow(10,p[i]-p[i-1])-1)*i9%mod;
	for(int i=1;i<=m;++i)s0[i]=1ll*(1ll*(pow(10,p[i]-p[i-1])-1)*i9+1)%mod*pow(s1[i],mod-2)%mod;
	dp[0][0]=1;
	for(int T=0;T<1<<q;++T){
		for(int k=1;k<=q;++k)if(T>>k-1&1)_S[T]|=(1<<pl[k]-1)|(1<<pr[k]-1);
		_X[T]=1;
		for(int k=2;k<=m;++k)if((_S[T]>>k-1&1)&&(_S[T]>>k-2&1))_X[T]=1ll*_X[T]*s0[k]%mod;
	}
	for(int i=0;i<9;++i)
		for(int j=0;j<1<<q;++j){
			if(!dp[i][j])continue;
			int S=0;
			for(int k=1;k<=q;++k)if(j>>k-1&1)S|=(1<<pl[k]-1)|(1<<pr[k]-1);
			for(int k=1;k<=q;++k)if((S>>pl[k]-1&1)^(S>>pr[k]-1&1)){S=-1;break;}
			for(int k=1;k<=q;++k)if(((~j>>k-1)&1)&&(S>>pl[k]-1&1)){S=-1;break;}
			if(S==-1){dp[i][j]=0;continue;}
			int U=((1<<q)-1)^j;
			for(int T=U;;T=(T-1)&U){
				S=_S[T];
				int x=1ll*dp[i][j]*_X[T]%mod;
				if((S&1)&&(i==0))x=1ll*x*s0[1]%mod;
				add(dp[i+1][j|T],x);
				if(!T)break;
			}
		}
	int ans=1ll*dp[9][(1<<q)-1]*pow(10,n-p[m])%mod;
	for(int i=1;i<=m;++i)ans=1ll*ans*s1[i]%mod;
	printf("%d\n",1ll*ans*i10%mod*i10%mod);
	return 0;
}


Measured memory_bytes: 1792
ostr = input()

slist = list(ostr)
length = len(slist)
half = length // 2

flg1 = True
flg2 = True
flg3 = True

len2 =  (length-1)//2
list2 = slist[:len2]
half2 = len(list2) // 2

len3 = ((length+3)//2)-1
list3 = slist[len3:]
half3 = len(list3) // 2

def judge(s, h):
    for i in range(1, h+1):
        if s[i-1] != s[-i]:
            return False
    return True

flg1 = judge(slist, half)
flg2 = judge(list2, half2)
flg3 = judge(list3, half3)
if flg1 and flg2 and flg3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    a = (a + 11) % 13;
    b = (b + 11) % 13;
    if(a > b) cout << "Alice" << endl;
    else if(a < b) cout << "Bob" << endl;
    else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

bool a,b,c;

void swap(int k){
	bool t;
	if(k==0){
		t=a;
		a=b;
		b=t;
	}
	else if(k==1){
		t=a;
		a=c;
		c=t;
	}
	else if(k==2){
		t=b;
		b=c;
		c=t;
	}
	//cout<<s<<" "<<u<<"aaa"<<endl;
	//cout<<"hoge"<<endl;
	return;
}

int main(){
	a=true;
	b=c=false;
	//cout<<a<<" "<<b<<" "<<c<<endl;
	string s;
	while(cin>>s){
		if(s=="A,B"||s=="B,A") swap(0);
		else if(s=="A,C"||s=="C,A") swap(1);
		else if(s=="C,B"||s=="B,C") swap(2);
		//cout<<a<<" "<<b<<" "<<c<<endl;
		
	}
	//cout<<a<<" "<<b<<" "<<c<<endl;
	if(a==true) cout<<"A\n";
	else if(b==true) cout<<"B\n";
	else if(c==true) cout<<"C\n";
	return 0;
}
		
		

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    string s;
    cin1(s);
    lli ans = 0;
    lli x = 0;
    REP(i,0,n) {
        if (s[i] == 'I')
            x++;
        else if (s[i] == 'D')
            x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
}


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

#define ll long long

ll n, k, cache[100][int(1e5)];
vector < pair <ll, ll> > a;

ll dp(ll i, ll c)
{
	if (i >= n)	return 0;

	if (cache[i][c] != -1)	return cache[i][c];

	ll ret = -2e9;
	if (c + a[i].first > k){
		ret = max(ret, dp(i + 1, c));
	}
	else{
		ret = max({ret, dp(i + 1, c), a[i].second + dp(i + 1, c + a[i].first)});
	}
	return cache[i][c] = ret;
}

int main()
{	
	memset(cache, -1, sizeof cache);
	cin >> n >> k;	a.resize(n);
	for (ll i = 0; i < n; i ++){
		ll x, y;	cin >> x >> y;
		a[i] = {x, y};
	}
	cout << dp(0, 0) << "\n";
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 99999
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,y,i,j,temp;
    cin>>n>>x>>y;
    vector<int>key(n);
    for(i=0;i<n;++i)
        key[i]=0;
    x--;y--;
    for(i=0;i<n;++i)
    {
        for(j=i+1;j<n;++j)
        {
            temp=min(j-i,abs(x-i)+1+abs(j-y));
            key[temp]++;
        }
        
    }
    
    for(i=1;i<=n-1;++i)
        cout<<key[i]<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> b(N,0);
  for(int i=0;i<N-1;i++){
    int k;
    cin >> k;
      b.at(k-1)++;
    }
  for(int i=0;i<N;i++){
      cout << b.at(i) << endl;
  }
}


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

#define ll long long

using namespace std;

//memset(dp, 0, sizeof(dp));

void work(int T) {
	
	int n, m, k, res = 0;
	cin >> n >> m >> k;
	
	vector<vector<char>> g(n, vector<char>(m));
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> g[i][j];
			if(g[i][j] == '#') {
			}
		}
	}
	for(int i = 0; i < (1 << (n + m)); i++) {
		int ct = 0, t = i;
		vector<int> row(n), col(m);
		for(int j = 0; j < m; j++, t = t >> 1) {
			if(t & 1) {
				col[j] = 1;
			}
		}
		for(int j = 0; j < n; j++, t = t >> 1) {
			if(t & 1) {
				row[j] = 1;
			}
		}
		for(int j = 0; j < n; j++) {
			for(int l = 0; l < m; l++) {
				if(g[j][l] == '#' && !row[j] && !col[l]) {
					ct++;
				}
			}
		}
		
		res += ct == k;
	}
	cout << res << endl;
	
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
	// int t;
	// for(cin >> t; t > 0; t--) {
		// work(t);
	// }
	work(0);
	return 0;
};

Measured memory_bytes: 3612
#include<stdio.h>

int main()
{
  char text[1200];
  int i = 0;
  scanf("%[^\n]s", text);

  while(text[i] != NULL)
    {
      if(text[i] >= 65 && text[i] <= 90)
	{
	  printf("%c", (text[i]+32));
	  i++;
	  continue;
	}
      if(text[i] >= 97 && text[i] <= 122)
	{
	  printf("%c", (text[i]-32));
	  i++;
	  continue;
	}
      printf("%c", text[i]);
      i++;
    }
  printf("\n");
}




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

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

    sort(a.begin(), a. end(), greater<int>());
    long long int ans = 0; 
    for(int i = 0; i < n; i++){
        ans += a[2 * i + 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main() {
int N,i,sum=0,highest=0;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
  int d;
  scanf("%d",&d);    
  sum=sum+d;
  if(highest<d) 
  {
    highest=d;
  }
  else 
  {
   highest=highest;
  }
}
 sum=sum-(highest/2);
 printf("%d",sum);
    return 0;
    }

Measured memory_bytes: 1736
#include <stdio.h>
struct Node{
  int p;
  int l;
  int r;
};
 
int n;
struct Node T[10001];
 
 
void preParse(int a){
  if(a==-1){
    return;
  }
  printf(" %d",a);
  preParse(T[a].l);
  preParse(T[a].r);
}
 
void inParse(int b){
  if(b==-1){
    return;
  }
  inParse(T[b].l);
  printf(" %d", b);
  inParse(T[b].r);
}
 
void postParse(int c){
  if(c==-1){
    return;
  }
  postParse(T[c].l);
  postParse(T[c].r);
  printf(" %d",c);
}
 
int main(){
  int i,a,l,r,root;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    T[i].p=-1;
  }
  for(i=0; i<n; i++){
    scanf("%d %d %d",&a,&l,&r);
    T[a].l=l;
    T[a].r=r;
    if(l!=-1){
      T[l].p=a;
    }
    if(r!=-1){
      T[r].p=a;
    }
  }
  for(i=0; i<n; i++){
    if(T[i].p==-1){
      root=i;
    }
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
   
  return 0;
}

Measured memory_bytes: 620
/**
 *  Kaiwen Zhou,
 *  CUHK
**/
#include <bits/stdc++.h>
using namespace std;
#define INS ios::sync_with_stdio(false);cin.tie(0);

long long *father, *rk;
long long *size;

long long Find(long long x) {
    if(father[x] != x) {
        father[x] = Find(father[x]);
    }
    return father[x];
}

long long Size(long long x) {
    long long x_r = Find(x);
    return size[x_r];
}

bool Union(long long x, long long y) {
    long long x_r = Find(x), y_r = Find(y);
    if(x_r == y_r) return false;
    if(rk[x_r] == rk[y_r]) {
        father[x_r] = y_r;
        rk[y_r] ++;
        size[y_r] += size[x_r];
    }
    else if(rk[x_r] > rk[y_r]) {
        father[y_r] = x_r;
        size[x_r] += size[y_r];
    }
    else {
        father[x_r] = y_r;
        size[y_r] += size[x_r];
    }
    return true;
}

int main(void) {
    INS;
    long long n, m;
    cin >> n >> m;
    father = new long long[n + 1];
    rk = new long long[n + 1];
    size = new long long[n + 1];
    long long all = n * (n - 1) / 2, res[m];
    vector<pair<long long, long long>> edges;
    for(int i = 0; i < m; i ++) {
        long long a, b;
        cin >> a >> b;
        edges.push_back(make_pair(a, b));
        res[i] = 0;
    }

    for(int i = 1; i <= n; i ++) {
        father[i] = i;
        rk[i] = 0;
        size[i] = 1;
    }

    res[m - 1] = all;

    for(int i = m - 1; i >= 1; i --) {
        long long size_1 = Size(edges[i].first), size_2 = Size(edges[i].second);
        if(Union(edges[i].first, edges[i].second))
            res[i - 1] = res[i] - size_1 * size_2;
        else
            res[i - 1] = res[i];
    }

    for(int i = 0; i < m; i ++)
        cout << res[i] << '\n';

    delete[] rk;
    delete[] father;
    delete[] size;
    return 0;
}


Measured memory_bytes: 6128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut done: bool = false;

    while !done {
        let mut cards: String = read();
        if cards == "-" {
            done = true;
        } else {
            let shuffle_number: u8 = read();
            for _ in 0..(shuffle_number) {
                let h: usize = read();
                cards = format!("{}{}", &cards[h..], &cards[..h]);
            }
            println!("{}", cards);
        }
    }
}



Measured memory_bytes: 5028
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,i=1,j,x;
	int stack=0,old=0;
	int ans=0;
	int alice=0,bob=0;
	vector<int> a;

	cin >>n;
	while (cin >> x) {
		a.push_back(x);
	}
	

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (a[i] > a[j]) {
				stack = a[i];
				a[i] = a[j];
				a[j] = stack;
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (i % 2 == 0) alice = alice + a[i];
		else bob = bob + a[i];
	}

	cout << alice - bob<< "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <fstream>

int main(){
	int n; std::cin >> n;
	std::unordered_map<std::string, int> map;
	for (auto i = 0; i < n; ++i) {
		std::string w; std::cin >> w;
		map[w]++;
	}
	int max = 0;
	std::vector<std::string> result; result.reserve(n);
	for (const auto& p : map) {
		if (max < p.second) {
			max = p.second;
			result.clear();
		}
		if (max == p.second) {
			result.push_back(p.first);
		}
	}
	std::sort(result.begin(), result.end());
	for (const auto& w : result) {
		std::cout << w << '\n';
	}
}


Measured memory_bytes: 20732
#include<iostream>

using namespace std;

int countDivisor(int n){
    int cnt = 0;

    for (int i = 1; i <= n; i++) {
        if (n % i == 0) cnt++;
    }
    return cnt;
}

int main(void){
    int n; 
    cin >> n;

    int ans = 0;

    for (int i = 1; i <= n; i += 2){
        if(countDivisor(i) == 8) ans++;
    }

    printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

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

    // input
    int a, b;
    cin >> a >> b;
    
    // calculation
    cout << (a + b + 1) / 2 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(n, _, c) = sc.nextLine.split(" ").map(_.toInt)
    val b: Array[Int] = sc.nextLine.split(" ").map(_.toInt)

    @annotation.tailrec
    def go(n: Int, accT: Int): Int = {
      if (n == 0) accT
      else {
        val linear = (sc.nextLine.split(" ").map(_.toInt) zip b).foldLeft(0)(
          (acc, item)
          => {
            item._1 * item._2 + acc}
        ) + c

        val total: Int = linear match {
          case m if m > 0 => 1
          case _ => 0
        }
        go(n - 1, accT + total)
      }
    }

    println(go(n, 0))

  }
}

Measured memory_bytes: 25664
#include <cstdio>
#include <algorithm>
using namespace std;
int main(void){
int a,b,re,co,i,p[100];
scanf("%d%d%d%d",&a,&co,&b,&re);
for(i=0;i<a;i++)scanf("%d",p+i);
sort(p,p+a);
for(i=a-1;i>=0;i--){
if((p[i]+re)*co>re*(co+b)){
re+=p[i];co+=b;
}
else break;
}
printf("%d\n",re/co);
return 0;
}

Measured memory_bytes: 1040
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int i,j,k,n,T,q,h,w;
	string s1,s2;
	char s[101][101];
	cin>>h>>w;
	for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin>>s[i][j];
        }
	}
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cout<<s[i][j];
        }
        cout<<endl;
        for(j=0;j<w;j++){
            cout<<s[i][j];
        }
        cout<<endl;
    }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
char s[10005];
int ss[10005];
int main(){
        int n;
        while(~getI(n)){
                scanf("%s",s);
                int l=strlen(s);
                F(i,0,l) ss[i]=s[i]-'A'+n;
                F(i,0,l) ss[i]%=26;
                F(i,0,l) printf("%c",ss[i]+'A');
                puts("");
        }
}

Measured memory_bytes: 256
import java.util.*

open class MainKt {
    companion object Static {
        @JvmStatic fun main(args: Array<String> = arrayOf()) {
            MainKt().solve()
        }
    }

    val scanner = Scanner(System.`in`)

    fun printf(pattern: String, vararg args: Any): Unit {
        println(String.format(pattern, *args))
    }

    open fun println(line: String) {
        kotlin.io.println(line)
    }

    fun println(line: Int) {
        println(line.toString())
    }

    fun println(line: Long) {
        println(line.toString())
    }

    open fun readLine(): String {
        return scanner.nextLine()
    }

    fun readArg(): String {
        return readLine()
    }

    fun readInt(): Int {
        return readArg().toInt()
    }

    fun readLong(): Long {
        return readArg().toLong()
    }

    fun readIntList(): List<Int> {
        return readArgList().map { it.toInt() }
    }

    fun readLongList(): List<Long> {
        return readArgList().map { it.toLong() }
    }

    fun readArgList(): List<String> {
        return readLine().split(" ")
    }

    fun solve() {
        val mod = Math.pow(10.0, 9.0).toLong() + 7L
        val (n, m) = readLongList()
        val d = Math.abs(n - m)
        when (d) {
            0L -> {
                var f = 1L
                for (i: Long in 1..m) {
                    f = f * i % mod
                    f = f * i % mod
                }
                f = 2 * f % mod
                println(f)
            }
            1L -> {
                var f = 1L
                for (i: Long in 1..m) {
                    f = f * i % mod
                }
                for (i in 1..n) {
                    f = f * i % mod
                }
                println(f)
            }
            else -> {
                println(0)
            }
        }
    }
}

Measured memory_bytes: 34172
#include <iostream>
#include <math.h>
typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){
  
  int N,K;
  cin >> N >> K;

  int a[N+1];
  FOR(i,1,N+1){
    cin >> a[i];
  }

  int ans = 0;
  FOR(i,1,N+1){
    int aDis = a[i] * 2;
    int bDis = abs(K - a[i]) * 2;
    ans += min(aDis,bDis);
  }

  cout << ans << endl;

  return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll arr[1005] ;

int main()
{
    ll n, m, flag = 0 ;
    double sum = 0, mVal ;
    cin >> n >> m ;
    for (int i = 0; i < n; i++) {
        cin >> arr[i] ;
        sum += arr[i] ;
    }
    sort(arr, arr + n, greater<ll>()) ;
    mVal = sum / (4 * m) ;
    for (int i = 0; i < m; i++) {
        if (arr[i] < mVal) {
            cout << "No" ;
            return 0 ;
        }
    }
    cout << "Yes" ;

    return 0 ;
}


Measured memory_bytes: 256
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 n;
    cin >> n;
    vector<vector<edge>> G(n);
    for (int i = 0; i < n - 1; ++i) {
        i64 u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        G[u].push_back(edge(u, v, w));
        G[v].push_back(edge(v, u, w));
    }
    vector<i64> d(n, - 1);
    d[0] = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int t = que.front(); que.pop();
        for (int i = 0; i < G[t].size(); ++i) {
            int v = G[t][i].to;
            if (d[v] == -1) {
                d[v] = d[t] + G[t][i].cost;
                que.push(v);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if(d[i] % 2) cout << 1 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 10112