akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <sstream>
 
class Area
{
public:
	Area()
	: m_area(0)
	, m_left(0)
	{}
	
	~Area()
	{}
	
	Area(const Area& obj) {
		m_area = obj.m_area;
		m_left = obj.m_left;
	}
	
	void setArea(int area, int left) {
		m_area = area;
		m_left = left;
	}
	
	void addArea(int area) {
		m_area += area;
	}
	
	int getArea() {
		return m_area;
	}
	
	int getLeft() {
		return m_left;
	}
private:
	int m_area;
	int m_left;
};
 
class AreaList
{
public:
	AreaList()
	: m_list()
	{}
	
	~AreaList()
	{
		while (!m_list.empty()) {
			Area* p = m_list.back();
			m_list.pop_back();
			delete(p);
		}
	}
	
	void pushArea(Area& counter) {
		Area* q = new Area(counter);
		while (!m_list.empty()) {
			Area* p = m_list.back();
			if (p->getLeft() < q->getLeft()) {
				break;
			}
			m_list.pop_back();
			delete(p);
		}
		m_list.push_back(q);
	}
	
	std::string toString() {
		std::ostringstream os1, os2;
		int total = 0;
		os2 << m_list.size();
		std::vector<Area*>::iterator itr;
		for (itr = m_list.begin(); itr != m_list.end(); itr++) {
			total += (*itr)->getArea() / 2;
			os2 << " " << ((*itr)->getArea() / 2);
		}
		os1 << total;
		std::string output = os1.str() + "\n" + os2.str();
		return output;
	}

private:
	std::vector<Area*> m_list;
};
 
int main() {
	std::string str;
	std::cin >> str;
	
	int w = str.size();
	int h[w + 1];
	int max, min;
	h[0] = max = min = 0;
	for (int i = 0; i < w; i++) {
		switch (str[i]) {
		case '_' :
			h[i + 1] = h[i];
			break;
		case '/' :
			h[i + 1] = h[i] + 1;
			if (h[i + 1] > max) {
				max = h[i + 1];
			}
			break;
		// case '\\' :
		default :
			h[i + 1] = h[i] - 1;
			if (h[i + 1] < min) {
				min = h[i + 1];
			}
			break;
		}
	}
	
	AreaList list;
	Area counter[max - min + 1];
	for (int j = 0; j < max - min + 1; j++) {
		counter[j].setArea(0, 0);
	}
	for (int i = 1; i < w + 1; i++) {
		for (int j = 0; j < max - min + 1; j++) {
			if (j > h[i] - min) {
				if (j == h[i - 1] - min) {
					counter[j].setArea(1, i - 1);
				} else if (counter[j].getArea() > 0) {
					counter[j].addArea((j - (h[i - 1] - min)) + (j - (h[i] - min)));
				}
			} else if (j == h[i] - min) {
				if (j > h[i - 1] - min && counter[j].getArea() > 0) {
					counter[j].addArea(1);
					list.pushArea(counter[j]);
				} else {
					counter[j].setArea(0, 0);
				}
			} else {
				counter[j].setArea(0, 0);
			}
		}
	}
	
	std::cout << list.toString() << std::endl;
	
	return 0;
}


Measured memory_bytes: 3500
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.map!(to!int).array;

  auto c = 0;

  foreach (i; 0..n) {
    auto minJ = i;
    foreach (j; i..n) {
      if (ai[j] < ai[minJ])
        minJ = j;
    }
    if (i != minJ) {
      swap(ai[i], ai[minJ]);
      ++c;
    }
  }

  writeln(ai.map!(to!string).join(" "));
  writeln(c);
}

Measured memory_bytes: 2500
#include <iostream>
#include <cstdlib>

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

using namespace std;

int main(void)
{
  int N;
  int W[100];
  int S2 = 0;
  int S1 = 0;
  int smallest, remain;
  cin >> N;
  rep(i, N)
    cin >> W[i];
  rep(i, N)
    S2 += W[i];
  smallest = S2;
  rep(i, N)
  {
    S1 += W[i];
    S2 -= W[i];
    remain = abs(S1 - S2);
    if(smallest > remain)
      smallest = remain;
  }
  cout << smallest;
  return 0;
}

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

using namespace std;

int main() {
	int n;

	cin >> n;

	int plus[20001] = {};

	int start = 300000000;
	/*
	int start = 1;
	for( int i = 0; i < n ;i++) {
		start += 1+ i;
	}
	*/


	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		p--;
		plus[p] = i;
	}

	int sum = 0;

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

	
	sum = 0;
	cout << start << " ";
	for (int i = 0; i < n - 1; i++) {
		sum += plus[i];
		cout << start - sum - i - 1 << " ";
	}
	cout << endl;

	return 0;

}

Measured memory_bytes: 640
import Control.Monad
import Data.List

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [_, k] <- readInts
  hs <- readInts
  print $ solve k hs

