akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    cin >> n;
    vi dp(n+1,INF);
    vi v;
    v.push_back(1);
    int t = 1;
    while(1){
        t *= 6;
        if(t > n)break;
        v.push_back(t);
    }
    t = 1;
    while(1){
        t *= 9;
        if(t > n)break;
        v.push_back(t);
    }
    int m = v.size();
    //rep(i,m)cout << " " << v[i];cout << endl;
    dp[0] = 0;
    rep(i,n)rep(j,m)if(i + v[j] <= n){
        dp[i + v[j]] = min(dp[i + v[j]], dp[i] + 1);
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int x;
    cin >> x;
    rep(i, x/100+10) {
        int t = x - 100*i;
        if(t >= 0 && t <= i * 5) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
roads = [[] for _ in range(n+1)]
ans = 0

for _ in range(m):
    a, b = map(int, input().split())
    roads[a].append(b)
    roads[b].append(a)
    
for i in range(1, n+1):
    for j in roads[i]:
        if h[i] <= h[j]:
            break
    else:
        ans += 1

print(ans)  

Measured memory_bytes: 29352
def count(x):
  if x % 2 == 1:
    return 0
  return count(x/2) + 1

n = int(input())
x = [int(i) for i in input().split()]
i = 0
while i < n:
  if i == 0:
    a = count(x[0])
  if a >count(x[i]):
    a = count(x[i])
  i+=1
    
print(a)

Measured memory_bytes: 9216
from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():

        def next_permutation(a):
            """Generate the lexicographically next permutation inplace.

            https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
            Return false if there is no next permutation.
            """
            # Find the largest index i such that a[i] < a[i + 1]. If no such
            # index exists, the permutation is the last permutation
            for i in reversed(range(len(a) - 1)):
                if a[i] < a[i + 1]:
                    break  # found
            else:  # no break: not found
                return False  # no next permutation

            # Find the largest index j greater than i such that a[i] < a[j]
            j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])

            # Swap the value of a[i] with that of a[j]
            a[i], a[j] = a[j], a[i]

            # Reverse sequence from a[i + 1] up to and including the final element a[n]
            a[i + 1:] = reversed(a[i + 1:])
            return True

        alpha = list(chr(ord('a')+i) for i in range(26))

        S = input()
        if len(S) < 26:
            for i in range(len(S)):
                alpha.remove(S[i])
            return S+alpha[0]
        else:
            S = list(S)
            P = S.copy()
            next_permutation(P)
            for i in range(26):
                if P[i] != S[i]:
                    return ''.join(P[:i+1])
            return -1
    print(main())

resolve()

Measured memory_bytes: 3416
#include <iostream>
#include <utility>
#include <algorithm>

const int MAX = 1000001;

using namespace std;

pair<int, int> p[MAX];
int a[MAX];

int main() {
    unsigned long long sum = 0;
    int n, m, b, c;
    std::cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        std::cin >> p[i].second >> p[i].first;
    }
    sort(a, a + n);
    sort(p, p + m);

    int cnt = 0;
    for (int i = m - 1; i > -1; --i) {
        b = p[i].second;
        c = p[i].first;

        while (b && cnt >= 0) {
            if (a[cnt] < c)
                a[cnt] = c;
            else break;
            --b;
            ++cnt;
        }
    }

    for(int i = 0;i < n; ++i){
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 8284
"use strict";

var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}


console.log(main().toString());

function main() {
    let w = next();
    let h = next();
    let n = next();
    let xya = nextm(n, 3)
    let t1 = [];
    let t2 = [];
    let t3 = [];
    let t4 = [];
    // xyaをaでソート
    // console.log({xya})
    xya.forEach(v => {
        if (v[2] == 1) t1.push(v)
        if (v[2] == 2) t2.push(v)
        if (v[2] == 3) t3.push(v)
        if (v[2] == 4) t4.push(v)
    });
    //console.log(t1,t2,t3,t4)
    t1 = t1.length > 0 ? t1.sort((a, b) => b[0] - a[0])[0][0] : 0
    t2 = t2.length > 0 ? t2.sort((a, b) => a[0] - b[0])[0][0] : w
    t3 = t3.length > 0 ? t3.sort((a, b) => b[1] - a[1])[0][1] : 0
    t4 = t4.length > 0 ? t4.sort((a, b) => a[1] - b[1])[0][1] : h

    //console.log(t1,t2,t3,t4)
    return Math.max(t2 - t1, 0) * Math.max(t4 - t3, 0)
}

