akhauriyash/Code-Regression huggingface dataset:
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<ll, vector<ll>>> vec;
  rep(i, n) {
    int x;
    cin >> x;
    vector<ll> r;
    vec.push_back(make_pair(x, r));
  }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    vec[a-1].second.push_back(b-1);
    vec[b-1].second.push_back(a-1);
  }
  int ans = 0;
  rep(i, n) {
    bool ok = true;
    rep(j, vec[i].second.size()) {
      ll x = vec[i].first;
      ll y = vec[vec[i].second[j]].first;
      if (x <= y) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 9820
#include<cstdio>
#include<cctype>
#include<queue>
#include<set>
#define N 500005
#define For(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
int l,pi[10];
void write(int x){
	l=0;
	while(x>0) pi[++l]=x%10,x=x/10;
	while(l) putchar(48+pi[l--]); putchar(10);
}
struct node{
	int key,pos;
	friend bool operator < (node a,node b){
		return a.key<b.key;
	}
};
int ans[N],a[N],v[N<<1],in[N],cnt,head[N],nex[N<<1];
void add(int x,int y){
	in[y]++; v[++cnt]=y; nex[cnt]=head[x]; head[x]=cnt;
}
int main(){
	int now=0,n=read(),k=read();
	For(i,1,n) a[i]=read();
	set<node> st; set<node>::iterator it;
	For(i,1,n){
		if (i>=k+1) st.erase((node){a[i-k],i-k});
		it=st.upper_bound((node){a[i],i});
		if (it!=st.end()) add(i,(*it).pos);
		st.insert((node){a[i],i});
	}
	st.clear();
	For(i,1,k-1) st.insert((node){a[i],i});
	For(i,1,n){
		st.erase((node){a[i],i});
		if (i+k-1<=n) st.insert((node){a[i+k-1],i+k-1});
		it=st.upper_bound((node){a[i],i});
		if (it!=st.end()) add(i,(*it).pos);
		st.erase((node){a[i-k+1]});
	}
	priority_queue<int,vector<int>,greater<int> > q;
	For(i,1,n) if (!in[i]) q.push(i);
	while(!q.empty()){
		int u=q.top(); q.pop();
		ans[u]=++now;
		for(int i=head[u];i;i=nex[i]){
			--in[v[i]];
			if (!in[v[i]]) q.push(v[i]);
		}
	}
	For(i,1,n) write(*(ans+i));
	return 0;
}

Measured memory_bytes: 42624
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  if (s <= "2019/04/30")
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	string s;
	long long k;

	cin >> s >> k;

	char c = '1';
	int pos = 0;
	rep(i,s.size()){
		if (s[i] != '1') {
			c = s[i];
			pos = i + 1;
			break;
		}
	}

	if (k < pos)cout << '1' << endl;
	else cout << c << endl;


	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define r register
inline bool isd(r char ch) {
	return ch<='9'&&ch>='0';
}
template<class temp>
inline temp F() {
	r temp x=0;
	r bool bo=0;
	r char ch=getchar();
	while(ch!='-'&&!isd(ch))
		ch=getchar();
	(ch=='-')&&(bo=1,ch=getchar());
	x=ch^'0',ch=getchar();
	while(isd(ch))
		x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	bo&&(x=-x);
	return x;
}
struct Edge {
	int f,t,d;
	Edge(r int F=0,r int T=0,r int D=0):f(F),t(T),d(D) {} 
}E[800001]; 
bool operator<(const Edge &a,const Edge &b) {
	return a.d<b.d;
}
int tot;
void Add(r int f,r int t,r int d) {
	E[++tot]=Edge(f,t,d);
} 
int n,t,ans;
struct Point {
	int x,y,id;
	Point(r int X=0,r int Y=0,r int i=0):x(X),y(Y),id(i) {} 
}P[400001];
bool cmp1(const Point &a,const Point &b) {
	return a.x<b.x;
}
bool cmp2(const Point &a,const Point &b) {
	return a.y<b.y;
}
int p[400001];
int Find(r int x) {
	return x==p[x]?x:p[x]=Find(p[x]);
}
void Kruskal() {
	r int cnt=0;
	std::sort(E+1,E+tot+1); 
	for(r int i=1;i<=tot&&cnt<=n-1;++i) {
		r int x=Find(E[i].f),y=Find(E[i].t);
		if(x!=y) {
			p[y]=x;
			++cnt;
			ans+=E[i].d;
		} 
	}
} 
int main() {
	n=F<int>();
	for(r int i=1;i<=n;++i)
		p[i]=i;
	for(r int i=1;i<=n;++i) {
		r int x=F<int>(),y=F<int>();
		P[i]=Point(y,x,i);
	}
	std::sort(P+1,P+n+1,cmp1);
	for(r int i=1;i<n;++i)
		Add(P[i].id,P[i+1].id,P[i+1].x-P[i].x);
	std::sort(P+1,P+n+1,cmp2);
	for(r int i=1;i<n;++i)
		Add(P[i].id,P[i+1].id,P[i+1].y-P[i].y);
	Kruskal();
	printf("%d",ans);
	return 0;
}



Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string s, t; cin >> s >> t;
  sort(all(s));
  sort(all(t));
  reverse(all(t));
  cout << (s<t?"Yes":"No") << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

int ans = 0;
    rep(i, n) {
        rep(j, d) {
            if (j * a[i] + 1 <= d) ans++;
        }
    }
    cout << ans + x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

struct Point
{
    int x, y;
};

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

    int h, w;
    cin >> h >> w;
    vector< string > field(h);
    rep (i, h) cin >> field[i];

    int num = 0;
    rep (i, h) rep (j, w) if (field[i][j] == '#') ++num;

    vector< vs32 > d(h, vs32(w, (int)1e9));
    queue< Point > q;
    q.push(Point{.x = 0, .y = 0});
    d[0][0] = 0;
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    while (!q.empty())
    {
        Point p = q.front(); q.pop();
        rep (i, 4)
        {
            int ny = p.y + dy[i];
            int nx = p.x + dx[i];
            if (IN(0, h, ny) && IN(0, w, nx) && field[ny][nx] != '#' && d[ny][nx] > d[p.y][p.x] + 1)
            {
                q.push(Point{.x = nx, .y = ny});
                d[ny][nx] = d[p.y][p.x] + 1;
            }
        }
    }

    if (d[h - 1][w - 1] == 1e9) cout << "-1\n";
    else cout << h * w - num - d[h - 1][w - 1] - 1 << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A , B , C ;
    cin >> A >> B >> C ;
    if (( A == 5 ) && ( B == 5) && ( C == 7 ) || ( A == 5 ) && ( B == 7 ) && ( C == 5 ) || ( A == 7 ) && ( B == 5) && ( C == 5))
        cout << "YES" ;
        else
        cout << "NO" ;
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    
    int sum = a + b;   //a, b の合計
    int ans = sum / 2; //平均値(切り捨て)
    if(sum % 2 == 1)ans += 1; //合計が奇数の場合に切り上げ分(+1)
    
    cout << ans << endl;
    return 0;
}
  

Measured memory_bytes: 256
N,X=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
count=0
for i in range(N):
	if i==(N-1):
		if X!=L[i]:
			count=count
		else:
			count+=1
	elif L[i]<=X:
		X-=L[i]
		count+=1
	
print(count)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int n, t, r, min = 1000000000, pvmin, prof = -999999999;
  pvmin = min;

  scanf("%d", &n);
  for (t = 0; t < n; t++) {
    scanf("%d", &r);
    if (r < min) {
      pvmin = r;
    }
    if (t > 0 && r - min > prof) {
      prof = r - min;
    }
    min = pvmin;
  }
  printf("%d\n", prof);

  return 0;
}

