akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut A = Vec::new();
    A.push(0);
    for _ in 0..N {
        let a: i64 = sc.get();
        A.push(a);
    }
    A.push(0);
    let mut diff = vec![0; N];
    let mut total = 0;
    let mut now = 0;
    for i in 1..N+1 {
        diff[i-1] = (A[i] - now).abs();
        total += diff[i-1];
        now = A[i];
    }
    diff.push(now.abs());
    total += now.abs();
    for i in 1..N+1 {
        let ans = total - diff[i-1] - diff[i] + (A[i+1] - A[i-1]).abs();
        println!("{}", ans);
    }
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n;
int t[101001];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    cin >> t[i];
    t[i]--;
  }
  int res = 0;
  R(i,n){
    if(t[t[i]] == i)res ++;
  }
  cout << res / 2 << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    ll x, y;
    cin >> n;
    vector<ll> xv(n), yv(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x >> y;
        xv[i] = x + y;
        yv[i] = y - x;
    }

    ll xmin = *min_element(xv.begin(), xv.end());
    ll xmax = *max_element(xv.begin(), xv.end());
    ll ymin = *min_element(yv.begin(), yv.end());
    ll ymax = *max_element(yv.begin(), yv.end());

    ll ret = max(xmax - xmin, ymax - ymin);
    cout << ret << endl;

    return 0;
}




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

void Main() {
  int n;
  cin >> n;
  double ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += 1000.0 / a;
  }
  cout << 1 / (ans / 1000) << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string g;
    cin >> g;
    
    map<string,int> m;
    m[s] = a;
    m[t] = b;
    m[g] --;
    PS(m[s]);P(m[t]);
    return  0;
}


Measured memory_bytes: 256
<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$a=explode(" ",trim(fgets(STDIN)));
$c=array_sum($a)/4/$m;
rsort($a);
$i=0;
while($i<$m){
  if($a[$i]<$c){
    echo "No";
    exit;
  }
  ++$i;
}
echo "Yes";

Measured memory_bytes: 4856
#include <iostream>
#include <iomanip>
#include <string>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

bool match(string s, string t, int k)
{
    int ns = s.size(), nt = t.size();
    if (k + nt > ns)
    {
        return false;
    }
    repi(i, t.size(), 0)
    {
        if (s.at(k + i) != '?' && s.at(k + i) != t.at(i))
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string s, t;
    cin >> s >> t;
    int ns = s.size(), nt = t.size();
    if (ns < nt)
    {
        puts("UNRESTORABLE");
        return 0;
    }
    string s_ = s;
    bool state = false;
    for (int i = ns - 1; i >= 0; i--)
    {
        if (match(s, t, i))
        {
            state = true;
            repi(j, nt, 0)
            {
                s_.at(i + j) = t.at(j);
            }
            break;
        }
    }
    if (!state)
    {
        puts("UNRESTORABLE");
    }
    else
    {
        repi(i, ns, 0)
        {
            if (s_.at(i) == '?')
            {
                s_.at(i) = 'a';
            }
        }
        cout << s_ << endl;
    }
    return 0;
}

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

int main(){
  int H, W;
  vector<vector<int>> a(510, vector<int>(510));

  int sum = 0;
  cin >> H >> W;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a[i][j];
      sum += a[i][j];
    }
  }

  vector<vector<int>> ans;

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i == H-1 && j == W-1) break;
      
      if(i % 2 == 0){ //左から右に
        if(a[i][j] % 2 == 1){
          a[i][j] -= 1;
          if(j == W-1){
            a[i+1][j] += 1;
            ans.push_back({i+1, j+1, i+2, j+1});
          } else {
            a[i][j+1] += 1;
            ans.push_back({i+1, j+1, i+1, j+2});
          }
        }
      }

      if(i % 2 == 1){ //右から左に
        if(a[i][W-j-1] % 2 == 1){
          a[i][W-j-1] -= 1;
          if(j == W-1){
            a[i+1][W-j-1] += 1;
            ans.push_back({i+1, W-j, i+2, W-j});
          } else {
            a[i][W-j-2] += 1;
            ans.push_back({i+1, W-j, i+1, W-j-1});
          }
        }
      }
    }
  }

  cout << ans.size() << endl;
  for(int i=0; i<ans.size(); i++){
    printf("%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
  }
}
  
  

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){int a,b;cin>>a>>b;cout<<a-b+1<<endl;
           
	
  

	
	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

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

int n, m, c, t;
int l[MAX], r[MAX];
char s[MAX];

int main() {
    cin >> n >> m >> c;
    scanf("%s", s+1);
    int now = -c-1, cnt = 0;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'x' || i-now < c+1) continue;
        l[++cnt] = i, now = i;
    }
    now = n+c+1;
    if(cnt > m) return 0;
    t = cnt;
    for(int i = n; i >= 1; i--){
        if(s[i] == 'x' || now-i < c+1) continue;
        r[cnt--] = i, now = i;
    }
    for(int i = 1; i <= t; i++){
        if(l[i] == r[i]) printf("%d\n", l[i]);
    }

    return 0;
}

