akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int g[1<<12];
int INF = 1000000000;
int N, M, a, b, c, d;

int main() {
    cin >> N >> M;
    // create price, mask
    vector<pair<int, int>> keys;
    for (int i=0; i<M; i++) {
        cin >> a >> b;
        d = 0;
        for (int j=0; j<b; j++) {
            cin >> c;
            d |= (1 << (c-1));
        }
        pair<int, int> mask = make_pair(a, d);
        keys.push_back(mask);
    }
    // greedy
    int n = 1 << N;
    for (int i=1; i<n; i++) {
        g[i] = INF;
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<M; j++) {
            int idx = i | keys[j].second;
            g[idx] = min(g[idx], g[i]+keys[j].first);
        }
    }
    if (g[n-1]==INF) {
        cout << "-1\n";
    } else {
        cout << g[n-1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s;
    cin>>s;
    rep(i,s.size()){
        if(i%2!=0){
            if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b;
	cin >> a >> b;
	print(max(a - b * 2, 0));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=200005,inf=0x3f3f3f3f;
int h[N],ne[N<<1],to[N<<1],mx[N],se[N],d[N],sz[N];
int n,tot;LL ans;char S[N];

void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void dfs1(int x,int las) {
	if(S[x]=='1') d[x]=0,sz[x]=1;
	else d[x]=inf;
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		int y=to[i];dfs1(y,x),sz[x]+=sz[y];
		if(mx[y]+1>mx[x]) se[x]=mx[x],mx[x]=mx[y]+1;
		else if(mx[y]+1>se[x]) se[x]=mx[y]+1;
		if(sz[y]) d[x]=min(d[x],mx[y]+1);
	}
}
void dfs2(int x,int las) {
	int R=min(se[x]+1,mx[x]-1);
	if(d[x]<=R) ans+=(LL)(R-d[x]+1);
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		int y=to[i],kl=(mx[y]+1==mx[x]?se[x]+1:mx[x]+1);
		if(kl>mx[y]) se[y]=mx[y],mx[y]=kl;
		else if(kl>se[y]) se[y]=kl;
		if(sz[1]-sz[y]) d[y]=min(d[y],kl);
		dfs2(y,x);
	}
}
int main()
{
	int x,y;
	n=read();
	for(RI i=1;i<n;++i) x=read(),y=read(),add(x,y),add(y,x);
	scanf("%s",S+1);
	dfs1(1,0),dfs2(1,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 14592
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e15 + 1
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  ll N, t, l = INF, r = 0;

  cin >> N;

  REP(i, 5)
  {
    cin >> t;
    if (t < l)
    {
      l = t;
      r = i + (N + t - 1) / t;
    }
    else
    {
      r++;
    }
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			while (true) {
				String[] s = reader.readLine().split(" ");
				int a = Integer.parseInt(s[0]);
				String op = s[1];
				int b = Integer.parseInt(s[2]);
				if (op.equals("+"))
					System.out.println(a + b);
				if (op.equals("-"))
					System.out.println(a - b);
				if (op.equals("*"))
					System.out.println(a * b);
				if (op.equals("/"))
					System.out.println(a / b);
				if (op.equals("?"))
					break;
			}
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 24436
#include <bits/stdc++.h>
#define INF 1023456789
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define trav(it,v) for(typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long long ll;

int main(){
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int a[n],b[m];
    rep(i,0,n){
        scanf("%d",&a[i]);
    }
    rep(i,0,m){
        scanf("%d",&b[i]);
    }
    int max_c=0,c,t=k,s=0;;
    int tmp = k,j=0,bc=0,used=0;

    while(j < m && tmp >= b[j]){
        tmp-= b[j++];
        used+=b[j-1];
        bc++;
    }
    max_c = bc;
    rep(i,0,n){
        t -= a[i];
        s++;
        c=s;
        if (t < 0)
            break;
        while(bc > 0 && used > t){
            used -= b[--bc];
        }
        if (used > t)
            break;
        max_c = max(max_c,s+bc);
    }
    cout << max_c;


}


Measured memory_bytes: 5288
import java.util.Scanner;
  
class Main{
 public static void main(String[] arge){
    
 Scanner sc=new Scanner(System.in);
  
int a = 0;

while(true){
int x = sc.nextInt();

    if ( x == 0 ) { break;}
 else {
                a++;
System.out.println("Case "+a+": "+x);     
        
        }  

}
}
}




Measured memory_bytes: 41244
#include <iostream>

 #define rep(i,n) for (int i = 0; i < (n); i++)
 using namespace std;
 using ll = long long;

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

    int t;
    int ans = 0;
    while (x >= 500) {
        x -= 500;
        ans += 1000;
        t = x % 500;
    }

    while (x >= 5) {
        x -= 5;
        ans += 5;
    }

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (map.containsKey(x)) {
		        map.put(x, map.get(x) + 1);
		    } else {
		        map.put(x, 1);
		    }
		}
		int[] arr = new int[map.size()];
		int idx = 0;
		for (int x : map.values()) {
		    arr[idx] = x;
		    idx++;
		}
		Arrays.sort(arr);
		int total = 0;
		for (int i = 0; i < arr.length - k; i++) {
		    total += arr[i];
		}
       System.out.println(total);
	}
}


Measured memory_bytes: 100776
N, M = [int(i) for i in input().split()]
lst = []
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    lst.append((a, b))
lst.sort()

count = 0
cost = 0
for a, b in lst:
    if count + b > M:
        cost += a * (M - count)
        break
    count += b
    cost += a * b
print(cost)


Measured memory_bytes: 16968
package main

import (
	. "fmt"
	"io"
	"os"
	"sort"
)

type event struct{ p, i, d int }
type events []event

func (p events) Len() int           { return len(p) }
func (p events) Less(i, j int) bool { return p[i].p < p[j].p }
func (p events) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	buf := make([]byte, 16384)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	ri := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	r, c, n := ri(), ri(), ri()
	border := func(x, y int) bool { return x == 0 || x == r || y == 0 || y == c }
	getP := func(x, y int) int {
		if y == 0 || x == r {
			return x + y
		}
		return 2*r + 2*c - x - y
	}
	es := events{}
	for i := 0; i < n; i++ {
		x1, y1, x2, y2 := ri(), ri(), ri(), ri()
		if border(x1, y1) && border(x2, y2) {
			p1, p2 := getP(x1, y1), getP(x2, y2)
			if p1 > p2 {
				p1, p2 = p2, p1
			}
			es = append(es, event{p1, i, 1}, event{p2, i, -1})
		}
	}
	sort.Sort(es)
	s := []int{}
	for _, e := range es {
		if e.d == 1 {
			s = append(s, e.i)
		} else {
			if s[len(s)-1] != e.i {
				Fprint(_w, "NO")
				return
			}
			s = s[:len(s)-1]
		}
	}
	Fprint(_w, "YES")
}

func main() { run(os.Stdin, os.Stdout) }


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


int main(){
    int N;
    cin >> N;
    vector<ll> a(N);

    for(int i=0; i<N; i++) cin >> a[i];
    
    ll ans = 0;
    int r = 0;
    ll sum = 0;
    for(int l=0; l<N; l++){
        while(r < N && (sum + a[r]) == (sum ^ a[r])){
            sum += a[r];
            r++;
        }
        ans += r - l;
        if(l == r) r++;
        else sum -= a[l];
    }

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

Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int d(int k){
    int res=0;
    for(int i=1;i<=k;i++){
        if (k%i==0){
            res++;
        }
    }
    return res;
}
int main(void){
    int N;
    cin >> N;
    int ans=0;
    for (int i=1;i<=N;i++){
        if (d(i)==8 && i%2==1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long long n,i,count=1;
    scanf("%I64d",&n);

    for(i=1; i<=n; i++)
    {
        count*=i;
        if(count>1000000007)
        {
            count%=1000000007;

        }
    }

    printf("%I64d\n",count);

    return 0;
}


Measured memory_bytes: 128
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int a1, a2 ,a3;
    cin >> a1 >> a2 >> a3;
    int ans = a1 + a2 + a3;
    if (ans >= 22) {
        cout << "bust" << endl;
    } else cout << "win" << endl;
    return 0;
}

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

using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    queue<pair<string, int>> q;
    for (int i = 0; i < n; i++) {
        string s;
        int len;
        cin >> s >> len;
        q.push(make_pair(s, len));
    }

    vector<pair<string, int>> ans;
    
    int t = 0;
    while (!q.empty()) {
        pair<string, int> p = q.front();
        q.pop();
        if (p.second > w) {
            q.push(make_pair(p.first, p.second - w));
            t += w;
        }
        else {
            t += p.second;
            ans.push_back(make_pair(p.first, t));
        }
    }

    for (auto a : ans) {
        cout << a.first << " " << a.second << endl;
    }
    return 0;
}


Measured memory_bytes: 7048
import sys


class Mat(object):

  def __init__(self, row, col):
    self.row = row
    self.col = col
    
def get_min_mult_cnt_dp(i, j, mat_list):

  multp = [[sys.maxsize for i in range(len(mat_list))] for i in range(len(mat_list))]

  

  # 長さ0連鎖の演算量
  for i in range(len(mat_list)):
    multp[i][i] = 0

  for le in range(1, len(mat_list)):
    for i in range(len(mat_list)-le):
      j = i + le

      tmp = sys.maxsize
      for k in range(i, j):
        p = mat_list[i].row
        n = mat_list[k].col
        q = mat_list[j].col
        tmp = multp[i][k] + multp[k+1][j] + p*n*q

        if (tmp < multp[i][j]):
          multp[i][j] = tmp
    
  
  return multp[i][j]
mat_list = []
num = int(input())
for i in range(num):
    a,b = map(int,input().split())
    mat_list.append(Mat(a,b))



print(int(get_min_mult_cnt_dp(0, num-1, mat_list)))


Measured memory_bytes: 5784
N,A,B = map(int,input().split())
sList = [str(i) for i in range(1,N+1)]
allcount = 0
count = 0
for i in sList:
    count = 0
    for j in i:
        count += int(j)
    if A <= count <= B:
        allcount += int(i)
print(allcount)

Measured memory_bytes: 3572
#include  <stdio.h>
/* Aizu Online Judge Problem 	 */
/* Volume0 0007:Debt Hell 	   */

int main(void)
{
  int week;
  int pay = 100000;
  double rate = 1.05;

  scanf("%d", &week);

  while(week)
  {
    pay *= rate;
    if(pay % 1000)
    {
      pay = (pay / 1000 + 1) * 1000;
    }
    week--;
  }
  printf("%d\n", pay);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    ll sumA = 0, sumB = 0, dif1 = 0, dif2 = 0, dif = 0;
    vector<int> a(n), b(n);
    rep(i, n)
    {
        cin >> a[i];
        sumA += a[i];
    }
    rep(i, n)
    {
        cin >> b[i];
        sumB += b[i];
    }
    rep(i, n)
    {
        if (b[i] < a[i])
            dif1 += a[i] - b[i];
        else
            dif2 += (b[i] - a[i] + 1) / 2;
    }
    dif = max(dif1, dif2);
    if (sumB < sumA)
    {
        cout << "No" << endl;
    }
    else
    {
        if (dif <= sumB - sumA)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;


int main()
{
  fastio
  ll x, d, k;
  cin >> x >> k >> d;
  x = abs(x);
  if((x+1)/d>k) cout << x-k*d;
  else
  {
    ll steps = x/d;
    k -= steps;
    x -= steps*d;
    k%=2;
    if(k) x-=d;
    x=abs(x);
    cout << x;
  }

	return 0;
}





Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i += 2) {
    int count = 0;
    for(int j = 1; j <= n; j++) {
      if(i % j == 0) count++;
    }
    if(count == 8) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader reader = new BufferedReader( new InputStreamReader(System.in));
    int a = Integer.parseInt(reader.readLine());
    String s = reader.readLine();
    reader.close();
    if(a>=3200){
      System.out.println(s);}
     else{
       System.out.println("red");}}}

Measured memory_bytes: 20564
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
ll dp[7070];
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int N, T;
	cin >> N >> T;
	vector<pair<ll, ll>>p(N);
	for (int i = 0; i < N; i++) {
		int A, B;
		cin >> A >> B;
		p[i] = { A,B };
	}
	sort(all(p));
 
 
	for (int i = 0; i < N; i++) {
		int A = p[i].first;
		int B = p[i].second;
		for (int j = T - 1; j >= 0;j--) {
			dp[j + A] = max(dp[j] + B,dp[j + A]);
		}
	}
 
	ll ans = -1;
	for (int i = 0; i < 7060; i++)ans = max(dp[i],ans);
	puts(ans);
 
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int N;
  cin >> N;
  cout << (N / 500 * 1000 + (N % 500) / 5 * 5) << endl;
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int h,w;

int main(){
  cin >> h >> w;
  ll vertical=h;
  if(w%3==0)vertical=0;
  ll transversal=w;
  if(h%3==0)transversal=0;
  ll mixVertical=inf;
  for(int i=w/3-1;i<=w/3+1;i++){
    for(int j=1;j<h;j++){
      ll a[3]={};
      a[0]=h*i;
      a[1]=j*(w-i);
      a[2]=(h-j)*(w-i);
      sort(a,a+3);
      mixVertical=min(mixVertical,a[2]-a[0]);
    }
  }
  ll mixTransversal=inf;
  for(int i=h/3-1;i<=h/3+1;i++){
    for(int j=1;j<w;j++){
      ll b[3]={};
      b[0]=w*i;
      b[1]=j*(h-i);
      b[2]=(w-j)*(h-i);
      sort(b,b+3);
      mixTransversal=min(mixTransversal,b[2]-b[0]);
    }
  }
  ll ans=inf;
  ans=min(transversal,vertical);
  ans=min(ans,mixTransversal);
  ans=min(ans,mixVertical);
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main(){
    int n;cin>>n;
    int a[3003];
    ll dp[3003][3003]={};
    rep(i,n) cin>>a[i];
    //rep(i,n) cout<<a[i]<<endl;
    RREP(i,n-1){
        for(int j=i;j<n;j++){
            if((n-i-j-1)%2==0){
                dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
            }else{
                dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<string,int>mp;
int n,m,ans;
string s[1000];
int main()
{
	ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		mp[s[i]]++;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		cin>>s[0];
		mp[s[0]]--;
	}
	for(int i=1;i<=n;i++)
		ans=max(mp[s[i]],ans);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static string S, T, U;
static sl A, B;

void solve(void) {
  if (S == U) {
    A--;
  } else {
    B--;
  }
  cout << A << " " << B << endl;
}

int main(void) {
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  solve();
  return 0;
}



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

int main(void){
    int N,*L,i,max=0,sum=0;
    scanf("%d",&N);
    L = (int*)malloc(sizeof(int)*N);
    for(i=0;i<N;i++){
        scanf("%d",&L[i]);
        if(L[i]>max)    max = L[i];
        sum += L[i];
    }
    if (max<sum-max)    printf("Yes\n");
    else                printf("No\n");
    return 0;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;

  bool flag = false;
  for (int i = 0; i < N; i++) {
    if (C * (N - 1 - i) - D * i <= B - A && B - A <= -C * i + D * (N - 1 - i)) flag = true;
  }

  // 解答
  cout << (flag ? "YES" : "NO") << endl;

  return 0;
}


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

int main(void) {
	int a, b, n;
	int x, step;
	for (;;) {
		scanf("%d", &a);
		scanf("%d", &b);
		if (a >= 2 && a <= (pow(2.0, 31.0) - 1) && b >= 2 && b <= (pow(2.0, 31.0) - 1)) {
			if (a < b) {
				x = a;
				a = b;
				b = x;
			}
			step = 1;
			if (a != 0 && b != 0) {
				while (a%b != 0) {
					x = a % b;
					a = b;
					b = x;
					step++;
				}
				printf("%d %d\n", b, step);
			}

			else break;
		}
		else break;
	}
		
		

		return 0;
}


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

#define all(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int n ;
  cin >> n ;
  vector<int> vec(n) ;
  vector<int> vecvec(n) ;
  int count = 0 ;
  
  rep(i, n){
    vecvec.at(i) = i+1 ;
  }
  
  rep(i, n){
    cin >> vec.at(i) ;
  }
 
  rep(i, n){
    if(vec.at(i)!=vecvec.at(i)){
      count++ ; 
    }
  }
  
  if(count==0 || count==2){
    cout <<"YES"<<endl ;
  }
  else{
    cout <<"NO"<<endl ;
  }  
    return 0 ;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int[] nums = new int[a];
        for (int i = 0; i < a; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(nums);
        int ans = 0;
        int end = a - b;
        for (int i = a - 1; i > end - 1; i--) {
            ans += nums[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int main(){
	int x,a, b, c;
		cin >> a >> b >> c;
		if (a > b){
			x = b;
			b = a;
			a = x;
		}
		if (b > c){
			x = c;
			c = b;
			b = x;
		}
		if (a > b){
			x = b;
			b = a;
			a = x;
		}
		cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 3068
import math

li=list(map(int, input().split()))
    
cost=10000

c = abs(li[0] - li[1]) + abs(li[2] - li[1])

if c < cost:
    cost=c

c = abs(li[0] - li[2]) + abs(li[2] - li[1])

if c < cost:
    cost = c
    
c = abs(li[0] - li[1]) + abs(li[2] - li[0])

if c < cost:
    cost = c

c = abs(li[2] - li[1]) + abs(li[2] - li[0])

if c < cost:
    cost = c

c = abs(li[2] - li[0]) + abs(li[0] - li[1])

if c < cost:
    cost = c

c = abs(li[2] - li[1]) + abs(li[0] - li[1])

if c < cost:
    cost = c

print(cost)

Measured memory_bytes: 3064
#include <iostream>

#include <functional>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::min;
using std::vector;

static int
solve(int D, int G, vector<int> const &p, vector<int> const &c)
{
  int ret = G / 100;
  int maxbits = 1 << D;
  for (int b = 0; b < maxbits; b++)
  {
    int count = 0;
    int total = 0;
    for (int d = 0; d < D && total < G; d++)
    {
      if (b & (1 << d))
      {
        count += p[d];
        total += c[d] + 100 * (d + 1) * p[d];
      }
    }
    for (int d = D - 1; 0 <= d && total < G; d--)
    {
      if ((b & (1 << d)) == 0)
      {
        for (int n = 0; n < p[d] && total < G; n++)
        {
          count++;
          total += 100 * (d + 1);
        }
      }
    }
    ret = min(ret, count);
  }
  return ret;
}

int
main()
{
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int d = 0; d < D; d++)
  {
    cin >> p[d] >> c[d];
  }
  cout << solve(D, G, p, c) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


struct UnionFind{
	vector<int> data;
	int n, m;

	UnionFind(int ns, int ms) : n(ns), m(ms), data(ns + ms, INT_MIN){
		REP(i, m){
			data[i + n] = -i-1;
		}
	}

	bool unite(int a, int b){//矛盾の判定
		a = root(a), b = root(b);

		if (a == b)
			return true;

		if (data[a] != INT_MIN && data[b] != INT_MIN){
			if (data[a] != data[b]){
				return false;
			}
			else {
				if (rand() % 2)
					data[b] = a;
				else
					data[a] = b;
			}
		}
		else if (data[a] != INT_MIN)
			data[b] = a;
		else if (data[b] != INT_MIN)
			data[a] = b;
		else{
			if (rand() % 2)
				data[b] = a;
			else
				data[a] = b;
		}
		return true;
	}


	bool unitebu(int a, int b){//矛盾の判定 aをbの部活
		a = root(a);
		b += n;

		if (data[a] == data[b])
			return true;
		if (data[a] != INT_MIN)
			return false;

		data[a] = b;
		return true;
	}

	bool findset(int a, int b){
		return root(a) == root(b);
	}

	int root(int x){
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
};

signed main() {
	int n, m, k;
	cin >> n >> m >> k;
	UnionFind uf(n,m);
	REP(i, k){
		int t, a, b;
		scanf("%d %d %d", &t, &a, &b);
		bool ret = 1;
		a--, b--;
		if (t == 1){
			ret = uf.unite(a, b);
		}
		else if (t == 2){
			ret = uf.unitebu(a, b);
		}

		if (!ret){
			printf("%d\n", i + 1);
			return 0;
		}
	}

	printf("0\n");

	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>

struct node{
	int id;
	struct node *parentNode;
	struct node *leftChild;
	struct node *rightChild;
	struct node *sibling;
};

void preorder(struct node* nd);
void inorder(struct node* nd);
void postorder(struct node* nd);
struct node* createNode(int);
struct node* searchNode(int);

struct node* nodes[26];
int n;

int main(){

int i,j;
int id;
int tmpId;
int left, right;
int depth;
struct node* currentNode;
struct node* tmpNode;
struct node* leftChild;
struct node* rightChild;

struct node* root;
	
scanf("%d",&n);
	
for(i=0;i<n;i++){
	
	scanf("%d",&id);
	currentNode = createNode(id);
	
	scanf("%d",&left);
	leftChild = createNode(left);
	scanf("%d",&right);
	rightChild = createNode(right);
	
	if(leftChild){
		leftChild->sibling = rightChild;
		leftChild->parentNode = currentNode;
		currentNode->leftChild = leftChild;
	}
	if(rightChild){
		rightChild->sibling = leftChild;
		rightChild->parentNode = currentNode;
		currentNode->rightChild = rightChild;
	}
	
}
	
	// search root
	for(i=0; i<n; i++){
		
		depth = 0;
		tmpNode = nodes[i]->parentNode;
		while(tmpNode){
			depth++;
			tmpNode = tmpNode->parentNode;
		}
		if(depth == 0){
			root = nodes[i];
			break;
		}
		
	}
	
	printf("Preorder\n");
	preorder(root);
	
	printf("\nInorder\n");
	inorder(root);
	
	printf("\nPostorder\n");
	postorder(root);

	printf("\n");
	
	return 0;
}

void preorder(struct node* nd){
	
	struct node *tmpNode;
	
	printf(" %d",nd->id);
	if(nd->leftChild) preorder(nd->leftChild);
	if(nd->rightChild) preorder(nd->rightChild);
	
}

void inorder(struct node* nd){
	
	struct node *tmpNode;
	
	if(nd->leftChild) inorder(nd->leftChild);
	printf(" %d",nd->id);
	if(nd->rightChild) inorder(nd->rightChild);
	
}

void postorder(struct node* nd){
	
	struct node *tmpNode;
	
	if(nd->leftChild) postorder(nd->leftChild);
	if(nd->rightChild) postorder(nd->rightChild);
	printf(" %d",nd->id);
	
}

struct node* createNode(int id){
	struct node *newNode;
	if(id < 0) return NULL;
	if(newNode = searchNode(id)) return newNode;
	newNode = (struct node*)malloc(sizeof(struct node));
	newNode->id=id;
	newNode->parentNode = NULL;
	newNode->leftChild = NULL;
	newNode->rightChild = NULL;
	newNode->sibling = NULL;
	nodes[id] = newNode;
	return newNode;
}

struct node* searchNode(int id){
	if(nodes[id]) return nodes[id];
	return NULL;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
inf = int(1e10)
dp = [inf] * (1 << N) #1をNだけシフトする 2**B

#鍵をビットで表す　dp[i]は鍵の状態iにできる最小費用を
dp[0] = 0
bits = set()
bits.add(0)

for i in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    # cを状態keyに変換
    key = 0
    for t in c:
        key += 1 << (t - 1)
    # bits内のbitとkeyのORを更新
    # 更新したbitはbitsに追加
    add_bits = set()
    for bit in bits:
        tmp = bit | key
        if dp[bit] + a < dp[tmp]:
            dp[tmp] = dp[bit] + a
            add_bits.add(tmp)
    bits |= add_bits
    
if dp[(1 << N) - 1] == inf:
    print(-1)
else:
    print(dp[(1 << N) - 1])

Measured memory_bytes: 47192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, s;
vector<ll> v(1005);
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> v[i];
	sort(v.begin() + 1, v.begin() + n + 1);
	for (int i = 1; i <= k; ++i)
		s += v[i];
	cout << s;
	return 0;
}


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

using namespace std;

int n;
long long ans;

int main(void)
{
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)
		{
			ans+=i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = 0;
	rep(i, n) {
		int a; cin >> a; a--;
		ans += a;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    multiset<int> S;
    vector<pii> v(n);
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        v[i] = pii(p, i);
    }
    sort(rall(v));

    S.insert(-1);
    S.insert(-1);
    S.insert(n);
    S.insert(n);

    ll res = 0;
    for (auto x : v) {
        ll val = x.first;
        int id = x.second;

        auto itr = S.upper_bound(id);
        int r1 = *itr;
        itr++;
        int r2 = *itr;
        itr--; itr--;
        int l1 = *itr;
        itr--;
        int l2 = *itr;
        res += val * (r2 - r1) * (id - l1);
        res += val * (r1 - id) * (l1 - l2);
        S.insert(id);
    }
    cout << res << endl;
}

Measured memory_bytes: 8732
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs) {
  var N = parseInt(inputs[0]);
  var vs = inputs[1].split(" ").map(function(a){return parseInt(a);});
  var max = 0;
  var min = 100000;
  for(var i in vs){
    max = Math.max(max, vs[i]);
    min = Math.min(min, vs[i]);
  }
  console.log(max - min);
}


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

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

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;

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

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
signed main(){
	int n;
	cin>>n;
	int a[210000];
	int ans=0;
	bool b=true;
	rep(i,n){
		cin>>a[i];
		if((i==0&&a[i]!=0)||(i>0&&a[i]-a[i-1]>=2))b=false;
		ans+=a[i];
	}
	if(b==false){
		cout<<-1<<endl;
		return 0;
	}
	rep(i,1,n){
		if(a[i]-1==a[i-1])ans-=a[i-1];
	}
	cout<<ans<<endl;
}

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

using namespace std;
const int mod=1e9+7;

int n,m,dp[1005][1005];
char s[1005][1005];

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	dp[1][1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1) continue;
			if(s[i][j]=='#') dp[i][j]=0;
			else{
				if(i==1) dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
				else if(j==1) dp[i][j]=(dp[i-1][j]+dp[i][j])%mod;
				else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			}
		}
	}
	//for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) printf("%d%c",dp[i][j],j==m?'\n':' ');
	printf("%d\n",dp[n][m]);
}

Measured memory_bytes: 5120
//
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    ll ans = 0;
    ll amax = A[0];
    for (int i = 1; i < N; ++i)
    {
        if (A[i] < amax)
        {
            ll d = amax - A[i];
            ans += d;
        }
        else
        {
            amax = A[i];
        }
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4836
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = [0] * n
ans[0] = S - 2*sum(A[1: n: 2])

for i in range(1, n):
    ans[i] = int((A[i-1]-ans[i-1]/2)*2)

print(' '.join(map(str, ans)))


Measured memory_bytes: 19148
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
ll K;
vector<ll> A;

const ll INF=1e18;

bool judge(ll g){

  vector<ll> B;
  for(int i=0;i<N;i++) B.push_back(A[i]%g);
  ll sum=0;
  for(int i=0;i<N;i++){
      if(A[i]%g==0);
      else sum+=(g-A[i]%g);
  }

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

  ll res=0;
  ll s=0;
  ll ans=INF;
  for(int i=0;i<N;i++){
      res+=B[i];
      if(B[i]==0);
      else{
          s+=(g-B[i]);
      }

      ans=min(ans,min(res,sum-s)+abs(res-(sum-s)));
  }

  if(ans<=K) return true;
  else return false;
}

int main(){
  cin>>N>>K;
  A.resize(N);
  for(int i=0;i<N;i++) cin>>A[i];

  ll sum=0;
  for(int i=0;i<N;i++) sum+=A[i];

  ll ans=1;
  for(ll i=1;i*i<=sum;i++){
    if(sum%i==0){
      ll a=sum/i;
      if(i!=1&&judge(i)) ans=max(ans,i);
      if(judge(a)) ans=max(ans,a);
    }
  }

  cout<<ans<<endl;


  return 0;
}


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

int main() {
    int n,m;cin>>n>>m;
    string a[n],b[m];
    for (int i=0;i<n;i++)
        cin>>a[i];
    for (int i=0;i<m;i++)
        cin>>b[i];
    for (int i=0;i<=n-m;i++)
        for (int j=0;j<=n-m;j++) {
            for (int k=0;k<m;k++)
                for (int l=0;l<m;l++)
                    if (a[i+k][j+l]!=b[k][l]) {
                        goto aaa;
                    }
            puts("Yes");
            return 0;
            aaa:;
        }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

int main(){
	string s;
	while(cin >> s){
		int mini[205][205];
		int maxi[205][205];
		rep(i,205) rep(j,205){
			mini[i][j] = INF;
			maxi[i][j] = -INF;
		}

		rep(i,s.size()){
			if(isdigit(s[i])){
				mini[i][i + 1] = maxi[i][i + 1] = s[i] - '0';
			}
		}

		range(w,3,s.size() + 1){
			rep(i,s.size() + 1 - w){
				int j = i + w;

				if(w > 3){
					if(s[i] == '('){
						maxi[i][j] = max(maxi[i][j], maxi[i + 1][j]);
						mini[i][j] = min(mini[i][j], mini[i + 1][j]);
						continue;
					}else if(s[j - 1] == ')'){
						maxi[i][j] = max(maxi[i][j], maxi[i][j - 1]);
						mini[i][j] = min(mini[i][j], mini[i][j - 1]);
						continue;
					}
				}

				range(k,i + 1,j - 1){
					if(s[k] == '-'){
						maxi[i][j] = max(maxi[i][j], maxi[i][k] - mini[k + 1][j]);
						mini[i][j] = min(mini[i][j], mini[i][k] - maxi[k + 1][j]);
					}else if(s[k] == '+'){
						//cout << i << ' ' << k << endl;
						//cout << maxi[i][k] << ' ' << maxi[i][k + 1] << endl;
						maxi[i][j] = max(maxi[i][j], maxi[i][k] + maxi[k + 1][j]);
						mini[i][j] = min(mini[i][j], mini[i][k] + mini[k + 1][j]);

					}
				}
			}
		}
		//rep(i,s.size() + 1){ rep(j,s.size() + 1){ cout << maxi[i][j] <<  ' '; } cout << endl; }
		cout << maxi[0][s.size()] << endl;
	}
}

Measured memory_bytes: 3532
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
for i in a:
  if i >= sum(a)/(4*m):
    ans += 1
    if ans == m:
      print("Yes")
      exit()
  else:
    print("No")
    exit()

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

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

    std::vector<std::string> mat[10][10];
    REP(i,10)REP(j,10)mat[i][j].clear();
    string a = "a";
    mat[0][0].push_back(a);
    REP(i,n-1){
        for(int j=i; j<n-1;j++){
            for(string str : mat[i][j]){
                //cout<<"###"<<str<<endl;
                REP(k,i+1)mat[i][j+1].push_back(str+(char)('a'+k));
                mat[i+1][j+1].push_back(str+(char)('a'+i+1));
            }
        }
    }
    ll count = 0;
    vector<string> v;
    REP(i,9){
        for(string str : mat[i][n-2]){
            //cout<<"###"<<str<<endl;
            REP(k,i+1){
                //cout<<(str+(char)('a'+k))<<endl;
                v.push_back(str+(char)('a'+k));
                count++;
            }
            //cout<<(str+(char)('a'+i+1))<<endl;
            v.push_back(str+(char)('a'+i+1));
            count++;
        }
        //for(string str : mat[i][n-1])cout<<str<<endl;
    }
    sort(v.begin(),v.end());
    for(auto i : v)cout<<i<<endl;
    //cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 15988
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef pair<int, int> P;

int main(){
  int n; double ma, mb; cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  map<P, int> mp1;
  rep(i, pow(2, n/2)){
    int ta = 0, tb = 0, tc = 0;
    rep(j, n/2)if((i>>j)&1) ta += a[j], tb += b[j], tc += c[j];
    if(mp1.count(P(ta, tb)) > 0) mp1[P(ta, tb)] = min(mp1[P(ta, tb)], tc);
    else mp1[P(ta, tb)] = tc;
  }
  map<P, int> mp2;
  rep(i, pow(2, n-n/2)){
    int ta = 0, tb = 0, tc = 0;
    rep(j, n-n/2)if((i>>j)&1) ta += a[n/2+j], tb += b[n/2+j], tc += c[n/2+j];
    if(mp2.count(P(ta, tb)) > 0) mp2[P(ta, tb)] = min(mp2[P(ta, tb)], tc);
    else mp2[P(ta, tb)] = tc;
  }
  int ans = 5000;
  int cur = 0;
  for(int i=1; i*max(ma, mb) <= 400; i++){
    for(auto itr=mp1.begin(); itr!=mp1.end(); itr++){
      P p = itr->first;
      if(mp2.count(P(i*ma-p.first, i*mb-p.second)) > 0) ans = min(ans, itr->second+mp2[P(i*ma-p.first, i*mb-p.second)]);
    }
  }
  cout << (ans<5000 ? ans : -1) << endl;
}

Measured memory_bytes: 896
function parseInt(x) parse(Int, x) end

function main()
	a = parseInt.(split(readline()))
	if a[2]-a[1] < 2*a[3]
		for i in 0:a[2]-a[1]
			println(a[1]+i)
		end
	else
		for i in 1:a[3]
			println(a[1]+i-1)
		end
		for i in 1:a[3]
			println(a[2]-a[3]+i)
		end
	end
end

main()

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

int main(){
    int n, sum=0, m = 0, p;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> p;
        sum += p;
        if(m <= p) m = p; 
    }
    cout << sum - m/2;
}


Measured memory_bytes: 256