Measured memory_bytes: 596
import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  a:b:_ <- (map read . words) <$> getLine
  putStrLn $ compareTwoInt a b

compareTwoInt :: Int -> Int -> String
compareTwoInt a b
  | a > b = "a > b"
  | a < b = "a < b"
  | otherwise = "a == b"

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
	int a;
	scanf("%d", &a);
	int b;
	scanf("%d", &b);
	
	int mix = 0;
	int i;
	for(i=0; i<2; i++){
		if(a>b){
			mix+=a;
			a--;
		}
		else
		{
			mix+=b;
			b--;
		}
	}
	printf("%d", mix);
	
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

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

// -----------------------------------------------------------------

type int64arr []int64

func (s int64arr) Len() int           { return len(s) }
func (s int64arr) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64arr) Less(i, j int) bool { return s[i] < s[j] }

func calc(l, r, e int64) int64 {
	a := make([]int64, 0, n)
	a = append(a, V[:l]...)
	a = append(a, V[n-r:]...)
	sort.Sort(int64arr(a))
	var ans int64
	for _, v := range a[e:] {
		ans += v
	}
	return ans
}

var V []int64
var n int64

func main() {
	n = readInt64()
	k := readInt64()
	V = make([]int64, n)
	for i := range V {
		V[i] = readInt64()
	}

	var kk, i, j, l, r, ans int64
	for kk = 0; kk <= k; kk++ {
		for i = kk; i > 0; i-- {
			if i > n {
				continue
			}
			j = kk - i
			if j > i {
				break
			}
			for l = 0; l <= i; l++ {
				r = i - l
				ans = max64(ans, calc(l, r, j))
			}
		}
	}
	fmt.Println(ans)
}

