akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const int MAXN = 50;
ll a[MAXN + 1];
const ll MAX = 1e16 + 1000;
int n;

bool check() {
    for(int i = 0; i < n; i++)
        if(a[i] >= n)
            return false;
    return true;
}

ll calc() {
    ll ans = 0;
    while(!check()) {
        ll sum = 0;
        for(int i = 0; i < n; i++)
            sum += a[i] / n;
        ans += sum;
        for(int i = 0; i < n; i++)
            a[i] = a[i] % n + sum - a[i] / n;
    }
    return ans;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll k;
    cin >> k;
    ll was = k;
    n = 50;
    for(int i = 0; i < n; i++) {
        a[i] = i;
    }
    while(k > 0) {
        sort(a, a + n);
        ll now = min(k, a[1]);
        now = min(now, (MAX - a[0]) / n);
        k -= now;
        a[0] += n * now;
        assert(a[0] <= MAX);
        for(int i = 1; i < n; i++)
            a[i] -= now;
    }
    cout << n << "\n";
    for(int i = 0; i < n; i++)
        cout << a[i] << " ";
    cout << "\n";
    assert(calc() == was);
    return 0;
}


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

int main(){
    double w,h;
    int x,y;
    cin >> w >> h;
    cin >> x >> y;

    double ans1 = (w*h)/2;

    if((x == w/2) && (y == h/2)){
        cout << fixed << ans1 << setprecision(10) << " " << "1" << endl;
    }
    else{
        cout << fixed << ans1 << setprecision(10) << " " << "0" << endl;
    }
}   


Measured memory_bytes: 256
#include<stdio.h>
#define mod 1000000007

int main()
{
  long N, K, i, j, n;
  long min_n = 0;
  long max_n = 0;
  long sum = 0;
  
  scanf("%ld %ld", &N, &K);
  n = 0;
  for(i = K; i <= N + 1; i++)
  {
   for(j = n; j < i; j++)
    {
     min_n += j;
     max_n += N - j;
    }
    sum += max_n - min_n + 1;
    n = j;
   
  }
  
  printf("%ld", sum % mod);

  return 0;
}

Measured memory_bytes: 1712
k = int(input())
num = input().split()

l = 0
ass = 0
ans = 0

for i in range(k):
    l += int(num[i])

for i in range(k):
    l -= int(num[i])
    ass += int(num[i]) * l
    

ans = ass % (10**9 + 7 )
print(ans)

Measured memory_bytes: 25084
#transit tree path
n=int(input())
graph={i:{} for i in range(1,n+1)}
for i in range(n-1):
    a,b,d=map(int,input().split())
    graph[a][b]=d
    graph[b][a]=d

import heapq
def dijkstra(s,graph,n):
    dist=[10**20 for i in range(n+1)]
    dist[s]=0
    pq=[]
    heapq.heapify(pq)
    heapq.heappush(pq,(0,s))
    while pq:
        x=heapq.heappop(pq)
        node,mini_dis=x[1],x[0]
        for point in graph[node].keys():
            w=graph[node][point]
            newlen=dist[node]+w
            if newlen<dist[point]:
                heapq.heappush(pq,(newlen,point))
                dist[point]=newlen
    return dist
Q,K=map(int,input().split())
P=dijkstra(K,graph,n)
for i in range(Q):
    x,y=map(int,input().split())
    print(P[x]+P[y])  

Measured memory_bytes: 66856
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


