akhauriyash/Code-Regression huggingface dataset:
// Contest: AtCoder Beginner Contest 175 (https://atcoder.jp/contests/abc175)
// Problem: E: Picking Goods (https://atcoder.jp/contests/abc175/tasks/abc175_e)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

const int N = 3005;
ll dp[N][N][4];
int item[N][N];

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

    int r, c, k; cin >> r >> c >> k;
    rep(i, k) {
        int x, y, v; cin >> x >> y >> v;
        item[x-1][y-1] = v;
    }

    dp[0][0][0] = 0;
    dp[0][0][1] = item[0][0];
    dp[0][0][2] = dp[0][0][3] = -INFL;

    rep(i, r) rep(j, c) {
        if (i + 1 < r) {
            rep(x, 4) {
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][x]);
                dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][x] + item[i+1][j]);
            }
        }
        if (j + 1 < c) {
            rep(x, 4)
                dp[i][j+1][x] = max(dp[i][j+1][x], dp[i][j][x]);
            rep(x, 3)
                dp[i][j+1][x+1] = max(dp[i][j+1][x+1], dp[i][j][x] + item[i][j+1]);
        }
    }

    ll mx = 0;
    rep(x, 4)
        mx = max(mx, dp[r-1][c-1][x]);
    cout << mx << '\n';

    return 0;
}


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

int main(){
  int n, max_cnt=0;
  cin >> n;
  int h[n];
  for(int i=0; i<n; i++) cin >> h[i];
  for(int i=0; i<n-1; i++){
    int cnt = 0;
    if(n-i-1 <= max_cnt) break;
    for(int j=i+1; j<n; j++){
      if(h[j-1]>=h[j]){
        cnt++;
        max_cnt = max(max_cnt, cnt);
      } else {
        break;
      }
    }
  }
  cout << max_cnt << endl;
  return 0;
}

Measured memory_bytes: 640
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i):
	a(x,3,x)
	for t in r(i,i+30):b(t+1);a(q:=t+2,3,q),*map(b,r(q,v:=i+31));a(v,x,t,1);b(t+1);a(q,t,q)
p(3934)
a(0,1,3)
a(2,3,3,1)
d(0,9)
d(1,50)
for t in r(60):a(2,2,2);[t-31<s<30!=(a(8+t-s,50+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9264
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n;
vector<int>s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>n;
    set<string> se;
    rep(i,n){
        string temp;
        cin>>temp;
        se.insert(temp);
    }
    cout<<se.size()<<"\n";
}


Measured memory_bytes: 19196
/*{{{*/
#include "bits/stdc++.h"
using namespace std;

#define MT make_tuple
#define all(x) begin(x), end(x)
#define putchar(x) cout << (x)
static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename ...T> string format(const string& fmt, T&&... args) {
    size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
    unique_ptr<char[]> buf(new char[sz]);
    snprintf(buf.get(), sz, fmt.c_str(), args...);
    return string(buf.get(), buf.get() + sz - 1);
}

template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
template<class T> auto dud(T* x) -> decltype(cerr << *x, 0);
template<class T> char dud(...);

struct debug {
#if DEBUG == 2
    debug(int line) {
        if(line) cerr << "LINE(" << line << ") -> ";
    }
    template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) {
        cerr << boolalpha << i; return * this;
    }
    template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) {
        return *this << range(begin(i), end(i));
    }
    template<class T, class U> debug& operator<<(pair<T, U> d) {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    debug& operator<<(tuple<>&) { return *this << "()"; };
    template<class ...T> debug& operator<<(tuple<T...> d) {
        *this << "("; debug_tuple<sizeof...(T), 0>(d);
        return *this << ")";
    }
    template<size_t L, size_t I, class T> void debug_tuple(const T& t) {
        *this << (I == 0 ? "" : ", ") << get<I>(t);
        if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t);
    }
    template<class T> debug & operator <<(rge<T> d) {
        *this << "[";
        for(auto it = d.b; it != d.e; ++it)
            *this << (it != d.b ?  ", " : "") << *it;
        return *this << "]";
    }
    debug& operator<<(ostream&(*pf)(std::ostream&)) {
        cerr << pf; return *this;
    }
#else
    debug(int) {}
    template<class T> debug& operator<<(T&&) { return *this; }
    debug& operator<<(ostream&(*)(std::ostream&)) { return *this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] "

#define debug0()  debug(__LINE__)
#define debug1(x) debug(0)
#define GET_MACRO(_0, _1, NAME, ...) NAME
#define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__)
/*}}}*/
using LL = long long;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 200005;

void solve(int) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    LL ans = 0;
    for(int i = 1; i < N; ++i) {
        ans += max(0, A[i - 1] - A[i]);
        A[i] = max(A[i], A[i - 1]);
    }
    cout << ans << endl;
}

