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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

int N;
int a[25][25];
mint dp[25][1<<21];

void solve() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    dp[0][0] = 1;

    for (int i = 0; i < N; i++) {
        for (int s = 0; s < 1<<N; s++) {
            if (dp[i][s] != 0) {
                for (int j = 0; j < N; j++) {
                    if (a[i][j] && !(s & (1<<j))) {
                        dp[i+1][s|(1<<j)] += dp[i][s];
                    }
                }
            }
            
        }
    }

    cout << dp[N][(1<<N)-1] << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 167316
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
using namespace std;
typedef long long int ll;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    rep(i, n-2) {
        dp[i+2] = min(dp[i] + abs(h[i] - h[i+2]), dp[i+1] + abs(h[i+1] - h[i+2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1152
N, M = map(int, input().split())
A = list(map(int, input().split()))

S = sum(A)

i = 0
count = 0

while i < N:
    if A[i] >= S / (4*M):
        count += 1
    if count == M:
        print('Yes')
        exit()
    i += 1
print('No')

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

#define PI 3.14159265358979323846264338327950L

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << "\n";
    } else {
        cout << "ABC" << "\n";
    }


}


Measured memory_bytes: 3624
s=str(input())
n=len(s)
k=[0]*(n+1)
for i in range (1,n+1):
    k[i]=int(s[i-1])
t=[0]*(n+1)
t[0]=0  
for i in range(1,n+1):
    t[i]=(10*t[i-1]+k[i])%2019

p=1
q=[0]*448
for z in range(0,448):
    q[z]=p%2019
    p=10*q[z]

d=[0]*n   
for j in range(1,n+1):
    f=(n-j)%448
    d[j-1]=q[f]*t[j]%2019
ds=sorted(d)
ct=0
ans=0
if ds[0]==0:
    ct=1
    ans=1
for i in range(n-1):
    if ds[i+1]==ds[i]:
        ct+=1
        ans+=ct
    else:
        ct=0
print(ans)



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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int> > v;
    map<int,int> m;
    for(int i=0;i<n;i++){
        v.push_back(make_pair(0,i+1));
    }

    for(int i=0;i<n*(n-1)/2;i++){
        int a,b,c,d;
        cin >> a >> b >> c >> d;

        if(c > d){
            v[a-1].first += 3;
        }else if(c < d){
            v[b-1].first += 3;
        }else{
            v[a-1].first += 1;
            v[b-1].first += 1;
        }
    }
    sort(v.rbegin(), v.rend());
    int pos=1;
    int cnt=0;
    int point;
    for(int i=0;i<n;i++){
        if(i != 0){
            if(point != v[i].first){
                pos++;
                pos += cnt;
                cnt = 0;
            }else{
                cnt++;
            }
        }       
        m[v[i].second] = pos;
        point = v[i].first;
    }

    map<int,int>::iterator it = m.begin();

    while(it != m.end()){
        cout << (*it).second << endl;
        ++it;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,k;
 cin>>n>>k;
 vector<ll> c(n),g(n);
 for(ll i=0;i<n;i++) cin>>c[i]>>g[i];
 vector<vector<ll> > v(10,vector<ll>(1,0) );
 for(ll i=0;i<n;i++){
  v[ g[i]-1 ].push_back( c[i] );
 }

 for(ll i=0;i<10;i++){
  sort( v[i].begin()+1 , v[i].end() );
  reverse( v[i].begin()+1 ,v[i].end() );
 }
 for(ll i=0;i<10;i++){
  for(ll j=1;j<v[i].size();j++) v[i][j] += v[i][j-1] ;
  for(ll j=2;j<v[i].size();j++) v[i][j] += j*(j-1);
 }
 
 /*
 for(ll i=0;i<10;i++){
  cout<<i<<endl;
  for(auto j:v[i])cout<<j<<' ';
  cout<<endl;
 }
 */



 vector<vector<ll > > dp( 11 , vector<ll>(k+1,0 ) );
 
 for(ll i=0;i<10;i++){
  for(ll j=0;j<=k;j++){
   for(ll l=0;l<v[i].size()&&j-l>=0;l++){
    dp[i+1][j] = max( dp[i+1][j] , dp[i][j-l] + v[i][l] );
   }
  }
 }

 cout<<dp[10][k]<<endl;

    return 0;
}



Measured memory_bytes: 3264
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)

	inputs := scanNums(N)

	rightNum := N - 1
	leftNum := 0
	s1 := inputs[leftNum]
	s2 := inputs[rightNum]
	for {
		// fmt.Println(s1, s2)
		if s1 >= s2 {
			rightNum--
			s2 += inputs[rightNum]
		} else {
			leftNum++
			s1 += inputs[leftNum]
		}

		if leftNum+1 == rightNum {
			break
		}
	}
	ans := math.Abs(float64(s1) - float64(s2))
	fmt.Println(int(ans))

}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to
  prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2512
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int A, B, C, N;
const int max_n = 8;
vector<int> l(max_n+1, 0);
int rtn = 2000000000;