solve :: Int -> [Int] -> Int
solve k = sum . drop k . sortBy (flip compare)


Measured memory_bytes: 79228
#include <iostream>
#include <vector>

typedef long long ll;

const int ms = 30000;

std::vector<int> nums[31];
std::vector<int> ans;
int n;

void go(int idx, int lim = 30) {
	if(lim != 1) lim = 30;
	while(n >= lim && nums[idx].size() >= lim) {
		for(int i = 0; i < lim; i++) {
			ans.push_back(nums[idx].back());
			nums[idx].pop_back();
			n--;
		}
	}
}

int main() {
	for(int i = ms; i > 1; i--) {
		if(i == 16 || i == 9 || i == 5) continue;
		if(i % 30 == 0) {
			nums[30].push_back(i);
		} else {
			nums[i % 30].push_back(i);
		}
	}
	std::cin >> n;
	n -= 3;
	ans.push_back(16);
	ans.push_back(5);
	ans.push_back(9);
	ll sum = 0;
	go(2, 15);
	go(3, 10);
	go(4, 15);
	go(5, 6);
	go(6, 5);
	go(8, 15);
	go(9, 10);
	go(10, 3);
	go(12, 5);
	go(14, 15);
	go(15, 2);
	go(16, 15);
	go(18, 5);
	go(20, 3);
	go(21, 10);
	go(22, 15);
	go(24, 5);
	go(25, 6);
	go(26, 15);
	go(27, 10);
	go(28, 15);
	go(30, 1);
	for(int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
		sum += ans[i];
	}
	//std::cout << sum % 30 << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, M;
vector<vector<int>> par;
vector<vector<int>> chi;
vector<int> nPar;
vector<int> dist;
vector<int> ans;

void dfs(int n){
    if(chi[n].size()==0) return;

    int nChi = chi[n].size();
    for(int i=0; i<nChi; i++){
        int nxt = chi[n][i];
        nPar[nxt]--;
        if(dist[nxt] < dist[n] + 1){
            ans[nxt] = n;
            dist[nxt] = dist[n] + 1;
        }
        if(nPar[nxt]==0) dfs(nxt);
    }
}

int main(){
    cin >> N >> M;
    par = vector<vector<int>>(N+1, vector<int>());
    chi = vector<vector<int>>(N+1, vector<int>());
    nPar = vector<int>(N+1,0);
    for(int i=0; i<N+M-1; i++){
        int A, B;  cin >> A >> B;
        par[B].push_back(A);
        chi[A].push_back(B);
        nPar[B]++;
    }
    int root = 1;
    while(par[root].size()!=0){
        root = par[root][0];
    }
    
    dist = vector<int>(N+1, 0);
    ans = vector<int>(N+1, 0);
    dist[root] = 0;
    ans[root] = 0;
    dfs(root);
    for(int i=1; i<=N; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 17664
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

ll db[310][310];
ll da[310][310];
void warshall_floyd(int n, long long d[310][310]) {
    for (int k = 0; k < n; k++){       // 経由する頂点
        for (int i = 0; i < n; i++){    // 始点
            for (int j = 0; j < n; j++) {  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int N,M,L; cin >> N >> M >> L;
    Fill(db, INF);

    for(int i=0; i<N; i++){
        db[i][i]=0LL;
    }

    for(int i=0; i<M; i++){
        int a,b,c; cin >> a >> b >> c;
        a--, b--;
        db[a][b] = db[b][a] = c;
    }

    warshall_floyd(N, db);

    Fill(da, INF);

    for(int i=0; i<N; i++){
        da[i][i]=0;
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i==j) continue;

            if(db[i][j]<=L){
                da[i][j]=da[j][i]=1;
            }
        }
    }

    warshall_floyd(N, da);

    int Q; cin >> Q;
    rep(i,Q){
        int s,t; cin >> s >> t;
        s--,t--;
        if(da[s][t]==INF) {
            cout << -1 << endl;
        }else {
            cout << da[s][t] - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
/*{{{*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std;
using ll = long long;
using ld = long double;
template < typename t > using V = vector< t >;
template< typename t > int size(const t& c) {return c.size();}
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
#define flag() __LINE__"| "__PRETTY_FUNCTION__
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
/*}}}*/



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

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

    cout << (k & 1? (b - a) : (a - b)) << '\n';
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Collection;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.ArrayList;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FiveEverywhere solver = new FiveEverywhere();
        solver.solve(1, in, out);
        out.close();
    }

    static class FiveEverywhere {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            boolean[] prime = eratos(55_556);

            List<Integer> nums = new ArrayList<>();
            for (int i = 0; i < prime.length; i++) {
                if (prime[i] && i % 5 == 2) {
                    nums.add(i);
                }
                if (nums.size() == n) {
                    break;
                }
            }

            out.print(nums.stream().map(Object::toString).collect(Collectors.joining(" ")));

        }

        static boolean[] eratos(int n) {
            boolean[] results = new boolean[n + 1];
            Arrays.fill(results, true);

            results[0] = false;
            results[1] = false;

            for (int i = 2; i <= n; i++) {
                int j = i + i;
                while (j <= n) {
                    results[j] = false;
                    j = j + i;
                }
            }
            return results;
        }

    }
}



Measured memory_bytes: 35928
n = int(input())
a = list(map(int,input().split()))

b = [0]*n
b[0]=a[0]
pt = 0
m = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
    b[i]=b[i-1]+a[i]

for i in range(n):
    if i%2==0 and b[i]+m<=0:
        ans1+=1-b[i]-m
        m+=1-b[i]-m
    elif i%2==1 and b[i]+m>=0:
        ans1+=1+b[i]+m
        m+=-1-b[i]-m
m=0
for i in range(n):
    if i%2==1 and b[i]+m<=0:
        ans2+=1-b[i]-m
        m+=1-b[i]-m
    elif i%2==0 and b[i]+m>=0:
        ans2+=1+b[i]+m
        m+=-1-b[i]-m
print(min(ans1,ans2))


Measured memory_bytes: 14332
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vvi f(n,vi(10));
	vvi p(n,vi(11));
	rep(i,n)rep(j,10) cin>>f[i][j];
	rep(i,n)rep(j,11) cin>>p[i][j];
	
	llong ans=-INF*2;
	for(int i=1;i<(1<<10);++i){
		vi cnt(n,0);
		rep(j,10){
			if((i>>j)&1){
				rep(k,n){
					if(f[k][j]) cnt[k]++;
				}
			}
		}
		llong sum=0;
		rep(j,n) sum+=p[j][cnt[j]];
		ans=max(ans,sum);
	}
	
	cout<<ans<<endl;
}

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


void solve(long long A, long double B){
    cout << std::fixed << std::setprecision(0) << floor((long double)A * B) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3864
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int):
    N = list(str(N))
    if all([s == '9' for s in N[1:]]):
        print(int(N[0]) + 9 * (len(N) - 1))
    else:
        print(int(N[0]) - 1 + 9 * (len(N) - 1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

int main() {
  int A;
  cin >> A;
  if(A / 100 <= 12 && A / 100 != 0) {
    if(A % 100 <= 12 && A % 100 != 0) {
      cout << "AMBIGUOUS" << endl;
    }
    else {
    cout << "MMYY" << endl;
    }
  }
  else {
    if(A % 100 <= 12 && A % 100 != 0) {
    cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]


class Tree:
    def __init__(self, v):
        self.v = v
        self.neighbors = []

    def set_rank(self, rank, parent):
        self.rank = rank
        for neighbor in self.neighbors:
            if neighbor is parent:
                continue
            neighbor.set_rank(rank=rank + 1, parent=self)


trees = {i: Tree(i) for i in range(1, N + 1)}

for a, b in AB:
    trees[a].neighbors.append(trees[b])
    trees[b].neighbors.append(trees[a])
try:
    trees[1].set_rank(1, None)
except:
    print(-1)
    exit()

group0 = [node.v for node in trees.values() if node.rank % 2 == 0]
group1 = [node.v for node in trees.values() if node.rank % 2]
x = [set(), set(), set()]
for i in range(1, N + 1):
    x[i % 3].add(i)
if len(group1) < len(group0):
    group1, group0 = group0, group1
result = {}
if len(group0) <= len(x[0]):
    while group0 and x[0]:
        result[group0.pop()] = x[0].pop()
    y = x[0] | x[1] | x[2]
    while group1 and y:
        result[group1.pop()] = y.pop()
else:
    while x[2] and group0:
        result[group0.pop()] = x[2].pop()
    while x[1] and group1:
        result[group1.pop()] = x[1].pop()
    while group0 and x[0]:
        result[group0.pop()] = x[0].pop()
    while group1 and x[0]:
        result[group1.pop()] = x[0].pop()
    if group0 or group1:
        print(-1)
        exit()

print(' '.join(str(result[i]) for i in range(1, N + 1)))

Measured memory_bytes: 262916
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local A = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
local N = read.n()

local function dfs(i, mx, s)
    if i == N then
        local a = {}
        while s do
            table.insert(a, s.val)
            s = s.next
        end
        local ss = table.concat(a, "")
        print(ss:reverse())
    else
        for j=1,mx+1 do
            local new = {}
            new.val = A[j]
            new.next = s
            dfs(i+1, math.max(j,mx),new)
        end
    end
end
dfs(0, 0, nil)


Measured memory_bytes: 1656
import sys
input = sys.stdin.readline
n = int(input())
cs = [int(input()) for _ in range(n)]

from collections import defaultdict
prev = -1
c_comp = []
# 連続する色はまとめて良い
for c in cs:
    if prev != c:
        c_comp.append(c)
    prev = c

d = defaultdict(list)
for i,c in enumerate(c_comp):
    d[c].append(i)


dp = [0] * 220000
mod = 10**9 + 7

# 何個目まで見たか
inds = defaultdict(int)
ans = 0
dp[0] = 1
for i,c in enumerate(c_comp):
    i_prev = d[c][inds[c]-1]
    if inds[c] >= 1:
        # かぶっていないそれ以前の場合の数を足す
        dp[i+1] += dp[i] + dp[i_prev+1]
    else:
        # 前の色が無い or 異なる場合はなにもしない
        dp[i+1] = dp[i]
    dp[i+1] %= mod
    inds[c] += 1
print(dp[len(c_comp)])

Measured memory_bytes: 76476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    ll ans = 0;
    ll diff = B - A;
    for(ll i = 0; i < N; i++){
        ll j = N - 1 - i;
        ll mn = -D * i + C * j;
        ll mx = -C * i + D * j;
        if(mn <= diff && diff <= mx)ans = 1;
    }
    if(ans)cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int A,B;
    cin>>A>>B;

    for(double i=1;i<=100000;i+=1){
        if(floor(i*0.08)==A &&floor(i*0.1)==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;

    return 0;

}
/*


*/


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


int main() {
	#define int long long

	int N;
	int H[200005];
	int aux[200005];

	memset(aux,0,sizeof(aux));

	int t = 1;
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> H[i];
		if(t - H[i] >= 0) {
			aux[t-H[i]]++;
		}
		t++;
	}

	int ans = 0;


	map<int, int> mp;

	for(int i=1;i<=N;i++) {
		int j = i + H[i] + 1;
		if(j > N) {
			continue;
		}
		int toFind = j-1;
		
		if(mp.find(toFind) != mp.end()) {
			mp[toFind]++;
		} else {
			mp[toFind] = 1;
		}
	}

	for(int i=1;i<=N;i++) {
		if(mp.find(i) != mp.end()) {
			ans += mp[i] * aux[i];
		}
		int x = i - H[i];
		if(x >= 0) {
			aux[x]--;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14728
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector> 
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 5e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n;
char s[N];
int dp[N];
int main()
{
	while (~scanf("%d%s", &n, s + 1))
	{
		MS(dp, 0);
		for (int i = 3, pre = -1; i <= n; ++i)
		{
			gmax(dp[i], dp[i - 1]);
			if (s[i - 2] == '1' && s[i - 1] == '0' && s[i] == '1')
			{
				pre = i - 3;
				for (int j = i - 2; j && s[j] == '1'; --j)
				{
					gmax(dp[i], dp[j - 1] + i - j - 1);
				}
			}
			else if (s[i] == '0')
			{
				pre = -1;
			}
			if (~pre)
			{
				gmax(dp[i], dp[pre] + i - pre - 2);
			}
		}
		printf("%d\n", dp[n]);
	}
	return 0;
}
/*
【trick&&吐槽】


【题意】
给你一个01串
我们每次可以把一个101变成010，问你，在最优操作序列下，最多的操作步数是多少。

【分析】
我们思考操作的连续性，
第一步是101变成010
第二步，如果旁边还有1的话，比如1011能够操作变成0010
继续，我们发现，每次能够变化的序列，无非是101111(101的右边有若干个1)或者111101(101的左边有若干个1）

而可以选择的合法串的个数是O(n)级别的（101左边的1的个数+右边的1的个数）
于是，我们按照这个转移就可以做到O(n)

【时间复杂度&&优化】
O（n）

【数据】


*/

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

    int count = 0;
    rep_1(x,k){
        rep_1(y,k){
            int z = s-x-y;
            if(z>= 0 && z<=k)count++;
        }
    }
    cout << count <<endl;

}



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

for i in range(n-1, 0, -1):
    if h[i] < h[i-1]-1:
        print('No')
        exit()
    elif h[i] < h[i-1]:
        h[i-1] = h[i-1]-1

print('Yes')


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

int main() {
    int h, w;
    cin >> h >> w;

    for(int i = 0; i < h + 2; i++) {
        for(int j = 0; j < w + 2; j++) {
            if(i == 0 || j == 0 || i == h + 1 || j == w + 1) cout << '#';
            else {
                char c;
                cin >> c;
                cout << c;
            }
        }
        cout << endl;
    }

    return 0;
}

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

using Edges=vector<int>;
using Graph=vector<Edges>;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> w(n);
    for(int i=0;i<n;i++) cin>>w[i];
    Graph g(n);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> leaf(n,false);
    vector<int> pot(n);
    pot[0]=1e8;
    queue<int> que;
    for(int i=1;i<n;i++){
        pot[i]=g[i].size();
        if(pot[i]==1){
            que.push(i);
            leaf[i]=true;
        }
    }
    vector<int> givew(n);
    while(!que.empty()){
        int v=que.front(); que.pop();
        for(int i=0;i<g[v].size();i++){
            if(leaf[g[v][i]]) continue;
            pot[g[v][i]]--;
            givew[g[v][i]]=max(w[v]+givew[v],givew[g[v][i]]);
            if(pot[g[v][i]]==1){
                que.push(g[v][i]);
                leaf[g[v][i]]=true;
            }
        }
    }
    int res=0;
    int maxLeaf=0;
    for(int i=0;i<n;i++){
        if(leaf[i]){
            maxLeaf=max(maxLeaf,givew[i]+w[i]);
        }
        else{
            res+=w[i];
        }
    }
    cout<<res+maxLeaf<<endl;
    return 0;
}


Measured memory_bytes: 10576
loop do
    s = gets.chomp
    break if s == ?.
    0 while s.gsub!(/\+\-|\-\+/, "")
    0 while s.gsub!(/\+([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 1) % 26).chr }
    0 while s.gsub!(/\-([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 25) % 26).chr }
    0 while s.gsub!(/\[([^\[\]]+?)\]/) { $1.scan(/[-+]*[A-Z?]/).reverse.join }
    puts s.gsub(/[-+]*\?/, ?A)
end

Measured memory_bytes: 9188
H,W = map(int,input().split())
S = [input() for i in range(H)]

def tor(x,y):
    to = {'6':'3','3':'1','1':'4','4':'6'} if y%4==0 else {'6':'4','4':'1','1':'3','3':'6'}
    return to[S[y][x]]
def tol(x,y):
    to = {'6':'3','3':'1','1':'4','4':'6'} if y%4==2 else {'6':'4','4':'1','1':'3','3':'6'}
    return to[S[y][x]]
def tod(x,y):
    to = {'6':'2','2':'1','1':'5','5':'6'} if x%4==0 else {'6':'5','5':'1','1':'2','2':'6'}
    return to[S[y][x]]
def tou(x,y):
    to = {'6':'2','2':'1','1':'5','5':'6'} if x%4==2 else {'6':'5','5':'1','1':'2','2':'6'}
    return to[S[y][x]]
dxyto = [(0,1,tod),(1,0,tor),(0,-1,tou),(-1,0,tol)]
stack = [(0,0)]
visited = [[0]*W for i in range(H)]
while stack:
    x,y = stack.pop()
    visited[y][x] = 1
    if (x,y) == (W-1,H-1):
        print('YES')
        exit()
    c = S[y][x]
    for dx,dy,to in dxyto:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if visited[ny][nx]: continue
        if S[ny][nx] == '#': continue
        if to(x,y) != S[ny][nx]: continue
        stack.append((nx,ny))
print('NO')


Measured memory_bytes: 5948
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M, K := ReadInt(), ReadInt(), ReadInt()
	uf := MakeUnionFind(N)
	friendAdjL := make([][]int, N)
	for i := 0; i < M; i++ {
		a, b := ReadInt()-1, ReadInt()-1
		uf.Unite(a, b)
		friendAdjL[a] = append(friendAdjL[a], b)
		friendAdjL[b] = append(friendAdjL[b], a)
	}
	blockAdjL := make([][]int, N)
	for i := 0; i < K; i++ {
		a, b := ReadInt()-1, ReadInt()-1
		blockAdjL[a] = append(blockAdjL[a], b)
		blockAdjL[b] = append(blockAdjL[b], a)
	}
	for i := 0; i < N; i++ {
		ans := uf.Size(i) - 1
		for _, j := range friendAdjL[i] {
			if uf.Connected(i, j) {
				ans--
			}
		}
		for _, j := range blockAdjL[i] {
			if uf.Connected(i, j) {
				ans--
			}
		}
		fmt.Printf("%d ", ans)
	}
}

type UnionFind []int

func MakeUnionFind(size int) UnionFind {
	uf := make([]int, size)
	for i := 0; i < size; i++ {
		uf[i] = -1
	}
	return uf
}
func (uf UnionFind) Root(x int) int {
	if uf[x] < 0 {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}
func (uf UnionFind) Unite(x, y int) {
	x, y = uf.Root(x), uf.Root(y)
	if x == y {
		return
	}
	if uf[x] > uf[y] {
		x, y = y, x
	}
	uf[x] += uf[y]
	uf[y] = x
}
func (uf UnionFind) Connected(x, y int) bool { return uf.Root(x) == uf.Root(y) }
func (uf UnionFind) Size(x int) int          { return -uf[uf.Root(x)] }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 17760
#include <iostream>
#include <string>
int main() {
    size_t      n, k;
    std::string s;
    std::cin >> n >> k >> s;
    size_t result = 0;
    for (size_t i = 0; i < n; ++i)
        if (s[i] == s[i - 1]) ++result;
    result += k << 1;
    std::cout << (result >= n ? n - 1 : result) << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int>in(m);
		rep(i,n)rep(j,m){
			int a;cin>>a;
			in[j]+=a;
		}
		vector<int>out(m);
		rep(i,m)out[i]=i;
		for(int i=1;i<m;i++){
			for(int j=m-1;j>=i;j--){
				if(in[out[j-1]]<in[out[j]])swap(out[j-1],out[j]);
			}
		}
		rep(i,m-1)cout<<out[i]+1<<" ";
		cout<<out[m-1]+1<<endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define N 305
using namespace std;
int n,w[N],dp[N][N];

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++)
      cin>>w[i];
    memset(dp,0,sizeof(dp));
    int ans=0;
    for(int i=1;i<=n;i+=2){
      for(int j=0;j<n-i;j++){
	dp[j][j+i]=dp[j+1][j+i-1];
	for(int k=j+1;k<=j+i;k+=2)
	  dp[j][j+i]=max(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
	if(dp[j+1][j+i-1]==i-1&&abs(w[j]-w[j+i])<=1)
	  dp[j][j+i]=max(dp[j][j+i],dp[j+1][j+i-1]+2);
	ans=max(ans,dp[j][j+i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3432
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
using ll = long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N;
int dp[100100][3];

void init()
{
  cin >> N;
}


void solve()
{
  rep(i, N) {
    int j = i+1;
    int x[3];
    rep(y, 3) cin >> x[y];
    rep(k, 3) {
      rep(l, 3) {
        if (k == l) continue;
        int t = x[l] + dp[i][k];
        dp[j][l] = max(dp[j][l], t);
      }
    }
  }
  int r = 0;
  rep(i, 3) r = max(dp[N][i], r);
  cout << r << endl;
}



Measured memory_bytes: 1408
from collections import deque
n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
  v,k,*u=map(int,input().split())
  edge[v]=u
p=[-1]*(n+1)
p[1]=0
q=deque([])
q.append(1)
v=[1]*(n+1)
v[1]=0
while q:
  now=q.popleft()
  for i in edge[now]:
    if v[i]:
      q.append(i)
      p[i]=p[now]+1
      v[i]=0
for i in range(1,n+1):
  print(i,p[i])


Measured memory_bytes: 6032
#include <iostream>
#include <algorithm>
#include <math.h>


using namespace std;



int main(){
  int r0,r1,i=0,coin=0;
  int n[200001];
  
  while (cin>>n[i]){
    i++;
  }
  
  r0= n[1];
   coin = n[3]-n[2];
   if(i==3){
   coin = n[2]-n[1];
   }
  for(int t=2;t<i;t++){
    
    if(n[t]<r0){
      r0=n[t];
      }
    if(t==i-1){
    }else{
    r1=n[t+1];
    }

    if(t==i-1){
    }else{
    if(r1-r0>coin){
    coin=r1-r0;

    }
    }

  }


  cout << coin<<endl;

  

  return 0;
}



Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 素因数分解：nの素因数分解を{素数, 指数}の形で昇順に返す
vector<pair<long long, long long>> primeFactorize(long long n){
    vector<pair<long long, long long>> ret;
    for(long long i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        long long ex = 0;
        while(n%i == 0){ ex++; n /= i; }
        ret.push_back({i, ex});
    }
    if(n != 1) ret.push_back({n, 1});
    return ret;
}

int main(){
    Init();
    ll n; cin >> n;
    auto pFac = primeFactorize(n);
    
    ll cnt = 0;
    for(auto p: pFac){
        ll i = 1, sum = 0;
        for(i; sum+i<=p.second; i++) sum += i;
        cnt += (i-1);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3664
def test(A, B):
    if((A > 0 and A <= 12) and (B > 0 and B <= 12)):
        print("AMBIGUOUS")
        return

    if((B > 0 and B <= 12)):
        print("YYMM")
        return

    if ((A > 0 and A <= 12)):
        print("MMYY")
        return

    print("NA")


S = list(input())
A = int(S[0] + S[1])
B = int(S[2] + S[3])
test(A, B)

Measured memory_bytes: 3064
def check(P):
	global k, T, n

	i = 0
	for j in range(k):
		s = 0
		while s + T[i] <= P:
			s += T[i]
			i += 1
			if (i == n):
				return n
	
	return i

def solve():
	left = 0
	right = 100000 * 10000

	while right - left > 1:
		mid = (left + right) // 2
		v = check(mid)
		if (v >= n):
			right = mid
		else:
			left = mid

	return right

if __name__ == '__main__':
	n, k = map(int, input().split())
	T = [int(input()) for i in range(n)]

	ans = solve()
	print(ans)


Measured memory_bytes: 9564
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;
    ll n = sz(s);

    vl cs(26);
    rep(i, n) cs[s[i] - 'a']++;
    ll ans = n * (n - 1) / 2;
    rep(i, 26) {
        ans -= cs[i] * (cs[i] - 1) / 2;
    }
    cout<<ans + 1<<endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int dp[m+1],v,w;
  for(int i = 0;i <= m;i++) dp[i] = 0;
  for(int i = 0;i < n;i++){
    cin >> v >> w;
    for(int j = w;j <= m;j++)dp[j] = max(dp[j],v);
  }
  for(int i = 1;i < m;i++){
    for(int j = 1;j <= m-i;j++){
      if(dp[i+j] < dp[i]+dp[j]) dp[i+j] = dp[i]+dp[j];
    }
  }
  cout << dp[m] <<endl;
  return (0);
}

Measured memory_bytes: 3088
def init()
	$t = Array.new(17).map{Array.new(17, 0)}
	$t[1][1] = 1
	$vert = Array.new(17).map{Array.new(17, true)}
	$horiz = Array.new(17).map{Array.new(17, true)}
end

def input_matatabi()
	a = gets.chomp.split(" ").map{|str| str.to_i}
	if a[0] == a[2]
		$vert[a[0] + 1][[a[1], a[3]].min + 1] = false
	else
		$horiz[[a[0], a[2]].min + 1][a[1] + 1] = false
	end
end

def calc_t(x, y)
	for i in 1..x
		for j in 1..y
			if $vert[i][j - 1]
				$t[i][j] += $t[i][j - 1]
			end
			if $horiz[i - 1][j]
				$t[i][j] += $t[i - 1][j]
			end
		end
	end
end

n = gets.chomp.to_i

n.times do
	init()

	gx, gy = gets.chomp.split(" ").map{|str| str.to_i}
	num_matatabi = gets.chomp.to_i

	num_matatabi.times do
		input_matatabi
	end

	calc_t(gx + 1, gy + 1)

	if ($t[gx + 1][gy + 1] == 0)
		puts "Miserable Hokusai!"
	else
		puts $t[gx + 1][gy + 1]
	end
end

Measured memory_bytes: 8904
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll h, w, x, y, ans, n;
ll cc[111][111];

int main(void)
{
	cin>>w>>h>>n; int i, j, k, v;
	for(i=1 ; i<=n ; i++)
	{
		cin>>x>>y>>v;
		if(v==1)
		{
			for(j=1 ; j<=x ; j++)
				for(k=1 ; k<=h ; k++)
					cc[j][k]=1;
		}
		if(v==2)
		{
			for(j=x+1 ; j<=w ; j++)
				for(k=1 ; k<=h ; k++)
					cc[j][k]=1;
		}
		if(v==3)
		{
			for(j=1 ; j<=w ; j++)
				for(k=1 ; k<=y ; k++)
					cc[j][k]=1;
		}
		if(v==4)
		{
			for(j=1 ; j<=w ; j++)
				for(k=y+1 ; k<=h ; k++)
					cc[j][k]=1;
		}
	}
	for(i=1 ; i<=w ; i++)
		for(j=1 ; j<=h ; j++)
			if(cc[i][j]==0) ans++;
	cout<<ans; return 0;
}
// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int shp = scan.nextInt();
		int wlf = scan.nextInt();
		String ans = "unsafe";
		
		if(shp > wlf){ans = "safe";}
		
		System.out.println(ans);
	}
}

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

unsigned long long lsum(long long K){
  unsigned long long s;
  s = (1 + K)*K/2 % 1000000007;
  return s;
}

int main(){
  long N;
  cin >> N;
  long long K;
  cin >> K;
  vector<long> A(N);
  vector<vector<long>> B(N, vector<long>(2,0));
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    for(int j = 0; j < i; j++){
      if(A.at(j) > A.at(i)){
        B.at(i).at(0)++;
        B.at(i).at(1)++;
      }//if
    }//j
  }//i
  for(int i = 0; i < N; i++){
    for(int j = N-1; j > i; j--){
      if(A.at(j) > A.at(i)) B.at(i).at(1)++;
    }//j
  }//i
  unsigned long long ans = 0;
  for(int i = 0; i < N; i++){
    unsigned long long temp = lsum(K - 1);
    temp %= 1000000007;
    ans += (B.at(i).at(1) * temp) % 1000000007;
    ans %= 1000000007;
    ans += (B.at(i).at(0) * K) % 1000000007;
    ans %= 1000000007;
//    cout << i << " temp = " << temp << endl;
//    cout << "ans = " << ans << endl;
  }
  cout << fixed;
  cout << setprecision(20);
  cout << ans << endl;
}

Measured memory_bytes: 384
import math
n = int(input())

min_count = 1000000000000
pre_i = 0
pre_j = 0

for i in range(1, int(math.sqrt(n))+1):
  j = n / i
  f, s = math.modf(j)
  if pre_i == j and pre_j == i:
    break
  if str(f) == "0.0":
    count = (i - 1) + (j - 1)
    if count <= min_count:
      min_count = count
    pre_i = i
    pre_j = j

print("{:.0f}".format(min_count))
    

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int a,b;
	char op;
	while(1)
	{
		scanf("%d %c %d",&a,&op,&b);
		if(op == '+')
		{
			printf("%d\n",a+b);
		}
		else if(op == '-')
		{
			printf("%d\n",a-b);
		}
		else if(op == '/')
		{
			printf("%d\n",a/b);
		}
		else if(op == '*')
		{
			printf("%d\n",a*b);
		}else
		{
			break;
		}
	}
	return 0;
	
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int t[26];

pair<bool,int> dfs(char *S, int l, int r) {
  int sum = 0, mid;

  if (l+1 == r) {
    return { true, S[l]-'a' };
  }

  for (int i=l; i<r; i++) {
    if (S[i] == '[') sum++;
    if (S[i] == ']') sum--;
    if (S[i] == '-') {
      if (sum == 1) mid = i;
    }
  }

  auto p = dfs(S, l+1, mid);
  auto q = dfs(S, mid+1, r-1);

  if (!p.first || !q.first) return {false, 0};

  int a = p.second;
  int b = q.second;
  if (min(t[a], t[b]) != 0 || max(t[a], t[b]) <= 0) return {false, 0};

  t[a]--; t[b]--;

  if (t[a] > t[b])
    return {true, a};
  else
    return {true, b};
}

int main(){
  char S[50];

  scanf("%s", S);
  int M = strlen(S);
  int N = (M + 3) / 4;

  debug(N);

  for (int i=0; i<N; i++) {
    char c;
    int v;
    scanf(" %c%d", &c, &v);

    t[c-'a'] = v;
  }

  auto p = dfs(S, 0, M);

  if (p.first && t[p.second] == 0) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}



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

long long int n, ans, an, an2;

int main() {
	cin >> n;
	if(n % 2) return cout << 0, 0;
	for(long long int i = 5; i <= n; i *= 5ll) {
		an += ((n / 2) / i);
	}
	for(long long int i = 2; i <= n; i *= 2ll) {
		an2 += (n / i);
	}
	cout << min(an, an2);
	return 0;
}


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

long long n,p;
vector<long long> a;

long long solve();

int main(){
    cin >> n >> p;
    a.resize(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    cout << solve() << endl;
    return 0;
}


long long solve(){
    long long ans = 1,cnt = 0,now = 0;
    for(int i = 0;i < n;++i)
        if(a[i]%2)++cnt;
        else ans *= 2;
    for(int i = p;i <= cnt;i += 2){
        long long num = 1;
        for(long long j = 1;j <= i;++j){
            num *= cnt - j + 1;
            num /= j;
        }
        now += num;
    }
    return ans * now;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n;
    vi va(n), vb(n), vc(n);
    REP(i,n) {
        cin >> va[i];
    }
    REP(i,n) {
        cin >> vb[i];
    }
    REP(i,n) {
        cin >> vc[i];
    }
    sort(ALL(va));
    sort(ALL(vb));
    sort(ALL(vc));
    REP(i,n) {
        m = lower_bound(ALL(va), vb[i]) - va.begin();
        k = n - (upper_bound(ALL(vc), vb[i]) - vc.begin());
        ans += m * k;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  bool f = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] % 2)
      f = 1;
  }
  if (f)
    cout << "first" << endl;
  else
    cout << "second" << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
const ll MOD = 10007;

struct WarshallFloyd{
    int n;
    vector<vll> d;

    WarshallFloyd(int n) : n(n), d(n, vll(n, INF)) {
        REP(i, n) d[i][i] = 0;
    }

    void add_edge(int s, int t, ll c) {
        d[s][t] = c;
    }

    ll query(int s, int t) {
        return d[s][t];
    }

    WarshallFloyd& operator()() {
        REP(k, n) {
            REP(i, n) REP(j, n) {
                if (d[i][k] == INF || d[k][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }

        return *this;
    }
};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int v, e; cin >> v >> e;

    WarshallFloyd g(v);

    REP(i, e) {
        ll s, t, d; cin >> s >> t >> d;
        g.add_edge(s, t, d);
    }

    g();

    bool neg = false;
    REP(i, v) {
        if (g.query(i, i) < 0) neg = true;
    }

    if (neg) {
        print("NEGATIVE CYCLE");
        return 0;
    }

    REP(i, v) {
        REP (j, v) {
            if (j > 0) cout << " ";
            ll c = g.query(i, j);
            if (c == INF) cout << "INF";
            else cout << c;
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3324