int main() {
    int T = 1;
    //cin >> T;
    for(int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}


Measured memory_bytes: 4028
import java.util.*;

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

        while (true) {
            int c = sc.nextInt();
            int n = sc.nextInt();
            int m = sc.nextInt();
            int s = sc.nextInt();
            int d = sc.nextInt();
            if ((c | n | m | s | d) == 0) {
                break;
            }
            s--;
            d--;

            @SuppressWarnings("unchecked")
            List<Edge>[] edges = new ArrayList[n];
            for (int i = 0; i < edges.length; i++) {
                edges[i] = new ArrayList<>();
            }
            int[][] dp = new int[n][c + 1];
            for (int[] dpp : dp) {
                Arrays.fill(dpp, Integer.MAX_VALUE >> 1);
            }
            for (int i = 0; i < m; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                int f = sc.nextInt();
                edges[a].add(new Edge(b, f));
                edges[b].add(new Edge(a, f));
            }
            PriorityQueue<P> queue = new PriorityQueue<>();
            dp[s][c] = 0;
            queue.add(new P(s, c, 0));
            while (!queue.isEmpty()) {
                P p = queue.poll();
                for (Edge e : edges[p.v]) {
                    if (dp[e.to][p.c] > dp[p.v][p.c] + e.cost) {
                        dp[e.to][p.c] = dp[p.v][p.c] + e.cost;
                        queue.add(new P(e.to, p.c, dp[e.to][p.c]));
                    }
                    if (p.c > 0 && dp[e.to][p.c - 1] > dp[p.v][p.c] + e.cost / 2) {
                        dp[e.to][p.c - 1] = dp[p.v][p.c] + e.cost / 2;
                        queue.add(new P(e.to, p.c - 1, dp[e.to][p.c - 1]));
                    }
                }
            }
            int res = Integer.MAX_VALUE;
            for (int i = 0; i <= c; i++) {
                if (dp[d][i] == Integer.MAX_VALUE >> 1) {
                    continue;
                }
                res = Math.min(res, dp[d][i]);
            }
            System.out.println(res);
        }
    }

    static class Edge {
        public int to, cost;

        Edge(int to, int cost) {
            this.to = to;
            this.cost = cost;
        }
    }

    static class P implements  Comparable<P> {
        int v;
        int cost;
        int c;

        P(int v, int c, int cost) {
            this.v = v;
            this.cost = cost;
            this.c = c;
        }

        @Override
        public int compareTo(P o) {
            return this.cost - o.cost;
        }
    }
}

Measured memory_bytes: 63504
#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;
    cin >> n;
    vector<ll> fib(n+1, 1);
    for (int i = 2; i <= n; ++i) {
        fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;
    return 0;
}


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

const int N = 3005;
const double PI = acos(-1), eps = 1e-10;

int n, L;
double alpha[N], ansx = 0.0, ansy = 0.0;

double midpoint (double x1, double x2) {
	double len = x2 - x1;
	if (len < -eps) len += 2.0 * PI;
	len /= 2.0;
	double mid = x1 + len;
	if (mid >= 2.0 * PI - eps) mid -= 2.0 * PI;
	return mid;
}

int main () {
	scanf("%d%d", &n, &L);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		alpha[i] = 2.0 * PI * x / L;
	}

	for (int i = 0; i < n; i++) {
		double nowx = 0.0, nowy = 0.0;
		for (int j = (i + 1) % n, k = 0; j != i; j = (j + 1) % n, k++) {
			double m = midpoint(alpha[j], alpha[i]), arg = alpha[j] - alpha[i];
			double vecx = cos(alpha[i]) - cos(m), vecy = sin(alpha[i]) - sin(m);

			ansx += cos(m) * k, ansy += sin(m) * k;
			ansx += vecx * nowx - vecy * nowy, ansy += vecx * nowy + vecy * nowx;

			if (arg < -eps) arg += 2.0 * PI;
			nowx += cos(arg / 2.0), nowy += sin(arg / 2.0);
		}
	}

	ansx /= 0.5 * n * (n - 1) * (n - 2), ansy /= 0.5 * n * (n - 1) * (n - 2);
	printf("%.10lf %.10lf\n", ansx, ansy);
	return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split(' '))

# pts = [tuple(map(int, input())) for _ in range(N)]

ans = 0
for _ in range(N):
  x, y = map(int, input().split(' '))
  if x**2 + y**2 <= D**2:
    ans+=1
    