void calc(vector<char> v) {
    int mp = 0;
    int cnta = 0, cntb = 0, cntc = 0;
    for(int i = 1; i <= N; i++) {
        if(v[i] == 'A') {
            if(cnta != 0) mp += 10;
            cnta += l[i];
        } else if(v[i] == 'B') {
            if(cntb != 0) mp += 10;
            cntb += l[i];
        } else if(v[i] == 'C') {
            if(cntc != 0) mp += 10;
            cntc += l[i];
        }
    }
    if(cnta == 0 || cntb == 0 || cntc == 0) return;
    mp += abs(A - cnta) + abs(B - cntb) + abs(C - cntc);
    rtn = min(rtn, mp);
}

void dfs(int depth, vector<char> v) {
    if(depth > N) {
        calc(v);
        return;
    }
    for(int i = 0; i < 4; i++) {
        v[depth] = 'A' + i;
        dfs(depth+1, v);
    }
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 1; i <= N; i++) cin >> l[i];
    
    vector<char> v(N+1, '0');
    dfs(1, v);
    cout << rtn << endl;
}


Measured memory_bytes: 888
import sys
n,m = map(int, input().split())
X = list(map(int, input().split()))

if n >= m:
    print(0)
    sys.exit(0)

X.sort()
Y = []
for i in range(len(X)-1):
    Y.append(X[i+1]-X[i])
Y.sort(reverse=True)

print(X[-1]-X[0]-sum(Y[:n-1]))

Measured memory_bytes: 13968
import sys

stdin = sys.stdin

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

a, b, k = na()
i = min(k, a)
res = k - i
if res == 0:
    print(a - i, b)
if res > 0:
    i = min(res, b)
    res -= i
    if res > 0:
        print(0, 0)
    else:
        print(0, b - i)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,T;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x,y,z;
	cin >> x >> y >> z;
	swap(x,y);
	swap(x,z);
	cout << x <<' '<<y <<' '<<z;
	return 0;
		
}

Measured memory_bytes: 256
n,Y = map(int,input().split())
 
ans_x = -1
ans_y = -1
ans_z = -1
 
for x in range(n+1):
    for y in range(n+1-x):
        z = int((Y -10000*x - 5000*y)/1000)
        if z >= 0 and (z%1==0 or z==0) and x+y+z == n:
            ans_x = x
            ans_y = y
            ans_z = z
            break
 
print(ans_x, ans_y, ans_z)

Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let tmp: Vec<u64> = read_vec();
	let(h, w) = (tmp[0], tmp[1]);

	let mut ans: u64 = 0;
	if h == 1 || w == 1 {
		println!("1");
		return;
	}
	if (h*w) % 2 == 0 {
		ans = (h*w)/2;
	} else {
		ans = (h*w)/2 + 1;
	}
	println!("{}", ans);
}


Measured memory_bytes: 4352
main(){
	int i,k,n,x=0,a[100009]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&k);a[k]++;a[k+1]++;a[k+2]++;}
	for(i=0;i<100009;i++)x=(a[i]>a[x])?i:x;
	printf("%d",a[x]);
}

