akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}
int dp[10010];
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll h, n;
  cin >> h >> n;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[n][2];
  fi(0, n) {
    cin >> arr[i][0] >> arr[i][1];
  }
  fi(1, h + 1) {
    dp[i] = INF;
  }
  fi(1, h + 1) {
    fj(0, n) {
      int a = arr[j][0];
      int b = arr[j][1];
      if(a >= i) {
        chmin(dp[i], b);
      }
      else {
        chmin(dp[i], b + dp[i - a]);
      }
    }
  }
  cout << dp[h] << endl;
  return 0;
}



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

using namespace std;

pair<int, int> select_subarray(vector<int> &arr) {
    int start = -1;
    int end = -1;
    int size = arr.size();
    for (int i = 0; i < size; i++) {
        if (start == -1 && arr[i] > 0) {
            start = i;
            end = start;
        }
        if (start != -1 && arr[i] != 0) {
            end++;
        }
        if (start != -1 && arr[i] == 0) {
            break;
        }
    }

    return make_pair(start, end);
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    vector<int> arr;
    int cur;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
        sum += cur;
    }

    int ans = 0;
    while (sum > 0) {
        pair<int, int> p = select_subarray(arr);
        int start = p.first;
        int end = p.second;

        int subarray_min = arr[start];
        for (int k = start; k < end; k++) {
            if (arr[k] <= subarray_min) {
                subarray_min = arr[k];
            }
        }
        for (int j = start; j < end; j++) {
            arr[j] -= subarray_min;
            sum -= subarray_min;
        } 
        if (start == end) {
            arr[start] -= subarray_min;
            sum -= subarray_min;
        }

        ans += subarray_min;
    }

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


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

int bingo[3][3];
bool said[3][3] = {};

void fill(int num){
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if(bingo[i][j] == num) said[i][j] = 1;
        }
    }
}

bool won(){
    for(int i=0; i<3; i++){
        if(said[i][0] && said[i][1] && said[i][2]) return 1;
        if(said[0][i] && said[1][i] && said[2][i]) return 1;
    }
    if(said[0][0] && said[1][1] && said[2][2]) return 1;
    if(said[0][2] && said[1][1] && said[2][0]) return 1;
    return 0;
}

int main() {
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++) cin >> bingo[i][j];
    }
    int qtn, num;
    cin >> qtn;
    while(qtn--){
        cin >> num;
        fill(num);
    }
    
    if(won()) cout << "Yes\n";
    else cout << "No\n";
    
	return 0;
}

Measured memory_bytes: 256
//====== begin of bisma c++ template===========

        #include <iostream>
        #include <string>
        #include <vector>
        #include <algorithm>
        #include <sstream>
        #include <queue>
        #include <deque>
        #include <bitset>
        #include <iterator>
        #include <list>
        #include <stack>
        #include <map>
        #include <set>
        #include <functional>
        #include <numeric>
        #include <utility>
        #include <limits>
        #include <time.h>
        #include <math.h>
        #include <stdio.h>
        #include <string.h>
        #include <stdlib.h>
        #include <assert.h>
        using namespace std;
        #define rep(a,b,c) for(int a=b;a<=c;a++)
        #define ll long long
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))