Measured memory_bytes: 4480
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect
import heapq

MOD = float('inf')
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

V, E, r = map(int, input().split())
std = [list(map(int, input().split())) for _ in range(E)]


def bellman_to_dijkstra(n, std):
    vertices_info = [[] for _ in range(n)]
    for edge in std:
        vertices_info[edge[0]].append([edge[1], edge[2]])
    return vertices_info


def dijkstra(n, vertices_info, r):
    weight = [INF for i in range(n)]
    weight[r] = 0
    vertices_index = []
    heapq.heappush(vertices_index, [r, 0])
    while len(vertices_index) > 0:
        u = heapq.heappop(vertices_index)
        for v in vertices_info[u[0]]:
            if u[1] + v[1] < weight[v[0]]:
                weight[v[0]] = u[1] + v[1]
                heapq.heappush(vertices_index, [v[0], weight[v[0]]])
    return weight


ans = dijkstra(V, bellman_to_dijkstra(V, std), r)
for i in ans:
    if i == INF:
        print("INF")
    else:
        print(i)



Measured memory_bytes: 228312
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

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

	int INF=1<<28;
	double EPS=1e-12;

	final char[] op={'0', '1', '+', '-', '*', '(', ')'};
	String s;
	char[] cs;
	int max;

	void run(){
		s=sc.nextLine();
		solve();
	}

	void solve(){
		s+="$";
		cs=s.toCharArray();
		max=-1;
		dfs(0);
		println(max+"");
	}

	void dfs(int i){
		if(i==cs.length){
			max=max(max, calc());
			return;
		}
		if(cs[i]=='.'){
			for(char c : op){
				cs[i]=c;
				dfs(i+1);
				cs[i]='.';
			}
		}else{
			dfs(i+1);
		}
	}

	int calc(){
		Result r=E(0);
		r.good&=r.p==cs.length-1;
		if(r.good){
			for(int i=0; i<cs.length; i++){
				if(cs[i]!='('){
					continue;
				}
				int stack=0;
				boolean op=false;
				for(int j=i+1; cs[j]!=')'||stack!=0; j++){
					if(cs[j]=='('){
						stack++;
					}else if(cs[j]==')'){
						stack--;
					}
					if(stack==0){
						op|=cs[j]=='+'||cs[j]=='-'||cs[j]=='*';
					}
				}
				r.good&=op;
			}
		}
		return r.good?r.value:-1;
	}

	Result E(int p){
		Result r=F(p);
		if(!r.good){
			return r;
		}
		for(; cs[r.p]=='+'||cs[r.p]=='-';){
			Result r2=F(r.p+1);
			if(!r2.good){
				return r2;
			}
			if(cs[r.p]=='+'){
				r.value+=r2.value;
			}else{
				r.value-=r2.value;
			}
			if(!r.update()){
				return r;
			}
			r.p=r2.p;
		}
		return r;
	}

	Result F(int p){
		Result r=T(p);
		if(!r.good){
			return r;
		}
		for(; cs[r.p]=='*';){
			Result r2=T(r.p+1);
			if(!r2.good){
				return r2;
			}
			r.value*=r2.value;
			if(!r.update()){
				return r;
			}
			r.p=r2.p;
		}
		return r;
	}

	Result T(int p){
		if(cs[p]=='('){
			Result r=E(p+1);
			if(!r.good||cs[r.p]!=')'){
				r.good=false;
				return r;
			}
			r.p++;
			return r;
		}else if(cs[p]=='0'||cs[p]=='1'){
			Result r=new Result(p, 0);
			for(; Character.isDigit(cs[r.p]); r.p++){
				r.value=r.value*2+cs[r.p]-'0';
				r.update();
			}
			return r;
		}else{
			return new Result(0, -1);
		}
	}

	class Result{
		int p, value;
		boolean good;

		Result(int p, int value){
			this.p=p;
			this.value=value;
			good=true;
			update();
		}

		boolean update(){
			return good&=0<=value&&value<1024;
		}
	}

	void println(String s){
		System.out.println(s);
	}

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

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;

    rep(i, n/7+0.999){
        if((n - 7 * i) % 4 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
int main(){
    int H,W;
    cin>>H>>W;
    string A[H];
    rep(i,H) cin>>A[i];

    vector<vector<int>> dist(H,vector<int>(W,-1));
    queue<pair<int,int>> que;
    rep(y,H){
    rep(x,W){
        if(A[y][x]=='#'){
            dist.at(y).at(x)=0;
            que.push(mp(y,x));
        }
    }
    }
    while(!que.empty()){
        pair<int,int> n=que.front();
        que.pop();
        rep(i,4){
            int nx=n.S+dx[i], ny=n.F+dy[i];
            if(nx<0 || ny<0 || nx>=W || ny>=H) continue;
            if(dist.at(ny).at(nx)>=0) continue;

            dist.at(ny).at(nx)=dist.at(n.F).at(n.S)+1;
            que.push(mp(ny,nx));
        }
    }
    int ans=0;
    rep(i,H){
        rep(j,W){
            ans=max(ans,dist.at(i).at(j));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e6+10,mod=1e9+7;
int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}

int fac[maxn],ifac[maxn],f[maxn];
inline int C(int n,int m){
	return (ll)fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(int n){
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n,1) ifac[i-1]=(ll)ifac[i]*i%mod;
}
inline void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
int calc(int n,int i){
	return (ll)C(n-2-i,i)*fac[n-1-i]%mod*fac[i]%mod;
}
int main(){
	int n=read();
	init(n);
	int ans=0;
	REP(i,0,(n-2)>>1) add(ans,(ll)(calc(n,i)-calc(n,i+1)+mod)*(n-1-i)%mod);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <limits>

using namespace std;

int main() {
  long long int l, r;
  cin >> l >> r;
  int a1 = numeric_limits<int>::max();
  for (long long int i = l; i < min(r,l + 2018); ++i) {
    for (long long int j = l+1; j <= min(r, l + 2018); ++j) {
      int a = (i % 2019) * (j % 2019) % 2019;
      if (a < a1) a1 = a;
    }
  }
  cout << a1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const int Inf = 1000000007;
const long long mod = 1000000007;//998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;

int main()
{
	cin >> n;
	n %= 10;
	if(n == 2 or n == 4 or n == 5 or n == 7 or n == 9)
	{
		cout << "hon";
	}
	else if(n == 0 or n == 1 or n == 6 or n == 8)
	{
		cout << "pon";
	}
	else
	{
		cout << "bon";
	}
}

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

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

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

    long long int sum = 0;
    for(int i=0; i<n+1; i++){
        sum += a[i];
    }

    for(int i=0; i<n; i++){
        if(a[i] >= b[i]){
            a[i] -= b[i];
        }
        else if(a[i] < b[i]){
            b[i] -= a[i];
            a[i] = 0;
            if(a[i+1] >= b[i]){
                a[i+1] -= b[i];
            }
            else if(a[i+1] < b[i]){
                a[i+1] = 0;
            }
        }
        /*
        for(int i=0; i<n+1; i++){
            cout << a[i] << " ";
        }
        cout << endl;
        */
    }

    long long int remained = 0;
    for(int i=0; i<n+1; i++){
        remained += a[i];
    }
    cout << sum - remained << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

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

		int n = scan.nextInt();
		int c = scan.nextInt();
		int k = scan.nextInt();

		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = scan.nextInt();
		}
		Arrays.sort(arr);

		int ans = 1;
		int firstTime = arr[0];
		int passenger = 1;
		for(int i = 1; i < n; i++) {
			if(passenger >= c || arr[i] > firstTime+k) {
				ans++;
				firstTime = arr[i];
				passenger = 0;
			}
			passenger++;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 50104
#include <iostream>
 
using namespace std;
int main() {
  int N; cin >> N;
  int judge = 1;
  
  for(int i=1; i <=9; i++){
    for(int j=1; j <=9; j++){
      if (N == i*j){
        judge = 0;
        break;
      }
    }
    if(judge == 0){
      break;
    }
  }
 
  if(judge == 0){
    cout << "Yes" << endl;
  }
 
  if(judge == 1){
    cout << "No" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0 ; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i * (m - j) + j * (n - i) == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

namespace ABC
{
    class ABC166B
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            string line;
            string[] sa;
            line = Console.ReadLine();
            sa = line.Split(' ');
            int n = int.Parse(sa[0]);
            int k = int.Parse(sa[1]);

            bool[] ba = new bool[n];

            for (int i = 0; i < k; ++i)
            {
                line = Console.ReadLine();
                int d = int.Parse(line);
                line = Console.ReadLine();
                string[] sa2 = line.Split(' ');
                for (int j = 0; j < d; ++j)
                {
                    int x = int.Parse(sa2[j]) - 1;
                    ba[x] = true;
                }
            }
            int result = 0;
            for (int i = 0; i < n; ++i)
            {
                if (ba[i] == false)
                {
                    result += 1;
                }
            }
            Console.WriteLine(result);

#if DEBUG
            Console.WriteLine();
#endif
        }
    }
}


Measured memory_bytes: 27876
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>

using namespace std;
int main(void){

    unsigned long long n;
    cin >> n;

    unsigned long long min = ULONG_MAX;
    for(int i=0; i<6; i++) {
        unsigned long long temp;
        cin >> temp;
        if(temp<min) min = temp;
    }
    
    unsigned long long cost;
    if(n%min==0) cost = n/min-1+5;
    else cost = n/min+5;
    
    
    cout << cost << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s;
int x, y;
vi v[2];
si s1, s2;
bool check(vi&w, int g){
  map<int, int> m;
  each(itr, w){
    if(m.find(*itr) == m.end()) m[*itr] = 0;
    m[*itr]++;
  }
  s1.clear();
  s2.clear();
  s1.insert(0);
  each(itr, m){
    s2.clear();
    each(itrr, s1) for(int i=-itr->se; i<=itr->se; i+=2){
      s2.insert(*itrr + itr->fi*i);
      s2.insert(*itrr - itr->fi*i);
    }
    swap(s1, s2);
  }
  return s1.find(g) != s1.end();
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> x >> y;
  int l = sz(s), idx = 0, z = 1;
  while(s[idx] == 'F')idx++;
  x -= idx;
  idx++;
  while(idx < l){
    int c = 0;
    while(idx < l && s[idx] == 'F') c++, idx++;
    if(c>0)v[z].pb(c);
    idx++;
    z = 1-z;
  }
  cout << ((check(v[0], x) && check(v[1], y)) ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>

#define cinf(n, x)                \
    for (int i = 0; i < (n); i++) \
        cin >> x[i];

using namespace std;

int main()
{
    string S;
    int N, K;
    cin >> N >> K;
    cin >> S;
    for (int i = 0; i < N; i++)
    {
        char w = S.at(i);
        if (i + 1 == K)
        {
            char s = tolower(w);
            cout << s;
        }
        else
        {
            cout << w;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

bool nibu(const vector<vector<int>> &G, vector<int> &p) {
    queue<pair<int, int>> que;
    que.push({0,-1});
    p[0] = 0;
    while (!que.empty()) {
        pair<int, int> v = que.front(); que.pop();
        for (int u : G[v.first]) {
            if (u != v.second) {
                if (p[u] == -1) {
                    p[u] = 1 - p[v.first];
                    que.push({u,v.first});
                }
                else if (p[u] != 1 - p[v.first]) {
                    return false;
                }
            }
        }
    }
  	return true;
}

int main() {
    ll n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    vector<int> p(n, -1);
    REP(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if (nibu(G, p)) {
        ll cnt = 0;
        REP(i, n) {
            if (p[i] == 0) {
                cnt++;
            }
        }
        cout << (n - cnt)*cnt - m << endl;
    }
    else {
        cout << n*(n - 1) / 2 - m << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
using ll =long long;
typedef long double ld;
const long double eps=1e-12;
const int maxn=(int)1e5+10;

ld p[maxn];

void mypow(){
    p[0]=1;
    for(int i=1;i<maxn;i++){
        p[i]=p[i-1]*0.5;
    }
}

int main()
{
    int n,m;
    ld sum;
    mypow();
    while(scanf("%d%d",&n,&m)!=EOF){
        sum=0;
        for(ll i=1;i<=n;i++){
            ll cnt=0,r=i;
            while(r<m) r*=2,cnt++;
            //cout << cnt << endl;
            sum+=(ld)((1.0/n)*p[cnt]);
        }
        printf("%.12Lf",sum);
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------



int main() {
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}


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

int main() {
  int N;
  cin >> N;
  string S = "APPROVED";
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A % 2 == 0) if (A % 3 and A % 5) S = "DENIED";
  }
  cout << S << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,sum=0;
  vector<int> a(51);
  vector<int> b(51);
  cin>>n>>m;
  for(int i=0;i<m;i++){
   cin>>a.at(i)>>b.at(i);
 }
 vector<int> road(51);
  for(int i=0;i<n;i++){
   		road.at(i)=0;
 }
  for (int i=0;i<m;i++){ 
    road.at(a.at(i)-1)+=1; road.at(b.at(i)-1)+=1;
}
for (int i=0;i<n;i++){ 
  cout << road.at(i) << endl;
}
  
}



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

int main() {
    
    int s;
    int c = 0;
    cin >> s;
    
    c = c + s % 10;
    s = s / 10;
    
    c = c + s % 10;
    s = s / 10;
    
    c = c + s % 10;
    cout << c << endl;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n;
  cin >> n;
  int x = n%1000;
  if (x == 0) {
    COUT(0);
  } else {
    COUT(1000 - x);
  }

  return 0;
}


Measured memory_bytes: 3648
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let mut v = vec![];
    let mut notzero = (0, 0, 0);
    for _ in 0..n {
        let (x, y, h): (isize, isize, isize);
        input!(x, y, h);
        v.push((x, y, h));
        if h != 0 {
            notzero = (x, y, h);
        }
    }

    for cx in 0..101 {
        for cy in 0..101 {
            let mut flag = true;
            let hmax = notzero.2 + (notzero.0 - cx).abs() + (notzero.1 - cy).abs();
            if hmax <= 0 {
                continue;
            }
            for t in &v {
                if t.2 != std::cmp::max(hmax - (t.0 - cx).abs() - (t.1 - cy).abs(), 0) {
                    flag = false;
                    break;
                }
            }
            if flag {
                println!("{} {} {}", cx, cy, hmax);
                return;
            }
        }
    }
}

Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	/*
	 *	...*....**
	 *	..........
	 *	**....**..
	 *	........*.
	 *	..*.......
	 *	..........
	 *	.*........
	 *	..........
	 *	....*..***
	 *	.*....*...
	 */
	
	public static class Rect{
		int start, height;

		public Rect(int start, int height) {
			super();
			this.start = start;
			this.height = height;
		}
		
		public String toString(){
			return "pos = " + start + " , height = " + height;
		}
	}

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

		while (true) {
			final int H = sc.nextInt();
			final int W = sc.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			
			boolean[][] wall = new boolean[H][W];
			
			for(int i = 0; i < H; i++){
				char[] input = sc.next().toCharArray();
				
				for(int j = 0; j < W; j++){
					if(input[j] == '*'){
						wall[i][j] = true;
					}
				}
			}
			
			int[][] count = new int[H][W];
			
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(wall[i][j]){
						count[i][j] = 0;
					}else if(i == 0){
						count[i][j] = 1;
					}else{
						count[i][j] = count[i-1][j] + 1;
					}
				}
			}
			
			int sek = 0;
			for(int i = 0; i < H; i++){
				Stack<Rect> stack= new Stack<Rect>();
				stack.push(new Rect(0, 0));
				//System.out.println(i);
				int max = 0;
				for(int j = 0; j < W; j++){
					Rect prev_del = null;
					//System.out.println(stack);
					
					if(stack.peek().height < count[i][j]){
						stack.add(new Rect(j, count[i][j]));
					}else{
						while(stack.size() != 0){
							Rect r = stack.peek();
							
							//System.out.println("=> " + r);
							
							if(r.height > count[i][j]){
								max = Math.max(max, r.height * (j - r.start));
								prev_del = r;
								stack.pop();
							}else if(r.height == count[i][j]){
								max = Math.max(max, r.height * (j - r.start));
								prev_del = null;
								break;
							}else{
								break;
							}
						}
					
						if(prev_del != null){
							stack.push(new Rect(prev_del.start ,count[i][j]));
						}
					}
				}
				//System.out.println(stack);
				for(Rect r : stack){
					max = Math.max(max, r.height * (W - r.start));
				}
				
				sek = Math.max(sek, max);
			}
			
			System.out.println(sek);
		}
	}
}

Measured memory_bytes: 41136
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long x = lread();
    long max_pow = 1;
    foreach (e; 2 .. 40)
    {
        long i = 2,j;
        while(1)
        {
            j = pow(e,i);
            i++;
            if(j > x)
            {
                break;
            }
            max_pow = max(j, max_pow);
        }
    }
    writeln(max_pow);
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <vector>
#include <deque>
#include <queue>
#include <cassert>
#include <iomanip>
#include <algorithm>


using namespace std;


#define x first
#define y second


int dist[500][500];
bool used[500][500];


vector<pair<int, int>> dir = { {0, -1}, {0, 1}, {-1, 0}, {1, 0} };

int n;

int us[500][500];
int pt = 0;

bool check(int x, int y) {
    return x >= 0 && x < n && y < n && y >= 0;
}


void dfs(int x, int y, int d) {
    dist[x][y]--;
    us[x][y] = pt;
    for (auto el : dir) {
        int x2 = el.x + x;
        int y2 = el.y + y;
        if (check(x2, y2) && us[x2][y2] != pt)
            if (used[x][y] && dist[x2][y2] == dist[x][y] + 1) {
                dfs(x2, y2, d);
            }
            else if (dist[x2][y2] == d) {
                dfs(x2, y2, d + 1);
            }
    }
}


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    vector<pair<int, int>> order;
    for (int i = 0; i < n * n; i++) {
        int num;
        cin >> num;
        num--;
        int x = num / n;
        int y = num % n;
        order.push_back({x, y});
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dist[i][j] = min(min(i, n - i - 1), min(j, n - j - 1));
        }
    }
    long long ans = 0;
    for (auto el : order) {
        ans += dist[el.x][el.y];
        pt++;
        used[el.x][el.y] = 1;
        for (auto el2 : dir) {
            int x = el.x + el2.x;
            int y = el.y + el2.y;
            if (check(x, y) && dist[x][y] == dist[el.x][el.y] + 1) {
                //if (el.x == el.y && el.x == 0)
                //    cout << x << ' ' << y << endl;
                dfs(x, y, dist[x][y] + 1);
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 30692
#define		_CRT_SECURE_NO_WARNINGS

#include	<cstdio>
#include	<cmath>

using namespace std;

int main()
{
	int			n;
	scanf("%d", &n);
	double		D[100];
	double		S[100];
	double		T;
	double		P1 = 0.;
	double		P2 = 0.;
	double		P3 = 0.;
	double		PINF = 0.;

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

	for (int i = 0; i < n; i++)
	{
		scanf("%lf", &T);
		S[i] = fabs(D[i] - T);
		P1 += S[i];
		P2 += S[i] * S[i];
		P3 += S[i] * S[i] * S[i];

		if (PINF < S[i])	PINF = S[i];
	}

	P2 = sqrt(P2);
	P3 = pow(P3, 1. / 3.);

	printf("%.6f\n", P1);
	printf("%.6f\n", P2);
	printf("%.6f\n", P3);
	printf("%.6f\n", PINF);

	return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

int n;
string s;
ll d[2][(1 << 18)][19];
char pat[(1 << 18)][18];

void add(ll& a, ll& b) {
	b += a;
}

int main() {
//	fin("t.in");
	sync;
	cin >> n;
	cin >> s;
	F(mask, 0, (1 << n)) {
		int l = 0;
		int r = n - 1;
		F(j, 0, n) {
			if (mask & (1 << j))
				pat[mask][r--] = s[j];
			else
				pat[mask][l++] = s[j];
		}
	}
	int tx = 1, ty = 0;
	clean(d);
	d[0][0][0] = 1;
	F(i, 0, 2 * n) {
		swap(tx, ty);
		clean(d[ty]);
		F(mask, 0, (1 << n)) {
			E(l, 0, min(n, i)) {
				int r = i - l;
				if (r > n || !d[tx][mask][l])
					cont;
				if (l < n) {
					if (i < n)
						add(d[tx][mask][l], d[ty][mask][l + 1]);
					else if (s[i] == pat[mask][l])
						add(d[tx][mask][l], d[ty][mask][l + 1]);
				}
				if (r < n) {
					if (i < n)
						add(d[tx][mask][l], d[ty][mask | (1 << i)][l]);
					else if (s[i] == pat[mask][n - 1 - r])
						add(d[tx][mask][l], d[ty][mask][l]);
				}
			}
		}
	}
	ll ans = 0;
	F(mask, 0, (1 << n))
		add(d[ty][mask][n], ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 82688
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
int n, m, x;

int main(){
    scanf("%d%d%d", &n, &m, &x);
    int grid[n][m], costs[n];
    for(int i = 0; i < n ; ++i){
        scanf("%d", &costs[i]);
        for(int j = 0; j < m ; ++j){
            scanf("%d", &grid[i][j]);
        }
    }

    int ans = oo;
    for(int i = 0; i < (1<<n) ; ++i){
        vector<int> s(m, 0);
        int cst = 0;
        for(int j = 0; j < n ; ++j){
            if(i & (1<<j)) continue;
            cst+=costs[j];
            for(int k = 0; k < m ; ++k) s[k]+=grid[j][k];
        }

        bool valid = true;
        for(int k = 0; k < m && valid; ++k){
            if(s[k] < x) valid = false;
        }
        if(valid) ans = min(ans, cst);
    }

    printf("%d\n", ans == oo ? -1 : ans);

    

    return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  ll Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
  ll cpl = min({4*Q, 2*H, S});
  if (2*cpl<D) cout << cpl*N;
  else {
    if (N%2==1) cout << (N/2)*D + cpl << endl;
    else cout << (N/2)*D << endl;
  }

  // cout << fixed << setprecision(6);
  return 0;
}



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

int main(void){
    ll a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<unordered_set>
#include<vector>
#include<cstring>
#include<sstream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;

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

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

    for(int i = 0; i < n; i++) {
        cout << (total^a[i]) << " ";
    }

    cout << endl;
}


Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
typedef long long ll;
ll a[N];
vector<ll>ls;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i], ls.emplace_back(a[i]);
    sort(ls.begin(), ls.end());
    ls.erase(unique(ls.begin(), ls.end()), ls.end());
    for(int i = 1; i <= n; ++i) a[i] = lower_bound(ls.begin(), ls.end(), a[i])-ls.begin()+1;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        if(abs(i-a[i])%2 == 1) ans++;
    }
    cout << ans/2 << '\n';
}

Measured memory_bytes: 1912
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<ll> factmemo, factmemoInv;
ll factmemoMod = -1;

ll factorial(int n, int M) {
  if (factmemoMod == M) return factmemo[n];
  if (n <= 1) return 1;

  ll res = 1;
  for (int i = 1; i <= n; i++) res = res * i % M;
  return res;
}

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

void initFactorial(int n, int M) {
  factmemo.assign(n + 1, 0);
  factmemoInv.assign(n + 1, 0);
  factmemoMod = M;
  factmemo[0] = 1;
  for (int i = 1; i <= n; i++) factmemo[i] = factmemo[i - 1] * i % M;
  factmemoInv[n] = power(factmemo[n], M - 2, M);
  for (int i = n; i > 0; i--) factmemoInv[i - 1] = factmemoInv[i] * i % M;
}

//nCm nPm nHm (mod M)

/*Combination*/
ll C(int n, int m, int M) {
  if (n < m) return 0;
  if (m == 0 || n == m) return 1;

  if (factmemoMod == M)
    return factmemo[n] * factmemoInv[m] % M * factmemoInv[n - m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(m, M) * factorial(n - m, M) % M;

  denom = power((int)denom, M - 2, M);

  return numer * denom % M;
}

/*Permutation*/
ll P(int n, int m, int M) {
  if (n < m) return 0;
  if (m == 0) return 1;

  if (factmemoMod == M)
    return factmemo[n] * factmemoInv[n - m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(n - m, M);

  denom = power((int)denom, M - 2, M);

  return numer * denom % M;
}

/*Combination with Repetitions*/
ll H(int n, int m, int M) {
  if (n == 0 && m == 0) return 1;
  return C(n + m - 1, m, M);
}


int main() {
  int N, K;
  map<int,int> counter;

  scanf("%d%d", &N, &K);

  initFactorial(N, mod);

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

  ll ans = 0;
  int sum = 0;

  for (auto p : counter) {
    // max
    ll s = (mod + C(sum + p.second, K, mod) - C(sum, K, mod)) % mod;

    ans += s * p.first % mod;

    // max
    ll t = (mod + C(N - sum, K, mod) - C(N - sum - p.second, K, mod)) % mod;

    ans -= t * p.first % mod;

    debug(s); debug(t);

    sum += p.second;
  }

  cout << (ans % mod + mod) % mod << endl;

  return 0;
}


Measured memory_bytes: 6016
<?php
list($n) = ints();
$a = ints();
sort($a);
for ($i = $n - 2; $i >= 1; --$i) {
    if ($a[$i] > 0) {
        $logs[] = [$a[0], $a[$i]];
        $a[0] -= $a[$i];
    } else {
        $logs[] = [$a[$n - 1], $a[$i]];
        $a[$n - 1] -= $a[$i];
    }
}
$logs[] = [$a[$n - 1], $a[0]];
$m = $a[$n - 1] - $a[0];
echo $m, PHP_EOL;
foreach ($logs as $log) echo implode(' ', $log), PHP_EOL;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 62408