Measured memory_bytes: 2092
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int[][] a = new int[s.nextInt()][s.nextInt()];
		for(int i=0;i<a.length;i++) {
			for(int j=0;j<a[i].length;j++) {
				a[i][j]=s.nextInt();
			}
		}
		int sum=0;
		for(int i=0;i<a.length;i++) {
			for(int j=i+1;j<a.length;j++) {
				if(isSeisuDistance(a[i],a[j])) {
					sum++;
				}
			}
		}
		System.out.println(sum);

	}

	public static boolean isSeisuDistance(int y[], int z[]) {
		long sum = 0;
		for(int i=0;i<y.length;i++) {
			int diff = y[i]-z[i];
			sum += diff*diff;
		}
		double distance = Math.sqrt(sum);
		long dislong = (long)distance;

		return (dislong*dislong == sum)?true:false;
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
main(){int n,i;while(cin>>n&&n){int a[n];int r=0;for(i=0;i<n;)cin>>a[i++];for(i=n-1;i>0;i--){for(int j=1;j<=i;j++){if(a[j-1]>a[j]){swap(a[j-1],a[j]);r++;}}}cout<<r<<endl;}}

Measured memory_bytes: 0
def norm(c):
    a = abs(c)
    return a*a
def dot_product(a,b):
    return (a.conjugate()*b).real
def cross_product(a,b):
    return (a.conjugate()*b).imag
def projection(p,b):
    return b*dot_product(p,b)/norm(b)

P = []

N = int(input())

for i in range(N):
    x,y = map(float,input().split(' '))
    P.append(complex(x,y))

total = 0.0
for i in range(1,N-1):
    a,b,c = P[0],P[i],P[i+1]
    S = cross_product(b-a,c-a)/2
    total += S

print("%.1f" % (abs(total)))


Measured memory_bytes: 5628
#include <stdio.h>
#include <string.h>

int main(void)
{
    char data[10][10];
    int map[10][10][4];
    char dir[4] = "LRDU";
    int now;
    int i, j;
    
    memset(data, -1, sizeof(data));
    memset(map, 0, sizeof(map));
    
    for (i = 0; i < 9; i++){
        scanf("%s", data[i]);
    }
    
    for (i = 0; i < 9; i++){
        for (j = 0; j < 5; j++){
            if (i % 2 == 1){
                if (data[i][j] == '1'){
                    map[i / 2][j][3] = 1;
                    map[i / 2 + 1][j][2] = 1;
                }
            }
            else {
                if (data[i][j] == '1'){
                    map[i / 2][j][0] = 1;
                    map[i / 2][j + 1][1] = 1;
                }
            }
        }
    }
    
    i = j = 0;
    now = 1;
    do {
        switch (now){
          case 0:
            if (i + 1 < 5 && map[i + 1][j][2] == 1){
                i++;
                now = 2;
            }
            else if (j > 0 && map[i][j - 1][0] == 1){
                j--;
                now = 0;
            }
            else if (i > 0 && map[i - 1][j][3] == 1){
                i--;
                now = 3;
            }
            else {
                j++;
                now = 1;
            }
            break;
          
          case 1:
            if (i > 0 && map[i - 1][j][3] == 1){
                i--;
                now = 3;
            }
            else if (j + 1 < 5 && map[i][j + 1][1] == 1){
                j++;
                now = 1;
            }
            else if (i + 1 < 5 && map[i + 1][j][2] == 1){
                i++;
                now = 2;
            }
            else {
                j--;
                now = 0;
            }
            break;
          
          case 2:
            if (j + 1 < 5 && map[i][j + 1][1] == 1){
                j++;
                now = 1;
            }
            else if (i + 1 < 5 && map[i + 1][j][2] == 1){
                i++;
                now = 2;
            }
            else if (j > 0 && map[i][j - 1][0] == 1){
                j--;
                now = 0;
            }
            else{
                i--;
                now = 3;
            }
            break;
          
          case 3:
            if (j > 0 && map[i][j - 1][0] == 1){
                j--;
                now = 0;
            }
            else if (i > 0 && map[i - 1][j][3] == 1){
                i--;
                now = 3;
            }
            else if (j + 1 < 5 && map[i][j + 1][1] == 1){
                j++;
                now = 1;
            }
            else {
                i++;
                now = 2;
            }
            break;
        }
        
        printf("%c", dir[now]);
    } while (i + j != 0);
    
    printf("\n");
    
    return (0);
}

Measured memory_bytes: 0
#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 int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll n0 = n;

  ll m=2;
  for (; m*m <= n0; m++);

  vector<bool> vb(m+1, false);

  int c = 0;
  for (ll i = 2; i*i <= n; i++) {
    if (vb[i]) continue;
    ll z = i;
    while (n % z == 0) {
      n = n / z;
      c++;
      vb[z] = true;
      z *= i;
    }
    while (n % i == 0) {
      n = n / i;
    }
    if (n == 1) break;
  }

  if (n != 1) c++;

  cout << c << endl;
}


