akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C[100007];

int main() {
    ll A[7];
    rep(i,4){
        cin >> A[i];
    }
    sort(A,A+3);
    cout << A[0]+A[1]+A[2]*pow(2,A[3]) << 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, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

bool dfs(vector<vector<ll>>& node,vector<ll> &color, ll v, ll cor) {
	color[v] = cor;
	for (auto next_v : node[v]) {

		if (color[next_v] == cor)return false;

		if ((color[next_v] == -1) && !dfs(node, color, next_v, !cor))return false;
	}
	return true;
}

int main() {
	ll n, m, a, b;;
	map<ll, ll>mp;
	a = b = n = m = 0;
	cin >> n >> m;
	vector<vector<ll>>node(n);
	vector<ll>color(n, -1);
	rep(i, m) {
		cin >> a >> b;
		a--, b--;
		node[a].push_back(b);
		node[b].push_back(a);
	}

	if (!dfs(node,color, 0LL, 0LL)) cout << ((n * (n - 1)) / 2) - m << endl;
	else {
		for (int c : color) {
			mp[c]++;
		}
		cout << mp[0] * mp[1] - m << endl;
	}
	return 0;
}


Measured memory_bytes: 7424
#include <stdio.h>

#define N 100
#define INF 0x3f3f3f3f

int main() {
	static int aa[N];
	int n, i, j, min;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	min = INF;
	for (j = -100; j <= 100; j++) {
		int sum;

		sum = 0;
		for (i = 0; i < n; i++)
			sum += (aa[i] - j) * (aa[i] - j);
		if (min > sum)
			min = sum;
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	long long int a,b,c,d;
	
	cin>>a>>b>>c>>d;
	long long int mul;
	mul = a*c;
	mul = max(mul,a*d);
	mul = max(mul,b*c);
	mul = max(mul,b*d);
	
	cout<<mul;
	
	
	return 0;
}


Measured memory_bytes: 3632
s = gets.strip.split(//).reverse

result = s.length

done = {}
s.length.times{|i|
	c = s[i]
	next if done[c]
	max = i
	count = 0
	(1...s.length).each{|j|
		if s[j] == c
			if count > max
				max = count
			end
			count = 0
		else
			count += 1
		end
		if count > max
			max = count
		end
	}
	
	if result > max
		result = max
	end
	
	done[c] = true
}

puts result



Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(n == 0) {
        out(0);
        re0;
    }

    string ans = "";
    while(n != 0) {
        if(n%2 == 0) {
            ans = "0" + ans;
        }
        else {
            ans = "1" + ans;
            n--;
            if(n == 0) {
                break;
            }
        }
        n /= -2;
    }

    out(ans);
    re0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    long long b[n];
    fill(b,b+n,0l);
    for(int i=0; i<n; i++){
        b[a[i]-1]++;
    }
    long long sum = 0;
    for(int i=0; i<n; i++){
        sum += b[i]*(b[i]-1)/2;
    }
    for(int j=0; j<n; j++){
        int i=a[j]-1;
        cout << sum-b[i]*(b[i]-1)/2+(b[i]-1)*(b[i]-2)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = [(1, a) for a in A]

D = [ tuple(map(int, input().split(' '))) for _ in range(M)]

AD = A + D
AD.sort(key = lambda x : -x[1])

ans = 0
cnt = 0
for ad in AD :
    if N < cnt + ad[0] :
        ans += ad[1] * (N - cnt)
        break
    else :
        cnt += ad[0]
        ans += ad[1] * ad[0]

print(ans)


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

using namespace std;
typedef long long ll;

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

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

  int count= N%2 + N/2;

  cout << count << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 20 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

size_t solve(int N, const vector<vector<ii>>& xs)
{
    size_t ans = 0;

    for (int i = 0; i < (1 << N); ++i)
    {
        bitset<MAX> mask(i);
        bool ok = true;

        for (int k = 0; k < N; ++k)
        {
            if (mask[k] == 0)
                continue;


            for (auto p : xs[k])
            {
                int x = p.first, y = p.second;

                if (mask[x] != y)
                {
                    ok = false;
                    break;
                }
            }
        }

        if (ok)
            ans = max(ans, mask.count());
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<vector<ii>> xs(N);

    for (int i = 0; i < N; ++i)
    {
        int A;
        cin >> A;

        while (A--)
        {
            int x, y;
            cin >> x >> y;

            xs[i].push_back(ii(x - 1, y));
        }
    }

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    a,b,c,d = LI()
    if a+b > c+d:
        print("Left")
    elif a+b == c+d:
        print("Balanced")
    else:
        print("Right")
    return

#B
def B():
    return

#C
def C():
    x,y = LI()
    ans = 1
    for i in range(10000000000000):
        x *= 2
        if x > y:break
        ans += 1
    print(ans)

#D
def D():
    s = S()
    n = len(s)
    ans = n
    for i in range(n-1):
        if s[i] != s[i+1]:
            ans = min(ans,max(i+1,n-i-1))
    print(ans)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38512
package main

import (
	"fmt"
)

func main() {
	var a string
	var r [13]byte
	fmt.Scan(&a)
	for index, v := range a {
		if index == 4 {
			r[index] = []byte(" ")[0]
			r[index + 1] = byte(v)
		} else if index > 4 {
			r[index + 1] = byte(v)
		} else {
			r[index] = byte(v)
		}
	}
	fmt.Println(string(r[:]))
}


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

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

Measured memory_bytes: 3060
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> A(H, vector<char>(W));

  int si, sj;
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
      if (A[i][j] == 'S') {
        si = i, sj = j;
      }
    }
  }

  vector<vector<int>> dist(H, vector<int>(W, INF));
  queue<int> q;

  vector<int> di = {0, -1, 0, 1}, dj = {1, 0, -1, 0};


  dist[si][sj] = 0;
  q.push(si * W + sj);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int ci = cur / W, cj = cur % W;
    rep(d, 4) {
      int ni = ci + di[d], nj = cj + dj[d];
      if (ni < 0 || H <= ni || nj < 0 || W <= nj || A[ni][nj] == '#')
        continue;
      if (chmin(dist[ni][nj], dist[ci][cj] + 1))
        q.push(ni * W + nj);
    }
  }

  int ans = INF;
  rep(i, H) {
    rep(j, W) {
      if (dist[i][j] > K)
        continue;
      int nearest = min({i - 0, j - 0, H - 1 - i, W - 1 - j});
      int temp = 1 + (nearest + K - 1) / K;
      chmin(ans, temp);
    }
  }

  cout << ans << endl;
}

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

using namespace std;

void dfs(int curr, int appeared, string prev, int N) {
    if (curr == N) {
        cout << prev << endl;
        return;
    }

    if (curr == 0) {
        dfs(curr + 1, appeared + 1, "a", N);
    }
    else {
        for (int i = 0; i < appeared; ++i) {
            char c = 'a' + i;
            dfs(curr + 1, appeared, prev + string({ c }), N);
        }
        char c = 'a' + appeared;
        dfs(curr + 1, appeared + 1, prev + string({ c }), N);
    }
}

void Main() {
    int N;
    cin >> N;
    dfs(0, 0, "", N);
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 

ll labs(ll x) {
    if (x < 0) return -x;
    else return x;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll c = a - b;
    if (c < 0) c = -c;
    if (c % 2 == 0) {
        cout << c/2 << endl;
        return 0;
    }
    ll r = min(a-1, min(b-1, min(n - a, n - b)));
    cout << r + (c + 1) / 2 << endl;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 154 (https://atcoder.jp/contests/abc154)
// Problem: C: Distinct or Not (https://atcoder.jp/contests/abc154/tasks/abc154_c)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cpp_lib_nonmember_container_access >= 201411
#   define sz(x) ((int)size(x))
#else
#   define sz(x) ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define all(a)         (a).begin(),(a).end()
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __has_cpp_attribute(maybe_unused) >= 201603
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18;
//endregion }}}

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

    int n; cin >> n;
    vi a(n);
    trav(ai, a) cin >> ai;
    set<int> b(all(a));
    cout << (sz(a) == sz(b) ? "YES" : "NO") << '\n';

    return 0;
}

Measured memory_bytes: 10368
n,w = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(w+1,0)
for i in 1..n
  wei,val = gets.chomp.split(" ").map(&:to_i)
  for j in wei..w
    if dp[w-j]+val > dp[w-j+wei]
      dp[w-j+wei] = dp[w-j]+val
    end
  end
end
puts dp[-1]


Measured memory_bytes: 2556
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)

	fs := make(map[int]int)
	for i := 1; i <= n; i++ {
		x := i
		for j := 2; j*j <= x; j++ {
			for x%j == 0 {
				fs[j]++
				x = x / j
			}
		}
		if x != 1 {
			fs[x]++
		}
	}

	mod := 1000000007
	ans := 1
	for _, v := range fs {
		ans = ans * (v + 1) % mod
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000000
#define nINF -1
int parent(int);
int left(int);
int right(int);
void maxHeapify(int*, int);
void buildMaxHeap(int*);
void insert(int*, int);
void heapIncreaseKey(int*, int);
int extractMax(int*);
int n=0;
int main(){
  int *T, key;
  char func[7];
  T = (int*)malloc(sizeof(int) * MAX);
  while(1){
    scanf("%s",func);
    if(func[2] == 'd') break;
    else if(func[0] == 'i'){
      scanf("%d",&key);
      insert(T, key);
    }
    else if(func[0] == 'e') printf("%d\n",extractMax(T));
  }
  return 0;
}
int parent(int x){
  return x/2;
}
int left(int x){
  return 2*x;
}
int right(int x){
  return 2*x+1;
}
  void maxHeapify(int *A, int i){
    int l=left(i), r=right(i), largest, temp;
    if(l <= n && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= n && A[r] > A[largest]) largest = r;
    if(largest != i){
      temp = A[i];
      A[i] = A[largest];
      A[largest] = temp;
      maxHeapify(A,largest);
    }
  }
  void buildMaxHeap(int *A){
    int i;
    for(i=n/2; i>0; i--) maxHeapify(A,i);
  }
  void insert(int *A, int key){
    n++;
    A[n] = nINF;
    heapIncreaseKey(A, key);
  }
  void heapIncreaseKey(int *A, int key){
    int temp, i=n;
    if(key < A[i]) printf("Error\n");
    A[i] = key;
    while(i > 1 && A[parent(i)] < A[i]){
      temp = A[i];
      A[i] = A[parent(i)];
      A[parent(i)] = temp;
      i = parent(i);
    }
  }
  int extractMax(int *A){
    int max;
    if(n < 1) printf("Error\n");
    max = A[1];
    A[1] = A[n];
    n--;
    maxHeapify(A,1);
    return max;
  }

Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl

int main() {
  int A, B, C;
  ci3(A, B, C);
  if(C - A + B > 0) {
    co(C - A + B);
  }
  else {
    co(0);
  }
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int ret=0;
	stack<char> stk;
	for (const char &ch : s)
		if(stk.empty()) stk.push(ch);
		else {
			if(stk.top()==ch) stk.push(ch);
			else stk.pop(), ret+=2;
		}
	cout<<ret<<"\n";
	return 0;
}

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

using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	long long ans1 = 0;
	long long ans2 = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] > x)
		{
			ans1 += a[i] - x;
			ans2 = ans1;
			a[i] -= a[i] - x;
		}
	}
	
	for(int i = 0; i < n - 1; i++)
	{
		long tmp = a[i];
		if(tmp + a[i + 1] > x)
		{
			ans1 += tmp + a[i + 1] - x;
		}			
	}
	
	for(int i = 1; i < n; i++)
	{
		long tmp = a[i];
		if(tmp + a[i - 1] > x)
		{
			ans2 += tmp + a[i - 1] - x;
			a[i] -= tmp + a[i - 1] - x;  
		}			
	}
	
	cout << (ans1 < ans2 ? ans1 : ans2) << endl;
	return 0;
}

Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL 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;
}


