akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
int n,m,s,t,A[N],used[N],depth[N];
vector<int> G[N];
vector<P> ans;

void dfs(int x,int d,int prev){
  depth[x]=d;
  for(int i=0;i<G[x].size();i++){
    int nx=G[x][i];
    if(nx==prev)continue;
    if(!used[nx]){
      used[nx]=true;
      dfs(nx,d+1,x);
      if(!A[nx])
	ans.push_back(P(min(x,nx),max(x,nx)));
      A[x]+=A[nx];
    }
    else if(d>depth[nx]){
      A[nx]--;
      A[x]++;
    }    
  }
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  used[0]=1;
  dfs(0,0,0);
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++)
    cout<<ans[i].first<<' '<<ans[i].second<<endl;
  return 0;
}

Measured memory_bytes: 7260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100005
vector<int> v;
unordered_set<int> s;
int dp[N];
int min_k;

// returns whether first person wins
// false = first person
// true = second person
bool search(int k, bool p) {
    if (k < 0) {
        return p == false;
    }
    if (k == 0) {
        return p == true;  
    }
    if (dp[k] != -1) {
        return dp[k]^p;
    } 
    bool r;
    if (p == true) {
        r = true;
        for (auto e : s) {
            r = min(r, search(k - e, !p));
        } 
        dp[k] = r^1;
        return r;
    } else {
        r = false;
        for (auto e : s) {
            r = max(r, search(k - e, !p));
        }
        dp[k] = r;
        return r;
    }
    return r;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k, e;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> e;
        v.push_back(e);
        s.insert(e);
    }
    memset(dp, -1, sizeof(dp));
    bool r = search(k, false);
    if (r == true) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
    return 0;
}


Measured memory_bytes: 5376
n=int(input())
s=[]
for _ in range(n):
    s.append(int(input()))
# print(n)
# print(s)
i=1
cnt=1
ans=0
s.sort()
# print(s)

tmp=s[0]
for i in range(1,n):
    # print(s[i])
    if tmp==s[i]:
        cnt+=1
    else:
        tmp=s[i]
        if cnt % 2 == 1:
            ans+=1
        cnt=1
    if i==n-1 and cnt%2==1:
        ans+=1

print(ans)


Measured memory_bytes: 50520
#include<iostream>

int main()
{
	int m[100], f[100], r[100];
	int count = 0;

	for (int i = 0; ; i++) {
		std::cin >> m[i] >> f[i] >> r[i];
		count++;
		if (m[i] == -1 && f[i] == -1 && r[i] == -1) {
			count--;
			break;
		}
	}

	for (int i = 0; i < count; i++) {
		if (m[i] == -1 || f[i] == -1)
			std::cout << "F" << std::endl;
		else if (m[i] + f[i] >= 80)
			std::cout << "A" << std::endl;
		else if (m[i] + f[i] < 80 && m[i] + f[i] >= 65)
			std::cout << "B" << std::endl;
		else if (m[i] + f[i] < 65 && m[i] + f[i] >= 50)
			std::cout << "C" << std::endl;
		else if (m[i] + f[i] < 50 && m[i] + f[i] >= 30 && r[i] < 50)
			std::cout << "D" << std::endl;
		else if (m[i] + f[i] < 50 && m[i] + f[i] >= 30 && r[i] >= 50)
			std::cout << "C" << std::endl;
		else if (m[i] + f[i] < 30)
			std::cout << "F" << std::endl;
	}
}

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

#define INF (1<<26)
struct edge{int to,cost,key;};
struct state{
  int pos,pos2,S,cost;  
  bool operator < (const state &p)const{    return cost > p.cost;  }
};

vector<edge> g[200];
int N,M,E,Si,Ti,R;
int c[200];
vector<int> nodes;
int dp[105][105];
int d[105][205][300];

