akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(){
    char a;
    cin >> a;
    if(a == 'A')cout << "T" << endl;
    else if (a == 'C')cout << "G" << endl;
    else if (a == 'G')cout << "C" << endl;
    else cout << "A" << endl;
 }


Measured memory_bytes: 256
# UnionFind
#############################################################
class UnionFind:

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, v):  # vが属する集合の根を返す
        if self.parents[v] < 0:
            return v
        else:
            self.parents[v] = self.find(self.parents[v])
            return self.parents[v]

    def unite(self, u, v):  # 「uが属する集合」と「vが属する集合」を併合（根同士を結ぶ）
        u = self.find(u)
        v = self.find(v)
        if u == v:
            return
        if self.parents[u] > self.parents[v]:  # u < v に統一する
            u, v = v, u
        self.parents[u] += self.parents[v]
        self.parents[v] = u

    def size(self, v):  # vが属する集合の要素数
        return -self.parents[self.find(v)]

    def same(self, u, v):  # uとvが同じ集合に属するか否か
        return self.find(u) == self.find(v)
#############################################################

N = int(input())
XY = [list(map(int, input().split())) + [i] for i in range(N)]

X = sorted(XY, key=lambda x: x[0])
Y = sorted(XY, key=lambda x: x[1])

dist = []
for i in range(N - 1):
    # iとi+1の距離、iのindex, i+1のindex
    dist.append([X[i + 1][0] - X[i][0], X[i][2], X[i + 1][2]])
    dist.append([Y[i + 1][1] - Y[i][1], Y[i][2], Y[i + 1][2]])

ans = 0
dist.sort(key=lambda x: x[0])

uf = UnionFind(N)
# クラスカル法
for cost, i, j in dist:
    if uf.same(i, j):
        continue
    uf.unite(i, j)
    ans += cost

print(ans)


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

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

    int bit;
    for (int i = 0; i < (1 << 3); i++) {
        int res = s[0] - '0';
        for (int j = 0; j < 3; j++) {
            if (i & (1 << j)) res += s[j + 1] - '0';
            else res -= s[j + 1] - '0';
        }
        if (res == 7) bit = i;
    }

    string ans = to_string(s[0] - '0');
    for (int i = 0; i < 3; i++) {
        if (bit & (1 << i)) ans += "+" + to_string(s[i + 1] - '0');
        else ans += "-" + to_string(s[i + 1] - '0');
    }

    ans += "=7";

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>
static std::vector<long long int> memo;
void cal_runrun(const int k, const int rest_digit, const int digit, const long long int result) {
	if (memo.size() >= k) return;
	if (rest_digit == 1) {
		memo.push_back(result);
		return;
	}
	if (digit > 0) cal_runrun(k, rest_digit - 1, digit - 1, result * 10 + digit - 1);
	cal_runrun(k, rest_digit - 1, digit, result * 10 + digit);
	if (digit < 9) cal_runrun(k, rest_digit - 1, digit + 1, result * 10 + digit + 1);
}
int main() {
	int k; std::cin >> k;
	for (auto digit = 1; digit < 16; ++digit) {
		for (auto head = 1; head < 10; ++head) {
			cal_runrun(k, digit, head, head);
		}
	}
	std::cout << memo[k - 1] << std::endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = a + b + c;
  ans -= max(max(a, b), c);
  cout << ans << endl;
}


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

using namespace std;

const int MAX = 100;
int adj[MAX][MAX] = {};

class BFS{
    int num, d[MAX], status[MAX];
public:
    BFS(int n) : num(n){
        for(int i=0;i<n;i++){
            d[i] = -1;
            status[i] = 0;
        }
    }

    void run(int node){
        queue<int> Q;
        Q.push(node);
        d[node] = 0;
        status[node] = 1;
        while(!Q.empty()){
            node = Q.front(); Q.pop();
            for(int i=0;i<num;i++){
                if(adj[node][i] && status[i] == 0) {
                    Q.push(i);
                    d[i] = d[node] + 1;
                    status[i] = 1;
                }
            }
        }
    }

