akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, AB):
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)

    s = [(1, -1, 0, 0)]
    ans = [1] * (N+1)
    while s:
        u, p, k1, k2 = s.pop()
        ans[u] = K - k1 - k2

        cu = 0
        for v in g[u]:
            if v == p:
                continue
            s.append((v, u, 1, cu+k1))
            cu += 1

    M = 10**9+7
    return reduce(lambda x, y: (x * y) % M, ans)



def main():
    N, K = read_int_n()
    AB = [read_int_n() for _ in range(N-1)]
    print(slv(N, K, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 120988
#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()
#define mod 1000000007
typedef long long ll;

int main(){
  ll a, b;
  cin >> a >> b;
  if(a != 0){
    a--;
    ll sum = 0;
    for(ll i=1; i<=50; i++){
      ll cnt;
      ll bc = (b+1)/(ll)pow(2, i)*(ll)pow(2, i-1);
      if((b+1)%(ll)pow(2, i) > (ll)pow(2, i-1)) 
        bc += (b+1)%(ll)pow(2, i)-(ll)pow(2, i-1);
      ll ac = (a+1)/(ll)pow(2, i)*(ll)pow(2, i-1);
      if((a+1)%(ll)pow(2, i) > (ll)pow(2, i-1)) 
        ac += (a+1)%(ll)pow(2, i)-(ll)pow(2, i-1);
      cnt = bc - ac;
      if(cnt % 2 == 1) sum += (ll)pow(2, i-1);
    }
    cout << sum << endl;
  }else{
    ll sum = 0;
    for(ll i=1; i<=50; i++){
      ll cnt;
      ll bc = (b+1)/(ll)pow(2, i)*(ll)pow(2, i-1);
      if((b+1)%(ll)pow(2, i) > (ll)pow(2, i-1)) 
        bc += (b+1)%(ll)pow(2, i)-(ll)pow(2, i-1);
      cnt = bc;
      if(cnt % 2 == 1) sum += (ll)pow(2, i-1);
    }
    cout << sum << endl;
  }
  return 0;
}


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

int main(){
  string A, B, C;

  cin >> A >> B >> C;

  char alast = A[A.size() - 1];
  char bfirst = B[0];
  char blast = B[B.size() - 1];
  char cfirst = C[0];

  if (alast == bfirst && blast == cfirst) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }



}


Measured memory_bytes: 3600
import sys
import math

n = int(input())

min_func = -1
for a in range(1, math.ceil(math.sqrt(n)) + 1, 1):
    if n % a != 0:
        continue
    else:
        b = int(n / a)
        if min_func == -1:
            min_func = max(len(str(a)), len(str(b)))
        else:
            if min_func > max(len(str(a)), len(str(b))):
                min_func = max(len(str(a)), len(str(b)))

print("{}".format(min_func))


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

int main(){
  int n,r;
  int p,c;
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int cards[n];
    int result[n];
    for(int index=0;index<n;index++){
      cards[index] = n - index;
    }
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<n;j++){
        if(j < c){
          result[j] = cards[p-1+j];
        }else if(j < c + p - 1){
          result[j] = cards[j-c];
        }else{
          result[j] = cards[j];
        }
      }
      for(int k=0;k<n;k++) cards[k] = result[k];
    }
    cout << cards[0];
    cout << endl;
  }
}



Measured memory_bytes: 3080
class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self,x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        while self.parents[x] != root:
            parent = self.parents[x]
            self.parents[x] = root
            x = parent
        return root

    def unite(self,x,y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot:
            return
        xrank = self.rank[xroot]
        yrank = self.rank[yroot]
        if xrank < yrank:
            self.parents[xroot] = yroot
        elif xrank == yrank:
            self.parents[yroot] = xroot
            self.rank[yroot] += 1
        else:
            self.parents[yroot] = xroot

N,M = map(int,input().split())
P = list(map(int,input().split()))

uf = UnionFind(N)

for _ in range(M):
    x,y = map(int,input().split())
    uf.unite(x-1,y-1)

ans = 0

for i in range(N):
    if uf.find(i) == uf.find(P[i]-1):
        ans += 1

print(ans)

Measured memory_bytes: 13812
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, m, c[N];
int main()
{
	int t1, t2;
	cin >> n >> m;
	while (m--) scanf("%d %d", &t1, &t2), c[t1]++, c[t2]++;
	while (n) if (c[n--] & 1) {cout << "NO"; return 0;}
    cout << "YES";
    return 0;
}

Measured memory_bytes: 640
H,W=map(int,input().split())
L=list(list(input()) for _ in range(H))
for h in range(H):
    for w in range(W):
        if L[h][w]=='#':
            if not any((0<=h+d<=H-1 and L[h+d][w]=='#')
                   or (0<=w+d<=W-1 and L[h][w+d]=='#')for d in [-1,1]):
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int a,b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;
}

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

