akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize x:i64)(list:[i64]));
    let mut list = list;
    let mut count = 0;
    for i in 0..n {
        if list[i] > x {
            count += list[i] - x;
            list[i] = x;
        }
        if i != 0 {
            if list[i - 1] + list[i] > x {
                count += list[i - 1] + list[i] - x;
                list[i] = x - list[i - 1];
            }
        }
    }
    count.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3 3\n2 2 2" => "1",
    test2: "6 1\n1 6 1 2 0 4" => "11",
    test3: "5 9\n3 1 4 1 5" => "0",
    test4: "2 0\n5 5" => "10",
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    V X(N);  VECCIN(X);

    ll ans = INF;
    //i : 集会を開く座標
    for(int i = 0 ; i <= 100 ; i++){
      ll keep = 0;
      for(int n : X)
        keep += (n - i) * (n - i);

      ans = min(ans, keep);
    }

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

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    Scanner sin=new Scanner(System.in);
	    String s1=sin.next();
	    String s2=sin.next();
	    int a1=sin.nextInt();
	    int a2=sin.nextInt();
	    String s3=sin.next();
	    if(s1.equals(s3)){
            System.out.println((a1-1)+" "+a2);
        }
	    else System.out.println(a1+" "+(a2-1));
    }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=255;
int n,mod,ans;
int dp[maxn*2][maxn];
pii a[maxn*2];
void Add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}