int main(){
    
    
    string s;
    cin>>s;
    
    bool a1=0,a2=0,a3=0,a4=0;
    
    rep(i,0,s.size()-1){
        if(s[i]=='N') a1=1;
        if(s[i]=='S') a2=1;
        if(s[i]=='E') a3=1;
        if(s[i]=='W') a4=1;
    }
    
    if(a1==a2 && a3==a4){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int N; cin>>N;
    vec A(N),B(N),C(N);
    REP(i,N) cin>>A[i];
    REP(i,N) cin>>B[i];
    REP(i,N-1) cin>>C[i];
    int sum = 0;
    REP(i,N){
        sum += B[A[i]-1];
        if(A[i]+1==A[i+1]) sum +=C[A[i]-1];
    }
    Out(sum);
}

Measured memory_bytes: 256
# 10 9 10 10
# 10 / 10 = 1 ...1度の攻撃で高橋くんは負ける
# 10 / 9 = 1.1.. 2度の攻撃が必要

# math.ceil(A / D) == math.ceil(C / B) のときは先行の勝利

import math

def battle_v1(A: int, B: int, C: int, D: int) -> str:
    while True:
        C -= B
        if C <= 0:
            return 'Yes'

        A -= D
        if A <= 0:
            return 'No'

def battle_v2(A: int, B: int, C: int, D: int) -> str:
    n = math.ceil(C / B)
    m = math.ceil(A / D)

    if n > m:
        return 'No'
    else:
        return 'Yes'

if __name__ == '__main__':
    A, B, C, D = map(int, input().split())
    res = battle_v2(A, B, C, D)
    print(res)


Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

  int n;
  cin >> n;
  vi a(n), b(n), c(n - 1);
  for(int& x : a) cin >> x;
  for(int& x : b) cin >> x;
  for(int& x : c) cin >> x;
  int res = 0;
  for(int i = 0; i < n; i++){
    res += b[a[i] - 1];
    if(i && a[i - 1] == a[i] - 1) res += c[a[i - 1] - 1];
  }
  cout << res;
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from collections import deque
    s=list(input())
    dq=deque(s)
    
    ans=0
    while len(dq)>=2:
        l=dq.popleft()
        r=dq.pop()
        if l==r:
            pass
        elif l=="x":
            ans+=1
            dq.append(r)
        elif r=="x":
            ans+=1
            dq.appendleft(l)
        else:
            print(-1)
            exit()
            
    print(ans)

main()


Measured memory_bytes: 79992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
const int N = 1e5+5;
const int INF = (1<<30)-1;

int hd[N],iter[N],dis[N];
struct E{int v,w,nxt;}e[N<<3];
queue<int>Q;
bool v[N];
int p[N],q[N],c[N],d[N];
int n,nc,nd,tot=1,S,T;

inline void add(int u,int v,int w){
	e[++tot]={v,w,hd[u]};hd[u]=tot;
	e[++tot]={u,0,hd[v]};hd[v]=tot;
}
inline bool bfs(){
	memcpy(iter,hd,sizeof(hd));
	memset(dis,-1,sizeof(dis));
	Q.push(S);dis[S]=0;
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		for(int i=hd[x],y;i;i=e[i].nxt)
			if(e[i].w&&dis[y=e[i].v]==-1){
				dis[y]=dis[x]+1, Q.push(y);
			}
	}
	return ~dis[T];
}
int dfs(int x=S,int f=INF){
	if(x==T||!f)return f;
	int sf=0,y;
	for(int &i=iter[x];i;i=e[i].nxt)
		if(e[i].w&&dis[y=e[i].v]==dis[x]+1){
			int w=dfs(y,min(f,e[i].w));
			e[i].w-=w, e[i^1].w+=w;
			f-=w, sf+=w;
			if(!f)break;
		}
	return sf;
}

void prep(int p[],int c[],int &m){
	m = 0;
	rep(i,1,n) if(!c[i]){
		++m;
		for(int x=i;!c[x];x=p[x]) c[x] = m;
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",p+i),++p[i];
	rep(i,1,n)scanf("%d",q+i),++q[i];
	prep(p,c,nc);
	prep(q,d,nd);
	S = 0, T = nc+nd+1;
	int ans = n;
	rep(i,1,n){
		bool f1 = (p[i]==i), f2 = (q[i]==i);
		if(f1&&f2) --ans;
		else if(f1) add(nc+d[i],T,1);
		else if(f2) add(S,c[i],1);
		else{
			add(nc+d[i],c[i],1);
			if(p[i]==q[i]) add(c[i],nc+d[i],1);
		}
	}
	int flow = 0;
	while(bfs()) flow += dfs();
	ans -= flow;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

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

	int n, k;
	std::cin >> n >> k;
	VI A(n);
	FOR(i, n) std::cin >> A[i];

	auto go = [&](){
		std::vector<int> B(n+1);
		FOR(i, n){
			int mn = std::max(0, i-A[i]);
			int mx = std::min(n-1, i+A[i]);
			B[mn]++;
			B[mx+1]--;
		}

		int have = 0;
		FOR(i, n){
			have += B[i];
			A[i] = have;
		}
	};

	while(k > 0){
		auto last = A;
		go();
		if(last == A) break;
		k--;
	}

	FOR(i, n) std::cout << A[i] << " ";

	return 0;
}

Measured memory_bytes: 5576
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int H,W;
    	//?¨??????\??????????????????????????§????????????
		Scanner scanner = new Scanner(System.in);
		
		while(true){
			H = scanner.nextInt();
			W = scanner.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			
			for(int i = 0; i < H;i++){
				for(int j = 0; j < W; j++){
					if(i == 0 || i == H-1 || j == 0 || j == W - 1){
						System.out.print("#");	
					}
					else{
						System.out.print(".");
					}
									
				}
				System.out.println();
			}
			System.out.println();
		}
    	scanner.close();
    }
}