using namespace std;
/*---------------------SAUGATA KUNDU---------------------------*/

#define int long long int
#define INF (int)1e9+5
#define MoD (int)1e9 + 7
#define debug(a) cerr << '[' << a << ']' << '\n'

#define clear(a) memset(a, 0, sizeof(a))
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fos(i, b) for(int i = 0; i < b; i++)
#define foe(i, a) for(auto &i: a)
#define re(i, a, b) for(int i = b; i > a; i--)
#define pb push_back
#define all(c) c.begin(), c.end()
#define sz(x) (int)(x).size()
#define Fast ios::sync_with_stdio(0);cin.tie(0)
//data_structures
#define vt vector
#define que queue
#define sta stack
#define pque priority_queue
#define dque deque

#define point(pt) vt<int>::iterator pt
template<typename T> void read(vt<T> &a){
	fos(i, sz(a)) cin >> a[i];
}

#define endl '\n'
template<typename T> void write(vt<T> a){
	fos(i, sz(a)) cout << a[i] << ' ';
	cout << endl;
}
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
void solve(){
	string n;

	cin >> n;

	if(n[n.length()-1]=='s') n+= "es";
	else n+='s';

	cout << n << endl;
}

int32_t main() {
	Fast;

	int t=1;
	for(int i=1; i<=t; ++i) {
		solve();
	}

}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N;
vector<int> S;

void solve() {
    multiset<int> M;
    vector<int> used;
    sort(all(S));
    FOR((1ll << N) - 1) {
        M.insert(S[i]);
    }
    used.pb(S[(1ll << N) - 1]);
    FOR(fagr, 0, N) {
        vector<int> tmp;
        for (auto& x : used) {
            auto it = M.lb(x);
            if (it == M.begin()) {
                No();
                return;
            }
            it--;
            tmp.pb(*it);
            M.erase(it);
        }

        used.insert(used.end(), all(tmp));
        sort(all(used), greater<int>());
    }
    Yes();
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    S.resize(1ll << N);
    FOR(1ll << N)
    cin >> S[i];


    solve();
    return 0;
}


Measured memory_bytes: 14592
#include <stdio.h>

int main(){
  int x1,y1,x2,y2;

  scanf("%d %d %d %d",&x1,&y1,&x2,&y2);

  printf("%d %d %d %d\n",x2+y1-y2,y2-x1+x2,x1+y1-y2,y1-x1+x2);

  return 0;
}


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

const double EPS = 1e-9;
const int N = (int) 4e4;

struct Line {
    int a, b, c;
};
Line d[N];
pair<double, int> val[N];
int pos[N];
int bit[N], bitsize;
int n;

int get(int x) {
    int res = 0;
    while (x >= 0) {
        res += bit[x];
        x -= ~x & (x + 1);
    }
    return res;
}

void update(int x, int delta) {
    while (x < bitsize) {
        bit[x] += delta;
        x |= x + 1;
    }
}

int count(double x) {
    for (int i = 0; i < n; ++i) {
        val[i] = make_pair(-(d[i].c - x * d[i].a) / d[i].b, i);
    }
    sort(val, val + n);
    //int npos = 0;
    for (int i = 0; i < n; ++i) pos[val[i].second] = i;
    //for (int i = 0; i < n; ) {
        //int j = i + 1;
        //while (j < n && abs(val[i].first - val[j].first) < EPS) ++j;
        //for (int k = i; k < j; ++k) pos[val[k].second] = npos;
        //++npos;
        //i = j;
    //}
    bitsize = n;
    fill_n(bit, bitsize, 0);
    int res = 0;
    for (int i = 0; i < n; ++i) {
        res += get(pos[i]);
        update(pos[i], 1);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    //cout.precision(9);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> d[i].a >> d[i].b >> d[i].c;
    }
    for (int turn = 0; turn < 2; ++turn) {
        for (int i = 0; i < n; ++i) {
            if (d[i].b < 0) {
                d[i].a *= -1;
                d[i].b *= -1;
                d[i].c *= -1;
            }
        }
        sort(d, d + n, [] (const Line &a, const Line &b) {
                return a.a * b.b - b.a * a.b < 0;
                });
        double low = -2e8, high = 2e8;
        for (int run = 0; run < 80; ++run) {
            double mid = (low + high) / 2;
            if (count(mid) >= (n * (n - 1) / 2 + 1) / 2) high = mid;
            else low = mid;
            //if (count(mid) <= n * (n - 1) / 4) low = mid;
            //else high = mid;
        }
        //for (int i = 0; i < n; ++i) cout << d[i].a << ' ' << d[i].b << ' ' << d[i].c << '\n';
        //cout << low << ' ' << high << '\n';
        printf("%.9lf ", (low + high) / 2);
        //cout << (low + high) / 2 << ' ';
        for (int i = 0; i < n; ++i) {
            swap(d[i].a, d[i].b);
        }
    }
    //cout << n * (n - 1) / 4 << ' ' << count((low + high) / 2) << endl;
    return 0;
}


