akhauriyash/Code-Regression huggingface dataset:
import sys

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


def main():
    N, *A = map(int, read().split())
    A.sort()

    M = 10 ** 6
    B = [True] * (M + 1)
    B[0] = False
    ans = 0
    for i in range(N):
        if not B[A[i]]:
            continue
        if i < N - 1 and A[i + 1] == A[i]:
            B[A[i]] = False
        else:
            ans += 1
        for n in range(2 * A[i], M + 1, A[i]):
            B[n] = False

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 108460
#include<bits/stdc++.h>
using namespace std;
int n, a, ans = 0;
multiset<int> s;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%d", &a);
        if(s.upper_bound(-a) == s.end()) {
            s.insert(-a);
            ans++;
        }
        else {
            s.erase(s.upper_bound(-a));
            s.insert(-a);
        }
    }
    cout << ans;
}

Measured memory_bytes: 4992
S = input()
A,B = int(S[0:2]),int(S[2:])
if A<13 and A>0:
    if B < 13 and B>0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if B < 13 and B>0:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
h,w,a,b=map(int,input().split())
mod=10**9+7
fuc=[1]
for i in range(1,h+w):
    e=fuc[i-1]*i
    fuc.append(e%mod)

def com(n,k):
    com=(fuc[n]%mod)*pow(fuc[k],mod-2,mod)*pow(fuc[n-k],mod-2,mod)
    return com

s=0
for i in range(1,h-a+1):
    s+=com(i-2+b,i-1)*com(w-b-1+h-i,w-b-1)
print(s%mod)    

Measured memory_bytes: 13076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

/*
1
4
0011
 */
public class Main {

    public static void main(String[] args) {
        FastScanner fs=new FastScanner();
        int T=1;//fs.nextInt();
//        PrintWriter out=new PrintWriter(System.out);
        for (int tt=0; tt<T; tt++) {
            //solve
            int n=fs.nextInt();
            char[] a=fs.next().toCharArray();
            ArrayList<Integer>ws=new ArrayList<>(),
                    rs=new ArrayList<>();
            for(int i=0;i<a.length;i++){
                if(a[i]=='W'){
                    ws.add(i);
                }
                else{
                    rs.add(i);
                }
            }
            int wInd=0,rInd=rs.size()-1;
            int count=0;
            while( wInd<ws.size()&& rInd>=0 && ws.get(wInd)<rs.get(rInd)){
                count++;
                wInd++;
                rInd--;
            }
            System.out.println(count);
        }

    }

    static final Random random=new Random();

    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] nextArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 42384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

using namespace std;

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define	show(x)	 copy( (x).begin(), (x).end(), ostream_iterator<int>(cout, ",") );	// container<int>を全て表示

using namespace std;

typedef long long ll;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
	string S;
	ll N = 0;
	ll M = 0;
	ll curr = 0;

	cin >> N;
	cin >> S;

	Rep(i, N) {
		if( S[i] == 'I') {
			curr++;
		}
		else {
			curr--;
		}
		M = max(M, curr);
	}

	cout << M << endl;
}


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

int a[2][110];
int dp[2][110];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < N; j++){
			cin >> a[i][j];
			dp[i][j] += a[i][j];
			if(i == 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
		}
	}
	cout << dp[1][N - 1] << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
cumsumA = []

total = 0
for a in A:
    total += a
    cumsumA.append(total)
cumsumA.append(0)

l = 0
r = 10 ** 6
while l + 1 < r:
    num = (l+r)//2
    pair_idx = n-1
    count = 0
    for a in A:
        while a + A[pair_idx] < num and pair_idx >= 0:
            pair_idx -= 1

        count += pair_idx+1

    if count < m:
        r = num
        continue
    elif count >= m:
        l = num


ans = 0
count = 0
num = l
pair_idx = n-1
for a in A:
    while a + A[pair_idx] < num and pair_idx >= 0:
        pair_idx -= 1

    count += pair_idx+1
    ans += cumsumA[pair_idx] + a*(pair_idx+1)

diff = count - m
ans -= num * diff
print(ans)

