akhauriyash/Code-Regression huggingface dataset:
def dijkstra(s, stop, g):
    import heapq

    n = len(g)
    heap = [(0, s)]
    heapq.heapify(heap)

    prev = [-1] * n
    cost = [float("Inf")] * n
    cost[s] = 0

    while heap:
        c, v = heapq.heappop(heap)
        x = cost[v]
        if c > x:
            continue
        for d, u in g[v]:
            path = d + x
            if path < cost[u]:
                cost[u] = path
                prev[u] = v
                heapq.heappush(heap, (path, u))
            if u == stop:
                break

    return prev, cost


def main():
    from collections import deque

    n, *uv = map(int, open(0).read().split())
    g = [[] for _ in range(n + 1)]

    for i, j in zip(*[iter(uv)] * 2):
        g[i].append([1, j])
        g[j].append([1, i])

    dk, cost = dijkstra(n, 1, g)
    l = cost[1] - 1
    k = l // 2 if l % 2 == 0 else l // 2 + 1
    vis = [False] * (n + 1)

    def f(now):
        if vis[now]:
            return 0
        vis[now] = True
        c = 1
        for _, nxt in g[now]:
            c += f(nxt)

        return c

    nw = dk[1]

    cnt = []
    i = 0
    vis[1] = True
    vis[n] = True
    while i < k:
        i += 1
        nx = dk[nw]
        vis[nx] = True
        tmp = f(nw)
        vis[nx] = False
        cnt.append(tmp)
        nw = nx

    fn = 0
    q = deque([1])
    vis[1] = False

    while q:
        i = q.popleft()
        if vis[i]:
            continue

        vis[i] = True
        fn += 1
        for _, j in g[i]:
            q.appendleft(j)

    fn += sum(cnt)
    sn = n - fn

    print("Fennec" if fn > sn else "Snuke")


if __name__ == '__main__':
    main()


Measured memory_bytes: 49280
def main():
    """
    数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶ

        各 i=1,2...,n-2 について、ai=ai+2
        数列に現れる数はちょうど 2種類偶数長の数列 

    v1,v2,...,vnが与えられます
    要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
    書き換える要素の数は最小でいくつになるか求めてください。

    2 <= n <= 10^5, nは偶数
    1 <= vi <= 10^5, viは整数
    """
    n = int(input())
    *v, = map(int, input().split())

    ans = f(n, v)
    print(ans)


def f(n, v):
    """
    3 1 3 2:
        3種類
        a1=a3, a2 != a4
    """
    ans = float("inf")
    v_idx_even = []
    v_idx_odd = []
    for i, x in enumerate(v):
        if i % 2 == 0:
            v_idx_even.append(x)
        else:
            v_idx_odd.append(x)

    from collections import Counter
    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

    if len(ve) == 1 and len(vo) == 1:
        # 両方1種類
        ans = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            ans = n // 2

    elif len(ve) == 1 or len(vo) == 1:
        # 片方1種類
        idx = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            idx = 1
        if len(ve) == 1:
            ans = n // 2 - vo.most_common()[idx][1]
        else:
            ans = n // 2 - ve.most_common()[idx][1]

    else:
        # 両方2種類以上
        if ve.most_common()[0][0] != vo.most_common()[0][0]:
            ans = n - ve.most_common()[0][1] - vo.most_common()[0][1]
        else:
            ans = n - \
                max(ve.most_common()[0][1] + vo.most_common()[1][1],
                    ve.most_common()[1][1] + vo.most_common()[0][1])

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 18912
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
using P=pair<int,int>;


const int MAX=100011;

int main(){
  int n;
  ll a[MAX],b[MAX],c[MAX];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    cin>>b[i];
  for(int i=0;i<n;i++)
    cin>>c[i];
  ll ans=0;
  sort(a,a+n);sort(b,b+n);sort(c,c+n);
  ll l,u;
  for(int i=0;i<n;i++){
    l=lower_bound(a,a+n,b[i])-lower_bound(a,a+n,-1);
    u=upper_bound(c,c+n,b[i])-upper_bound(c,c+n,-1);
    ans+=(l*(n-u));
    
  }
  cout<<ans<<endl;
  return 0;
}
  
      
    
  

Measured memory_bytes: 2560
import java.util.Scanner;

