akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

int H, W;
char s[51][51];
int dist[51][51];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int sy = 0, sx = 0;

int dfs(){
    queue<pint> que;
    rep(i, H) rep(j, W) dist[i][j] = -1;
    int gy = H - 1, gx = W - 1;
    que.push(pint(sy, sx));
    dist[sy][sx] = 0;

    while(que.size()){
        pint p = que.front(); que.pop();
        if(p.first == gy && p.second == gx) break;

        rep(i, 4){
            int ny = p.first + dx[i], nx = p.second + dy[i];
            if(0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == '.' && dist[ny][nx] == -1){
                dist[ny][nx] = dist[p.first][p.second] + 1;
                que.push(pint(ny, nx));
            }
        } 
    }
    return dist[gy][gx];
}

int main(){
    cin >> H >> W;
    int cnt = 0;

    rep(i, H) rep(j, W){
        cin >> s[i][j];
        if(s[i][j] == '.') cnt++;
    }

    int rel = dfs();
    if(rel == -1) COUT(-1);
    else COUT(cnt - rel - 1);
}

Measured memory_bytes: 256
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)


def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


def main():
    a, b, q = map(int, input().split())

    s = sorted(int(input()) for _ in range(a))
    t = sorted(int(input()) for _ in range(b))

    for _ in range(q):
        x = int(input())

        lo, hi = 0, a - 1
        while lo < hi:
            mi = lo + (hi - lo) // 2
            if s[mi] > x:
                hi = mi
            else:
                lo = mi + 1

        if lo == 0:
            p1, _p1 = s[0] - x, s[0] - x
        else:
            p1, _p1 = s[lo - 1] - x, s[lo] - x

        lo, hi = 0, b - 1
        while lo < hi:
            mi = lo + (hi - lo) // 2
            if t[mi] > x:
                hi = mi
            else:
                lo = mi + 1

        if lo == 0:
            p2, _p2 = t[0] - x, t[0] - x
        else:
            p2, _p2 = t[lo - 1] - x, t[lo] - x

        res = float('inf')

        if p1 <= 0 and p2 <= 0:
            res = min(res, abs(min(p1, p2)))

        if p1 <= 0 and _p2 <= 0:
            res = min(res, abs(min(p1, _p2)))

        if _p1 <= 0 and p2 <= 0:
            res = min(res, abs(min(_p1, p2)))

        if _p1 <= 0 and _p2 <= 0:
            res = min(res, abs(min(_p1, _p2)))

        if p1 >= 0 and p2 >= 0:
            res = min(res, max(p1, p2))

        if p1 >= 0 and _p2 >= 0:
            res = min(res, max(p1, _p2))

        if _p1 >= 0 and p2 >= 0:
            res = min(res, max(_p1, p2))

        if _p1 >= 0 and _p2 >= 0:
            res = min(res, max(_p1, _p2))

        res = min(res, 2 * abs(p1) + abs(p2))
        res = min(res, 2 * abs(p1) + abs(_p2))
        res = min(res, 2 * abs(_p1) + abs(p2))
        res = min(res, 2 * abs(_p1) + abs(_p2))

        res = min(res, 2 * abs(p2) + abs(p1))
        res = min(res, 2 * abs(p2) + abs(_p1))
        res = min(res, 2 * abs(_p2) + abs(p1))
        res = min(res, 2 * abs(_p2) + abs(_p1))

        print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47540
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 10000000;
    int s_n = s.size();
    int t_n = t.size();
    rep(i, s_n - t_n + 1){
        int cnt = 0;
        rep(j, t_n){
            if(s[i+j] != t[j]) cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * 提出
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int W = scanner.nextInt();
		int H = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();

		/* 水平方向を調べる */
		/* 円が長方形の内側にない場合 */
		if (x - r < 0 || x + r > W) {
			System.out.println("No");
		} else {

			/* 垂直方向を調べる */
			if (y - r <  0 || y + r > H) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}

		}
	}
}



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