print(ans)
  


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

struct UnionFind
{
  vector< int > data;

  UnionFind(int size)
  {
    data.assign(size, -1);
  }
  int Find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = Find(data[k]));
  }
  void unite(int x, int y)
  {
    x = Find(x);
    y = Find(y);
    if(x == y) return;
    data[x] += data[y];
    data[y] = x;
  }
  int Size(int k)
  {
    return(-data[Find(k)]);
  }
};
int main()
{
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  for(int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    tree.unite(A, B);
  }
  int mura = 0;
  int used[1000] = {};
  for(int i = 0; i < N; i++) {
    int K = tree.Find(i);
    if(used[K]++) continue;
    if(tree.Size(K) == 1) ++mura;
    else --mura;
  }
  cout << abs(mura) << endl;
}

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


int main(){
    ll n, x, m;
    cin >> n >> x >> m;

    if(n <= m*1000 || n < (ll)1e8){
        vector<ll>a(n+1);
        a[1] = x;
        for(int i=2;i<=n;i++){
            a[i] = a[i-1]*a[i-1]%m;
        }
        ll ans = 0;
        for(int i=1;i<=n;i++) ans += a[i];
        cout << ans << endl;
        return 0;
    }

    vector<ll>A;
    set<ll> st;
    A.push_back(x);
    st.insert(x);
    ll t, sz_A = 1;
    while(1){//高々m回
        t = A[sz_A-1]*A[sz_A-1]%m;
        if(st.find(t) != st.end()) break;
        A.push_back(t);
        st.insert(t);
        sz_A++;
    }

    int i;
    for(i=0;i<sz_A;i++) if(A[i] == t) break;

    int T = sz_A - i;

    ll ans = 0;
    for(int j=0;j<i;j++) ans += A[j];

    ll q = (n-i)/T, r = (n-i)%T;
    ll sum = 0;
    for(int j=i;j<sz_A;j++) sum += A[j];
    sum *= q;
    for(int j=i;j<i+r;j++) sum += A[j];

    ans += sum;

    cout << ans << endl;
}


Measured memory_bytes: 10820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
int H,W;
int main(){
    cin>>H>>W;
    char c[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)
            cin>>c[i][j];
    }

    for(int i=0;i<2*H;i++){
        for(int j=0;j<W;j++)   
            cout<<c[i/2][j];
        cout<<"\n";
    }

    return 0;
}




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

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
            if (arr[i] == 0) {
                System.out.println(0);
                return;
            }
        }
        in.nextLine();
        final long limit = (long) 1e18;
        long prod = arr[0];
        for (int i = 1; i < n; i++) {
            if (prod > limit / arr[i]) {
                System.out.println(-1);
                return;
            }
            prod *= arr[i];
        }
        System.out.println(prod);
    }
}