class Main {
	static Node node;
	static Node root;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ins;
		for (int i = 0; i < n; i++) {
			ins = sc.next();
			if (ins.equals("print")) {
				inorder(root);
				System.out.println();
				preorder(root);
				System.out.println();
			} else if (ins.equals("insert")) {
				Node z = new Node();
				z.key = sc.nextInt();
				insert(z);
			} else if (ins.equals("find")) {
				int k = sc.nextInt();
				find(k);
				System.out.println();
			}

		}
	}
	static void inorder(Node node) {
		if (node == null) return;
		inorder(node.l);
		System.out.print(" " + node.key);
		inorder(node.r);
	}

	static void preorder(Node node) {
		if (node == null) return;
		System.out.print(" " + node.key);
		preorder(node.l);
		preorder(node.r);
	}

	static void insert(Node z) {
		if (root == null) {
			root = z;
			return;
		}
		Node y = null;
		Node x = root;
		while (x != null) {
			y = x;
			if (z.key < x.key) x = x.l;
			else x = x.r;
		}

		if (z.key < y.key) y.l = z;
		else y.r = z;
	}

	static void find(int k) {
		node = root;
		while (true) {
			if (node.key > k) {
				if (node.l == null) {
					System.out.print("no");
					return;
				} else {
					node = node.l;
				}
			} else if (node.key < k) {
				if (node.r == null) {
					System.out.print("no");
					return;
				} else {
					node = node.r;
				}
			} else if (node.key == k) {
				System.out.print("yes");
				return;
			}
		}
	}
}

class Node {
	int key;
	Node l;
	Node r;
	Node() {
		key = -1;
		l = null;
		r = null;
	}
}

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

int main(){

    long long n; cin >> n;
    vector<long long> a(n + 1);
    vector<long long> b(n + 1);
    a[0] = 0;
    b[0] = 0;

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

    for(int i = 1; i <= n; i++){
        a[i] += a[i - 1];
        b[i] = (b[i] ^ b[i - 1]);
    }

    /*for(int i = 1; i <= n; i++){
        cout << a[i] << " " << b[i] << endl;
    }*/

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

            long long ub = n + 1;
            long long lb = i;
            //cout << "i = " << i << endl; 
            while(ub - lb > 1){
                long long mid = (ub + lb) / 2;
                //cout << mid << " " << (a[mid] - a[i - 1] == (b[mid] ^ b[i - 1])) << endl;
                if((a[mid] - a[i - 1] == (b[mid] ^ b[i - 1]))) lb = mid;
                else ub = mid; 
            }

            /*cout << i << " " << j << " " << (a[j] - a[i - 1]) << " " << (b[j] ^ b[i - 1]) << endl;
            if((a[j] - a[i - 1]) == (b[j] ^ b[i - 1])) ans++;
            else break;*/
            //cout << "lb = " << lb << endl;
            ans += (lb - i + 1);
    }

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

Measured memory_bytes: 3328
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

temp_list = [abs(t - i * 0.006 - a) for i in h]
min_diff = min(temp_list)
for i, temp in enumerate(temp_list):
    if temp == min_diff:
        print(i + 1)
        break