Measured memory_bytes: 1664
// quote from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#![allow(unused)]
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)]
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)*}
    };
}

#[allow(unused)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

macro_rules! out {
    ($x:expr) => {
        println!("{}", $x)
    };
}

macro_rules! debug {
    ($x:expr) => {
        println!("{:?}", $x)
    };
}

fn main() {
    input! {
        n: i32,
        m: i32,
    }
    out!(std::cmp::max(0, n - 2 * m))
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        string a,b;
        cin >> a >> b;
       int n=a.size();
        int m=b.size();
        int i,j,dp[n+1][m+1];
        //  for(i=0; i<=n; i++){
        //      for(j=0; j<=m; j++){
        //          dp[i][j]=0;
        //      }
        //  }
        vector<char>v;
        // string s;
        for(i=0; i<=n; i++){
            for(j=0; j<=m; j++){
                 dp[i][j]=0;
                if(i==0 || j==0)dp[i][j]=0;
                else if(a[i-1]==b[j-1]){
                    //s=s+a[i-1];
                    dp[i][j]=dp[i-1][j-1]+1;
                   // v.push_back(a[i]);
                }
                else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
       // cout << dp[n][m];

            i = n, j = m;
           
   while (i > 0 && j > 0)
   {
      if (a[i-1] == b[j-1])
      {
          v.push_back(a[i-1]);
          i--; j--;     
    }
      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }

   reverse(v.begin(),v.end());
   for(auto i :v) cout << i;


       


   
    

}


Measured memory_bytes: 70656
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
int m,d;
while(scanf("%d %d",&m,&d),(m!=0)){
for(int i=0;i<m;i++){
d=d+month[i];
}
d=d%7;
switch(d){
case 0:
cout<<"Wednesday"<<endl;
break;
case 1:
cout<<"Thursday"<<endl;
break;
case 2:
cout<<"Friday"<<endl;
break;
case 3:
cout<<"Saturday"<<endl;
break;
case 4:
cout<<"Sunday"<<endl;
break;
case 5:
cout<<"Monday"<<endl;
break;
case 6:
cout<<"Tuesday"<<endl;
}
}
return 0;
}

Measured memory_bytes: 1200
N = int(input())
W = [input() for _ in range(N)]
flag = True

for i in range(1, N):
  if W.count(W[i]) != 1 or W[i - 1][-1] != W[i][0]:
    flag = False
    break

if flag:
  print("Yes")
else:
  print("No")
    


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

int main() {
  string s;
  cin >> s;
  int out = 0;

  if (s[0] == '1') ++out;
  if (s[1] == '1') ++out;
  if (s[2] == '1') ++out;

  cout << out << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ld long double
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
const int inf=1e9+7;

int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vector<bool> dp(k+1,0);
	loop(i,0,n)
	{
		cin>>a[i];
	}
	loop(i,1,k+1)
	{
		loop(j,0,n)
		{
			if(i-a[j]>=0 && dp[i-a[j]]==0 ) dp[i]=1;
		}
	}
	(dp[k])?cout<<"First":cout<<"Second";
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;


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

  vector<int> W(N);

  for(int i = 0; i < N; i++)
  {
    cin >> W[i];
  }

  int sumdiff = 100;

  for(int i = 0; i < N; i++)
  {
    int T = i;
    int sumlow, sumup;

    sumlow = 0;
    sumup = 0;

    for(int j = 0; j < N; j++)
    {
      if(T >= j)  sumlow += W[j];
      else  sumup += W[j];
    }

    int temp = abs(sumup - sumlow);

    if(sumdiff > temp)  sumdiff = temp;

  }

  cout << sumdiff << endl;

  return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = float("INF")
b = [[float("INF")]*N for _ in range(N)]
b[0] = a
for k in range(N):
    for i in range(N):
        b[k][i] = min(b[k-1][i],a[i-k])
    ans = min(ans, sum(b[k])+k*x)

print(ans)


Measured memory_bytes: 36724
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<assert.h>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;
const int mod=1e9+7;

const int N=1e6;

int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

namespace io {
	const int L=(1<<21)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
	inline void flush() {
		fwrite(obuf,1,oS-obuf,stdout);
		oS=obuf;
	}
	inline void putc(char x) { *oS++=x; if (oS==oT) flush(); }
	template<class I> inline void gi(I&x) {
		for (f=1,c=gc();c<'0'||c>'9';c=gc()) if (c=='-') f=-1;
		for (x=0;c<='9'&&c>='0';c=gc()) x=x*10+(c&15); x*=f;
	}
	template<class I> inline void print(I x) {
		if (!x) putc('0');
		if (x<0) putc('-'),x=-x;
		while (x) st[++tp]=x%10+'0',x/=10;
		while (tp) putc(st[tp--]);
	}
	inline void gs(char*s, int&l) {
		for (c=gc();c<'a'||c>'z';c=gc());
		for (l=0;c<='z'&&c>='a';c=gc()) s[l++]=c;
		s[l]=0;
	}
	inline void ps(const char*s) { for (int i=0,n=strlen(s);i<n;i++) putc(s[i]); }
	struct IOFLUSHER{ ~IOFLUSHER() { flush(); } } _ioflusher_;
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::print;

int L[N],R[N];
int main()
{
	int n,i,l,r;LL ans=0;gi(n);
	for (i=1;i<=n;i++) {
		gi(l),gi(r),l+=1e5,r+=1e5;
		++R[r];++L[l];
	}
	for (i=2e5;~i;i--) L[i]+=L[i+1];
	for (i=1;i<=2e5;i++) R[i]+=R[i-1];
	for (i=1;i<=1e5;i++) {
		ans+=min(R[i-1],L[i]+1);
	}
	for (;i<=2e5;i++) {
		ans+=min(R[i-1]+1,L[i]);
	}
	print(ans*2);
	return 0;
}


Measured memory_bytes: 10112
#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn gcd(min: i64, max: i64) -> i64 {
    if min == 0 { max } else {gcd(max % min, min)}
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut left: Vec<i64> = vec![0; n + 1];
    let mut right: Vec<i64> = vec![0; n + 1];
    for i in 0..n {
        let index_r = n - i - 1;
        left[i + 1] = gcd(std::cmp::min(left[i], a[i]), std::cmp::max(left[i], a[i]));
        right[index_r] = gcd(std::cmp::min(right[index_r + 1], a[index_r]), std::cmp::max(right[index_r + 1], a[index_r]));
    }
    let mut answer = 0;
    for i in 0..n {
        answer = std::cmp::max(answer, gcd(std::cmp::min(left[i], right[i + 1]), std::cmp::max(left[i], right[i + 1])));
    }
    println!("{}", answer);
}

Measured memory_bytes: 6396
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
N,X=map(int,input().split())
l=[1]*(N+1)
p=[1]*(N+1)
for i in range(1,N+1):
    l[i]=2*l[i-1]+3
    p[i]=2*p[i-1]+1
def ans(n,x):
    if n==0:
        return 1
    if x==1:
        return 0
    elif 1<x<=l[n-1]+1:
        return ans(n-1,x-1)
    elif x==l[n-1]+2:
        return p[n-1]+1
    elif l[n-1]+2<x<=2*l[n-1]+2:
        return p[n-1]+1+ans(n-1,x-l[n-1]-2)
    else:
        return p[n-1]*2+1
print(ans(N,X))

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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0; }
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path; vl A, T;
//***********//
int main() {
	string S, T;
	cin >> S >> T;
	string Ans = T + S;
	cout << Ans;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
s =[]
s_w =[]

m = []

for i in range(H):
    s_t = input()
    s_w =[]
    for j in range(W):           
        s_w.append(s_t[j])
    s.append(s_w)

#print(s)

dy = [-1, -1, -1,  0,  0,  1, 1, 1]
dx = [-1,  0,  1, -1,  1, -1, 0, 1]

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            continue
        
        count = 0
        for k in range(8):
            
            ni = i + dy[k]
            nj = j + dx[k]
            
            if (ni<0 or H<=ni) or (nj<0 or W<=nj):
                continue
            if s[ni][nj] == "#":
                count += 1
        s[i][j] = str(count)

for i in range(H):
    for j in range(W):
        print(s[i][j], end="")
    print()

Measured memory_bytes: 3572
import java.util.*;

public class Main {
  public static void main(String[] args) {
 	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
 
	int ans = 0;
    for(int i = 0; i < n; i++){
    	int num = sc.nextInt();
    	while(num % 2 == 0){
     		ans++;
       		num /= 2;
      	}
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 32384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (void) {
	int n; cin >> n;
	vector <int> sides(n);
	for (int i = 0; i < n; i++)
		cin >> sides[i];
	sort(sides.rbegin(), sides.rend());
	long long L = -1, l = -1;
	for (int i = 0; i < n-1; i++) {
		if (L == -1) {
			if (sides[i] == sides[i+1]) {
				L = sides[i];
				sides[i] = -1; sides[i+1] = -1;
				i++;
			}
			else
				sides[i] = -1;
		}
		else if (l == -1) {
			if (sides[i] == sides[i+1]) {
				l = sides[i];
				sides[i] = -1; sides[i+1] = -1;
				i++;
				break;
			}
		}
	}
	if (l == -1 or L == -1) 
		cout << 0 << endl;
	else
		cout << L * l << endl;



	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair {
	int first;
	int second;
	int pos;

	Pair(int first, int second, int pos) {
		this.first = first;
		this.second = second;
		this.pos = pos;
	}
}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		int K = in.nextInt();
		int arr[] = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		long ans = Long.MAX_VALUE;
		long l = -1, r = -1;
		for (int i = 0; i + K - 1 < N; i++) {
			long moves = 0;
			l = arr[i];
			r = arr[i + K - 1];
			moves = Math.min((Math.abs(l) + Math.abs(l - r)), (Math.abs(r) + Math.abs(l - r)));
			ans = Math.min(ans, moves);

		}
		pw.println(ans);

	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 35184
#include<bits/stdc++.h>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a) for(ll i=a;i>=0;i--)
ll mod=1e9+7;
/*ll power(ll x,ll n)
{
    ll ans=1;
    while(n)
    {
       if(n&1)
       ans=(ans*x)%mod;
       n>>=1;
       x=(x*x)%mod;
    }
   // ans%=mod;
    return ans;
}
/*
struct comp {
    bool operator()(const pair& x, const pair& y) const {
        if (x.second != y.second)
            return x.second < y.second;

        return x.first < y.first;
    }
};
void dfs(int source,vector<int> graph[],vector<int> &path,bool status[])
{
 path.push_back(source);
 status[source]=0;
 //int j=graph[source].size();
 for(int i=0;i<graph[source].size();i++)
 {
     if(status[graph[source][i]]==1)
     dfs(graph[source][i],graph,path,status);
 }
 return;
}*
bool solve(int i,int j,string s)
{
    while(i<j)
    {
      if(s[i]<s[j])
      return 0;
      if(s[i]>s[j])
      return 1;
      i++;
      j--;
    }
    return 1;
}
bool isprime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        return 0;
    }
    return 1;
    
}
ll lg(ll x,ll n)
{
    ll ans=0;
    while(x/n!=0)
    {
        ans++;
        x/=n;
    }
    return ans;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k,q,t,y,x,k1,i1,j1,z,x1,y1,m,z1;
   string s;
   cin>>s;
   x=0;
  for(i=0;i<s.length();i++)
   x+=(s[i]-'0');
   if(x%9==0)
   cout<<"Yes";
   else
   cout<<"No";
}



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

using namespace std;

long fs_log2(long n) {
	long res = 0;
	while (n > 1) {
		res++;
		n = n >> 1;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	long h;
	cin >> h;
	cout << (1L << (fs_log2(h) + 1)) - 1;
	return 0;
}


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

typedef struct {
	double x, y, z, r;
} Coord;

typedef struct {
	int from, to;
	double weight;
} Edge;

Coord coord[ 100 ];
int node[ 100 ];
Edge edge[ 4950 ];

int compare( const void *a, const void *b ) {
	double at = (*(Edge *)a).weight, bt = (*(Edge *)b).weight;

	if ( at < bt )
		return -1;
	if ( at > bt )
		return 1;
	return 0;
}

int find( int x ) {
	if ( node[ x ] == x )
		return x;
	else
		return node[ x ] = find( node[ x ] );
}

int main( void ) {
	int i, j;
	int n;

	while ( scanf( "%d", &n ), n ) {
		int cnt;
		double sum;

		for ( i = 0; i < n; i++ )
			scanf( "%lf %lf %lf %lf", &coord[ i ].x, &coord[ i ].y, &coord[ i ].z, &coord[ i ].r );

		cnt = 0;
		for ( i = 0; i < n; i++ )
			for ( j = i + 1; j < n; j++ ) {
				edge[ cnt ].from = i;
				edge[ cnt ].to = j;
				edge[ cnt ].weight = fmax( sqrt( ( coord[ i ].x - coord[ j ].x ) * ( coord[ i ].x - coord[ j ].x ) + ( coord[ i ].y - coord[ j ].y ) * ( coord[ i ].y - coord[ j ].y ) + ( coord[ i ].z - coord[ j ].z ) * ( coord[ i ].z - coord[ j ].z ) ) - coord[ i ].r - coord[ j ].r, 0.0 );
				cnt++;
			}
		qsort( edge, cnt, sizeof(Edge), &compare );

		for ( i = 0; i < n; i++ )
			node[ i ] = i;

		sum = 0.0;
		for ( i = 0; i < cnt; i++ ) {
			int set1 = find( edge[ i ].from ), set2 = find( edge[ i ].to );
			if ( set1 != set2 ) {
				node[ set2 ] = set1;
				sum += edge[ i ].weight;
			}
		}

		printf( "%.3f\n", sum );
	}

	return 0;
}

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

using namespace std;

typedef pair <int, int> pii;

int res=0;
int N, M;
vector <pii> ab;

bool all_flag(bool flag[]){
        for(int i=0;i<N;i++){
                if(!flag[i]){
                        return false;
                }
        }
        return true;
}

void rec(int n, bool flag[]){
        if(all_flag(flag)){
                res++;
                return;
        }
        for(int i=0;i<M;i++){
                if(n==ab[i].first&&!flag[ab[i].second-1]){
                        flag[ab[i].second-1]=true;
                        rec(ab[i].second, flag);
                        flag[ab[i].second-1]=false;
                }
                else if(n==ab[i].second&&!flag[ab[i].first-1]){
                        flag[ab[i].first-1]=true;
                        rec(ab[i].first, flag);
                        flag[ab[i].first-1]=false;
                }
        }
}

int main(){
        cin>>N;
        cin>>M;
        for(int i=0;i<M;i++){
                int aa, bb;
                cin>>aa>>bb;
                if(bb>aa){
                        swap(aa, bb);
                }
                ab.push_back(make_pair(aa, bb));
        }
        sort(ab.begin(), ab.end());
        bool flag[8];
        for(int i=0;i<8;i++){
                flag[i]=false;
        }
        flag[0]=true;
        rec(1, flag);
        cout<<res<<endl;
        return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vl a(n);
    REP(i,n) cin>>a[i];

    ll ans = 0;
    ll cnt1;
    ll cnt0;
    REP(i,60){
        cnt1=0;
        cnt0=0;
        REP(j,n){
            if( (a[j]>>i) & 1) cnt1 += 1;
            else            cnt0 += 1;
        }

        ll dec = (1LL<<i) % MOD;
        
        dec = dec*cnt0 % MOD;
        dec = dec*cnt1 % MOD;
        //ll dec = (cnt0*cnt1) % MOD;
        //dec = (dec * (1LL<<i % MOD)) % MOD;
        ans = (ans+dec) % MOD;
    }

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

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long N;

  cin >> N;

  if( N%2 == 0){
    cout << N << endl;
  }else{
    cout << 2*N << endl;
  }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0 ; i < N ; i++) a[i] = sc.nextInt();
		int[] hindo = new int[100000];
		int[] ans = new int[100000];
		//頻度配列作成
		for(int i = 0 ; i < N ; i++) {
			hindo[a[i]]++;
		}

		for(int i = 0 ; i < 100000 ; i++) {
			if(i == 0) {
				ans[i] += hindo[i] + hindo[i + 1];
			} else if(i == 99999){
				ans[i] += hindo[i - 1] + hindo[i];
			} else {
				ans[i] += hindo[i - 1] + hindo[i] + hindo[i + 1];
			}
		}
		Arrays.sort(ans);
		System.out.println(ans[99999]);
	}
}

Measured memory_bytes: 50984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
int main()
{
    ll t,n,k,p,q,r,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    map<ll,ll>mp;
    vector<ll>v;
    cin>>s;
    p=s.size()-1;
    if(s[p]=='3') cout<<"bon"<<endl;
    else if(s[p]=='0' || s[p]=='1' || s[p]=='6' || s[p]=='8') cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}





Measured memory_bytes: 3628
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let ws = invec!(i64);

    let mut min = std::i64::MAX;
    for t in 1..n {
        let less: i64 = ws[0..t].iter().sum();
        let greater: i64 = ws[t..n].iter().sum();
        min = std::cmp::min(min, (greater - less).abs());
    }

    println!("{}", min);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std ;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    string ans="";
    for (int i = 0; i <s.length() ; i++) {
        if(s[i]=='0')ans+='0';
        else if(s[i]=='1')ans+='1';
        else{
            if(ans.size()!=0){
                ans.pop_back();
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);
	int c, i, j;
	c = B - A;
	if (2*K > c)
		for (i = A; i <= B; i++)
			printf("%d\n", i);
	else
	{
		for (i = A; i <A + K; i++)
			printf("%d\n", i);
		for (j = B - K + 1; j <= B ; j++)
			printf("%d\n", j);
	}
	return 0;
}

Measured memory_bytes: 128
s1 = input()
s2 = input()
dict = dict([])
s1_num = []
s2_num = []
for s in s1:
    if not s in dict:
        dict[s] = len(dict)
    s1_num.append(dict[s])
for s in s2:
    if not s in dict:
        dict[s] = len(dict)
    s2_num.append(dict[s])

s1_len = len(s1_num)
s2_len = len(s2_num)

lst = [[0] * (s2_len + 1) for _ in range(s1_len + 1)]
lst[0] = [i for i in range(s2_len + 1)]
for x in range(s1_len + 1):
    lst[x][0] = x

for i in range(1, s1_len + 1):
    for j in range(1, s2_len + 1):
        if s1_num[i - 1] == s2_num[j - 1]:
            lst[i][j] = min((lst[i - 1][j - 1]), (lst[i - 1][j] + 1), (lst[i][j - 1] + 1))
        else:
            lst[i][j] = min((lst[i - 1][j - 1] + 1), (lst[i - 1][j] + 1), (lst[i][j - 1] + 1))
print(lst[s1_len][s2_len])



Measured memory_bytes: 41888
#include "cstdio"
#include "string"
#include "iostream"
using namespace std;
string s;
int main(){
	cin>>s;
	int x=s.size();
	if(x==1){
		cout<<s;return 0;
	}
	long long ss=(x-1)*9;
	ss+=s[0]-'0';ss--;
	for(int i=1;i<x;i++)if(s[i]!='9'){
	printf("%lld\n",ss);return 0;
	}
	printf("%lld\n",ss+1);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    uint64_t n = 0;
    cin >> n;

    vector<uint64_t> traffic;
    for(int i = 0 ; i < 6 ; i++){
        uint64_t t;
        cin >> t;
        traffic.push_back(t);
    }

    uint64_t jam = *min_element(traffic.begin(), traffic.end());
//    uint64_t jam = *min_element(traffic.begin(), traffic.end(), [](uint64_t a, uint64_t b){
//        cout << a << ":" << b << endl;
//        return a < b;
//    });

    uint64_t arrival = (n + jam - 1) / jam + 4;

    cout << arrival;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> l(N);
    for (int i = 0; i < N; i++) cin >> l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            auto it = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            it--;
            int d = distance(l.begin(), it);
            ans += d - j;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

void printArray(int *a, int n) {
    for (int i = 0; i < n; ++i) {
        printf("%d", a[i]);
        if (i != n - 1) printf(" ");
    }
    printf("\n");
}

void insertionSort(int *a, int n) {
    for (int i = 1; i < n; ++i) {
        printArray(a, n);
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            --j;
        }
        a[j + 1] = v;
    }
}

int main(void){
    int n;
    int a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    
    insertionSort(a, n);
    
    printArray(a, n);
}



Measured memory_bytes: 2044
inf = 10**9
N = int(raw_input())
p = [int(raw_input()) for i in xrange(N)]
to = [i for i in xrange(N)]
for i in xrange(N):
        if to[i] != i: continue
        seq = set([])
        while 1:
            if to[i] != i:
                for j in seq: to[j] = to[i]
                break
            elif i in seq:
                for j in seq: to[j] = -1
                break
            elif p[i] == 0:
                for j in seq: to[j] = i
                break
            else:
                seq.add(i)
                i += p[i]

visited = [False]*N
visited[0] = True
que = [[0,0]]
while 1:
    cur,step = que.pop(0)
    if cur == N-1:
        print step
        break
    for nxt in range(cur+1,min(N,cur+7)):
        if to[nxt] > 0 and not visited[to[nxt]]:
            visited[to[nxt]] = True
            que.append([to[nxt], step+1])

Measured memory_bytes: 12112
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n;
double a[55];
double sum;
int main()
{
	fast;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	sum=(a[1]+a[2])/2;
	for (int i=3;i<=n;i++)
	{
		sum=(sum+a[i])/2;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main () {
	cin.tie(0);
	cin.sync_with_stdio(0);

	int n;
	cin >> n;
	multiset<int> ms;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		ms.emplace(x);
	}
	for(int i = 0; i < n; ++i) {
		int d = abs( (i) - (n-(i+1)) );
		auto f = ms.find(d);
		if(f == ms.end())
			return cout << 0, 0;
		ms.erase(f);
	}
	int ans = 1;
	int const M = 1'000'000'007;
	int m = n / 2;
	while(m--) ans = (ans + ans) % M;
	cout << ans << flush;
}

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

int main() {
    int n;
    string s;
    cin >> n ;
    for(int i = 0; i < n; i++) {
        cin >> s;
        if(s == "Y") {
            cout << "Four" <<endl;
            exit(0);
        }
    }
    cout << "Three" <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 100100;
int n, a[N];
char s[N];

bool check(int x) {
	int pre = (x - 1 + n) % n, nxt = (x + 1) % n;
	int t = s[x] == 'o' ? 0 : 1;
	return (a[pre] ^ a[x] ^ a[nxt]) == t;
}

int main() {
	scanf("%d",&n);
	scanf("%s",s);
	for(a[0] = 0;a[0] <= 1; a[0]++) for(a[1] = 0;a[1] <= 1; a[1]++) {
		rep(j,2,n - 1) {
			if (s[j - 1] == 'o') a[j] = 0; else a[j] = 1;
			a[j] ^= a[j - 1] ^ a[j - 2];
		}
		if (check(0) && check(n - 1)) {
			Rep(i,n) if (!a[i]) putchar('S'); else putchar('W');
			putchar('\n');
			return 0;
		}
	}
	printf("-1\n"); return 0;
}


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

int main() {
  int N, T;
  cin >> N >> T;
  vector<vector<int>> v(N, vector<int>(2));
  for (int i = 0; i < N; i++) cin >> v[i][0] >> v[i][1];

  int ans = 1001;
  for (int i = 0; i < N; i++)
    if (v[i][1] <= T) ans = min(v[i][0], ans);

  if (ans == 1001) cout << "TLE" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;

int main() {
  int N; cin >> N;
  vector<vector<int>> vec(2, vector<int>(N));
  rep(i,2){
    rep(j,N){
      cin >> vec.at(i).at(j);
    }
  }
  
  int ans=0;
  rep(i,N){
    int ssum = 0;
    rep(j,i+1){
      ssum += vec.at(0).at(j); 
    }
    for (int j=i; j<N; j++){
      ssum += vec.at(1).at(j); 
    }
    ans = max(ans, ssum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
## coding: UTF-8
#N, M, K = 9, 3, 4
N, M, K = map(int,input().split())
p = 998244353


# 返り値: a と b の最大公約数
# 返り値: ax + by = gcd(a, b) を満たす (x, y) が格納される
def aug_gcd(a, b):
    lq = []
    while b > 0:
        q = int(a/b)
        r = a % b
        a = b
        b = r
        lq.append(q)
    x = 1
    y = 0
    for i in range(len(lq)):
        tmp = x
        x = y
        y = tmp - lq[(-1)*(i+1)] * y
    return a, x, y

#拡張ユークリッドの互除法による逆元計算
#拡張ユークリッドの方が二分累乗法より高速/mが素数でなくとも良い
def modinv(a, p):
    inv = aug_gcd(a, p)[1] #ax == 1(mod p) <==> ax + py == 0, xの値が逆元
    if(inv < 0):
        inv += p #pがマイナスだったらプラスに書き換える
    return inv


#[NC0, NC1, NC2, NC3, ..., NCN % p]
def N_Combination_k(N, p):
    #NCkのリストを作ります
    l = [1]
    res = 1
    for i in range(1, N+1):
        res *= (N+1-i)
        res %= p
        res *= modinv(i, p)
        res %= p
        l.append(res)
    return l


combination_N_1 = N_Combination_k(N-1, p)
#print(combination_N_1)
Cumulative = [0] #累積和
s = 0
tod = 1 #(M-1) ** (N-1-i)
for i in range(N):
    s += M * tod * combination_N_1[(-1)*(i+1)]
    s %= p
    tod *= (M-1)
    tod %= p
    Cumulative.append(s)
    #print(s)
#print(Cumulative)

ans = Cumulative[-1] - Cumulative[(-1)*(K+2)]
if(ans < 0):
    ans += p
print(ans)

Measured memory_bytes: 101400
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    std::vector<int> a(3);
    a[0] = P;
    a[1] = Q;
    a[2] = R;

    sort(ALL(a));

    cout << a[0] + a[1] << endl;


    return 0;
}


Measured memory_bytes: 384