    void print(){
        for(int i=0;i<num;i++){
            cout << i+1 << " " << d[i] << endl;
        }
    }
};

int main(){
    int r, c, n_c, n;
    cin >> n;
    BFS bfs(n);

    for(int i=0;i<n;i++){
        cin >> r >> n_c;
        for(int j=0;j<n_c;j++){
            cin >> c;
            adj[r-1][c-1]++;
        }
    }

    bfs.run(0);
    bfs.print();
}


Measured memory_bytes: 3120
a=input().split(' ')
b=input().split(' ')
a[0]=int(a[0])
a[1]=int(a[1])
m=0
while m<a[1]:
    b[m]=int(b[m])
    a[0]=a[0]-b[m]
    if a[0]<=0:
        m=m+a[1]
        print('Yes')
    m=m+1
if a[0]>0:
    print('No')

Measured memory_bytes: 10712
import collections

def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()], reverse=True)
    if len(vals) == 1:
        if vals[0] == 1: return YES
        else: return NO
    elif len(vals) == 2:
        if vals[0] == 1 and vals[1] == 1: return YES
        else: return NO
    
    _max = vals[0]
    _sum = sum(vals[1:])
    if (_max-1)*2 <= _sum:
        if vals[1]-vals[2] > 1: return NO
        else: return YES
    return NO

s = input()
print(answer(s))

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

int main() {
  int a, b, c, k, ans=0;
  cin >> a >> b >> c >> k;
  for(int i=1; i<=k; i++) {
    if(i<=a) {
      ans++;
    }
    else if(i<=a+b) {
    }
    else if(i<=a+b+c) {
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll linf=1e18;
const int inf=1001001001;
const ll mod=1e9+7; // 998244353 = (119<<23)+1
// head
const int nax=1e5+7;
vector<pii> edge[nax];
int n,mc,col[nax];
void bfs(int v) {
	queue<pii> q;
	q.push(mp(v,0));
	while(!q.empty()) {
		pii u=q.front();
		q.pop();
		mc=max(mc,sz(edge[u.fi]));
		int des=1;
		for(auto a:edge[u.fi]) {
			if(col[a.se]) continue;
			if(des==u.se) des++;
			col[a.se]=des;
			des++;
			q.push(mp(a.fi,col[a.se]));
		}
	}
}
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>n;
		rep(i,0,n-1) {
			int a,b;
			cin>>a>>b;
			edge[a].pb(mp(b,i));
			edge[b].pb(mp(a,i));
		}
		bfs(1);
		cout<<mc<<'\n';
		rep(i,0,n-1) cout<<col[i]<<'\n';
		return 0;
}

Measured memory_bytes: 7040
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m):
        e = [[0]*n for _ in range(n)]
        cs = []
        for _ in range(m):
            a,b,c = LI_()
            c += 1
            e[a][b] = c
            e[b][a] = c
            cs.append([a,b])

        r = 0
        while cs:
            ns = []
            for a in cs:
                t = 0
                for i in a:
                    m = inf
                    for j in a:
                        if i == j:
                            continue
                        if m > e[i][j]:
                            m = e[i][j]
                    t += m
                if r < t:
                    r = t
                for i in range(a[-1]+1,n):
                    f = True
                    for j in a:
                        if e[i][j] < 1:
                            f = False
                            break
                    if f:
                        ns.append(a + [i])
            cs = ns

        return r


    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))
        # print('rr', rr[-1])
        break

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 13596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = (int)1e8 + 5;
const int N = 1010;
int n, m;
char s[N][N];
int dist[N][N];
const int DX[] = {-1, 1, 0, 0};
const int DY[] = {0, 0, -1, 1};
int q[N * N][2];
int topQ;

bool checkCell(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < m;
}