Measured memory_bytes: 35320
#include <iostream>
#include <cstdio>
#include <cstring>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//????¬???¬??¢?????°???
int getint(char ch) {
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

//?°?????¬??????¬??¢?????°?????¶??????key
long long getkey(char str[]) {
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++) {
		sum += p*(getint(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) { return key%M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
	long long key, i, h;
	key = getkey(str);
	for(i=0;;i++){
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h])==0) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i, h;
	key = getkey(str);
	for(i=0;;i++)
	{
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h],str) == 0) return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int i, n, h;
	char str[L], com[10];
	memset(H, 0, sizeof(H));
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s %s", com, str);

		if (com[0] == 'i') {
			insert(str);
		}
		else {
			if (find(str))
				printf("yes\n");
			else
				printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 17464
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int R, G;
    cin >> R >> G;
    cout << 2 * G - R << endl;
    return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    string s;
    cin >> s;
    
    int counter = 0;
    if (s[0] == '1') counter++;
    if (s[1] == '1') counter++;
    if (s[2] == '1') counter++;
    
    cout << counter << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
 
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
 
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
 
#define pb(a) push_back(a)
 
ll n,m,k;
ll cnst=1000000007LL;

ll moddiv(ll a,ll b,ll c){
	ll x0=c;
	ll x1=b;
  ll x2;
	ll n0=0LL;
	ll n1=1LL;
  ll n2;
	ll t=a%b;
  ll m;
  ll ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=n0-m*n1;
      n2%=c;
      if (x2==1){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;
      x1=x2;
      n0=n1;
      n1=n2;
    }
	ans=a+((t*ans)%c)*b-t;
	return ans/b;
}





 
int main(){
  ll ans=0LL;
  cin >> n >> m >> k;
  ll k2ans=0LL;
  REP(x,m){
    REP(y,n){
      ll x1=m-x-1;
      ll xline=x*(x+1)/2+x1*(x1+1)/2;
      ll y1=n-y-1;
      ll yline=y*(y+1)/2+y1*(y1+1)/2;
      k2ans+=xline*n+yline*m;
      k2ans%=cnst;
    }
  }
  
  k2ans=moddiv(k2ans,2LL,cnst);
  ll nmt=k2ans;
  k-=2;
  ll nm=n*m;

  ll saigonojosann=1LL;
  REP(i,k){
    nmt=nmt*(nm-2-i);
    nmt%=cnst;
    saigonojosann*=i+1;
    saigonojosann%=cnst;
  }
  
  nmt=moddiv(nmt,saigonojosann,cnst);
  ans=nmt;
  cout<<ans<<endl;
 
  return 0;
}

Measured memory_bytes: 256
/**
 * Author : Deep Raval
 * There are no two words in the English language more harmful than "good job".
 * 1729 0_0
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
using ll = long long;
#define endl '\n'
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define all(x) (x).begin(), (x).end()
/* **************************************************************************************** */

void test_case()
{
    ll n;
    cin >> n;
    vector <ll> a(n), mxa(n);
    for(ll &x : a) cin >> x;

    ll cur_max = a[0];

    ll ans = 0;

    for(int i = 0; i < n; i ++)
    {
        cur_max = max(cur_max, a[i]);
        ans +=abs(cur_max- a[i]);
    }
    cout << ans << endl;
	return ;
}
int main()
{
	FAST_IO
    int t = 1;
    //cin >> t;
    while(t--)
        test_case();
	return 0;
}

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

int ok[1000000];

int main() {
    int n, q;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < (1 << n); ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if ((i >> j) & 1) {
                sum += a[j];
            }
        }
        ok[sum] = 1;
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int m;
        cin >> m;
        cout << (ok[m] ? "yes\n" : "no\n");
    }
    return 0;
}

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