Measured memory_bytes: 7500
from collections import deque
 
N, M = map(int, input().split())
 
vec = [[] for _ in range(N)]
for _ in range(M) :
    u, v = map(int, input().split())
    vec[u-1].append(v-1)
 
S, T = map(int, input().split())
S, T = S - 1, T - 1
 
visited = [[False] * N for _ in range(3)]
visited[0][S] = True
queue = deque([(S, 0)])
 
while queue :
    q, cost = queue.popleft()

    p = (cost + 1) % 3
    for i in vec[q] :
        if p == 0 and i == T :
            
            print((cost + 1) // 3)
            exit()
        if not visited[p][i] :
            visited[p][i] = True

            queue.append((i, cost + 1))
 
print(-1)

Measured memory_bytes: 61856
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

    int n=sc.nextInt();
		int h[]=new int[n];
		int max=0;
		int count=0;

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

		for(int i=0;i<n;i++){
			if(h[i]>=max){
				max=h[i];
				count++;
			}
		}

		System.out.println(count);

	}
}


Measured memory_bytes: 21844
n=gets.to_i
a=gets.split.map &:to_i
a.sort!
if n%2==0
  b=([*0..n/2-1]*2).map{|i|i*2+1}.sort
  if a==b
    p 2**(n/2)%(10**9+7)
  else
    p 0
  end
else
  b=[0]+([*1..n/2]*2).map{|i|i*2}.sort
  if a==b
    p 2**(n/2)%(10**9+7)
  else
    p 0
  end
end

Measured memory_bytes: 12280
# https://atcoder.jp/contests/abc094/tasks/arc095_b

def comb(a, b)
  up, down = 1, 1
  1.upto(b) do |i|
    up *= a - i + 1
    down *= i
  end
  return up / down
end

n = gets.to_i
nums = gets.split.map(&:to_i).sort.reverse

res = 0

up = nums[0]
nums.delete_at(0)

target = (up.to_f / 2).round
current_diff = up

nums.each do |i|
  diff = (target - i).abs
  break if diff > current_diff
  current_diff = diff
  res = i
end

puts "#{up} #{res}"

Measured memory_bytes: 10112
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}




int main() {
  int n,i;
  cin >> n;
  i = n%10;
  if (i==2 || i==4 || i==5 || i==7 || i==9) cout << "hon\n";
  else if (i==3) cout << "bon\n";
  else cout << "pon\n";
}

Measured memory_bytes: 3636
while True:
	h,w=map(int,input().split())
	if h==w==0:break
	for hh in range(h):
		ol=''
		for ww in range(w):
			if hh == 0 or ww == 0 or hh == h - 1 or ww == w - 1:
				ol+='#'
			else:
				ol+='.'
		print(ol)
	print()

Measured memory_bytes: 7656
fun main(args: Array<String>) {
    val (l, r) = readLine()!!.split(' ').map(String::toInt)
    val ml = l % 2019
    val mr = r % 2019
    print(when{
        r - l > 2019 -> 0
        ml >= mr -> 0
        ml == 0 || mr == 0 -> 0
        else -> {
            val ls = (ml..mr).toList()
            ls.indices.flatMap { i -> (i+1 until ls.size).map { j ->
                ls[i] * ls[j] % 2019
            }
            }.min()
        }
    })
}

Measured memory_bytes: 115840
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

#define 	N 200*1000+5
int n, m;
vi v[N];
bool check[N];