void solve(){
  for(int i=0;i<105;i++)
    for(int j=0;j<205;j++)
      for(int k=0;k<300;k++)
	d[i][j][k]=INF;

  priority_queue<state> Q;
  int a=0;
  if(c[Si]!=-1)a=(1<<c[Si]);
  Q.push((state){Si,0,a,0});
  d[Si][0][a]=0;

  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(d[s.pos][s.pos2][s.S]<s.cost)continue;
    if(s.pos==Ti){cout<<s.cost<<endl;return;}
    if(s.pos2>R)continue;
    if(d[Si][0][s.S]>s.cost+1){
      d[Si][0][s.S]=s.cost+1;
      Q.push((state){Si,0,s.S,s.cost+1});
    }

    for(int i=0;i<(int)nodes.size();i++){      
      int to=nodes[i];
      if(dp[s.pos][to]==INF)continue;
      int ncost=s.cost+dp[s.pos][to];
      int nS=s.S;
      int npos2=s.pos+dp[s.pos][to];
      if(c[to]!=-1)nS|=(1<<c[to]);
      if(d[to][npos2][nS]<=ncost)continue;
      d[to][npos2][nS]=ncost;
      Q.push((state){to,npos2,nS,ncost});
    }
    
    for(int i=0;i<(int)g[s.pos].size();i++){
      edge e=g[s.pos][i];
      if(!((s.S>>e.key)&1))continue;
      int to=e.to;
      int ncost=s.cost+e.cost;
      int nS=s.S;
      int npos2=s.pos+e.cost;
      if(c[to]!=-1)nS|=(1<<c[to]);
      if(d[to][npos2][nS]<=ncost)continue;
      d[to][npos2][nS]=ncost;
      Q.push((state){to,npos2,nS,ncost});
    }
  }
  cout<<-1<<endl;
}

int main(){
  for(int i=0;i<105;i++){
    c[i]=-1;
    for(int j=0;j<105;j++)dp[i][j]=(i==j?0:INF);
  }

  cin>>N>>M>>E>>Si>>Ti>>R;
  int x,y,z;
  for(int i=0;i<M;i++){
    cin>>x>>y;
    dp[x][y]=dp[y][x]=min(dp[x][y],1);
  }

  for(int i=0;i<E;i++){
    cin>>x>>y>>z;
    g[x].push_back((edge){y,1,i});
    g[y].push_back((edge){x,1,i});
    c[z]=i;
    nodes.push_back(x);
    nodes.push_back(y);
    nodes.push_back(z);
  }
  nodes.push_back(Si);  nodes.push_back(Ti);
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);

  solve();
  return 0;
}

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

using namespace std;

using ll = long long;

constexpr ll MOD = 998244353;

ll dp[3005][3005];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll ans = 0;
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= s; ++j) {
            dp[i + 1][j] = dp[i][j];
            if (j >= a[i]) {
                ll hoge = dp[i][j - a[i]] * (j == a[i] ? i + 1 : 1) % MOD;
                (dp[i + 1][j] += hoge) %= MOD;
                if (j == s) (ans += hoge * (n - i) % MOD) %= MOD;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 70656
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N = int(input())
G = [[] for _ in range(N+1)]
degree = [0] * (N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
    degree[a] += 1
    degree[b] += 1
c = list(map(int, input().split()))
c.sort(reverse=True)

heap = []
for i in range(1, N+1):
    heappush(heap, (degree[i], i))

M = 0
num = [0] * (N+1)
while heap:
    d, i = heappop(heap)
    if num[i] != 0:
        continue
    num[i] = c.pop()
    for j in G[i]:
        if num[j] == 0:
            M += num[i]
            degree[i] -= 1
            degree[j] -= 1
            heappush(heap, (degree[j], j))
print(M)
print(' '.join(map(str, num[1:])))

Measured memory_bytes: 64092
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n = inp[0]
a = [0]+inp
t = na(n+1,0)
ans = []
((n/2+1)..n).each do |i|
  if(1 == a[i])
    t[i] = 1
    ans.push(i)
  end
end
(1..(n/2)).reverse_each do |i|
  d = i+i
  c = 0
  while d <= n
    c += t[d]
    d += i
  end
  if(c%2 != a[i])
    t[i] = 1
    ans.push(i)
  end
end
puts ans.size
puts ans.join(" ") if(ans.size > 0)

Measured memory_bytes: 24652
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const long long UNKNOWN = LLONG_MAX;

class UnionFindTree
{
    int n;
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    vector<long long> weight;
    int find(int x){
        if(parent[x] == x)
            return x;

        int y = find(parent[x]);
        weight[x] += weight[parent[x]];
        parent[x] = y;
        return y;
    }
public:
    UnionFindTree(int n0){ // コンストラクタ
        n = n0;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
        weight.assign(n, 0);
    }
    void unite(int x, int y, long long w){ // xとyのグループを併合
        int x2 = find(x);
        int y2 = find(y);
        if(x2 != y2){
            if(rank[x2] < rank[y2]){
                parent[x2] = y2;
                num[y2] += num[x2];
                weight[x2] = w - weight[x] + weight[y];
            }else{
                parent[y2] = x2;
                if(rank[x2] == rank[y2])
                    ++ rank[x2];
                num[x2] += num[y2];
                weight[y2] = -w - weight[y] + weight[x];
            }
            -- n;
        }
    }
    long long same(int x, int y){ // xとyのグループが同じかを調べる
        if(find(x) == find(y))
            return weight[x] - weight[y];
        else
            return UNKNOWN;
    }
};

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        UnionFindTree uft(n+1);
        while(--m >= 0){
            char c;
            int a, b;
            cin >> c >> a >> b;

            if(c == '!'){
                long long w;
                cin >> w;
                uft.unite(a, b, w);
            }else{
                long long ret = uft.same(a, b);
                if(ret == UNKNOWN)
                    cout << "UNKNOWN" << endl;
                else
                    cout << ret << endl;
            }
        }
    }
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int c1,c2;
    string s;
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            c1=i+1;
            break;
        }
    }
    for(int i=0;i<l;i++)
    {
        if(s[i]=='Z')
        {
            c2=i+1;
        }
    }
    cout<<c2-c1+1<<endl;
    return 0;
}