int main(){
	scanf("%d%d",&n,&mod);
	rep(i,n)a[i]=mp(sqrt(n*n-1-i*i),-i);
	for(int i=n;i<2*n;i++)a[i]=mp(min(2*n-1,int(sqrt(4*n*n-i*i))),-i);
	sort(a,a+2*n);
	rep(i,2*n)a[i].snd=-a[i].snd;
	rep(k,n+1){
		int cnt=0;
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		rep(i,2*n){
			rep(j,n+1){
				int cur=dp[i][j];
				if(!cur)continue;
				if(a[i].snd>=n&&a[i].snd<2*n)Add(dp[i+1][j],1LL*cur*max(a[i].fst+1-cnt-j,0)%mod);
				else{
					int nval=min(int(sqrt(4*n*n-a[i].snd*a[i].snd)),2*n-1);
					Add(dp[i+1][j],1LL*cur*max(nval+1-k-n-(i-cnt-j),0)%mod);
					Add(dp[i+1][j+1],1LL*cur*max(a[i].fst+1-cnt-j,0)%mod);
				}
			}
			if(a[i].snd>=n&&a[i].snd<2*n)cnt++;
		}
		if(k&1)Add(ans,mod-dp[2*n][k]);
		else Add(ans,dp[2*n][k]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
#define SZ(a) int((a).size())

template <class T>
void chmax(T &a, T b) {
  if (a < b) a = std::move(b);
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = std::move(b);
}

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename Container>
ostream &pprint(const Container &a, string_view sep = " ",
                string_view ends = "\n", ostream *os = nullptr) {
  if (os == nullptr) os = &cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  return pprint(a, ", ", "", &(os << "[")) << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

struct UnionFind {
  vector<int> data;  // positive: parent, negative: size

  UnionFind() = default;

  explicit UnionFind(size_t sz) : data(sz, -1) {}

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  int find(int k) {
    if (data[k] < 0) return k;
    return data[k] = find(data[k]);
  }

  int size(int k) { return -data[find(k)]; }

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

  vector<int> roots() {
    vector<int> res;
    res.reserve(data.size());
    for (int i = 0; i < (int)data.size(); ++i) {
      if (data[i] < 0) res.push_back(i);
    }
    return res;
  }
};

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

  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  V<int> roots = uf.roots();
  int ans = 0;
  for (int r : roots) {
    chmax(ans, uf.size(r));
  }
  cout << ans << endl;
}


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

const int N = 21;
const int MOD = 1e9 + 7;

int n, a[N][N], dp[N][1 << N];

int f(int i, int mask) {
	if (i == n)
		return 1;
	
	int& ret = dp[i][mask];
	if (ret != -1)
		return ret;
	
	ret = 0;
	for (int j = 0; j < n; j++)
		if (a[i][j] and !(mask & (1 << j)))
			ret = (ret + f(i + 1, mask | (1 << j))) % MOD;
	
	return ret;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	
	memset(dp, -1, sizeof dp);
	cout << f(0, 0) << '\n';
	return 0;
}

Measured memory_bytes: 172288
package main

import "fmt"

func main() {
	var H, W int
	var odd, even int
	fmt.Scan(&H, &W)
	if H == 1 || W == 1 {
		fmt.Println(1)
		return
	}
	if W%2 != 0 {
		even = W/2 + 1
		odd = W / 2
	} else {
		even = W / 2
		odd = W / 2
	}
	if H%2 != 0 {
		fmt.Println((H/2+1)*even + H/2*odd)
	} else {
		fmt.Println(H/2*even + H/2*odd)
	}

}


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

int main() {
	string i, o;
	int ans = 0;
	cin >> i >> o;

	for (int n = 0; n < 3; n++) {
		if (i.at(n) == o.at(n)) {
			ans += 1;
		}
	}
	cout <<ans;
}


Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 int main(){
 string S;
 cin >> S;
 int L = S.size();
 string ans = "AC";
 if(S[0] != 'A'){
ans = "WA";
 }
 int cnt = 0;
 for(int i = 1; i < L; ++i){
 if(isupper(S[i])){
 if(i == 1 || i == L - 1 || S[i] != 'C'){
 ans = "WA";
 }
 ++cnt;
 }
 }
 if(cnt != 1){
 ans = "WA";
 }
 cout << ans << endl;
}



Measured memory_bytes: 256
#include <cstdio>
using namespace std;

const int maxn=4e5+5;
int n, m;
char s[maxn];
struct Edge{
    int to, nxt;
}e[maxn*2];
int cnte, fir[maxn], in[maxn];
void addedge(int x, int y){
    Edge &ed=e[++cnte]; in[y]++;
    ed.to=y; ed.nxt=fir[x]; fir[x]=cnte; }
int q[maxn], hd, tl;

int main(){
    scanf("%d%d%s", &n, &m, s+1); int x, y;
    for (int i=1; i<=m; ++i){
        scanf("%d%d", &x, &y);
        if (s[x]==s[y]){  //边为0
            addedge(x*2+1, y*2);
            addedge(y*2+1, x*2); }
        else{
            addedge(x*2, y*2+1);
            addedge(y*2, x*2+1); }
    }
    for (int i=2; i<=n*2+1; ++i)
        if (!in[i]) q[tl++]=i;
    int u, v;
    while (hd<tl){
        u=q[hd++];
        for (int i=fir[u]; i; i=e[i].nxt){
            --in[v=e[i].to]; if (!in[v]) q[tl++]=v; }
    }
    for (int i=2; i<=n*2+1; ++i)
        if (in[i]){ puts("Yes"); return 0; }
    puts("No");
    return 0;
}


Measured memory_bytes: 8448
package main

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

var sc *bufio.Scanner

var (
	BufferSize = 10 * 10 * 10 * 10 * 10 * 10
)

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

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	in := nextString()
	a := make([]int, len(in))
	last := "1"
	ind := 0
	for i := 0; i < len(in); i++ {
		c := string(in[i])
		if last != c {
			ind++
			last = c
		}
		a[ind]++
	}
	sum := 0
	max := 0
	for i := 0; i < n; i++ {
		sum += a[i]
		if i > k*2 {
			sum -= a[i-k*2-1]
		}
		if i%2 == 0 && max < sum {
			max = sum
		}
	}
	_, _ = fmt.Fprintf(writer, "%d\n", max)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 2048
#!/usr/bin/env python3
from queue import Queue

INF = 10 ** 9
dx = [1, 0]
dy = [0, 1]

h, w = map(int, input().split())
s = [input() for _ in range(h)]
dist = [[INF] * w for _ in range(h)]
dist[0][0] = 0

q = Queue()
sx, sy = 0, 0
q.put([0, 0])
while not q.empty():
    ux, uy = q.get()
    for k in range(2):
        vx = ux + dx[k]
        vy = uy + dy[k]
        if not (0 <= vx < h and 0 <= vy < w):
            continue
        cost = s[ux][uy] == "#" and s[vx][vy] == "."
        if dist[vx][vy] > dist[ux][uy] + cost:
            dist[vx][vy] = dist[ux][uy] + cost
            q.put([vx, vy])

print(dist[-1][-1] + (s[-1][-1] == "#"))


Measured memory_bytes: 4072
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>

using namespace std;

using Z = int;
constexpr Z INF = numeric_limits<Z>::max();

#ifdef DEBUG
# define dump(x) cerr << "dump@" << __LINE__ << " : " << #x << " = " << (x) << endl
# define mesg(m) cerr << "mesg@" << __LINE__ << " : " << m << endl
# define debug if (true)
#else
# define NDEBUG
# define dump(x)
# define mesg(m)
# define debug if (false)
#endif
#define rep(i, n) for (auto i = 0; i < n; i++)
#define rrep(i, n) for (auto i = n; i >= 0; i--)
#define all(c) begin(c), end(c)

int count_water(vector<Z> const& hs, Z l, Z r, Z done) {
  if (r == l) return 0;
  if (r - l == 1) return hs[l] - done;
  Z minpos = min_element(cbegin(hs) + l, cbegin(hs) + r) - cbegin(hs);
  dump(minpos);
  Z lc = count_water(hs, l, minpos, hs[minpos]),
    rc = count_water(hs, minpos + 1, r, hs[minpos]);
  return lc + rc + hs[minpos] - done;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Z n;
  cin >> n;
  vector<Z> hs(n);
  for (auto& h : hs) cin >> h;
  cout << count_water(hs, 0, n, 0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define labs(a) ((a>0)?a:-a)

int main(void){
    double a,b;
    double v,w;
    double t;
    scanf("%lf %lf",&a,&v);
    scanf("%lf %lf",&b,&w);
    scanf("%lf",&t);

    if(v == w || w>v){
        printf("NO");
        return 0;
    }

    
    (((labs((a-b)))/(labs((v-w)))) <= t)?printf("YES"):printf("NO");
    return 0;
}

Measured memory_bytes: 1752
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    //Initialize ans with a temporal value.
    //This value should be large enough; otherwise you will get wrong answer
    //Make sure that the value will lead to the correct answer.
    int ans = T.size();
 
    //Brute force through all initial position in S
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    int mod[n];
    fill(mod, mod + n, 0);

    for(int i = 0; i < n; i++){
        while (a[i] % 2 == 0){
            a[i] /= 2;
            mod[i]++;
        }
    }
    int ans = 100;
    for (int i = 0; i < n; i++){
        if (ans > mod[i]) ans = mod[i];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 504
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

LL N,P;
string S;
 
LL ans = 0;
 
void solve(){
	if(10%P==0){//Pが2,5,10のいずれか
		for(int i=0;i<N;i++){
			if((S[i]-0x30)%P==0){
				ans += i+1;
			}
		}
		return;
	}

	vector<LL> pow10(N,1);//10のi乗の、modPにおける数値をpow10[i]とおく
	for(int i=1;i<N;i++) pow10[i] = (pow10[i-1]*(10%P))%P;

	//S_rem[i] = ((S[i]%P)*pow10[i])%P
	vector<LL> S_rem(N);
	for(int i=0;i<N;i++) S_rem[i] = (((S[N-1-i]-0x30)%P)*pow10[i])%P;

	//S_remの累積和
	//S_rem[0]~S_rem[j-1]全部を足したものをcul_sum[j]とする
	//ただしcul_sum[0] = 0
	vector<LL> cul_sum(N+1,0);
	for(int i=1;i<=N;i++) cul_sum[i] = (cul_sum[i-1]+S_rem[i-1])%P;

	//cul_sumのうち、Pで割ったあまりがiである数値の数をnumof_rem[i]とする
	vector<LL> numof_rem(P,0);
	for(int i=0;i<=N;i++) numof_rem[cul_sum[i]]++;

	for(int i=0;i<P;i++){
		LL psize = numof_rem[i];
		ans += (psize)*(psize-1)/2;
	}
}
 
int main(){
	cin >> N >> P;
	cin >> S;
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5252
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main()
{
    char s[100000],s1;
    int i,n,a1=0,a2=0,t;
    cin>>s;
    n=strlen(s);
    for(i=0;i<n;i++)
    {
        if(i%2==0)
        {
            s1='0';
            if(s[i]==s1)
                a2++;
            else
                a1++;
        }
        else
        {
            s1='1';
            if(s[i]==s1)
                a2++;
            else
                a1++;
        }
    }
    if(a1>=a2) t=a2;
    else t=a1;
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n,m;
    cin >> n >> m;
    int nn = 0, mm = 1e9;
    rep(i,m){
        int a,b; cin >> a >> b;
        nn = max(nn, a); mm = min(mm, b);
    }
    if(mm-nn < 0) cout << 0 << endl;
    else cout << mm-nn+1 << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

if __name__ == '__main__':
    N, Q = map(int, input().split())
    count = [0] * (N + 1)
    tree = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(Q):
        idx, val = map(int, input().split())
        count[idx] += val

    q = deque()
    q.append(1)

    is_valid = [1] * (N + 1)
    while q:
        idx = q.pop()
        is_valid[idx] = 0
        for t in tree[idx]:
            if is_valid[t] == 0: continue
            count[t] += count[idx]
            q.append(t)
    print(*count[1:])

Measured memory_bytes: 105804
a,b,h,m = map(int,input().split())

a_y = ((h/12)*360+m/(60*12)*360)%360
b_y = ((m/60)*360)%360

from math import *

alpha = ((a_y - b_y)%360)*pi/180

ans = sqrt(a**2+b**2-2*a*b*cos(alpha))

print(ans)

Measured memory_bytes: 62588
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
 
typedef long long int ll;
typedef pair<int, int> P;
 
const long long INF = 3e18 + 12;
const int inf = 1e9;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  int n, m;
  cin >> n;
 
  map<string, int> nn;
  vector<string> v(n);
 
  rep(i, n) {
    string a;
    cin >> a;
    v[i] = a;
    nn[a]++;
  }
 
  cin >> m;
  map<string, int> mm;
 
  rep(i, m) {
    string a;
    cin >> a;
    mm[a]++;
  }
  int res = 0;
  rep(i, n) {
    res = max(nn[v[i]] - mm[v[i]], res);
  }
  cout << res << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  int count=0;
  
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  for(int i=0; i<N; i++){
    cin>>B.at(i);
  }
  for(int i=0; i<N-1; i++){
    cin>>C.at(i);
  }
  
  for(int i=0; i<N; i++){
    count += B.at(A.at(i)-1);
    //cout << count << endl;
  }
  
  for(int i=0; i<N-1; i++){
    if(A.at(i) == A.at(i+1)-1){
      count += C.at(A.at(i)-1);
      //cout << count << endl;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
const int N=100005;
using namespace std;
bool flag[100005];
int n,res;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		flag[i]=flag[i/10]^1;
		if(flag[i]){
			res++;
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int K=s.nextInt();
    int A=s.nextInt();
    int B=s.nextInt();

    System.out.println(K*(A/K)+K<=B||A%K==0?"OK":"NG");
  }  
}

Measured memory_bytes: 35768
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();

		out.println("ABC" + numN);
	}

	private void solveB() {
		int numN = nextInt();

		int res = 0;
		int index = 0;
		for (int i = numN; i > 0; i--) {
			int wk = chkB(i);
			if (res <= wk) {
				res = wk;
				index = i;
			}
		}

		out.println(index);
	}

	private int chkB(int numN) {
		int cnt = 0;
		while (numN > 0) {
			if (numN % 2 == 0) {
				numN /= 2;
				cnt++;
			} else {
				break;
			}
		}
		return cnt;
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 23380
#include<stdio.h>
#include<string.h>
int main(){
	char a[1001],b[1001],c[1001];
	int n,tl,ml,cnt=0,tf=0;
	int i,j,k,l,m;
	scanf("%d",&n);
	scanf("%s",a);
	tl=strlen(a);
	for(i=0;i<n;i++){
		scanf("%s",b);
		ml=strlen(b);
		
		while(1){
			if(strstr(b,a)!=NULL)cnt++;
			else{
				for(j=0;j<=ml;j++){
					for(k=1;k<=(ml-tl)/2;k++){
						for(l=j,m=0;l<=ml;l+=k,c[m]='\0'){
							c[m++]=b[l];
						}
						if(strstr(c,a)!=NULL)tf=1;
					}
				}
			}
			if(tf!=0)tf=0,cnt++;
			break;
		}
		
	}
	printf("%d\n",cnt);
	return 0;
}



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

using namespace std;

vector<int> l;

int n,k;
vector< vector<int> > memo(100,vector<int>(100,0));
vector< vector<bool> > done(100,vector<bool>(100,false));

int dfs(int i,int selects)
{
    int res;
    if(done[i][selects])
    {
        res = memo[i][selects];
    }
    else if(selects >= k)
    {
        res = 0;
    }
    else if(i >= n)
    {
        res = 0;
    }
    else
    {
        res = max(dfs(i+1,selects),dfs(i+1,selects+1)+l[i]);
        memo[i][selects] = res;
        done[i][selects] = true;
    }

    return res;
}

int main()
{
    cin >> n >> k;
    l.resize(n);
    for(int i=0;i < n;i ++)
    {
        cin >> l[i];
    }

    int ans = dfs(0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>

std::vector<size_t> gaps = {1};

template <typename T>
long long insertion_sort(T a[], size_t n, size_t gap = 1){
  long long count = 0;
  for(size_t i = gap; i < n; i++){
    T v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void make_gap_table(size_t n){
  size_t h = 4;
  while(h < n){
    gaps.push_back(h);
    h = 3*h + 1;
  }
  std::reverse(gaps.begin(),gaps.end());
}

template <typename T>
void shell_sort(T a[], size_t n){
  make_gap_table(n);
  long long count = 0;
  for(auto const &v : gaps){
    count += insertion_sort(a,n,v);
  }

  std::cout << gaps.size() << '\n';

  for(int i=0;i<gaps.size()-1;i++){
    std::cout << gaps[i] << ' ';
  }
  std::cout << gaps[gaps.size()-1] << '\n';

  std::cout << count << '\n';
}

int main(){
  size_t n;
  size_t buf;
  std::vector<size_t> a;
  std::cin >> n;
  for(size_t i = 0; i < n; i++){
    std::cin >> buf;
    a.push_back(buf);
  }

  shell_sort(a.data(),a.size());
  for(auto &v : a){
    std::cout << v << '\n';
  }
}

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

using namespace std;

int nCk(int n, int k){
    if(k == 0){
        return 1;
    }else if(k == 1){
        return n;
    }else if(k == 2){
        return n*(n-1)/2;
    }else if(k == 3){
        return n*(n-1)*(n-2)/6;
    }else{
        return 0;
    }
}

int p9(int k){
    if(k == 0){
        return 1;
    }else if(k == 1){
        return 9;
    }else if(k == 2){
        return 81;
    }else if(k == 3){
        return 729;
    }else{
        return 0;
    }
}

int main() {
    string N;
    int K;
    cin >> N >> K;
    int ans = 0;
    int n = N.length();
    int j = n;
    for(int i = K; i >= 0; i--) {
        if(j < i)
            break;
        ans += nCk(j - 1, i) * p9(i);
        int l = N[n - j] - '0' - 1;
        ans += l * nCk(j - 1, i - 1) * p9(i - 1);
        j--;
        if(j<0)
            break;
        while(N[n - j] == '0' && j > 0) {
            j--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;

class CycleFinder {
public:
	map<int, int> state;
	map<int, vector<int>> nxt;
	vector<int> cycle;
	set<int> vertices;
	vector<int> stk;
	void dfs(int u) {
		state[u] = 1;
		stk.pb(u);
		for(int v : nxt[u]) {
			if(cycle.size() == 0 && state[v] == 1) {
				bool write = false;
				for(int j = 0; j < stk.size(); j++) {
					if(stk[j] == v) {
						write = true;
					}
					if(write) cycle.pb(stk[j]);
				}
			} else if(!state[v]) {
				dfs(v);
			}
		}
		stk.pop_back();
		state[u] = 2;
	}
	vector<int> find() {
		vector<int> ord;
		for(int i : vertices) ord.pb(i);
		random_shuffle(ord.begin(), ord.end());
		for(int i : ord)  if(!state[i]) {
			dfs(i);
		}
		return cycle;
	}
};

int main() {
	scanf("%d%d", &n, &m);
	CycleFinder initial;
	vector<pair<int,int>> edges;
	REP(i, n) {
		initial.state[i] = 0;
		initial.vertices.insert(i);
		initial.nxt[i] = vector<int>{};
	}
	REP(i, m) {
		int a,b;
		scanf("%d%d", &a, &b);
		a--;b--;
		edges.pb({a,b});
		initial.nxt[a].pb(b);
	}

	vector<int> initCycle = initial.find();
	if(initCycle.size() == 0) {
		printf("-1\n");
		return 0;
	}

	vector<int> currCycle = initCycle;
	vector<int> nxtCycle;
	for(int t = 0; t < 1000; t++) {
		CycleFinder cf;
		set<int> has;
		for(int i : currCycle) {
			has.insert(i);
			cf.state[i] = 0;
			cf.vertices.insert(i);
			cf.nxt[i] = vector<int>{};
		}
		for(auto e : edges) {
			if(has.count(e.first) && has.count(e.second)) {
				cf.nxt[e.first].pb(e.second);
			}
		}
		for(int i : currCycle) {
			random_shuffle(cf.nxt[i].begin(), cf.nxt[i].end());
		}
		currCycle = cf.find();
	}
	printf("%d\n", currCycle.size());
	for(int x : currCycle) printf("%d\n", x+1);
	return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<string> s = {
		"NO",
		"NO",
		"NO",
		"YES",
		"NO",
		"YES",
		"NO",
		"YES",
		"NO",
		"NO",
	};

	cout << s[n] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	int pm, pe, pj;
	double avr;
	
	while (scanf("%d", &n), n){
		for (int i=0; i<n; i++){
			scanf("%d %d %d", &pm, &pe, &pj);
			avr = (pm+pe+pj)/3.;
			if (pm==100 || pe==100 || pj==100){
				puts("A");
			} else if (pm+pe >= 180){
				puts("A");
			} else if (avr>=80){
				puts("A");
			} else if (avr >= 70){
				puts("B");
			} else if (avr >= 50 && (pm>=80 || pe >= 80)){
				puts("B");
			} else {
				puts("C");
			}
		}
	}
	return 0;
}
	
	

Measured memory_bytes: 1012
# mathモジュールをインポート
import math

# 円の面積を求める関数
def circle(r):
  return r*r*math.pi

r = input().rstrip()
r = int(r)

# 円の面積
r_circle = circle(r)

# 半径1の円の面積
one_r_circle = circle(1)

ans = round(r_circle / one_r_circle)
print(ans)


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

int main(void){
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> C(h);
    rep(i,h) cin>>C[i];
    long long ans=0;
    //塗り替えないマスでbit全探索
    for(int bith=0;bith<(1<<h);++bith){
        for(int bitw=0;bitw<(1<<w);++bitw){
            int count=0;
            rep(i,h) rep(j,w){
                if(C[i][j]=='#'){
                    if((bith&(1<<i)) && (bitw&(1<<j))){
                        count++;
                    }
                }
            }
            //cout<<bith<<" "<<bitw<<":"<<count<<endl;
            if(count==k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

#define int llong

    signed call_of_Cthulhu( signed datum ) {

        int a[3];
        int k;
        for ( int i = 0; i < 3; i++ ) read a[i];
        read k;
        bozo_sort(a, a+3);
        for ( int i = 0; i < k; i++ ) {
            a[2] *= 2;
        }
        echo std::accumulate(a, a+3, 0ll) fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef double db;
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p) memset(p,0,sizeof(p))
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main()
{
    ios::sync_with_stdio(false);
    int n,x,ans=0;
    cin>>n;
    rep(i,1,n){
    	cin>>x;
    	if(x!=i) ans++;
	}
	if(ans<=2){
		cout<<"YES";
	}
	else cout<<"NO";
	return 0;
}



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

using namespace std;

int main(){
	
	int n,m,x;
	
	cin >> n >> m >> x;
	
	int a[m];
	
	for(int i = 0;i<m;i++)
		cin >> a[i];
	
	int f=0,r=0;
	
	for(int i=1;i<n;i++){
		for(int j = 0;j<m;j++){
			if(a[j] == i && i<x)
				f++;
			else if(a[j] == i && i>x)
				r++;
		}
	}
	
	cout << min(r,f);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  scanf("%d%d",&n,&m);
  vector<int>dp((1<<n),1e9);
  dp[0]=0;
  rep(i,m){
    int a,b;
    scanf("%d%d",&a,&b);
    int s=0;
    rep(j,b){
      int p;
      scanf("%d",&p);
      s+=1<<(p-1);
    }
    rep(j,1<<n){
      dp[j|s]=min(dp[j|s],dp[j]+a);
    }
  }
  if(dp[(1<<n)-1]==1e9)puts("-1");
  else printf("%d\n",dp[(1<<n)-1]);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,d; cin >> a >> b >> c >> d;
    int ans = 0;
    
    if(c<=b && a<=d) ans = min(b,d) - max(a,c);
    
    cout << ans << endl;
    
    
    
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1)
        invfact=[1]*(n+1)
        for i in range(1,n+1):
            fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1):
            invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact
        self.__invfact=invfact

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n-k<0): return 0
        return (self.fact(n)*self.invfact(k)*self.invfact(n-k))%MOD

def resolve():
    h,w,a,b=map(lambda x:int(x)-1,input().split())
    mf=modfact(h+w)
    ans=mf.comb(h+w,h)
    for j in range(b+1):
        i=(h-a)+b-j
        ans-=mf.comb(i+j,i)*mf.comb(h-i+w-j,h-i)%MOD
    print(ans%MOD)
resolve()

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

int ordena(const void *x, const void *y){
    const int *a = x;
    const int *b = y;

    if ((*a) > (*b))
        return -1;

    if ((*a) < (*b))
        return 1;

    return 0;
}


int main(){
    scanf("%*d");
    int *a = malloc(1 * sizeof(int));
    int n = 0;
    while (scanf("%d", &a[n]) != EOF){
        ++n;
        a = realloc(a, (n+1) * sizeof(int));
    }

    qsort(a,n,sizeof(a[0]),ordena);

    printf("%d\n", a[(n/2)-1] - a[n/2]);


    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();

    vector<int> pos = {};
    for (int i = 1; i < N; i++) {
        if (S[i] != S[i - 1]) pos.push_back(i);
    }
    pos.push_back(N);
    // for (int i = 0; i < pos.size(); i++) cout << pos[i] << endl;
    vector<int> ans(N);
    for (int i = 0; i < pos.size(); i++) ans[i] = 0;
  
    for (int i = 1; i < pos.size(); i += 2) {
        int RL = 0;
        if (i == 1) RL = pos[i];
        else RL = pos[i] - pos[i - 2];
        if (RL % 2 == 0) {
            ans[pos[i - 1] - 1] = RL / 2;
            ans[pos[i - 1]] = RL / 2;
        }
        else {
            int L = pos[i] - pos[i - 1];
            int R = RL - L;
            if (R > L) {
                if ((R - 1) % 2 == 0) {
                    ans[pos[i - 1] - 1] = RL / 2 + 1;
                    ans[pos[i - 1]] = RL / 2;
                }
                else {
                    ans[pos[i - 1] - 1] = RL / 2;
                    ans[pos[i - 1]] = RL / 2 + 1;
                }
            }
            else {
                if ((L - 1) % 2 == 0) {
                    ans[pos[i - 1] - 1] = RL / 2;
                    ans[pos[i - 1]] = RL / 2 + 1;
                }
                else {
                    ans[pos[i - 1] - 1] = RL / 2 + 1;
                    ans[pos[i - 1]] = RL / 2;
                }
            }
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        if (i != ans.size() - 1) cout << ans[i] << " ";
        else cout << ans[i] << endl;
    }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> p(N);
	int count = 0;
	for (int i=0; i < N; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < N; i++) {
		if (p[i] != (i+1)) {
			count += 1;
		}
	}

	if ((count == 2)||(count==0)) {
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <queue>  
#include <vector>  
#include <cstdio>  
#include <cstring>  
#include <iostream>  
#include <algorithm>  
#define  pb push_back  
#define  mp make_pair  
#define  sz(x) ((int)(x).size())  
using namespace std;  
typedef long long int LL;
const int N = 1e5+24;  
const LL INF = 1e15;  
int n, q,st;
LL dis[N];  
bool vis[N];  
struct Node {  
    LL d;
	int e;  
    bool operator < (const Node x) const {  
        return x.d < d;  
    }  
    Node(LL d, int e):d(d), e(e){}  
};  
vector<pair<int, LL> > V[N];  
  
void dijkstra(int s) {  
    priority_queue<Node> q;  
    fill(dis + 1, dis + n + 1, INF);  
    fill(vis + 1, vis + n + 1, false);  
    q.push(Node(0, s));  
    dis[s] = 0;  
    while(!q.empty()) {  
        Node deq = q.top(); q.pop();  
        if(vis[deq.e])    
            continue;  
        vis[deq.e] = true;  
        for(int i = 0;i < sz(V[deq.e]);i++) {  
            int e = V[deq.e][i].first;  
            LL w = V[deq.e][i].second;  
            if(dis[deq.e] < dis[e] - w) {  
                dis[e] = dis[deq.e] + w;  
                q.push(Node(dis[e], e));      
            }  
        }  
    }     
}  
  
int main(){  
    while(~scanf("%d",&n)) {  
        for(int i = 1;i <= n;i++)  
            V[i].clear();  
        for(int i = 1;i < n;i++) {  
            int a, b; LL w;  
            scanf("%d%d%lld", &a, &b, &w);  
            V[a].pb(mp(b, w));  
            V[b].pb(mp(a, w));    
        }  
		scanf("%d%d",&q,&st);
        dijkstra(st);
		for(int i=1;i<=q;i++){
			int a,b;
			scanf("%d%d",&a,&b);
			printf("%lld\n", dis[a]+dis[b]);  
		}
    }  
    return 0;  
} 

Measured memory_bytes: 11248
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int a = -1;
    int cnt = 1;
    for (int i = 1; i < N; i++) {
        if (a==-1) {
            if (A[i-1] < A[i]) a = 1;
            if (A[i-1] > A[i]) a = 0;
        } else if (a==0) {
            if (A[i-1] < A[i]) {
                a = -1;
                cnt++;
            }
        } else {
            if (A[i-1] > A[i]) {
                a = -1;
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<time.h>
using namespace std;

int main()
{
	int N;
	cin >> N;
	while (1) {
		if ((int)sqrt(N)*sqrt(N) == N) {
			cout << N;
			break;
		}
		else {
			N--;
		}
	}
	return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back
int T[2019];
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int v = 0;
    int p10 = 1;
    T[0]++;
    for(int i = 0; i < s.size(); i++){ 
        v += p10 * (s[i] - '0');
        v %= 2019;
        T[v]++;
        p10 = p10 * 10 % 2019;
    }
    int ans = 0;
    for(int i = 0; i < 2019; i++) {
        ans += (T[i] * (T[i] - 1))/2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3752
import math


def f(a, b):
    q = len(str(a))
    w = len(str(b))
    return max(q, w)


N = int(input())
mi = 10**10
for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        mi = min(mi, f(i, int(N/i)))
print(mi)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)
	{
		double s;
		s=i*1.000000*1.08;
		if((int)(s)==n)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<":(";
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  A
//
//  Created by E SAMEER KUMAR on 09/04/20.
//  Copyright © 2020 E SAMEER KUMAR. All rights reserved.

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int main(int argc, const char * argv[]) {
    // insert code here...
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    char grid[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grid[i][j];
        }
    }
    int ans=0;
    int dp[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            dp[i][j]=0;
        }
    }
    dp[n-1][m-1]=1;
    for(int i=n-1;i>=0;i--)
        for(int j=m-1;j>=0;j--){
            //cout<<dp[i][j]<<'\n';
            if(j+1<m && grid[i][j]!='#'){
                dp[i][j]+=dp[i][j+1];
                dp[i][j]%=MOD;
            }
            if(i+1<n && grid[i][j]!='#'){
                dp[i][j]+=dp[i+1][j];
                dp[i][j]%=MOD;
            }
        }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<'\n';
    }*/
    cout<<dp[0][0]<<endl;
    return 0;
}


Measured memory_bytes: 5120