Measured memory_bytes: 61644
#include <stdio.h>
int main()
{
  int a,b,c,n;
  scanf("%d %d %d",&a,&b,&c);
  n=0;
  while(a<=b){
    if(c%a==0){
      ++n;
    }
    a++;
  }
  printf("%d\n",n);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <queue>
#include <algorithm>

inline int read(void){
	int res = 0;
	char ch = std::getchar();
	while(ch < '0' || ch > '9')
		ch = std::getchar();
	while(ch >= '0' && ch <= '9')
		res = res * 10 + ch - 48, ch = std::getchar();
	return res;
}

typedef long long ll;

const int MAXN = 2e5 + 19;

namespace camel{
	struct Node{
		int val, k;
		
		bool operator<(const Node &b)const{
			return k < b.k;
		} 
	}A[MAXN], B[MAXN];
	
	int n, anum, bnum;
	ll ans;
	
	std::priority_queue<int, std::vector<int>, std::greater<int> > q;
	
	int main(){
		n = read(), ans = 0ll, anum = 0, bnum = 0;
		for(int i = 1; i <= n; ++i){
			int k = read(), l = read(), r = read();
			if(l > r)
				ans += r, A[++anum] = (Node){l - r, k};
			else
				ans += l, B[++bnum] = (Node){r - l, n - k};
		}
		std::sort(A + 1, A + 1 + anum);
		std::sort(B + 1, B + 1 + bnum);
		for(int i = 1; i <= anum; ++i){
			if(A[i].k == 0)
				continue;
			if(q.size() < A[i].k)
				q.push(A[i].val);
			else if(q.size() == A[i].k){
				if(A[i].val > q.top())
					q.pop(), q.push(A[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		for(int i = 1; i <= bnum; ++i){
			if(B[i].k == 0)
				continue;
			if(q.size() < B[i].k)
				q.push(B[i].val);
			else if(q.size() == B[i].k){
				if(B[i].val > q.top())
					q.pop(), q.push(B[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		std::printf("%lld\n", ans);
		return 0;
	}
}

int main(){
	for(int T = read(), i = 1; i <= T; ++i)
		camel::main();
	return 0;
}

Measured memory_bytes: 4876
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ans = 0
count = 0
i = 0
while count < m:
    ans += ab[i][0]
    count += 1
    ab[i][1] -= 1
    if ab[i][1] == 0:
        i += 1
print(ans)

Measured memory_bytes: 29024
#include <iostream>

using namespace std;

int main(){
    int x,i;
    i = 1;
    while (i > 0){
        cin >> x;
        if (x == 0){
            i = 0;
        }
        if (x != 0){
            cout << "Case " << i << ": " << x << endl;
            i++;
        }
    }
    return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 5e3 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll a,b,n;
ll cal(ll x){
    return floor((ld) (a*x)/b) - a*floor((ld) x/b);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>a>>b>>n;
    ll res = min(b - 1,n);
    cout<<cal(res);
}



Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
string S;

//解法
void solve() {

	ll _size = S.size();
	ll cnt = 0;
	ll ans = 0;

	rep(i, _size) {
		if (S[i] == 'W') {
			ans += i - cnt;
			cnt++;
		}
	}

	cout << ans;

	return;
}

int main() {
	//入力

	cin >> S;

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
  int n;
  int page;
  bool isFirst;
  int startPage, lastPage;
  
  while (1) {
    cin >> n;
    if (n == 0) break;
    if (n == 1) {
      cin >> page;
      cout << page << endl;
      continue;
    }
    lastPage = -1;
    isFirst = true;
    for (int i = 0; i < n; i++) {
      cin >> page;
      if (page == lastPage + 1) {
        lastPage = page;
      } else {
        if (lastPage != -1) {
          if (isFirst == true) {
            if (startPage == lastPage) {
              cout << startPage;
            } else {
              cout << startPage << "-" << lastPage;
            }
            isFirst = false;
          } else {
            if (startPage == lastPage) {
              cout << " " << startPage;
            } else {
              cout << " " << startPage << "-" << lastPage;
            }
          }
        }
        startPage = page;
        lastPage = page;
      }
    }
    if (isFirst == true) {
      if (startPage == lastPage) {
        cout << startPage << endl;
      } else {
        cout << startPage << "-" << lastPage << endl;
      }
    } else {
      if (startPage == lastPage) {
        cout << " " << startPage << endl;
      } else {
        cout << " " << startPage << "-" << lastPage << endl;
      }
    }
  }
}



Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
    int len=3;
    cin>>a>>b;
    for (int i = 0; i < 3; i++)
    {
        if (a[i]!=b[len-i-1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
        
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> parse(string str) {
	vector<int> ret; int t = 0; str += ' ';
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int bitcount(int x) {
	int ret = 0;
	for (int i = 0; i < 31; i++) {
		if (x & (1 << i)) ret++;
	}
	return ret;
}
string s; double dp[4100][12];
int main() {
	while (s = "", getline(cin, s)) {
		vector<int> u = parse(s);
		vector<int> v(u.begin() + 1, u.end());
		int n = v.size();
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) dp[i][j] = 999999999.9L;
		}
		for (int i = 0; i < n; i++) dp[1 << i][i] = v[i];
		for (int i = 1; i < (1 << n); i++) {
			if (bitcount(i) <= 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				dp[i][j] = 999999999.9L;
				for (int k = 0; k < n; k++) {
					if ((i & (1 << k)) && (j != k)) {
						double d1 = v[j] + v[k], d2 = abs(v[j] - v[k]);
						dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + sqrt(d1 * d1 - d2 * d2));
					}
				}
			}
		}
		double ret = 999999999.9L;
		for (int i = 0; i < n; i++) ret = min(ret, dp[(1 << n) - 1][i] + v[i]);
		cout << (ret <= u[0] + 1e-10 ? "OK" : "NA") << endl;
	}
}

Measured memory_bytes: 3464
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a>9 || a<=0)
		cout << -1 << endl;
	else if(b>9 || b<=0)
		cout << -1 << endl;
	else
		cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define max(x,y) x>y?x:y
int main(){
	int pm[50]={0},m[50]={0},pl=0,l=0,v;
	while(~scanf("%d",&v)){
		m[l]=v;
		l++;
		v=getchar();
		if(v=='\n'){
			if(l>pl){
				pl=l;
				while(--l){
					m[l]+=max(pm[l],pm[l-1]);
				}
				m[l]+=pm[l];
			} else {
				pl=l;
				while(l--){
					m[l]+=max(pm[l],pm[l+1]);
				}
				l=0;
			}
			memcpy(pm,m,sizeof(pm));
		}
	}
	printf("%d\n",pm[0]);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K = 0;//m
    int N = 0;//houses

    vector<int> A;
    vector<int> B;
    int Ai;
    int i = 0;
    cin >> K;
    cin >> N;
    while (cin >> Ai) {
        A.emplace_back(Ai);
        i++;
    }
    sort(A.begin(), A.end());
    int result = 0;
    for (int j = 0; j < i-1; j++) {
        int distance = A[j+1] - A[j];//小さい順のため負にはならない
        B.emplace_back(distance);
    }
    int distance=K+A[0]-A[i-1];
    B.emplace_back(distance);

    int max=*std::max_element(B.begin(),B.end());
    result=std::accumulate(B.begin(),B.end(),0)-max;
    cout << result << "\n";
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

signed main()
{
    usaco();
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << "3\n";
    else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << "2\n";
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << "1\n";
    else cout << "0\n";
}



Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
	int N,M,s,c;
	int ans[N];
	cin >>N >> M;
	
	REP(i,N){
		ans[i] = 11;
	}
	REP(i,M){
		cin >> s >> c;
		if(ans[s-1]==11){
			ans[s-1] = c;
		}else if(ans[s-1]==c){
			
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	
	if(N == 1){
		if(ans[0] == 11){
			ans[0] = 0;
		}
	}else{
		if(ans[0] == 0){
			cout << -1 << endl;
			return 0;
		}else if(ans[0] == 11){
			ans[0] = 1;
		}
		for(int i=1;i<N;i++){
			if(ans[i] == 11) ans[i] = 0;
		}
	}
	
	
	
	REP(i,N){
		cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
import heapq

N = int(input())

mochis = []

for i in range(N):
  mochis.append(int(input()))
heapq.heapify(mochis)

step = 0
pre_m = 1000
for i in range(N):
  m = heapq.heappop(mochis)
  if m == pre_m:
    continue
  step += 1
  pre_m = m

print(step)

Measured memory_bytes: 3064
n,*a=map(int,open(0).read().split())
#print(f.reduce(o.mul,a))
a=[s for s in a if s%2==0]
if len(a)==0:
    print(0)
    exit()
count=0

for x in a:
    while True:
        if x%2==0:
            x=x//2
            count+=1
        else:
            break
print(count)

Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const int mod = 1e9 + 7;
const int MAX = 200005;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    int n,m; cin >> n >> m;
    COMinit();
    auto vec = prime_factorize(m);
    ll ans = 1;
    for(auto f : vec){
        int cnt = f.second;
        ll tmp = COM(cnt+n-1, cnt);
        ans *= tmp;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(void)
{
	int i, x, n;
	fflush(stdout);
	scanf("%d", &n);

	for(i = 1; i <= n; i++){
		x = i;
		if(x%3==0){
			printf(" %d", i);
		}
		else{
			while(x > 0){
			if(x%10==3){
				printf(" %d", i);
				break;
			}
			x = x / 10;
			}
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2056
import math
n = int(input())
a = [int(i) for i in input().split()]

s = 0
for i in range(1,n):
    if i%2 == 1:
        s+=a[i]
    else:
        s-=a[i]
x = []
x1 = (a[0] - s) /2
x2 = (a[0] + s) /2
x.append(x1)
x.append(x2)
for i in range(2,n):
    x.append(a[i-1] - x[i-1])
s = ""
for i in range(n):
    s += str(int(x[i]*2)) + " "
print(s)

Measured memory_bytes: 14264
n, q = map(int, input().split())
s = input()

L = [0]*len(s)
for i in range(1,len(s)):
    L[i] = L[i-1]
    if s[i-1] == "A" and s[i] == "C":
        L[i] += 1


for _ in range(q):
    l, r = map(int, input().split())
    print(L[r-1]-L[l-1])
    

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    scanf(" %d", &n);
    vector<int> a(n);
    rep(i,n) scanf(" %d", &a[i]);
    sort(all(a));

    vector<ll> suma(n);
    suma[0]=a[0];
    for(int i=1; i<n; ++i) suma[i] = suma[i-1]+a[i];

    int ans=1;
    for(int i=n-2; i>=0; --i)
    {
        if(a[i+1]<=suma[i]*2) ++ans;
        else break;
    }

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


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 998244353
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll


signed main() {
	fast;

	int t = 1;
	// cin>>t;

	while(t--) {
		
		int r, g, b;
		cin>>r>>g>>b;
		int k;
		cin>>k;

		while(g<=r) {
			g <<= 1;
			k--;
		}
		while(b<=g) {
			b<<=1;
			k--;
		}

		if(k>=0) cout<<"Yes\n";
		else cout<<"No\n";

	}
}

Measured memory_bytes: 3664
//
// Created by 李青坪 on 2018/10/5.
//

#include "cstdio"

using namespace std;

int maxk = 100000;  //最大卡车数目
int maxw = 10000;   //单个货物最大重量
int goods[100000];

int search(int P, int n, int k){
    int sum = 0, numCarUsed = 0;
    for (int i = 0; i < n; ++i) {
        if (goods[i] > P ) return 0;
        if ((sum + goods[i] == P) && (i == n - 1)){
            return n;
        }
        if (sum + goods[i] >= P) {
            int temp = sum;
            sum = 0;
            ++numCarUsed;
            if (temp + goods[i] > P)
                sum += goods[i];
        }
        else {
            sum += goods[i];
        }
        if (numCarUsed >= k){
            return i; //最后几个货物还没装的情况下就已经把车用完了
        }
    }
    return n;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &goods[i]);
    }
    int low = 0;
    int high = maxk * maxw;
//    int low = 28;
//    int high = 56;  //238 59
    while ( high - low > 1){
        int mid = (low + high) /2;
        int numGoods = search(mid, n, k);
        if (numGoods == n) high = mid;
        else low = mid;
    }
    printf("%d\n", high);
}

/*
5 3
8
1
7
3
9
 */


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;
            int cur = 0;
            for (int di = -1; di <= 1; di++) {
                for (int dj = -1; dj <= 1; dj++) {
                    if (!di && !dj) continue;
                    if (i + di >= 0 && i + di < h && j + dj >= 0 && j + dj < w) {
                        if (s[i + di][j + dj] == '#') cur++;
                    }
                }
                s[i][j] = '0' + (cur);
            }
        }
        cout << s[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static int withdrawByMultiplier(int totalAmount, int multiplier) {
        if (totalAmount < multiplier) {
            return totalAmount;
        }

        int withdrawAmount = 1;
        while (withdrawAmount * multiplier <= totalAmount) {
            withdrawAmount *= multiplier;
        }

        int remainingAmount = totalAmount -withdrawAmount;
        int nine = 1 + withdrawByMultiplier(remainingAmount, 9);
        int six = 1 + withdrawByMultiplier(remainingAmount, 6);

        return Math.min(nine, six);
    }

    private static int withdraw(int totalAmount) {
        return Math.min(withdrawByMultiplier(totalAmount, 9), withdrawByMultiplier(totalAmount, 6));
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int n = in.nextInt();
        out.println(withdraw(n));
    }

}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  int N;
  cin >> N;
  cin >> str;
  int count1=0;
  for(int i=N-1;i>=0;i--){
    if(str[i]==')'){
      count1++;
    }else if(str[i]=='('){
      count1--;
    }
    if(count1==-1){
      count1++;
    }
  }
  string s1;
  for(int i=0;i<count1;i++){
    s1+='(';
  }
  str=s1+str;
  int count=count1+N;
  count1=0;
  for(int i=0;i<count;i++){
    if(str[i]==')'){
      count1++;
    }else if(str[i]=='('){
      count1--;
    }
  }
  string s2;
  count1*=-1;
  for(int i=0;i<count1;i++){
    s2+=')';
  }
  cout <<str<<s2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;

int main() {
    int n, m, sum=0, count = 0;
    string s = "Yes";
    cin>>n>>m;

    vector<int> a(n);
    rep(i, n) cin>>a[i];
    
    rep(i, n) sum+=a[i];
    
    
    rep(i, n){
        if(a[i] * 4 * m>= sum) count ++;
    }
    
    if (count<m) s= "No";
    
    cout<<s<<endl;
    
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep0c(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

int H, W, h[2020][2020], w[2020][2020];
bool cell[2020][2020];

void solve() {
  rep(i, H) {
    int a = 0;
    rep(j, W) {
      if(cell[i][j]) w[i][j] = ++a;
      else w[i][j] = a = 0;
    }
    repc0(W-1, j) {
      if(w[i][j]) {
        if(a) w[i][j] = a;
        else a = w[i][j];
      } else {
        a = 0;
      }
    }
  }
  rep(j, W) {
    int a = 0;
    rep(i, H) {
      if(cell[i][j]) h[i][j] = ++a;
      else h[i][j] = a = 0;
    }
    repc0(H-1, i) {
      if(h[i][j]) {
        if(a) h[i][j] = a;
        else a = h[i][j];
      } else {
        a = 0;
      }
    }
  }
  int maxv = 0;
  rep(i, H) rep(j, W) {
    maxv = max(maxv, h[i][j] + w[i][j] - 1);
  }
  printf("%d\n", maxv);
}

int main() {
  scanf("%d %d", &H, &W);
  rep(i, H) {
    string s;
    cin >> s;
    rep(j, W) {
      if(s[j] == '.') cell[i][j] = true;
      else cell[i][j] = false;
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 35968
import sys
L, R = map(int, input().split())
N, val = 2019, 2019

for i in range(L, R):
    for j in range(i+1, R+1):
        mod = (i * j) % N
        if val > mod:
            val = mod
        if val == 0:
            print(val)
            sys.exit()
print(val)


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

import sys
from collections import defaultdict

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    def find(self, x):
        """ 根の検索(グループ番号と言えなくもない) """
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """ 併合 """
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x=None):
        if x is not None:
            """ あるノードの属する集合のノード数 """
            return self.size[self.find(x)]
        else:
            """ 集合の数 """
            res = set()
            for i in range(self.n+1):
                res.add(self.find(i))
            # グループ0の分を引いて返却
            return len(res) - 1
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

MAX = 10 ** 5
N = INT()
uf = UnionFind(MAX * 2)
edges = []
for i in range(N):
    x, y = MAP()
    edges.append((x, y))
    uf.union(x, y+MAX)

# 連結成分Sが持つ辺の数i,xの頂点数j,yの頂点数k
# D[S] = (i, j, k)
D = defaultdict(lambda: [0, 0, 0])
# 辺の集計
for x, y in edges:
    D[uf.find(x)][0] += 1
# 頂点の集計
for x in range(1, MAX+1):
    y = x + MAX
    D[uf.find(x)][1] += 1
    D[uf.find(y)][2] += 1

ans = 0
# 各連結成分についての、追加できる辺の数を合計する
for edgecnt, xcnt, ycnt in D.values():
    # 追加できる辺の数 = 完全2部グラフの辺数 - 既にある辺の数
    ans += xcnt * ycnt - edgecnt
print(ans)


Measured memory_bytes: 69956
N = int(input())
S = input().rstrip()

white_num_r = len([val for val in S if val == "."])
black_num_l = 0

min_val = white_num_r
for val in S:
	if val == ".":
		white_num_r -= 1
	else:
		black_num_l += 1
	new_val = white_num_r + black_num_l
	min_val = min(new_val,min_val)

print(min_val)

Measured memory_bytes: 5096
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  string S;
  cin >> S;

  bool easy = true;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if (S.at(i) == 'L') { easy = false; }
    } else {
      if (S.at(i) == 'R') { easy = false; }
    }
  }

  cout << (easy ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int, int>;
const int MX = 200005;
int n, x, y, xmax, ymin = 1e9, c[MX], u, e, l = 1e9;
long long ans;
P pr[MX*2];
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d%d", &x, &y);
		if(x > y) swap(x,y);
		xmax = max(xmax, x);
		ymin = min(ymin, y);
		pr[i*2] = P(x,i);
		pr[i*2+1] = P(y,i);
	}
	sort(pr, pr+n*2);
	ans = (long long)(pr[n*2-1].first - ymin) * (xmax - pr[0].first);
	rep(i,n*2-2){
		if(++c[pr[i+1].second] == 1 && ++u == n){
			while(--c[pr[++e].second]);
			l = min(l, pr[i+1].first - pr[e].first);
			u--;
		}
	}
	ans = min(ans, (long long)(pr[n*2-1].first - pr[0].first) * l);
	printf("%lld\n", ans);
}

Measured memory_bytes: 4096
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main() {
	int n;
	string s;
	cin >> n >> s;
	int hoge = 0;
	int count = 0;
	rep(i, 0, n) {
		if (s[i] == '(') {
			hoge++;
		}
		else {
			hoge--;
		}
		count = max(-hoge, count);
	}
	rep(i, 0, count) {
		s.insert(s.begin(),'(');
	}
	hoge += count;
	rep(i, 0, hoge) {
		s.push_back(')');
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=999999999;
int n;
char s[1000010];
int dp[1000010][2];

int dfs(int u,int pre)
{
	if(u==n+1)
	{
		if(pre) return 1;
		return 0;
	}
	if(dp[u][pre]!=-1) return dp[u][pre];
	int ans=inf;
	if(pre)
	{
		int tmp=10-s[u]+'0';
		ans=min(ans,dfs(u+1,0)+1+s[u]-'0');
		if(s[u]-'0'!=9)ans=min(ans,dfs(u+1,1)+1+s[u]-'0'+1);
		ans=min(ans,dfs(u+1,1)+tmp-1);
	}
	else
	{
		ans=min(ans,dfs(u+1,0)+s[u]-'0');
		ans=min(ans,dfs(u+1,1)+1+s[u]-'0');
	}
	return dp[u][pre]=ans;
}
signed main()
{
	memset(dp,-1,sizeof(dp));
	cin>>s+2;
	s[1]='0';
	n=strlen(s+1);
	printf("%d",dfs(1,0));
	return 0;
}


Measured memory_bytes: 55936
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, read().split())

    X = list(map(int, str(N)))
    L = len(X)

    dp1 = [[0] * (K + 1) for _ in range(L + 1)]
    dp2 = [[0] * (K + 1) for _ in range(L + 1)]
    dp1[0][0] = 1

    for i, x in enumerate(X):
        for j in range(K + 1):
            if x != 0:
                if j > 0:
                    dp1[i + 1][j] = dp1[i][j - 1]
            else:
                dp1[i + 1][j] = dp1[i][j]
            if j > 0:
                dp2[i + 1][j] = dp2[i][j - 1] * 9
                if x != 0:
                    dp2[i + 1][j] += dp1[i][j - 1] * (x - 1)
            dp2[i + 1][j] += dp2[i][j]
            if x != 0:
                dp2[i + 1][j] += dp1[i][j]

    print(dp1[L][K] + dp2[L][K])
    return


if __name__ == '__main__':
    main()


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

#define MAX ((long long int)pow(10, 18))
#define ERROR -1

long long int n_list[100000];

int main()
{
	long n = 0;
	long long int a = 1;

    scanf("%ld", &n);

	for (long i = 0; i<n; i++)
	{
        scanf("%lld", &n_list[i]);

		if (n_list[i] == 0)
		{
			a = 0;
		}
	}

	for (long i = 0; i<n; i++)
	{

        if(a == 0)
        {
            break;
        } else if (n_list[i] <= (MAX/a)) {
			a = a * n_list[i];
		}
		else {
			a = ERROR;
			break;
		}
	}

	printf("%lld", a);

	return 0;
}

Measured memory_bytes: 2472
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll N, M;
ll A[101010];
ll B[101010];

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

    cin >> N >> M;
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A+N);
    reverse(A, A+N);

    for (int i = 0; i < N; ++i) A[i] = -A[i];
    B[0] = 0;
    for (int i = 1; i <= N; ++i) B[i] = (-A[i-1]) + B[i-1];

    ll lo = 0, hi = 1000000000000LL; 
    while (lo+1<hi) {
        ll u = (lo + hi) / 2;
        ll count = 0;
        for (int i = 0; i < N; ++i) {
            int idx = upper_bound(A, A+N, - (u + A[i])) - A;
            count += idx;
        }
        if (count >= M) lo = u;
        else hi = u;
    }

    ll ans = 0;
    ll count = 0;
    for (int i = 0; i < N; ++i) {
        int idx = upper_bound(A, A+N, - (lo + A[i])) - A;
        ans += idx * (-A[i]) + B[idx];
        count += idx;
    }
    assert(count >= M);
    cout << ans - (count - M) * lo << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	int A,B;
	cin>>A>>B;
	for(int i=1;i<=100000;i++){
		if((int)(i*0.08)==A&&(int)(i*0.1)==B){
			cout<<i<<endl;return 0;
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include <algorithm>
#include <complex>
using namespace std;

typedef long long int lli;
const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;
// sort/unique用、setではうまく動かないので使うべからず
namespace std {
	bool operator==(const point &a, const point &b){
		return eq(a, b);
	}
	bool operator<(const point& a, const point& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}

int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}


//点集合 ps に対してその凸包を求める．
//O(n log n)
vector<point> convex_hull(vector<point> ps) {
  int n=ps.size(), k=0;
  sort(ps.begin(), ps.end());
  vector<point> ch(2*n);
  for (int i=0; i < n; ch[k++]=ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i=n-2, t=k+1; i >= 0; ch[k++]=ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<point> a;
      for(int i=0;i<n;i++)
	{
	  double x,y;
	  char aa;
	  cin>>x>>aa>>y;
	  a.push_back(point(x,y));
	}
      cout<<n-convex_hull(a).size()<<endl;
    }

}

Measured memory_bytes: 1268