int main(){
    int N;
    cin >> N;
    string s[N];
    int t[N];
    REP(i,N) cin >> s[i] >> t[i]; 
    string X;
    cin >> X;
    int ans=0,sum=0;
    for(int i=0;i<N;++i){
        sum+=t[i];
    }
    
    for(int i=0;i<N;++i){
        if(s[i]!=X){
            ans+=t[i];
        }
        else{
            ans+=t[i];
            break;
        }
    }
    cout << sum-ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int count=0,out=0;
  str w;
  cin>>w;
  rep(0,w.size()){
    REP(0,w.size()){
      if(w.at(i)==w.at(j))count+=1;
    }
    if(count%2!=0){
      out=1;
      break;
    }
    count=0;
  }
  if(out==1)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
typedef vector<ll> vll;
#define rall(s) s.rbegin(),s.rend()
typedef map<ll,ll> mll;
#define fr(n,x) for(ll n=0;n<x;n++)
#define pb push_back
#define EL cout<<'\n'
#define all(s) s.begin(),s.end()

void solve(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	ll x,y,r,p,sc,n,k,res=0;
	cin>>x>>y;
	cout<<6-(x+y);
}

int main(){
    ll T=1;
    //cin>>T;
    while(T--)solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

struct Edge {
  int src, dst;
  Edge(int src, int dst) : src(src), dst(dst) {}
};
bool operator<(const Edge& e, const Edge& f) {
  return e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool augment(const Graph& g, int u, vector<int>& matchTo,
             vector<bool>& visited) {
  if (u < 0) return true;
  for (auto& e : g[u])
    if (!visited[e.dst]) {
      visited[e.dst] = true;
      if (augment(g, matchTo[e.dst], matchTo, visited)) {
        matchTo[e.src] = e.dst;
        matchTo[e.dst] = e.src;
        return true;
      }
    }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  for (int u = 0; u < L; u++) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  for (int u = 0; u < L; u++)
    if (matchTo[u] >= 0)  // make explicit matching
      matching.push_back(Edge(u, matchTo[u]));
  return match;
}

int main() {
  int N;
  while (cin >> N) {
    vector<pair<int, int>> red(N), blue(N);
    for (int i = 0; i < N; i++) {
      cin >> red[i].first >> red[i].second;
    }
    for (int i = 0; i < N; i++) {
      cin >> blue[i].first >> blue[i].second;
    }
    Graph g(2 * N);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (red[i].first < blue[j].first && red[i].second < blue[j].second) {
          g[i].push_back({i, N + j});
        }
      }
    }
    Edges edges;
    cout << bipartiteMatching(g, N, edges) << endl;
  }
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int) n; ++i)
#define FOR(i, m, n) for(int i = (int) m; i < (int) n; ++i)
const int MOD = 1e+9 +7;


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> S(N+1), T(M+1);
    FOR(i, 1, N+1) cin >> S[i];
    FOR(i, 1, M+1) cin >> T[i];

    // dp[i][j]: S[:i] と T[:j] について、S[i], T[j] を含む共通部分列の数
    // cum_sum[i][j]: dp[1][1] ~ dp[i][j] の和
    vector<vector<long long>> dp(N+1, vector<long long>(M+1)), cum_sum(N+1, vector<long long>(M+1));
    FOR(i, 1, N+1){
        FOR(j, 1, M+1){
            if(S[i] == T[j]) dp[i][j] = (cum_sum[i-1][j-1]+1) % MOD;
            cum_sum[i][j] = (cum_sum[i-1][j]+cum_sum[i][j-1]-cum_sum[i-1][j-1]+dp[i][j]) % MOD;
            // cout << i << j << " " << dp[i][j] << " " << cum_sum[i][j] << endl;
        }
    }
    cout << (1+cum_sum[N][M]+MOD)%MOD << endl;

    return 0;
}

