akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        a_s: [u64; n],
    }
    // 1/(1/a + 1/b + 1/c + 1/d)
    // a/(1 + a/b + a/c + a/d)
    // ab/(b + a + ab/c + ab/d)
    // abc/(bc + ac + ab + abc/d)
    // abcd/(bcd + acd + abd + abc)
    let numerator = a_s.iter().fold(1.0, |sum, i| sum * *i as f64);
    let denominator = a_s
        .iter()
        .map(|i| numerator / *i as f64)
        .fold(0.0, |sum, i| sum + i);
    let ans = numerator / denominator;
    println!("{}", ans);
}


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

int main(void){
    int k, s;
    cin >> k >> s;
    
    int x, y, z;
    int cnt = 0;
    for (x = 0; x <= k; x++){
        for (y = 0; y <= k; y++){
            z = s - (x + y);
            if (z < 0) continue;
            if (z <= k) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	while (1)
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		bool flag = false;
		int max_value = 0;
		int now = 0;
		for ( int i = 0; i < n; i++ )
		{
			int value;
			cin >> value;
			now += value;
			if ( flag == false )
			{
				max_value = now;
				flag = true;
			}
			max_value = max( now, max_value );
			if ( now < 0 )
				now = 0;
		}

		if ( now > 0 )
			max_value = max( now, max_value );

		cout << max_value << endl;

	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))

# 1〜Nの並び替えなので、最後は必ず1になる

# まず左端までを1に
idx = A.index(1)

# 左の個数
left = ceil(idx / (K-1))
remain = (K-1)*(left-1)+K

# 右の個数
right = ceil((N-remain) / (K-1))

print(left+right)

Measured memory_bytes: 13876
#include <bits/stdc++.h>
using namespace std;
string S;
string T;
vector<int> Rs(26, -1);
vector<int> Rt(26, -1);

int main() {
    cin >> S;
    cin >> T;

    int len = S.length();
    int flag = 0;
    for(int i = 0; i < len; ++i) {
        if(Rs.at(S.at(i) - 97) < 0) {
            Rs.at(S.at(i) - 97) = T.at(i);
        }else {
            if(Rs.at(S.at(i) - 97) != (int)T.at(i)) {
                flag = 1;
                break;
            }
        }

        if(Rt.at(T.at(i) - 97) < 0) {
            Rt.at(T.at(i) - 97) = S.at(i);
        }else {
            if(Rt.at(T.at(i) - 97) != (int)S.at(i)) {
                flag = 1;
                break;
            }
        }
    }

    if(flag == 0) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 776
import java.util.ArrayList;
import java.util.Scanner;

// 2015 C??????, compiler
public class Main {
    public static int INF = Integer.MAX_VALUE;
    static Scanner sc;

    public static void main(String[] args) {
        init();

        while (true) {
            int n = ni();
            if (n == 0) {
                break;
            }
            nl();

            Element root;
            String ls = nl();
            if (ls.equals("+")) {
                root = new Plus();
            } else if (ls.equals("*")) {
                root = new Multi();
            } else {
                root = new Operand(Integer.parseInt(ls));
            }

            for (int i = 1; i < n; i++) {
                String l = nl();
                int level = l.length() - 1;
                String value = "" + l.charAt(l.length() - 1);
                if (value.equals("+")) {
                    root.add(level, new Plus());
                } else if (value.equals("*")) {
                    root.add(level, new Multi());
                } else {
                    root.add(level, new Operand(Integer.parseInt(value)));
                }
            }
            System.out.println(root.calc());
        }

        end();
    }
    public static void init() {
        sc = new Scanner(System.in);
    }
    public static void end() {
        sc.close();
    }
    public static int ni() {
        return sc.nextInt();
    }
    public static String nl() {
        return sc.nextLine();
    }
}

interface Element {
    int calc();
    void add(int level, Element value);
}

abstract class Operator implements Element {
    public ArrayList<Element> elements;
    public Operator making;
    public Operator() {
        this.elements = new ArrayList<>();
    }
    public void add(int level, Element value) {
        if (level == 1) {
            this.elements.add(value);
            if (value instanceof Operator) {
                this.making = (Operator) value;
            }
            return;
        }
        making.add(level - 1, value);
    }
}

class Operand implements Element {
    int value;
    public int calc() {
        return value;
    }
    public void add(int level, Element value) {
    }
    Operand(int value) {
        this.value = value;
    }
}

class Plus extends Operator {
    public int calc() {
        int ans = 0;
        for (Element e : elements) {
            ans += e.calc();
        }
        return ans;
    }
}

class Multi extends Operator {
    public int calc() {
        int ans = 1;
        for (Element e : elements) {
            ans *= e.calc();
        }
        return ans;
    }
}

Measured memory_bytes: 32500
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()
	a := scanInts(n)

	t := a[0]
	ma := a[0]
	for _, e := range a {
		t = gcd(t,e)
		ma = max(ma, e)
	}

	if k%t == 0 && k <= ma {
		fmt.Fprintln(wr, "POSSIBLE")
	} else {
		fmt.Fprintln(wr, "IMPOSSIBLE")
	}
}

func gcd(a,b int) int { for b != 0 { a, b = b, a%b }; return a }


Measured memory_bytes: 3072
N, C = gets.split(' ').map(&:to_i)
ss = [[0, 0]]
N.times do
  ss.push(gets.split(' ').map(&:to_i))
end
fsum = Array.new(N + 2, 0)
fsumm =  Array.new(N + 2, 0)
fsumr =  Array.new(N + 2, 0)
bsum =  Array.new(N + 2, 0)
bsumm =  Array.new(N + 2, 0)
bsumr =  Array.new(N + 2, 0)
t = 0
1.upto(N) do |i|
  t += ss[i][1]
  fsum[i] = t - ss[i][0]
  fsumm[i] = [fsumm[i - 1], fsum[i]].max
  fsumr[i] = t - 2 * ss[i][0]
end
t = 0
N.downto(1) do |i|
  t += ss[i][1]
  bsum[i] = t - (C - ss[i][0])
  bsumm[i] = [bsumm[i + 1], bsum[i]].max
  bsumr[i] = t - 2 * (C - ss[i][0])
end
cand = []
0.upto(N) do |i|
  cand.push(fsum[i])
  cand.push(bsum[i])
  cand.push(fsumr[i] + bsumm[i + 1])
  cand.push(bsumr[i] + fsumm[i - 1])
end
puts cand.max

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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int k, a, b;
num ans;

int main() {
    cin >> k >> a >> b;
    if (b - a <= 2) {
        cout << k + 1 << endl;
    } else {
        if (k <= a) {
            cout << k + 1 << endl;
        } else {
            bool flag = 0;
            k -= a - 1;
            if (k & 1) {
                flag = 1;
            }
            ans = (num) (b - a) * (k / 2) + a + flag;
            cout << ans << endl;
        }
    }
}


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

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

	int n, m;
	cin >> n >> m;

	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(m);
	vector<int>d(m);

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

	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}

	vector<int>shortest(n);
	for (auto &x : shortest)
		shortest[x] = -1;

	long long int count0, count1, num;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			count0 = a[i] - c[j];
			count1 = b[i] - d[j];
			if (count0 < 0)count0 *= (-1);
			if (count1 < 0)count1 *= (-1);
			if (j==0) {
				num = count0 + count1;
				shortest[i] = j;
			}
			else if (num > count0 + count1) {
				shortest[i] = j;
				num = count0 + count1;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << shortest[i] + 1 << "\n";
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
const long long INF = 1e12;

int main() {
ll s;
cin >>s;
if (s % 10 == 3) cout << "bon" << endl;
else if(s % 10 == 0||s % 10 == 1||s % 10 == 6||s % 10 == 8)
    cout << "pon" << endl;
else
    cout << "hon" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
    using namespace std;
   
    int main(){
    int N,count = 0;
    cin >> N;
    double sum=0.0,ave;
    int x[N],y[N];

    vector<int> v(N);
    for (int i = 0; i < N; i++) {
      cin >> x[i] >> y[i];
      v[i] = i;
    }
    do{
      for (int i = 0; i < N-1; i++)
      {
        sum += pow(pow(x[v[i]]-x[v[i+1]],2) + pow(y[v[i]]-y[v[i+1]],2) ,0.5);
      }
      count++;

    }while(next_permutation(v.begin(),v.end()));
     
    ave = sum / count;
    cout << fixed << setprecision(10)<<ave;
     }

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


ll a[sz];
ll b[sz];




int main()
{

  ll n,i,j,k,p;

  cin>>n;

  for(i=1;i<n;i++)cin>>b[i];

  a[1]=b[1];

  for(i=2;i<n;i++)
  {
      a[i]=min(b[i],b[i-1]);
  }
  a[n]=b[n-1];


  ll s=0;

  for(i=1;i<=n;i++)s+=a[i];

  cout<<s<<endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#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;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

long long gcd(long long int a, long long int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

long long lcm(long long int a,long long int b) {
    return a / gcd(a, b) * b ;
}

int main(void) {
    long long int t[100];
    int n,i;
    long long int ans=1LL;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&t[i]);
        ans=lcm(ans, t[i]);
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
c[1100000],n=1e6;main(i,j){for(i=2;i*i<n;++i)if(!c[i])for(j=i;j<n;c[j+=i]=1);for(j=0;~scanf("%d",&n);j=!printf("%d\n",j))for(i=n;i>1;j+=!c[i--]);}

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

lli pw[11];
int main() {
    pw[0]=1;
    for(int i=1;i<11;i++) pw[i]=pw[i-1]*10;

    int arr[11]={0,};
    for(int s=0;s<11;s++) {
        int lo=(s==0 ? 0 : -1), up=9;
        lli v=0;
        for(int i=0;i<s;i++) v=v*10+arr[i];
        
        while(up-lo>1) {
            int md=(lo+up)>>1;
            
            lli tv=v*10+md;
            for(int i=s;i<11;i++) tv=tv*10+9;
            printf("? %lld\n",tv);
            fflush(stdout);
            
            char str[11];
            scanf("%s",str);
            if(str[0]=='Y') up=md;
            else lo=md;
        }
        arr[s]=up;
    }

    lli ans=0,s;
    if(arr[0]==1) s=2;
    else s=1;

    for(int i=0;i<11;i++) {
        printf("? %lld\n",s*pw[i]);
        fflush(stdout);
        
        char str[10];
        scanf("%s",str);
        if(arr[0]==1 && str[0]=='Y') {
            for(int j=0;j<=i;j++) ans=ans*10+arr[j];
            break;
        }
        if(arr[0]!=1 && str[0]=='N') {
            for(int j=0;j<i;j++) ans=ans*10+arr[j];
            break;
        }
    }
    printf("! %lld\n",ans);
    fflush(stdout);

    return 0;
}


Measured memory_bytes: 596
a = Array.new
3.times do
    a_row = gets.chomp.split
    a_row.length.times do |i|
        a_row[i] = a_row[i].to_i
    end
    a << a_row
end

n = gets.to_i
b = Array.new
n.times do
    input_b = gets.to_i
    b << input_b
end

3.times do |i|
    3.times do |j|
        9.times do |k|
            if a[i][j] == b[k]
                a[i][j] = 0
            end
        end
    end
end

result = false

3.times do |i|
    3.times do|j|
        if a[i][j] != 0
            break
        end
        if j == 2
            result = true
        end
    end
    if result
        break
    end
end

unless result
    3.times do |i|
        3.times do|j|
            if a[j][i] != 0
                break
            end
            if j == 2
                result = true
            end
        end
        if result
            break
        end
    end
end

# if a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0
#     result = true
# end

# if a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0
#     result = true
# end

# if a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0
#     result = true
# end

# if a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0
#     result = true
# end

# if a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0
#     result = true
# end

# if a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0
#     result = true
# end

if !result && ((a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) || (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0))
    result = true
end

if result
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        int N = s.nextInt();

        while (N-- > 0) {
            String mcxi1 = s.next();
            String mcxi2 = s.next();

            int num1 = changeToNum(mcxi1);
            int num2 = changeToNum(mcxi2);

            int ans = num1 + num2;

            changeToMCXI(ans);

//            System.out.println(changeToMCXI(ans));
        }
    }

    static int changeToNum(String str) {
        char[] ch = str.toCharArray();
        int num = 0;
        int temp = 1;

        for (int i = 0; i < ch.length; i++) {
            if (Character.isDigit(ch[i])) {
                temp = (int) ch[i] - 48;
            } else {
                switch (ch[i]) {
                    case 'm':
                        num += temp * 1000;
                        break;
                    case 'c':
                        num += temp * 100;
                        break;
                    case 'x':
                        num += temp * 10;
                        break;
                    case 'i':
                        num += temp;
                        break;
                }
                temp = 1;
            }
        }
        return num;
    }

    static void changeToMCXI(int num) {
        char[] ch = new char[9];
        int i = 0;
        if (num / 1000 != 0) {
            if (num / 1000 != 1)
                System.out.print(num / 1000);
//                ch[i++] = (char) (48 + num / 1000);
            System.out.print("m");
//            ch[i++] = 'm';
            num = num % 1000;
        }
        if (num / 100 != 0) {
            if (num / 100 != 1)
                System.out.print(num / 100);
//                ch[i++] = (char) (48 + num / 100);
            System.out.print("c");
//            ch[i++] = 'c';
            num = num % 100;
        }
        if (num / 10 != 0) {
            if (num / 10 != 1)
                System.out.print(num / 10);
//                ch[i++] = (char) (48 + num / 10);
            System.out.print("x");
//            ch[i++] = 'x';
            num = num % 10;
        }
        if (num / 1 != 0) {
            if (num != 1)
                System.out.print(num);
//                ch[i++] = (char) (48 + num);
            System.out.print("i");
//            ch[i++] = 'i';
        }
        System.out.println();
//        return String.valueOf(ch);
    }
}

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

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()
{
    const ll INF = 10000000000;
    int n;
    cin >> n;
    vector<int> h;
    vector<ll> dp(n,INF);
    for( int i = 0; i < n; ++i )
    {
        int a; cin >> a;
        h.push_back(a);
    }
    
    dp[0] = 0;
    for( int i = 1; i < n; ++i )
    {
        chmin( dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if( i > 1 )
        {
            chmin( dp[i], dp[i-2]+abs(h[i]-h[i-2]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1660
// written by @kakira9618
// problem: http://icpc.iisf.or.jp/past-icpc/domestic2016/problems/all_ja.html#section_D


#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <map>

using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long int;

ll fact[100001];
ll inverse[100001];
ll mod = 1e9+7;

ll pow(ll n, ll k, ll mod) {
    if (k == 0) return 1;
    else if (k % 2 == 1) {
        return n * pow(n, k - 1, mod) % mod;
    } else {
        ll t = pow(n, k / 2, mod);
        return t * t % mod;
    }
}

void init(ll n, ll mod) {
    fact[0] = 1;
    inverse[0] = 1;
    ll now = 1;
    for(int i = 1; i <= n; i++) {
        now = now * i % mod;
        fact[i] = now;
        inverse[i] = pow(now, mod - 2, mod);
    }
}

int comb(ll n, ll k, ll mod) {
    if (n < 0 || k < 0 || k > n) {
        return 0; 
    }
    return (fact[n] * inverse[k]) % mod * inverse[n - k] % mod;
}

int main() {

    int n;
    cin >> n;
    vector<int> A;
    map<int,int> cnt;
    for(int i = 0; i < n + 1; i++) {
        int a;
        cin >> a;
        A.push_back(a);
        cnt[a]++;
    }
    int num = 0;
    for(auto &e: cnt) {
        if (e.second == 2) {
            num = e.first;
        }
    }

    int l = -1, r = -1;
    for(int i = 0; i < n + 1; i++) {
        if (A[i] == num) {
            if (l == -1) {
                l = i;
            } else {
                r = i;
                break;
            }
        }
    }

    init(n + 1, mod);

    for(int k = 1; k <= n + 1; k++) {
        cout << ((comb(n + 1, k, mod) - comb(l + n - r, k - 1, mod)) + mod) % mod << endl;
    }

    return 0;
}

Measured memory_bytes: 7800
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector<ld> a(n);
	fori(n) {
		cin >> a[i];
	}
	
	vector<vector<ld>> dp(n+1, vector<ld> (n+1, 1.0));
	fori(n+1) 
		forj(n+1) 
			if (j > i) dp[i][j] = 0;

	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j <= n; ++j) {
			dp[i][j] = dp[i-1][j]*(1-a[i-1]);
			if (j > 0) 
				dp[i][j] += dp[i-1][j-1]*a[i-1];
		}	
	}

	ld ans = 0;
	for(int j = n/2+1; j <= n; ++j) 
		ans += dp[n][j];

	cout << fixed << setprecision(10) << ans << nl;
		
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<pair<double,string>>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i].first>>a[i].second;
  }
  double kotae=0;
  for(int i=0;i<n;i++){
    //cout<<a[i].second<<endl;
    if(a[i].second=="JPY"){
      kotae+=a[i].first;
    }else{
      kotae+=a[i].first*(double)380000;
    }
  }  
  cout<<fixed<<setprecision(6)<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,k,tmp;
    cin>>n>>k;
    tmp=k;
    ll i=1;
    while(!(tmp>n)){
        tmp*=k;
        ++i;
    }
    cout<<i<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	int dp[10001]{};
	for (int c = 0; c < a; c++) {
		int d, e;
		cin >> d >> e;
		for (int f = b;f>=e; f--) {
			dp[f] = max(dp[f], dp[f - e] + d);
		}
	}
	cout << dp[b] << endl;
}

Measured memory_bytes: 3132
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      string[] str=Console.ReadLine().Split(' ');
      string s=str[0];
      string t=str[1];
      
      for(int i=0;i<=(N-1);i++){
        Console.Write(s.Substring(i,1));
        Console.Write(t.Substring(i,1));
      }
     
    }
    
  }

}