/*
6 10
-10 8 2 1 2 6
*/


Measured memory_bytes: 5504
s = int(input())
m = int(1e9)+7
if s < 3:
    ans = 0
else:
    d = [0] * (s+1)
    d[0] = 1
    for i in range(3, s+1):
        for j in range(3, s+1):
            if i>= j:
                d[i] = (d[i] + d[i-j])%m
    ans = d[s]
print(ans)

Measured memory_bytes: 9036
#ABC107B
h,w = list(map(int,input().split()))
a = [0]*h
for i in range(h):
    a[i] = input()

h_d = []
for i in range(h):
    cnt = 0
    for j in range(w):
        if a[i][j] != '.':
            break
        cnt += 1
    if cnt == w:
        h_d.append(i)
a = [a[i] for i in range(h) if i not in h_d]

h_ = len(a)
w_d = []
for j in range(w):
    cnt = 0
    for i in range(h_):
        if a[i][j] != '.':
            break
        cnt += 1
    if cnt == h_:
        w_d.append(j)
a = [[a[j][i] for i in range(w) if i not in w_d]for j in range(h_)]

for i in range(h_):
    print(''.join(a[i]))

Measured memory_bytes: 3188
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int N, M, a[300004], i;
long long int r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(int &x){int k=gc();x=0;for(;;k=gc()){if(isdigit(k)){x=k-48;break;}}for(;;){k=gc();if(!isdigit(k))break;x=x*10+k-48;}}

int main(){
    read(N);
    M = N;
    M += (N << 1);
    for(; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<int>());
    N <<= 1;
    ++N;
    for(i = 1; i ^ N; i += 2){
        r += a[i];
    }
    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(ALL(a));
    ll pp = lower_bound(ALL(a), a[n - p]) - a.begin();
    ll ppp = upper_bound(ALL(a), a[n - p]) - a.begin();
    ll ans = n - pp + 1;

    ll ok = n - 1;
    ll ng = -1;
    while(ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if(mid >= pp) {
            ok = mid;
            continue;
        }
        vector<ll> tmp;
        for(ll i = 0; i < n; i++) {
            if(i != mid) {
                tmp.push_back(a[i]);
            }
        }
        ll up = a[mid] + m;
        ll cnt = 0;
        reverse(ALL(tmp));
        bool flg = 0;
        for(ll i = 0; i < tmp.size(); i++) {
            if(i < p - 1) {
                cnt += m;
            } else if(up >= tmp[i]) {
                cnt += min(m, up - tmp[i]);
            } else {
                flg = true;
            }
        }
        if(flg) {
            ng = mid;
        } else if(cnt >= m * (v - 1)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << n - ok << endl;
}

Measured memory_bytes: 2916
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = int64_t;

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

    int n, tmp;
    cin >> n;

    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        a.push_back(make_pair(tmp, i + 1));
    }

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

    for (const auto &e : a) {
        cout << e.second << " ";
    }

    return 0;
}


Measured memory_bytes: 1780
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

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

const int MX = 200005;
const int MM = 1000000007;

int N, a, b;
int rl = 1e9, rr, bl = 1e9, br;
pii D[MX];

