akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;
static const signed int SMOD = 1000000007;

template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}

int n;

vector<int>  edge[100100];

int dp[100100][5];

void dfs(int u, int pr) {
	dp[u][0] = dp[u][1] = 1LL;
	for(int i = 0; i < edge[u].size(); i++) {
		int v = edge[u][i];
		if(v == pr) continue;
		dfs(v, u);
		dp[u][0] = dp[u][0] * (dp[v][0]+dp[v][1]) % SMOD;
		dp[u][1] = dp[u][1] * dp[v][0] % SMOD;
	}
}

signed main() {

	cin >> n;

	for(int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		edge[a].bash(b);
		edge[b].bash(a);
	}

		
	dfs(1, -1);

	cout << (dp[1][0] + dp[1][1]) % SMOD << endl;



    return 0;
}



Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int N = read(), M = read(), X = read(), Y = read();
    vector<int> VX(N), VY(M);
    for (auto& v:VX) v = read();
    for (auto& v:VY) v = read();
    printf((max(*max_element(VX.begin(), VX.end()), X) < min(*min_element(VY.begin(), VY.end()), Y))?"No War\n":"War\n");
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
  "strconv"
  "strings"
  "bufio"
  "os"
  )
  
func lower_bound(ary []int, n int) int {
  size := len(ary)
  if ary[size-1] < n { return size }
  u := size
  l := 0
  for u>l {
    s := (u+l)/2
    if (ary[s] < n) { l = s+1 } else { u = s }
  }
  return l
}

func upper_bound(ary []int, n int) int {
  size := len(ary)
  if ary[size-1] <= n { return size }
  u := size
  l := 0
  for u>l {
    s := (u+l)/2
    if (ary[s] <= n) { l = s+1 } else { u = s }
  }
  return l
}

func s2i(s string) []int {
  ss := strings.Fields(s)
  tmp := make([]int, len(ss))
  for i, v := range ss {
    tmp[i], _ = strconv.Atoi(v)
  }
  return tmp
}

func readline() string {
  buff := make([]byte, 0)
  for {
    ln, isP, _ := rd.ReadLine()
    buff = append(buff, ln...)
    if !isP { break }
  }
  return string(buff)
}

//var sc = bufio.NewScanner(os.Stdin)
var rd = bufio.NewReader(os.Stdin)

func main() {
  n := 0
  fmt.Scan(&n)
  //
  a := s2i(readline())
  b := s2i(readline())
  c := s2i(readline())
  
  sort.Ints(a)
  sort.Ints(c)
  
  sum := 0
  for _, v := range b {
    sml := lower_bound(a, v)
    big := upper_bound(c, v)
    sum += sml * (n-big)
  } 
  
  fmt.Println(sum)
}