Measured memory_bytes: 11092
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    t,h =input().split()
    if t > h:
        taro+=3
    elif t<h:
        hanako += 3
    else:
        taro += 1
        hanako += 1

print("%d %d" % (taro,hanako))

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

int main(void)
{
    char S[10*10*10*10*10*10],T[10*10*10*10*10*10] ;
    if(fgets(S, sizeof(S), stdin)==NULL) exit(1);
    if(fgets(T, sizeof(T), stdin)==NULL) exit(1);

    int i, count = 0;
    for (i = 0; i < strlen(S); i++){
        if(S[i] != T[i]){
            count++;
        }
    }

    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1996
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 200005, inf = 1000000005;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, a[N];
map<int, int> m;

bool check (int mid) {
	m.clear();
	for (int i = 1, j = 0; i < n; i++) {
		if (a[i] <= a[i - 1]) {
			if (mid <= 1) return false;
			while (!m.empty() && m.rbegin() -> first > a[i]) m.erase(m.rbegin() -> first);
			m[a[i]]++;
			for (j = a[i]; j; j--) {
				if (m[j] < mid) break;
				m[j] = 0, m[j - 1]++;
			}
			if (!j) return false;
		}
	}
	return true;
}
int main () {
	read(n);
	for (int i = 0; i < n; i++) read(a[i]);
	int l = 1, r = inf;
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	write(l), putchar('\n');
	return 0;
}

Measured memory_bytes: 1024
import math
import copy

#n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

if (s == 'ABC'):
    print('ARC')
else:
    print('ABC')




Measured memory_bytes: 9284
// 赵文浩 orz
#include<bits/stdc++.h>
#define pts putchar('\n');
#define ptc putchar(' ');
#define f1(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long ll;
typedef long long ll;
const int maxm=3e5+9;
const int maxn=5e3+9;
const int N=200+9;
const int mod=20100403;
const ll inf=1e18;
const int base=131;
const double eps=1e-4;
int n,m;
ll dis[maxn]; 
ll val[maxn][N];
ll sum[maxn][maxn];
int L[maxn],R[maxn],stck[maxn],head=0;
ll read(){
    ll a=1,b=0;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-') a=-1;c=getchar();}
    while(c>='0'&&c<='9'){b=(b<<1)+(b<<3)+(c^'0');c=getchar();}
    return a*b;
}
void print(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int main(){
	n=read(),m=read();
	for(int i=2;i<=n;++i) dis[i]=read()+dis[i-1];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j) val[i][j]=read();
	for(int i=1;i<=m;++i){
		head=0;stck[0]=0;
		for(int j=1;j<=n;++j) L[j]=R[j]=0;
		for(int j=1;j<=n;++j){
			while(head&&val[j][i]>val[stck[head]][i]) head--;
			L[j]=stck[head]+1;stck[++head]=j;
		} 
		head=0;stck[0]=n+1;
		for(int j=n;j;--j){
			while(head&&val[j][i]>val[stck[head]][i]) head--;
			R[j]=stck[head]-1;stck[++head]=j;
		}
		for(int j=1;j<=n;++j){
			sum[L[j]][j]+=val[j][i];
			sum[j+1][j]-=val[j][i];
			sum[L[j]][R[j]+1]-=val[j][i];
			sum[j+1][R[j]+1]+=val[j][i];
		}
	}
	ll ans=-inf;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(i<=j) ans=max(ans,sum[i][j]-dis[j]+dis[i]);
		}
	}
	print(ans);
    return 0;
}