Measured memory_bytes: 832
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N = int(input())
S = input()


# In[15]:


cnt = S[1:].count("E")
ans = cnt
for i in range(1,N):
    if S[i] == "E":
        if S[i-1] == "E":
            cnt -= 1
    else:
        if S[i-1] == "W":
            cnt += 1
    ans = min(ans,cnt)
print(ans)


# In[ ]:






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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n-1];
    int b[n+1]={0};
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=n;i++)
        cout<<b[i]<<endl;
    return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

struct edge{
    int to, cost;
};

double p;
int n;
vector<edge> G[100010];
double x[100010];

void dfs(int pos, int prev){
    x[pos] = 0;
    for(int i = 0; i < G[pos].size(); i++){
        edge e = G[pos][i];
        if(e.to == prev) continue;
        dfs(e.to, pos);
        x[pos] += (double)(x[e.to] + e.cost) * p;
        cout << x[pos] << endl;
    }
}

double solve(int pos, int prev){
    double res = x[0];
    for(int i = 0; i < G[pos].size(); i++){
        edge e = G[pos][i];
        if(e.to == prev) continue;
        res += (solve(e.to, pos) + (double)e.cost) * p;
    }
    return res;
}

signed main(){
    cin >> p >> n;
    rep(i, 0, n - 1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a]. push_back((edge){b, c});
        G[b]. push_back((edge){a, c});
    }
    dfs(0, -1);
    // rep(i, 0, n){
    //     printf("%.10lf\n", x[i]);
    // }
    printf("%.10lf\n", solve(0, -1));
}

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

int main() {
    int n, q;
    std::cin >> n >> q;

    std::vector<std::queue<int>> queues{};
    queues.resize(n);
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        int t;
        switch (kind) {
            case 0:
                int x;
                std::cin >> t >> x;
                queues[t].push(x);
                break;
            case 1:
                std::cin >> t;
                if (queues[t].size() != 0)
                    std::cout << queues[t].front() << std::endl;
                break;
            case 2:
                std::cin >> t;
                if (queues[t].size() != 0) queues[t].pop();
                break;
            default:
                std::cerr << "strange kind" << std::endl;
        }
    }
}