Measured memory_bytes: 14152
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ss () = read_line () |> split_on_char ' '

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

module SegmentTree = struct

  let default_val = ref 0

  let size = ref 0

  let make n init =
    default_val := init;
    let rec pow_of_2 i =
      if i >= n then i
      else pow_of_2 (2 * i) in
    size := pow_of_2 1;
    Array.make (2 * (!size) - 1) init

  let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

  let left i = 2*i + 1

  let right i = 2*i + 2

  let add s i x =
    let j = !size + i - 1 in
    s.(j) <- x + s.(j);
    let rec doit j =
      if j <= 0 then () else begin
        let p = parent j in
        s.(p) <- s.(left p) + s.(right p);
        doit p
      end in
    doit j

  let sum s a b =
    let rec doit k l r =
      if r <= a || b <= l then 0
      else if a <= l && r <= b then s.(k)
      else
        let m = (l + r) / 2 in
        doit (left k) l m + doit (right k) m r in
    doit 0 0 !size

end

module S = SegmentTree

let solve n q =
  let s = S.make n 0 in
  for _ = 0 to q - 1 do
    match IO.read_ns () with
    | c :: x :: y :: _ ->
      if c = 0 then S.add s (x - 1) y
      else begin
        S.sum s (x - 1) y |> print_int;
        print_newline ();
      end
    | _ -> assert false
  done

let () =
  match IO.read_ns () with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6440
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    for(int i=0;i<s.length();i++){
      System.out.print((char)(((s.charAt(i)-'A')+n)%26+'A'));
    }
  }
}

Measured memory_bytes: 25812
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_7_A&lang=jp
#  Set: Search: python3
#  2018.12.02 yonezawa

import sys
input = sys.stdin.readline
import collections

def main():
    tl = {}
    for i in range(int(input())):
        l = list(map(int,input().split()))
        if l[0] == 0:
            tl[l[1]] = 1
            print (len(tl))
        else:
            c = 1 if l[1] in tl else 0
            print (c)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 27020
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, w, dp[N];

signed main() {
  init_ios();
  cin >> n >> w;
  for (int i = 1; i < N; ++i)
    dp[i] = 1e12;
  for (int _ = 1; _ <= n; ++_) {
    int x, y;
    cin >> x >> y;
    for (int i = N-5; i >= y; --i)
      dp[i] = min(dp[i], x+dp[i-y]);
  }
  int res = 0;
  for (int i = 1; i < N-5; ++i)
    if (dp[i] <= w)
      res = i;
  cout<<res<<"\n";
}

Measured memory_bytes: 1024
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  ll n;cin >> n;

  ll t;

  rep(i,n)
  {
    if(i == 0)
    {
      cin >> t;
    }
    else
    {
      ll buf;cin >> buf;
      t = LCM(t,buf);
    }
  }
  cout << t << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int n, k;
int w[100002];

int check(int x)
{
	int i, f, s;

	f = 0, s = 0;
	for (i = 0; i < n; i++) {
		if (s + w[i] > x) {
			s = 0;
			if (++f >= k) break;
		}
		s += w[i];
	}
	return ++f <= k;
}

int main()
{
	int i, a, lo, hi, mi;
	
	n = in(), k = in();
	lo = 0, hi = 0;
	for (i = 0; i < n; i++) {
		w[i] = a = in();
		if (a > lo) lo = a;
		hi += a;
	}
	if (k == 1)    { printf("%d\n", hi); return 0; }
	if (check(lo)) { printf("%d\n", lo); return 0; }
	while (lo+1 < hi) {
		mi = (lo + hi) >> 1;
		if (check(mi)) hi = mi; else lo = mi;
	}
	printf("%d\n", hi);
	return 0;
}





Measured memory_bytes: 2172
sx, sy, tx, ty = map(int, input().split())

# first s to t
for _ in range(sx, tx):
    print('R', end='')
for _ in range(sy, ty):
    print('U', end='')

# return t to s
for _ in range(sx, tx):
    print('L', end='')
for _ in range(sy, ty):
    print('D', end='')

#Second s to T
print('D', end='')
for _ in range(sx, tx+1):
    print('R', end='')
