akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces



H, W = na()
S = [ns() for _ in range(H)]
tmp = [[0] * W for _ in range(H)]

tmp2 = [[0] * W for _ in range(H)]
for i in range(H):
    ct = 0
    for j in range(W):
        if S[i][j] == '#':
            if ct != 0:
                for k in range(ct):
                   tmp[i][j-(k+1)] += ct 
            ct = 0
        else:
            ct += 1
    if ct != 0:
        for k in range(ct):
            tmp[i][j-k] += ct 
    

for j in range(W):
    ct = 0
    for i in range(H):
        if S[i][j] == '#':
            if ct != 0:
                for k in range(ct):
                   tmp[i-(k+1)][j] += ct - 1
            ct = 0
        else:
            ct += 1
    if ct != 0:
        for k in range(ct):
            tmp[i-k][j] += ct - 1

ans = -1
for i in range(H):
    for j in range(W):
        ans = max(ans, tmp[i][j])
print(ans)

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

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x.at(i).at(j);
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int dist = 0;
            for (int k = 0; k < d; k++) {
                dist += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
            }

            for (int k = 1; k * k <= dist; k++) {
                if (k * k == dist) {
                    ans++;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    uint64_t N;

    scanf("%"PRIu64, &N);

    if (N <= 9) {
        printf("%"PRIu64, N);
    }
    else if (N <= 99) {
        printf("9");
    }
    else if (N <= 999) {
        printf("%"PRIu64, N - 90);
    }
    else if (N <= 9999) {
        printf("909");
    }
    else if (N <= 99999) {
        printf("%"PRIu64, N - 9090);
    }
    else {
        printf("90909");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,s,count=0,z,n=0;
	cin>>k>>s;
for(int x=0;x<=k;x++){
	for(int y=0;y<=k;y++){
		if(x+y<=s){
		     z=s-(x+y);
		     if(z<=k)
		          count++;
	}
}
}
	cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
 
int main(){
int S,W;
  cin>>S>>W;
  if(S<=W)cout<<"unsafe";
  else cout<<"safe";
return 0;
 
 
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1,
     14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
     int i,n;
     cin>>n;
     cout<<a[n-1];
}


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

using namespace std;

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define trace(x) cerr << #x << ": " << x << " " << endl;

#define sz(a) ( (int) (a).size() )
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for(auto (it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end()) //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i) REP(i, 0, n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<int>::iterator vit;

const int N = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    cout << (n*(n-1))/2 + (m*(m-1))/2 << endl;
}

int32_t main(int32_t argc, char** argv) {
    fastio;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<stack>

using namespace std;

int n;
int m;
int ini;
string ins;
map<string,long long> item;
vector<string> change[200];

int minmoney(string ss){
	int mm=item[ss];
	for(int i=0;i<m;i++){
		if(change[i][0]==ss){
			int cm=0;
			for(int j=1;j<change[i].size();j++){
				cm+=minmoney(change[i][j]);
			}
			if(cm<mm) item[ss]=cm;
		}
	}
	return item[ss];
}

int main(){

	
	

	while(1){

		cin>>n;
		if(n==0) break;

		if(!item.empty()) item.clear();
		for(int i=0;i<200;i++){
			if(!change[i].empty()) change[i].clear();
		}

		for(int i=0;i<n;i++){
			cin>>ins>>ini;
			item[ins]=ini;
		}

		cin>>m;

		for(int i=0;i<m;i++){
			cin>>ins;
			change[i].push_back(ins);
			cin>>ini;
			for(int j=0;j<ini;j++){
				cin>>ins;
				change[i].push_back(ins);
			}
		}

		cin>>ins;

		cout<<minmoney(ins)<<endl;

	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

// i<j
// j-i = a[i]+a[j]
// a[i]+i = j-a[j]

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,int> mp;
  ll ans = 0;
  rep(i,n) {
    int sa = i-a[i];
    int wa = a[i]+i;
    ans += mp[sa];
    mp[wa]++;
  }
  cout << ans << endl;
  return 0;
}

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

const int maxn = 2000;

int n, k, dep[maxn];
vector<int> g[maxn];

void Dfs(int u, int p) {
  for (int v : g[u]) {
    if (v == p) continue;
    dep[v] = dep[u] + 1;
    Dfs(v, u);
  }
}

int Dfs2(int u, int d, int lim, int p) {
  if (dep[u] > lim) return 0;
  if (d == k) return 1;
  int ans = 1;
  for (int v : g[u]) {
    if (v == p) continue;
    ans += Dfs2(v, d + 1, lim, u);
  }
  return ans;
}

int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dep[0] = 0;
  Dfs(0, -1);
  int ans = 0;
  for (int s = 0; s < n; ++s) {
    ans = max(ans, Dfs2(s, 0, dep[s], -1));
  }
  printf("%d\n", n - ans);
  return 0;
}


Measured memory_bytes: 512
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Measured memory_bytes: 73660
h,w = map(int,input().split())

if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    best = (h*w)/3
    # wから割る方法
    col_num = int(round(best/h))
    remain_w = w - col_num
    h1 = h // 2
    h2 = h - h1
    w1 = remain_w // 2
    w2 = remain_w - w1
    min_area1 = min(remain_w*h1, remain_w*h2, col_num*h) # 垂直
    max_area1 = max(remain_w*h1, remain_w*h2, col_num*h)
    min_area2 = min(w2*h, w1*h, col_num*h) # 平行
    max_area2 = max(w2*h, w1*h, col_num*h)
    num_w1 = max_area1 - min_area1
    num_w2 = max_area2 - min_area2
    # hから割る方法
    row_num = int(round(best/w))
    remain_h = h - row_num
    w1 = w // 2
    w2 = w - w1
    h1 = remain_h // 2
    h2 = remain_h - h1
    min_area1 = min(remain_h*w1, remain_h*w2, row_num*w) # 垂直
    max_area1 = max(remain_h*w1, remain_h*w2, row_num*w)
    min_area2 = min(h2*w, h1*w, row_num*w) # 平行   
    max_area2 = max(h2*w, h1*w, row_num*w)
    num_h1 = max_area1 - min_area1
    num_h2 = max_area2 - min_area2
    print(min(num_h1,num_w1,num_h2,num_w2))

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

const int N = 1000010;

char s[N], tmp[N];

int ct[3], fucked[N];

vector<int> pos, pos2;

int main() {
    int n, tp = 0; scanf("%s", tmp + 1); n = strlen(tmp + 1);
    for (int i = 1; i <= n; i++) 
        if (tp == 0 || s[tp] != tmp[i]) s[++tp] = tmp[i];
    n = tp;
    for (int i = 1; i <= n; i++) ct[s[i] - 'A']++;
    int mn = 0, mx = 0;
    for (int i = 1; i < 3; i++) {
        if (ct[mn] > ct[i]) mn = i;
        if (ct[mx] <= ct[i]) mx = i;
    }
    int diff = ct[mx] - (n - ct[mx] - ct[mn]);
    for (int i = 0, j = 0; i < n; i = j) if (i == 0 || s[i] == 'A' + mn) {
        j = i + 1;
        while (j <= n && s[j] != 'A' + mn) j++;
        if (j == i + 1) continue;
        if (j == i + 2 && j <= n && i) {
            if (s[i + 1] == 'A' + mx) pos2.push_back(i + 1);
        } else {
            if (s[i + 1] == 'A' + mx) pos.push_back(i + 1);
            if (j - 1 != i + 1 && s[j - 1] == 'A' + mx) pos.push_back(j - 1);
        }
    }
    int pos1 = 0, pos3 = 0;
    for (int i = 1; i <= diff; i++) {
        if (pos1 < pos.size()) fucked[pos[pos1]] = 1, pos1++;
        else fucked[pos2[pos3]] = fucked[pos2[pos3] - 1] = 1, pos3++;
    }
    tp = ct[0] = ct[1] = ct[2] = 0;
    for (int i = 1; i <= n; i++) if (!fucked[i]) 
        tmp[++tp] = s[i], ct[s[i] - 'A']++;
    diff = ct[mx] - ct[mn];
    ct[0] = ct[1] = ct[2] = 0;
    for (int i = 1; i <= tp; i++) {
        if (diff && i < tp && tmp[i] != mn + 'A' && tmp[i + 1] != mn + 'A' && tmp[i] != tmp[i + 1] && (i + 2 > tp || tmp[i + 2] != mn + 'A'))
            diff--, i++;
        else putchar(tmp[i]), ct[tmp[i] - 'A']++;
    }
    return 0;
}//

Measured memory_bytes: 7412
import math

num = {}

num = input().split()

# print(num)

answer1 = math.ceil(int(num[0]) / 0.08)
answer2 = math.ceil(int(num[1]) / 0.1)

kensyo1 = math.floor(answer1 * 0.1) == int(num[1])
kensyo2 = math.floor(answer2 * 0.08) == int(num[0])

# print(answer1, answer2)
# print(kensyo1, kensyo2)

if int(num[0]) < 0 or int(num[1]) < 0:
  print(-1)
elif kensyo1:
  print(answer1)
elif kensyo2:
  print(answer2)
else:
  print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int i, len = s.size();
    map <char, char> a, b;
    map<char,char>::iterator ita, itb;
    for(i = 0; i < len; i++)
    {
        ita = a.find(s[i]), itb = b.find(t[i]);

        if(ita == a.end() && itb == b.end())
        {
            a.insert({s[i], t[i]});
            b.insert({t[i], s[i]});
        }
        else if(ita == a.end() || itb == b.end())
        {
            printf("No");
            return 0;
        }
        else if(a[s[i]] != t[i] || b[t[i]] != s[i])
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	long long  x,y;
	cin >> x >> y;
	vector<long long> v;
	v.push_back(y-x);
	v.push_back(y+x+1);
	v.push_back(-y-x+1);
	v.push_back(-y+x+2);
	sort(v.begin(),v.end());
	for(int i=0;i<=3;i++){
		if(v[i]>=0){
			cout << v[i] << endl;
			break;
		}
	}
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int l = in.nextInt();

        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += l + i;
        }
        if (l >= 0) {
            sum -= l;
            System.out.println(sum);
        } else {
            if (l + n - 1 >= 0) {
                System.out.println(sum);
            } else {
                sum -= l + n - 1;
                System.out.println(sum);
            }
        }
    }
}


Measured memory_bytes: 21844
from collections import deque

A = deque(input())
B = deque(input())
C = deque(input())

flag = 'a'

while True:
	if flag == 'a':
		if len(A) == 0:
			break
		flag = A.popleft()
	elif flag == 'b':
		if len(B) == 0:
			break
		flag = B.popleft()
	elif flag == 'c':
		if len(C) == 0:
			break
		flag = C.popleft()
		
print(flag.upper())

Measured memory_bytes: 3444
// 嘘解法
// 4 8
// 0 0 8 8
// とかで嘘の答え出す

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#include <stack>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll N, K; cin >> N >> K;
  ll A[N]; rep(i,N) cin >> A[i];
  ll t_bit[50] = {}; rep(i,N) rep(j,50) t_bit[j] += ((A[i]>>j)&1);
  bool bit[50]; rep(i,50) bit[i] = !(t_bit[i]>(N-1)/2);

  ll X = 0;
  for(int i=50; i>=0; i--) {
    if (bit[i]) {
      ll tmp = X | ((ll)1<<i);
      if (tmp<=K) X = tmp;
    }
  }
  ll result = 0; rep(i,N) result += X^A[i];

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a_vec: [usize; n],
        b_vec: [usize; n],
        c_vec: [usize; n - 1]
    }
    let mut ans = 0;
    for i in 0..a_vec.len() {
        ans += b_vec[a_vec[i] - 1];
        if i >= 1 && a_vec[i] > a_vec[i - 1] {
            if a_vec[i] - a_vec[i - 1] == 1 {
                ans += c_vec[a_vec[i - 1] - 1];
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    if t.size <= 0 then failwith "out of size" else
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let prim a n =
  let reached_p = Array.make n false in
  let d = Array.make n max_int in
  d.(0) <- 0;
  let que = H.make 2000 (0, 0) in
  H.push (0, 0) que;
  while not (H.empty_p que) do
    let (u, _) = H.pop que in
    reached_p.(u) <- true;
    List.iter (fun (v, c) ->
      if not reached_p.(v) && c < d.(v) then begin
        d.(v) <- c;
        H.push (v, c) que;
      end) a.(u);
  done;
  Array.fold_left (fun sum c -> if c = max_int then sum else sum + c) 0 d

let () =
  let n = read_int () in
  let a = Array.make n [] in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      let x = Scanf.scanf " %d" (fun i -> i) in
      if x <> (-1) then a.(i) <- (j, x) :: a.(i);
    done
  done;
  prim a n |> Printf.printf "%d\n"

Measured memory_bytes: 4840
n = int(input()) - 1
A = [chr(i) for i in range(ord("a"),ord("z")+1)]

m = 26
s = 0
g = 1
while s+m <= n:
    s += m
    m *= 26
    g += 1

# print(g)
n -= s

# print("n",n)
ANS = []
for i in range(g):
    ANS.append(A[n%26])
    n//=26
print("".join(ANS[::-1]))

Measured memory_bytes: 61716
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
int d[N], r[N], n, m;
int main(){
	cin>>n>>m;
	r[0] = 1;
	rep(i, n) d[i] = 1;
	rep(i, m){
		int x, y;
		cin>>x>>y; x--; y--;
		r[y] |= r[x];
		d[x]--; d[y]++;
		if(!d[x]) r[x] = 0;
	}
	int res = 0;
	rep(i, n) res += r[i];
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  int st = -1;
  rep(i,(1<<n)){
    int x; cin >> x;
    mp[x]++;
    st = max(st, x);
  }
  mp[st]--;
  if(mp[st]==0){ mp.erase(st); }
  priority_queue<int> q;
  q.push(st);
  while(!mp.empty()){
    priority_queue<int> q2;
    while(!q.empty()){
      auto p = q.top(); q.pop();
      auto pos = mp.lower_bound(p);
      if(pos==mp.begin()){ cout << "No" << ln; return 0; }
      pos--;
      pos->S--;
      q2.push(p);
      q2.push(pos->F);
      if(pos->S==0){ mp.erase(pos); }
    }
    swap(q2,q);
  }
  cout << "Yes" << ln;
  return 0;
}

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

#define int		long long

using namespace std;

void solve()
{
	int n;
	cin>>n;
	if(n>=400 and n<=599)
		cout<<8<<endl;
	else if(n>=600 and n<=799)
		cout<<7<<endl;
	else if(n>=800 and n<=999)
		cout<<6<<endl;
	else if(n>=1000 and n<=1199)
		cout<<5<<endl;
	else if(n>=1200 and n<=1399)
		cout<<4<<endl;
	else if(n>=1400 and n<=1599)
		cout<<3<<endl;
	else if(n>=1600 and n<=1799)
		cout<<2<<endl;
	else
		cout<<1<<endl;
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	//int t;cin >> t;while(t--)
		solve();;
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	string s,t;
	in(s,t);
	t+=s;
	out(t);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>

using namespace std;
//#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

double len(int x1, int y1, int x2, int y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}

int fact(int N)
{
	if (N == 1)return 1;
	return N * fact(N - 1);
}

signed main()
{
	int N;
	cin >> N;
	vector<int>x(N), y(N);
	vector<int>p;
	for (int i = 0; i < N; i++)p.push_back(i);
	vector<int>res(N);
	double ans = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i];
	}
	do
	{
		int j = 0;
		for (int i : p)
		{
			res[j] = i;
			j++;
		}
		for (int k = 0; k < N - 1; k++)
		{
			ans += len(x[res[k]], y[res[k]], x[res[k + 1]], y[res[k + 1]]);
		}
	} while (next_permutation(p.begin(), p.end()));
	printf("%.10f", ans / fact(N));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int kirikae(char input);
int main(){
    while(1){
        int i,len,henkan[100],result=0;
        char input[100];
        if(scanf("%s",input)==EOF)break;
        len=strlen(input);
        for(i=0;i<len;i++){
            henkan[i]=kirikae(input[i]);
        }
        for(i=0;i<len-1;i++){
            if(henkan[i]<henkan[i+1]){
                result-=henkan[i];
            }else{
                result+=henkan[i];
            }
        }
        result+=henkan[len-1];
        printf("%d\n",result);
    }
    return 0;
}
int kirikae(char input){
    int i,re[7]={1,5,10,50,100,500,1000};
    char tai[7]={'I','V','X','L','C','D','M'};
    for(i=0;i<7;i++){
        if(tai[i]==input){
            return re[i];
        }
    }
}

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

int main(){
	string S;
	int Q;
	cin >> S >> Q;
	deque<char> dq;
	for(int i=0;i<S.size();i++) dq.push_back((char)S[i]);
	int rcnt = 0;
	for(int i=0;i<Q;i++) {
		int q;
		cin >> q;
		if(q == 1) {
			rcnt++;
		} else if(q == 2) {
			int f;
			char c;
			cin >> f >> c;
			if(f == 1) {
				if(rcnt % 2 == 0) {
					dq.push_front(c);
				} else {
					dq.push_back(c);
				}
			} else {
				if(rcnt % 2 == 0) {
					dq.push_back(c);
				} else {
					dq.push_front(c);
				}
			}
		}
	}
	while(!dq.empty()) {
		if(rcnt % 2 == 0) {
		cout << dq.front();
		dq.pop_front();
		} else {
			cout << dq.back();
			dq.pop_back();
		}
	}
	cout << endl;
}

Measured memory_bytes: 1024
sx, sy, tx, ty = map(int, input().split())
ans = 'D'
ans += 'R'*(tx-sx+1)
ans += 'U'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'D'*(ty-sy)
ans += 'R'*(tx-sx)
ans += 'U'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'D'*(ty-sy+1)
ans += 'R'
print(ans)

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

typedef long long ll;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll l,r;
    cin>>l>>r;

    if(r-l+1>=2019){
        cout<<0;
    }else{
        ll ans=2020;
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
        cout<<ans;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	V<int> B(N+1); rep1(i,N-1) cin >> B[i];
	B[0] = B[N] = 1e9;
	int ans = 0;
	rep(i,N) ans += min(B[i],B[i+1]);
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    if a[i] %2 == 0:
        b.append(a[i])

d = len(b)
if d == 0:
    print('APPROVED')
    exit()

bool == True
for c in b:
    if (c %3 != 0) and (c %5 != 0):
        bool = False
        break
    else:
        bool = True

if bool == True:
    print('APPROVED' )
else:
    print('DENIED')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C; cin >> A >> B >> C;
    bool f=false;
    for(int i=1;i<=B;i++){
        if((A*i)%B==C) f=true;
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N;
  cin >> N;
  map<int,int> a;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    a[A[i]]++;
  }
  int M;
  cin >> M;
  int flag = 0;
  vector<int> T(M);
  REP(i, M){
    cin >> T[i];
    if(a[T[i]]!=0){
      a[T[i]]--;
    }else if(a[T[i]]==0){
      flag = 1;
    }
  }
  
  if(flag == 1){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr long long inf = 3e18;

template<int MOD>
struct mint{
	int32_t n;
	mint():n(0){}
	mint(int x):n(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD){}

	mint &operator+=(const mint &p){
		if((n+=p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator-=(const mint &p){
		if((n+=MOD-p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator*=(const mint &p){
		n=1ll*n*p.n%MOD;
		return *this;
	}
	mint &operator/=(const mint &p){
		*this*=p.inverse();
		return *this;
	}
	mint operator-()const{return mint(-n);}
	mint operator+(const mint &p)const{return mint(*this)+=p;}
	mint operator-(const mint &p)const{return mint(*this)-=p;}
	mint operator*(const mint &p)const{return mint(*this)*=p;}
	mint operator/(const mint &p)const{return mint(*this)/=p;}
	bool operator==(const mint &p)const{return n==p.n;}
	bool operator!=(const mint &p)const{return n!=p.n;}

	friend ostream &operator<<(ostream &os,const mint &p){
		return os<<p.n;
	}
	friend istream &operator>>(istream &is,mint &p){
		int x;is>>x;
		p=mint(x);
		return is;
	}
	mint pow(int64_t x)const{
		mint res(1),mul(n);
		while(x>0){
			if(x&1)res*=mul;
			mul*=mul;
			x>>=1;
		}
		return res;
	}
	mint inverse()const{
		return pow(MOD-2);
	}
};
using modint=mint<mod>;

template<class T>
class BIT{
	int N;
	vector<T>bit;
	void add_(int x,T y){
		while(x<=N){
			bit[x]+=y;x+=x&-x;
		}
	}
	T sum_(int x){
		T res=0;
		while(x>0){
			res+=bit[x];x-=x&-x;
		}
		return res;
	}
public:
	int lower_bound(T w){
		if(w<=0)return -1;
		int x=0;
		int k=1;while(k*2<=N)k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&bit[x+k]<w){
				w-=bit[x+k];
				x+=k;
			}
		}
		return x;
	}
	void add(int x,T y){add_(x+1,y);}
	T sum(int l,int r){return sum_(r)-sum_(l);}
	BIT(int x):N(x),bit(x+1){}
};

int N,K,A[200005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>K;
	rep(i,N){cin>>A[i];A[i]--;}

	BIT<modint>bit(N),bit2(N);
	modint ans;
	rep(i,N){
		int j=max(0ll,i+1-K);
		modint k=(modint(K-1)/modint(K)).pow(j);
		ans+=bit.sum(A[i],N)*k/modint(2);
		ans+=bit2.sum(A[i],N)-bit.sum(A[i],N)*k;
		ans+=bit.sum(0,A[i])*k/modint(2);
		bit.add(A[i],modint(1)/k);
		bit2.add(A[i],1);
	}
	cout<<ans<<"\n";
}


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

using namespace std;
#define ll long long

const int INF = 1e9 + 5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n>>k;
    int ar[n];
    for (int i = 0; i < n; i++) {
        cin >> ar[i];
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= i + k; j++) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(ar[i] - ar[j]));
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      int num = scanner.nextInt();
      int point = scanner.nextInt();
      int ques = scanner.nextInt();
      int[] res = new int[num];
      Arrays.fill(res, point - ques);
      for (int i = 0; i < ques; i++) {
      	res[scanner.nextInt() - 1]++;
      }
      
      for (int i = 0; i < num; i++) {
        if (res[i] > 0) System.out.println("Yes");
        else System.out.println("No");
      }
      
    }
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, N; cin >> D >> N;
    int num[] = {1, 100, 10000};
    if(N < 100) cout << N*num[D] << endl;
    else{
        if(D == 0) cout << 101 << endl;
        else if(D == 1) cout << 10100 << endl;
        else cout << 1010000 << endl;
    }
    return 0;
}

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

#define int long long int
#define vi vector<int>
#define pii pair<int,int>
#define pq priority_queue<int>
#define pb push_back
#define INF 1000000000000000000
#define modu 1000000007
#define out(a) cout<<a
#define out2(a,b) cout<<a<<" "<<b
#define out3(a,b,c) cout<<a<<" "<<b<<" "<<c
#define in(a) cin>>a
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define spc <<" "
#define nl <<"\n"
#define khubTesh(ti) cout<<"Case "<<ti<<": "

void testCase(int ti,int ans){
    khubTesh(ti);
    out(ans) nl;
}

void debug(string pr,vector<int> var)
{
    cout<<pr;
    for(int i=0;i<var.size();i++) cout<<" "<<var[i];
    cout<<endl;
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}
const int MaxSize=100010;
int n;
int ara[MaxSize];
int ans[MaxSize];

int dp(int at){
    if(at==n) return 0;
    if(ans[at]!=-1) return ans[at];
    int a1=INF,a2=INF;
    if(at+2<=n) a2=dp(at+2)+abs(ara[at+2]-ara[at]);
    if(at+1<=n) a1=dp(at+1)+abs(ara[at+1]-ara[at]);
    return ans[at]=min(a1,a2);
}

int32_t main(){
    faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
    //Now I will start writing codes and start preparation to get errors
    cin>>n;
    for(int i=1;i<=n;i++) cin>>ara[i],ans[i]=-1;
    cout<<dp(1);
    return 0;
}


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


int main()
{
	int d, g, p[11], c[11]; cin >> d >> g;
	for (int i = 0; i < d; ++i)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int i = 0; i < 1 << d; ++i)
	{
		int sum = 0, num = 0, rest = -1;
		for (int j = 0; j < d; ++j)
		{
			if (i & 1 << j)
			{
				sum += (j+1)*100*p[j]+c[j];
				num += p[j];
			}
			else
			{
				rest = j;
			}
		}
		if (sum < g)
		{
			int x = (rest+1)*100;
			int need = (g-sum+x-1)/x;
			if (need > p[rest])
				continue;
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3592
N, M = map(int, input().split())
p = [list(map(int, input().split())) for i in range(M)]
import itertools
v = list(map(list, itertools.permutations(range(2,N+1), N-1)))
cnt = 0
for i in range(len(v)):
    vit = True
    v_i = [1]+v[i]
    for j in range(N-1):
        if sorted(v_i[j:j+2]) not in p:
            vit = False
    if vit:
        cnt += 1
print(cnt)

Measured memory_bytes: 3828
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  double ans = 0.0;
  rep(i, n - 1) {
    double exp = (double)(1LL << (i + 1));
    ans += v[i] / exp;
  }
  ans += v[n - 1] / (double)(1LL << (n - 1));
  printf("%.10f", ans);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 200'000

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int res = 0;
  int _t;
  cin >> _t;
  for (int i = 1; i < N; ++i) {
    int t;
    cin >> t;
    res += min(T, t - _t);
    _t = t;
  }
  printf("%d\n", res + T);
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int K,X;
	vector<int> v;
	cin>>K>>X;
	for(int i=X+1;i<X+K;i++){
		v.push_back(i);
	}
	for(int i=X;i>X-K;i--){
		v.push_back(i);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	return 0;
}

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

int main(){
    int A=read(),B=read();
    printf("%d",(A<=9&&B<=9)?A*B:-1);
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  cin >> x;
  if(x == 22) cout << "Christmas Eve Eve Eve" << endl;
  else if(x == 23) cout << "Christmas Eve Eve" << endl;
  else if(x == 24) cout << "Christmas Eve" << endl;
  else cout << "Christmas" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s,p;

int main()
{
    ft
    ll t,i,j,n,m,a,b,l,r;
    cin>>a>>b;
    for(i=0;i<2001;i++)
    {
        l=i*.08;
        r=i*.1;
        if(l==a && r==b)
        {
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<"-1\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int n;
vector<int> G[N];
ll dp[N][2];
// white 0 , black 1
void dfs(int u,int p)
{
    dp[u][0] = dp[u][1] = 1;
    for(auto v:G[u])
    {
        if (v==p) continue;
        dfs(v,u);
        dp[u][0] = (dp[u][0]*((dp[v][0]+dp[v][1])%MOD))%MOD;
        dp[u][1] = (dp[u][1]*dp[v][0])%MOD;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> n;
    REP(i,0,n-2)
    {
        int x,y;
        cin >> x >> y;
        G[x].PB(y);
        G[y].PB(x);
    }
    dfs(1,-1);
    cout << (dp[1][0] + dp[1][1])%MOD << endl;
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
const int INF =1e9;

string S,T;
vector<vector<int>> alpha(30);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>S>>T;
    int N = S.size();
    int M = T.size();
    rep(i,N){
        alpha[S[i]-'a'].push_back(i);
    }
    rep(i,N)alpha[S[i]-'a'].push_back(INF);
    ll ans = 0;
    int preidx = -1;
    rep(i,M){
        vector<int> &v = alpha[T[i]-'a'];
        if((int)v.size() == 0){
            ans = -1;
            break;
        }
        auto x = upper_bound(all(v),preidx) - alpha[T[i]-'a'].begin();
        if(v[x] == INF){
            ans += N-preidx-1;
            ans += v[0] + 1;
            preidx = v[0];
            continue;
        }
        ans += v[x] - preidx;
        preidx = v[x];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h, n; cin >> h >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  rep(i, n) {
    h -= a[i];
    if (h <= 0) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

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

int A[3];
int main()
{	
	for(int i=0;i<3;i++)
		cin>>A[i];
		
	int c=A[1]*10+A[2];
	if(c%4==0)
		cout<<"YES\n";
	else
		cout<<"NO\n";
		
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int main() {
	int n;
	scanf("%d", &n);

	if (n == 1) return !printf("Hello World");
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d", a + b);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  vector<bool> ok(1000, false);
  for (ll i = 1; i <= 9; i++)
  {
    for (ll j = 1; j <= 9; j++)
    {
      ok.at(i * j) = true;
    }
  }
  cout << ((ok.at(N)) ? "Yes" : "No") << endl;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  ll i;
  for(i=0;i<=4;i++)
    if(x[i] == 0) cout << i + 1 << endl;
}



Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  cout << 800*n - 200*(n/15) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

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

  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 1; n <= 3500; n++) {
      ll numer = N * h * n;
      ll denom = 4 * h * n - N * (n + h);
      if (denom == 0)
        continue;
      ll w = numer / denom;

      if (w < 0)
        continue;

      if (w * denom == numer) {
        cout << h << ' ' << n << ' ' << w << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256