int main()
{
	int a, b, c, s;
	cin >> a >> b >> c;

	if( c == a + b or a == b + c or b == c + a ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No"  << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
div = 2
res = 0
m = int(math.sqrt(n))
while div < m:
    cnt = 0
    if ((n // div) * div != n):
        div += 1
        continue
    while (n // div) * div == n:
        cnt += 1
        n = n // div
    #print(div, cnt)
    tmp = 1
    while tmp <= cnt:
        res += 1
        cnt -= tmp
        tmp += 1
    if (n == 1):
        div = m
    div += 1
print(res+1*(n != 1))


Measured memory_bytes: 9136
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(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(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
ll n, cnt, ans[ohara], a, b, c, d, tmp, m, h, w, x, y, sum, k, q, s;

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

  cin >> n >> k >> s;
  rep(i, n) {
    ans[i] = s;
    cnt++;
  }
  rep(i, n) {
    if (cnt == k) break;
    cnt--;
    if (s != 1000000000)
      ans[i] = 1000000000;
    else
      ans[i] = 1;
  }
  rep(i, n) {
    if (i == n - 1)
      Cout(ans[i]);
    else
      cout << ans[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 2176
a = input().split()
 
A = int(a[0])
V = int(a[1])
 
b = input().split()
 
B = int(b[0])
W = int(b[1])
 
T = int(input())
 
if B <0:
    B = B*-1
    A = A*-1
 
if A<B and A + V*T>= B +W*T:
    print("YES")
elif B<A and B -W*T >= A - V*T:
    print("YES")
else:
  print("NO")

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;

	int ans = 1;
	char current = S[0];
	for (int i = 1; i < N; i++) {
		if (current != S[i]) {
			ans++;
			current = S[i];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++) 
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

int main() {
	ll a, b, k, n = 0, z = 0,x,y;

	cin >> x >> y;
	if (y % 2 != 0) { cout << "No"; return 0; }
	if (x * 2 <= y && y <= x*4) { cout << "Yes"; return 0; }
	cout << "No";


	return 0;

}
	

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            try {
                String line = br.readLine();
                String[] lines = line.split(" ", 0);
                int a = Integer.parseInt(lines[0]);
                char op = lines[1].charAt(0);
                int b = Integer.parseInt(lines[2]);

                if (op == '+') {
                    System.out.println(a + b);
                } else if (op == '-') {
                    System.out.println(a - b);
                } else if (op == '*') {
                    System.out.println(a * b);
                } else if (op == '/') {
                    System.out.println(a / b);
                } else break;
            } catch (NumberFormatException e) {
                break;
            } catch (IOException e) {
                break;
            }
        }


    }
}


Measured memory_bytes: 24408
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main() {
    int N;
    unsigned long long K;
    cin >> N >> K;

    vector<pair<unsigned long long, unsigned long long>> arr;
    for (int i = 0; i < N; i++) {
        unsigned long long ai, bi;
        cin >> ai >> bi;
        arr.emplace_back(ai, bi);
    }
    sort(arr.begin(), arr.end());

    unsigned long long count = 0;
    for (auto &elm : arr) {
        if (K <= (count += elm.second)) {
            cout << elm.first << endl;
            return 0;
        }
    }
};


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

using namespace std;

int main(){
 string s;
  cin >> s;
  if (s.at(5)=='1') cout << "TBD" << endl;
  else if (s.at(6)=='9')  cout << "TBD" << endl;
    else if (s.at(6)=='8')  cout << "TBD" << endl;
      else if (s.at(6)=='7')  cout << "TBD" << endl;
        else if (s.at(6)=='6')  cout << "TBD" << endl;
          else if (s.at(6)=='5')  cout << "TBD" << endl;
  else cout << "Heisei" << endl;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        ls: [usize; n],
    }
    let mut ls = ls;
    ls.sort();
    let mut ans = 0;
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            let mut l = j;
            let mut r = n;

            while r - l > 1 {
                let t = l + (r - l) / 2;
                if ls[i] + ls[j] > ls[t] {
                    l = t;
                } else {
                    r = t;
                }
            }
            ans += l - j;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    char s[101];
    scanf("%s", s);
    int len = strlen(s);
    rep(i, 0, len){
        printf("x");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A + B < C + D){
        cout << "Right" << endl;
    }
    else if(A + B == C + D){
        cout << "Balanced" << endl;
    }
    else cout << "Left" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {     
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        if (v[i] % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
}




Measured memory_bytes: 3760
import sys
import numpy as np

N, T = list(map(int, input().split())) 

ct = np.zeros([2,N])

for i in range(N):
    ct[0,i], ct[1,i] = list(map(int, input().split()))

ct = ct[:,np.argsort(ct[0,:])]

for i in range(N):
    if ct[1,i] <= T:
        print(int(ct[0,i]))
        sys.exit()

print('TLE')


Measured memory_bytes: 14444
# -*- coding: utf-8 -*-
A, B, C, D = map(int, input().split())
lifeT = A
lifeA = C

for battle_num in range(1, 100):
    if battle_num % 2 != 0:
        lifeA = lifeA - B
    else:
        lifeT = lifeT - D

    if lifeA <= 0 or lifeT <= 0:
        break

if battle_num % 2 != 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT = mp::cpp_int;
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll;
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x) low2way(v, x) - v.begin()       //1番左が0、もし見つから無いならｎを出力
#define higher(v, x) high2way(v, x) - v.begin() - 1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b) \
  putout(a);          \
  putout(b)
#define putout3(a, b, c) \
  putout(a);             \
  putout(b);             \
  putout(c)
#define putout4(a, b, c, d) \
  putout(a);                \
  putout(b);                \
  putout(c);                \
  putout(d)
#define putout5(a, b, c, d, e) \
  putout(a);                   \
  putout(b);                   \
  putout(c);                   \
  putout(d);                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}
ll lcm(ll x, ll y)
{
  ll z = gcd(x, y);
  return x * y / z;
}
INT LCM(INT x, INT y)
{
  INT z = gcd(x, y);
  return x * y / z;
}
ll primejudge(ll n)
{
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;
  double sqrtn = sqrt(n);
  Loop(i, 3, sqrtn + 1)
  {
    if (n % i == 0)
    {
      return 0;
    }
    i++;
  }
  return 1;
}
INT modinv(INT a, INT m)
{
  INT b = m, u = 1, v = 0;
  while (b)
  {
    INT t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
int main()
{
  cout << fixed << setprecision(30);
  ll A,B,M;
  cin>>A>>B>>M;
  vec a(A);
  vec b(B);
  vec x(M);
  vec y(M);
  vec c(M);
  loop(i,A)cin>>a[i];
  loop(i,B)cin>>b[i];
  loop(i,M)cin>>x[i]>>y[i]>>c[i];
  vec ans(M+1,1e18);
  loop(i,M){
    ans[i]=a[x[i]-1]+b[y[i]-1]-c[i];
  }
  sort(all(a));
  sort(all(b));
  ans[M]=a[0]+b[0];
  sort(all(ans));
  putout(ans[0]);
}


Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;const int N=2*1e5+10;
int w[N];int d[N];int cnt[20];int res;int n;int st;bool book[N];int sxr[N];
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v,va;i<n;i++){scanf("%d%d%d",&u,&v,&va);w[u]^=va;w[v]^=va;}
    for(int i=0;i<n;i++){cnt[w[i]]++;}//贪心
    for(int i=1;i<=15;i++)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);
    for(int i=1;i<(1<<15);i++)d[i]=d[i>>1]+(i&1);
    for(int i=1;i<(1<<15);i++)d[i]-=1;//预处理每个dp值的下界
    for(int i=1;i<(1<<15);i++)
        for(int j=0;j<15;j++)if((i>>j)&1)sxr[i]^=(j+1);//预处理集合的异或和
    for(int i=1;i<(1<<15);i++)//枚举子集进行转移
    {
        if(sxr[i]!=0)continue;
        for(int k=(i-1)&i;k;k=(k-1)&i)
            if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
    }printf("%d",res+d[st]);return 0;
}

Measured memory_bytes: 896
/*ITP1_8_A:Toggling Cases*/
#include <iostream>
//#include <cstdio>
#include <string>
using namespace std;

int main()
{
  string str;
  getline(cin,str);

  for(int i=0; i < str.size(); i++)         // 大・小文字間の
  {                                         // コード差は32
    if( 'a'<=str[i] && str[i]<='z' ) 
      str[i] += 'A'-'a';
    else if( 'A'<=str[i] && str[i]<='Z' ) 
      str[i] += 'a'-'A';
  }
   
  cout << str << endl;

//  printf("%c : %d\n",'a','a');
//  printf("%c : %d\n",'A','A');

  return 0;
}



Measured memory_bytes: 3148
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
//char buf[1<<24],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
void del(int &x,int y) { x+=y; x=x>=P?x-P:x; }
struct EDGE { int v,w,nx; }lb[N<<1]; int top[N],tot;
void add (int u,int v,int w) { lb[++tot]=(EDGE){v,w,top[u]},top[u]=tot; }
#define pii pair<LL,int>
#define fi first
#define se second
#define mp make_pair
priority_queue <pii> q;
bool vis[N];
int n,m;
void dij (int s,LL *dis,int *an)
{
	memset (dis,63,sizeof (LL)*(n+1));
	memset (vis,0,sizeof (bool)*(n+1));
	dis[s]=0,q.push (mp(-dis[s],s));
	an[s]=1;
	while (q.size ())
	{
		int u=q.top ().se; q.pop ();
		if (vis[u]) continue;
		vis[u]=1;
		for (int kb=top[u]; kb; kb=lb[kb].nx)
		{
			int v=lb[kb].v,w=lb[kb].w;
			if (dis[v]> dis[u]+w)
			{
				dis[v]=dis[u]+w;
				q.push (mp(-dis[v],v));
				an[v]=0;
			}
			if (dis[v]==dis[u]+w) del(an[v],an[u]);
		}
	}
}
int S(int A) { return (LL)A*A%P; }
LL dis[2][N];
int an[2][N];
int s,t;
int x[N],y[N],w[N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	sc(n),sc(m),sc(s),sc(t);
	for (int i=1; i<=m; i++)
	{
		sc(x[i]),sc(y[i]),sc(w[i]);
		add (x[i],y[i],w[i]),add (y[i],x[i],w[i]);
	}
	dij (s,dis[0],an[0]);
	dij (t,dis[1],an[1]);
	LL d=dis[0][t],d2=d>>1;
	int ans=(LL)an[0][t]*an[1][s]%P;
	if (!(d&1)) for (int i=1; i<=n; i++)
		if (dis[0][i]==d2) del(ans,P-S((LL)an[0][i]*an[1][i]%P));
	for (int i=m+1; i<=m<<1; i++)
		x[i]=y[i-m],y[i]=x[i-m],w[i]=w[i-m];
	m<<=1;
	for (int i=1; i<=m; i++)
		if (dis[0][x[i]]< d2&&dis[1][y[i]]< d2&&dis[0][x[i]]+dis[1][y[i]]+w[i]==d)
			del(ans,P-S((LL)an[0][x[i]]*an[1][y[i]]%P));
	pr(ans);
	return 0;
}


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

using namespace std;
using ll = long long;

template<typename T>
void catv(vector<T> a) {
    for(auto x: a) {
        cout << x << " ";
    }
    cout << endl;
}

int upperBound(vector<ll> a, int v) {
    int l = 0;
    int r = a.size();
    while(l < r) {
        int mid = (l + r) / 2;
        if(v >= a[mid]) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    return l;
}

template<typename T>
int mybinary_search(T key, vector<T> a, function<bool(T, T)> f) {
    int ng = -1;
    int ok = (int)a.size();

    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(f(a[mid], key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    for (auto &x : A)
        cin >> x;
    for (auto &x : B)
        cin >> x;
    for (auto &x : C)
        cin >> x;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    vector<ll> BC(N, 0);
    function<bool(ll, ll)> comp = [](ll a, ll b) { return a > b; };
    for (int i = 0; i < N; i++)
    {
        BC[i] = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    }
    for(int i = N - 2; i >= 0; i--) {
        BC[i] += BC[i + 1];
    }

    ll res = 0;
    for(auto x: A) {
        int index = upper_bound(B.begin(), B.end(), x) - B.begin();
        res += BC[index];
    }

    cout << res << endl;
}

Measured memory_bytes: 3456
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var A = lines[1].split(" ").map(i => Number(i));
    A.unshift(0); A.push(0)

    var Sum = 0;
    for (var i = 1; i < N + 2; i++) { Sum += Math.abs(A[i] - A[i - 1]) }

    for (var i = 1; i < N + 1; i++) {
        var ans = Sum - (Math.abs(A[i] - A[i - 1]) + Math.abs(A[i + 1] - A[i])) + Math.abs(A[i - 1] - A[i + 1]);
        console.log(ans);
    }

});

Measured memory_bytes: 35584
def slove(n, ab_list):

    hoge = {}
    for i,j in ab_list:
        if int(i) not in hoge:
            hoge[int(i)] = []
        hoge[int(i)].append(int(j))

    ans = len([j for i in hoge[1] if i in hoge for j in hoge[i] if j == n])

    if ans >=1:
        return "POSSIBLE"
    else:
        return "IMPOSSIBLE" 

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    ab_list = [input().split() for i in range(m)]
    print(slove(n, ab_list))


Measured memory_bytes: 90020
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for (int i = 0; i < (n); i++) 
int main() {
  int x,n;cin>>x>>n;
  vector<int>p(n),vec(102);
  lp(i,n){
    cin>>p[i];
  vec[p[i]]=1;
  }
  int ans=1e9,a;
  lp(i,102){
    if(vec[i]==0){
     if(ans>abs(x-i)){
     	ans=abs(x-i);
     	 a=i;
	 }
    }
  }
  cout<<a<<endl;
}


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

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

  int m = max({A, B, C});

  if (m == A)
  {
    cout << A * 10 + B + C << endl;
  }
  else if (m == B)
  {
    cout << A + B * 10 + C << endl;
  }
  else
  {
    cout << A + B + C * 10 << endl;
  }
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

typedef long long ll;
int N,x;
int a[100003];
ll ans;
int main() {
  cin >> N >> x;

  for(int i = 0; i < N; i++) cin >> a[i];
  if(a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  if(a[N-1] > x) {
    ans += a[N-1] - x;
    a[N-1] = x;
  }

  for(int i = 1; i <= N; i++) {
    if(a[i]+a[i-1] > x) {
      ans += a[i]+a[i-1]-x;
      a[i] -= a[i]+a[i-1]-x;
    }
  }

  cout << ans <<endl;
}


Measured memory_bytes: 640
//Coded By Visnunathan

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        // FastScanner sc=new FastScanner();
        // char[] line = sc.next().toCharArray();
        // int sum = 0;
        // for (char c:line) sum+=c-'0';
        // System.out.println(sum%9==0?"YES":"NO");
         FastScanner fs=new FastScanner();
        char[] line=fs.next().toCharArray();
        int sum=0;
        for (char c:line) sum+=c-'0';
        System.out.println(sum%9==0?"Yes":"No");
    }
    // public static void main(String[] args) {
    //     FastScanner fs=new FastScanner();
    //     char[] line=fs.next().toCharArray();
    //     int sum=0;
    //     for (char c:line) sum+=c-'0';
    //     System.out.println(sum%9==0?"Yes":"No");
    // }

    static final Random random=new Random();
    
    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort 
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

    
}


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

typedef long long ll;

#define debug(args...)do{cerr<< #args << " : ";shaon(args);}while(0)
void shaon () { cerr << endl; }
template <typename T, typename ... north>
void shaon(T arg, const north &... rest){cerr << arg << ' ';shaon(rest...);}

const ll N=1e5+5;
ll n, dp[N], m, ans;
bool vis[N];
vector <ll> G[N];

ll solve (ll x)
{
    if(vis[x]){
        return dp[x];
    }
    vis[x]=1;
    dp[x]=1;
    for(ll y: G[x]){
        dp[x]=max(dp[x],1+solve(y));
    }
    ans=max(ans,dp[x]);
    return dp[x];
}

int main()
{
    scanf("%lld %lld",&n,&m);

    for(ll i=1; i<=m; i++){
        ll x, y;
        scanf("%lld %lld",&x,&y);
        G[x].push_back(y);
    }

    for(ll i=1; i<=n; i++){
        if(!vis[i]){
            vis[i]=1;
            dp[i]=1;
            for(ll y: G[i]){
                dp[i]=max(dp[i],1+solve(y));
            }
            ans=max(ans,dp[i]);
        }
    }

    printf("%lld",ans-1);


    return 0;
}


















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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    int n,total_even(0);  cin >> n;
    vector<int> v(n);
    bool ev(true),ad(true);
    rep(i,n){
        cin >> v[i];
        if(v[i]%2==0){
            total_even++;
            ev = false;
        }
        if(v[i]%2==1){
            ad = false;
        }
    }

    int ans(pow(3,n));

    if(ev){
        ans--;
    }else{
        ans -= pow(2,total_even);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4060
#include<stdio.h>
int main()
{
	int count=5,max=0,sum=0,d,temp;
	while(count--)
	{
		scanf("%d", &d);
		temp = ((d+10-1)/10)*10;
		sum+=temp;
		if(temp-d>max) max = temp-d;
	}
	sum-=max;
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <valarray>
#include <utility>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP2(i,m,n) for(int i=m+1;i<=(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<=(int)(n);i++)
#define INF 2000000000
#define INFLL 9000000000000000000
#define MOD (1e9)+7

typedef long long int ll;

// a 0x61 z 0x7a

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << ((abs(a - b) % 2) == 0 ? "Alice" : "Borys");

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7

k= int(input())
a,b = get_nums_l()

print("OK" if a%k==0 or b-a+1 > k or a%k>b%k else "NG") 

Measured memory_bytes: 61708
H,W,K=gets.split.map &:to_i
dp=(0..H).map{[0]*(W+2)}
dp[0][1]=1;
(1..H).each do |i|
    (0...2**(W-1)).select{|k| (k & k/2)==0}.each do |k|
        m=k*2
        (1..W).each do |j|
            dp[i][j]+=dp[i-1][m[j]>0 ? j+1 : m[j-1]>0 ? j-1 : j]
            dp[i][j]%=10**9+7
        end
    end
end
puts dp[H][K]

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a,b;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a>b) swap(a,b);
	if((b-a)%2==0) return printf("%lld",(b-a)/2),0;
	long long ans=min(a,n-b+1);
	printf("%lld",ans+(b-a-1)/2);
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}



//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll N;cin>>N;vl A(N);rep(i,N)cin>>A[i];
  vl nbit(61);
  rep(i,N){
    int j=0;
    while(A[i]>0){
      if(A[i]%2==1)nbit[j]++;
      A[i]/=2;
      j++;
    }
  }
  ll ans=0;
  ll po=1;
  rep(i,61){
   ans +=((po*(nbit[i]%MOD))%MOD)*(N-nbit[i]);
   ans%=MOD;
   po*=2;
   po%=MOD;
  }
  cout<<ans%MOD<<endl;
}







Measured memory_bytes: 2560
import statistics
N = int(input())
a = list(map(int, input().split()))

ans = 0
anslst = []
for i in range(N):
    anslst.append(a[i] - (i + 1))
anslst.sort()
tmp = int(statistics.median(anslst))
for i in range(N):
    ans += abs(a[i] - (tmp + i + 1))

print(ans)

Measured memory_bytes: 27264
n,m=map(int,input().split())

x=[]
for i in range(m):
    p,y = input().split()
    x.append({"i":i, "p":p, "y":int(y)})
cnt = {}
x=sorted(x, key=lambda z: z["y"])
for city in x:
    c = cnt.get(city["p"], 0)
    cnt[city["p"]] = c+1
    city["n"] = city["p"].zfill(6) + str(c+1).zfill(6)

x = sorted(x, key=lambda z: z["i"])
for city in x:
    print(city["n"])

Measured memory_bytes: 60688
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

ll arr[1000010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(6);

    int n, q;
    cin >> n >> q;

    priority_queue<pair<int, int>> que;

    for (int i = 0; i < q; ++i)
    {
        int a, v;
        cin >> a >> v;
        arr[a] += v;

        que.push(make_pair(arr[a], -a));
        while (!que.empty())
        {
            if (que.top().first == arr[-que.top().second])
            {
                cout << -que.top().second << " " << que.top().first << endl;
                break;
            }
            que.pop();
        }
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int N = s.size();
    int K;
    cin >> K;
    for (int i = 0; i < N-1; i++) {
        char c = s[i];
        if (c == 'a') continue;
        if (26-(int)(c-'a') <= K) {
            K -= 26-(int)(c-'a');
            s[i] = 'a';
        }
        if (K == 0) break;
    }
    s[N-1] = (s[N-1] -'a' + K)%26 + 'a';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>

int main()
{    long long a,b,n,k,i,j,m;
    scanf("%lld%lld%lld",&a,&b,&k);
    for(i=0;i<k;i++){
        if(a%2==1){
            a--;
        }
        b+=a/2;
        a/=2;
        i++;
        if(i>=k)break;
        if(b%2==1){
            b--;
        }
        a+=b/2;
        b/=2;
    }
    printf("%lld %lld",a,b);

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    private static int count;
    private static int dominant_type; // 1 if white, 2 if black, 3 if neither;
    private static int[][] Map;
    private static int[][] directions = new int[][] {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    private static void paint(int x, int y) {
        count++;
        Map[y][x] = -1;
        int t;
        int ny, nx;
        for (int[] direction: directions) {
            ny = y + direction[1];
            nx = x + direction[0];

            if (nx >= 0 && nx < Map[0].length && ny >= 0 && ny < Map.length) {
                t = Map[ny][nx];
                if (t == -1) continue;
                if (t == 0) {
                    paint(nx, ny);
                } else {
                    if (dominant_type == 0)
                        dominant_type = t;
                    else if (dominant_type != t)
                        dominant_type = 3;
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w, h;
        int white, black;
        String[] input;

        while (true) {
            input = sc.nextLine().trim().split(" ");
            w = Integer.parseInt(input[0]);
            h = Integer.parseInt(input[1]);
            count = 0;
            dominant_type = 0;
            white = 0;
            black = 0;

            if (w == 0) break;

            // Initialize Map
            Map = new int[h][w];
            for (int y = 0; y < h; y++) {
                input = sc.nextLine().trim().split("");
//                System.out.println(Arrays.toString(input));
                for (int x = 0; x < w; x++) {
//                    System.out.println(input[x]);
                    if (input[x].equals("W"))
                        Map[y][x] = 1;
                    else if (input[x].equals("B"))
                        Map[y][x] = 2;
                }
            }

            for (int x = 0; x < w; x++) {
                for (int y = 0; y < h; y++) {
                    if (Map[y][x] == 0) {
                        paint(x, y);
//                        System.out.println(dominant_type + " " + count);
                        if (dominant_type == 1)
                            white += count;
                        else if (dominant_type == 2)
                            black += count;
                    }
                    count = 0;
                    dominant_type = 0;

                }
            }

            System.out.println(black + " " + white);
        }
    }
}

Measured memory_bytes: 47172
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Deque<Integer> q = new ArrayDeque<>();
		if(n % 2 == 1) {
			for(int i = 0 ; i < n ; i++) {
				if(i % 2 == 0) q.addFirst(a[i]);
				else q.addLast(a[i]);
			}
		} else {
			for(int i = 0 ; i < n ; i++) {
				if(i % 2 == 1) q.addFirst(a[i]);
				else q.addLast(a[i]);
			}
		}
		while(!q.isEmpty()) {
			System.out.print(q.poll() + " ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 95636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 comb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}
int main() {
    i64 n, k;
    cin >> n >> k;
    cout << comb(n + k - 1, n) << endl;
    return 0;
}


Measured memory_bytes: 3124
H, W = gets.chomp.split(" ").map(&:to_i)
$grid = []
blk = 0
H.times do
  row = gets.chomp.split("")
  row.each do |c|
    blk += 1 if c == "#"
  end
  $grid << row
end

INF = 10**9

$d = Array.new(H + 1){Array.new(W + 1, INF)}

$dx = [1, 0, -1, 0]
$dy = [0, 1, 0, -1]

def bfs()
  que = []
  que << [0, 0]
  $d[0][0] = 0
  while !que.empty?
    pos = que.shift
    break if pos[0] == H - 1 && pos[1] == W - 1
    4.times do |i|
      nx = pos[0] + $dx[i]
      ny = pos[1] + $dy[i]
      if 0 <= nx && nx < W && 0 <= ny && ny < H && $grid[ny][nx] != "#" && $d[ny][nx] == INF then
        que << [nx, ny]
        $d[ny][nx] = $d[pos[1]][pos[0]] + 1
      end
    end
  end
  return $d[H-1][W-1]
end

res = bfs()
if res == INF then
  puts -1
else
  puts H * W - blk - (res + 1)
end

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

const vector<char> ch{'F', 'E', 'S', 'T', 'I', 'V', 'A'};

lint checker(string &s)
{
    vector<lint> dp(9);
    dp[0] = 1;
    for (auto c : s)
    {
        if (c == 'F') dp[1] += dp[0];
        if (c == 'E') dp[2] += dp[1];
        if (c == 'S') dp[3] += dp[2];
        if (c == 'T') dp[4] += dp[3];
        if (c == 'I') dp[5] += dp[4];
        if (c == 'V') dp[6] += dp[5];
        if (c == 'A') dp[7] += dp[6];
        if (c == 'L') dp[8] += dp[7];
    }
    return dp[8];
}

int main()
{
    lint K;
    cin >> K;
    string ret;
    vector<lint> digit(8);
    digit[0] = 1;
    int l = 0;
    REP(d, 60)
    {
        while (digit[l] == (1LL << (9 * l))) l++;

        if (!digit[1])
        {
            REP(i, 7) digit[i + 1] += digit[i], ret += ch[i];
        }
        else if (d < 8)
        {
            int i = 6;
            while (i > 0 and digit[i] != digit[i + 1]) i--;
            FOR(j, i, 7) digit[j + 1] += digit[j], ret += ch[j];
        }
        else
        {
            int t = digit[l] / digit[l - 1];
            // dbg(l);
            REP(_, t) digit[l] += digit[l - 1], ret += ch[l - 1];
            FOR(i, l, 7) digit[i + 1] += digit[i], ret += ch[i];
        }
        if (K & (1LL << d)) ret += 'L';
        // dbg(digit);
    }
    cout << ret << endl;
    // dbg(ret.length());
    // dbg(checker(ret));
}


Measured memory_bytes: 256