void dfs(int pos, int cnt){
	if(cnt > 2) return;
	check[pos] = true;
	rep(i,0,sz(v[pos]))
		if(!check[v[pos][i]])
			dfs(v[pos][i], cnt+1);
}
void solve(){
	cin>>n>>m;
	rep(i,0,m){
		int a, b;
		cin>>a>>b;
		a--, b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs(0,0);
	if(check[n-1])cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 12144
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from bisect import bisect_right, bisect_left
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    l = sorted(map(int, input().split()))

    o = 0
    c = []

    for i in range(n):
        for j in range(i):
            a, b = l[i], l[j]

            s = bisect_right(l, a - b)
            e = bisect_left(l, a + b)

            o += max(0, e - max(s, i + 1))

    print(o)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

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

# endregion

if __name__ == "__main__":
    main()


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

int main() {
  long long N, M;
  cin >> N >> M;
  if (N == 1LL && M == 1LL) {
    printf("1");
  } else if (N == 1LL || M == 1LL) {
    printf("%lld", N * M - 2LL);
  } else {
    printf("%lld", N * M - 2LL * (N + M - 2LL));
  }
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

static const int INF = 0x3f3f3f3f;

int main() {
        int n;
        while (scanf("%d", &n), n) {
                vector<int> p(n + 1), t(n + 1);
                for (int i = 0; i < n; i ++) scanf("%d%d", &p[i + 1], &t[i + 1]);
                vector<vector<int>> dp(n + 1, vector<int> (4, INF));
                dp[0][0] = 0;
                for (int i = 1; i <= n; i++) {
                        for (int j = 1; j <= 3; j++) {
                                int D = p[i - 1] + p[i];
                                int T = p[i - 1] * (j + 1) + p[i];
                                if(t[i] - t[i - 1] >= T) dp[i][1] = min(dp[i][1], dp[i - 1][j] + D);
                        }
                        for (int j = 0; j <= 2; j++) {
                                int D = abs(p[i - 1] - p[i]);
                                int T = D * (j + 1);
                                if (t[i] - t[i - 1] >= T) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + D);
                        }
                }
                int ans = INF;
                for (int i = 1; i <= 3; i++) ans = min(ans, dp[n][i] + p[n]);
                if (ans != INF) {
                        printf("OK %d\n", ans);
                } else {
                        ans = 0;
                        for (int i = 1; i <= n; i++) {
                                if (dp[i][1] == INF && dp[i][2] == INF && dp[i][3] == INF) {
                                        ans = i;
                                        break;
                                }
                        }
                        printf("NG %d\n", ans);
                }
        }
        return 0;
}

Measured memory_bytes: 2804
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + j*100 + k*50 == x:
                count += 1

print (count)


Measured memory_bytes: 3060
# ABC074 C - Sugar Water
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b,c,d,e,f = nm()
L =[]
for aa in range(0,31):
    for bb in range(0,31):
        for cc in range(0,101):
            for dd in range(0,101):
                if 100*a<=100*a*aa+100*b*bb+c*cc+d*dd<=f:
                    L.append((aa,bb,cc,dd))

max_w = 0.0
idx = 10*7
for i,l in enumerate(L):
    # water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    sugar = c*l[2]+d*l[3]
    if (100+e)*100*sugar<=(100*e)*water:
        # if water!=0 and (l[0]>0 or l[1]>0):
        if l[0]>0 or l[1]>0:
            t = (sugar/water)*100
            if t>=max_w:
                max_w=t
                idx = i

for i,l in enumerate(L):
    if i==idx:
        water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
        sugar = c*l[2]+d*l[3]
        print(water,sugar)
        exit()



Measured memory_bytes: 73020
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

int H, W;
char hw[60][60];

char solv(int i, int j) {
	if (hw[i][j] == '#')  return '#';
	else {
		int count = 0;
		repi(p, i - 1, i + 2) {
			repi(q, j - 1, j + 2) {
				if (p == i && q == j)continue;
				if (hw[p][q] == '#')count++;
			}
		}
		return (char)('0' + count);
	}
}

int main() {
	cin >> H >> W;
	repi(i, 1, H + 1) {
		repi(j, 1, W + 1) {
			cin >> hw[i][j];
		}
	}
	repi(i, 1, H + 1) {
		repi(j, 1, W + 1) {
			cout << solv(i, j);
		}
		cout << endl;
	}
	
	return 0;
}

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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;

using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> dp(100015,0);
    rep(i,100015){
        dp[i] = i;
    }

    for(int i = 6; i <= 100001; i *= 6){
        for(int j = i; j <= 100001; j++){
            dp[j] = min(dp[j],dp[j-i]+1);
        }
    }

    for(int i = 9; i <= 100001; i *= 9){
        for(int j = i; j <= 100001; j++){     
            dp[j] = min(dp[j],dp[j-i]+1);
        }
    }

    rep(i,100015){
        dp[i] = min(dp[i],dp[i-1]+1);
    }

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/A_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
R=N%1000
if R==0:
    print(R)
else:
    print(1000-(N%1000))
f.close()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s;
    cin>>s;
    ll z=0,o=0,n=s.size();
    rep(i,n){
        if(s[i]=='0') z++;
        else o++;
    }
    cout << 2*min(z,o) << endl;
    return 0;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int main(){
  int i,j,n,c=0;
  double x[50],y[50],a[50],ans;
  while(1){
    cin >> n;
    if(n == 0) break;
    ans = 0;
    for(i=0;i<n;i++) cin >> x[i] >> y[i];
    for(i=0;i<n;i++){
      ans += (x[i] - x[(i+1)%n]) * (y[i] + y[(i+1)%n]);
    }
    ans /= -2;
    cout << ++c << " ";
    printf("%.1f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
float x[100],y[100],t,u,a,b;n,i,j,k,c,s;main(m){for(;m=scanf("%d",&n),c=i=n;printf("%d\n",m))for(;j=c?scanf("%f,%f",x+c,y+--c):--i;)for(;s=!c&&j--;)for(u=acos(hypot(a=x[j]-x[i],b=y[j]-y[i])/2),t=atan2(b,a);c=0,u<9&&s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}

Measured memory_bytes: 0
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

ll calc(ll a){
  if(a <= 0) return 0;
  a++;
  ll ans = 0;
  rep(i,50){
    ll loop = (1LL << (i+1));
    ll cnt = (a/loop)*(loop/2);
    cnt += max(0LL,(a%loop)-(loop/2));
    
    if(cnt%2 == 1){
      ans += 1LL << i;
    }
  }
  
  return ans;
}

int main() {
  ll a,b; cin >> a >> b;
  ll ans = calc(b) ^ calc(a-1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x, y; cin >> x >> y;
    rep(a, 100) rep(b, 100) {
    	if(a+b == x && 2*a+4*b==y) {
    		cout << "Yes" << endl;
    		return 0;
    	}
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3608
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int[] d = {a,b,c};
		
		if(d[0] > d[1]){
			int e = d[0];
			d[0] = d[1];
			d[1] = e;
		}
		if(d[1] > d[2]){
			int f = d[1];
			d[1] = d[2];
			d[2] = f;
		}
		if(d[0] > d[1]){
			int e = d[0];
			d[0] = d[1];
			d[1] = e;
		}
		
		System.out.println(d[0] + " " + d[1] + " " + d[2]);
	}
}


Measured memory_bytes: 26236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            Main main = new Main();

            // main.solveA(sc);
            main.solveB(sc);
            // main.solveC(sc);

        }
    }

    private void solveC(Scanner sc) {

    }

    void solveB(Scanner sc) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(br.readLine());
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = Integer.parseInt(br.readLine());
            }

            long sum = 0;
            for (int i = 0; i < n - 1; i++) {
                sum += (nums[i] / 2);
                if (nums[i] % 2 > 0 && nums[i + 1] > 0) {
                    sum++;
                    nums[i + 1]--;
                }
            }

            sum += (nums[n - 1] / 2);

            System.out.println(sum);

        } catch (IOException e) {

        }

    }

    void solveA(Scanner sc) {
        String s = sc.next();
        if (s.indexOf("N") >= 0 && s.indexOf("S") < 0) {
            System.out.println("No");
            return;
        }
        if (s.indexOf("S") >= 0 && s.indexOf("N") < 0) {
            System.out.println("No");
            return;
        }
        if (s.indexOf("W") >= 0 && s.indexOf("E") < 0) {
            System.out.println("No");
            return;
        }
        if (s.indexOf("E") >= 0 && s.indexOf("W") < 0) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 19920
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,fun[100005][10],ans,dp[100005][10]={};
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>fun[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
	if(k!=j){
	  dp[i+1][j]=max(dp[i+1][j],dp[i][k]+fun[i][j]);
	}
      }
    }
  }
  ans=max(dp[n][0],dp[n][1]);
  ans=max(dp[n][2],ans);
  cout<<ans<<endl;
  return(0);
}

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