void addQ(int x, int y) {
	q[topQ][0] = x;
	q[topQ][1] = y;
	topQ++;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
		for (int j = 0; j < m; j++) {
			dist[i][j] = INF;
			if (s[i][j] == '#') {
				dist[i][j] = 0;
				addQ(i, j);
			}
		}
	}
	for (int i = 0; i < topQ; i++) {
		int x = q[i][0], y = q[i][1];
		for (int d = 0; d < 4; d++) {
			int xx = x + DX[d], yy = y + DY[d];
			if (!checkCell(xx, yy)) continue;
			if (dist[xx][yy] <= dist[x][y] + 1) continue;
			dist[xx][yy] = dist[x][y] + 1;
			addQ(xx, yy);
		}
	}
	printf("%d\n", dist[q[topQ - 1][0]][q[topQ - 1][1]]);

	return 0;
}


Measured memory_bytes: 13692
N,K = [int(v) for v in input().split()]

have = [0 for _ in range(N)]
for _ in range(K):
    d = int(input())
    a = [int(v) for v in input().split()]
    for v in a:
        have[v-1] += 1

ans = 0
for v in have:
    if v == 0: ans+=1
print(ans)


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;
typedef map<int, arr> graph;
typedef vector<char> chararr;
typedef vector<chararr> charmat;
typedef pair<int, int> fraction;
ll MOD = 1000000007;
int n;
ll slimes[400];
ll pref[400];
longmat dp(400, longarr(400, -1));
ll psum(int i, int j) {
	ll ans = 0;
	ans += pref[j];
	if (i != 0) ans -= pref[i - 1];
	return ans;
}
ll fun(int i, int j) {
	if (i == j) return 0;
	ll &ans = dp[i][j];
	if (ans != -1) return dp[i][j];
	ans = LLONG_MAX;
	for (int k = i; k < j; ++k) {
		ans = min(ans, fun(i, k) + fun(k + 1, j) + psum(i, k) + psum(k + 1, j) );
	}
	return ans;
}

int main() {

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> slimes[i];
	}
	partial_sum(slimes, slimes + n, pref);
	cout << fun(0, n - 1);

}

Measured memory_bytes: 4936
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<int> tree[100010];
ll dp[100010] = {};
ll N,M;
ll ans[100010] = {};

void dfs(ll cur, ll par){
    dp[cur] = 1;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        dp[cur] *= dp[e];
        dp[cur] %= M;
    }
    (dp[cur] += 1) %= M;
}


void dfs2(ll cur, ll par){
    ans[cur] = (dp[cur] - 1 + M) % M;
    vector<ll> mul, mul_left, mul_right;
    for(auto &e: tree[cur]){
        mul.push_back(e);
    }
    sort(mul.begin(), mul.end());

    ll cc = 1;
    mul_left.push_back(cc);
    for(auto &e: mul){
        (cc *= dp[e]) %= M;
        mul_left.push_back(cc);
    }
    cc = 1;
    mul_right.push_back(cc);
    reverse(mul.begin(), mul.end());
    for(auto &e: mul){
        (cc *= dp[e]) %= M;
        mul_right.push_back(cc);
    }
    reverse(mul.begin(), mul.end());

    for(auto &e: tree[cur]){
        if(e == par) continue;
        ll ps = lower_bound(mul.begin(), mul.end(), e) - mul.begin();
        ll sz = mul.size();
        ll val = mul_left[ps] * mul_right[sz - ps - 1] % M;

        ll prev_cur = dp[cur];
        ll prev_e = dp[e];
        (dp[cur] = val + 1) %= M;
        (dp[e] = (dp[e] - 1 + M) * dp[cur] % M + 1) %= M;

        dfs2(e, cur);
        dp[cur] = prev_cur;
        dp[e] = prev_e;
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    
    rep(i,0,N-1){
        ll x,y;
        cin >> x >> y;
        x--; y--;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    dfs(0, -1);
    dfs2(0, -1);
    rep(i,0,N) print(ans[i]);
}

Measured memory_bytes: 31104
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
vl divisor(ll n) {
	vl ret;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i != 1 && i * i != n) ret.push_back(n / i);
		}
	}
	ret.push_back(n);
	return ret;
}