Measured memory_bytes: 204544
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int R; cin >> R;
	if (R < 1200)cout << "ABC" << endl;
	else if(R < 2800)cout << "ARC" << endl;
	else cout << "AGC" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int x;
int main(){
	cin >> x;
	for(int i=x;;i++){
		bool y=true;
		for(int j=2;j<i;j++)
			if(i%j==0){
				y=false;
				break;
			}
		if(y)return printf("%d",i),0;
	}
	return 0;
}

Measured memory_bytes: 256
n,a,b  = map(int,input().split( ))
mod = 10**9+7
ans = pow(2,n,mod)
def chs(t,s):
    res = 1
    for i in range(t,t-s,-1):
        res *= i
        res %=mod
    for i in range(1,s+1):
        rev = pow(i,mod-2,mod)
        res *= rev
        res %=mod
    return res
ans -= chs(n,a)
ans -= chs(n,b)
ans -= 1
ans %=mod
print(ans)


Measured memory_bytes: 40880
N = int(input())
S = list(input())

reS = S[::-1]

wSum = [0 for i in range(N)]
eSum = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        if S[i] == 'W':
            wSum[i] = 1
        if reS[i] == 'E':
            eSum[i] = 1
    else:
        if S[i] == 'W':
            wSum[i] = wSum[i-1] + 1
        else:
            wSum[i] = wSum[i-1]
        if reS[i] == 'E':
            eSum[i] = eSum[i-1] + 1
        else:
            eSum[i] = eSum[i-1]