Measured memory_bytes: 3752
import sys

def solve():
    readline = sys.stdin.readline

    N = int(readline())
    A = list(map(int, readline().split()))
    
    ans = 0

    for i in range(1, len(A)):
        if A[i] < A[i - 1]:
            diff = A[i - 1] - A[i]
            ans += diff
            A[i] = A[i - 1]
    
    print(ans)

solve()

Measured memory_bytes: 91968
def d n;$t[n]||($t[n]=[n+1,$n+=1];$c[n].map{|i|d i.to_i-1};$t[n]<<$n+=1)end
gets
$c=[]
$<.map{|l|a,_,*b=l.split;$c[a.to_i-1]=b}
$n=0
$t=[]
$c.size.times{|i|d i;puts$t[i]*" "}

Measured memory_bytes: 6228
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(sum([abs(x - y) for x,y in zip(x,y)]))
print(pow(sum([pow(abs(x - y),2) for x,y in zip(x,y)]), 1/2))
print(pow(sum([pow(abs(x - y),3) for x,y in zip(x,y)]), 1/3))
print(max([abs(x - y) for x,y in zip(x,y)]))

Measured memory_bytes: 7812
import Data.List
main = do
  [n,t] <- map read . words <$> getLine
  a <- transpose . map (map read . words) . lines <$> getContents
  let b = filt t (a !! 0) (a !! 1)
  if length b > 0
    then print $ minimum b
    else putStrLn "TLE"

filt :: Int -> [Int] -> [Int] -> [Int]
filt _ [] [] = []
filt t (x:xs) (y:ys) = if y <= t
                         then x : (filt t xs ys)
                         else filt t xs ys


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

