akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <typename T>
class seg {
	T t;
	using N = typename T::N;
	using F = typename T::F;
	vector<N> nt;
	vector<F> ft;
	void eval(int p, int l, int r) {
		if (ft[p] == t.IF)
			return;
		nt[p] = t.FN(ft[p], r - l, nt[p]);
		if (l + 1 < r) {
			t.FF(ft[p], ft[p + 1]);
			t.FF(ft[p], ft[p + (r - l & -2)]);
		}
		ft[p] = t.IF;
	}
	N init(N n, int p, int l, int r) {
		if (l + 1 == r)
			return nt[p] = n;
		int m = (l + r) / 2;
		return nt[p] = t.NN(init(n, p + 1, l, m), init(n, p + (r - l & -2), m, r));
	}
	N upd(int a, int b, F f, int p, int l, int r) {
		eval(p, l, r);
		if (b <= l || r <= a)
			return nt[p];
		if (a <= l && r <= b)
			return t.FN(ft[p] = f, r - l, nt[p]);
		int m = (l + r) / 2;
		return nt[p] = t.NN(upd(a, b, f, p + 1, l, m), upd(a, b, f, p + (r - l & -2), m, r));
	}
	N get(int a, int b, int p, int l, int r) {
		if (b <= l || r <= a)
			return t.IN;
		eval(p, l, r);
		if (a <= l && r <= b)
			return nt[p];
		int m = (l + r) / 2;
		return t.NN(get(a, b, p + 1, l, m), get(a, b, p + (r - l & -2), m, r));
	}
public:
	const int s;
	seg(int s) :s(s), nt(s * 2 - 1, t.IN), ft(s * 2 - 1, t.IF) {}
	seg(int s, N n) :seg(s) {
		init(n, 0, 0, s);
	}
	void upd(int a, int b, F f) {
		upd(a, b, f, 0, 0, s);
	}
	N get(int a, int b) {
		return get(a, b, 0, 0, s);
	}
};
struct L {
	typedef int N, F;
	const N IN = 1e9;
	const F IF = 1e9;
	N NN(N m, N n) { return min(m, n); }
	N FN(F f, int, N n) { return min(f, n); }
	void FF(F f, F &g) { g = min(f, g); }
};
tuple<int, int, int> t[222222];
vector<int> z;
int d[222222];
int main() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		t[i] = tuple<int, int, int>(a - c, b - c, c);
		z.push_back(a - c);
		z.push_back(b - c);
		z.push_back(c);
	}
	for (int i = 0; i < q; i++) {
		scanf("%d", d + i);
		z.push_back(d[i]);
	}
	sort(z.begin(), z.end());
	unique(z.begin(), z.end());
	for (int i = 0; i < n; i++) {
		get<0>(t[i]) = lower_bound(z.begin(), z.end(), get<0>(t[i])) - z.begin();
		get<1>(t[i]) = lower_bound(z.begin(), z.end(), get<1>(t[i])) - z.begin();
		get<2>(t[i]) = lower_bound(z.begin(), z.end(), get<2>(t[i])) - z.begin();
	}
	for (int i = 0; i < q; i++)
		d[i] = lower_bound(z.begin(), z.end(), d[i]) - z.begin();
	seg<L> s(z.size() + 1);
	for (int i = 0; i < n; i++)
		s.upd(get<0>(t[i]), get<1>(t[i]), get<2>(t[i]));
	for (int i = 0; i < q; i++) {
		int y = s.get(d[i], d[i] + 1);
		cout << (y > 1e8 ? -1 : z[y]) << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 20844
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int i[3] = {0, 0, 0};
    int t = 0;
    while (i[t] < s[t].size()) {
        int next;
        switch (s[t][i[t]]) {
            case 'a':
                next = 0;
                break;
            case 'b':
                next = 1;
                break;
            case 'c':
                next = 2;
                break;
        }
        ++i[t];
        t = next;
    }
    cout << "ABC"[t] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<int,int>

string toString(ll n)
{
    string str;
    stringstream ss;
    ss << n;
    ss >> str;
    return str;
}

// Method to convert n to base negBase
string toNegativeBase(ll n, int negBase)
{
    //  If n is zero then in any base it will be 0 only
    if (n == 0)
        return "0";

    string converted = "";
    while (n != 0)
    {
        // Get remainder by negative base, it can be
        // negative also
        ll remainder = n % negBase;
        n /= negBase;

        // if remainder is negative, add abs(base) to
        // it and add 1 to n
        if (remainder < 0)
        {
            remainder += (-negBase);
            n += 1;
        }

        // convert remainder to string add into the result
        converted = toString(remainder) + converted;
    }

    return converted;
}

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

    ll n;
    cin>>n;
    cout<<toNegativeBase(n,-2);

return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n,flag = 0,a,b,count = 0;
	cin >> a >> b ;
	string s[101];
	for (; a <= b; a++) {
		int c, d, e, f;
		c = a % 10;
		d = a / 10000;
		e = a / 1000 % 10;
		f = a % 100 / 10;
		if (c == d && e == f) count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    int result = 0;
    for (int i=0; i<4; i++) {
        if (s[i] == '+') {
            result++;
        } else if (s[i] == '-') {
            result--;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

ll tot,n;
unordered_map<int,int> cnt;

int main(){
    while(cin>>n){
        cnt.clear();
        vi a(n);
        forn(i,n){
            cin>>a[i];
            cnt[a[i]]++;
        }

        tot = 0;
        for(auto p: cnt){
            ll i = p.second;
            tot+= (i*(i-1))/2;
        }

        for(auto x: a){
            ll i = cnt[x];
            ll cur = (i*(i-1))/2;
            --i;
            ll out = tot - cur + (i*(i-1))/2;
            cout<<out<<endl;
        }
        // cout<<endl;

        
    }
    return 0;
}

Measured memory_bytes: 8392
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int l, r, d;
    cin >> l >> r >> d;

    int c = 0;
    for (int i = l; i <= r; i++) {
        c += i % d == 0;
    }

    cout << c << endl;

    return 0;
}

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

int main(){long N, H;
cin >> N >> H;
vector<long> a(N); vector<long> b(N);
rep(i, N) cin >> a.at(i) >> b.at(i);
sort(a.begin(), a.end()); reverse(a.begin(), a.end());
sort(b.begin(), b.end()); reverse(b.begin(), b.end());

long ans;
long i = 0;
while(b.at(i) > a.at(0)){
    H -= b.at(i);
    if(H <= 0){
        ans = i + 1;
        cout << ans << endl;
        return 0;
    } 
    i++;
    if(i == N) break;
}
long div; long res;
div = H / a.at(0);
res = H % a.at(0);
if(res) div++;
ans = i + div;

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;			
	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif

			ll t;
			t=1;
			while(t--)
			{
				ll n;
				cin>>n;
				
				ll total=0;
				ll arr[n];
				for(ll i=0;i<n;i++)
				{
				cin>>arr[i];
				total^=arr[i];
				}

				for(ll i=0;i<n;i++)
				{
					ll x=total^arr[i];
				cout<<x<<" ";
				}


			

                
			}
			return 0;
		 }	


Measured memory_bytes: 5140
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, colorX, colorY, D; vll path;
//***********//
int main() {
	cin >> N;
	string S;
	cin >> S;
	cin >> Q;
	for (l = 0; l < Q; l++) {
		ll k;
		cin >> k;
		ll D = 0, M = 0, DM = 0;
		ll ans = 0;
		for (i = 0; i < N; i++) {
			if (S[i] == 'D') {
				D++;
			}
			if (S[i] == 'M') {
				M++;
				DM += D;
			}
			if (S[i] == 'C') {
				ans += DM;
			}
			if (i >= k - 1) {
				if (S[i - k + 1] == 'D') {
					D--;
					DM -= M;
				}
				if (S[i - k + 1] == 'M') {
					M--;
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main()
{
    int N = 0;
    std::cin >> N;
    std::vector<int> A(N);
    for(int i = 0; i < N; i++)  std::cin >> A[i];

    int max = 0;
    long long sum = 0;
    for(int i = 0; i < N; i++)
    {
        if(max == A[i])
        {
            continue;
        }
        else if(A[i] < max)
        {
            sum += max - A[i];
        }
        else if(A[i] > max)
        {
            max = A[i];
        }
    }

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

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
 
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}
 
int main(){
    string s;
    cin >> s;
    s = '0' + s;
    int N = s.size();
    vector<int> A(N), S(N+1);
    for(int i=0; i<N; i++){
        A[i] = s[i] - '0';
        S[i+1] = S[i] + A[i];
    }
 
    static int64_t dp[1001001][2];
    for(int i=0; i<=N; i++) for(int j=0; j<2; j++) dp[i][j] = 1e18;
    dp[0][0] = 0;
    for(int i=0; i<N; i++){
        chmin(dp[i+1][0], dp[i][0] + A[i]);
        chmin(dp[i+1][1], dp[i][0] + A[i] + 1);
        chmin(dp[i+1][0], dp[i][1] + 10-A[i]);
        chmin(dp[i+1][1], dp[i][1] + 10-A[i]-1);
    }
    int64_t ans = dp[N][0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27740
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll N;
  cin >> N;
  vl a(N);
  rep(i,N){
    cin >> a[i];
  }
  vl num(N,0);
  per(i,N-1){
    ll j=i+1;
    ll k=2*j;
    ll cnt=0;
    while(k<=N){
      cnt+=num[k-1];
      k+=j;
    }
    cnt%=2;
    if((cnt-a[i])==0){
      num[i]=0;
    }
    else{
      num[i]=1;
    }
  }
  ll CNT=0;
  rep(i,N){
    if(num[i]==1){
      CNT++;
    }
  }
  cout << CNT << endl;
  rep(i,N){
    if(num[i]==1){
      cout << i+1 << endl;
    }
  }
}

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

int main() {
  int a,b,c;
  cin >> a>>b;
  c=a*b;

  if (c%2==0) {
    cout << "Even" << endl;
  }
  else if(c%2!=0){
  cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._
  import scala.math._
  val n = readInt()
  val files = List.fill(n){
    val Array(d, l) = readLine.trim.split(' ')
    (d == "y", l.toInt)
  }
  val sanitized = sanitize(files)
  val isRemoved = Array.fill(sanitized.length){false}
  var count = 0
  for (i ← sanitized.indices.filter(i ⇒ sanitized(i)._1).sortBy(i ⇒ sanitized(i)._2) if !isRemoved(i)) {
    count += 1
    val deleteLen = sanitized(i)._2
    var left = i
    var right = i
    while (sanitized.indices.contains(left) && (sanitized(left)._1 || sanitized(left)._2 < deleteLen)) {
      isRemoved(left) = true
      left -= 1
    }
    while (sanitized.indices.contains(right) && (sanitized(right)._1 || sanitized(right)._2 < deleteLen)) {
      isRemoved(right) = true
      right += 1
    }
  }
  println(count)
  @tailrec def sanitize(file: List[(Boolean, Int)], result: List[(Boolean, Int)] = Nil): Array[(Boolean, Int)] = {
    (file, result) match {
      case (Nil, _) ⇒ result.reverse.toArray
      case ((f@(true, _))::r, Nil) ⇒ sanitize(r, f::result)
      case (_::r, Nil) ⇒ sanitize(r, Nil)
      case ((true, l)::fr, (true, r)::rr) ⇒ sanitize(fr, (true, min(l, r))::rr)
      case ((false, l)::fr, (false, r)::rr) ⇒ sanitize(fr, (false, max(l, r))::rr)
      case (f::fr, _) ⇒ sanitize(fr, f::result)
    }
  }
}



Measured memory_bytes: 45488
#include<bits/stdc++.h>
using namespace std;
priority_queue<double,vector<double>,greater<double> > que;
int main()
{
    int n;
    double ans=0;
    double a;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lf",&a);
        que.push(a);
    }
    while(que.size()!=1)
    {
        double x=que.top();
        que.pop();
        double y=que.top();
        que.pop();
        que.push((x+y)/2);
    }
    printf("%lf\n",que.top());
    return 0;
}


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

int main(){

int N;
string S;
cin >> N >> S;

//'.'　=　白、'#' =　黒
//.....####か全部'#'or'.'
//左の黒の数と右の白の数の合計が一番少なくなる境目があるはず（だよね？）



//白と黒の累積和を作る

vector<int>w_sum(N + 1);
vector<int>b_sum(N + 1);

w_sum.push_back(0);
b_sum.push_back(0);

    for(int i = 1; i < N + 1; i++){

        if(S.at(i - 1) == '.') {
            w_sum.at(i) = w_sum.at(i - 1) + 1;
            b_sum.at(i) = b_sum.at(i - 1);           
        }else if(S.at(i - 1) == '#'){
            w_sum.at(i) = w_sum.at(i - 1);
            b_sum.at(i) = b_sum.at(i - 1) + 1;            
        }
    }

//各境目の左の黒の数と右の白の数の合計を求める。（合計の最小値を保持しながら）

int ans = N;

    for(int i = 0; i < N + 1; i++){ 
        
    ans = min(ans, b_sum.at(i) + (w_sum.at(N) - w_sum.at(i)));

    }

cout << ans << endl; 
}

Measured memory_bytes: 2948
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22)
		printf("bust\n");
	else
		printf("win\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int n;
  int i, j;
  int p[10001] = {};
  p[0] = p[1] = 1;
  for(i = 2 ;i < 10001 ; i++){
    if(p[i] != 1)
      for(j = 2 * i ; j < 10001 ; j += i){
       p[j] = 1;
 }
  }
  while(1){
  scanf("%d",&n);
  if( n == 0 ){
  break;
  }
    for(i = n ; i >= 0 ; i--)
  	if(p[i] != 1 && p[i - 2] != 1){
        break;
  	}
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 648
use proconio::input;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut s = BTreeSet::new();

    for _ in 0..k {
        input! {
            d: usize,
            a: [usize; d],
        }

        for j in a {
            s.insert(j);
        }
    }

    println!("{}", n - s.len());
}


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

using namespace std;

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

#define F first
#define S second

const int MAXN = 100 + 3;

int n;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s; n = s.size();

	int ans = 1e9;
	for (char c = 'a'; c <= 'z'; c++){
		bool fl = 0;
		for (char ch:s)
			if (ch == c) fl = 1;
		if (!fl) continue;

		string t = s;
		int ret = 0;
		while (1){
			bool fail = 0;
			for (char ch:t)
				if (ch != c) fail = 1;
			if (!fail) break;

			string temp;
			for (int i = 0; i + 1 < t.size(); i++)
				if (t[i] == c || t[i+1] == c)
					temp.push_back(c);
				else
					temp.push_back(t[i]);
			t = temp;
			ret++;
		}
		ans = min(ans, ret);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int H, W;
  cin >> H >> W;
  string s;
  rep(i, H) {
    cin >> s;
    cout << s << '\n' << s << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
#include "string"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int howlong = (h2 * 60 + m2) - (h1 * 60 + m1);
	cout << howlong - k << endl;
	return 0;
}

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

using namespace std;

int main() {
  // input
  int _a, _b, _c, k;
  cin >> _a >> _b >> _c;
  cin >> k;

  // sort
  std::vector<int> v = {_a, _b, _c};
  std::sort(v.begin(), v.end());
  int ans = v[0] + v[1] + (v[2] * (1 << k));
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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



int main(){

  int n;
  cin>> n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int al=0,b=0;
  rep(i,n){
    if(i%2==0){
      al+=a[i];
    }else{
      b+=a[i];
    }
  }
  cout<<al-b<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool flg=true;
  for(int i=1; i<=s.size(); i++){
    if(i%2==1){
      if(s[i-1]=='L'){flg=false; break;}
    }
    else{
      if(s[i-1]=='R'){flg=false; break;}
    }
  }
  if(flg) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 2005;
array<ll, MAX_SIZE> fac, inv, finv;
void finit() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
    finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
    for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;
    
    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

// N個の区別できるものをK個以下の区別できないグループに分類する通り数 O(KlogN)
ll bell_number(ll N, ll K){
    ll ret = 0;
    vector<ll> acc(K + 1, 1);
    for (ll i = 1; i <= K; i++) acc[i] = (MOD + finv[i] * (i & 1 ? -1 : 1) + acc[i - 1]) % MOD;

    for (ll i = 0; i <= K; i++) (ret += modpow(i, N, MOD) * finv[i] % MOD * acc[K - i]) %= MOD;
    return ret;
}

int main() {
    init();
    finit();
    ll N, K;
    cin >> N >> K;

    cout << bell_number(N, K) << endl;
}


Measured memory_bytes: 3284
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    int N;
    cin >> N;
    string S = to_string(N);
    int f = 0;
    for(int i=0; i<S.size(); i++) f += S[i] - '0';
    if(N%f == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;

using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

int main() {
    string S;
    
    cin >> S;
  
    auto it = S.begin(), ite = S.end() - 1;
  int r = 0;
  
    REP(i, S.length() / 2) {
      if (*it != *ite)
        r++;
      it++;
      ite--;
    }
    
    cout << r << endl;
    
    return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const string MINUSINF = "-";

void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; ++i) cin >> A[i];

    // 初期化
    for (int i = 0; i < 11000; ++i) dp[i] = MINUSINF;

    // 初期条件
    dp[0] = "";

    // DP ループ
    for (int i = 0; i <= N; ++i) {
        if (dp[i] == MINUSINF) continue;
        for (auto a : A)  {
            chmax(dp[i+match[a-1]], dp[i] + (char)('0' + a));
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 43776
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(j,n) for(int i=(int)(j);i<=(int)(n);i++)
signed main(){
  int N;
  cin>>N;
  int ans5=N/105,ans0=N/100;
  bool flag=true;
  rep(ans5,ans0){
    if(i*100<=N&&N<=i*105){
      flag=false;
      cout<<"1"<<endl;
      break;
    }
      }
  if(flag)
    cout<<"0"<<endl;
      }

Measured memory_bytes: 256
def main():
    import bisect
    import numpy as np
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    l.sort()
    l1 = np.array(l)
    def bise(x):
        y = np.searchsorted(l1,x-l1)
        return n*n-y.sum()

    left = -1
    right = l[-1]*2+1

    while right > left+1:
        mid = (right+left)//2
        
        if bise(mid) >= k:
            left = mid
        else:
            right = mid
    ans = 0
    count = 0
    acc = [0]
    for i in l:
        acc.append(acc[-1]+i)
    for i in l:
        index = bisect.bisect_left(l,right-i)
        ans += i*(n-index) + acc[n]-acc[index]
        count += n-index

    print(ans-(count-k)*left)
if __name__ == "__main__":
    main()

Measured memory_bytes: 23420
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
int main() {
	int a = 0, b = 0, c = 0,d = 0;
	int minx = 0, miny = 0;
	int ary[10000] = {};
	char str[10000] = {};
	std::cin >> a>> b >> c >> d;
	if (a < b) {
		minx = a;
	}
	else { minx = b; }
	if (c < d) {
		miny = c;
	}
	else { miny = d; }
	std::cout <<minx+miny << std::endl;

}

Measured memory_bytes: 256
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const int maxn = 110;
int n, k;
int a[maxn];
int f[100100];

void work() {
  n = read(), k = read();
  rep(i, 1, n) a[i] = read();
  f[0] = 0;
  rep(i, 1, k) {
    rep(j, 1, n) if (i >= a[j] && f[i - a[j]] == 0) {
      f[i] = 1; break;
    }
  }
  puts(f[k] == 1 ? "First" : "Second");
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 640
s = input()
x,y = map(int,input().split())
l = []
cnt = 0
for i in s:
    if i=='T':
        l.append(cnt)
        cnt = 0
    else:
        cnt+=1
l.append(cnt)
horizontal = l[2::2]
vartical = l[1::2]
horizontal.sort()
horizontal = horizontal[::-1]
vartical.sort()
vartical = vartical[::-1]
x-=l[0]
now_x = 0
now_y = 0
for i in horizontal:
    if now_x<x:
        now_x+=i
    else:
        now_x-=i
for i in vartical:
    if now_y<y:
        now_y+=i
    else:
        now_y-=i
if now_x==x and now_y==y:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
N = int(input())
line_1 = list(map(int, input().split()))
line_2 = list(map(int, input().split()))

score = line_1[0] + line_2[N - 1]
for i in range(1, N):
    score = max(score, sum(line_1[:i]) + sum(line_2[i - 1:]))
print(score)

Measured memory_bytes: 3060
var n,i:longint;
    a:array[0..500]of longint;
    x,ans:longint;
begin
  read(n);
  for i:=1 to n do
  begin
    read(x);
    inc(a[x]);
  end;
  for i:=1 to 100 do
  if a[i]>0 then inc(ans);
  writeln(ans);
end.

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
using namespace std;
#define ll long long

int main() {
	string S; cin >> S;
	int lose=0;
	for(int i=0; i<S.size(); ++i){
	    if(S[i]=='x') ++lose;
	}
	cout << (lose<8 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll x; cin >> x;
	ll ans=0;
	ans+=(x/500)*1000;
	x%=500;
	ans+=(x/5)*5;
	cout << ans << endl;
	return 0;
}

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

using namespace std;


int main() {

    string S, T;
    cin >> S >> T;
    string UNRESTORABLE = "UNRESTORABLE";
    int lengthS = S.length();
    int lengthT = T.length();


    // 例外
    if (lengthS < lengthT) {
        cout << UNRESTORABLE << endl;
        return 0;
    }

    int n = -1;
    // とりあえず辞書順文字列は後で考える
    // 文字列S中に文字列Tが存在可能化どうかを文字列Sのi番目の文字を起点にしたときに考える
    for (int i = 0; i < lengthS; ++i) {
        //char s = S[i];
        // cout << s;
        for (int j = 0; j < lengthT; ++j) {
            if (i + j >= lengthS) { break; }
            char s = S[i + j];
            char t = T[j];
            // cout <<s <<":"<< t<<":"<<endl;
            if (s != t && s != '?') {
                break;
            }
            if (j == lengthT - 1) {
                n = i;
            }
//             cout << n << endl;
        }
        //cout << n<<endl;
//        if (n > -1) {
//            break;
//        }
    }

//    cout << n << endl;
    string ans;
    if (n == -1) {
        ans = UNRESTORABLE;
    }

    int temp = 0;
//    cout << "n:" << n << endl;
    if (n > -1) {
        for (int i = 0; i < lengthS; ++i) {

            // 文字列Tに変換
            if (i >= n && i < n + lengthT) {
                S[i] = T[temp];
                temp++;
            }
//            cout <<"S[i]"<<S[i]<<endl;
            if (S[i] == '?') {
                S[i] = 'a';
            }
        }
        ans = S;
    }


    cout << ans << endl;
}

Measured memory_bytes: 256
// Problem : D - Knapsack 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

# include<bits/stdc++.h> 
#define ll long long
#define pb push_back

using namespace std ; 

int main() {
	int n , w; 
	cin >> n >>w; 
	int weights[n+1] ; 
	int values[n+1] ; 
	ll dp[w+1][n+1] ; 
	memset(dp,0,sizeof(dp)) ; 
	for(int i =1 ; i <= n ; ++i)
		cin >> weights[i] >> values[i] ; 

	for(int i = 1; i <= w ; ++i) {
		for(int j =1 ; j <= n ; ++j) {
			dp[i][j] = dp[i][j-1] ; 
			if(i-weights[j] >= 0)
			dp[i][j] = max(dp[i][j] , dp[i-weights[j]][j-1] + values[j] ) ; 
		}
	}
	/*for(int i = 1; i <= w ; ++i) {
		for(int j =1 ; j <= n ; ++j) {
			cout << dp[i][j] <<" " ; 
		}
		cout<<endl ;
	}*/
	cout<<dp[w][n] ; 
	
}

Measured memory_bytes: 79104
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))
(defun f(str0 str1)
  (labels ((rec(i acc)
             (if (< i (length str0))
               (rec (1+ i) (cons (char str1 i) (cons (char str0 i) acc)))
               (nreverse acc))))
    (rec 0 nil)))
(let* ((line0 (read-line nil nil))
       (line1 (read-line nil nil))
       (splited (splitat #\space line1)))
  (format t "~{~A~}~%" (f (car splited) (cadr splited))))


Measured memory_bytes: 13792
use std::io::*;
use std::str::*;
use std::f64::consts::*;
use std::f64;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        a: i32,
        b: i32,
        v: String,
    }
    let mut all = 0;
    let mut external = 0;
    let chars: Vec<char> = v.chars().collect();
    for p in chars {
        if p == 'c' { println!("No"); continue; }
        if all < a + b {
            if p == 'a' {
                all += 1;
                println!("Yes");
                continue;
            } else if p == 'b' && external < b {
                all += 1;
                external += 1;
                println!("Yes");
            } else {
                println!("No");
                continue;
            }
        } else {
            println!("No");
            continue;
        }
    }
}

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

bool calc(int x) {
    if (x == 0) {
        return true;
    }
    while (x % 2 == 0) {
        if (x == 2) {
            return true;
        }
        x /= 2;
    }
    return false;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c) {
        cout << (a % 2 == 0 ? "-1" : "0") << endl;
        return 0;
    }

    int t = 0;
    int aa, bb, cc;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        t++;
        aa = b/2 + c/2;
        bb = a/2 + c/2;
        cc = a/2 + b/2;
        a = aa;
        b = bb;
        c = cc;
    }

    cout << t << endl;
}


Measured memory_bytes: 384
k, n = map(int, input().split())
a = list(map(int, input().split()))

ans = []

for i in range(n):
    if i == 0:
        dist = a[0] + (k - a[-1])
    else:
        dist = a[i] - a[i - 1]
    ans.append(dist)

print(k - max(ans))

Measured memory_bytes: 26444
str1 = gets.split
A,B,C = str1[0].to_i, str1[1].to_i, str1[2].to_i

if A > C
  if B < C
    puts "Yes"
  else
    puts "No"
  end
else
  if B > C
    puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 1788
#include<stdio.h>
#define H 1400
#define W 1400
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

int a[H][W];

int solve(int h,int w){
	int dp[h][w];
	int max=-1;
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			dp[i][j]=0;
		}
	}
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]==1)
				dp[i][j]=0;
			else if(i==0 || j==0)
				dp[i][j]=!a[i][j];
			else 
				dp[i][j]=MIN3(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])+1;
			
			max=MAX(dp[i][j],max);
			
		}
	}
	
	return max*max;
}


int main(){
	int h,w;
	
	scanf("%d %d",&h,&w);
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	printf("%d\n",solve(h,w));
	
	return 0;
	
}


Measured memory_bytes: 17112
N=int(input())
A=[int(_) for _ in input().split()]
height=A[0]
s=0
for a in range(len(A)-1):
    if A[a+1]<height:
        s+=height-A[a+1]
    elif A[a+1]>height:
        height=A[a+1]
print(s)


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

using namespace std;

int H, W, N;
int a[10005];

queue<int> Q;
int tmp[105];


int main(void)
{
	cin >> H >> W >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= a[i]; j++){
			Q.push(i);
		}
	}
	
	for(int h = 0; h < H; h++){
		for(int w = 0; w < W; w++){
			tmp[w] = Q.front();
			Q.pop();
		}
		if(h % 2) reverse(tmp, tmp + W);
		for(int i = 0; i < W; i++){
			cout << tmp[i];
			if(i != W-1) cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a[26]={0};
	char ch;
	while(cin>>ch){
		ch=ch-'A';
		if(ch==0||ch==32)a[0]+=1;
		if(ch==1||ch==33)a[1]+=1;
		if(ch==2||ch==34)a[2]+=1;
		if(ch==3||ch==35)a[3]+=1;
		if(ch==4||ch==36)a[4]+=1;
		if(ch==5||ch==37)a[5]+=1;
		if(ch==6||ch==38)a[6]+=1;
		if(ch==7||ch==39)a[7]+=1;
		if(ch==8||ch==40)a[8]+=1;
		if(ch==9||ch==41)a[9]+=1;
		if(ch==10||ch==42)a[10]+=1;
		if(ch==11||ch==43)a[11]+=1;
		if(ch==12||ch==44)a[12]+=1;
		if(ch==13||ch==45)a[13]+=1;
		if(ch==14||ch==46)a[14]+=1;
		if(ch==15||ch==47)a[15]+=1;
		if(ch==16||ch==48)a[16]+=1;
		if(ch==17||ch==49)a[17]+=1;
		if(ch==18||ch==50)a[18]+=1;
		if(ch==19||ch==51)a[19]+=1;
		if(ch==20||ch==52)a[20]+=1;
		if(ch==21||ch==53)a[21]+=1;
		if(ch==22||ch==54)a[22]+=1;
		if(ch==23||ch==55)a[23]+=1;
		if(ch==24||ch==56)a[24]+=1;
		if(ch==25||ch==57)a[25]+=1;
	}
	for(int i=0;i<=25;i++){
		printf("%c : %d\n",'a'+i,a[i]);
	}
	return 0;
}


Measured memory_bytes: 3228
from heapq import heappush, heappop
N, M = map(int, input().split())
D = []
for i in range(N):
    a, b = map(int, input().split())
    D.append((a, b))
D = sorted(D)
ans = 0
j = 0
que = []
for i in range(1, M + 1):
    while j < N and D[j][0] <= i:
        heappush(que, -D[j][1])
        j += 1
    if que:
        ans += -heappop(que)

print(ans)





Measured memory_bytes: 70488
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main(){
  vector<int> G[100];
  stack<int> q;
  vector<int> d(100,200000000),f(100,200000000);
  int n,u,k,v,time=0;
  bool flg;
  
  cin >> n;
  //G.push_back(new vector<int>(,10));
  for (int i=0;i<n;i++){
    cin >> u>> k;
    for (int j=0;j<k;j++){
      cin >> v;
      G[u-1].push_back(v-1);
    }
  }
  for (int vi=0;vi<n;vi++){
    if (d[vi]<=time)continue;
    q.push(vi);
    d[vi]=++time;
    while (!q.empty()){
      u=q.top();
      for (int i=0;i<G[u].size();i++){
	v=G[u][i];
	if (d[v]>time){
	  q.push(v);
	  d[v]=++time;
	  flg=true;
	  break;
	}
      }
      if (!flg){
	q.pop();
	f[u]=++time;
      }else{
	flg=false;
      }
    }
    
  }
  for (int i=0;i<n;i++)
    cout << i+1 <<" "<< d[i]<<" "<<f[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] A = new int[n];
        for(int i=0;i<n;i++) A[i] = sc.nextInt();
        int q = sc.nextInt();
        for(int i=0;i<q;i++){
            int m = sc.nextInt();
            boolean check = false;
            for(int j=0;j<n;j++) {
                check = recursive(A, m, 0, j,n,check);
            }
            if(check) System.out.println("yes");
            else System.out.println("no");
        }
    }
    public static boolean recursive(int A[],int m,int sum,int num,int n,boolean check){
        for(int i=num;i<n;i++){
            if(check) break;
            if (A[i]+sum==m) {
                check =true;
                break;
            }
            else if(A[num]+sum<m){
                int sum2=sum+A[num];
                check = recursive(A,m,sum2,i+1,n,check);
            }
            else break;
        }
        return check;
    }
}


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


#define rep(i, j) for(int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define rrep(i, j) for(int i = (j); i >= 0; i--)
#define all(v) v.begin(), v.end()



template<class T, T f(T, T), T unit>
class SegmentTree {
  public:
    int n;
    vector<T> data;
    // function<T(T, T) > f; // ?????????
    // T unit;               // f ?????????????????????
    SegmentTree(int nn) {
        n = 1;
        while(n < nn) n *= 2;
        data.resize(2 * n - 1, unit);
    }
    //index k in [0, n) ????????? val ?????´??°
    void update(int k, T val) {
        assert(0 <= k and k < n);
        k += n - 1;
        data[k] = val;
        while(k > 0) {
            k = parent(k);
            data[k] = f(data[left_child(k)], data[right_child(k)]);
        }
    }
    // [a, b) 
    int query(int a, int b) {
        assert(0 <= a and a < b and b <= n);
        return query(a, b, 0, 0, n);
    }
  private:
    //[a, b) ????????¨???, now???????????´???, [l,r)?????????????????´???
    T query(int a, int b, int now, int l, int r){
        if( out_of_range(a, b, l, r) ) return unit;
        if( within_range(a, b, l, r) ) return data[now];
        else { // cross range
            T vleft = query(a, b, left_child(now), l, (l + r) / 2);
            T vright = query(a, b, right_child(now), (l + r) / 2, r);
            return f(vleft, vright);
        }
    }
    bool out_of_range(int a, int b, int l, int r) { return r <= a or b <= l; }
    bool within_range(int a, int b, int l, int r) { return a <= l and r <= b; }
    int left_child(int i) { return i * 2 + 1; }
    int right_child(int i) { return i * 2 + 2; }
    int parent(int i) { return (i - 1) / 2; }
};

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


template<class T>
T rmq_op(T a, T b) {
    return min(a, b);
}

template<class T, T INF>
using RangeMinimumQuery = SegmentTree<T, rmq_op<T>, INF>;

/*
template<class T>
class RangeMinimumQuery : public SegmentTree<T> {
  public:
    RangeMinimumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ min(a, b); }, INF) {}
};

template<class T>
class RangeMaximumQuery : public SegmentTree<T> {
  public:
    RangeMaximumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ max(a, b); }, -INF) {}
};

template<class T>
class RangeSumQuery : public SegmentTree<T> {
  public:
    RangeSumQuery(int n) : SegmentTree<T>(n, [](T a, T b){ a + b; }, 0) {}
};

*/


int main() {
    int n, q; cin >> n >> q;
    RangeMinimumQuery<long long, (1LL << 31) - 1> rmq(n);
    rep(i, q) {
        int com, x, y; cin >> com >> x >> y;
        if(com == 0) rmq.update(x, y);
        else cout << rmq.query(x, y + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 4932
#include<bits/stdc++.h>
using namespace std;
const int inf=1000000000;
int N=1000000;
vector<int>d(N,-inf);
vector<int>check(N,0);
vector<vector<int>>e(N);
int dfs(int v){
    if(d[v]!=-inf)return d[v];
    if(e[v].size()==0)return d[v]=1;
    for(int i=0;i<e[v].size();i++){
        int u=e[v][i];
        if(check[u]==1 && d[u]==-inf)return d[v]=inf;//non-DAG
        check[u]=1;
        d[v]=max(d[v],dfs(u)+1);
    }
    return d[v];
}
int main(){
    int n;
    cin>>n;
    int a[n][n-1];
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n-2;j++){
            e[min(i,a[i][j])*1000+max(i,a[i][j])].push_back
            (min(i,a[i][j+1])*1000+max(i,a[i][j+1]));
        }
    }
    int m=0;
    for(int i=0;i<N;i++)m=max(m,dfs(i));
    if(m>=inf)cout<<"-1"<<endl;
    else cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 54116
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner (System.in);
		final int n = scan.nextInt();
		int[] sequence = new int[n];
		
		for (int i = 0; i < n; i++) {
			sequence[i] = scan.nextInt();
		}
		scan.close();
		
		Partition (sequence, 0, n - 1);
		
		
	}
	
	static void Partition (int[] array, int p, int r) {
		int x = array[r];
		int i = p - 1;
		int temp;
		
		for (int j = p; j < r; j++) {
			if (array[j] <= x) {
				i++;
				temp = array[j];
				array[j] = array[i];
				array[i] = temp;
			}
		}
		
		array[r] = array[i + 1];
		array[i + 1] = x;
		
		printArray (array, i + 1);
		
		
		
	}
	
	static void printArray (int[] data, int x) {
		int n = data.length;
		for (int i = 0; i < n; i++) {
			if ( i != n - 1) {
				if ( i != x) System.out.print(data[i] + " ");
				else System.out.print("[" +data[i] + "] "); 
			}
			else System.out.println(data[i]);
		}
	}

	
}



Measured memory_bytes: 70064