Measured memory_bytes: 9272
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    k = int(ipt())
    a = [int(i) for i in ipt().split()]
    mi = 2
    ma = 2
    for i in a[::-1]:
        mi = ((mi-1)//i+1)*i
        ma = (ma//i)*i
        if mi > ma:
            print(-1)
            exit()
        ma = ma+i-1
    print(mi,ma)

    return None

if __name__ == '__main__':
    main()


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}



int main2() {
  int N; cin >> N;
  string s; cin >> s;
  int K; cin >> K;
  char ch = s[K-1];
  REP(i, N) if (s[i] != ch) s[i] = '*';
  cout << s << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

vector<ll> par,par2; ll N,K,L;
//union-find

void initialize(){
 par.resize(N);
  
 for(ll i = 0; i < N; i++){
   par[i] = i;
 }
  //始めは任意のノードの親が自分自身
  
}

int root(ll x){
 return par[x] == x ? x : par[x] = root(par[x]);
}

void unite(ll x, ll y){
  root(x) == root(y) ? : par[root(x)] = root(y);
}

bool issame(ll x, ll y){
return root(x) == root(y);}



 
//union-find
void initialize2(){
 par2.resize(N);
 for(int i = 0; i < N; i++){
par2[i] = i;} //始めは任意のノードの親が自分自身
}

int root2(int x){
if(par2[x] == x){ return x;}
else{ return par2[x] = root2(par2[x]);}}

void unite2(int x, int y){
if( root2(x) == root2(y)){ return;}
else{
 par2[root2(x)] = root2(y);}}

bool issame2(int x, int y){
return root2(x) == root2(y);}







int main(){
  
  cin >> N >> K >> L;
  
  initialize(); initialize2();
  for(ll i = 0; i < K; i++){
    ll p, q; cin >> p >> q; p--; q--;
    unite(p,q);
    
  }
 
  
  for(ll i = 0; i < L; i++){
    ll r,s; cin >> r >> s; r--; s--;
    unite2(r,s);
    
  }
  
  map<pair<ll,ll>,ll> mp;
  
  for(ll i = 0; i < N; i++){
    mp[{root(i),root2(i)}]++;
  }
  
  for(ll i = 0; i < N; i++){
    cout << mp[{root(i),root2(i)}] << " ";}
  
  cout << endl;
  
  
  return 0;
}
    
  

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

bool palindrome(string &S) {
    for(int i = 0; i < S.size()/2; ++i){
        int j = S.size() - 1 - i;
        if(S[i] != S[j]) return false;
    }
    return true;
}

int main()
{
    string S;
    cin >> S;
    string T;
    vector<int> P;
    P.push_back(-1);
    for(int i = 0; i < S.size(); ++i)
        if(S[i] != 'x') {
            T.push_back(S[i]);
            P.push_back(i);
        }
    P.push_back((int)S.size());

    if(!palindrome(T)) { cout << -1 << endl; return 0;}

    vector<int> diff;
    for(int i = 1; i < P.size(); ++i) diff.push_back(P[i] - P[i-1]);
    int res = 0;
    for(int i = 0; i < diff.size()/2; ++i) {
        int j = diff.size() - 1 - i;
        res += abs(diff[j] - diff[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1784
/* https://atcoder.jp/contests/dp/tasks/dp_d */


#include <bits/stdc++.h>
using namespace std;
/*
             
                       .:.
                       :|:
                      .:|:.
                      ::|::
       :.             ::|::             .:
       :|:.          .::|::.          .:|:
       ::|:.         :::|:::         .:|:;
       `::|:.        :::|:::        .:|::'
        ::|::.       :::|:::       .::|:;
        `::|::.      :::|:::      .::|::'
         :::|::.     :::|:::     .::|::;
         `:::|::.    :::|:::    .::|::;'
`::.      `:::|::.   :::|:::   .::|::;'      .:;'
 `:::..     ¹::|::.  :::|:::  .::|::¹    ..::;'
   `:::::.    ':|::. :::|::: .::|:'   ,::::;'
     `:::::.    ':|:::::|:::::|:'   :::::;'
       `:::::.:::::|::::|::::|::::.,:::;'
          ':::::::::|:::|:::|:::::::;:'
             ':::::::|::|::|:::::::''
                  `::::::::::;'
                 .:;'' ::: ``::.
                      :':':
                        ;
*/

#define ll long long 
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  


    ll n,c; cin >> n >> c;
    ll val[n]; ll wt[n];
    for(ll i=0;i<n;i++) {cin >> wt[i]; cin >> val[i];}
    
    ll dp[n+1][c+1];
    memset(dp,0,sizeof(dp));

    for(ll j=1;j<=c;j++)
    {
        for(ll i=1;i<=n;i++)
        {
            if(wt[i-1]<=j)
            {
                dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            else if(wt[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    cout << dp[n][c] << endl;

}

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

int main(){
	int X, A, B, C, num;
	cin >> A >> B >> C >> X;
	num = 0;

for ( int i = 0; i < A + 1; i++){
	for(int j = 0; j < B + 1; j++){
     	for(int k = 0; k < C + 1; k++){
        	if( X == 500*i + 100*j + 50*k){
            	num++;
            }
        }
    }
	
}
	cout << num << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

ll N;
vector<ll> A;
int main()
{
    cin >> N;

    pair<ll, ll> a_min = make_pair(0, 100000000);
    pair<ll, ll> a_max = make_pair(0, -100000000);

    REP(i, N) {
        ll a;
        cin >> a;
        if(a < a_min.second) {
            a_min = make_pair(i, a);
        }
        if(a > a_max.second) {
            a_max = make_pair(i, a);
        }
        A.push_back(a);
    }

    if(a_min.second == 0 && a_max.second == 0) {
        printf("0\n");
        return 0;
    }

    DBG("a_min: %lld a_max: %lld\n", a_min.second, a_max.second);

    bool isPlus = true;     // どちらの符号に揃えるか
    if(a_max.second == 0) { isPlus = false; }
    else if(a_min.second == 0) { isPlus = true; }
    else if(a_min.second < 0 && a_max.second < 0) { isPlus = false; }
    else if(a_min.second >= 0 && a_max.second >= 0) { isPlus = true; }
    else {
        if(abs(a_max.second) < abs(a_min.second)) {
            isPlus = false;
        }
    }

    DBG("use %d\n", (isPlus) ? 1 : -1);

    vector< pair<ll, ll> > ans;
    if(isPlus) {
        // 正に寄せる
        REP(i, A.size()) {
            if(A[i] <= 0) {
                while(A[i] <= 0) {
                    A[i] += a_max.second;
                    ans.push_back(make_pair(a_max.first+1, i+1));
                }
            }
        }
        // 左から足していく
        for(int i = 1; i < A.size(); ++i) {
            if(A[i-1] > A[i]) {
                A[i] += A[i-1];
                ans.push_back(make_pair(i, i+1));
            }
        }
    } else {
        // 負に寄せる
        REP(i, A.size()) {
            if(A[i] >= 0) {
                while(A[i] >= 0) {
                    A[i] += a_min.second;
                    ans.push_back(make_pair(a_min.first+1, i+1));
                }
            }
        }
        // 右から足していく
        for(int i = A.size() - 1; i > 0; --i) {
            if(A[i-1] > A[i]) {
                A[i-1] += A[i];
                ans.push_back(make_pair(i+1, i));
            }
        }
    }

    // 答えの出力
    printf("%zu\n", ans.size());
    for(auto& p : ans) {
        printf("%lld %lld\n", p.first, p.second);
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	x := nextInt()
	res := 1
	for i := 2; i < 100; i++ {
		if i * i > x {
			break
		}

		t := i
		for t * i <= x {
			t *= i
		}

		if res < t {
			res = t
		}
	}

	fmt.Println(res)
}

Measured memory_bytes: 640
/*
  AUTHOR:SOURABH
  CREATED:27:08:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,ans=0;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a(n),post(n);
        fn(i,n)
        cin>>a[i];
        post[n-1]=a[n-1];
        fr(i,n-2)
        post[i]=(a[i]+post[i+1])%mod;
        fn(i,n-1)
        {
            ans=(ans+(a[i]*post[i+1])%mod)%mod;
        }
        cout<<ans;
    }
    return 0;
}





Measured memory_bytes: 6304
/*****************************************************

*****************************************************/

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ip pair<int, int>
#define ff first
#define ss second

#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 1e5+7;
const ll inf = 1e17;

int pwr(int x, int y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r % MOD;
}

int inv(int x)
{
    return pow(x, MOD-2);
}


void solve()
{
    int n; cin>>n;
    int d[n];
    for(int i=0;i<n;i++)
        cin>>d[i];
    sort(d, d+n);
    int ans = d[n/2]-d[n/2-1];
    cout<<ans;
}

signed main()
{
    int t=1;
    // cin >>t;
    while(t--){
        solve();
    }
    return 0;
}

/*****************************


****************************/

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
}

Measured memory_bytes: 21332
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();
    let mut same_count = 0;

    'outer: for i in (1..n + 1).rev() {
        let offset = n - i;
        for j in 0..i {
            if s[offset + j] == t[j] {
            } else {
                continue 'outer;
            }
        }
        same_count = i;
        break;
    }

    println!("{}", 2 * n - same_count);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
<?php

fscanf(STDIN, "%d %d", $a, $b);

echo sxor($b) ^ sxor($a - 1), PHP_EOL;

function sxor($x) {
    if ($x <= 0) return 0;
    ++$x;

    $ans = 0;
    for ($i = 0; $i < 50; ++$i) {
        $loop = 1<<($i + 1);

        $cnt = intdiv($x, $loop) * ($loop / 2);

        $cnt += max(0, ($x % $loop) - ($loop / 2));

        if ($cnt % 2 === 1) {
            $ans += 1<<$i;
        }
    }
/* echo "x: " . ($x - 1) . ', ans: ' . $ans . PHP_EOL; */
    return $ans;
}


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

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200];
int main(){
	int n;cin>>n;
	vector<int>v;
	int cnt=0;
	rep(i,n){
		cin>>a[i];
		if(a[i]%2==0)cnt+=a[i]/2;
		else v.push_back(a[i]);
	}
	sort(v.begin(),v.end(),greater<>());
	int sum=0;
	for(int i:v){
		sum+=i;
	}
	if(v.size()%2==1)sum-=v.back();
	cout<<cnt+sum/2<<endl;
}


Measured memory_bytes: 3148
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int h,w,n;
vector<string> vs, real_vs;

bool del(){
  bool ret = false; // 消えるかどうか
  vector<string> nvs = vs;
  // 横方向
  FOR(i,0,h){
    FOR(j,0,w-n+1){
      bool con = true;
      FOR(k,0,n-1){
        if(vs[i][j+k]!=vs[i][j+k+1]||vs[i][j+k]=='.'||vs[i][j+k+1]=='.') {
          con = false;
          break;
        }
      }
      // n連続なら消える
      if(con){
        ret = true;
        FOR(k,0,n){
          nvs[i][j+k] = '.';
        }
      }
    }
  }
  FOR(i,0,h-n+1){
    FOR(j,0,w){
      bool con = true;
      FOR(k,0,n-1){
        if(vs[i+k][j]!=vs[i+k+1][j]||vs[i+k][j]=='.'||vs[i+k+1][j]=='.') {
          con = false;
          break;
        }
      }
      if(con){
        ret = true;
        FOR(k,0,n){
          nvs[i+k][j] = '.';
        }
      }
    }
  }
  if(ret) vs = nvs;
  return ret;
}

void down(){
  FOR(i,0,w){
    int num = h - 1;
    for(int j = h - 1; j >= 0; j--){
      if(vs[j][i]!='.'){
        swap(vs[num][i], vs[j][i]);
        num--;
      }
    }
  }
}

bool ok(){
  FOR(i,0,h){
    FOR(j,0,w){
      if(vs[i][j]!='.') return false;
    }
  }
  return true;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>h>>w>>n;
  real_vs.resize(h);
  FOR(i,0,h)cin>>real_vs[i];
  FOR(i,0,h){
    FOR(j,0,w-1){
      vs = real_vs;
      //if(vs[i][j] == '.' || vs[i][j+1] == '.') continue;
      swap(vs[i][j], vs[i][j+1]);
      bool next = true;
      while(next){
        down();
        next = del();    
      }
      if(ok()){
        cout<<"YES"<<endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define fr0(i, a, b) for (long long i = a; i < b; ++i)
#define fr1(i, b, a) for (long long i = b; i >= a; --i)
#define PB push_back
#define MP make_pair
#define set0(a) memset(a, 0, sizeof(a)) 
#define setneg(a) memset(a, -1, sizeof(a))
#define trace(a) cerr << #a << ": " << a << endl
#define mod 1000000007
typedef vector<long long> vll;
typedef vector<pair<long long, long long>> vllp;
typedef pair<long long, long long> llp;
typedef long long int ll;
typedef unsigned long long ull;
// for sorting acc to second var in vector pair
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
ll Npow(ll x, ll n, ll M = 1000000007)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return Npow((x * x) % M, n / 2, M);
	return (x * Npow((x * x) % M, (n - 1) / 2, M)) % M;
}
template <typename T>
void show(T *a, int size)
{
	int i;
	cout << endl
		 << "The array is ";
	fr0(i, 0, size)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}
int main()
{
	ll n;
	cin>>n;
	ll arr[n+1][4];
	ll i,j,x;
	fr0(i,1,n+1)
	{
		fr0(j,1,4)
		{
			cin>>arr[i][j];
		}
	}
	ll dp[n+1][4];
	dp[1][1]=arr[1][1];
	dp[1][2]=arr[1][2];
	dp[1][3]=arr[1][3];
	fr0(i,2,n+1)
	{
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+arr[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+arr[i][2];
		dp[i][3]=max(dp[i-1][2],dp[i-1][1])+arr[i][3];
	}
	ll ans = max(dp[n][1],max(dp[n][2],dp[n][3]));
	cout<<ans;
}


Measured memory_bytes: 6528
A, B = list(map(str, input().split()))

a = int(A)
b = int(B[0])
b2 = int(B[2:4])
#print(b)
#print(b2)
#print(b)

b3 = b*100
bb = b3 + b2
tmp = a*bb
#print(a*b)

print(int(tmp//100))

Measured memory_bytes: 9148
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){

	double p1[2],p2[2];
	cin >> p1[0] >> p1[1] >> p2[0] >> p2[1];

	double dist = 0.;

	for(int i=0; i<2; ++i){
		dist += pow(p1[i] - p2[i], 2);
	}

	cout << fixed << setprecision(5) << sqrt(dist) << endl;
	
	return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,m,a[50],b[50],c[50],d[50];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
 
  for(int i=0;i<m;i++){
    cin>>c[i]>>d[i];
  }
  
  for(int i = 0;i<n;i++){
    int e = abs(a[i]-c[0])+abs(b[i]-d[0]);
    int f = 1;
    for(int j=0;j<m ;j++){
      int g = abs(a[i]-c[j])+abs(b[i]-d[j]);
      
      if( e>g){
        e = g;
        f = j+1;
      }
    }
    cout << f << endl;
  }
}
  
    
 


Measured memory_bytes: 256
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    int n = Integer.parseInt(br.readLine());
    String[] s=  br.readLine().split(" ");
    int[] counts = new int[9];
    for (int i=0; i<n; i++) {
      int val = Integer.parseInt(s[i]);
      if (val<=399) {
        counts[0]++;
      } else if (val<=799) {
        counts[1]++;
      } else if (val<=1199)  {
        counts[2]++;
      } else if (val<=1599) {
        counts[3]++;
      } else if (val<=1999) {
        counts[4]++;
      } else if (val<=2399) {
        counts[5]++;
      } else if (val<=2799) {
        counts[6]++;
      } else if (val<=3199) {
        counts[7]++;
      } else {
        counts[8]++;
      }
    }
    int nNonMax = 0;
    for (int i=0; i<8; i++) {
      if (counts[i]>0) {
        nNonMax++;
      }
    }
    int min = Math.max(1,nNonMax);
    int max = nNonMax+counts[8];
    System.out.println(min+ " "+max);
  }
}


Measured memory_bytes: 21204
import itertools as it

n, A = int(input()), [*map(int, input().split())]
yes_nums = set()
for bools in it.product([True, False], repeat=n):
  yes_nums.add(sum(A[i] for i in range(n) if bools[i]))

_ = input()
for m in map(int, input().split()):
  print("yes" if m in yes_nums else "no")


Measured memory_bytes: 5732
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int D = int.Parse(input[1]);

        List<List<int>> X = new List<List<int>>();
        int count = 0;

        for(int i = 0; i < N; i++) {
            string[] strPoint = Console.ReadLine().Split(' ');
            List<int> y = new List<int>();

            foreach(string item in strPoint) {
                y.Add(int.Parse(item));
            }

            for(int j = 0; j < X.Count; j++) {
                
                double sum = 0;
            
                for(int k = 0; k < D; k++) {
                    double diff = X[j][k] - y[k];
                    sum += diff * diff;
                }

                double sqrt = Math.Sqrt(sum);

                if((int)sqrt == sqrt) {
                    count++;
                }

            }
            
            X.Add(y);

        }

        Console.WriteLine(count);

    }
}

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

int main(){
  string s,t;
  cin>>s;
  cin>>t;
  int j=0;
  for(int i=0;i<s.size();i++){
    int b=s.size();
    char d=s.at(0);
    for(int i=1;i<b;i++){
      s.at(i-1)=s.at(i);
    }
    s.at(b-1)=d;
    if(s==t){
      j=1;
      break;
    }
    else
      continue;
  }
  if(j==1){
    cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
import itertools
import numpy as np

N = int(input())
stl = []
for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        stl.append((i, x-1, y))
dl = np.array(list(itertools.product([0, 1], repeat=N)), np.bool)
for i, x, y in stl:
    bl = np.logical_not(dl[:, i]) | (dl[:, x] == bool(y))
    dl = dl[bl]
res = dl.sum(axis=1).max()
print(res)


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<ll> v(n);
	fori(i, 0, n) {
		cin >> v[i];
		v[i] -= i + 1;
	}

	sort(v.begin(), v.end());

	ll chosen = v[n / 2];

	ll ans = 0;
	fori(i, 0, n) {
		ans += abs(v[i] - chosen);
	}

	cout << ans << '\n';

	return 0;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string S[6];
    for(int i=0; i<H; i++) cin >> S[i];

    int ans = 0;
    for(int a=0; a<(1<<H); a++) for(int b=0; b<(1<<W); b++){
        int cnt = 0;
        for(int i=0; i<H; i++) for(int j=0; j<W; j++) if(nth_bit(a, i) && nth_bit(b, j) && S[i][j] == '#') cnt++;
        if(cnt == K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;

int main(){
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << endl;
}




Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long n,i,j,jc[200005],ny[200005],book[200005];
long long ans,sum,flag[200005],flagg;
long long x,y,top,nex[1200005],fir[200005],to[1200005];
struct nyh{
	long long c,w,id;
}o[200005];
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
bool cmp(nyh u,nyh v){
	return u.w<v.w;
}
bool cmp2(nyh u,nyh v){
	return u.c<v.c||u.c==v.c&&u.w<v.w;
}
bool cmp3(nyh u,nyh v){
	return u.id<v.id;
}
int lj(long long u,long long v){
	top++;
	to[top]=v;
	nex[top]=fir[u];
	fir[u]=top;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long C(long long u,long long v){
	return jc[u]*ny[v]%mo*ny[u-v]%mo;
}
long long ss(long long v){
	book[v]=1;
	ans=ans*ksm(C(sum,flag[o[v].c]),mo-2)%mo;
	sum++;
	flag[o[v].c]++;
	ans=ans*C(sum,flag[o[v].c])%mo;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(book[to[top1]]==0)
			ss(to[top1]);
}
long long ss2(long long v){
	book[v]=2;
	flag[o[v].c]=0;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(book[to[top1]]!=2)
			ss2(to[top1]);
}
int main(){
	n=read();x=read();y=read();
	for(i=1;i<=n;i++){
		o[i].c=read();
		o[i].w=read();
		o[i].id=i;
	}
	sort(o+1,o+n+1,cmp);
	for(i=n;i>=2;i--)
		if(o[1].c!=o[i].c&&o[1].w+o[i].w<=y){
			flagg=i;
			lj(o[1].id,o[i].id);
			lj(o[i].id,o[1].id);
		}
	if(flagg!=0)
		for(i=1;i<=n;i++)
			if(o[i].c!=o[flagg].c&&o[i].w+o[flagg].w<=y){
				lj(o[i].id,o[flagg].id);
				lj(o[flagg].id,o[i].id);
			}
	sort(o+1,o+n+1,cmp2);
	for(i=1;i<=n;i++)
		if(i==1||o[i].c!=o[i-1].c){
			for(j=i+1;o[j].c==o[i].c;j++)
				if(o[i].w+o[j].w<=x){
					lj(o[i].id,o[j].id);
					lj(o[j].id,o[i].id);
				}
		}
	jc[0]=1;ny[0]=1;
	for(i=1;i<=n;i++){
		jc[i]=jc[i-1]*i%mo;
		ny[i]=ksm(jc[i],mo-2);
	}
	sort(o+1,o+n+1,cmp3);
	ans=1;
	for(i=1;i<=n;i++)
		if(book[i]==0){
			sum=0;
			ss(i);
			ss2(i);
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 29440
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n;
  cin >> n;
  VLL ct1(n, 0), ct2(n, 0);
  REP2(LL, i, 1, n+1)
  {
    LL a;
    cin >> a;
    if (i+a <= n-1) ++ct1[i+a];
    if (i-a >= 2) ++ct2[i-a];
  }
  LL ans = 0;
  REP(int, i, n) ans += ct1[i] * ct2[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6376
private data class Edge(val to: Int, val w: Int)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val color = IntArray(n) { -1 }

    var adjList = mutableListOf<MutableList<Edge>>()
    for (i in 0 until n) {
        adjList.add(mutableListOf<Edge>())
    }

    for (i in 0 until n - 1) {
        val (s, t, w) = readLine()!!.split(" ").map { it.toInt() }
        adjList[s-1].add(Edge(t-1, w))
        adjList[t-1].add(Edge(s-1, w))
    }

    color[0] = 0

    fun paintWithDfs(from: Int, now: Int, distance: Int) {

        if (distance % 2 == 0) {
            color[now] = if (color[from] == 0) 0 else 1
        } else {
            color[now] = if (color[from] == 0) 1 else 0
        }

        for (e in adjList[now]) {
            if (e.to == from) {
                continue
            }
            paintWithDfs(from = now, now = e.to, distance = e.w)
        }
    }

    paintWithDfs(0, 0, 0)

    for (c in color){
        println(c)
    }
}

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

int main() {
  int64_t x,k,d;
  cin>>x>>k>>d;
  
  if(abs(x)/d<k){
    int64_t a,b;
    a=abs(x)/d;
    if(x<0){
      x+=d*a;
      b=a;
      if(abs(x)>abs(x-d)){
        x-=d;
        b++;
      }
    }
    else{
      x-=d*a;
      b=a;
      if(abs(x)>abs(x+d)){
        x+=d;
        b++;
      }
    }
    
    
    if((k-b)%2==1){
      if(abs(x-d)>abs(x+d))
        x+=d;
      else
        x-=d;
    }
      
  }
  else{
    if(x>0)
      x-=d*k;
    else
      x+=d*k;
    
  }
  
  cout<<abs(x)<<endl;
}





Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

bool cmp_x(P a, P b) {
    if(a.fi != b.fi) return a.fi < b.fi;
    else return a.se < b.se;
}

bool cmp_y(P a, P b) {
    if(a.se != b.se) return a.se < b.se;
    else return a.fi < b.fi;
}

signed main() {
    int N, K;
    cin >> N >> K;
    V(P) p(N), xf(N), yf(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        P t = P(x, y);
        p[i]=t; xf[i]=t; yf[i]=t;
    }
    sort(ALL(xf), cmp_x); sort(ALL(yf), cmp_y);

    int res = 5e18;
    for(int xi=0; xi<N-1; xi++) {
        for(int xj=xi+1; xj<N; xj++) {
            for(int yi=0; yi<N-1; yi++) {
                for(int yj=yi+1; yj<N; yj++) {
                    int mix=xf[xi].fi, max=xf[xj].fi;
                    int miy=yf[yi].se, may=yf[yj].se;

                    int cnt = 0;
                    rep(i, N) {
                        int px=p[i].fi, py=p[i].se;
                        if((mix<=px && max>=px) && (miy<=py && may>=py)) cnt++;
                    }

                    if(cnt>=K) {
                        int s = (max-mix)*(may-miy);
                        res = min(res, s);
                    }
                }
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const long long INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	vector<int> a(3*N);
	for (int i = 0; i < 3*N; i++) cin >> a[i];

	priority_queue<int, vector<int>, greater<int>> queue_l;
	vector<long long> sum_l(N+1);
	for (int i = 0; i < N; i++) {
		queue_l.push(a[i]);
		sum_l[0] += a[i];
	}
	for (int i = 0; i < N; i++) {
		queue_l.push(a[i+N]);
		sum_l[i+1] = sum_l[i] + a[i+N] - queue_l.top();
		queue_l.pop();
	}

	priority_queue<int, vector<int>> queue_r;
	vector<long long> sum_r(N+1);
	for (int i = 0; i < N; i++) {
		queue_r.push(a[i+2*N]);
		sum_r[N] += a[i+2*N];
	}
	for (int i = 0; i < N; i++) {
		queue_r.push(a[2*N-1-i]);
		sum_r[N-1-i] = sum_r[N-i] + a[2*N-1-i] - queue_r.top();
		queue_r.pop();
	}

	long long ans = -INF;
	for (int i = 0; i < N+1; i++) {
		ans = max(ans, sum_l[i] - sum_r[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4088
(n, m) = parse.([Int], split(readline()))
MOD = 10^9 + 7

if 1 < abs(n - m)
    ans = 0
else
    ans = 1
    for i in 1 : n
        ans *= i
        ans %= MOD
    end
    for i in 1 : m
        ans *= i
        ans %= MOD
    end
    if n == m
        ans *= 2
        ans %= MOD
    end
end
println(ans)

Measured memory_bytes: 174352
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, x, y;
const int maxN = 2e5 + 10;
int c[maxN], w[maxN];
vector < int > g[maxN];
vector < pair < int, int > > f[maxN];
bool used[maxN];
map < int, int > mp;
void dfs(int v) {
    used[v] = true;
    mp[c[v]]++;
    for (int to : g[v]) {
        if (!used[to]) dfs(to);
    }
}
const int mod = (int)1e9 + 7;
int fact[maxN];
int invfact[maxN];
int inv[maxN];
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    inv[1] = fact[0] = invfact[0] = invfact[1] = fact[1] = 1;
    for (int i = 2; i < maxN; i++) {
        inv[i] = mult(inv[mod % i], mod - mod / i);
        fact[i] = mult(fact[i - 1], i);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
    cin >> n >> x >> y;
    vector < pair < int, int > > t;
    for (int i = 1; i <= n; i++) {
        cin >> c[i] >> w[i];
        assert(c[i] <= n);
        f[c[i]].emplace_back(make_pair(w[i], i));
        t.emplace_back(w[i], i);
    }
    sort(t.begin(), t.end());
    vector < int > r;
    for (auto it : t) {
        bool has = false;
        for (int q : r) {
            if (c[q] == c[it.second]) {
                has = true;
                continue;
            }
            else {
                if (w[q] + w[it.second] <= y) {
                    g[q].emplace_back(it.second);
                    g[it.second].emplace_back(q);
                }
            }
        }
        if (!has && r.size() < 3) r.emplace_back(it.second);
    }
    for (auto it : r) {
        for (int i = 1; i <= n; i++) {
            if (it == i) continue;
            if (c[it] == c[i]) continue;
            if (w[it] + w[i] <= y) {
                g[it].emplace_back(i);
                g[i].emplace_back(it);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (f[i].empty()) continue;
        sort(f[i].begin(), f[i].end());
        for (int p = 1; p < f[i].size(); p++) {
            if (f[i][0].first + f[i][p].first <= x) {
                g[f[i][0].second].emplace_back(f[i][p].second);
                g[f[i][p].second].emplace_back(f[i][0].second);
            }
        }
    }
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            mp.clear();
            dfs(i);
            int sz = 0;
            for (auto it : mp) {
                ans = mult(ans, invfact[it.second]);
                sz += it.second;
            }
            ans = mult(ans, fact[sz]);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 39024
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e5+100;
long long t,a,n;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        int tt;
        cin>>tt;
        t+=tt%2!=0;
        a+=tt%4==0;
    }
    if(((n-t-a)!=0&&t<=a)||(n-t-a)==0&&t<=a+1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

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

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long a[1000];
int main()
{
    long long N,K,sum=0;
    scanf("%lld %lld",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+N);
    for(int i=0;i<K;i++) sum+=a[i];
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



struct UnionFind
{

  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]); 
  }

  bool unite(int x, int y) {

    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];

    return true;
  }

  bool find(int x,int y){
    return root(x)==root(y);
  }

  int size(int x) {
    return sizes[root(x)];
  }
};


main(){
  int n,m;
  cin>>n>>m;
  UnionFind uf(n);
  set<int> a,b;
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    uf.unite(x,y);
  }

  int ans=0;
  rep(i,n){
    ans+=(uf.root(i)==i);
  }

  cout<<ans<<endl;
}


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

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i + 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
def count_order(x):
    count = 1
    while True:
        x = int(x/10)
        if x != 0:
            count += 1
        else:
            break
    return count

def F(A,B):
    a = count_order(A)
    b = count_order(B)
    if a > b:
        return a
    else:
        return b
min_order = 10
for A in range(1, int(N**0.5)+1):
    if N % A == 0:
        B = N / A
        
        order = F(A,B)
        if order < min_order:
            min_order = order
print(min_order)
    

Measured memory_bytes: 3060