ll x,m,k,y,z,sum,dp[1005][1005];
char ar[1005][1005];

int main() {
	scanf("%lld%lld",&x,&y);
	dp[x][y+1] = 1;
	for (int a = 1; a <= x; a++) for (int b = 1; b <= y; b++) cin >> ar[a][b];
	while (x != 0 && y != 0) {
		for (int a = x; a >= 1; a--) if (ar[a][y] != '#') dp[a][y] = (dp[a][y+1]+dp[a+1][y])%MOD; else dp[a][y] = 0;
		for (int a = y; a >= 1; a--) if (ar[x][a] != '#') dp[x][a] = (dp[x][a+1]+dp[x+1][a])%MOD; else dp[x][a] = 0;
		x--; y--;
	}
	cout << dp[1][1]%MOD << "\n";
	return 0;
} 

Measured memory_bytes: 9088
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()
print(N-K+1)


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

using namespace std;
#define int long long
const int INF = 200000000007;


 
signed main(){
    int n;
    cin>>n;
    int p[n],t=0;
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=1;i<n-1;i++){
        if(p[i-1]<p[i]&&p[i]<p[i+1])t++;
        if(p[i+1]<p[i]&&p[i]<p[i-1])t++;
    }
    cout<<t;
    
  
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;

int main(){
	int n;
	cin >> n;
	ll ans = 0;
	int prev;
	cin >> prev;
	ans += prev / 2;
	prev %= 2;
	for(int i=1;i<n;i++){
		int num;
		cin >> num;
		if(prev && num){
			num--;
			ans++;
		}
		ans += num / 2;
		prev = num % 2;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define swap(X , Y) {int Z ; Z = Y ; Y = X , X = Z}

int main()
{
	int a, i=1;
	while(scanf("%d", &a) && (a != 0))
	{
		printf("Case %d: %d\n", i++, a);
	}

	return 0;
} 


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

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

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

    int ans = 0;
    int i = 0;
    while(true){
        if(i >= n - 1) break;

        i += (k - 1);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    char S[1001];

    scanf("%s", S);

    bool containsN = false;
    bool containsW = false;
    bool containsS = false;
    bool containsE = false;

    const size_t len = strlen(S);

    for (size_t i = 0; i < len; i++) {
        if (S[i] == 'N') {
            containsN = true;
        }
        else if (S[i] == 'W') {
            containsW = true;
        }
        else if (S[i] == 'S') {
            containsS = true;
        }
        else {
            containsE = true;
        }
    }

    puts(((containsN && containsS) || (!containsN && !containsS)) && ((containsW && containsE) || (!containsW && !containsE)) ? "Yes" : "No");

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x;
	FOR(i,1,6){
		cin>>x;
		if(x==0){
			cout<<i<<endl;
			return 0;
		}
	}

    return 0;
}




Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

const int maxn = 100010;
int N,A[maxn];

inline int gi()
{
	int ret = 0,f = 1; char ch;
	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
	if (ch == '-') f = -1,ch = getchar();
	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
	return ret*f;
}

int main()
{
	//freopen("A.in","r",stdin);
	//freopen("A.out","w",stdout);
	N = gi(); int ans = 0;
	for (int i = 1;i <= N;++i) A[i] = gi();
	for (int i = 1;i <= N;)
	{
		++ans;
		if (i >= N) break;
		else
		{
			int j1 = i+1,j2 = i+1;
			if (A[i+1] >= A[i]) for (j1 = i+1;j1 <= N&&A[j1] >= A[j1-1];++j1);
			if (A[i+1] <= A[i]) for (j2 = i+1;j2 <= N&&A[j2] <= A[j2-1];++j2);
			i = max(j1,j2);
		}
	}
	cout << ans << endl;
	//fclose(stdin); fclose(stdout);
	return 0;
}


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

int main() {
  int X, Y, Z;
  // int N, M;
  cin >> X >> Y >> Z;
  swap(X, Y);
  swap(X, Z);
  cout << X << " " << Y << " " << Z << endl;
}

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

mod=10**9+7

def prime_fact(x):
    fact=[]
    for i in range(2, int(x**(0.5))+1):
        while x%i==0:
            fact.append(i)
            x//=i
    if x!=1:
        fact.append(x)
    if not fact:
        fact=[x]
    return fact

def eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

era=eratosthenes(n)
d={}
for key in era:
    d[key]=0

for i in range(2,n+1):
    prime_list=prime_fact(i)
    for prime in prime_list:
        d[prime]+=1

ans=1
for key in d:
    ans*=(d[key]+1)%mod

print(ans%mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin>>s;
    int m = stoi(s.substr(5,2));
    cout<<(m <= 4 ? "Heisei" : "TBD")<<endl;

    return 0;
}


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

int main() {
  string s;cin>>s;
  long long sum=0;
  for(int i=0;i<(1<<s.size()-1);i++) {
    bitset<9> key(i);
    int temp=0;
    long long temp_sum=0;
    for(int j=0;j<s.size()-1;j++) {
      if(key.test(j)) {
        if(temp==j) {
          temp_sum+=int(s.at(temp)-48);
        }
        else {
          temp_sum+=stoll(s.substr(temp,j-temp+1));
        }
        temp=j+1;
      }
    }
    if(temp==s.size()-1) {
      temp_sum+=int(s.at(temp)-48);
    }
    else {
      temp_sum+=stoll(s.substr(temp));
    }
    //cout << temp_sum << endl;
    sum+=temp_sum;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)
using namespace std;
const int maxn = 1e5 + 7;
LL fac[maxn], inv[maxn];
LL ksm(LL a, LL b)
{
    LL res = 1, base = a;
    while (b)
    {
        if (b & 1) res = MOD(res * base);
        base = MOD(base * base);
        b /= 2;
    }
    return res;
}
int n, k;
LL ans = 1;
LL cal(int n, int m) 
{
    if (n < m) return 0;
    return MOD(fac[n] * inv[n - m]);
}
vector<int>E[maxn];
void dfs(int u, int fa)
{
    for (int v : E[u])
    {
        if (v == fa) continue;
        dfs(v, u);
    }
    if (fa == -1) ans = MOD(ans * cal(k - 1, E[u].size()));
    else ans = MOD(ans * cal(k - 2, E[u].size() - 1));
}
int main()
{
	scanf("%d%d", &n, &k);
    fac[0] = 1; for (int i = 1; i <= 100000; i++) fac[i] = MOD(fac[i - 1] * i);
    inv[100000] = ksm(fac[100000], mod - 2); inv[0] = 1;
    for (int i = 100000 - 1; i >= 1; i--) inv[i] = MOD(inv[i + 1] * (i + 1));
    for (int i = 1; i < n; i++)
    {
        int u, v; scanf("%d%d", &u, &v);
        E[u].pb(v); E[v].pb(u);
    }
    ans = k;
    dfs(1, -1);
    printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005;
bool vis[N];
int cnt[N];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	ll resp = 0, resa = 0;
	while (m--) {
		int p;
		string s;
		cin >> p >> s;
		if (vis[p]) continue;
		if (s[0] == 'W') {
			cnt[p]++;
		} else {
			vis[p] = true;
			resa++;
			resp += cnt[p];
		}
	}
	cout << resa << " " << resp;
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool dp[13][1<<(12*2)];
int main()
{
    
    int n; cin >> n;
    while(n--){
    	string s,t; cin >> s >> t;
    	int k = t.size(), tmp=0;
    	for(int i=0 ; i<k ;i++){
    		tmp *=4;
    		if(t[i] == 'A') tmp+=0;
    		if(t[i] == 'T') tmp+=1;
    		if(t[i] == 'C') tmp+=2;
    		if(t[i] == 'G') tmp+=3;
    	}   	
    	if(s == "insert") dp[k][tmp] =1; 
    	else{
    		cout << (dp[k][tmp]? "yes" : "no") << endl;
    	}
    }


    return 0;
}



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

using namespace std;

typedef long long ll;

ll n,A[200050],B[200050];
ll Ac[200050], Bc[200050];

bool compute(int x){
//	ll cnt = 0;
//	for(ll i = 0; i<n; i++){
//		for(ll j = 0; j<n; j++){
//			if((A[i]+B[j])>>x & 1) cnt++;
//		}
//	}
//	return cnt%2;
	ll mod = 1<<(x+1);
	ll T = 1<<x;
	for(int i = 0; i<n; i++){
		Ac[i] = A[i]%mod;
		Bc[i] = B[i]%mod;
	}
	sort(Bc, Bc+n);
	ll cnt = 0;
	for(ll i = 0; i<n; i++){
//		for(int j = 0; j<n; j++){
//			ll cur = Bc[j];
//			if( cur >= T-A[i] and cur < 2*T-A[i] ) cnt++;
//			else if(cur >= 3*T-Ac[i] and cur < 4*T-A[i] ) cnt++;
		cnt+=-1+lower_bound(Bc, Bc+n, 2*T-Ac[i])-lower_bound(Bc, Bc+n, T-Ac[i]);
		cnt+=-1+lower_bound(Bc, Bc+n, 4*T-Ac[i])-lower_bound(Bc, Bc+n, 3*T-Ac[i]);
//		}
	}
	return cnt%2;
}

int main(){
//	freopen("input.txt", "r", stdin);
	cin >> n;
	for(ll i = 0; i<n; i++){
		cin >> A[i];
	}
	for(ll i = 0; i<n; i++) cin >> B[i];
	ll ans = 0;
	for(int i = 0; i<=29; i++){
//		printf("%d ", i);
		if(compute(i) == 1) ans += 1 << i;
	}
	cout << ans;
}

Measured memory_bytes: 6528
def f(a,b,c):
	return a*a+b*b+c*c+a*b+b*c+c*a
n=int(input())
ans=[0]*n
r=int(n**0.5)+1
for i in range(1,r+1):
	for j in range(1,r+1):
		for k in range(1,r+1):
			if f(i,j,k)<=n:
				ans[f(i,j,k)-1]+=1
			else:
				break
for x in ans:
	print(x)

Measured memory_bytes: 9456
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

void A_146()
{
  string S;
  cin >> S;

  vector<string> week{ "SUN","MON","TUE","WED","THU","FRI","SAT" };

  for (int i = 0; i < week.size(); ++i)
  {
    if (week[i] == S)
    {
      cout << 7 - i << endl;
      return;
    }
  }
  
}

int main()
{
  //C_140();
  //C_141();
  //C_142();
  //C_143();
  //C_144();
  //C_145();
  //C_146();
  //C_147();
  //C_148();
  //C_149();
  //A_149();
  //B_149();
  //A_148();
  //B_148();
  //A_147();
  //B_147();
  A_146();
  return 0;
}


Measured memory_bytes: 256
fun main() {
  val (H, W, K) = readInts()
  val C = (1..H).map { readString() }

  fun newC(): Array<Array<Char>> {
    val array = Array(H) { Array(W) { '.' } }
    for (h in 0 until H) {
      for (w in 0 until W) {
        array[h][w] = C[h][w]
      }
    }
    return array
  }

  var ans = 0
  for (hb in 0 until 1.shl(H)) {
    for (wb in 0 until 1.shl(W)) {
      val c = newC()
      for (h in 0 until H) {
        for (w in 0 until W) {
          val hf = hb.and(1.shl(h)) > 0
          val wf = wb.and(1.shl(w)) > 0
          if (hf || wf) c[h][w] = 'x'
        }
      }
      var cnt = 0
      for (h in 0 until H) {
        for (w in 0 until W) {
          if (c[h][w] == '#') cnt++
        }
      }
      if (cnt == K) ans++
    }
  }
  println(ans)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 39388
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans;
  if((b - a) % 2) {
    ans = min(n - b, a - 1) + 1 + (b - a - 1) / 2;
  } else {
    ans = (b - a) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
bool isThere(int x, int arr[], int len){
	for (int i=0; i<len; i++){
		if (arr[i]==x){
			return true;
		}
	}
	return false;
}
int main() {
	int price;
    int len;
    cin >> price>>len;
    int arr[len];
    for (int i=0; i<len; i++){
    	cin>>arr[i];
    }
    for (int i=price; i<100000; i++){
    	string ss = to_string(i);
    	int sslen=ss.length();
    	int ssarr[sslen];
    	for(int i=0; i<sslen; i++){
    		ssarr[i]=ss[i]-'0';
    	}
    	int sum=0;
    	for (int i=0; i<sslen; i++){
    		if (!isThere(ssarr[i], arr, len)) sum++ ;
    	}
    	if (sum==sslen){
    		cout << i << endl;	
    		break;
    	} 
    }
    
    	
}
 

Measured memory_bytes: 256
import bisect
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        L = list(map(int, input().split()))

        ans = 0
        L.sort()

        for i in range(N - 2):
            for j in range(i + 1, N - 1):
                ind = bisect.bisect_left(L, L[i] + L[j])
                ans += ind - j - 1

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
ll n,k;
cin>>n>>k;
ll ans = k;
rep(i,n-1){
    ans *= k-1;
}
cout<<ans<<endl;
   return 0;
}


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

int main(void) {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = A[i] - (i + 1);
    }
    sort(A.begin(), A.end());
    long long ans = LLONG_MAX;
    long long mid = N / 2;
    long long tmp = 0;
    for (int i = 0; i < N; i++) {
        tmp += abs(A[mid] - A[i]);
    }
    ans = min(tmp, ans);
    if (N % 2 != 0) {
        mid = (N + 1) / 2;
        tmp = 0;
        for (int i = 0; i < N; i++) {
            tmp += abs(A[mid] - A[i]);
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);++i)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int N,M; cin>>N>>M;
	ll h = N - 2, w = M - 2;

	ll ans = 0;
	if(h<0 && w<0){
		ans = 1;
	}
	else if(h<0 || w<0){
		ans = max(h, w);
	}
	else{
		ans = h * w;
	}
	ote(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::map<int, int > mp;
  int a, b;
  for (int i=0; i<M; i++){
    scanf("%d", &a);
    scanf("%d", &b);
    mp[a]++;
    mp[b]++;
  }
  bool ok = true;
  for (auto &entry: mp){
    if (entry.second%2==1){
      ok=false;
      break;
    }
  }
  printf("%s\n", ok?"YES":"NO");
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int a,b; cin>>a>>b;
    cout<<max({a+(a-1),a+b,b+(b-1)});
    return 0;
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

const int mod = 1e9+7, sh = 1275 + 51;
int dp[2][51][2 * sh];

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

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, z;
	cin >> n >> z;

	if (z & 1)
	{
		cout << "0\n";
		return 0;
	}

	dp[0][0][sh] = 1;
	const int g = n*(n+1)/2;
	for (int i = 0; i < n; ++i)
	{
		auto &cur = dp[i&1];
		auto &ndp = dp[~i&1];
		memset(ndp, 0, sizeof ndp);
		for (int j = 0; j < n; ++j)
			for (int l = sh-g; l <= sh+g; ++l)
			{
				add(ndp[j][l], (2*j+1LL) * cur[j][l] % mod);
				if (j) add(ndp[j-1][l+i+1], (ll)j*j*cur[j][l] % mod);
				add(ndp[j+1][l-i-1], cur[j][l]);
			}
	}
	cout << dp[n&1][0][sh+z/2] << "\n";

	return 0;
}


Measured memory_bytes: 1280