int main() {
    int n;
    cin>>n;
    ll ans=1;
    for (int i=1; i<=n; i++) {
        ans*=i;
        ans%=MOD;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(){
    char line[128];
    int n, a, b, c;

    gets(line);
    n = atoi(line);
 
    while(n--)
    {
        char *sp1, *sp2;
        gets(line);

        sp1 = strchr(line, ' ');
        *sp1 = '\0';
        sp2 = strchr(sp1+1, ' ');
        *sp2 = '\0';

        a = atoi(line);
        b = atoi(sp1+1);
        c = atoi(sp2+1);

        if (
            (a*a + b*b == c*c) ||
            (b*b + c*c == a*a) ||
            (c*c + a*a == b*b) 
        )
        {
            puts("YES");
        }
        else
        {
            puts("NO");
        }
    }
    return 0;
}

Measured memory_bytes: 524
import math
import random
class Prime:
    seed_primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
    def is_prime(self,n):
        is_prime_common=self.is_prime_common(n)
        if is_prime_common is not None:return is_prime_common
        if n<2000000:return self.is_prime_brute_force(n)
        return self.is_prime_miller_rabin(n)
    def is_prime_common(self,n):
        if n==1:return False
        if n in Prime.seed_primes:return True
        if any(map(lambda x:n%x==0,self.seed_primes)):return False
    def is_prime_brute_force(self,n):
        for k in range(2,int(math.sqrt(n))+1):
            if n%k==0:return False
        return True
    def is_prime_miller_rabin(self,n):
        d=n-1
        while d&1==0:d>>=1
        witnesses=self.get_witnesses(n)
        for w in witnesses:
            y=pow(w,d,n)
            while d!=n-1and y!=1and y!=n-1:
                y=y*y%n
                d<<=1
            if y!=n-1and d&1==0:return False
        return True
    def get_witnesses(self,num):
        def _get_range(num):
            if num<2047:return 1
            if num<1373653:return 2
            if num<25326001:return 3
            if num<3215031751:return 4
            if num<2152302898747:return 5
            if num<3474749660383:return 6
            if num<341550071728321:return 7
            if num<3825123056546413051:return 9
            return 12
        return self.seed_primes[:_get_range(num)]
    def gcd(self,a,b):
        if a<b:return self.gcd(b,a)
        if b==0:return a
        while b:a,b=b,a%b
        return a
    @staticmethod
    def f(x,n,seed):
        p=Prime.seed_primes[seed%len(Prime.seed_primes)]
        return(p*x+seed)%n
    def find_factor(self,n,seed=1):
        if self.is_prime(n):return n
        x,y,d=2,2,1
        count=0
        while d==1:
            count+=1
            x=self.f(x,n,seed)
            y=self.f(self.f(y,n,seed),n,seed)
            d=self.gcd(abs(x-y),n)
        if d==n:
            return self.find_factor(n,seed+1)
        return self.find_factor(d)
    # nのすべての素因数を見つける
    def find_factors(self,n):
        primes={}
        if self.is_prime(n):
            primes[n]=1
            return primes
        while n>1:
            factor=self.find_factor(n)
            primes.setdefault(factor,0)
            primes[factor]+=1
            n//=factor
        return primes
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]%mod*self.i[k]%mod
mod=10**9+7
n,m=map(int,input().split())
*d,=Prime().find_factors(m).values()
if d:f=Factorial(n+max(d),mod)
ans=1
for t in d:
    ans=ans*f.comb(n-1+t,t)%mod
print(ans)

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

int A, B, C, X;
cin >> A >> B >> C >> X;
int cnt = 0;
for(int i = 0; i <= A; i++){ 
     for(int j = 0; j <= B; j++){ 
          for(int k = 0; k <= C; k++){ 
            if(X == 500 * i + 100 * j + 50 * k) cnt++;   
          }
     }
}

print(cnt);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B, K;
  cin >> A >> B >> K;
  for(int i=0; i<K; i++){
    if(i %2 == 0){
      if(A %2 == 1){
        A--;
      }
     B += A / 2;
     A = A / 2;
    }
    if(i %2 != 0){
      if(B %2 == 1){
        B--;
      }
     A += B / 2;
     B = B / 2;
    }
  }
  cout << A << endl;
  cout << B << endl;
}

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