Measured memory_bytes: 4448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    ll res = 1;
    for(int i = 0; i < N;i++){
        res = min(res*2,res+ K);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
	
	int n, ans = 0;
	cin >> n;

	vector<int> v(n);
	vector<int> c(n);

	for (int i = 0; i < n; i++){ cin >> v.at(i); }

	for (int i = 0; i < n; i++){ cin >> c.at(i); }

	for (int i = 0; i < n; i++){
		if (v.at(i) - c.at(i)>0){
			ans += v.at(i) - c.at(i);
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
 
int N,K,Q,a;
cin >>N>>K>>Q;
  
 vector<int> A(N,K-Q);
 for(int i=0; i<Q; i++){cin>>a;A[a-1]++;}
for(int i=0; i<N; i++){if(A[i]>0)cout<<"Yes"<<endl;
                       else cout<<"No"<<endl;}
}


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

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

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int ans = 0;
    int cnt = 0;
    for(int i = 1; i < n; i++){
        if(a[i-1] >= a[i]) cnt++;
        else cnt = 0;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

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

typedef long long ll;
const ll INF = (ll)1e18 + 1;

int main()
{
  ll N;
  std::cin >> N;

  ll ans = INF;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) ans = std::min(ans, N / i + i - 2);
  }

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


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
int x[110];
int y[110];
ll h[110];

int main () {
  cin >> N;

  rep(i, N) cin >> x[i] >> y[i] >> h[i];

  Rep(cx, 101) {
    Rep(cy, 101) {
      ll kouho = -1;

      rep(i, N) {
        if (h[i] != 0) {
          kouho = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
        }
      }

      bool flg = true;

      rep(i, N) {
        ll tmp = max(kouho - abs(x[i] - cx) - abs(y[i] - cy), 0LL);
        if (tmp != h[i]) {
          flg = false;
          break;
        }
      }

      if (flg) {
        cout << cx << " " << cy << " " << kouho << "\n"; 
      }
    }
  }
}

Measured memory_bytes: 764
<?php
    list($n, $m, $l) = explode(" ", trim(fgets(STDIN)));

    for($i = 0; $i < $n; $i++){
        $a[$i] = explode(" ", trim(fgets(STDIN)));
    }
    for($i = 0; $i < $m; $i++){
        $b[$i] = explode(" ", trim(fgets(STDIN)));
    }

    $c = array_fill( 0, $n, array_fill(0, $l,0));

    for($i = 0; $i < $n; $i++){
        for($j = 0; $j < $l; $j++){
            for($k = 0; $k < $m; $k++){
                $c[$i][$j] += $a[$i][$k] * $b[$k][$j];
            }    
        }
    }
    
    foreach($c as $value){
        print implode(" ",$value)."\n";        
    }

Measured memory_bytes: 20512
n=int(input())
p=list(map(int,input().split()))
# 数字xのあるidxを取得するdict
dn={x:i for i,x in enumerate(p)}

def segfunc(x, y):
    return x+y
ide_ele = 0
class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

st=SegTree([0]*n,segfunc,0)
ans=0
st.update(dn[n],1)
for i in range(n-1,0,-1):
    # 左が0となる最大のidxを検索
    l,r=0,dn[i]
    while r-l>1:
        x=(l+r)//2
        if st.query(x,dn[i]+1)>0:
            l,r=x,r
        else:
            l,r=l,x
    l0=l if st.query(l,dn[i]+1)==0 else r
    # 左が1となる最大のidxを検索。l0=0なら存在しない
    if l0==0:
        l1=-1
    else:
        l,r=0,l0
        while r-l>1:
            x=(l+r)//2
            if st.query(x,dn[i]+1)>1:
                l,r=x,r
            else:
                l,r=l,x
        l1=l if st.query(l,dn[i]+1)==1 else r
    # 右が0となる最小のidxを検索
    l,r=dn[i],n-1
    while r-l>1:
        x=(l+r)//2
        if st.query(dn[i],x+1)>0:
            l,r=l,x
        else:
            l,r=x,r
    r0=r if st.query(dn[i],r+1)==0 else l
    # 右が1となる最小のidxを検索。r0=n-1なら存在しない
    if r0==n-1:
        r1=-1
    else:
        l,r=r0,n-1
        while r-l>1:
            x=(l+r)//2
            if st.query(dn[i],x+1)>1:
                l,r=l,x
            else:
                l,r=x,r
        r1=r if st.query(dn[i],r+1)==1 else l
    if l1!=-1:
        ans+=(l0-l1)*(r0-dn[i]+1)*i
    if r1!=-1:
        ans+=(dn[i]-l0+1)*(r1-r0)*i
    st.update(dn[i],1)
print(ans)


Measured memory_bytes: 102772
def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 'APPROVED'
    for i in range(n):
        if a[i] % 2 == 0:
            if a[i] % 3 != 0 and a[i] % 5 != 0:
                ans = 'DENIED'
                break

    print(ans)


main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n,x,t,z;
    cin>>n>>x>>t;
    if (n%x==0)
    {
    	z=(n/x)*t;
	}
	else
	{
		z=(n/x +1)*t;
	}
	cout<<z<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, x[50];
// i番目まででj枚選んで合計がsになるような選び方
ll dp[55][55][2555], ans;

int main() {
	cin >> n >> a;
	rep(i,n) cin >> x[i];
	
	dp[0][0][0] = 1;
	repst(i,1,n) {
		rept(j,i) {
			rept(k,50*i) {
				if (j==0 || k<x[i-1]) dp[i][j][k] = dp[i-1][j][k];
				else dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
			}
		}
	}
	repst(i,1,n) ans += dp[n][i][i*a];
	cout << ans << ln;
}

Measured memory_bytes: 55552
#include <stdio.h>


int main() {
	int x, a, b;
	
	scanf("%d %d %d", &x, &a, &b);
	
	int rangeA = (x > a)? (x - a) : (a - x);
	int rangeB = (x > b)? (x - b) : (b - x);
	
	(rangeA < rangeB)? puts("A") : puts("B");
	
	return 0;
}

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

int main()
{
    int n; cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    int maxv=*max_element(v.begin(),v.end());
    int idx=max_element(v.begin(),v.end())-v.begin();
    int sum=0;
    for(int i=0;i<n;i++){
        if(i!=idx) sum+=v[i];
    }
    if(maxv>=sum) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
ll n;
ll c;
vector<pair<ll, ll>>xv;

vector<ll> lef, rig;
ll leftgain(int num) {
	if (num == 0)return 0;
	return lef[num] - xv[num - 1].first;
}
ll riggain(int num) {
	if (num == 0)return 0;
	ll dis = c - xv[n - num].first;
	return rig[num] - dis;
}
int main() {
	cin >> n >> c;
	xv = vector<pair<ll, ll>>(n);
	rep(i, 0, n)cin >> xv[i].first >> xv[i].second;
	sort(all(xv));

	lef = vector<ll>(n + 1, 0);
	rig = vector<ll>(n + 1, 0);
	rep(i, 1, n + 1) {
		lef[i] += lef[i - 1] + xv[i - 1].second;
		rig[i] += rig[i - 1] + xv[n - i].second;
	}

	ll ans = 0;
	vector<ll> maxleft(n + 1, 0);
	vector<ll> maxright(n + 1, 0);
	repc(i, 1, n)maxleft[i] = max(maxleft[i - 1], leftgain(i));
	repc(i, 1, n)maxright[i] = max(maxright[i - 1], riggain(i) - (c - xv[n - i].first));
	repc(i, 0, n)ans = max(ans, maxleft[i] + maxright[n - i]);

	ll ans2 = 0;
	vector<ll> maxleft2(n + 1, 0);
	vector<ll> maxright2(n + 1, 0);
	repc(i, 1, n)maxleft2[i] = max(maxleft2[i - 1], leftgain(i) - xv[i - 1].first);
	repc(i, 1, n)maxright2[i] = max(maxright2[i - 1], riggain(i));
	repc(i, 0, n)ans2 = max(ans2, maxleft2[i] + maxright2[n - i]);
	cout << max(ans, ans2);


	return 0;
}





Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c=0;
    string s;
    cin>>s;
    if(s=="SAT")
    {
        c=1;
    }
    if(s=="SUN")
    {
        c=7;
    }
    if(s=="FRI")
    {
        c=2;
    }
    if(s=="THU")
    {
        c=3;
    }
    if(s=="WED")
    {
        c=4;
    }
     if(s=="TUE")
    {
        c=5;
    }
    if(s=="MON")
    {
        c=6;
    }

cout<<c<<endl;




}


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

using namespace std;

int main()
{

	long a, b, c, K, ans;
	cin >> a >> b >> c;
	cin >> K;

	ans = (pow(2, K) - 1)*max(max(a, b), c) + a + b + c;

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define MAX_N 210
using namespace std;

int N;
int coox[MAX_N], cooy[MAX_N];
bool f[MAX_N][MAX_N], vis[MAX_N];
int match[MAX_N];
int res;

bool dfs (int);

int main () {
    scanf("%d", &N);
    for (int i = 1;i <= 2 * N; ++i) scanf("%d%d", coox + i, cooy + i);
    for (int i = 1;i <= N; ++i)
	for (int j = N + 1;j <= 2 * N; ++j)
	    if (coox[i] < coox[j] && cooy[i] < cooy[j]) {
		f[i][j - N] = true;
	    }

    for (int i = 1;i <= N; ++i) {
	memset(vis, false, sizeof(vis));
	if (dfs(i)) res++;
    }
    printf("%d\n", res);
    return 0;
}

bool dfs (int x) {
    for (int i = 1;i <= N; ++i) {
	if (!f[x][i] || vis[i]) continue;
	vis[i] = true;
	if (!match[i] || dfs(match[i])) {
	    match[i] = x;
	    return true;
	}
    }
    return false;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

char s[51][51];

int vx[] = { 0,  1, 1, 1, 0, -1, -1, -1};
int vy[] = {-1, -1, 0, 1, 1,  1,  0, -1};

// 周囲にMineがいくつあるかカウントする
int countMine(int h, int w, int x, int y) {
    int cnt = 0;

    for (int i = 0; i < 8; i++) {
        if (((x + vx[i] < w && x + vx[i] >= 0) || (y + vy[i] < h && y + vy[i] >= 0)) && (s[x + vx[i]][y + vy[i]] == '#')) cnt++;
    }

    return cnt;

}
int main()
{
    int h, w; cin >> h >> w;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s[i][j];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') s[i][j] += 2 + countMine(h, w, i, j);

            if (j != w - 1) cout << s[i][j];
            else cout << s[i][j] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
def Euclid(x,y):
    while x != 0:
        z=x
        x=y%x
        y=z
    return y
l = c*d//(Euclid(c,d))
print((b- b//c - b//d + b//l) - ((a-1)- (a-1)//c - (a-1)//d + (a-1)//l))


Measured memory_bytes: 2940
// ARC092B.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5 + 200;

int n, ai[MAX_N], bi[MAX_N], ta[MAX_N], tb[MAX_N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    for (int i = 1; i <= n; i++)
        scanf("%d", &bi[i]);
    int ans = 0;
    for (int b = 0; b < 29; b++)
    {
        int T = 1 << b, mod = T << 1;
        for (int i = 1; i <= n; i++)
            ta[i] = ai[i] % mod, tb[i] = bi[i] % mod;
        sort(tb + 1, tb + 1 + n);
        int pans = 0;
        for (int i = 1; i <= n; i++)
        {
            int l = lower_bound(tb + 1, tb + 1 + n, T - ta[i]) - tb;
            int r = lower_bound(tb + 1, tb + 1 + n, mod - ta[i]) - tb;
            pans ^= (r - l) & 1;
            l = lower_bound(tb + 1, tb + 1 + n, T * 3 - ta[i]) - tb;
            r = lower_bound(tb + 1, tb + 1 + n, (mod << 1) - ta[i]) - tb;
            pans ^= (r - l) & 1;
        }
        ans += (pans << b);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>

using namespace std;

int main()
{
  int x;
  int a,b;

  cin >> x >> a >> b;

  if(a-b >= 0) cout << "delicious" << endl;
  else if(b > a+x) cout << "dangerous" << endl;
  else cout << "safe" << endl;

  return 0;
}

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

int main(){
  int l, r, i, j, mod, mini=2500, a, b;
  cin >> l >> r;

  a = l/2019;
  b = r/2019;

  if(b-a>0)
      mini=0;
  else{

      for(int i=l; i<=r; i++){
	  for(int j=i+1; j<=r; j++){
	      int tmp = ((i%2019)*(j%2019))%2019;
	      mini = min(mini, tmp);
	  }	  
      }
  }


  cout << mini << endl;

  return 0;
}


Measured memory_bytes: 256
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rng(i, k, n) {
        if (a[i - k] < a[i]) cout << "Yes\n";
        else cout << "No\n";
    }
    return;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
class disjoint_set {
  public:
  vector<int> rank, prt, ptl;
  disjoint_set (int size) {
    rank.resize(size);
    prt.resize(size);
    ptl.resize(size);
    for (int i = 0; i < size; i++) {
      prt[i] = i;
      rank[i] = 0;
      ptl[i] = 0;
    }
  }
  int find (int x) {
    if (x == prt[x]){
      return x;
    } else {
      int r = find(prt[x]);
      ptl[x] += ptl[prt[x]];
      return prt[x] = r;
    }
  }
  bool is_equiv (int x, int y) {
    return find(x) == find(y);
  }
  bool unite (int x, int y, int w) {
    if (find(x) == find(y)) {
      return false;
    }
    w += ptl[x];
    w -= ptl[y];
    x = find(x);
    y = find(y);
    if (rank[x] < rank[y]) {
      swap(x, y);
      w *= -1;
    }
    prt[y] = x;
    ptl[y] = w;
    if (rank[x] == rank[y]) {
      rank[x]++;
    }
    return true;
  }
  int diff (int x, int y) {
    find(x);
    find(y);
    return ptl[y] - ptl[x];
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  disjoint_set djs(n);
  while (q--) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    if (djs.is_equiv(x, y)) {
      if (djs.diff(x, y) != z) {
        cout << "No" << '\n';
        return 0;
      }
    } else {
      djs.unite(x, y, z);
    }
  }
  cout << "Yes" << '\n';
  return 0;
}

Measured memory_bytes: 1408
import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List
import Data.Maybe

f :: [Int] -> Bool
f xs = let mx = maximum xs in sum xs > 2 * mx

cond :: a -> a -> Bool -> a
cond t f p = if p then t else f

main = getLine >> map read . words <$> getLine >>= putStrLn . cond "Yes" "No" . f

Measured memory_bytes: 636
#include "stdio.h"

int main(void){
  int A,B;
  int coin=0;
  scanf("%d %d", &A, &B);
  
  for(int i=0; i<2; i++){
    if(A>=B){
      coin+=A;
      A--;
    }
    else{
      coin+=B;
      B--;
    }
  }
  printf("%d", coin);
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

#define PI 3.1415926535897932

int main() {
  int n;
  cin>>n;
  nvec(int,d,n);
  int s=pow(SUM(d),2);
  for (size_t i = 0; i < n; i++) {
    s-=pow(d[i],2);
  }
  cout<<s/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2);

    int num = vec.at(0) * 100 + vec.at(1) * 10 + vec.at(2);
    if(num % 4 == 0){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

}

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

int L[210];

int main() {
	int n, ans = 0;
	cin >> n;
	for (int i = 0; i < 2*n; i++) {
		cin >> L[i];
	}
	sort(L, L + 2*n);
	for (int i = 0; i < n; i++) {
		ans += L[2 * i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	ll ans = 0;
	ll sum = 0;
	for (int i = n - 1; i >= 0; i--) {
		a[i] += sum;
		if (a[i] % b[i] == 0) continue;
		else if (a[i] < b[i]) {
			ans += b[i] - a[i];
			sum += b[i] - a[i];
		}
		else {
			ans += b[i] - a[i] % b[i];
			sum += b[i] - a[i] % b[i];
		}
	}

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

Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

#define SIZE 100000
bool prime[SIZE];

int main(){
    memset( prime, 0, sizeof(prime) );
    for( int i=2; i<(int)sqrt(SIZE)+1; i++ ){
        if( !prime[i] ){
            for( int j=i+i; j<SIZE; j+=i ){
                prime[j] = true;
            }
        }
    }

    int n;
    while( cin >> n ){
        for( int i=n-1; i>=2; i-- ){
            if( !prime[i] ){
                cout << i;
                break;
            }
        }
        for( int i=n+1; i<SIZE; i++ ){
            if( !prime[i] ){
                cout << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int a;
  cin>>a;
  cout << a + a*a + a*a*a << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
using namespace std;
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }
int dist(int x, int y) { return abs(x - y);}
//# Functions for Vector/Matrix
template <typename T>
vector<T> zeros(int length){
    vector<T> vec(length, 0);
    return vec;
}
template <typename T>
vector<vector<T>> zeros(tuple<int, int> dim){
    vector<vector<T>> mat(get<0>(dim), vector<T>(get<1>(dim), 0));
    return mat;
}
template <typename T>
void show(vector<T> &vec){
    for (auto value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
template <typename T>
void show(vector<vector<T>> &mat){
    for (auto vec : mat) {
        show(vec);
    }
}
size_t split(const std::string &txt, std::vector<std::string> &strs, char ch)
{
    size_t pos = txt.find( ch );
    size_t initialPos = 0;
    strs.clear();

    // Decompose statement
    while( pos != std::string::npos ) {
        strs.push_back( txt.substr( initialPos, pos - initialPos ) );
        initialPos = pos + 1;

        pos = txt.find( ch, initialPos );
    }

    // Add the last one
    strs.push_back( txt.substr( initialPos, std::min( pos, txt.size() ) - initialPos + 1 ) );

    return strs.size();
}
int main(){
    int N, M; cin >> N >> M; cin.ignore();
    string line;
    vector<int> likes(M, 0);
    for(int i=0; i<N; i++){
        getline(cin, line);
        vector<string> svec;
        split(line, svec, ' ');
        auto it = svec.begin(); ++it;
        while(it != svec.end()){
            likes[stoi(*it)-1] += 1;
            ++it;
        }
    }
    int ans = 0;
    for(auto &like: likes){
        if(like == N) ++ans;
    }
    cout << ans;
    return 0;
}



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

using namespace std;

int main(){
        int K, S;
        cin>>K>>S;
        int res=0;
        for(int i=0;i<=K;i++){
                for(int j=0;j<=K;j++){
                        if(S-i-j<=K&&S-i-j>=0){
                                res++;
                        }
                }
        }
        cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

int main() {
  ll n;
  cin >> n;
  ll a[n+1];
  for(ll i = 1; i <= n; i++) cin >> a[i];

  ll mx = a[1];
  ll ans = 0;
  for(ll i = 2; i <= n; i++) {
      mx = max(a[i],mx);

      ans+=(mx - a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5148
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
unsigned long long MOD = 1e9 + 7;
ll INF = 1e18;
long long modMult(long long a, long long b, long long m)
{
    long long res = 0;
    long long exp = a % m;
    while (b)
    {
        if (b & 1)
        {
            res += exp;
            if (res > m)
                res -= m;
        }
        exp <<= 1;
        if (exp > m)
            exp -= m;
        b >>= 1;
    }
    return res;
}
long long powMod(long long a, long long b, long long m)
{
    long long res = 1;
    long long exp = a % m;
    while (b)
    {
        if (b & 1)
            res = modMult(res, exp, m);
        exp = modMult(exp, exp, m);
        b >>= 1;
    }
    return res;
}
//powMod(a,b,MOD)
//O(log(b))?
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> vec(n);
    vector<ll> reg(100, 0);
    rep(i, n)
    {
        cin >> vec[i];
    }
    rep(i, n)
    {
        for (ll j = 61; j >= 0; j--)
        {
            ll k=j;
         //   cout<<(1<<k)<<endl;
            if ((ll)pow(2,j) <= vec[i])
            {
                reg[j]++;
                vec[i] -= ((ll)pow(2,j));
            }
        }
    }
  //  rep(i,61)cout<<reg[i]<<" ";
   // cout<<endl;
    ll res=0;
  	ll g=1;
    rep(i, 62)
    {
        ll k=g;
        ll f=reg[i]*(n-reg[i]);
        f%=MOD;
        ll p=k*f%MOD;
        res += p;
        res %= MOD;
        g*=2;
        g%=MOD;
    }
    cout << res%MOD << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

struct elem {
    int ex;
    int k;
};
int func(vector<elem> &p,int x) {
    int ret=0;
    FORE(e,p) {
        ret+=e.k*pow(x,e.ex);
    }
    return ret;
}
signed main() {
    string s;
    cin>>s;
    s+="+";
    vector<elem> poly;
    REP(i,SZ(s)-1) {
        elem a;
        string tmp="";
        while(s[i]!='x') {
            tmp+=s[i++];
            if(s[i]=='+' || s[i]=='-') {
                a.k=stoi(tmp);
                a.ex=0;
                goto next;
            }
        }
        if(tmp=="+" || tmp=="") a.k=1;
        else if(tmp=="-") a.k=-1;
        else a.k=stoi(tmp);
        i++;
        tmp="";
        if(s[i]=='^') {
            i++;
            while(s[i]!='+' && s[i]!='-') {
                tmp+=s[i++];
            }
            a.ex=stoi(tmp);
        }
        else {
            a.ex=1;
        }
        next:
        poly.push_back(a);
        i--;
    }
    // REP(i,SZ(poly)) {
    //     cout<<poly[i].k<<" * x ^ "<<poly[i].ex<<endl;
    // }
    vector<int> ans;
    FOR(i,-2000,2001) {
        if(func(poly,i)==0) {
            ans.push_back(-i);
        }
    }
    sort(ALL(ans));
    string ans_;
    FORE(x,ans) {
        ans_+="(x"+string(x>0?"+":"")+to_string(x)+")";
    }
    cout<<ans_<<endl;
    return 0;
}

Measured memory_bytes: 3500
#include <iostream>
    #include <vector>
    #include <array>
    #include <list>
    #include <string>
    #include <stack>
    #include <queue>
    #include <deque>
    #include <map>
    #include <unordered_map>
    #include <set>
    #include <unordered_set>
    #include <tuple>
    #include <bitset>
    #include <memory>
    #include <cmath>
    #include <algorithm>
    #include <functional>
    #include <iomanip>
    #include <numeric>
    #include <climits>
    #include <cfloat>
    #include <cassert>
    #include <random>
    #include<iostream>
    #include<cmath>
     
    long long int min_op(const int current, const int prev_height_pos, const int k, const std::vector<int>& heights, std::vector<std::vector<std::vector<long long int>>> &memo) {
    	if (current == heights.size()) return 0;
    	if (memo[current][prev_height_pos][k] >= 0) return memo[current][prev_height_pos][k];
    	if (heights[current] >= heights[prev_height_pos]) {
    		long long int min = min_op(current + 1, current, k, heights, memo) + heights[current] - heights[prev_height_pos];
    		if (k > 0) {
    			min = std::min(min, min_op(current + 1, prev_height_pos, k - 1, heights, memo));
    		}
    		return memo[current][prev_height_pos][k] = min;
    	}
    	else {
    		long long int min = min_op(current + 1, current, k, heights, memo);
    		if (k > 0) {
    			min = std::min(min, min_op(current + 1, prev_height_pos, k - 1, heights, memo));
    		}
    		return memo[current][prev_height_pos][k] = min;
    	}
    }
    int main() {
    	int n, k; std::cin >> n >> k;
    	std::vector<int> column(n + 1, 0); for (auto i = 1; i <= n; ++i) std::cin >> column[i];
    	std::vector<std::vector<std::vector<long long int>>> memo(n + 1, std::vector<std::vector<long long int>>(n, std::vector<long long int>(k + 1, -1)));
    	std::cout << min_op(1, 0, k, column, memo) << '\n';
    }

Measured memory_bytes: 216192