int main() {
  long n;
  cin >> n;
  int ln = floor(log2(n));
  n = pow(2, ln+1)-1;
  cout << n;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL a, b;
    cin >> a >> b;
    if(a + b == 15){
        cout << "+" << endl;
    }else if(a * b == 15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
def eat(n,x)
  if n == 0
    return 1
  end
  if x == 1
    return 0
  elsif 1 < x && x <= 1 + $array[n-1]
    return eat(n-1,x-1)
  elsif x == 2 + $array[n-1]
    return $parray[n-1] + 1
  elsif 2 + $array[n-1] < x && x <= 2 + $array[n-1]*2
    return eat(n-1,x-$array[n-1]-2) + $parray[n-1] +1
  elsif x == $array[n]
    return $parray[n]
  end
end
$array = Array.new(51,0)
$parray = Array.new(51,0)
$array[0] = 1
$parray[0] = 1
1.upto(50) do |i|
  $array[i] = $array[i-1]*2 + 3
  $parray[i] = $parray[i-1]*2 + 1
end
n,x = gets.split.map(&:to_i)
puts eat(n,x)


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

int main() {

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

	int left = 0, right = length - 1;
	if (length % 2 == 0) {
		for (int i = length - 1; i > 0; i -= 2) {
			b[left++] = a[i];
			b[right--] = a[i - 1];
		}
	}
	else {
		for (int i = length - 1; i > 0; i -= 2) {
			b[left++] = a[i];
			b[right--] = a[i - 1];
		}
		b[length / 2] = a[0];
	}


	for (int i = 0; i < length; i++) {
		cout << b[i] << " ";
	}
}




Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll N;  cin>>N;
  if(N==1){
    cout<<0<<endl;
  }else{
    ll a = 1;
    rep(i,0,N){
      a *= 9;
      a %= mod;
    }
    ll b = 1;
    rep(i,0,N){
      b *= 9;
      b %= mod;
    }
    ll c = (a+b)%mod;
    ll d = 1;
    rep(i,0,N){
      d *= 8;
      d %= mod;
    }
    ll ans = (c-d)%mod;
    if(ans<0) ans += mod;
    ll zen = 1;
    rep(i,0,N){
      zen *= 10;
      zen %= mod;
    }
    ans = (zen-ans)%mod;
    if(ans<0) ans += mod;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

const int maxn = 2e5+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}



int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    bool pp = 0;
    ll re = 0;
    REP(i,n){
    	int x; cin>>x;
    	if (pp && x) pp=0, x--, re++;
    	re+=x/2;
    	x%=2; 
    	pp = x;
    }
    cout<<re<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0110
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                bool flg = false;
                for (int i = 0 ; i < 10 ; i++)
                {

                    string tmp = line;
                    tmp = tmp.Replace("X", i.ToString());

                    string[] items = tmp.Trim().Split("+=".ToCharArray());
                    if (items.Any(x => x[0] == '0' && x.Length > 1)) continue;

                    if (Sum(items[0], items[1]) == items[2])
                    {
                        Console.WriteLine(i);
                        flg = true;
                        break;
                    }
                }
                if(!flg) Console.WriteLine("NA");
            }

        }

        public static string Sum(string a , string b)
        {
            const int N = 126;
            a = string.Join("", a.PadLeft(N, '0').Reverse());
            b = string.Join("", b.PadLeft(N, '0').Reverse());

            string[] resAr = new string[N];
            bool carrying = false;
            for (int j = 0 ; j < resAr.Length ; j++)
            {
                string tmp = (int.Parse(a[j].ToString()) + int.Parse(b[j].ToString()) + (carrying ? 1 : 0)).ToString();
                resAr[j] = tmp.Substring(tmp.Length - 1, 1);
                carrying = (int.Parse(tmp) > 9) ? true : false;
            }

            string ans =  string.Join("", resAr.Reverse().SkipWhile(x => x == "0").ToArray());
            return ans == "" ? "0" : ans;

        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 20568
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std ;

int main()
{
	int n ;
	long int m ;
	while( cin >> n >> m ,1 )
	{
		if( !n && !m )
			return 0 ;

		vector< long int > p ,ans ;
		p.push_back( 0 ) ;
		long int a ;
		for( int i = 1 ; i <= n ; i++ )
			cin >> a ,p.push_back( a ) ;

		sort( p.begin() ,p.end() ) ;

		for( int i = 0 ; i <= n ; i++ )
		{
			for( int j = i ; j <= n ; j++ )
			{
				if( p[ i ] + p[ j ] <= m )
					ans.push_back( p[ i ] + p[ j  ] ) ;
			}
		}

		sort( ans.begin() ,ans.end() ) ;

		long int lp = ans.size() - 1 ,Im_home = 0 ;
		for( int i = 0 ;  i < ans.size() ; i++ )
		{
			while( ans[ i ] + ans[ lp ] > m )
				lp-- ;
			if( ans[ i ] + ans[ lp ] <= m )
				Im_home = max( Im_home ,ans[ i ] + ans[ lp ] ) ;
		}

		cout << Im_home << endl ;
	}
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, M;
    cin >> N >> M;

    vector<pair<bool,int>> answers(N, make_pair(false,0));

    REP(i, M){
        ll p;
        string S;
        cin >> p >> S;
        if( S == "AC"){
           answers[p-1].first = true;
        }else{
           if( !answers[p-1].first ){
              answers[p-1].second++;
           }
        }
    }

    ll t = 0;
    ll w = 0;
    REP(i, N){
       if( answers[i].first ){
          t++;
          w += answers[i].second;
       }
    }

   cout << t << " " << w << endl;

}


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

struct edge {int to, cap, rev; };
const int MAX_V = 10000;
const int INF = 1 << 28;

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, cap, G[from].size() - 1});
}