using namespace std;

int same(int a[], int b[], int n) {
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int a[n], b[n], p[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        p[i] = i + 1;
    }
    int cnt = 0;
    int X, Y;
    do {
        cnt++;
        if (same(a, p, n)) {
            X = cnt;
        }
        if (same(b, p, n)) {
            Y = cnt;
        }
    } while (next_permutation(p, p + n));
    cout << abs(X - Y) << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int w = Math.abs(a-x);
    int y = Math.abs(b-x);
    if(w<y){
      System.out.println("A");
    }else{
      System.out.println("B");
    }
  }
}


Measured memory_bytes: 20820
#include <iostream>
#include <queue>
#include <algorithm>

int main(void) {
    std::priority_queue<u_int> heights;

    for (u_int h, i = 0; i < 10; ++i) {
        std::cin >> h;
        heights.push(h);
    }

    for (u_int i = 0; i < 3; ++i) {
        std::cout << heights.top() << std::endl;
        heights.pop();
    }

    return 0;
}

Measured memory_bytes: 1204
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

using namespace std;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
const int max_w = 10000;
int n, w;
int dp[10001];

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

	memset(dp, -1, sizeof dp);
	dp[0] = 0;

	REP(_i, n)
	{
		int v_item, w_item;
		cin >> v_item >> w_item;

		REP(i, w)
			if (dp[i] != -1)
				if (i + w_item <= w)
					chmax(dp[i + w_item], dp[i] + v_item);
	}

	int ans = 0;
	REPC(i, w)
		chmax(ans, dp[i]);

	cout << ans << endl;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h> 
using namespace std; 
int main(){
int k,x,res,intial,final;
cin>>k>>x;
res=k-1;
intial=x-res;
final=x+res;
for(int i=intial;i<=final;i++){
	cout<<i<<" ";
}
return 0;
	}

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

using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> dp(h+1, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = 0; j < h; j++) {
            int nj = min(j+a, h);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[h] << endl;
    
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] s = str.split(" ");
		int h = Integer.parseInt(s[0]);
		int w = Integer.parseInt(s[1]);
		str = br.readLine();
		int c = Integer.parseInt(str);
		str = br.readLine();
		String[] a = str.split(" ");
		int ci = 1;
		int[] map = new int[h * w];
		int mi = 0;
		for (String cn_s : a) {
			int cn = Integer.parseInt(cn_s);
			for (int i = 0; i < cn; i++) {
				map[mi] = ci;
				mi++;
			}
			ci++;
		}
		for (int i = 0; i < h; i++) {
			int[] r = new int[w];
			System.arraycopy(map, w * i, r, 0, w);
			if (i % 2 == 0) {
				for (int j = 0; j < w; j++) {
					System.out.print(r[j]);
					if (j != w - 1)
						System.out.print(" ");
					else
						System.out.println();
				}
			} else {
				for (int j = 0; j < w; j++) {
					System.out.print(r[w - j - 1]);
					if (j != w - 1)
						System.out.print(" ");
					else
						System.out.println();
				}

			}
		}
	}
}


Measured memory_bytes: 24868
import sys
sys.setrecursionlimit(10**6)
def dfs(v,p,d):
    dist[v]=d
    for nv,nd in G[v]:
        if nv==p:
            continue
        dfs(nv,v,d+nd)