ll solve()
{
	sort(D+1, D+N+1);
	int mx = 1;
	for(int i = 2; i <= N; i++) if( D[mx].second < D[i].second ) mx = i;
	if( 1 == mx ) return 2e18;
	swap(D[mx], D[2]);
	sort(D+3, D+N+1);
	multiset<int> L; L.insert(D[1].second); L.insert(D[2].first);
	ll mn = 2e18;
	for(int i = 3; i <= N; i++){
		L.insert(D[i].first);
	}
	mn = min(mn, (ll)*L.rbegin() - *L.begin());
	for(int i = 3; i <= N; i++){
		L.erase(L.find(D[i].first));
		L.insert(D[i].second);
		mn = min(mn, (ll)*L.rbegin() - *L.begin());
	}
	return mn * (D[2].second - D[1].first);
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d%d", &a, &b);
		if( a > b ) swap(a, b);
		D[i] = pii(a, b);

		rl = min(rl, a);
		rr = max(rr, a);
		bl = min(bl, b);
		br = max(br, b);
	}
	printf("%lld\n", min(solve(), (ll)(rr-rl) * (br-bl)));
}


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

const int mod = 1e9 + 7;
const int MAXN = 3e2 + 10;

int n, m, dp[MAXN][MAXN][MAXN];
vector<pair<int, int> > lim[MAXN];

inline bool check(int r, int g, int b) {
	int k = max(r, max(g, b));
	for (int j = 0; j < lim[k].size(); ++j) {
		int l = lim[k][j].first, x = lim[k][j].second, cnt;
		cnt = (r >= l) + (g >= l) + (b >= l);
		if (cnt != x) return 0;
	}
	return 1;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		lim[r].push_back(make_pair(l, x));
	}
	memset(dp, 0, sizeof dp);
	dp[0][0][0] = 1;
	int ans = 0;
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k <= n; ++k) {
				if (!dp[i][j][k]) continue;
				if (!check(i, j, k)) {
					dp[i][j][k] = 0;
					continue;
				}
				int len = max(i, max(j, k)) + 1;
				if (len == n + 1)
					(ans += dp[i][j][k]) %= mod;
				(dp[len][j][k] += dp[i][j][k]) %= mod;
				(dp[i][len][k] += dp[i][j][k]) %= mod;
				(dp[i][j][len] += dp[i][j][k]) %= mod;
			}
	printf("%d\n", ans);
}

Measured memory_bytes: 116736
#include <iostream>
#include <queue>

using namespace std;