eSum = eSum[::-1]

cost = eSum[1]

for i in range(1,N):
    if i == N - 1:
        if cost > wSum[N-2]:
            cost = wSum[N-2]
    else:
        if cost > wSum[i-1] + eSum[i+1]:
            cost = wSum[i-1] + eSum[i+1]
print(cost)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto& e : a) cin >> e;

  int b = 0, t = 1e9, m;
  while (b + 1 < t) {
    m = b + (t - b) / 2;

    int c = 0;
    for (auto e : a) c += (e - 1) / m;

    if (c > k) {
      b = m;
    } else {
      t = m;
    }
  }
  cout << t << endl;
}


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


int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d) printf("Yes\n");
	else printf("No\n");
	return 0;
} 

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

int main()
{
   int a,b,c;
   cin >> a >> b >> c;
   if (b<=a)
      {cout << "No" << endl;}
   else if (c<=a)
      {cout << "No" << endl;}
   else if (c<=b)
      {cout << "No" << endl;}
   else {cout << "Yes" << endl;}
   
    return 0;
}



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

#define MAX 100000
bool is_cached, erased[MAX + 1], is2017[MAX + 1];
int natural[MAX + 1], cumsum[MAX + 1];

void eratosthenes() {
    for (int i = 2; i <= MAX; ++i) {
        natural[i] = i;
    }

    for (int i = 2; i <= MAX; ++i) {
        if (!erased[i]) {
            for (int j = 2 * i; j <= MAX; j += i) {
                if (natural[j] % natural[i] == 0) {
                    erased[j] = true;
                }
            }
        }
    }
}