int main() {
	cin >> N;
	for (k = 1; k <= N; k++) {
		ll p = N / k;
		ll pre = (p * (p + 1) / 2) * k;
		ans += pre;
	}
	cout << ans;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> l(n);
  rep(i,n) cin >> l[i];
  int cnt = 0;
  for (int i = 1; i < n - 1;i++){
    if((l[i-1]<l[i] && l[i]<l[i+1]) || l[i-1]>l[i] && l[i]>l[i+1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

int N, A[200];

int main()
{
	int dmin = 100;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int A;
		scanf("%d", &A);
		int d = 0;
		while (A % 2 == 0) {
			A /= 2;
			++d;
		}
		dmin = min(dmin, d);
	}
	printf("%d\n", dmin);
	return 0;
}


Measured memory_bytes: 1704
from sys import stdin
import bisect
        
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()

ans = 0
for a in range(len(L)-2):
    for b in range(a + 1, len(L)-1):
        c = bisect.bisect_left(L, L[a] + L[b])
        if c > b:
            ans += c - 1 - b

print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

#define MAX 7368791


int main(void)
{
	int m, n;
	bool year[MAX];
	
	while(1){
		scanf("%d %d", &m, &n);
		if(m == 0 && n == 0) break;
		
		for(int i = 0; i < MAX; i++) year[i] = false;
		
		int seed = 0;
		for(int i = m; i <= MAX; i++){
			if(!year[i-1]){
				if(seed < n){
					for(int j = i; j <= MAX; j += i) year[j-1] = true;
					seed++;
				}else{
					seed = i;
					break;
				}
			}
		}
		
		printf("%d\n", seed);
	}
	
	return 0;
}
		

Measured memory_bytes: 9856
N,A = (int(T) for T in input().split())
X = [int(T) for T in input().split()]
DP = [[[0]*(N+1) for TS in range(0,50*N+1)] for TI in range(0,N+1)]
DP[0][0][0] = 1
for TI in range(0,N):
    for TS in range(0,50*N+1):
        for TK in range(0,N+1):
            if DP[TI][TS][TK]!=0:
                DP[TI+1][TS][TK] += DP[TI][TS][TK]
                DP[TI+1][TS+X[TI]][TK+1] += DP[TI][TS][TK]
print(sum(DP[N][A*TA][TA] for TA in range(1,N+1)))

Measured memory_bytes: 83752
using System;
    class Program
{
    static void Main(string[] args)
    {
        int i;
        string[] lines = Console.ReadLine().Split(' ');
        int n = int.Parse(lines[0]);
        int x = int.Parse(lines[1]);
        int t = int.Parse(lines[2]);

        for(i = 0; n > 0; i++)
        {
            n = n - x;
        }
        Console.WriteLine(i*t);
    }
}

Measured memory_bytes: 27300
import collections
N = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i in range(N):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
EC = collections.Counter(E).most_common()
OC = collections.Counter(O).most_common()
if len(EC) == 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2)
    else:
        print(0)
elif len(EC) == 1 and len(OC) != 1:
    if EC[0][0] == OC[0][0]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N//2-OC[0][1])
elif len(EC) != 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2-EC[1][1])
    else:
        print(N//2-EC[0][1])
elif EC[0][0] == OC[0][0]:
    if EC[0][1]+OC[1][1] == EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    elif EC[0][1]+OC[1][1] > EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N-EC[1][1]-OC[0][1])
else:
    print(N-EC[0][1]-OC[0][1])

Measured memory_bytes: 25844
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

typedef struct{double l,a,b;} lab;

void run(){
    int n,m;
    cin>>n>>m;
    vector<lab> v(n);
    rep(i,n){
        cin>>v[i].l>>v[i].a>>v[i].b;
    }
    double ans=0;
    rep(i,1<<n){
        vector<lab> t;
        rep(j,n){
            if(i&1<<j)t.pb(v[j]);
        }
        if(t.size()!=m)continue;
        double tmp=0;
        rep(i,m){
            Rep(j,i+1,m){
                tmp+=sq(t[i].l-t[j].l)+sq(t[i].a-t[j].a)+sq(t[i].b-t[j].b);
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M;
    cin >> M;
    ll sum = 0;
    ll C = 0;
    ll ans = 0;

    REP(i,M){
        ll d, c;
        cin >> d >> c;
        sum += d * c;
        C += c;
    }
    if(sum % 9) ans += sum / 9;
    else ans += sum / 9 - 1;
    ans += C - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    ll a, b, c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    if (a > k) {
        cout << k << endl;
    } else if (k - (a + b) <= 0) {
        cout << a << endl;
    } else {
        cout << a + -1LL * (k - a - b) << endl;
    }
    
    return 0;
}

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

long long cmb(int x, int y){
    if (y == 0) return 1;
    long long res = 1;
    for (int i = 1; i <= y; i++){
        res *= x - i + 1;
        res /= i;
    }
    return res;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end(), greater<long long>());
    bool flag = true;
    long long ans = v[0];
    for (int i = 1; i < a; i++){
        if (v[i] != v[i - 1]) flag = false;
        ans += v[i];
    }
    if (flag){
        int cnt = a;
        for (int i = a; i < n; i++){
            if (v[i] == v[a - 1]) cnt++;
            else break;
        }
        cout << setprecision(30) << (double)1.0 * ans / a << endl;
        long long q = 0;
        for (int i = a; i <= b; i++){
            q += cmb(cnt, i);
        }
        cout << setprecision(30) << q << endl;
        exit(0);
    }
    else if (a == b || v[a] != v[a - 1]) {
        cout << setprecision(30) << (double)1.0 * ans / a << endl;
        cout << setprecision(30) << 1 << endl;
        exit(0);
    }
    else {
        int left = a - 1;
        int right = a;
        while (left > 0){
            if (v[left - 1] == v[a]) left--;
            else break;
        }
        while (right < n - 1){
            if (v[right + 1] == v[a]) right++;
            else break;
        }
        cout << setprecision(30) << (double)1.0 * ans / a << endl;
        cout << setprecision(30) << cmb(right - left + 1, a - left) << endl;
    }
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = ((int64_t)2e18);
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;

  // cin >> t;
  t = 1;

  while (t--) {
    int n;
    cin >> n;

    map<int, int> m;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {

      int x;
      cin >> x;

      ans += m[(i - x)];

      ++m[(i + x)];
    }
    cout << ans << endl;
  }
}

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

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

Measured memory_bytes: 3640
k, n = map(int, input().split())

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

# 最も感覚が広い家を探す
max_dis = 0
index = 0
for i in range(len(a)):
    if i+1 == n:
        if a[0] + k - a[i] > max_dis:
            max_dis = a[0] + k - a[i]
            index = i
    else:
        if a[i+1] - a[i] > max_dis:
            max_dis = a[i+1] - a[i]
            index = i

if index+1 == n:
    print(a[n-1]-a[0])
else:
    print(k - a[index+1] + a[index])

Measured memory_bytes: 26444
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll n, x, l, ans, d;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> n >> x;
	ans = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> l;
		d += l;
		if (d <= x)
		{
			ans++;
		}
	}
	cout << ans << endl;
	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
int battle(){
    queue<char> qz[3];
    for(int i = 0; i < 3;i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            qz[i].push(s[j]);
        }
    }

    int next = 0;

    while(true){
        if(qz[next].empty()){
            return next;
        }
        int cur = next;
        next = qz[cur].front() - 'a';
        qz[cur].pop();
    }

//    return -1;
}

int main() {
    cout << (char)('A' + battle() ) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int main(){
  int i,n,a[MAX];
char S[MAX];
  for ( i = 1; i < MAX ;i++){
    if(scanf("%s",S) == EOF)break;
    //printf("%s",S);
    if (S[0] == '+'){
      a[i-2] = a[i-2]+a[i-1];
      i-=2;
    } 
    else if (S[0] == '-'){
      a[i-2] = a[i-2]-a[i-1];
      i-=2;
    }
    else if (S[0] == '*'){
      a[i-2] = a[i-2]*a[i-1];
      i-=2;
    }
    else a[i] = atoi(S);

  }  
  printf("%d\n",a[1]);


}

Measured memory_bytes: 988
import java.awt.geom.Point2D;
import java.util.*;

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

	public Main() {
		while(in.hasNext())new AOJ0524().doIt();
	}
	
	class AOJ0524{
		void doIt(){
			int m = in.nextInt();
			if(m==0)return;
			ArrayList<Integer> x= new ArrayList<Integer>(),y= new ArrayList<Integer>();
			for(int i=0;i<m;i++){
				x.add(in.nextInt());
				y.add(in.nextInt());
			}
			Stars target = new Stars(x, y);
//			System.out.println(target.min_index);
			int n = in.nextInt();
			ArrayList<Integer> tx = new ArrayList<Integer>(),ty = new ArrayList<Integer>();
			HashSet<String> set = new HashSet<String>();
			for(int i=0;i<n;i++){
				tx.add(in.nextInt());ty.add(in.nextInt());
				set.add(tx.get(tx.size()-1)+" "+ty.get(ty.size()-1));
			}
			for(int i=0;i<n;i++){//一点ずつ見ていく。
				int sx = target.x.get(target.min_index)-tx.get(i);
				int sy = target.y.get(target.min_index)-ty.get(i);
//				System.out.println(sx+" "+sy);
				boolean sw = true;
				for(int s=0;s<target.n;s++){
					if(!(set.contains((target.x.get(s)-sx)+" "+(target.y.get(s)-sy))))sw=false;
				}
				if(sw){
					System.out.println((sx*-1)+" "+(sy*-1));
					break;
				}
			}
		}
		
		class Stars{
			ArrayList<Integer> x,y;
			int n;
			int min_index;
			public Stars(ArrayList<Integer> x,ArrayList<Integer> y){
				this.x = new ArrayList<Integer>();
				this.y = new ArrayList<Integer>();
				this.n = x.size();
				for(int i=0;i<n;i++){
					this.x.add(x.get(i));
					this.y.add(y.get(i));
				}
				min_index = 0;
				double min=Double.MAX_VALUE;
				for(int i=0;i<n;i++){
					if(min>new Point2D.Double(x.get(i), y.get(i)).distance(0,0)){
						min_index = i;
						min = new Point2D.Double(x.get(i), y.get(i)).distance(0,0);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 66544
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,a,b,v[110],A,B,C;

int main()
{
	cin>>n>>a>>b;
	rep(i,n)
	{
		cin>>v[i];
		if(v[i]<=a) A++;else
		if(a<v[i]&&v[i]<=b) B++;else
		C++;
	}
	cout<<min(A,min(B,C))<<endl;
	rt0;
}

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

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    # 2**x の xの総和が答え
    for a in A:
        while a%2 == 0:
            a = a / 2
            ans += 1
    
    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 4140
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n, l;
		cin >> n >> l;
		if (!n)break;
		vi v(n), d(n);
		REP(i, n) {
			char c;
			cin >> c >> v[i];
			if (c == 'R')d[i] = 1;
			else d[i] = -1;
		}
		int cnt = 0, last = 0;
		vector<bool> end(n, false);
		REP(i ,INF) {
			vi prev = v;


			REP(j, n) {
				if(!end[j])v[j] += d[j];
			}
			REP(s, n) {
				FOR(t, s + 1, n) {
					if ((prev[s] < prev[t] && v[s] >= v[t]) || (prev[s] > prev[t] && v[s] <= v[t])) {
						if (abs(prev[s] - prev[t])==2) {
							swap(d[t], d[s]);
						}
					}
				}
			}
			REP(j, n) {
				if (v[j] >= l&&!end[j]) {
					end[j] = true;
					cnt++;
					last = j;
				}
			}
			REP(j, n) {
				if (v[j] <= 0 && !end[j]) {
					end[j] = true;
					cnt++;
					last = j;
				}
			}
			if (cnt == n) {
				cout << i + 1 << " " << last + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3000
from itertools import product
def main():
    s = input()
    ans = 0
    for v in product([True, False], repeat=len(s)+1):
        if not v[0] or not v[len(s)]:
            continue
        l, r = 0, 1
        while r < len(s)+1:
            if v[r]:
                x = int(s[l:r])
                ans += x
                l = r
            r += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.function.BiConsumer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			Set<Integer> set = new HashSet<>();
			for (int i = 0; i < n; i++) {
				set.add(in.nextInt());
			}
			if (n == set.size()) {
				out.println("YES");
			} else {
				out.println("NO");
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

	}
}


Measured memory_bytes: 58668
#include<stdio.h>

int main(){
  int s[10000],n,t[10000],max,sum;
  char ss[10];
  while(1){
    scanf("%d",&n);
    if(n==0)
      break;
    for(int i=0;i<n;i++){
      scanf("%s",ss);
      s[i]=0;
      for(int j=0;j<8;j++){
        if(j==2||j==5);
        else if(j==0||j==3||j==6)
          s[i]+=(ss[j]-'0')*10;
        else if(j==7)
          s[i]+=ss[j]-'0';
        else{
          s[i]+=ss[j]-'0';
          s[i]*=60;
        }
      }
      scanf("%s",ss);
      t[i]=0;
      for(int j=0;j<8;j++){
        if(j==2||j==5);
        else if(j==0||j==3||j==6)
          t[i]+=(ss[j]-'0')*10;
        else if(j==7)
          t[i]+=ss[j]-'0';
        else{
          t[i]+=ss[j]-'0';
          t[i]*=60;
        }
      }
    }
    max=0;
    for(int i=0;i<=86400;i++){
      sum=0;
      for(int j=0;j<n;j++)
        if(i>=s[j]&&i<t[j])
          sum++;
      if(sum>max)
        max=sum;
    }
    printf("%d\n",max);
  }
}


Measured memory_bytes: 2048
N = int(input())
str_in = input()
num = [int(n) for n in str_in.split()]
num = list(map(int, str_in.strip().split()))

hight = num[0]
stools = 0

for x in range(1,len(num)):
    if hight>num[x]:
        stools+=hight-num[x]
    elif num[x] > hight:
        hight = num[x]       
print (stools)

Measured memory_bytes: 41360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const ll mod = 998244353;
const int MAX = 1000005;
int n , cnt[MAX];
int fact[MAX];
int main()
{	
	fact[0] = 1;
	for(int i = 1; i < MAX; i++) fact[i] = (fact[i - 1] * (ll)i) % mod;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x;cin >> x;cnt[x]++;
		if(i == 0 && x != 0)
		{
			cout << 0;
			return 0;
		}
	}
	if(cnt[0] > 1){cout << 0;return 0;}
	ll ans = 1;
	ll prevLevel = 1;
	for(int i = 0; i < 100005; i++)
	{
		for(int j = 0; j < cnt[i]; j++)
			ans = (ans * (ll) prevLevel) % mod;
		prevLevel = cnt[i];
	}
	cout << ans;
		
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);

void solve(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=-1e18;
    ans=max(max(a*c,b*d),max(a*d,b*c));
    cout<<ans<<endl;
}
int main()
{
    ll t=1;
    //cin >> t;
    while(t--) {
        solve();
    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int A[3][3];

int main() {
  int n, t;
  map<int, pair<int, int>> m;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> t;
      m[t] = make_pair(i, j);
    }
  }
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    if (m.count(t)) {
      A[m[t].first][m[t].second] = 1;
    }
  }
  bool ok = false;
  for (int i = 0; i < 3; ++i) {
    if (A[i][0] + A[i][1] + A[i][2] == 3) ok = true;
    if (A[0][i] + A[1][i] + A[2][i] == 3) ok = true;
  }
  if (A[0][0] + A[1][1] + A[2][2] == 3) ok = true;
  if (A[0][2] + A[1][1] + A[2][0] == 3) ok = true;
  cout << (ok?"Yes":"No");
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; ++i) cin >> v[i] >> w[i];
    int dp[110][10010]{};
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j >= w[i]) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 7400
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

int n, S;
pair <int, int> a[101];
int d[N], ans[N];

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> S;
	for (int i = 0; i < n; i++){
		cin >> a[i].f >> a[i].s;
	}
	d[0] = 1;
	int mx = 0;
	for (int i = 0; i < n; i++){
		for (int j = S; j >= 0; j--){
			if (d[j] && j + a[i].f <= S){
				d[j + a[i].f] = 1;
				ans[j + a[i].f] = max(ans[j + a[i].f], ans[j] + a[i].s);
			}
			
		}
	}
	for (int i = 0; i <= S; i++){
		mx = max(ans[i], mx);
	}
	cout << mx;
	return 0;
}












Measured memory_bytes: 3200
# -*- Coding: utf-8 -*-
import numpy as np

N = int(raw_input())
W = map(int,raw_input().split())
W = np.array(W)
W_sum = np.sum(W)
ans = W_sum
for i in xrange(1,N):
	right = np.sum(W[i:N])
	left = W_sum - right
	ans = min(ans,abs(left-right))

print ans


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

int main() {
    ll N, D;
    cin >> N >> D;

    int count = 0;
    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= D * D) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3528
n,a,b = map(int,input().split())
if (b-a)%2==0:
  print(int((b-a)//2))
else:
  s = a-1
  b1 = b-s
  c = (b1-1)//2+s+1
  
  t = n-b
  a1 = a+t
  d = (n-a1-1)//2+1+t
  print(min(c,d))

Measured memory_bytes: 9084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;

int K, T;
vector <int> a;

int main()
{

	cin >> K >> T;
	for(int i=0; i<T; i++){
		int input;
		cin >> input;
		a.push_back(input);
	}
	int it_now=T;		
	int it_saidai=-1;

	for (int i=0; i<K; i++){
		//get max except now's cake
		int saidai=0;
		for(int j=0; j<it_now; j++){
			if (saidai<a[j]){
				saidai=a[j];
				it_saidai=j;
			}
		}
		for(int j=it_now+1; j<T; j++){
			if (saidai<a[j]){
				saidai=a[j];
				it_saidai=j;
			}			
		}
		if(it_saidai==it_now){
			cout << a[it_now] << endl;
			return 0;
		}
		//cout << it_saidai<< "  "<< a[it_saidai]<< endl;
		a[it_saidai]--;
		it_now=it_saidai;
	}
	cout << "0" << endl;
	return 0;
}


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

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

    int N, M;
    cin >> N >> M;

    pair<bool, int> count[N + 1];
    for (int i = 0; i <= N; ++i) {
        count[i] = make_pair(false, 1);
    }
    count[1].first = true;
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        count[x].second--;
        count[y].second++;
        count[y].first |= count[x].first;
        if (count[x].second == 0) {
            count[x].first = false;
        }
    }

    int res = 0;
    for (int i = 1; i <= N; ++i) {
        res += count[i].first && count[i].second > 0;
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 1024
class BinarySearchTree
	class Node
		attr_accessor :key, :left, :right
		def initialize(key)
			@key = key
		end
	end

	attr_accessor :root

	def insert(key)
		parent  = nil
		current = @root
		while current
			parent = current
			if key < current.key
				current = current.left
			else
				current = current.right
			end
		end

		new_node = Node.new(key)
		if !parent
			@root = new_node
		elsif key < parent.key
			parent.left = new_node
		else
			parent.right = new_node
		end
	end

	def find(key)
		current = @root
		while current
			return true if key == current.key
			if key < current.key
				current = current.left
			else
				current = current.right
			end
		end
		false
	end

	def keys_inorder
		inorder_helper(@root)
	end

	def keys_preorder
		preorder_helper(@root)
	end

	private
	def inorder_helper(node)
		return [] unless node
		result = []
		result.concat(inorder_helper(node.left))
		result << node.key
		result.concat(inorder_helper(node.right))
	end

	def preorder_helper(node)
		return [] unless node
		result = [node.key]
		result.concat(preorder_helper(node.left))
		result.concat(preorder_helper(node.right))
	end

end

tree = BinarySearchTree.new
n = STDIN.gets.to_i
n.times do
	command, param = STDIN.gets.split[0..1]
	if command == "insert"
		tree.insert(param.to_i)
	elsif command == "find"
		puts (tree.find(param.to_i) ? "yes" : "no")
	elsif command == "print"
		puts " #{tree.keys_inorder.join(" ")}"
		puts " #{tree.keys_preorder.join(" ")}"
	else
		raise "Unexpected input #{command}, #{param}"
	end
end

Measured memory_bytes: 99656