void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(que.size()) {
        int v = que.front(); que.pop();
        for(int i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f) {
    if(v == t)  return f;

    for(int &i = iter[v]; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t, int flow_=INF) {
    int flow = 0;
    while (bfs(s), level[t] >= 0 && flow_ > 0) {
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, flow_)) > 0) {
            flow += f;
            if (flow_ != INF) flow_ -= f;
        }
    }

    return flow;
}

int main() {
    int n, e, q;
    cin >> n >> e >> q;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            add_edge(i, j, 0);
        }
    }
    for (int i = 0; i < e; i++) {
        int f, t;
        cin >> f >> t;
        int j = 0;
        while (G[f][j].to != t) j++;
        G[f][j].cap = 1;
        G[t][G[f][j].rev].cap = 1;
    }

    int f = max_flow(1, n);
    for (int i = 0; i < q; i++) {
        int m, a, b;
        cin >> m >> a >> b;
        int j = 0;
        while (G[a][j].to != b) j++;
        if (m == 1) {
            G[a][j].cap = 1;
            G[b][G[a][j].rev].cap = 1;
            f += max_flow(1, n);
        } else {
            int from = -1, to = -1;
            if (G[a][j].cap == 2) from = b, to = a;
            if (G[b][G[a][j].rev].cap == 2) from = a, to = b;
            G[a][j].cap = 0;
            G[b][G[a][j].rev].cap = 0;
            if (from > 0 && to > 0 && max_flow(from, to, 1) == 0) {
                f--;
                max_flow(from, 1, 1);
                max_flow(n, to, 1);
            }
        }
        cout << f << endl;
    }

    return 0;
}

Measured memory_bytes: 4608
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length()-1; i++) {
    if (s[i] == s[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  // int x;
  // cout << endl;
}

signed main() {
  int ans = 0;
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    while (a % 2 == 0) {
      ans++;
      a /= 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=1,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi COL;
  COL.pb(n);
  bool flg = true;
  while(flg) {
    if(n%2==0) n/=2;
    else n=n*3+1;
    COL.pb(n);
    c++;
    REP(i,COL.size()){
      REP(j,COL.size()){
        if(i==j)continue;
        if(COL[i]==COL[j]) flg=false;
      }
    }
  }
  OUT(c);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    #define mod 1e9+7
    #define FOR(a,c)   for ( int (a)=0; (a)<(c); (a)++)
    #define FORL(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
    #define FORR(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
    #define INF 1000000000000000003
    typedef long long int ll;
    typedef vector<long long int> vi;
    typedef pair<long long int,long long int> pi;
    typedef priority_queue<long long int> max_pq;
    typedef priority_queue<long long int, vector<long long int>, greater<long long int>> min_pq;
    #define F first
    #define S second
    #define PB push_back
    #define POB pop_back
    #define MP make_pair
    #define pi 3.1415926535
    #define buff cin.ignore(numeric_limits<streamsize>::max(),'\n')

    // Use inbuilt function  __gcd(a,b), __builtin_popcount(n), Use (x&-x) for last set Bit;
    
    int main()
    {
        ios::sync_with_stdio(NULL);
        cin.tie(NULL);
        cout.tie(NULL);

        ll n=0;
        cin>>n;
        ll arr[n+1]={0};
        for(ll i=0;i<n;i++)
            cin>>arr[i];
        ll dp[n+1];
        for(ll i=0;i<=n;i++)
            dp[i]=LLONG_MAX;
        dp[0]=0;
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]), dp[i-2]+abs(arr[i-1]-arr[i-3]));
        }
        cout<<dp[n]<<endl;

        return 0;
    }

Measured memory_bytes: 1792
N = int(input())
A = 1
B = 1

def div(x, y):
  if x % y == 0:
    return x // y
  else:
    return x // y + 1

for i in range(N):
  x, y = map(int, input().split())
  n = max(div(A, x), div(B, y))
  if n == 0:
    n = 1
  A = n * x
  B = n * y
print(A + B)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int H = 1e5+5, N = 3005, MOD = 1e9+7;
pii bad[N];
int dp[N];
int fac[2*H];