bool is_prime(int x) {
    if (!is_cached) {
        eratosthenes();
        is_cached = true;
    }

    return !erased[x];
}

int N, L, R;

int main() {
    for(int i = 3; i <= MAX; ++i) {
        if(is_prime(i) && is_prime((i + 1) / 2)) {
            is2017[i] = true;
        }
    }

    for(int i = 3; i <= MAX; ++i) {
        if (is2017[i]) {
            cumsum[i] = cumsum[i - 1] + 1;
        } else {
            cumsum[i] = cumsum[i - 1];
        }
    }

    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> L >> R;
        cout << cumsum[R] - cumsum[L - 1] << endl;
    }
}


Measured memory_bytes: 1664
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int llcmp(const void *a, const void *b) {
    if (*(long long *)a > *(long long *)b) return -1;
    else if (*(long long *)a < *(long long *)b) return 1;
    else return 0;
}

long long T[1000010], U[3000010];

long long max(int len, ...) {
    long long i, _max, num;
    va_list ap;
    va_start(ap, len);

    _max = va_arg(ap, long long);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, long long);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}
int main(void) {
    int i, j, l, m, n, X, Y, Z, K;
    long long A[1010], B[1010], C[1010];
    scanf("%d%d%d%d", &X, &Y, &Z, &K);
    for (l=0;l<X;l++) scanf("%lld", &A[l]);
    for (m=0;m<Y;m++) scanf("%lld", &B[m]);
    for (n=0;n<Z;n++) scanf("%lld", &C[n]);
    i = 0; j = 0;
    qsort(A, X, sizeof(long long), llcmp);
    qsort(B, Y, sizeof(long long), llcmp);
    qsort(C, Z, sizeof(long long), llcmp);
    for (l=0;l<X;l++) for (m=0;m<Y;m++) {
        T[i++] = A[l] + B[m];
    }
    qsort(T, i, sizeof(long long), llcmp);
    for (l=0;l<3000;l++) for (m=0;m<Z;m++) {
        U[j++] = T[l] + C[m];
    }
    qsort(U, j, sizeof(long long), llcmp);
    for (l=0;l<K;l++) printf("%lld\n", U[l]);

    return 0;
}