for _ in range(sy-1, ty):
    print('U', end='')
print('L', end='')

# Return second t to s
print('U', end='')
for _ in range(sx, tx+1):
    print('L', end='')
for _ in range(sy-1, ty):
    print('D', end='')
print('R', end='')

Measured memory_bytes: 70036
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	struct s {
		long long price;
		long long num;
	};

	vector
 sp;
	int a, b;
	for(int i=0; i<n; i++){
		cin >> a >> b;
		sp.push_back({ a, b });
	}
	sort(sp.begin(), sp.end(), [](const s&x, s&y) { return x.price < y.price; });

	long long x = 0;
	long long y = 0;
	long long i = 0;

	while (x < m) {
		s shohin = sp[i];

		if (x + shohin.num <= m) {
			y += shohin.price * shohin.num;
			x += shohin.num;
		}
		else {
			y += shohin.price * (m - x);
			x = m;
		}
		i++;
	}

	cout << y << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

int mod;

vector<int> dp(100005, 0), ans(100005);
vector<int> g[100005];

void dfs(int u, int p)
{
    for(auto it = g[u].begin(); it != g[u].end(); it++)
        if(*it == p)
        {
            g[u].erase(it);
            break;
        }
    dp[u] = 1;
    for(auto &k: g[u])
        dfs(k, u), dp[u] *= (dp[k]+1), dp[u] %= mod;
}