Measured memory_bytes: 9344
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]C = new int[M];
		for(var i=0;i<N;i++){
			string[] str2 = Console.ReadLine().Split();
			int K = int.Parse(str2[0]);
			for(var j=0;j<K;j++){
				int A = int.Parse(str2[1+j]);
				C[A-1]++;
			}
		}
		int ans = 0;
		for(var i=0;i<M;i++){
			if(C[i]==N){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

a,b,c,d,e,f = map(int, readline().split())


ok = [0]*3001
for i in range(0,3001,c):
    ok[i] = 1

for i in range(3001):
    if ok[i] and i+d <= 3000:
        ok[i+d] = 1

#print(ok[:30])

ans = (0.0,100*a,0)

for x in range(31):
    for y in range(31):
        p = x*100*a + y*100*b
        if p==0: continue
        if p > f: break
        for q in range(min(f-p,e*p//100),-1,-1):
            if ok[q]:
                v = q/(p+q)
                if v > ans[0]:
                    ans = (v,p+q,q)
                break
        
print(*ans[1:])




Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define MOD (int)(1E9 + 7)
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    int res = 0;
    for (int i = k; i <= n + 1; i++)
        res = (res + ((i * (2 * n - i + 1) / 2) - (i * (i - 1) / 2) + 1)) % MOD;
    cout << res << endl;
    GAME_OVER;
}

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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); ++i) {
		if (i == A) {
			if ('-' != S[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			int num = S[i] - '0';
			if ((num < 0) || (num > 9)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
"""
D - Patisserie ABC
https://abc100.contest.atcoder.jp/tasks/abc100_d

"""
import sys
from sys import stdin
input = stdin.readline


from heapq import heappop, heappush


def solve(cakes, M):
    result = []
    for xx in [1, -1]:
        for yy in [1, -1]:
            for zz in [1, -1]:
                hq = []
                for x, y, z in cakes:
                    x *= xx
                    y *= yy
                    z *= zz
                    heappush(hq, -(x+y+z))
                ans = 0
                for _ in range(M):
                    ans += heappop(hq)
                result.append(-ans)
    return sorted(result)[-1]


def main(args):
    N, M = map(int, input().split())

    cakes = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        cakes.append((x, y, z))
    ans = solve(cakes, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3444
io = STDIN
n=io.gets.to_i
P=io.gets.split.map(&:to_i)
cnt=0
rm=[]
min=P[0]
n.times do |i|
  min=[min,P[i]].min
  rm[i]=min
end
n.times do |i|
  cnt += 1 if P[i] <=rm[i]
end
p cnt


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  long long prefix[n];
  prefix[0] = a[0];
  for(int i=1; i<n; i++) prefix[i] = a[i] + prefix[i-1];
  long long ans = 1e15;
  for(int i = 0; i<n-1; i++) ans = min(abs(prefix[i] - (prefix[n-1] - prefix[i])), ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define chmax(x,y) x = max(x,y)
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string s, t;
ll ans = 10000;

int main() {
	cin >> s;
	cin >> t;
	rep(i, sz(s) - sz(t) + 1) {
		ll cnt = 0;
		rep(j, sz(t)) {
			if (s[i + j] != t[j])cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,n;
    cin>>a>>b>>n;
    int x=a; 
    if(n >= b){
        long long int m=(a*(b-1))/b - (a*((b-1)/b));
         cout<<m<<endl;
    }
    else{
          long long int m=(a*(n))/b - (a*((n)/b));
         cout<<m<<endl;  
    }
return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数s 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

bool chk(string &s, ll a,ll b){
    fr(i,a - 1, b - 1){
        auto j = i +1;
        if(s[i] == '#' && s[j]== '#') {
            return false;
        }
    }
    return true;
}

int main() {
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string s;
    cin>>s;
    bool fl;
    if(d<c){
        fl = chk(s,a,c);
        bool h = false;
        fr(i,b - 1, d){
            if(s[i-1] == '.' && s[i] == '.'&& s[i+1] == '.') h = true;
        }
        fl = fl && h;
    } else if(b<c) {
        fl = chk(s, a,d);
    } else {
        fl = (chk(s, a,c) && chk(s,b,d) );
    }
    if(fl) pr("Yes");
    else pr("No");
    
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstring>

using namespace std;

const int MOD = 1e9 + 7;
int N;
char *M;

void init(int n = 8) {
    M = new char[(n + 7) / 8];
    memset(M, 0, (n + 7) / 8);
}

void set(int n) {
    M[n >> 3] |= (0x80 >> (n & 0x07));
}

bool test(int n) {
    return M[n >> 3] & (0x80 >> (n & 0x07));
}

void prime_set(int n) {
    set(0); set(1);
    for (int i = 2; i < n; i++)
        if( !test(i) )
            for (int j = i * i; j <= n; j += i)
                set(j);
}

int main() {
    cin >> N;
    long long ans = 1;
    init(N);
    prime_set(N);
    for (int i = 2; i <= N; i++) {
        if(!test(i)) { // 1到N的所有质数
            long long res = 0;
            for (int temp = i; temp <= N; temp *= i)
                res += N / temp;
            ans *= (res + 1) % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using ll=long long;
using namespace std;
const long MOD=1e9+7;
template<class T>
T lcm(T a,T b){
    return a/__gcd(a,b)*b;
}

int main(){
    string s;
    cin >> s;
    string t="";

    for(int i=0;i<s.size();i++){
        if(s[i]=='0' || s[i]=='1'){
            t.push_back(s[i]);
        }else{
            if(t!=""){
                t.pop_back();
            }
        }
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
ss = list()
for n in range(len(S)-len(T)+1):
    for m in range(len(T)):
        if S[n+m] not in ["?", T[m]]:
            break
    else:
        ss.append((S[:n]+T+S[n+len(T):]).replace("?","a"))
if len(ss) == 0:
    print("UNRESTORABLE")
else:
    print(min(ss))



Measured memory_bytes: 3060
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Maybe

lowerBound :: VU.Vector Int -> (Int, Int) -> Int -> Int
lowerBound vec (from, to) target
    | from == to = from
    | mValue >= target = lowerBound vec (from, mid) target
    | mValue < target = lowerBound vec (mid + 1, to) target
        where
            mid = (from + to) `quot` 2
            mValue = vec VU.! mid

upperBound :: VU.Vector Int -> (Int, Int) -> Int -> Int
upperBound vec (from, to) target
    | from == to = from
    | mValue > target = upperBound vec (from, mid) target
    | mValue <= target = upperBound vec (mid + 1, to) target
        where
            mid = (from + to) `quot` 2
            mValue = vec VU.! mid

solve :: VU.Vector Int -> VU.Vector Int -> VU.Vector Int -> Int
solve as bs cs
    | VU.null bs = 0 
    | otherwise = res + solve as (VU.tail bs) cs
        where
            res = lowa * (lc - uppc)
            b = VU.head bs
            lc = VU.length cs
            lowa = lowerBound as (0, VU.length as) b
            uppc = upperBound cs (0, VU.length cs) b

main = do
    n <- readLn :: IO Int
    as <- VU.fromList . sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    bs <- VU.fromList . sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    cs <- VU.fromList . sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    
    print $ solve as bs cs

Measured memory_bytes: 23932
#include<stdio.h>
void quicksort(int a[],int s,int t){
  if(s<t){
    int i=s,j=t,p=a[(s+t)/2];
    while(1){
      while(a[i]<p)i++;
      while(p<a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  int n,a[100001],i,x=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  quicksort(a,0,n-1);
  a[n]=-1;
  for(i=0;i<n;i++){if(a[i]==a[i+1]){x--;i++;}x++;}
  printf("%d",x);
}


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

using namespace std;

const int MAX = 1e6+5;
const int mod = 1e9+7;
long long int fact[MAX+1];
long long int inv_fact[MAX+1];
long long int inv[MAX+1];

long long int pow(long long int x, long long int n) {
    long long int ret = 1ll;
    while(n > 0) {
        if(n&1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

void init() {
    fact[0] = 1;
    inv_fact[0] = inv_fact[1] = 1;
    inv[1] = 1;
    for(int i=1;i<MAX;i++)
        fact[i] = (i % mod * fact[i-1] % mod) % mod;

    for(int i=2;i<MAX;i++) {
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        inv_fact[i] = inv_fact[i-1] * inv[i] % mod;
    }
}

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

int main() {
    int X,Y; cin >> X >> Y;

    if(2*X-Y < 0 || 2*Y-X < 0 || (2*X-Y)%3 != 0 || (2*Y-X)%3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int a = (2*Y-X)/3;
    int b = (2*X-Y)/3;
    init();

    cout << comb(a+b, b) << endl;


    return 0;
}


Measured memory_bytes: 23808
N = int(input())
SP = []
for i in range(N):
    S, P = map(str, input().split())
    SP.append([S, int(P), i+1])

SP.sort(key = lambda x:x[1], reverse=True)
SP.sort(key = lambda x:x[0])

for e in SP:
    print(e[2])

Measured memory_bytes: 3060
function RGBTriplets()
    N = parse(Int, readline())
    S = readline()
    r, g, b = 0, 0, 0
    for s in S
        if s =='R'
            r+=1
        elseif s == 'G'
            g+=1
        else
            b+=1
        end
    end
    counter = 0
    for i in 1:N-1
        for j in i+1:N
            k = 2j - i
            k > N && break
            (S[i] ≠ S[j]) && (S[j] ≠ S[k]) && (S[k] ≠ S[i]) && (counter += 1)
        end
    end
    return println(r*g*b - counter)
end
RGBTriplets()

Measured memory_bytes: 160796
#include <bits/stdc++.h>
using namespace std;
int n,m;
string g[15];
bool ok[15][15],dp[1<<15];
int main(){
	random_device random;
	mt19937 seed(random());
	cin>>n>>m;
	for(int i=0;i<n;++i){
		cin>>g[i];
	}
	for(int times=0;times<100000;++times){
		memset(ok,1,sizeof(ok));
		memset(dp,0,sizeof(dp));
		for(int i=0;i<m;++i){
			for(int j=i;j<m;++j){
				for(int k=0;k<n;++k){
					if(g[k][i]!=g[n-1-k][j]){
						ok[i][j]=0;
					}
				}
			}
		}
		dp[0]=1;
		for(int mask=0;mask<(1<<m);++mask){
			if(dp[mask]){
				for(int i=0;i<m;++i){
					for(int j=i+1;j<m;++j){
						if(!(mask>>i & 1)&&!(mask>>j & 1)&&ok[i][j]){
							dp[mask | (1<<i) | (1<<j)]=1;
						}
					}
				}
			}
		} 
		bool success=0;
		if(m%2==0){
			success=dp[(1<<m)-1];
		}
		else{
			for(int i=0;i<m;++i){
				if(dp[(1<<m)-1-(1<<i)]&&ok[i][i]){
					success=1;
				}
			}
		}
		if(success){
			cout<<"YES\n";
			return 0;
		}
		shuffle(g,g+n,seed);
	}
	cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int x, n, a;
    cin>>x>>n;
    bool p[102]={0};
    while(n--) {
        cin>>a;
        p[a]=1;
    }
    int mn=102, ii=-1;
    for(int i=-1; i<102; i++) {
        if(i>0 && p[i]) continue;
        if(abs(x-i)<mn) {
            mn=abs(x-i);
            ii=i;
        }
    }
    cout<<ii<<"\n";
    return 0;
}

Measured memory_bytes: 3636
#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()
typedef long long ll;
const int INF (1<<30);

int main() {
  int N;
  cin >> N;
  vector<int> A(N,0);

  rep(i, N-1) {
    int idx;
    cin >> idx;
    idx--;
    A[idx]++;
  }

  rep(i, N) cout << A[i] << endl;

  return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using lint128 = __int128_t;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
inline void YES(bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
inline void assert_NO(bool condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
inline void assert_No(bool condition){ if(!condition){ cout << "No" << endl; exit(0); } }
inline void assert_minus_1(bool condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
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; }
inline int at(lint x, int k){ return (x >> k) & 1; }
random_device rnd;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int K, N;
    cin >> K >> N;
    int A[N + 1];
    cins(A, A + N);
    A[N] = K + A[0];
    int ans = 0;
    rep(i, N){
        ans = max(ans, A[i + 1] - A[i]);
    }
    cout << K - ans << endl;
}


Measured memory_bytes: 1024
s = input()

dream = 'dream'
erase = 'erase'
dreamer = 'dreamer'
eraser = 'eraser'
ans = 'YES'
n = len(s)
while n > 0:
  if s[n-5:n] == dream:
    n += -5
  elif s[n-5:n] == erase:
    n += -5
  elif s[n-6:n] == eraser:
    n += -6
  elif s[n-7:n] == dreamer:
    n += -7
  else:
    ans = 'NO'
    break
print(ans)
  

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string S;
    cin >> S;

    for (char i = 'a'; i <= 'z'; i++) {
        bool f = false;
        REP(j, S.length()) {
            if (S[j] == i) {
                f = true;
                break;
            }
        }
        if (!f) {
            cout << i << endl;

            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    t: usize,
    ct: [(usize, usize); n]
    }
    let mut ans = 100000000;
    for i in 0..n{
        if ct[i].1 <= t {
            ans = min(ans, ct[i].0)
        }
    }
    if ans == 100000000 {
        println!("TLE")
    } else{
        println!("{}", ans);
    }
}


Measured memory_bytes: 2172
// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}

	for(int k = 0; k < m; k++){
		for(int i = 0; i < m; i++){
			for(int j = 0; j < m; j++){
				if(C[i][j] > C[i][k] + C[k][j]){
					C[i][j] = C[i][k] + C[k][j];
				}
				if(T[i][j] > T[i][k] + T[k][j]){
					T[i][j] = T[i][k] + T[k][j];
				}
			}
		}
	}
	
	int k = 0; 
	cin >> k;
	for(int i = 0; i < k; i++){
		int start, goal, r;
		cin >> start >> goal >> r;
		if(r == 0){
			cout << C[start - 1][goal - 1] << endl;
		}else{
			cout << T[start - 1][goal - 1] << endl;
		}
	}
	}

	return 0;
}

Measured memory_bytes: 3068
def Zalgorithm(s):
    z = [0 for _ in range(len(s))]
    z[0] = len(s)
    i, j = 1, 0
    while i < len(s):
        while i+j < len(s) and s[j] == s[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < len(s) and k+z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
    return z

n = int(input())
s = input().strip()
ans = 0
for i in range(len(s)):
    zarr = Zalgorithm(s[i:])
    for j in range(len(zarr)):
        ans = max(ans, min(j, zarr[j]))
print(ans)


Measured memory_bytes: 56924
#include<stdio.h>
#include<stdlib.h>
 
struct node{
 struct node *right;
 struct node *left;
 struct node *parent;
 int key;
 };
 
typedef struct node * Node;
Node root;

void insert(int k){
 
   Node y=NULL;
   Node x=root;
   Node z;
  
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NULL;
  z->right=NULL;
  
  while(x!=NULL){
    y=x;
    if(z->key<x->key){
    x=x->left;
    }
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
   root=z;
  }
  else if(z->key<y->key){
   y->left=z;
  }
  else y->right=z;
}
  
void inorder(Node u){
 
  if(u->left !=NULL){
   inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NULL){
   inorder(u->right);
  }
 
}
  
void preorder(Node u){
 
  printf(" %d",u->key);
  if(u->left !=NULL){
   preorder(u->left);
  }
  if(u->right !=NULL){
   preorder(u->right);
  }
}
  
int main(){
 
   int m,n,i;
   char order[10];
  scanf("%d",&m);
  root=NULL;
  
  for (i=0;i<m;i++){
    scanf("%s",order);
    if(order[0]=='i'){
      scanf("%d",&n);
      insert(n);
    } 
    else if (order[0]=='p'){
     inorder(root);
     printf("\n");
     preorder(root);
     printf("\n");
    }
  }
  return 0;
}   

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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int a = 1; a * a <= n; ++a) {
    for (int b = a; b <= n; ++b) {
      int c = n - a * b;
      if (c < 1) {
        continue;
      }
      if (a * b + c == n) {
        if (a == b) {
          ++ans;
        } else {
          ans += 2;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
import java.lang.*;

 class Main{

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer stk = new StringTokenizer("");

    public static void main(String args[]){
        try{
            int N = Integer.parseInt(bf.readLine());
            stk = new StringTokenizer(bf.readLine());
            int arr[] = new int[N];
            for(int i=0;i<N;i++){
                arr[i] = Integer.parseInt(stk.nextToken());
            }

            System.out.println(solver(arr,N));
            bf.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static int solver(int[] arr,int N){
        if(N <= 1)
            return 0;

        int dp[]  = new int[N];
        dp[0] = 0;

        for(int i=1;i<N;i++){
            dp[i] = Math.min(dp[i-1] + Math.abs(arr[i] - arr[i-1]) , ( (i-2 >= 0) ? (dp[i-2] + Math.abs(arr[i] - arr[i-2])) : Integer.MAX_VALUE) );
        }
        return dp[N-1];
    }
}

Measured memory_bytes: 34152
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;



void solve(){

   
    int n;
    cin>>n;

    vec arr(n);

    rep(i,n) {
        cin>>arr[i];
    }

    int64_t ans = 0;

    int min = arr[0];

    for(int i=1; i<n; i++) {
        if(arr[i] < min) {
            ans+= abs(arr[i] - min);
        } else {
            min = max(min, arr[i]);
        }
    }

    cout<<ans<<endl;


    

    


}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

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

int main()
{
    int n, k;
    std::cin >> n >> k;
    std::string s;
    std::cin >> s;

    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) {
            ans++;
        }
    }

    ans = std::min((long long)n - 1, ans + k * 2);

    std::cout << ans << std::endl;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    int mx = a[n-1];
    int ans;
    double d = mx;
    rep(i,n){
        if(d > abs(a[i]-mx/2.0)){
            d = abs(a[i]-mx/2.0);
            ans = a[i];
        }
    }
    cout << mx << " " << ans << endl;
}

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

int n, a, b, sum;

bool chk(int x){
int s=0;
while(x>0){
    s+=x%10;
    x/=10;
}
if(s>=a&&s<=b)return true;
else return false;
}

int main(){
cin >> n >> a >> b;
for(int i=1; i<=n; i++){
    if(chk(i))sum+=i;
}
cout << sum << endl;

return 0;}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class DRedistribution {
    int n;
    vector<ll> dp;

    int Ways(int target) {
        if (dp[target] != -1) return dp[target];

        ll ways = 0;
        for (int i = 3; i < target - 2; i++) {
            ways += Ways(target - i) % MOD;
        }
        return dp[target] = (ways + 1) % MOD;
    }

public:
    void solve(std::istream &in, std::ostream &out) {
        in >> n;
        if (n < 3) {
            out << 0 << endl;
            return;
        }
        dp.resize(n + 1, -1);
        dp[0] = 1;
        out << Ways(n) << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    DRedistribution solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

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

using namespace std;
using lint=long long;

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

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> a(n),b(n),c(n),d(m),e(m),f(m);
	rep(i,n) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	rep(j,m) scanf("%d%d%d",&d[j],&e[j],&f[j]);

	vector<int> X={0},Y={0};
	rep(i,n){
		X.emplace_back(2*c[i]-2);
		X.emplace_back(2*c[i]-1);
		X.emplace_back(2*c[i]);
		Y.emplace_back(2*a[i]-2);
		Y.emplace_back(2*a[i]);
		Y.emplace_back(2*b[i]-2);
		Y.emplace_back(2*b[i]);
	}
	rep(j,m){
		Y.emplace_back(2*d[j]-2);
		Y.emplace_back(2*d[j]-1);
		Y.emplace_back(2*d[j]);
		X.emplace_back(2*e[j]-2);
		X.emplace_back(2*e[j]);
		X.emplace_back(2*f[j]-2);
		X.emplace_back(2*f[j]);
	}

	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());

	int sx=lower_bound(X.begin(),X.end(),0)-X.begin();
	int sy=lower_bound(Y.begin(),Y.end(),0)-Y.begin();

	int h=Y.size(),w=X.size();
	vector<vector<int>> B(h,vector<int>(w)); // 0: not visited, 1: visited, 2: wall
	B[sy][sx]=1;

	rep(i,n){
		int y0=lower_bound(Y.begin(),Y.end(),2*a[i])-Y.begin();
		int y1=lower_bound(Y.begin(),Y.end(),2*b[i])-Y.begin();
		int x =lower_bound(X.begin(),X.end(),2*c[i]-1)-X.begin();
		for(int y=y0;y<y1;y++) B[y][x]=2;
	}
	rep(j,m){
		int x0=lower_bound(X.begin(),X.end(),2*e[j])-X.begin();
		int x1=lower_bound(X.begin(),X.end(),2*f[j])-X.begin();
		int y =lower_bound(Y.begin(),Y.end(),2*d[j]-1)-Y.begin();
		for(int x=x0;x<x1;x++) B[y][x]=2;
	}

	queue<pair<int,int>> Q;
	Q.emplace(sy,sx);
	while(!Q.empty()){
		int y,x; tie(y,x)=Q.front(); Q.pop();
		rep(k,4){
			int y2=y+dy[k],x2=x+dx[k];
			if(0<=y2 && y2<h && 0<=x2 && x2<w && B[y2][x2]==0){
				B[y2][x2]=1;
				Q.emplace(y2,x2);
			}
		}
	}

	if(B[0][0]==1) return puts("INF"),0;

	lint ans=0;
	rep(i,h) rep(j,w) if(B[i][j]==1) {
		assert(i<h-1 && j<w-1);
		lint y0=Y[i],y1=Y[i+1];
		lint x0=X[j],x1=X[j+1];
		if(y0%2!=0 || x0%2!=0) continue;
		if(y1%2!=0) y1++;
		if(x1%2!=0) x1++;
		ans+=(y1-y0)*(x1-x0)/4;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 195196
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  _int64 i,j,a,b,tmp,ans,tmp1,cap,l1,r1;
  scanf("%lld%lld",&a,&b);
  ans=0;
  cap=(1LL<<62);
  for (i=60;i>=0;i--)
  {
    tmp=(1LL<<i);
    if ((a-1)/tmp<b/tmp)
    {
      tmp1=(b/tmp)*tmp;
      //cout<<a<<" "<<b<<" "<<tmp<<" "<<tmp1<<" "<<ans<<endl;
      if (b-a+1>=tmp)
      {
        ans+=tmp;
        ans+=tmp1-a;
        if (cap<tmp1+tmp)
        {
          ans-=tmp1+tmp-cap;
        }
        break;
      }
      else
      {
        ans+=(tmp1-a+1);
        if (tmp1-a>0)
        {
          l1=(a|tmp1);
          r1=tmp1+tmp-1;
          if (cap-1<r1) r1=cap-1;
          if (r1-l1+1>0)
            ans+=r1-l1+1;
        }
        cap=l1;
        a=tmp1+1;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, h[100010];
signed main() {
	cin >> n;
	int ans = 0, cnt = 0;
	rep(i, n) {
		cin >> h[i];
		if (i) {
			if (h[i - 1] >= h[i])cnt++;
			else {
				ans = max(ans, cnt);
				cnt = 0;
			}
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll ans = 1000;
    ll pre = a.at(0);
    ll now = a.at(0);
    bool flag = true;
    for(i = 1;i < n;++i){
        if(flag){
            if(a.at(i) >= now) now = a.at(i);
            else{
                ll kabu = ans/pre;
                ans -= kabu*pre;
                ans += kabu*now;
                now = a.at(i);
                flag = false;
            }
        }else{
            if(a.at(i) <= now) now = a.at(i);
            else{
                pre = now;
                now = a.at(i);
                flag = true;
            }
        }
    }
    if(flag && now > pre){
        ll kabu = ans/pre;
        ans -= kabu*pre;
        ans += kabu*now;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
X = int(input())
dp = [0 for i in range(X+1)]
if X <100:
    print(0)
elif X <= 105:
    print(1)
else:
    for i in range(100,106):
        dp[i] =1
    for i in range(100,X+1):
        if dp[i-100] == 1 or dp[i-101] == 1 or dp[i-102] == 1 or dp[i-103] == 1 or dp[i-104] == 1 or dp[i-105] == 1:
            dp[i] = 1
    print(dp[-1])

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

typedef long long  LL;
const int N=100010;
struct node{int l,r,id;}a[N],b[N];
int n,vis[N];
LL ans;

bool cmpl(node x,node y){return x.l>y.l;}
bool cmpr(node x,node y){return x.r<y.r;}

int move(node x,int &pos)
{
	int ret;
	if (pos<x.l)  ret=x.l-pos,pos=x.l;
	else  if (pos>x.r)  ret=pos-x.r,pos=x.r;
	else  ret=0;
	return ret;
}

LL solve()
{
	LL s=0;  int pos=0;
	for (int i=1; i<=n; i++)  b[i]=a[i],vis[i]=0;
	sort(a+1,a+n+1,cmpl),sort(b+1,b+n+1,cmpr);
	for (int i=1,j=1; i<=n&&j<=n; )
		{
			while ((i<=n)&&(vis[a[i].id]))  i++;
			if (i<=n)  s+=move(a[i],pos),vis[a[i].id]=1,i++;
			while ((j<=n)&&(vis[b[j].id]))  j++;
			if (j<=n)  s+=move(b[j],pos),vis[b[j].id]=1,j++;
		}
	return s+abs(pos);
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)  scanf("%d %d",&a[i].l,&a[i].r),a[i].id=i;
	ans=solve();
	for (int i=1; i<=n; i++)  a[i].l*=-1,a[i].r*=-1,swap(a[i].l,a[i].r);
	ans=max(ans,solve());
	printf("%lld",ans);
}

int main()
{
	work();
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using mint = modint998244353;
const mint inv9 = mint(1)/9;

struct S {
    mint x, w;
    S(mint x = 0, mint w = 1): x(x), w(w){}
};

S op(S a, S b){ return S(a.x * b.w + b.x, a.w * b.w); }

S e() { return S(); }

S mapping(int f, S a){
    if(f == 0) return a;
    return S((a.w - 1) * inv9 * f, a.w);
}

int composition(int f, int g){
    if(f == 0) return g;
    return f;
}

int id(){ return 0; }

void Main(){
    int n, q; cin >> n >> q;
    lazy_segtree<S, op, e, int, mapping, composition, id> t(n);
    rep(i, n) t.set(i, S(1,10));
    while(q--){
        int l, r, d; cin >> l >> r >> d;
        l--;
        t.apply(l,r,d);
        S ans = t.all_prod();
        printf("%d\n", ans.x.val());
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	double x[4],y[4],d[3];
	for(int i = 0;i < 3;i++) cin >> x[i] >> y[i];
	x[3] = x[0],y[3] = y[0];
	double ma = 0,sum = 0;
	for(int i = 0;i < 3;i++){
		d[i] = sqrt((x[i] - x[i + 1]) * (x[i] - x[i + 1]) + (y[i] - y[i + 1]) * (y[i] - y[i + 1]));
		chmax(ma,d[i]);
		sum += d[i] / 2;
	}
	double s = sqrt(sum * (sum - d[0]) * (sum - d[1]) * (sum - d[2]));
	double ans = s / (sum + 2 * s / ma);
	printf("%.12lf\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,t;
    ll len1,len2,ans,minim=1e15;
    cin>>s;
    cin>>t;
    len1=s.length();
    len2=t.length();
    for(int i=0;i<=len1-len2;i++)
    {
        ans=0;
        for(int j=0;j<len2;j++)
        {
            if(s[i+j]!=t[j])
            {
                ans++;
            }
        }
        minim=min(minim,ans);

    }
    cout<<minim<<'\n';
}

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

int main() {
  vector<int>vec;
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << vec.at(k-1) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> K(M);
    REP(i, 0, M) {
        int k; cin >> k;
        REP(j, 0, k) {
            int s; cin >> s;
            K[i].push_back(--s);
        }
    }

    vector<int> P(M);
    REP(i, 0, M) cin >> P[i];

    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool ok = true;
        REP(i, 0, M) {
            int count = 0;
            for (auto s : K[i]) {
                if (bit & (1 << s)) count++;
            }
            if (count % 2 != P[i]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

Int n;
Int a[212345];
Int dp[2][212345];

int main(){
	cin >> n;
	RC(i, n){
		cin >> a[i];
	}

	if(n % 2 == 0){
		dp[0][n - 1] = 0;
		dp[1][n - 1] = a[n - 1];
		RCH(i, n - 1){
			if(i % 2 == 0){
				dp[0][i] = ant(dp[0][i + 2] + a[i], dp[1][i + 1]);
			}else{
				dp[0][i] = ant(dp[0][i + 2] + a[i], dp[0][i + 1]);
				dp[1][i] = dp[1][i + 2] + a[i];
			}
		}
		cout << dp[0][0] << endl;
	}else{
		dp[0][n - 1] = 0;
		dp[1][n - 1] = a[n - 1];
		dp[0][n - 2] = 0;
		dp[1][n - 2] = ant(a[n - 1], a[n - 2]);
		RCH(i, n - 2){
			if(i % 2 == 0){
				dp[0][i] = ant(dp[0][i + 2] + a[i], dp[1][i + 1]);
				dp[1][i] = dp[1][i + 2] + a[i];
			}else{
				dp[0][i] = ant(dp[0][i + 2] + a[i], dp[0][i + 1]);
				dp[1][i] = ant(dp[1][i + 2] + a[i], dp[1][i + 1]);
			}
		}
		cout << dp[0][0] << endl;
	}
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(c - a) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
  	cout << "Yes" << '\n';
  } else cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 256