Measured memory_bytes: 54916
n = int(input())
a = [int(input()) for _ in range(n)]

a = sorted(a)
l = len(a)

if n % 2 == 0:
    # 谷max, 山, 谷, ..., 山, 谷, 山min
    tani = sorted(a[:l // 2], reverse=True)
    yama =  a[l // 2 + 1:] + [a[l // 2]]
    ans = 0
    for i in range(l //2):
        ans += yama[i] - tani[i]
    for i in range(l //2 - 1):
        ans += yama[i] - tani[i + 1]
    print(ans)

else:
    # 谷max, 山, 谷, ..., 山, 谷max
    tani = sorted(a[:l // 2 + 1], reverse=True)
    tani = tani[1:] + [tani[0]]
    yama = a[l // 2 + 1:]
    t = 0
    for i in range(l // 2):
        t += yama[i] - tani[i]
    for i in range(l // 2):
        t += yama[i] - tani[i + 1]
    ans = t

    # 山min, 谷, 山, ..., 谷, 山min
    tani = sorted(a[:l // 2], reverse=True)
    yama = a[l // 2:]
    yama = yama[1:] + [yama[0]]
    t = 0
    for i in range(l // 2):
        t += yama[i] - tani[i]
    for i in range(l // 2):
        t += yama[i + 1] - tani[i]

    ans = max(ans, t)
    print(ans)

Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define PI 3.1415926535897932384626
#define mod 1000000007
#define modd 998244353

void io() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int T=1;
	// cin>>T;
	while(T--) {
		int n;
		cin>>n;
		cout<<(n>=30 ? "Yes" : "No");

	}
	return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

Measured memory_bytes: 3668
n=int(input())
A=list(map(int,input().split()))
S=0
cnt=0 #マイナスの個数
m=10**10 #絶対値の最小値
for a in A:
    S+=abs(a)
    m=min(abs(a),m)
    if a<0:
        cnt+=1

if cnt%2==0 or m==0:
    print(S)
    
else:
    print(S-2*m)

Measured memory_bytes: 14284
#include <stdio.h>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;
#define MAXN 100001

int A[MAXN];
int n;

int main()
{
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

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

	int mx = 0;
	int ans;
	for (int i = 0; i < MAXN; i++) {
		int s = A[i];
		if (i) s += A[i-1];
		if (i < MAXN-1) s += A[i+1];

		if (mx < s) {
			mx = s;
			ans = i;
		}
	}

	printf("%d", mx);

	return 0;
}

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

int main(){
  const long long c=1e9+7;
  long long N;
  long long p=1;
  cin >> N;
  for(long long i=1; i<=N; i++){
    p = (p*i) % c;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(long[]), H = ip[0], W = ip[1];
	if(min(H, W) == 1) {
		writeln(1);
		return;
	}
	writefln("%d", ceil(H * W / 2.).to!long);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n+1);
  vector<ll> b(m+1);
  a.at(0)=0;
  b.at(0)=0;
  for(ll i=1;i<=n;i++){
    cin >> a.at(i);
    a.at(i)=a.at(i-1)+a.at(i);
  }
  for(ll i=1;i<=m;i++){
    cin >> b.at(i);
    b.at(i)=b.at(i-1)+b.at(i);
  }
  ll ans=0;
  ll j=m;
  for(ll i=0;i<=n;i++){
    if(a.at(i)>k)
    break;
    while(b.at(j)>k-a.at(i))
    j--;
    ans=max(ans,i+j);
  }
  cout << ans << endl;      
}

Measured memory_bytes: 6428
#include <stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  int i;
  int h[n];
  for(i=0;i<n;i++){
    scanf("%d", &h[i]);
  }
  int ans = 0;
  int height = 0;
  for(i=0;i<n;i++){
    if(height <= h[i]){
      height = h[i];
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e15;
int mod = 1e9+7;

//最小値取得
class SegmentTree{
public:
	int n = 1;
	vector<int> seg[2];
	//m要素のセグメントツリー作成
	void init(int m){
		while(n < m)n *= 2;
		rep(i,2)seg[i].resize(2*n);
		rep(i,2)fill(all(seg[i]), inf);
	}
	//kの値をxに変更
	void update(int t, int k, int x){
		k += n-1;
		seg[t][k] = x;
		while(k > 0){
			k = (k-1)/2;
			seg[t][k] = min(seg[t][k*2+1], seg[t][k*2+2]);
		}
	}
	int calc(int t, int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return inf;
		if(a <= l && r <= b)return seg[t][k];
		int vl = calc(t, a, b, k*2+1, l, (l+r)/2);
		int vr = calc(t, a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
	//[a,b)の最小値を求める
	int get(int t, int a, int b){return calc(t, a, b, 0, 0, n);}
};

int a[200004], dp[2][200004];
int n, q, x, y;
SegmentTree seg;
int solve(){
	int ans = inf, mem = 0;
	rrep(i,q){
		int vl = seg.get(0, 1, a[i])+a[i];
		int vr = seg.get(1, a[i], n+1)-a[i];
		int res = min(vl, vr)-llabs(a[i]-a[i-1]);
		seg.update(0, a[i-1], res-a[i-1]);
		seg.update(1, a[i-1], res+a[i-1]);
		mem += llabs(a[i]-a[i-1]);
	}
	rrep(i,n)chmin(ans, seg.get(0, i, i+1)+i);
	rrep(i,n)chmin(ans, seg.get(1, i, i+1)-i);
	return ans+mem;
}

signed main(){
	scanf("%lld%lld%lld%lld", &n, &q, &x, &y);
	rrep(i,q)scanf("%lld", &a[i]);
	
	a[0] = y;
	seg.init(n+1);
	seg.update(0, x, -x);
	seg.update(1, x, x);
	printf("%lld\n", solve());
	return 0;
}


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

/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

//const ll md = 1e9 + 7;//998244353;
const int xn = 2e3 + 10;
const int xm = -20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int Md = 998244353;
const int TM = 3;
const int Base = 257;

int n, m, f[xn][xn], ans;
pii last[xn][xn];
string s[xn];
stack <int> st;
bool fl1, fl2;

int main(){
    InTheNameOfGod;
    
    cin >> n >> m;
    for (int i = 0; i < n; ++ i) cin >> s[i];
    for (int i = 0; i < m; ++ i) f[0][i] = i + 1;
    for (int i = 0; i < n; ++ i) f[i][0] = 1;
    for (int i = 1; i < n; ++ i){
    	for (int j = 1; j < m; ++ j){
    		fl1 = (s[i][j] == s[i - 1][j]);
    		fl2 = (s[i][j - 1] == s[i - 1][j - 1]);
    		f[i][j] = 1 + f[i][j - 1];
    		if (fl1 ^ fl2) f[i][j] -= f[i][j - 1];
		}
	}
	ans = max(n, m);
	for (int i = 0; i < m; ++ i){
		while (st.size()) st.pop();
		for (int j = 0; j < n; ++ j){
			while (st.size() && f[st.top()][i] >= f[j][i]) st.pop();
			if (st.size()) last[j][i].A = st.top();
			else last[j][i].A = 0;
			st.push(j);
		}
		while (st.size()) st.pop();
		for (int j = n - 1; j >= 0; -- j){
			while (st.size() && f[st.top()][i] >= f[j][i]) st.pop();
			if (st.size()) last[j][i].B = st.top();
			else last[j][i].B = n;
			st.push(j);
		}
	}
	for (int i = 0; i < n; ++ i) for (int j = 0; j < m; ++ j) ans = max(ans, f[i][j] * (last[i][j].B - last[i][j].A));
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 51840
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vi v(n);
	rep(i,n)cin>>v[i];
	vb b(10000,true);
	rep(i,n){
		int sum=0;
		for(int j=i;j<min(n,i+4);j++){
			sum*=10;
			sum+=v[j];
			b[sum]=false;
		}
	}
	rep(i,10000){
		if(b[i]){
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[100100],b[100100];
set<ll> sl;

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		cin >> b[i];
		sl.insert(b[i]);
	}
	bool f = 1;
	vector<ll> vl[2];
	rep(i, n) {
		vl[0].push_back(a[i]);
		if (sl.find(a[i]) != sl.end()) {
			vl[1].push_back(a[i]);
		}
		else {
			f = 0;
			if (i != 0)vl[1].push_back(a[0]);
			else vl[1].push_back(a[1]);
		}
	}
	if (f)cout << "Yes" << endl;
	else {
		cout << "No" << endl;
		rep(j, 2) {
			rep(i, n) {
				if (i != 0)cout << " ";
				cout << vl[j][i];
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 11056