#include <set>
void solve() {
  int n, m;
  cin >> n >> m;
  vector<set<int> > S(m);
  loop(i,0,n) {
    int k;
    cin >> k;
    loop(j,0,k) {
      int a;
      cin >> a; a--;
      S[a].insert(i);
    }
  }
  
  int total = 0;
  for (auto s: S) {
    if (s.size() == n) total++;
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  string N;
  string result = "Yes";
  cin >> N;
  for(int i = 0; i < N.size(); i++){
    if(i % 2 == 0){ //odd
      if(N.at(i) == 'L'){
        result = "No";
      }
    } else if(N.at(i) == 'R'){
      result = "No";
    }
  }
  cout << result;
}

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

int main() {
    string S;
    long long K;
    cin >> S >> K;
    for (int i = 0; i < min((long long)S.size(), K); i++) {
        if (S[i] >= '2') {
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<P> vec;
const int N=1<<18;

/*
int dat[N*2-1];

void update(int k,int a){
	k+=N-1;
	dat[k].first=a;
	dat[k].second=i;
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[k*2+1],dat[k*2+2]);
	}
}

P query(int a,int b,int k=0,int l=0,int r=N){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	P vl=query(a,b,k*2+1,l,(l+r)/2);
	P vr=query(a,b,k*2+2,(l+r)/2,r);
	return max(vl,vr);
}
*/

bool flag[200005];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		P p;
		scanf("%d%d",&p.first,&p.second);
		vec.push_back(p);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	priority_queue<P> que;
	priority_queue<P,vector<P>,greater<P> > que2;
	int l=0,cnt=1;
	memset(flag,false,sizeof(flag));
	for(int i=m;i>=1;i--){
		while(l<n && vec[l].first>=i){
			que.push(P(vec[l].second,l));
			l++;
		}
		if(que.size()){
			P p=que.top();
			que.pop();
			cnt++;
		}
	}
	for(;l<n;l++){
		que.push(P(vec[l].second,l));
	}
	while(que.size()){
		P p=que.top();
		que.pop();
		que2.push(p);
	}
	for(int i=cnt;i<=m;i++){
		if(!flag[i]){
			if(que2.size()){
				P p=que2.top();
				if(i>=p.first){
					que2.pop();
				}
			}
		}
	}
	int res=(int)que2.size();
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
    sort(a.begin(), a.end(), greater<ll>());
    ll maxV = a[0];
	ll ansV;
	ll minTmp = 9223372036854775807LL;
    for (ll i = 1; i < n; i++) {
		ll tmp = abs(maxV / 2 - a[i]);
		if (chmin(minTmp, tmp)) {
			ansV = a[i];
		}
    }
    cout << maxV << " " << ansV << endl;
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll n, m;
    ll mod = 1e9 + 7;
    cin >> n >> m;
    ll cnt = 1;
    if (abs(m - n) >= 2)
        cnt = 0;
    else
    {
        for (int i = 1; i <= n; i++)
            cnt = (cnt * i) % mod;
        for (int i = 1; i <= m; i++)
            cnt = (cnt * i) % mod;
        if (n == m)
            cnt = (2 * cnt) % mod;
    }

    OP(cnt);

    return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};



int main(){
  ll N; cin >> N;
  vector<pair<ll, ll>> TA(N);
  rep(i, N) cin >> TA[i].first >> TA[i].second;

  ll l = 1, r = 1;

  rep(i, N){
    ll n = max((l+TA[i].first-1)/TA[i].first, (r+TA[i].second-1)/TA[i].second);
    l = n * TA[i].first, r = n * TA[i].second;
  }
  cout << l + r << endl;

}


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

def COOKIE(A,B):
    if A%2==1:A -= 1
    B += A//2
    A //= 2
    return A,B

for i in range(K):
    if i%2==0: A,B = COOKIE(A,B)
    else: B,A = COOKIE(B,A)
    
print(A,B)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
int main() {
	
	int N;
	int count=0,MAX=0;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++)
	{
		cin >> H[i];
	}

	for (int i = 0; i<N-1; i++)
	{
		if (H[i] >= H[i + 1])
		{
			count++;
			MAX = max(count, MAX);
		}
		else {
			count = 0;
		}
	}
	
	cout <<MAX ;
}

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

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
 
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template <class T>
inline void in(T &m)
{
    char ch;
    int flag = 0;
    while ((ch = getchar()) < '0' || ch > '9')
    {
        if (ch == '-')
        {
            flag = 1;
        }
    }
    for (m = 0; ch >= '0' && ch <= '9'; ch = getchar())
    {
        m = m * 10 + ch - '0';
    }
    if (flag)
    {
        m *= -1;
    }
}

int main(){
    int path[4]={0};
     int a,b;
    REP(i, 3) 
    {
      cin>>a>>b;
      path[a-1]++;
      path[b-1]++;
    }
    
  REP(i, 4) 
   {
     if(path[i]>2){
     cout<<"NO"<<endl;
     return 0;}
  }
  
  cout<<"YES"<<endl;
    
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, M, K;
  std::cin >> N >> M >> K;
  std::vector<i64> A, B;
  tools::read(A, N);
  tools::read(B, M);

  std::vector<i64> A_cumsum({0});
  std::partial_sum(A.begin(), A.end(), std::back_inserter(A_cumsum));
  std::vector<i64> B_cumsum({0});
  std::partial_sum(B.begin(), B.end(), std::back_inserter(B_cumsum));

  // 合計所要時間がK分を超えないようにx冊読めるような本の選び方が存在するか
  const auto f = [&](const i64& x) {
    for (i64 i = std::max<i64>(0, x - M); i <= std::min(x, N); ++i) {
      if (A_cumsum[i] + B_cumsum[x - i] <= K) {
        return true;
      }
    }
    return false;
  };

  i64 ok = 0;
  i64 ng = N + M + 1;
  while (ng - ok > 1) {
    i64 center = (ok + ng) / 2;
    if (f(center)) {
      ok = center;
    } else {
      ng = center;
    }
  }

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

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

vector<string> stringSplit(const string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep)) {
    v.push_back(buffer);
  }
  return v;
}

int main() {

  string s;
  getline(cin, s);
  
  vector<string> v = stringSplit(s, ' ');
  deque<string> que;

  for (int i = 0; i < v.size(); i++) {
    if (v[i] == "+" || v[i] == "-" || v[i] == "*") {
      string b_ = que.back();
      que.pop_back();
      string a_ = que.back();
      que.pop_back();
      int b = atoi(b_.c_str());
      int a = atoi(a_.c_str());
      if (v[i] == "+") {
        que.push_back(to_string(a + b));
      } else if (v[i] == "-") {
        que.push_back(to_string(a - b));
      } else {
        que.push_back(to_string(a * b));
      }
    } else {
      que.push_back(v[i]);
    }
  }

  string answer = que.front();
  que.pop_front();

  cout << answer << endl;

  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(string, s, t);
  vector<set<char>> to(26), from(26);
  rep(i, s.size()) {
    to[s[i] - 'a'].insert(t[i]);
    from[t[i] - 'a'].insert(s[i]);
  }
  rep(i, 26) {
    if (to[i].size() > 1 || from[i].size() > 1) {
      out("No");
      return 0;
    }
  }
  out("Yes");
}


Measured memory_bytes: 3920
using System;
using System.Collections.Generic;
using System.Linq;

namespace A {
    class Program {
        static void Main (string[] args) {
            var s = Console.ReadLine ();
            var dateInfos = s.Split ('/').Select (str => int.Parse (str)).ToList ();
            var yyyy = dateInfos[0];
            var mm = dateInfos[1];
            var dd = dateInfos[2];

            if (yyyy != 2019) {
                if (yyyy < 2019) {
                    Console.WriteLine ("Heisei");
                } else {
                    Console.WriteLine ("TBD");
                }
            } else if (mm != 4) {
                if (mm < 4) {
                    Console.WriteLine ("Heisei");
                } else {
                    Console.WriteLine ("TBD");
                }
            } else {
                if (dd <= 30) {
                    Console.WriteLine ("Heisei");
                } else {
                    Console.WriteLine ("TBD");
                }
            }
        }
    }
}

Measured memory_bytes: 11220
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int; using ull = unsigned long long;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& Rd(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) Rd(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { (Rd(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
		template <class T> auto operator[](T t) const { Rd(t); return t; }
		template <class... Ts> auto operator()(Ts... ts) const { (Rd(ts), ...); return tuple{move(ts)...}; }
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m"
	#define ASSERT(...) if(not(__VA_ARGS__)) throw runtime_error("local assertion failed")
	#define LOCAL_ONLY(...) __VA_ARGS__
	#else
	#define Debug(...) 0
	#define ASSERT(...) 0
	#define LOCAL_ONLY(...) 0;
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
	#define let auto const

// clang-format on





auto Main() {
	let n = Cin[0];
	auto A = Cin[vector<int> (n)];
	ll ans = 0;
	FOR(i,1,n) {
		ans += max(0,A[i-1]-A[i]);
		A[i] = max(A[i],A[i-1]);
	}
	cout<<ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 3960
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    vec A(N);
    vec cnt(N+1, 0);
    Rep (i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    ll ans = 0;
    Rep (i, N+1) {
        ans += cnt[i] * (cnt[i]-1) / 2;
    }

    Rep (i, N) {
        ll v = ans;
        ll n = A[i];
        v -= cnt[n] * (cnt[n]-1) / 2;
        v += (cnt[n]-1) * (cnt[n]-2) / 2;
        cout << v << endl;
    }
}

Measured memory_bytes: 5760
import std.stdio, std.conv, std.string, std.algorithm, std.range, std.array;

void main() {
auto input = readln.split.to!(int[]);
writeln((input[0] % 3 == 0 || input[1] % 3 == 0 || input.sum % 3 == 0) ? "Possible" : "Impossible");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] Az = new int[N];
        int[] sortedAz = new int[N];
        for (int i = 0; i < N; i++){
            Az[i] = sc.nextInt();
        }
        Arrays.sort(Az);
        int sum = 0;
        for (int i = 0; i < N; i++){
            sortedAz[i] = Az[N-i-1];
            sum += Az[N-i-1];
        }

        double limit = (double) sum / (4*M);
        for (int i = 0; i < M; i++){
            if (sortedAz[i] < limit){
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 35960
# initialize
s = list(input())
s2 = {}
s2_index = 1
num = 1

# RunLength
for index in range(len(s)):
  if index<len(s)-1:
    if s[index]!=s[index+1]:
      s2[s2_index] = num
      num = 1
      s2_index += 1
    else:
      num += 1
  s2[s2_index] = num

# initialize
zero = ""
zero2 = ""
s3 = ""
s4 = ""

def countzero(zero_number):
  temp = ""
  for index in range(zero_number-1):
    temp += "0 "
  return temp

for key,value in s2.items():
  if key%2!=0:
    # when R=L
    if s2[key]==s2[key+1]:
      zero += countzero(s2[key])
      if s2[key]=="1":
        s3 += "1 1 "
      else:
        s3 += zero+str(s2[key])+" "+str(s2[key])+" "+zero
        zero = ""
    # when (R+L)/2 is even
    elif (s2[key]+s2[key+1])%2 == 0:
      number = str(int((s2[key]+s2[key+1])/2))
      zero += countzero(s2[key])
      zero2 += countzero(s2[key+1])
      s3 += zero+number+" "+number+" "+zero2
      zero = ""
      zero2 = ""
    # when (R+L)/2 is odd
    else:
      number = str(int((s2[key]+s2[key+1])//2)+1)
      number2 = str(int((s2[key]+s2[key+1])//2))
      zero += countzero(s2[key])
      zero2 += countzero(s2[key+1])
      if int(s2[key])<int(s2[key+1]):
        if s2[key+1]%2==0:
          s3 += zero+number+" "+number2+" "+zero2
        else:
          s3 += zero+number2+" "+number+" "+zero2
      else:
        if s2[key]%2==0:
          s3 += zero+number2+" "+number+" "+zero2
        else:
          s3 += zero+number+" "+number2+" "+zero2
      zero = ""
      zero2 = ""

print(s3[:-1])

Measured memory_bytes: 15912
def main():
    N, MA, MB = map(int, input().split())
    dp = [[[float("inf")] * (401) for _ in range(401)] for _ in range(2)]
    dp[0][0][0] = 0
    dp[1][0][0] = 0
    for i in range(N):
        a, b, c = map(int, input().split())
        prev = (i-1) % 2
        current = i % 2
        for j in range(401):
            for k in range(401):
                if j-a >= 0 and k-b >= 0:
                    dp[current][j][k] = min(dp[prev][j][k],
                                            dp[prev][j-a][k-b] + c)
                else:
                    dp[current][j][k] = dp[prev][j][k]
    ans = float("inf")
    for i in range(1, 401):
        a = MA * i
        b = MB * i
        if a <= 400 and b <= 400:
            ans = min(ans, dp[(N-1) % 2][a][b])
        else:
            continue
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 66268
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author P Marecki
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            int n = s.length;
            int[][] a = new int[26][n];
            for (int i = 0; i < 26; i++) {
                a[i][n - 1] = 0;
                for (int at = n - 2; at >= 0; --at) {
                    a[i][at] = a[i][at + 1];
                    if (s[at + 1] == (char) ('a' + i)) a[i][at]++;
                }
            }
            //
            long res = 1;
            for (int at = 0; at < n; ++at) {
                res += (n - at - 1) - a[s[at] - 'a'][at];
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int c[3][3];
    rep(i, 0, 3){
        rep(j, 0, 3){
            scanf("%d", &c[i][j]);
        }
    }
    int f=1;
    rep(i, 0, 2){
        int buf = c[i][0] - c[i+1][0];
        rep(j, 1, 3){
            if(c[i][j] - c[i+1][j] != buf){
                f = 0;
            }
        }
    }
    printf(f ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int rgb = r * 100 + g * 10 + b;
    if (rgb % 4 == 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int h,w,sg,g,r,lg;
  scanf("%d %d",&h,&w);
  while(h!=0||w!=0){
    for(sg=0;sg<w;sg++){
      if(h==0){
	break;
	  }
      printf("#");
    }
    printf("\n");
    for(g=0;g<h-2;g++){
      if(w==0){
	break;
	  }
      printf("#");
      for(r=0;r<w-2;r++){
	printf(".");
      }
      printf("#\n");
    }
    for(lg=0;lg<w;lg++){
      if(h==0){
	break;
	  }
      printf("#");
    }
    printf("\n\n");
    scanf("%d %d",&h,&w);
  }
  return 0;
}
      

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

int K;
string S;
vector<string> sub;

int main(){
  cin >> S >> K;
  for(int i=0; i<S.size(); i++){
    for(int j=1; j<=5 && i+j<=S.size(); j++){
      sub.push_back(S.substr(i, j));
    }
  }
  sort(sub.begin(), sub.end());
  unique(sub.begin(), sub.end());
  cout << sub[K-1] << endl;

  return 0;
}

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

int main() {

  int n, m, nsum, msum, result;
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    nsum += i;
  }
  
  for (int j = 0; j < m; j++) {
    msum += j;
  }

  result = nsum + msum;
  cout << result << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <random>

#define ll long long

using namespace std;

struct item {
    int w;
    int c;
};

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n, W;
    scanf("%d %d", &n, &W);
    vector<item> a(n + 1);
    int commonVal = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &a[i].w, &a[i].c);
        commonVal += a[i].c;
    }
    vector<vector<int>> dp(2 + 1, vector<int>(commonVal + 1, 1e9 + 1e3));
    dp[0][0] = 0;
    int cur = 1;
    int prev = 0;
    for (int i = 1; i <= n; i++) {
        //printf("cur = %d prev = %d\n", cur, prev);
        for (int j = 0; j <= commonVal; j++)
            dp[cur][j] = (1e9 + 1e3);
        for (int prevVal = 0; prevVal <= commonVal; prevVal++) {
            dp[cur][prevVal] = min(dp[cur][prevVal], dp[prev][prevVal]);
            if (prevVal - a[i].c >= 0)
                dp[cur][prevVal] = min(dp[cur][prevVal], dp[prev][prevVal - a[i].c] + a[i].w);
        }
        swap(cur, prev);
    }
    for (int i = commonVal; i >= 0; i--) {
        if (dp[prev][i] <= W) {
            printf("%d", i);
            return 0;
        }
    }
    printf("0");
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
 
int main(){
  int a[1000005];
  int s,i=2,ans=0,m;
  
  cin >> s;
  a[1]=s;
  while(1){
    if(a[i-1]%2==0){
      a[i]=a[i-1]/2;
    }else{
      a[i]=3*a[i-1]+1;
    }
    for(int j=1;j<i;j++){
      if(a[j]==a[i]){
	ans=1;
	m=i;
      }
    }
    if(ans==1){
      break;
    }
    i++;
  }
  
  cout << m << '\n';
  return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A')a++;
        if(s[i]=='B')b++;
    }
    if(a==0||b==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


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

use v5.18;
use warnings;
use feature 'say';
use constant {
  'MIN' => 1,
  'MAX' => 10 ** 5,
  'B' => 'B',
  'W' => 'W',
};

LOOP: while( defined( my $text = <> ) ){
  chomp($text);

  my $length = length( $text );

  # 制約条件1: 1≦|S|≦10^5
  (MIN <= $length && $length <= MAX) or next LOOP;

  # 1文字切り出し
  my $temp = chop($text);

  # 制約条件2: S に含まれる文字は B または W のいずれかである
  unless($temp eq B || $temp eq W){
    next LOOP;
  }

  if(MIN == $length){
    say 0;
    next LOOP;
  }

  my $c = 0;
  for(2..$length){
    $text or last;
    my $compare = chop( $text );
    if( $temp ne $compare ){
      $c += 1;
      $temp = $compare;
    }
  }
  say $c;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
long a[100001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    
    long cnt = 0, sum = 0;
    // case 1: pos, neg, pos, ...
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        if (i % 2 == 0 & sum <= 0) {
            cnt += 1 - sum;
            sum = 1;
        } else if (i % 2 == 1 & sum >= 0) {
            cnt += sum + 1;
            sum = -1;
        }
        //cout << cnt << " ";
    }
    //cout << endl;
    long cnt_even = cnt;
    sum = cnt = 0;
    // case 2: neg, pos, neg, ...
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        if (i % 2 == 1 & sum <= 0) {
            cnt += 1 - sum;
            sum = 1;
        } else if (i % 2 == 0 & sum >= 0) {
            cnt += sum + 1;
            sum = -1;
        }
        //cout << cnt << " ";
    }
    //cout << endl;
    
    cout << min(cnt, cnt_even) << endl;
    
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  int64_t ans=0;
  cin >> v.at(0);
  int min=v.at(0);
  ans++;
  for(int i=1;i<N;i++){
    cin >> v.at(i);
    if(v.at(i)<=min){
      ans++;
      min=v.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappushpop

N,M = map(int,input().split())
# task[締切][価値]
tasks = [[] for _ in range(M)] 
for _ in range(N):
    a,b = map(int,input().split())
    if a <= M:
        tasks[M-a].append(b)

# 受注したバイト
q = []
# 締切=dayとなる最大の価値をqに格納
for day in range(M):
    # その日締切のバイト
    for v in tasks[day]:
        # まだ今日は受注してない
        if len(q) < day+1:
            heappush(q,v)
        else:
            heappushpop(q,v)

answer = sum(q)
print(answer)

Measured memory_bytes: 18404
#include<iostream>
using namespace std;
#include<cmath>
bool prime_judge(long long x) {
	if (x == 2)return true;
	if (x % 2 == 0)return false;
	if (x == 1 || x <= 0)return false;
	for (int i = 3; i <= sqrt(x); i += 2) {
		if (x%i == 0)return false;
	}
	return true;
}
int main() {
	//while (1) {
	//	long long x;
	//	cin >> x;
	//	cout << prime_judge(x) << endl;
	//}
	int a, d, n;
	while (cin >> a >> d >> n&&a&&d&&n) {
		long long x;
		int cnt = 0;
		for (int i = 0;; i++) {
			x = a + d*i;
			if (prime_judge(x)) {
				cnt++;
				//cout << cnt << " " << x << endl;
			}
			if (cnt == n) {
				cout << x << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
n=int(input())
h=list(map(int,input().split()))

m=h[0]
judge=True
for i in range(n-1):
    if h[i+1]>=h[i] and m<=h[i+1]:
        continue
        m=h[i+1]
    else:
        h[i]-=1
        if h[i+1]>=h[i] and m<=h[i+1]:
            m=h[i+1]
            continue
        else:
            judge=False

print("Yes" if judge else "No")


Measured memory_bytes: 14396
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n;
  ll a,b,c;
  ll p,q,r;
  p = q = r = 0;
  s = "Yes";
  rep(i,0,n){
    cin >> a >> b >> c;
    if(abs(b - q) + abs(c - r) == 0){
      s = "No";
      break;
    }
    if(abs(a - p) % (abs(b - q) + abs(c - r)) != 0)s = "No";
    p = a;q = b;r = c;
  }
  print(s);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	switch (n % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	default:
		break;
	}

	return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;

/////////////////////////////////

int const MAX = 100 * 1000 + 41;

int n;
int l[MAX];
int r[MAX];
multiset<ll> tl, tr;
ll addl, addr, ans;

ll getmax(multiset<ll> &t) {
	return (*t.rbegin());
}

ll getmin(multiset<ll> &t) {
	return (*t.begin());
}

void solve() {
	tl.insert(l[1]);
	tr.insert(l[1]);
	fi(2, n) {
		addl -= (r[i] - l[i]);
		addr += (r[i - 1] - l[i - 1]);
		ll l1 = getmax(tl) + addl;
		ll r1 = getmin(tr) + addr;
		err("l1 = %lld r1 = %lld l[i] = %d\n", l1, r1, l[i]);
		if (l1 < l[i] && l[i] < r1) {
			tl.insert(l[i] - addl);
			tr.insert(l[i] - addr);
			continue;
		}
		if (l[i] >= r1) {
			ans += l[i] - r1;
			tr.erase(tr.begin());
			tr.insert(l[i] - addr);
			tr.insert(l[i] - addr);						
			tl.insert(r1 - addl);
			continue;
		}
		if (l[i] <= l1) {
			ans += l1 - l[i];
			auto it = tl.end();
			it--;
			tl.erase(it);
			tl.insert(l[i] - addl);
			tl.insert(l[i] - addl);			
			tr.insert(l1 - addr);
			continue;
		}
		assert(false);
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	fi(1, n) {
		scanf("%d %d", &l[i], &r[i]);
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 10368
/* 
Rohit645
Rohit Kumar 
*/

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end() 
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main() {
	fastIo();
	int n, d; cin >> n >> d;
	int num = 2*d+1;
	cout << ll(ceil(n*1.0/num)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}



int main(){
    // Failed to predict input format
    ll N,M,X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    for (long long i = 0; i < N; i++) {
        cin >> C[i];
        for (long long j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    // vout(C);
    // mout(A);

    ll n = N;
    ll res=INT_MAX;
    for (ll bit = 0; bit < (1<<n); bit++) {
        V v;
        // V w;
        for (ll i = 0; i < n; i++) {
            if(bit & (1<<i)) {
                v.push_back(i);
            }else{
                // w.push_back(i);
            }
        }

        vector<ll> a(M);
        ll mi=0;
        for (ll i = 0; i < v.size(); i++) {
            ll idx=v[i];
            mi+=C[idx];
            for (long long j = 0; j < M; j++) {
                a[j]+=A[idx][j];
            }
        }

        bool f=true;
        for (long long j = 0; j < M; j++) {
            if(a[j]<X){
                f=false;
                break;
            }
        }
        if(f==true){
            chmin(res, mi);
        }

        // cout << bit << ": ";
        // for (ll i = 0; i < v.size(); i++) {
        //     cout << v[i] << " ";
        // }
        // cout << endl;

    }
    if(res==INT_MAX){
        cout << -1 << endl;
    }else{
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
n, m = gets.split.map(&:to_i)
a = Array.new(n)
n.times do |i|
    a[i] = gets.chomp
end
b = Array.new(m)
m.times do |i|
    b[i] = gets.chomp
end
ans_flag = false
(n - m + 1).times do |i|
    (n - m + 1).times do |j|
        flag = true
        m.times do |k|
            if a[i + k][j, m] != b[k]
                flag = false
                break
            end
        end
        ans_flag |= flag
        break if ans_flag
    end
    break if ans_flag
end

puts ans_flag ? "Yes" : "No"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

int lsone(int n)
{
	return (n&-n);
}

void mult(ll a[matmax][matmax], ll b[matmax][matmax], ll c[matmax][matmax], int m, int n, int p)
{
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= p; j++)
		{
			c[i][j] = 0;
			for (int k = 1; k <= n; k++)
			{
				c[i][j] += (a[i][k]*b[k][j])%mod;
				c[i][j] %= mod;
			}
		}
	}
}

void mat_pow(ll a[matmax][matmax], ll c[matmax][matmax], int n, ll p)
{
	if (p == 0)
	{
		for (int i = 1; i <= n; i++)
			c[i][i] = 1;
	}
	else if (p == 1)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
				c[i][j] = a[i][j];
		}
	}
	else
	{
		ll d[matmax][matmax];
		mat_pow(a, d, n, p/2);
		if (p % 2)
		{
			ll e[matmax][matmax];
			mult(d, d, e, n, n, n);
			mult(e, a, c, n, n, n);
		}
		else
		{
			mult(d, d, c, n, n, n);
		}
	}
}

ll pow1(ll a, ll b)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2);
		x *= x;
		x %= mod;
		if (b%2)
		{
			x *= a;
			x %= mod;
		}
		return x;
	}
}

ll a, b;

int main()
{
	fastio;		
	cin>>a>>b;

	if (a >= 9 or b >= 9)
	{
		cout<<":(\n";
	}
	else
		cout<<"Yay!\n";

	return 0;
}


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

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

#define FOR(i,n,m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i,n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin>>S;
    ll w=0,ans=0;
    
    REP(i,S.length())
    {
        if(S[i]=='W')
        {
            ans+=(i-w);
            w++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  
  vector<set<Int> > G(n),H(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace(y);
    G[y].emplace(x);
  }
  using P = pair<Int, Int>;
  queue<P> q;
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    if(G[x].count(y)) q.emplace(x,y);
    H[x].emplace(y);
    H[y].emplace(x);
  }

  UnionFind uf(n);
  while(!q.empty()){
    Int x,y;
    tie(x,y)=q.front();q.pop();
    if(uf.same(x,y)) continue;
    x=uf.find(x);y=uf.find(y);
    
    uf.unite(x,y);
    
    for(auto z:H[y]){
      if(G[x].count(z)) q.emplace(x,z);
      H[x].emplace(z);
      H[z].emplace(x);
    }    
    for(auto z:G[y]){
      if(H[x].count(z)) q.emplace(x,z);
      G[x].emplace(z);
      G[z].emplace(x);
    }
  }
  cout<<(uf.r[uf.find(0)]==n?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 125056