int inv(int b, int e){
  int ans = 1;
  while(e){
    if(e&1)ans = (1ll*ans*b)%MOD;
    b = (1ll*b*b)%MOD;
    e /= 2;
  }
  return ans;
}

int pascal(int c, int r){
  int den = (1ll*fac[r]*fac[c-r])%MOD;
  den = inv(den, MOD-2);
  return (1ll*fac[c]*den)%MOD;
}

int f(int i){
  int &ans  = dp[i];
  if(ans != -1)return ans;
  int n = bad[i].F;
  int m = bad[i].S;
  ans = pascal(n+m, m);

  forn(j, 0, i){
    int y = bad[j].F;
    int x = bad[j].S;
    if(x > m)continue;
    int dy = n-y;
    int dx = m-x;
    int aux = (1ll*pascal(dx+dy, dx)*f(j))%MOD;
    ans = (1ll*ans - aux + MOD) % MOD;
  }
  
  return ans;
}


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

  int h, w, n;
  cin >> h >> w >> n;

  int r, c;
  fac[0] = 1;
  forn(i, 1, h+w+1){
    fac[i] = (1ll*i*fac[i-1])%MOD;
  }
  forn(i, 0, n){
    cin >> bad[i].F >> bad[i].S;
    bad[i].F--;
    bad[i].S--;
  }
  bad[n] = {h-1, w-1};
  
  sort(bad, bad+n);
  memset(dp, -1, sizeof dp);

  cout << f(n) << endl;





}





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

int main() {
  int n, m; std::cin >> n>>m;
  std::vector<int> H(n);
  std::vector<bool> good(n, true);
  for(int i=0; i<n; i++) std::cin >> H[i];
  for(int i=0; i<m; i++){
    int a,b; std::cin >> a>>b;
    a--; b--;
    if(H[a] >= H[b]) good[b] = false;
    if(H[b] >= H[a]) good[a] = false;
  }
  int res{0};
  for(int i=0; i<n; i++) res += good[i];
  std::cout << res << std::endl;
}

Measured memory_bytes: 3740
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x, y = M()
ans = 'No'
for i in range(x+1):
    for j in range(x+1):
        if i + j == x and i*2 + j*4 == y:
            ans = 'Yes'

print(ans)