N=int(input())
G=[[] for i in range(N)]
dist=[-1]*N
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
Q,K=map(int,input().split())
dfs(K-1,-1,0)
for i in range(Q):
    x,y=map(lambda x:int(x)-1,input().split())
    print(dist[x]+dist[y])

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	map<int, int> mp;
	rep(i, n){
		int a; cin >>a;
		mp[a]++;
	}
	int ans = 0;
	for(auto x: mp){
		if(x.first != x.second){
			if(x.second - x.first >= 0) ans += x.second - x.first;
			else ans += x.second;
		}
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define llint long long
#define rg register
#define RI register int
#define RC register char
#define rg register
#define ed putchar('\n')
#define space putchar(' ')
#define Pair pair<int,int >
using namespace std;
	
template <typename tp> inline void read(tp &x)
{		
	x=0;
	RI f=1;
	RC c=getchar();
	while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	x*=f;
}	
	
template <typename tp> inline void print(tp x)
{	
	if(x<0) x=-x,putchar('-');
	if(x>9) print(x/10);
	putchar(x%10+'0'); 
}

#define int long long
const int N=1e6+10;
const int mod=998244353; 
int n,a,b,k; 
int jc[N];
int jc_inv[N];
int ans;

inline int mul(int x,int y)
{
	int res=1;
	for(;y;y>>=1)
	{
		if(y&1) res=(res*x)%mod;
		x=(x*x)%mod;
	}
	return res;
}

inline int C(int x,int y)
{
	if(y>x) return 0;
	int tmp1=jc[x];
	int tmp2=mul(jc[y],mod-2);
	int tmp3=mul(jc[x-y],mod-2);
//	int tmp2=jc_inv[y];
//	int tmp3=jc_inv[x-y];
	tmp1=(tmp1*tmp2)%mod;	
	tmp1=(tmp1*tmp3)%mod;
	return tmp1;
}

signed main()
{
	jc[0]=1;
	for(RI i=1;i<=300002;++i) jc[i]=(jc[i-1]*i)%mod,jc_inv[i]=mul(jc[i],mod-2);
	read(n),read(a),read(b),read(k);
	
//	if(!k)
//	{
//		print(1);
//		return 0;
//	}
	
	for(RI R=0;R<=n;++R)
	{
		if(R*a>k) break;
		int B=k-R*a;
		if(B%b) continue;
		B/=b;
		ans=(ans + (C(n,R) * C(n,B)) %mod) %mod;				
	}
	print(ans);
	return 0;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int n, a, b, c, d;
string s;

int main() {

  while(1){
    cin>>s;
    if(s == "#") break;
    cin>>a>>b>>c>>d;

    string array[10];
    int cnt = 0, pos = 0;
    REP(i,0,s.size()){
      if(isdigit(s[i])){
        REP(j,0,(s[i]-'0')){
          array[cnt] += ".";
        }
      }else if(s[i] == 'b'){
        array[cnt] += "b";
      }else if(s[i] == '/'){
        cnt++;
      }
    }
    /////////////
    array[a-1][b-1] = '.';
    array[c-1][d-1] = 'b';
    /////////////
    string ans = "";
    REP(i,0,cnt+1){
      int tmp = 0;
      REP(j,0,array[i].size()){
        bool flag = true;
        if(array[i][j] == 'b'){
          if(tmp > 0){
            ans += to_string(tmp);
            tmp = 0;
          }
          flag = false;
          ans += "b";
        }else if(array[i][j] == '.'){
          tmp++;
        }
        if(j == array[i].size()-1){
          if(flag){
            ans += to_string(tmp);
            tmp = 0;
          }
          if(i != cnt) ans += "/";
        }
      }
    }

    cout<<ans<<endl;

}

  return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double c = h * 30.0 + m * 0.5;
  double d = m * 6.0;
  double e = min(abs(c-d), 360-abs(c-d));
  e = e / 180.0 * 3.1415926535;
  double ans = a*a + b*b - 2*a*b*cos(e);
  ans = sqrt(ans);
  printf("%.15lf\n", ans);
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string X;
    cin >> X;

    ll s = 0, t = 0;
    for (auto e : X) {
        if (e == 'S') {
            s++;
        } else {
            t++;
            if (s) {
                s--; t--;
            }
        }
    }

    cout << s + t << "\n";
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

// 200, 5min

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> L;

signed main()
{
    cin >> N;
    REP(i, 2*N) {
        ll tmp;
        cin >> tmp;
        L.push_back(tmp);
    }
    SORT(L);
    ll ans = 0;
    for(int i = 0; i < L.size() - 1; i += 2) {
        ans += L[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class SCC {
  int V;
  std::vector<std::vector<int>> G, rG;
  std::vector<int> vs;
  std::vector<bool> used;
  std::vector<int> cmp;

  void dfs(int v){
    used[v] = true;
    for(int i=0; i<G[v].size(); i++)
      if(!used[G[v][i]]) dfs(G[v][i]);
    vs.push_back(v);
  }
  
  void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i=0; i<rG[v].size(); i++)
      if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
public:
  SCC(int V):V(V),G(V),rG(V),used(V),cmp(V){}

  int size(){ return V; }
  std::vector<int> get_edge(int from){ return G[from]; }

  void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  // 強連結成分(2点が相互に行き来できるグループ)数
  int scc(){
    for(int i=0; i<used.size(); i++) used[i] = 0;
    vs.clear();
    for(int v=0; v<V; v++)
      if(!used[v]) dfs(v);
    for(int i=0; i<used.size(); i++) used[i] = 0;
    int k = 0;
    for(int i=vs.size()-1; i>=0; i--)
      if(!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }

  // サイクルがあるか
  bool iscyclic(){ return scc() != V; }

  // 強連結成分番号
  std::vector<int> get_cmp(){ return cmp; }
  
  // 同じ辺を2度通らない、その頂点までの最長経路
  std::vector<int> depth(){
    scc();

    std::vector<pair<int,int>> order;
    std::vector<int> dp(V, 1);

    for(int i=0; i<V; i++){
      order.push_back(make_pair(cmp[i],i));
    }
    std::sort(order.begin(), order.end());

    for(int i=0; i<V; i++){
      int node = order[i].second;
      for(int j=0; j<G[node].size(); j++){
        dp[G[node][j]] = max(dp[G[node][j]], dp[node]+1);
      }
    }
    return dp;
  }
};

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

  SCC scc(N*N);
  
  rep(i,N){
    vector<int> v;
    rep(j,N-1){
      int a;
      cin >> a;
      a--;
      v.push_back(a);
    }
    rep(j,v.size()-1){
      int x = i;
      int y = v[j];
      int z = v[j+1];
 
      int a = min(x,y) * N + max(x,y);
      int b = min(x,z) * N + max(x,z);
 
      scc.add_edge(a,b);      
    }
  }

  if(scc.iscyclic()){
    cout << -1 << endl;
    return 0;
  }

  int mx = 0;
  vector<int> ret = scc.depth();
   
  rep(i,ret.size()){
    mx = max(mx, ret[i]);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 99444
#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long LL;

int main(){
    int a,b,x;
    cin>>a>>b>>x;
    string ans;
    if(x<a) ans="NO";
    else if(a+b>=x) ans="YES";
    else ans="NO";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc127/tasks/abc127_b

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << '\n';
    }

    return 0;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int cnt[26] = {0};

ll cnt3(char a, char b, char c){
	return (ll)cnt[a - 'A'] * cnt[b - 'A'] * cnt[c - 'A'];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	REP(i, n){
		string s;
		cin >> s;
		cnt[s[0] - 'A']++;
	}
	ll ans = cnt3('A', 'C', 'H') + cnt3('A', 'C', 'M') + cnt3('A', 'C', 'R') + cnt3('A', 'H', 'M') + cnt3('A', 'H', 'R') + cnt3('A', 'M', 'R') + cnt3('C', 'H', 'M') + cnt3('C', 'H', 'R') + cnt3('C', 'M', 'R') + cnt3('H', 'M', 'R');
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

//ll dfs(int a, int b, int c, int d)
//{
//	if (a > SZ(wv[0]) || b > SZ(wv[1]) || c > SZ(wv[2]) || d > SZ(wv[3]))
//		return -LLMAX;
//
//	if (a * w + b * (w + 1) + c * (w + 2) + d * (w + 3) > lim)
//		return -LLMAX;
//
//	ll ret = 0;
//	if (a)
//		ret += memo[0][a - 1];
//	if (b)
//		ret += memo[1][b - 1];
//	if (c)
//		ret += memo[2][c - 1];
//	if (d)
//		ret += memo[3][d - 1];
//
//	chmax(ret, dfs(a + 1, b, c, d));
//	chmax(ret, dfs(a, b + 1, c, d));
//	chmax(ret, dfs(a, b, c + 1, d));
//	chmax(ret, dfs(a, b, c, d + 1));
//
//	return ret;
//}


int n;
ll lim, w;
vvll wv, memo;


void init()
{
	ll v, tmp;

	wv.resize(4);
	memo.resize(4, vll(101, 0LL));

	cin >> n >> lim >> w >> v;
	wv[0].PB(v);

	REP(i, n - 1)
	{
		cin >> tmp >> v;
		wv[tmp - w].PB(v);		
	}

	REP(i, 4)
		sort(ALL(wv[i]), greater<ll>());

	REP(i, 4)
	{
		if (!wv[i].empty())
		{
			REP1C(j, SZ(wv[i]))
				memo[i][j] = memo[i][j - 1] + wv[i][j - 1];
		}
	}

}


int main()
{
	init();

	ll ans = 0;

	REPC(a, SZ(wv[0]))
	{
		REPC(b, SZ(wv[1]))
		{
			REPC(c, SZ(wv[2]))
			{
				REPC(d, SZ(wv[3]))
				{
					if (a * w + b * (w + 1) + c * (w + 2) + d * (w + 3) <= lim)
					{
						ll v = memo[0][a] + memo[1][b] + memo[2][c] + memo[3][d];
						chmax(ans, v);
					}
				}
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int mincnt[26];

vector <int> get_cnt(string s) {
    vector <int> cnt(26);
    for (int i = 0; i < s.size(); i++)
        cnt[s[i] - 'a']++;
    return cnt;
}

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

    vector <int> m(26);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        auto cnt = get_cnt(s);
        if (i == 0) {
            m = cnt;
        }
        else {
            for (int j = 0; j < 26; j++)
                m[j] = min(m[j], cnt[j]);
        }
    }
    string t;
    for (int j = 0; j < 26; j++)
        while (m[j] > 0)
            t += 'a' + j, m[j]--;
    cout << t << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[100005];
    int b[100005];
    for (int i = 0; i<100005; ++i)
        b[i] = 0;
    long long res = 0;
    for (int i = 0; i<n; ++i){
        cin >> a[i];
        res+=a[i];
        b[a[i]]++;
    }
    int q;
    cin >> q;
    while(q--){
        int l,r;
        cin >> l >> r;
        res = res + (long long)b[l]*(r - l);
        b[r]+=b[l];
        b[l] = 0;
        cout << res << endl;
    }

}

Measured memory_bytes: 4360
n = gets.to_i
s = gets.split.map(&:to_i)
q = gets.to_i
t = gets.split.map(&:to_i)

sum = 0

for i in 0..(q-1)
  left = 0
  right = n
  key = t[i]
  while left < right
    mid = (right+left)/2
    if key == s[mid]
      sum += 1
      break
    elsif key < s[mid]
      right = mid
    else
      left = mid+1
    end
  end
end
puts sum

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

typedef long long  ll;
typedef vector<int> vec;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int>par;
typedef vector<par>vpar;

#define forn(i,n) for(ll i=0;i<n;i++)
#define wez(n) ll (n); cin>>(n);
#define setmax(a,b) (a)=max((a),(b))
#define setmin(a,b) (a)=min((a),(b))
#define pb push_back
#define mp make_pair
#define outa(a,e) forn(i,e) cout << a[i] << (i==e-1?'\n':' ')
#define oute(n) cout<<n<<"\n"

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll n;
    cin>>n;
    ll dp[n][2];
    ll h[n];
    forn(i,n)cin>>h[i];
    dp[0][1]=0;
    dp[0][2]=0;
    dp[1][2]=1e9;
    dp[1][1]=(h[0]>h[1]?h[0]-h[1]:h[1]-h[0]);
    for(ll i=2;i<n;i++){ 
      dp[i][1]=min(dp[i-1][1],dp[i-1][2])+(h[i]>=h[i-1]?h[i]-h[i-1]:h[i-1]-h[i]);
      dp[i][2]=min(dp[i-2][1],dp[i-2][2])+(h[i]>=h[i-2]?h[i]-h[i-2]:h[i-2]-h[i]);
    }
    cout<<min(dp[n-1][1],dp[n-1][2])<<endl;
return 0;
}



Measured memory_bytes: 2688