void dfs2(int u, int p, int up)
{
    ans[u] = (dp[u]*(up+1))%mod;
    vector<int> pref(sz(g[u])+5), suff(sz(g[u])+5);
    pref[0] = 1;
    suff[sz(g[u])+1] = 1;
    for(int i = 1; i <= sz(g[u]); i++)
        pref[i] = (pref[i-1]*(dp[g[u][i-1]]+1))%mod;
    for(int i = sz(g[u]); i >= 1; i--)
        suff[i] = (suff[i+1]*(dp[g[u][i-1]]+1))%mod;
    for(int i = 1; i <= sz(g[u]); i++)
        dfs2(g[u][i-1], u, (((pref[i-1]*suff[i+1])%mod)*(up+1))%mod);
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n >> mod;
    for(int i = 0; i < n-1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    dfs(1, 1);
    dfs2(1, 1, 0);
    for(int i = 1; i <= n; i++)
        cout << ans[i] << endl;
}

Measured memory_bytes: 24052
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

// d[i][k] := ノード i から 2^(k) 移動してたどり着くノード
int d[200050][100];
const int u_b = 62;

int main(){
	ll n, k; cin >> n >> k;
   vector<int> a(n);
	for( auto &t : a ){
		cin >> t;
		--t;
	}
   for( int i = 0; i < n; ++i ){
		d[i][0] = a[i];
   }
   for( int j = 0; j < u_b; ++j ){
		for( int i = 0; i < n; ++i ){
			d[i][j+1] = d[d[i][j]][j];
		}
   }
	priority_queue<int> cand;
	for( int i = 0; i < u_b; ++i ){
		if( k bitand (1ll<<i) ){
			cand.push(i);
		}
	}
	int cur = 0;
	while( !cand.empty() ){
		cur = d[cur][cand.top()];
		cand.pop();
	}
	cout << cur+1 << endl;
}


Measured memory_bytes: 82128
INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from heapq import heapify,heappop,heappush

def main():
    n,m,d = map(int,input().split())
    if d == 0:
        ans = (n - d)*(m - 1)/pow(n,2)
    else:
        ans = 2*(n - d)*(m - 1)/pow(n,2)
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
def binary_search_1(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if data[mid] < value:
      l = mid + 1
    else:
      r = mid
  return l  

def binary_search_2(data,value):
  l=0
  r=len(data)
  while l < r:
    mid = (l+r) // 2
    if value < data[mid]:
      r = mid 
    else:
      l = mid + 1
  return l  
  
n=int(input())

a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0

for i in b:
    cnt +=(binary_search_1(a,i)*(len(c)-binary_search_2(c,i)))

print(cnt)

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

using namespace std;
using ll = long long;

string s, t;
set<vector<char>> st;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> s;

    vector<char> v;
    int n = s.size() - 1, p;
    for(int mask=0; mask<(1<<n); mask++){
        v = {}, p = 0;
        for(int i=0; i<n; i++){
            v.push_back(s[i]);
            if(mask & (1<<i)) v.push_back('+');
        }
        v.push_back(s.back());
        st.insert(v);
    }

    ll cur, glob = 0;
    for(auto it:st){
        cur = 0;
        for(auto is:it)
            if(is == '+') glob += cur, cur = 0;
            else cur *= 10, cur += is - '0';
        glob += cur;
    }

    cout << glob;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define MAX_NUM 100005

int main(){
    int n;
    cin >> n;
    int a[MAX_NUM];
    FOR(i, 1, n+1){
        cin >> a[i];
    }

    int ans = 0;

    FOR(i, 1, n+1){
        if(i == a[a[i]]) ans++;  
    }

    cout << ans/2 << endl;
}


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

#define ran 1011

const int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

int n, m;
char s[ran][ran];
int d[ran][ran];
int q[ran*ran*2], l, r;

int main() {
	scanf("%d%d", &n, &m);
	memset(d, -1, sizeof d);
	l = r = 0;
	for(int i=0;i<n;i++) {
		scanf("%s", s[i]);
		for(int j=0;j<m;j++)
			if(s[i][j]=='#') {
				q[r++] = i;
				q[r++] = j;
				d[i][j] = 0;
			}
	}
	
	int ans=0;
	while(l<r) {
		int cur_x = q[l++], cur_y = q[l++];
		int cur_d = d[cur_x][cur_y];
		for(int i=0;i<4;i++) {
			int x = cur_x + go[i][0], y = cur_y + go[i][1];
			if(x<0 || x>=n || y<0 || y>=m) continue;
			if(d[x][y]>=0) continue;
			
			d[x][y] = cur_d + 1;
			q[r++] = x; q[r++] = y;
			ans = max(ans, d[x][y]);
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 13184
$D = []
$inf = 2147483647
def init(n_)
  n=1
  while(n<n_) do n*=2 end
  0.upto(2*n-1){
    $D<<$inf
  }
end
def update(a,b,k,l,r,x)
  if(r<=a||b<=l)
    return
  end
  if(a<=l&&r<=b)
    $D[k]=x
  else
    if($D[k]!=$inf)
      $D[k*2+1]=$D[k]
      $D[k*2+2]=$D[k]
      $D[k]=$inf
    end
    update(a,b,k*2+1,l,(l+r)/2,x)
    update(a,b,k*2+2,(l+r)/2,r,x)
  end
end
def find(a,b,k,l,r)
  if(r<=a||b<=l)
    return $inf
  end
  if(a<=l&&r<=b)
    return $D[k]
  else
    if($D[k]!=$inf)
      $D[k*2+1]=$D[k]
      $D[k*2+2]=$D[k]
      $D[k]=$inf
    end
    return [find(a,b,k*2+1,l,(l+r)/2),find(a,b,k*2+2,(l+r)/2,r)].min
  end
end

n, q = gets.split.map(&:to_i)
init(n)
q.times{
  u,s,t,x = gets.split.map(&:to_i)
  if(u == 0)
    update(s,t+1,0,0,n,x)
  else
    puts find(s,s+1,0,0,n) if n!=1
    puts $D[0] if n==1
  end
}



Measured memory_bytes: 9168
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>

#define MAX_V 400

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int INF=0x7fffffff;

struct edge{int to,cap,cost,rev;};
int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost)
{
	edge a={to,cap,cost,G[to].size()};
	G[from].push_back(a);
	edge b={from,0,-cost,G[from].size()-1};
	G[to].push_back(b);
}

int min_cost_flow(int s,int t,int f)
{
	int res=0;
	while(f>0)
	{
		fill(dist,dist+V,INF);
		dist[s]=0;
		bool update=true;
		while(update)
		{
			update=false;
			for(int v=0;v<V;v++)
			{
				if(dist[v]==INF)continue;
				for(int i=0;i<G[v].size();i++)
				{
					edge &e=G[v][i];
					if(e.cap>0&&dist[e.to]>dist[v]+e.cost)
					{
						dist[e.to]=dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						update=true;
					}
				}
			}
		}
		if(dist[t]==INF)
			return -1;

		int d=f;
		for(int v=t;v!=s;v=prevv[v])
		{
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*dist[t];
		for(int v=t;v!=s;v=prevv[v])
		{
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}


int main()
{
	int Cnt;
	int n,v,f;
	for(;scanf("%d",&Cnt),Cnt;)
	{
		n=366;
		V=366;
		for(int i=0;i<Cnt;i++)
		{
			int a,b,cost;
			scanf("%d%d%d",&a,&b,&cost);
			add_edge(a-1,b,1,-cost);
		}
		for(int i=0;i<366;i++)add_edge(i,i+1,2,0);
		printf("%d\n",-min_cost_flow(0,365,2));
		for(int i=0;i<366;i++)G[i].clear();
	}
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e3 + 5;
const int M = (int) 1e4 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

ll x,n;
ll a[N],b[N];
ll dp[N][M];
ll call(ll pos,ll xx){
    if(pos>n){
        if(xx<=0)return 0ll;
        else{
            return (ll)100000000;
        }
    }
    if(xx<=0)return 0ll;
    if(dp[pos][xx]!=-1)return dp[pos][xx];

    return dp[pos][xx]=min({b[pos]+call(pos+1,xx-a[pos]),call(pos+1,xx),b[pos]+call(pos,xx-a[pos])});
}

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

    int t=1,te=0;
    // cin>>t;
    while(t--){
        cin>>x>>n;

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

        memset(dp,-1,sizeof(dp));

        ll res= call(1,x);

        printf("%lld\n", res);

        //printf("Case %d: ",++te);
    }
    return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100100;

int n;
int a[maxn + 5];

inline bool solve()
{
	sort(a, a + n);
	if (a[0] == a[n - 1])
	{
		if (a[0] == n - 1) return 1;
		return (a[0] << 1) <= n;
	}
	int p = upper_bound(a, a + n, a[0]) - a;
	if (a[n - 1] - a[0] > 1) return 0;
	if (a[n - 1] <= p) return 0;
	return ((a[n - 1] - p) << 1) <= (n - p);
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);
	REP(i, 0, n) scanf("%d", a + i);
	puts(solve() ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 640
import sys
n, k = map(int, input().split())
if k > (n-1)*(n-2)//2:
  print(-1)
  sys.exit()

key = 0
ans = []
for i in range(2, n+1):
  if k == 0:
    for j in range(1, i):
      ans.append((i, j))
  else:
    ans.append((1, i))
    if k >= key:
      k -= key
      key += 1
    else:
      key -= k
      for j in range(2, 2+key):
        ans.append((i, j))
      k = 0

print(len(ans))
for value in ans:
  print(*value)

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main()
{
    vector<int> v(11);

    for(int i = 0; i < 3; ++i) {
        int x;
        cin >> x;
        v[x]++;
    }

    cout << (v[5] == 2 && v[7] == 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			2011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
 
}

char a[M][M];
vii r[M],c[M];


int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>n>>m;
    lp(1,n){

    	lpj(1,m){
    		char cc;cin>>cc;a[i][j]=cc;
    		if(cc=='#')
    			r[i].pb(j),c[j].pb(i);
    	}
    }
    lp(1,n)r[i].pb(0),r[i].pb(m+1);
    lp(1,m)c[i].pb(0),c[i].pb(n+1);
    lp(1,n)sort(all(r[i]));
    lp(1,m)sort(all(c[i]));
    ll mx=-inf;
    lp(1,n){
    	lpj(1,m){
    		if(a[i][j]=='#')continue;
    		ll cnt=0;
    		x=0,p=r[i].size();
    		for(;p>=1;p/=2){
    			while(x+p<r[i].size()&&r[i][x+p]<=j)x+=p;
    		}
    		cnt+=-r[i][x]+r[i][x+1]-1;
    		x=0,p=c[j].size();
    		for(;p>=1;p/=2){
    			while(x+p<c[j].size()&&c[j][x+p]<=i)x+=p;
    		}
    		cnt+=(-c[j][x]+c[j][x+1]-1);
    		cnt-=1;
    		mx=max(mx,cnt);

    	}
    }
    cout<<mx<<"\n";



}



Measured memory_bytes: 71040
#include <stdio.h>

int main(void)
{
  int a;
  int b;
  int h;

  scanf("%d\n",&a);
  scanf("%d\n",&b);
  scanf("%d\n",&h);

  int ans;
  ans = (a+b)*h/2;
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 1692
# coding: utf-8
# Your code here!
N=int(input())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,b])
#print(L)
L.sort(key=lambda x: x[1])
#print(L)

t=0
ans=0
for i in range(N):
    if t+L[i][0]<=L[i][1]:
        ans+=1
        t+=L[i][0]

if ans==N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38044
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ull mod1 = 2e18 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 3e5 + 5;
int t;


int main()
{
	//freopen("in.txt", "r", stdin);
	string s;
	while (cin >> s)
	{
		int half = (s.size() - 1) / 2;
		int ans = 0;
		f(i, 0, half)if (s[i] != s[s.size() - i - 1])ans++;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
a,b = [int(i) for i in input().split()]
if a > 0:
  print('Positive')
elif a == 0:
  print('Zero')
else:
  if b >= 0:
    print('Zero')
  elif abs(b-a) % 2 == 0:
    print('Negative')
  else:
    print('Positive')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 a; string s;
  cin >> a >> s;
  cout << (a >= 3200 ? s : "red") << endl;

  return 0;
}



Measured memory_bytes: 256
n=int(input())
a_list=list(map(int,input().split()))
pre1=[]
pre2=[]
for i in range(20):
    pre1.append(-1)
    pre2.append(-1)
ans=0
for i in range(n):
    Min=n
    s=format(a_list[i],'b').zfill(20)
    for j in range(20):
        if s[j]=='0':
            Num=i-pre2[j]
        else:
            Num=i-pre1[j]
            pre2[j]=pre1[j]
            pre1[j]=i
        Min=min(Min,Num)
    ans=ans+Min
print(ans)
    


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

using namespace std;

#define scnaf scanf
#define sacnf scanf
#define sancf scanf

#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define MP(a,b) make_pair((a),(b))
#define PB(a) push_back((a))
#define P(p) cout << (p) << endl;
#define S(s) cin >> (s);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,(n))
#define rreps(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define rrep(i,n) reprt(i,n,0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

void Yes(bool f) {if(f){P("Yes");}else{P("No")}}
void yES(bool f) {if(f){P("yES");}else{P("nO")}}
void Yay(bool f) {if(f){P("Yay!");}else{P(":(")}}

/*********TEMPLATE**********/

ll N;

void init() {

  S(N);

}

signed main() {

  init();

  ll ans = INFF;

  reps(i,1,N) {
    ll A = i;
    ll B = N - A;
    ll tmp = 0;
    while(A) {
      tmp += A % 10;
      A /= 10;
    }
    while (B) {
      tmp += B % 10;
      B /= 10;
    }
    chmin(ans,tmp);
  }

  P(ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
using namespace std;
int dp[14349000];
const int INF=1e9+7;

int sti(string s){
  int res=0;int k=1;
  for(int i=0;i<s.size();i++){
    res+=(s[i]-'0')*k;
    k*=3;
  }
  return res;
}
int pw(int a,int b){
  int res=1;
  while(b--)res*=a;
  return res;
}

signed main(){
  std::vector<int> ans;
  while(true){
    int N,M;cin>>N>>M;if(N==0&&M==0)break;
    string s(N,'0');
    int a;cin>>a;
    for(int i=0;i<a;i++){int b;cin>>b;s[b-1]='0';}
    cin>>a;
    for(int i=0;i<a;i++){int b;cin>>b;s[b-1]='1';}
    cin>>a;
    for(int i=0;i<a;i++){int b;cin>>b;s[b-1]='2';}
    for(int i=0;i<14349000;i++)dp[i]=INF;
    dp[sti(s)]=0;
    //cout<<dp[0]<<endl;
    //cout<<s<<" "<<sti(s)<<endl;
    queue<string> que;que.push(s);
    while(dp[0]==INF&&dp[pw(3,N)-1]==INF&&que.size()){
      int a,b,c;a=b=c=-1;
      string t=que.front();que.pop();
      if(dp[sti(t)]>M)break;
      for(int i=0;i<t.size();i++){
        if(t[i]=='0')a=i;
        if(t[i]=='1')b=i;
        if(t[i]=='2')c=i;
      }
      string t1,t2;t1=t2=t;
      if(a>b)t1[a]='1';
      if(a<b)t1[b]='0';
      if(b<c)t2[c]='1';
      if(b>c)t2[b]='2';
      if(dp[sti(t1)]>dp[sti(t)]+1){dp[sti(t1)]=dp[sti(t)]+1;que.push(t1);}
      if(dp[sti(t2)]>dp[sti(t)]+1){dp[sti(t2)]=dp[sti(t)]+1;que.push(t2);}
    }
    //for(int i=0;i<27;i++)cout<<dp[i]<<" ";cout<<endl;
    if(min(dp[0],dp[pw(3,N)-1])<=M)ans.push_back(min(dp[0],dp[pw(3,N)-1]));
    else ans.push_back(-1);
  }
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
}



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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
void findNumberOfDigits(long n, int base)
{
    int dig = (int)(floor( log(n) /
                         log(base)) + 1);

    cout << dig << endl;
}
int main()
{ FAST
    int n, k; cin >> n >> k;
    findNumberOfDigits(n, k);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;



int main(){
  int n,k;
  cin>>n>>k;
  vector<bool> have(n);
  rep(i,n) have[i]=true;
    
  rep(i,k){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      --a;
      have[a]=false;
    }
  }
  int ans=0;
  rep(i,n){
    if(have[i]==true) ans++;
  }
  
  cout<<ans<<endl;
 
}


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

long a[3002];
long long dp[3002][3002] = {};

long long rec(int begin, int end, int turn){
    if(dp[begin][end] != -1) return dp[begin][end];
    if(begin == end) return dp[begin][end] = turn*a[begin];

    if(turn == 1){
        return dp[begin][end] = max(rec(begin+1, end, -turn) + turn*a[begin],
                                    rec(begin, end-1, -turn) + turn*a[end]);
    }
    else{
        return dp[begin][end] = min(rec(begin+1, end, -turn) + turn*a[begin],
                                    rec(begin, end-1, -turn) + turn*a[end]);
    }
}

int main(){
    int N;
    cin >> N;
    for(int n=0;n<N;n++) cin >> a[n];
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = -1;
        }
    }
    cout << rec(0, N-1, 1) << endl;
    return 0;
}

Measured memory_bytes: 70912
import sys
sys.setrecursionlimit(10**9)

def dfs(v):
  if len(g[v])==0:
    return 0
  dic={}
  for u in g[v]:
    tmp=dfs(u)
    if tmp not in dic:
      dic[tmp]=1
    else:
      dic[tmp]+=1
  arr=[]
  for pos in dic.keys():
    arr+=[pos]*dic[pos]
  arr=sorted(arr,reverse=True)
  return max([(i+1)+arr[i] for i in range(len(arr))])

n=int(input())
g=[[] for _ in range(n+1)]
for i in range(n-1):
  v=int(input())
  g[v].append(i+2)
print(dfs(1))

Measured memory_bytes: 159536
/* ITP1_2_D: Circle in a Rectangle */

#include <iostream>
using namespace std;

bool between(int from, int v, int to) {
    return from <= v && v <= to;
}

int main() {
    int W, H, x, y, r, c_x = 0, c_y = 0;
    cin >> W >> H >> x >> y >> r;

    bool is_inside =
           between(c_x, x, W)
        && between(c_y, y, H)
        && between(c_x + r, x, W - r)
        && between(c_y + r, y, H - r);

    cout << ( is_inside ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int main()
{
    int n;
    cin >> n;
    double sum = 0.f;
    for(int i = 0; i < n; ++i)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
        {
            sum += x;
        }
        else 
        {
            sum += x * 380000.f;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

int main() {
	ios;
    ld a,b;
   cin>>a>>b;
   cout<<((ll)floor(a*b));
	return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	string ans = "Yes";

	REP(i, INF) {
		if (IsEven(i)) {
			C -= B;
			if (C <= 0) {
				break;
			}
		} else {
			A -= D;
			if (A <= 0) {
				ans = "No";
				break;
			}
		}
	}

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


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin>>N;
  ll ans=N;
  for(int i=1;i<=(int)sqrt(N);i++){
    if(N%i==0)ans=min(ans,i+(N/i)-2);
  }
  cout<<ans;
  return 0;
}

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

int main() {
	long long a,b,c,x,y,ans=0;
	cin >> a >> b >> c >> x >> y;
	
	if(x>y){
		swap(x,y); swap(a,b);
	}
	if(a+b>c*2){
		ans+=c*2*x;
		if(b>c*2){
			ans+=c*2*(y-x);
		}else{
			ans+=b*(y-x);
		}
	}else{
		ans+=a*x+b*y;
	}
	cout << ans;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> data(N);
  for(int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    data.at(i) = make_pair(a, b);
  }
  sort(data.begin(), data.end());
  int ans = 0;
  priority_queue<int> keep;
  int start = 0;
  for(int i = 0; i < M; i++) {
    if(start <= N - 1) {
      for(int j = start; j < N && data.at(j).first <= i + 1; j++) {
        keep.push(data.at(j).second);
        start++;
      }
    }
    if(!keep.empty()) {
      ans += keep.top();
      keep.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    
    int ans = 0;
    for(int i = 0; i < s.size() / 2; i++) {
        if(s[i] !=  s[s.size() - 1 - i]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#define N 100000
#define mod 1000000007
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define minn(a,b) a=min(a,b)

using namespace std;

int a[3333];
long long dp[3333][3333];

long long rec(int l, int r)
{
	if(l == r) return a[l];
	if(dp[l][r]!=-1)return dp[l][r];
	dp[l][r]=max(a[l] - rec(l + 1, r), a[r] - rec(l, r - 1));
	return dp[l][r];
}

int main(int argc, char const *argv[]) {

	int n;cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		memset(dp[i],-1,sizeof dp[i]);
	}
	cout << rec(0, n - 1);
}



Measured memory_bytes: 80256
#include <stdio.h>

static const int topfront[6][6] = {
    {-1, 2, 4, 1, 3, -1},
    {3, -1, 0, 5, -1, 2},
    {1, 5, -1, -1, 0, 4},
    {4, 0, -1, -1, 5, 1},
    {2, -1, 5, 0, -1, 3},
    {-1, 3, 1, 4, 2, -1}};

int find6(int numbers[6], int n)
{
    for (int *elm = numbers, *const end = elm + 6; elm != end; ++elm)
    {
        if (*elm == n)
        {
            return (int)(elm - numbers);
        }
    }
    return -1;
}

int main(int argc, char *argv[])
{
    int numbers[6];
    for (int *elm = numbers, *const end = elm + 6; elm != end; ++elm)
    {
        scanf("%d", elm);
    }
    int n;
    scanf("%d", &n);
    int rights[24];
    for (int *elm = rights, *const end = elm + n; elm != end; ++elm)
    {
        int top, front;
        scanf("%d%d", &top, &front);
        *elm = topfront[find6(numbers, top)][find6(numbers, front)];
    }
    for (int *elm = rights, *const end = elm + n; elm != end; ++elm)
    {
        printf("%d\n", numbers[*elm]);
    }
    return 0;
}



Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> ans = { 1, 4, 7, 9};
  vector<int> N(4);
  for (int i = 0; i < 4; i++){
    cin >> N.at(i);
  }
  sort(N.begin(),N.end());
  if (N == ans)
    cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N;
	cin >> N;

	int n = sqrt(N);

	while (1) {
		if (N % n == 0) break;
		n--;
	}

	int a = n, b = N / n;
	COL(a+b-2);

	return 0;
}

Measured memory_bytes: 256