Measured memory_bytes: 68512
#include <iostream>
using namespace std;
/*
A 11 B 1 C 1111 D 01 E 110 F 10 G 011
  11   1          11   011   11   110
       1          10         01
       1
*/
int main() {
    string map[8], in;
    while (cin>>in) {
        map[0]=in;
        int h;
        string key[4];
        if (in=="00000000") h=0;
        else {
            key[0]=in;
            h=1;
        }
        for (int i=1; i<8; i++) {
            cin>>map[i];
            if (map[i]!="00000000") key[h++]=map[i];
        }
        if (h==4) cout<<"B"<<endl;
        else if (h==1) cout<<"C"<<endl;
        else if (h==3) {
            bool flag=true;
            for (int i=0; i<8; i++) if (key[1][i]=='1') {
                if (key[0][i]=='1') flag=false;
                break;
            }
            if (flag) cout<<"D"<<endl;
            else cout<<"F"<<endl;
        } else {
            bool flag=true;
            for (int i=0; i<8; i++) if (key[0][i]=='1') {
                if (key[1][i]=='0') flag=false;
                break;
            }
            if (flag) {
                for (int i=0; i<8; i++) if (key[1][i]=='1') {
                    if (key[0][i]=='0') flag=false;
                    break;
                }
                if (flag) cout<<"A"<<endl;
                else cout<<"G"<<endl;
            } else {
                cout<<"E"<<endl;
            }
        }
    }
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, ans, tmp;
    vector<ll> a;
    queue<ll> edge;

    cin >> n;
    for(ll i = 0; i < n; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    dsort(a, ll);

    ans = 0;
    for(ll i = 0; i < n; i++) {
        if(i == 0) {
            edge.push(a[i]);
        } else {
            ans += edge.front();
            edge.pop();
            edge.push(a[i]);
            edge.push(a[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6404
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
  
int main(){
    string S , T ; cin >> S >> T ;
    int cnt = 0 ;
    for( int i = 0 ; i < S.length() ; i++ ){
        if( S[i] != T[i] )
            cnt++ ;
    }
    cout << cnt << endl ;
    return 0 ;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int N, M;
const int MAX_N = 1e5 + 1;
vvint graph(MAX_N); // graph[i] := iから出てる辺の集合
vll dp(MAX_N, -1);
ll solve(int i)
{
    if (i < N and dp[i] != -1)
        return dp[i];

    if (graph[i].size() == 0)
        return dp[i] = 0;

    ll res = 0;
    for (auto &&j : graph[i])
    {
        chmax(res, solve(j));
    }
    return dp[i] = res + 1;
}
int main()
{

    cin >> N >> M;
    int x, y;
    for (size_t i = 0; i < M; i++)
    {
        cin >> x >> y;
        x--;
        y--;
        graph[x].push_back(y);
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        chmax(ans, solve(i));
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

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

int c[200][200];
int vis[200][200];
int w,h;


void dfs(int ci, int cj){
    vis[ci][cj] = true;
    int di[] = {0,1,0,-1, 1,1,-1,-1};
    int dj[] = {1,0,-1,0, -1,1,-1,1};
    rep(d,8){
        int ni = ci+di[d];
        int nj = cj+dj[d];
        if(ni < 0 || nj < 0) continue;
        if(ni >= h || nj >= w) continue;
        if(vis[ni][nj]) continue;
        if(c[ni][nj]==0) continue;
        dfs(ni,nj);
    }
}

int main(){
    while(cin >> w >> h && w){
        rep(i,h)rep(j,w) cin >> c[i][j], vis[i][j] = 0;
        int ans = 0;
        rep(i,h)rep(j,w){
            if(vis[i][j]) continue;
            if(c[i][j] == 0) continue;
            dfs(i,j);
            ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1452
from collections import Counter
n = int(input())
A = list(map(int, input().split()))

P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]

Q = Counter(Q)

cnt = 0
for p in P:
    cnt += Q[p]

print(cnt)

Measured memory_bytes: 146308
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;


long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main(){
    double l;cin>>l;
    double res = pow(l/3,3);
    cout<<fixed<<setprecision(10);
    cout<<res;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if (N == 1) {cout << "Hello World" << endl; return 0;}
    else {
        int A, B; cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a, b;
    int diff;
    int i, j, k;
    int tall=0;

    scanf("%d %d", &a, &b);
    diff = b-a;

    for(i=0; i<=diff; i++){
        tall += i;
    }

    printf("%d", tall -b);

    return 0;
}

Measured memory_bytes: 128
let readCharArray _ = stdin.ReadLine().ToCharArray()
let choice ok ng bool = if bool then ok else ng

readCharArray ()
|> Array.groupBy id
|> Array.map snd
|> Array.map Array.length
|> Array.map (fun x -> x % 2 = 0)
|> Array.reduce (&&)
|> choice "Yes" "No"
|> printfn "%s"


Measured memory_bytes: 29764
// *** creator : cfmasterr *** // 
#include <bits/stdc++.h>  
using namespace std;  int main() {   ios::sync_with_stdio(false);   cin.tie(0);   int n;   cin >> n;   vector<int> a(n);  for (int i = 0; i < n; i++) {   cin >> a[i];  }  sort(a.begin(), a.end());  int ans = 0;  vector<int> v;  v.push_back(a[0] + a[1]);  for (int i = 2; i < n; i++) {   for (int k : v) {    ans += (a[i] < k);   }   for (int j = 0; j < i; j++) {    v.push_back(a[i] + a[j]);   }  }  cout << ans << '\n';   return 0; }


Measured memory_bytes: 10220
n,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in [0]*n]
dp=[0 for _ in range(w+1)]
for i in range(n):
    for j in range(w,l[i][0]-1,-1):
        dp[j]=max(dp[j],dp[j-l[i][0]]+l[i][1])
print(max(dp))

Measured memory_bytes: 45040