int main ()
{
    int buf;
    priority_queue<int> qu;
    
    for (int i=0; i<10; i++) {
        cin >> buf;
        qu.push(buf);
    }
    
    cout << qu.top() << '\n';
    qu.pop();
    cout << qu.top() << '\n';
    qu.pop();
    cout << qu.top() << '\n';
    
    return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

int arr[2000001];

int main()
{
    int a,b=1,c,i;
    long long int sum=0;
    scanf("%d",&a);
    for(i=1;i<=a;i++){
        scanf("%d",&arr[i]);
        if(arr[1]!=0) {
            printf("-1"); return 0;
        }
        if(arr[i]>arr[i-1]+1 ){
            printf("-1"); return 0;
        }
        else if(arr[i]==arr[i-1]+1 ){
            sum++;
        }
        else {
            sum+=arr[i];
        }
    }

    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 896
n = int(input())
s = input()

mx = 0

# print(s)

for i in range(0, n):
    f = s[:i]
    b = s[i:]

    # print(i)
    res = 0
    l = []
    # print(i)
    for fi in f:
        # print(fi)
        if fi in b:
            # print('!')
            if not fi in l:
                l.append(fi)
                res += 1
    # print(res)

    if res > mx:
        # print(mx)
        mx = res

print(mx)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N,K;
    cin >> N >> K;
    vector<long long> H(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> H[i];
    }
    long long ans = LLONG_MAX;
    sort( H.begin(), H.end() );
    for ( int i = 0; i <= N-K; i++ ) {
        long long h = H[i+K-1] - H[i];
        ans = min( ans, h );
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
tbl = []
s = []
p = []
for i in range(n):
    l = list(map(str,input().split()))
    l[1] = int(l[1])
    l2 = [l[1], l[0], i + 1]
    tbl.append(l2)
    s.append(l2[1])
    p.append(l2[0])

p.sort()
p.reverse()
tbl2 = []
for i in range(n):
    for j in range(n):
        if(tbl[j][0] == p[i]):
            tbl2.append(tbl[j])
s = list(set(s))
s.sort()
for i in range(len(s)):
    for j in range(len(tbl2)):
        if (tbl2[j][1] == s[i]):
            print(tbl2[j][2])


Measured memory_bytes: 9072
import sys
sys.setrecursionlimit(10 ** 9)

class Union_Find:
    def __init__(self, n = 0):
        self.d = [-1] * n

    def find_root(self, x: int) -> int:
        if self.d[x] < 0:
            return x
        self.d[x] = self.find_root(self.d[x])
        return self.d[x]

    def unite(self, x: int, y: int) -> bool:
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def is_same(self, x: int, y: int) -> bool:
        return self.find_root(x) == self.find_root(y)

    def size(self, x: int) -> int:
        return (-1) * self.d[self.find_root(x)]

n, m, k = map(int, input().split())
uf = Union_Find(n)
ng = [set() for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ng[a].add(b)
    ng[b].add(a)
    uf.unite(a, b)

for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.is_same(c, d):
        ng[c].add(d)
        ng[d].add(c)

ans = [0] * n
for i in range(n):
    ans[i] = uf.size(i) - len(ng[i]) - 1

print(*ans)


Measured memory_bytes: 64544
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let mut v = Vec::new();
    let mut min = usize::max_value();
    for i in 0..5 {
        let tmp = get!(usize);
        if tmp < min {
            min = tmp;
        }
        v.push(tmp);
    }
    //eprintln!("{}", min);
    //eprintln!("{:?}", v);
    //一番狭いところ
    let mut ans = (n + min - 1) / min;
    //最初＋最後
    ans += 4;
    println!("{}", ans);
}


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

int main(){
  string s;
  cin >> s;
  vector <char> A;
  for (int i=0; i<s.length(); i+=2){
    A.push_back(s.at(i));
  }
  for (int i=0; i<A.size();i++){
    cout << A.at(i);
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MAXN 2550
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    int a;
    cin >> a;
    cout <<  a*a*a << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  if(n<=111) cout<<111;
  else if(n<=222) cout<<222;
  else if(n<=333) cout<<333;
  else if(n<=444) cout<<444;
  else if(n<=555) cout<<555;
  else if(n<=666) cout<<666;
  else if(n<=777) cout<<777;
  else if(n<=888) cout<<888;
  else if(n<=999) cout<<999;
}

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

typedef long long ll;
using namespace std;

int main(void)
{
	ll l,r;
	cin >> l >> r;
	ll mod = 2019;

	ll min = 2020;
	ll ansi = 0;
	ll ansj = 0;

	for (int i = 0;  l + i <= r && i <= 2019 * 2; i++) {
		for (int j = i + 1; l + j <= r && j <= 2019 * 2 - i - 1; j++) {
			if ((((l +i)%mod) * ((l+j)%mod)) % mod < min) {
				min = (((l+i)%mod) * ((l+j)%mod)) % mod;
			}
		}
	}

	cout << min << endl;

}

Measured memory_bytes: 256
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,m=0,x=0,y=0;
    cin>>n>>m;
    int h[n];
    for(int i=0;i<n;++i)
        cin>>h[i];
    vector<int> v[n];
    for(int i=0;i<m;++i)
    {
        cin>>x>>y;
        --x;--y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bool mark[n]={false};
    for(int i=0;i<n;++i)
    {
        bool flag=true;
        for(int j=0;j<v[i].size();++j)
        {
            if(h[v[i][j]]>=h[i])
            {
                flag=false;
                break;
            }
        }
        if(flag)
            mark[i]=true;
    }
    int ct=0;
    for(int i=0;i<n;++i)
    {
        if(mark[i])
            ++ct;
    }
    cout<<ct<<endl;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<int> vec(m,0);
  rep(j,n){
    int k;cin>>k;
    vector<int> v(k);
    rep(i,k){
      cin>>v.at(i);
      vec.at(v.at(i)-1)++;
    }
  }
  cout<<count(vec.begin(),vec.end(),n);
}
      




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int k; cin >> k;
    bool b[k];
    fill(b, b+k, false);
    int x = 0;
    for (int i = 1;; i++) {
        // cerr << x << endl;
        x = (7 + 10 * x) % k;
        if (x == 0) { cout << i << endl; return 0; }
        if (b[x]) { cout << -1 << endl; return 0; }
        b[x] = true;
    }
}


Measured memory_bytes: 4168
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
using namespace std;
int main() {
	int n,m;
	cin>>n>>m;
	int k[m],s[m][n],p[m];
	ll ans=0;
	rep(i,0,m){
		cin>>k[i];
		rep(j,0,k[i]) cin>>s[i][j];
	}
	rep(i,0,m) cin>>p[i];
	rep(i,0,(1<<n)){
		int cnt=0;
		rep(j,0,m){
			int sum=0;
			rep(q,0,n){
				if(i&(1<<q))
                    rep(l,0,k[j])
						if(s[j][l]-1==q)sum++;
			}
			if(sum%2==p[j])cnt++;
		}
		if(cnt==m)ans++;
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type xyz struct {
	x int
	y int
	z int
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	Y := nextInt()
	//N := 9
	//Y := 45000
	slice := []xyz{}

	L: 
	for i := 0; i < N+1; i++ {
		x := N - i
		for j := 0; j < x+1; j++ {
			z := N - i - j
			if 10000*i+5000*j+1000*z == Y {
				slice = append(slice, xyz{
					x: i,
					y: j,
					z: z,
				})
				break L
			}

		}
	}

	if len(slice) == 0 {
		fmt.Printf("-1 -1 -1")
	} else {
		x := slice[0].x
		y := slice[0].y
		z := slice[0].z

		fmt.Printf("%d %d %d", x, y, z)
	}
}


Measured memory_bytes: 640
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		
		while(true){
			String[] str=br.readLine().split(" ");
			int H=Integer.parseInt(str[0]);
			int W=Integer.parseInt(str[1]);
			
			if(H==0&&W==0) break;
			
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(i==0||i==H-1||j==0||j==W-1){
						sb.append("#");
					}
					else{
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 25512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

typedef pair<long,long> P;
long  d[55][55];

int main(int argc, char* argv[])
{
    long h,w;
    scanf("%ld %ld", &h, &w);

    long count=0;
    char a[55][55]={0};
    long i,j;
    for(i=0; i<h; i++) {
        scanf("%s", a[i]);
        for(j=0; j<w; j++) {
            if(a[i][j]=='.') count++;
        }
    }

    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            d[i][j]=-1;
        }
    }

    long dx[4]={1,0,-1,0};
    long dy[4]={0,1,0,-1};
    queue<P> que;
    que.push(P(0,0));
    d[0][0]=0;
    while( que.size() ) {
        P p=que.front(); que.pop();
        if(p.first==h-1 && p.second==w-1) break;

        for(i=0; i<4; i++) {
            long nx =p.first+dx[i];
            long ny =p.second+dy[i];

            if(0<=nx && nx<h && 0<=ny && ny<w && a[nx][ny]!='#' && d[nx][ny]<0) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second]+1;
            }
        }
    }
    if(d[h-1][w-1]>=0) {
        printf("%ld\n", count - d[h-1][w-1] -1);
    }
    else {
        printf("-1\n");
    }

    return 0;
}


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

namespace Test
{
    class AIZU
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var nums =Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            nums.Reverse();
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


Measured memory_bytes: 18440
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<Pll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i].fi>>a[i].se;
    }
    sort(all(a));
    for(ll i=0;i<n;i++){
        cout<<a[i].fi<<" "<<a[i].se<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































Measured memory_bytes: 4428
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

string S;
ll K;
ll memo[310][310][310];//[)
ll solve(ll l, ll r, ll rest){
  if(l > r) return -INFL;
  if(l == r) return 0;
  if(l + 1 == r) return 1;
  if(memo[l][r][rest] != -1) return memo[l][r][rest];
  ll res = max(solve(l, r-1, rest), solve(l+1, r, rest));
  if(S[l] == S[r-1]){
    res = max(res, solve(l+1, r-1, rest) + 2);
  }else{
    if(rest >= 1) res = max(res, solve(l+1, r-1, rest - 1) + 2);
  }
  return memo[l][r][rest] = res;
}

int main(){
  cin >> S >> K;
  rep(i, 310)rep(j, 310)rep(k, 310) memo[i][j][k] = -1;
  cout << solve(0, S.size(), K) << endl;
}


Measured memory_bytes: 232960
N, M = map(int,input().split()) 
p = [input() for i in range(N)]

ans = "Yes"
for n in range(1,N-1):
    for m in range(1,M-1):
        if p[n][m] == '#':
            if p[n-1][m] != "#" and p[n][m-1] != "#" and p[n+1][m] != "#" and p[n][m+1]!= "#":
                ans = "No"
                break
print(ans)

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

int main () {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ((abs(a - b) <= d && abs(b - c) <= d) || (abs(a - c) <= d))
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import pprint
import math

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def prime_fact(n):
	p = {}
	for i in range(2, int(-(-n**0.5//1))+1):
		if n % i == 0:
			while n % i == 0:
				n //= i
				p[i] = p.get(i, 0) + 1
	if n != 1:
		p[n] = p.get(n, 0) + 1
	return p
# s = n(n+1)/2 

def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	if n == 1:
		print(0)
		exit()
	p = prime_fact(n)
	ans = 0
	if len(p.keys()) == 0:
		print(1)
		exit(0)
	for key in p:
		i = 1
		while p[key] >= i:
			p[key] -= i
			ans += 1
			i += 1
	print(ans)


	# keys = list(p.keys())
	# key = keys[0]
	# i = 1
	# j = 0
	# while 1:
	# 	if p[key] < i:
	# 		j += 1
	# 		if len(keys) == j:
	# 			break
	# 		key = keys[j]
	# 		i = 1
	# 		continue
	# 	log.print(p, n, key)
	# 	z = key ** i
	# 	n /= z
	# 	p[key] -= i
	# 	ans += 1
	# 	i += 1
	# print(ans)


main()

Measured memory_bytes: 68996
import sys
input = sys.stdin.readline


h, w = map(int, input().split())
A = []

for i in range(h):
    line = list(map(int, input().split()))
    A.append(line)

for i in range(h):
    line = list(map(int, input().split()))
    for j, num in enumerate(line):
        A[i][j] = abs(A[i][j] - num)

const = 640000
bitset = 1 << const
DP = [0]*w
DP[0] = bitset >> A[0][0]


def slide_down(y, x):
    bit = DP[x]
    delta = A[y+1][x]
    new1 = bit << delta
    new2 = bit >> delta
    DP[x] = new1 | new2


def slide_right(y, x):
    bit = DP[x]
    delta = A[y][x+1]
    new1 = bit << delta
    new2 = bit >> delta
    DP[x+1] |= new1 | new2


for y in range(h):
    for x in range(w):
        if x < w-1:
            slide_right(y, x)
        if y < h-1:
            slide_down(y, x)

ans = DP[w-1]
for i in range(81):
    if (ans >> const+i) & 1 or (ans >> const-i) & 1:
        print(i)
        exit()


Measured memory_bytes: 13752
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	char d=' ';
	cout<<a<<d<<b<<d<<3*c-a-b<<endl;
	cout<<4*c-b-2*a<<d<<c<<d<<2*a+b-2*c<<endl;
	cout<<a+b-c<<d<<2*c-b<<d<<2*c-a<<endl;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            #define N           5000005
            using namespace std;
            ll n,k,sum,q,res,m,val;
            ll x,y;
            
            void solve()    
            {   

                cin>>n;
                map<ll,ll> hm;
                ll sum=0;
                for(int i=0;i<n;i++)
                {
                    cin>>x;
                    hm[x]++;
                    sum+=x;
                }
                cin>>q;
                while(q--)
                {
                    cin>>x>>y;
                    sum+=((y-x)*hm[x]);
                    hm[y]+=hm[x];
                    hm[x]=0;
                    cout<<sum<<"\n";

                }



            }
            int main()
            {   
                ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;
                //cin>>t;
                
                for(int i=1;i<=t;i++)
                    solve();
            
            }            

Measured memory_bytes: 9468
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N, M;	cin >> N >> M;
	vector<vector<int>> len(N, vector<int>(M, 0));
	vector<int> a(N), b(N);
	vector<int> c(M), d(M);

	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> c[i] >> d[i];
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			len[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
		}
		int min = *min_element(len[i].begin(), len[i].end());
		int num = 0;
		while (true) {
			if (min == len[i][num]) {
				cout << num + 1 << endl;
				break;
			}
			num++;
		}
	}
	cin >> N;
}

Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n,a,b = imap()
div,mod = divmod(n, a+b)
ans = div*a + min(mod, a)
print(ans)


Measured memory_bytes: 15256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>

#define INF 10000000100
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<long long(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll bit=1,n,ans=1;
  cin>>n;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  
  while(1){
    bit=(bit<<1)+1;
    //cout<<"debug: "<<bit<<endl;
    if(bit<=n)ans++;
    else break;
  }
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

int seq[19];
int N;

long long dfs(int l,int r,long long lt,long long rt)
{
	if(l + 1 == r) return 0;
	long long ans = 1e18;
	long long tms = lt + rt;
	for(int i = l + 1;i < r; ++ i) ans = min(ans,dfs(l,i,lt,tms) + dfs(i,r,tms,rt) + tms * seq[i]);
	return ans;
}

int main()
{
	scanf("%d",&N);
	for(int i = 1;i <= N; ++ i) scanf("%d",&seq[i]);
	printf("%lld\n",dfs(1,N,1,1) + seq[1] + seq[N]);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '

const int INF = 1e9 + 5;

int main() {
	ll a = 0, b = 0, c = 0, k = 0;
	cin >> a >> b >> c >> k;
	if(k <= a){
		cout << (ll)k << endl;
		return 0;
	}
	if(a + b >= k){
		cout << (ll)a << endl;
		return 0;
	}
	else{
		k-=a;
		k-=b;
		for(int i = 0; i < k; ++i){
			a+=-1;
		}
	}
	cout << a << endl;


    return 0;
} 


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

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

    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    int flag = 1;
    int counter = 0;

    while(flag){
        flag = 0;
        for (int i = N - 1; i >= 1 ; i--){
            if (A[i] < A[i - 1]){
                int a = A[i];
                A[i] = A[i - 1];
                A[i - 1] = a;
                counter++;
                flag = 1;
            }
        }
    }

    rep(i, N){
        if (i == N - 1){
            cout << A[N - 1] << endl;
        } else {
            cout << A[i] << " ";
        }
    }

    cout << counter << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n;

int main() {
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  rep(i, n) cin >> a[i + 1];

  for (int i = n; i >= 1; --i) {
    int s = 0;
    for (int j = 2 * i; j <= n; j += i) {
      s ^= b[j];
    }
    b[i] = s ^ a[i];
  }

  vector<int> ans;
  for (int i = 1; i <= n; ++i) if (b[i]) ans.push_back(i);
  if (ans.size()) {
    cout << ans.size();
    cout << endl;
    for (auto A : ans) cout << A << " ";
  } else {
    cout << 0;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3064
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXK = 19;
const int MAXN = 1 << MAXK;
const int INF = 2e9;

char s[MAXN];

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	bool first = 1;
	while (scanf("%s", s) == 1) {
		if (first) first = 0;
		else printf("\n");

		int n = strlen(s);

		vector<vector<int> > frst(n + 2, vector<int>(26 + 1, n + 1));
		for (int i = n - 1; i >= 0; i--) {
			frst[i][s[i] - 'a'] = i + 1;
			for (int j = s[i] - 'a' + 1; j <= 26; j++) {
				frst[i][j] = frst[frst[i][j - 1]][j - 1];
			}
			for (int j = 0; j < s[i] - 'a'; j++) {
				frst[i][j] = frst[frst[i][26]][j];
			}
		}
		vector<vector<int> > nxt(n + 2, vector<int>(MAXK));
		for (int i = n + 1; i >= 0; i--) {
			for (int j = 0; j < MAXK; j++) {
				if (j == 0) nxt[i][j] = frst[i][26];
				else nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
			}
		}

		int q;
		scanf("%d", &q);
		for (int it = 0; it < q; it++) {
			int l, r;
			scanf("%d%d", &l, &r);
			--l; --r;

			bool ok = 1;

			if (l == r) ok = 0;
			else {
				int x = s[l] - 'a';
				int p = l;
				p = frst[p][26];

				for (int j = MAXK - 1; j >= 0; j--) {
					if (nxt[p][j] <= r + 1) p = nxt[p][j];
				}
				ok = p == r + 1;
			}

			printf("%s\n", (ok ? "Yes" : "No"));
		}
	}

	return 0;
}

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

int main()
{
    int k,n;cin>>k>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int mx=0;
    for(int i=0;i<n;i++){
    if(i==n-1)
    mx=max(mx,k-arr[i]+arr[0]);
    else mx=max(mx,arr[i+1]-arr[i]);
    }
    cout<<k-mx<<endl;
    return 0;
}

Measured memory_bytes: 4372