Measured memory_bytes: 62976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll MAX = 1000000007;

int main() {
    vector<vector<int>> a(3, vector<int>(3));

    for (int i=0; i<3; ++i) {
        for (int j=0; j<3; ++j) {
            cin >> a[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);

    for (int k=0; k<N; ++k){
        cin >> b[k];


        for (int i=0; i<3; ++i) {
            for (int j=0; j<3; ++j) {
                if (a[i][j]==b[k]) a[i][j] =-1;
            }
        }
    }

    // たて
    for (int i=0; i<3; ++i) {
        if (a[i][0] + a[i][1] + a[i][2]==-3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i=0; i<3; ++i) {
        if (a[0][i] + a[1][i] + a[2][i]==-3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    int sum = 0;
    for (int i=0; i<3; ++i) {
        sum += a[i][i];
    }
    if (sum==-3) {
        cout << "Yes" << endl;
        return 0;
    }
    if (a[0][2] + a[1][1] + a[2][0]==-3) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

}

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

int main()
{
    int r, c;
    int t[101][101] = {0};
    int i, j, sum = 0;
    cin >> r >> c;

    for (i = 0; i < r; i++)
        for (j = 0; j < c; j++)
            cin >> t[i][j];

    for (i = 0; i < r; i++)
    {
        for (j = 0; j < c; j++)
            t[i][c] += t[i][j];
    }
    for (j = 0; j < c; j++)
    {
        for (i = 0; i < r; i++)
            t[r][j] += t[i][j];
        sum += t[r][j];
    }   
    t[r][c] = sum;

    for (i = 0; i <= r; i++)
    {
        for (j = 0; j <= c; j++)
        {
            if (j) cout << " ";
            cout << t[i][j];
        }
        cout << endl;
    } 
    return 0;
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int r;
	cin >> r;

	out(3 * r * r);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<ll>vec(n);
  vec[0]=0;
  rep(i,n-1){
    if(s[i]=='A' && s[i+1]=='C'){
      vec[i+1]=vec[i]+1;
    }
    else vec[i+1]=vec[i];
  }
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;
    r--;
    cout <<vec[r]-vec[l]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(){
  int n;
  int l[10];
  scanf("%d",&n);
  int max = 0;
  int maxid;
  for(int i=0;i<n;i++){
    scanf("%d",l+i);
    if(l[i] > max){
      max = l[i];
      maxid = i;
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(i != maxid) sum+=l[i];
  }
  if(sum > max) printf("Yes");
  if(sum <= max) printf("No");
  return 0;
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll K,A,B;bool tf=false;
    cin >> K;
    cin >> A >> B;
    for(int i = 0; i<1000;i++){
        if(K*i>=A&&K*i<=B){
            tf = true;
            break;
        }
    }
    if(tf){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    int ans = 0;
    int ma = 0;
    rep(i,n){
        int a; cin >> a;
        ma = max(ma,a);
        ans += a;
    }
    cout << ans - ma / 2 << endl;
}

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

int main(){
  int x;
  cin >> x;
  int k = 1;
  while(1){
    if((k * x) % 360 == 0){
      cout << k << endl;
      exit(0);
    }
    k++;
  }
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
int cmpfunc(const void*a,const void*b)
{
    if((*(int*)a - *(int*)b)>0)
    {
        return 1;
    }
    if((*(int*)a - *(int*)b)<0)
    {
        return -1;
    }
    if(*(int*)a == *(int*)b)
    {
        return 0;
    }
    
}
int main(void)
{
    int n,d[100],count=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&d[i]);
    }
    qsort(d,n,sizeof(d[0]),cmpfunc);
    /*for(int i=0;i<n;i++)
    {
        printf("%d\n",d[i]);
    }*/
    for(int i=0;i<(n-1);i++)
    {
        if(d[i] != d[i+1])
        {
            count++;
        }
    }
    printf("%d",count);

}

Measured memory_bytes: 128
mod = 998244353

n,s = map(int, input().split())
a = list(map(int, input().split()))

table = [0]*(s+1)
table[0] = 1
for ai in a:
    nxt = [0]*(s+1)
    if ai <= s:
        for j in range(ai, s+1):
            nxt[j] = table[j-ai]
    table = [(2*table[i] + nxt[i])%mod for i in range(s+1)]
ans = table[-1]
print(ans)


Measured memory_bytes: 73556
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;


void solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	map<lli, lli> memo;
	for (int i = 0; i < N; i++) {
		memo[A[i]]++;
	}
	lli all = 0;
	for (auto kv : memo) {
		lli value = kv.second;
		if (value >= 2) {
			all += (value * (value - 1)) / 2;
		}
	}

	for (int k = 0; k < N; k++) {
		lli ans = all;
		lli value = memo[A[k]];
		if (value != 1) {
			lli d_value = (value * (value - 1)) / 2;
			ans -= d_value;
			d_value = ((value - 1) * (value - 2)) / 2;
			ans += d_value;
		}
		cout << ans << endl;
	}


}

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

Measured memory_bytes: 10240
N,A,B=map(int,input().split())

if N==1:
  if A==B:
    print(1)
  else:
    print(0)
else:
  if A>B:
    print(0)
  else:
    sum_max=A+B+(N-2)*B
    sum_min=A+B+(N-2)*A
    print(sum_max-sum_min+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 +7;
//constexpr int mod2 = 998244353;
constexpr int MAXNe5 = 1e5 +7;
constexpr int MAXNe6 = 1e6 + 7;
#pragma region 
inline long long read()
{
	char c = getchar();long long flag = 1, ans = 0;
	while(c < '0' || c > '9'){if(c == '-')flag = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ans = ans * 10 + c - '0'; c = getchar();}
	return (ans * flag);
}
#pragma endregion
// C'est la vie
int main() {
	long long N = read(), a = read(), b = read();
    cout << N / (a + b) * a + (N % (a + b) >= a ? a : N % (a + b));
    #ifndef ONLINE_JUDGE
    system("pause");
    #endif
}

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

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

int main() {
	ll n;
	ll buf;
	int i, j, k;
	int count = 0;
	cin >> n;
	buf = pow(n, 0.5);
	for (i = 2; i <= buf;i++) {
		if (n == 1)break;
		j = 0;
		while (n % i == 0) {
			n /= i;
			j++;
		}
		k = 1;
		while (j >= k) {
			count++;
			j -= k;
			k++;
		}
	}
	if (n != 1)count++;
	cout << count << endl;
	return 0;
}

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

// ll cnt_at(ll hp, int depth) {
//     if(hp > 1){
//         depth++;
//         return pow(2, depth)*cnt_at(hp / 2, depth);
//     }
//     else{
//         return pow(2, depth);
//     }
// }

ll rec(ll hp) {
    if (hp == 1) return 1;
    ll ans = rec(hp / 2) * 2 + 1;
    return ans;
}

int main() {
    ll hp;
    cin >> hp;
    // int depth = 0;
    ll ans = rec(hp);
    // while(hp > 0){
    //     ans += pow(2, depth);
    //     hp /= 2;
    //     depth++;
    // }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

string s;
int A, B, C, D;
int main()
{
	cin >> s;
	A = s[0] - '0';
	B = s[1] - '0';
	C = s[2] - '0';
	D = s[3] - '0';

	REP(i, 0, 8) {
		int ans = 0;
		bool f1, f2, f3;
		if ((i & 1) == 1) {
			ans = A + B;
			f1 = true;
		}
		else {
			ans = A - B;
			f1 = false;
		}

		if ((i>>1 & 1) == 1) {
			ans += C;
			f2 = true;
		}
		else {
			ans -= C;
			f2 = false;
		}

		if ((i>>2 & 1) == 1) {
			ans += D;
			f3 = true;
		}
		else {
			ans -= D;
			f3 = false;
		}

		if (ans == 7) {
			cout << A;
			if (f1) cout << "+";
			else cout << "-";

			cout << B;
			if (f2) cout << "+";
			else cout << "-";

			cout << C;
			if (f3) cout << "+";
			else cout << "-";

			cout << D;

			cout << "=" << 7 << endl;
			
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
a =[0]*(n+1)
for k in range(1,n+1):
  m = n
  for x in s:
    if x <= k:
      m = min(m, a[k-x]+1)
  a[k]=m   
print(a[n])

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

using namespace std;

typedef long long ll;

vector<vector<int>> g(100010,vector<int>(0));
vector<int> ans(100010,-1);
int dp(int x){
	if(ans[x] >= 0)return ans[x];
	int sz = g[x].size();
	if(sz == 0) return ans[x] = 0;
	vector<int> res(sz,0);
	for (int i = 0; i < sz; ++i)
	{
		res[i] = dp(g[x][i]);
	}

	sort(res.begin(),res.end());
	for (int i = 0; i < sz; ++i)
	{
		res[i] += sz - i;
	}
	sort(res.begin(),res.end());
	return 	ans[x] = res[sz-1];
}

int main(int argc, char const *argv[])
{
	int n;scanf("%d",&n);
	for (int i = 0; i < n-1; ++i)
	{
		int a;scanf("%d",&a);
		a--;
		g[a].push_back(i+1);
	}
	printf("%d\n",dp(0));
	return 0;
}

Measured memory_bytes: 18560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		List<Integer> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			list.add(in.nextInt());
		}
		in.close();

		int count = 1;
		int before = list.get(0);
		int now;
		for (int i = 1; i < list.size(); i++) {
			now = list.get(i);
			if (before < now) {
				before = now;
				for (i++; i < list.size(); i++) {
					now = list.get(i);
					if (before > now) {
						count++;
						break;
					}
					before = now;
				}
			} else if (before > now) {
				before = now;
				for (i++; i < list.size(); i++) {
					now = list.get(i);
					if (before < now) {
						count++;
						break;
					}
					before = now;
				}
			} else if (before == now) {
				continue;
			} else {
				count++;
			}
			before = now;
		}
		System.out.println(count);
	}

}

// 10
// 9 8 7 6 3 2 1 1 1 1

Measured memory_bytes: 60652
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;


void yes(){
   cout<<"Yes";
   // exit(0);
}

void no(){
   cout<<"No";
   // exit(0);
}


int n, m;
string s, t;

int32_t main(){_
   
   cin >> n;
   vector<int> a(n);

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

   int ans = 0;

   int mx = a[0];
   for (int i = 1; i < n; ++i)
   {
      ans += max(mx - a[i], 0LL);
      mx = max(mx, a[i]);
   }


   cout<<ans;

   return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main (){
string s;
cin>>s;
int i;
int m=114514,x;
for(i=0;i<s.length()-2;i++){
x=ctoi(s[i])*100+ctoi(s[i+1])*10+ctoi(s[i+2]);
m=min(m,abs(753-x));
}
cout<<m;
return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    ll now = 1;
    for (int i = 0; i < N; i++) {
        ll a; cin >> a;
        if(now == a){
            now++;
        }
    }
    now--;
    if(now == 0){
        cout << "-1" << endl;
    } else {
        cout << N-now << endl;
    }
}

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

using namespace std;

int main()
{
	int N, K;

	cin >> N >> K;

	double R = 0;
	for ( int d = 1; d <= N; d ++ ) {

		double r;
		r = 1.0 / N;
		int v = d;
		while ( 1 ) {
			if ( v >= K ) break;
			v *= 2;
			r /=2;
		}

//		r *= pow( 0.5, a );
// cout << r << endl;
		R+= r;
	}

	cout.precision(12);
	cout << R << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    a[i]=make_pair(b,i+1);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout << a[i].second << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1664
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<pair<int, int>, int> tup;

inline void solve()
{
	int n, m;
	cin >> n >> m;
	vector<vector<char>> g(n, vector<char>(m));
	fore(i, 0, n)
		fore(j, 0, m)
	{
		cin >> g[i][j];
	}

	int otv = 0;

	fore(i, 0, n)
	{
		fore(j, 0, m)
		{
			fore(k, 0, n)
			{
				fore(h, 0, m)
				{
					if (g[i][j] != '#' && g[k][h] != '#')
					{
						vector<vector<bool>> used(n, vector<bool>(m, 0));
						queue<tup> q;
						q.push({ {i,j}, 0 });

						while (q.size())
						{
							tup v = q.front();
							q.pop();

							if (v.first.first < 0 || v.first.first >= n || v.first.second < 0 || v.first.second >= m || used[v.first.first][v.first.second] || g[v.first.first][v.first.second] == '#')
							{
								continue;
							}
							used[v.first.first][v.first.second] = 1;

							if (v.first.first == k && v.first.second == h)
							{
								otv = max(otv, v.second);
								break;
							}

							q.push({ { v.first.first + 1, v.first.second }, v.second + 1 });
							q.push({ { v.first.first - 1, v.first.second }, v.second + 1 });
							q.push({ { v.first.first, v.first.second + 1}, v.second + 1 });
							q.push({ { v.first.first, v.first.second - 1}, v.second + 1 });
						}
					}
				}
			}
		}
	}
	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            long result = 0;
            int n = sc.nextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                a.add(sc.nextInt());
            }
            Collections.sort(a);
            int latestNum = -1;
            for (int i = a.size() - 1; i >= 0; i--) {
                int Num = a.get(i);
                if (Num != latestNum) {
                    latestNum = Num;
                    result++;
                } else {
                    latestNum = -1;
                    result--;
                }
            }
            return result;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}


Measured memory_bytes: 51164
A,B,C=map(int, input().split())
K = int(input())

import math
b=0

if B>A:
	b=0
elif 2*B>A:
	b=1
	B=2*B
elif 4*B>A:
	b=2
	B=4*B
else:
	b=3
	B=8*B

c=0
if C>B:
	c=0
elif 2*C>B:
	c=1
elif 4*C>B:
	c=2
elif 8*C>B:
	c=3
elif 16*C>B:
	c=4
elif 32*C>B:
	c=5
else:
	c=6



if b+c<=K:
	print("Yes")
else:
	print("No")



# 2darray [[0] * 4 for i in range(3)]

Measured memory_bytes: 9100
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll res = 0;
    ll jtmp = 0, itmp = 0, tmp = 0, ma = 0;
    ll jcnt = 0, icnt = 0;
    rep(i, N) {
        if(S[i] == 'I')
            icnt++;
    }
    rep(i, N) {
        if(S[i] == 'J')
            jcnt++;
        if(S[i] == 'I')
            icnt--;
        if(S[i] == 'O') {
            jtmp += (jcnt + 1) * icnt;
            itmp += jcnt * (icnt + 1);
            tmp += jcnt * icnt;
        }
        ma = max(ma, jcnt * icnt);
    }
    cout << max(jtmp, max(itmp, tmp + ma)) << endl;
    return 0;
}


Measured memory_bytes: 3292