akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
	long long int x,y,h,w,n,i,price;
	while(cin >> n && n){
		price = 0;
		for(i=0;i<n;i++){
			cin >> x >> y >> h >> w;
			if(x+y+h<=60&&w<=2) price += 600;
			else if(x+y+h<=80&&w<=5) price += 800;
			else if(x+y+h<=100&&w<=10) price += 1000;
			else if(x+y+h<=120&&w<=15) price += 1200;
			else if(x+y+h<=140&&w<=20) price += 1400;
			else if(x+y+h<=160&&w<=25) price += 1600;
		}
		cout << price << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int wa=0;
    
    if(a>=b){
        wa+=b;
    }else{
        wa+=a;
    }
    
    if(c>=d){
        wa+=d;
    }else{
        wa+=c;
    }
    
    cout<<wa<<endl;
    
   
    
    return 0;
   
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, m, c;
	cin >> n >> m >> c;
	int b[m];
	int j[m];
	REP(i, m) cin >> b[i];
	int a[n][m];
	int cnt = 0;
	REP(i, n){
		ll tmp = 0;
		REP(j, m){
			cin >> a[i][j];
			tmp += a[i][j] * b[j];
		}
		if (tmp + c > 0) cnt++;
	}

	cout << cnt << endl;

}


Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<map>
#include<set>

template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
using ll = long long;
using P = pair<int, ll>;
int n;
ll k;
vector<int> a;
vector<vector<P>> hop;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a = vector<int>(n);
    hop = vector<vector<P>>(60, vector<P>(n));
    REP(i, n) cin >> a[i];
    map<int, int> last;
    REP(i, n) last[a[i]] = i;
    REP(i, n) {
        int lasti = last[a[i]];
        int dist = lasti < i ? i - lasti : i + n - lasti;
        hop[0][lasti] = make_pair((i + 1) % n, dist + 1);
        last[a[i]] = i;
    }

    // doubling
    for (int k = 1; k < 60; ++k) {
        REP(i, n) {
            P prehop = hop[k - 1][i];
            P next = hop[k - 1][prehop.first];
            hop[k][i] = make_pair(next.first, next.second + prehop.second);
        }
    }

    // for (int k = 0; k < 20; ++k) {
    //     D(k); DV(hop[k]);
    // }

    ll max_steps = k * n;
    ll steps = 0;
    int i = 0;
    while(1) {
        int kok = 0;
        int kng = 60;
        while (kok + 1 < kng) {
            int kmid = (kok + kng) / 2;
            if (kmid != 60 && steps + hop[kmid][i].second <= max_steps) {
                kok = kmid;
            } else {
                kng = kmid;
            }
        }
        if (steps + hop[kok][i].second > max_steps) break;
        steps += hop[kok][i].second;
        i = hop[kok][i].first;
    }
    // DD(i, steps);
    set<int> st;
    vector<int> ans;
    while(steps < max_steps) {
        int nx = a[i];
        if (st.find(nx) == st.end()) {
            st.insert(nx);
            ans.push_back(nx);
        } else {
            while (st.find(nx) != st.end()) {
                st.erase(*ans.rbegin());
                ans.pop_back();
            }
        }
        i = (i + 1) % n;
        steps++;
        // DV(ans);
    }
    // D(steps);
    if (ans.size() > 0) {
        REP(i, ans.size() - 1) cout << ans[i] << " ";
        cout << *ans.rbegin();
    }
    cout << endl;
}


Measured memory_bytes: 209480
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var AB = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var A = AB[0];
            var B = AB[1];
            var S = Console.ReadLine();
            var answer = true;
            for (var i = 0; i < S.Length; i++)
            {
                if (i == A)
                {
                    if (S[i] != '-') answer = false;
                }
                else
                {
                    if (S[i] == '-') answer = false;
                }
            }
            Console.WriteLine(answer ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28252
//12-2 ????????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    int siai = N*(N-1)/2;
    int point[101] = {};
    for(int i=0; i<siai; i++){
        int A,B,C,D;
        cin >> A >> B >> C >> D;
        if(C==D){
            point[A] += 1;
            point[B] += 1;
        }
        else if(C>D){
            point[A] += 3;
        }
        else if(C<D){
            point[B] += 3;
        }
    }
    int rank[101] = {};
    int team = 1;
    for(int i=N*3; i>=0; i--){
        int now_team = 0;
        for(int l=1; l<N+1; l++){
            if(point[l] == i){
                rank[l-1] = team;
                now_team++;
            }
        }
        team += now_team;
    }
    for(int i=0; i<N; i++){
        cout << rank[i] << endl;
    }

    return 0;
}


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

string next(string s) {
	ll n = s.size();
	if (n == 1) {
		if (s == "9")s = "10";
		else ++s[0];
		return s;
	}
	if (abs(s[n - 1] + 1 - s[n - 2]) <= 1 && s[n - 1] != '9') {
		++s[n - 1];
		return s;
	}
	if (n == 2) {
		if (s.front() != '9') {
			s[0] = s[0] + 1;
			s[1] = max(s[0] - 1, (int)'0');
			return s;
		}
	}
	for (ll i = n - 2; i > 0; --i) {
		if (abs(s[i] - s[i - 1] + 1) <= 1 && s[i] != '9') {
			++s[i];
			for (ll j = i + 1; j < n; ++j) {
				s[j] = max((int)'0', s[j - 1] - 1);
			}
			return s;
		}
	}
	string ret;
	if (s.front() == '9') {
		ret.resize(n + 1, '0');
		ret[0] = '1';
		return ret;
	}
	else {
		ret.resize(n);
		ret[0] = s[0] + 1;
		for (ll i = 1; i < n; ++i) {
			ret[i] = max((int)'0', ret[i - 1] - 1);
		}
		return ret;
	}
}

int main() {
	ll k;
	cin >> k;
	string s = "0";
	for (ll i = 0; i < k; ++i) {
		s = next(s);
		//cerr << s << endl;
	}
	cout << s << endl;
}

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

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

  int a[101][101];
  int b[101];

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

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

  int sum[101];
  for(int i=0;i<n;i++){
    sum[i] = 0;
    for(int j=0;j<m;j++){
      sum[i] += a[i][j] * b[j];
    }
  }

  for(int i=0;i<n;i++){
    cout << sum[i] << endl;
  }

  return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    int stagelen[] = {5, 7, 5, 7, 7};

    while (true) {
        int n; cin >> n;
        if (!n) break;
        vector<string> v(n);
        rep(i, 0, n) cin >> v[i];
        rep(i, 0, n) {
            int stage = 0, len = 0;
            rep(j, i, n) {
                len += v[j].length();
                if (len > stagelen[stage]) goto badloop;
                if (len == stagelen[stage]) ++stage, len = 0;
                if (stage == 5) break;
            }
            if (stage == 5) {
                cout << i + 1 << endl;
                goto nextloop;
            }
            badloop: void(0);
        }
        nextloop: void(0);
    }
}


Measured memory_bytes: 3260
#!/usr/bin/env python3

from math import log2

def func(n):
    # (2x) ^ (2x+1) = 1 の性質を利用
    # n = 2mのとき
    # 0^1^...^2m = (0^1) ^ (2^3) ^ ... ^ (2m-2- ^ 2m-1) ^ 2m
    # = 1^...^1 ^ 2m (1はm個)

    # n = 2m+1 のとき
    # 0^1^...^2m+1 = (0^1)^...(2m ^ 2m+1)
    # = 1^...^1 (1は m+1個)

    if n % 2 == 0:
        m = n // 2
        if m % 2 == 0:
            return n
        else:
            return n ^ 1
    else:
        m = (n-1) // 2
        return 0 if m % 2 == 1 else 1

def main():
    a, b = list(map(int, input().split()))

    #f(a, b) = f(0, a-1) ^ f(0, b)
    # f(0, n)をfunc(n)とする
    print(func(b) ^ func(a-1))

if __name__ == '__main__':
    main()


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

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

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

	sw = bubbleSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i != 0)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}

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

using namespace std;

int main()
{
    int n, m, l;
    cin >> n >> m >> l;

    vector<vector<long>> A(n, vector<long>(m, 0));
    vector<vector<long>> B(m, vector<long>(l, 0));
    vector<vector<long>> C(n, vector<long>(l, 0));

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

    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> B.at(i).at(j);
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++){
                C.at(i).at(j) += A.at(i).at(k) * B.at(k).at(j);
            }
        }
    }

    for(int i = 0; i < n; i++){
        string sep = "";
        for(int j = 0; j < l; j++){
            cout << sep << C.at(i).at(j);
            sep = " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3272
local mod = 1000000007
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y) return (x * y) % mod end
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
table.sort(t)
local mul = {1}
for i = 2, n + 1 do
  mul[i] = bmul(mul[i - 1], 2)
end
local ret = 0
local csum = 0
for i = 1, n do
  local c = t[i]
  ret = badd(ret, bmul(c, mul[n]))
  if 1 < i then
    ret = badd(ret, bmul(csum, mul[n - 1]))
  end
  csum = badd(csum, c)
end
ret = bmul(ret, mul[n + 1])
print(ret)


Measured memory_bytes: 8568
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    int r;
    cin >> r;
    cout << 2 * M_PI * r;
    
    return 0;
}


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

int main() {
  int s;
  cin >> s;
  if (100 <= s && s < 1300) {
    if (1 <= (s%100) && (s%100) < 13)
      cout << "AMBIGUOUS";
    else
      cout << "MMYY";
  }
  else {
    if (1 <= (s%100) && (s%100) < 13)
      cout << "YYMM";
    else
      cout << "NA";
  }
}

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

int main() {
  long long n,ans=0;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    long long l;
    cin>>l;
    a[i]=l;
  }
  sort(a,a+n);
    for(int i=0;i<n/2;i++){
      ans-=2*a[i];
    }
    for(int i=(n+1)/2;i<n;i++){
      ans+=2*a[i];
    }
  if(n%2==0){
    ans=ans+a[n/2-1]-a[n/2];
  }
  else{
   ans=ans-min(a[n/2]-a[n/2-1],a[n/2+1]-a[n/2]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	if (N == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}
	
	int flag = (A[1] == A[2])? 0: (A[1] < A[2])? 1: -1, count = 1;
	for (i = 2; i < N; i++) {
		if (flag == 0 && A[i+1] != A[i]) flag = (A[i] < A[i+1])? 1: -1;
		else if ((A[i+1] - A[i]) * flag < 0) {
			flag = 0;
			count++;
		}
	}
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 512
// 1 << i と pow(2,i) がi>32のときに死んだ

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include<bits/stdc++.h>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int a[200000];
int keta[80];
int keta2[80];
int l;
int b2[200000];
// Number of bits to
// represent int

int mypow(int _x, int _n){
	int ret = 1;
	while(0 < _n){
		if((_n % 2) == 0){
			_x *= _x;
			_n >>= 1;
		}
		else{
			ret *= _x;
			--_n;
		}
	}
	return ret;
}

// Function to return
// maximum XOR subset
// in set[]
int maxSubarrayXOR(int set[], int n,int l2){
  int index = 0;
  for (int i = l2-1; i >= 0; i--){
    int maxInd = index;
    int maxEle =  -10;
    for (int j = index; j < n; j++) {
      if ( (set[j] & (mypow(2,i))) != 0 && set[j] > maxEle ){
        maxEle = set[j], maxInd = j;
        //cout << (set[j] & (mypow(2,i))) << endl;
      }
    }

    if (maxEle ==  -10) continue;

    swap(set[index], set[maxInd]);

    maxInd = index;

    for (int j=0; j<n; j++){

      if (j != maxInd &&(set[j] & (mypow(2,i))) != 0){
        set[j] = set[j] ^ set[maxInd];
      }
    }
    index++;
  }

  int res = 0;
  for (int i = 0; i < n; i++) res ^= set[i];
  return res;
}




signed main(){
  int n;

  int su = 0;
  int ma = -INF;
  cin >> n;
  REP(i,n){
    cin >> a[i];
    su ^= a[i];
    ma = max(ma,a[i]);
  }
  int l = 0;
  while(ma>0){
    l++;
    ma/=2;
  }
  REP(i,n){
    int no = a[i];
    int kai2 = 0;
    while(no>0){
      keta[kai2] += no%2;
      no/=2;
      kai2 ++;
    }
  }
  int su2 = su;
  int kai3 = 0;
  while(su2>0){
    keta2[kai3] += su2%2;
    su2/=2;
    kai3 ++;
  }
  int ans = su;

  REP(i,n){
    int no3 = a[i];
    int kai4 = 0;
    int ketaa = 0;
    while(no3>0){
      //if(i==0) dump(no3%2);
      if(keta2[kai4]==0){
        int kee = no3%2;
        ketaa += kee*mypow(2,kai4);
        if(i==0){
          //dump(ketaa);
          //dump(kee*mypow(2,kai4));
        }
      }
      no3/=2;
      kai4 ++;
    }
    b2[i] = ketaa;
  }
  //cout << "su=" << bitset<65>(su) << endl;
  REP(i,n){
    //cout << "ai="<<bitset<65>(a[i]) << endl;
    //cout << "bi="<<bitset<64>(b2[i]) << endl;
  }
  //dump(ans);
  ans += 2* maxSubarrayXOR(b2,n,64);
  //dump(l);
  //cout << "   "<<bitset<65>(2012721721873704572-ans) << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.List

main :: IO ()
main = do
  _ <- getLine
  s <- getLine
  putStrLn $ show $ (foldl1' (\x y -> (mod0 $ x*y)) $ map (mod0.(+1).length) $ group $ sort s)-1

mod0 :: Int -> Int
mod0 n = if n < 1000000007 then n else mod n 1000000007


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


int main()
{
	const int INF=1e8;
	int H,N;
	cin>>H>>N;
	int max_size=H+1e4+1;
	vector<int> dp(max_size,INF);
	dp[0]=0;
	rep(i,N)
	{
		int a,b;
		cin>>a>>b;
		rep(k,max_size-a)
		{
			dp[k+a]=min(dp[k+a],dp[k]+b);
		}
	}
	int ans=INF;
	Rep(i,H,max_size)
	{
		ans=min(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define debug(...) { printf("#  "); printf(__VA_ARGS__); puts(""); }
#define fi first
#define se second
#define endl "\n" 
using ll = long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
using VI = vector <int>;
using VL = vector <ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; while (x >= mod) x -= mod; while (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }
template <class T> inline void out(T s) { cout << s << "\n"; }
template <class T> inline void out(vector <T> &vec) { for (auto &it : vec) cout << it << " "; cout << endl; } 
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
constexpr int N = 1e5 + 10;
constexpr int INF = 0x3f3f3f3f;
int n, m, f[1 << 12]; 
void run() {
	memset(f, 0x3f, sizeof f);
	f[0] = 0;
	for (int i = 1; i <= m; ++i) {
		int a, b; cin >> a >> b;
		int mask = 0;
		for (int j = 1, x; j <= b; ++j) {
			cin >> x;
			mask |= (1 << (x - 1));
		}
		for (int j = (1 << n) - 1; j >= 0; --j) 
			f[j | mask] = min(f[j | mask], f[j] + a);
	}
	cout << (f[(1 << n) - 1] == INF ? -1 : f[(1 << n) - 1]) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n >> m) run();
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int main() {
    bool flag=false;
    int a, b;
    while (scanf("%d%d",&a,&b)) {
        if (!a&&!b) break;
        if (flag) puts("");
        flag=true;
        vector<int> leap;
        for (int i=a; i<=b; i++) {
            if (i%4==0&&(i%100!=0||i%400==0)) {
                leap.push_back(i);
            }
        }
        if (leap.size()==0) puts("NA");
        else {
            for (int i=0; i<leap.size(); i++) printf("%d\n",leap[i]);
        }
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <cstring>

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+150, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll h[N], dp[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, K; cin >> n >> K;
    memset(dp, inf, sizeof(dp));
    rep (i, 0, n) cin >> h[i];

    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int k = 1; k <= K; ++k)
            dp[i+k] = min(dp[i+k], dp[i] + abs(h[i+k]-h[i]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> n >> m;
	vi a(m); veccin(a);
	
    cout << ((k = n - ACCM(a)) < 0 ? -1 : k) << endl;
}


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

typedef long long ll;

static const int MAX = 1e6;
static const int NIL = -1;
static const ll INF = 1<<21;
static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    string S;
    cin >> S;

    for(int i=0;i<S.size();i++) {
        cout << 'x';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		string tmp;
		bool f=false;
		for(int i=0;i<s.size();++i){
			if(s[i]==','||s[i]=='.'||s[i]==' '){
				if(3<=tmp.size()&&tmp.size()<=6){
				cout<<((f)?" ":"")<<tmp;
				f=true;
				}
				tmp="";
			}else tmp+=s[i];
			if(i==s.size()-1&&3<=tmp.size()&&tmp.size()<=6)cout<<((f)?" ":"")<<tmp;
			if(i==s.size()-1)cout<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 0
var a,b,c:longint;
i,j,k:longint;
p:array[1..10000] of longint;
begin
readln(k);
for i:=1 to k do read(p[i]);
for i:=1 to k-1 do
 for j:=i+1 to k do 
 if p[i]<p[j] then begin c:=p[i]; p[i]:=p[j]; p[j]:=c; end;
 c:=0;
 for i:=1 to k do
   begin 
   if i mod 2=1 then c:=c+p[i] else b:=b+p[i]; end;
   writeln(c-b);
   end.

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

bool can(ll end, ll start, ll K) {
  if (abs(end - start) > K) return false;
  if ((abs(end - start) & 1) != (K & 1)) return false;
  return true;
}

int main2() {
  ll X = nextLong();
  ll K = nextLong();
  ll D = nextLong();

  ll x = X / D;
  ll r = X % D;

  ll ans = 1LL << 61;

  for (ll t : vector<ll>({-2, -1, 0, 1, 2, x-K, x+K})) {
    if (can(t, x, K)) {
      chmin(ans, abs(t*D + r));
    }
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

#define ll long long int
#define ld long double

void solve() {
	int n, k, price = 0;
	cin >> n >> k;
	int p[n];
	for (int i = 0; i < n; ++i) 
		cin >> p[i];
	sort(p, p + n);
	for (int i = 0; i < k; ++i) 
		price += p[i];
	cout << price << endl;
}

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

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

int main(){
    int n;
    cin >> n;
    
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    ll maxv = -1000001;
    ll minv = 1000001;
    ll sum = 0;
    rep(i,n){
        maxv = max(maxv,a[i]);
        minv = min(minv,a[i]);
        sum += a[i];
    }
    cout << minv << " " << maxv << " " << sum << endl;
}




Measured memory_bytes: 3172
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}
double calc(double R1, double R2) {
    double A = R1 + R2;
    double B = abs(R1 - R2);
    return sqrt(A * A - B * B);
}
int main(){
    iostream_init();
    int n;
    cin >> n;
    vector<double> r(n);
    REP(i, n) cin >> r[i];
    vector<double> d(n);
    REP(i, n) {
        d[i] = r[i];
        for(int j = 0; j < i; j++) {
            d[i] = max(d[i], d[j] + calc(r[i], r[j]));
        }
    }
    double ans = 0;
    REP(i, n) ans = max(ans, d[i] + r[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3312
#[test]
fn test_solve() {
    assert_eq!(solve("5 7 5\n"), "Yes\n");
    assert_eq!(solve("4 4 4\n"), "No\n");
    assert_eq!(solve("4 9 6\n"), "No\n");
    assert_eq!(solve("3 3 4\n"), "Yes\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: usize = sc.read();
    let b: usize = sc.read();
    let c: usize = sc.read();

    if a == b && b != c || b == c && a != b || a == c && a != b {
        format!("Yes\n")
    } else {
        format!("No\n")
    }
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.get().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
string a;
int n, v[130];
int main() {
    int i, j;
    cin>>a;
    n = a.size();
    for(i=0; a[i]; i++) v[a[i]] = 1;
    for(i='a'; i<='z'; i++) if(!v[i]) a += i;
    if(n<26) cout<<a.substr(0,n+1) << '\n';
    else {
    next_permutation(a.begin(), a.end()+1);
    if(!a[0]) cout<<-1;
    else for(i=0; a[i]; i++) cout<<a[i];
    cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(std::string S)
{
    ll n = S.size() + 1;
    vector<ll> ans(n, 0);
    for (ll i = 0; i < n; i++)
    {
        if (S[i] == '<')
        {
            ans[i + 1] = ans[i] + 1;
        }
    }

    for (ll i = n - 2; i >= 0; i--)
    {
        if (S[i] == '>')
        {
            ans[i] = max(ans[i], ans[i + 1] + 1);
        }
    }
    ll anscnt=0;

    for (ll i = 0; i < n; i++)
    {
        anscnt+= ans[i];
    }
    cout << anscnt << endl;
    
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9

ll C[51][51];

void comb_table(int N){
    for(int i=0;i<=N;i++){
        for(int j=0;j<=i;j++){
            if(j==0 || i==1){
                C[i][j]=1LL;
            }
            else{
                C[i][j]=C[i-1][j-1]+C[i-1][j];
            }
        }
    }
}


int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    const int NMAX=50;
    ll v[NMAX];

    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    
    comb_table(N);
    sort(v,v+N);
    reverse(v,v+N);
    
    double max_average=0.0;
    for(int i=0;i<A;i++) max_average+=v[i];
    max_average/=A;
    
    int a_th_val_num=0,a_th_val_pos=0;
    for(int i=0;i<N;i++){
        if(v[i]==v[A-1]){
            a_th_val_num++;
            if(i<A){
                a_th_val_pos++;
            }
        }
    }
    
    ll cnt=0LL;
    if(a_th_val_pos==A){
        for(a_th_val_pos=A;a_th_val_pos<=B;a_th_val_pos++){
            cnt+=C[a_th_val_num][a_th_val_pos];
        }
    }
    else{
        cnt+=C[a_th_val_num][a_th_val_pos];
    }
    
    cout.precision(20);
    cout<<fixed<<max_average<<endl;
    cout<<cnt<<endl;
}

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

int main() {
  int N, X, a;
  cin >> N >> X;
  vector<int> v(N+1);
  cin >> v.at(0); 
  if (N == 1) {
  cout  << abs(v.at(0) - X);
  }else{
    a = abs(X - v.at(0));
    for (int i= 1; i < N; i++) {
      cin >> v.at(i);
      a=__gcd(a,abs(X-v.at(i)));
    } 
      cout << a;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int a, b;
    cin >> a >> b;
    int ans = 0, cnt = 1;
    while (cnt < b) {
        ans++;
        cnt += a - 1;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;
 
using namespace std;
 
/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
 
int h, w, d;
int c[1200];
char s[1200][1200];
 
int main() {
	cin >> h >> w >> d;
	for (int i = 0; i < h + w - 1; ++i) {
		if (i >= d)
			c[i] = c[i - d] ^ 1;
		else
			c[i] = 0;
	}
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			int a = c[i + j] * 2 + c[i + (w - 1 - j)];
			if (a == 0)
				s[i][j] = 'G';
			else if (a == 1)
				s[i][j] = 'R';
			else if (a == 2)
				s[i][j] = 'B';
			else
				s[i][j] = 'Y';
		}
	for (int i = 0; i < h; ++i) {
		printf("%s\n", s[i]);
	}
	return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> v(N);
  rep(i, 0, N) { cin >> v[i]; }
  map<int, int> mp1, mp2;
  rep(i, 0, N) {
    if (i & 1) {
      mp1[v[i]]++;
    } else {
      mp2[v[i]]++;
    }
  }
  vector<pii> v1, v2;
  v1.eb(0,INF);
  v2.eb(0,INF);

  for (auto p : mp1) {
    v1.eb(p.se, p.fi);
  }
  for (auto p : mp2) {
    v2.eb(p.se, p.fi);
  }
  sort(all(v1));
  sort(all(v2));
  reverse(all(v1));
  reverse(all(v2));

  dump(v1,v2);
  int ans(INF);
  rep(i,0,2)rep(j,0,2){
    if(v1[i].se==v2[j].se)continue;

    int a=N/2 - v1[i].fi;
    int b=N/2 - v2[j].fi;
    chmin(ans,a+b);
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 6524
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

string fix(int n, int l) {
    string ret = to_string(n);
    rep(i,ret.length(),l) {
        ret = '0' + ret;
    }
    return ret;
}

signed main() {
    int n, l;
    while(cin >> n >> l, n || l) {
        vector<int> v; v.pb(n);
        while(1) {
            string s = fix(n, l);
            int a[7];
            rep(i,0,s.length()) a[i] = s[i] - '0';
            sort(a, a+s.length());
            int ma = 0, mi = 0;
            int d = 1;
            rep(i,0,s.length()) {
                ma += a[i] * d;
                mi += a[s.length() - i - 1] * d;
                d *= 10;
            }
            // printf("ma: %lld, mi: %lld\n", ma, mi);

            bool ok = false;
            rep(i,0,v.size()) {
                if(v[i] == ma - mi) {
                    printf("%lld %lld %lld\n", i, ma-mi, v.size()-i);
                    ok = true;
                    break;
                }
            }
            if(ok) break;
            v.pb(ma - mi);
            n = ma - mi;
        }
    }
    return 0;
}

Measured memory_bytes: 3300
import array


class Stack:
    def __init__(self):
        self.size = 0
        self.list = list()

    def push(self, el):
        self.size += 1
        self.list.append(el)

    def pop(self):
        self.size -= 1
        return self.list.pop()

    def top(self):
        return self.list[-1]

    def is_empty(self):
        return self.size == 0

    def __str__(self):
        return(self.list.__str__())


def cstep(ar):
    if len(ar)  == 1:
        return 0
    s = Stack()
    d = array.array('i', [0]*len(ar))
    maxima = ar[0]
    for index in range(1, len(ar)):
        el = ar[index]
        if maxima < el:
            maxima = el
        d[index] = maxima - el
    return sum(d)

def main():
    n = int(input())
    ar = list(map(int, input().strip().split()))
    print(cstep(ar))


main()

Measured memory_bytes: 33208
#include <bits/stdc++.h>
using namespace std;
main(){
  map<char,string> m;
string a,b,c;cin>>a>>b>>c;
m['a']=a;
m['b']=b;
m['c']=c;
char t='a';
while(1){
  if(m[t].size()==0){cout<<(char)('A'+t-'a');return 0;}
char tm=m[t][0];
m[t]=m[t].substr(1,m[t].size()-1);
t=tm;}}


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

typedef long long ll;
typedef vector<int> poly;
const int maxn = 8005, maxm = 205, mod = 998244353;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int fpow(int x, int k)
{
	int res = 1;
	while (k) {
		if (k & 1) res = (ll)res * x % mod;
		k >>= 1; x = (ll)x * x % mod;
	}
	return res;
}

inline int add(int x, int y) {return x + y < mod ? x + y : x + y - mod;}
inline int sub(int x, int y) {return x < y ? x - y + mod : x - y;}

int n, m, fac[maxn], ifac[maxn];
int N, L, R[maxn << 2], w[maxn << 2];
int f[maxm][maxn];

void init(int n)
{
	for (N = 1, L = -1; N < n; N <<= 1) ++L;
	for (int i = 0; i < N; ++i) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L);
	w[N >> 1] = 1;
	int wn = fpow(3, (mod - 1) / N);
	for (int i = (N >> 1) + 1; i < N; ++i) w[i] = (ll)w[i - 1] * wn % mod;
	for (int i = (N >> 1) - 1; ~i; --i) w[i] = w[i << 1];
}


void dft(poly &a)
{
	a.resize(N);
	for (int i = 0; i < N; ++i) if (i < R[i]) swap(a[i], a[R[i]]);
	for (int d = 1; d < N; d <<= 1)
		for (int i = 0; i < N; i += d << 1)
			for (int j = 0; j < d; ++j) {
				int t = (ll)w[d + j] * a[i + d + j] % mod;
				a[i + d + j] = sub(a[i + j], t);
				a[i + j] = add(a[i + j], t);
			}
}

void idft(poly &a)
{
	dft(a);
	reverse(a.begin() + 1, a.end());
	for (int i = 0, inv = fpow(N, mod - 2); i < N; ++i) a[i] = (ll)a[i] * inv % mod;
}

poly operator * (poly a, poly b)
{
	int m = a.size(), n = b.size();
	if (0 && (m < 50 || n < 50)) {
		poly c(m + n - 1);
		for (int i = 0; i < m; ++i)
			for (int j = 0; j < n; ++j)
				c[i + j] = (c[i + j] + (ll)a[i] * b[j]) % mod;
		return c;
	}
	init(m + n - 1);
	dft(a); dft(b);
	for (int i = 0; i < N; ++i) a[i] = (ll)a[i] * b[i] % mod;
	idft(a); a.resize(m + n - 1);
	return a;
}

inline int C(int m, int n)
{
	return (ll)fac[m] * ifac[n] % mod * ifac[m - n] % mod;
}

int main()
{
	n = gi(); m = gi();
	fac[0] = 1;
	for (int i = 1; i <= n + 3; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	ifac[n + 3] = fpow(fac[n + 3], mod - 2);
	for (int i = n + 2; ~i; --i) ifac[i] = (ll)ifac[i + 1] * (i + 1) % mod;
	
	f[0][0] = 1;

	for (int j = 1; j <= m; ++j) {
		for (int i = 0; i <= n; ++i)
			f[j][i] = (1 + i + (ll)i * (i - 1) / 2 % mod) * f[j - 1][i] % mod;
		poly a(n + 3), b(n + 3);
		for (int i = 0; i <= n; ++i) a[i] = (ll)f[j - 1][i] * ifac[i] % mod;
		for (int i = 1; i <= n; ++i) b[i] = ifac[i + 2];
		a = a * b;
		for (int i = 1; i <= n; ++i) f[j][i] = (f[j][i] + (ll)a[i] * fac[i + 2]) % mod;
	}

	int ans = 0;
	for (int i = 0; i <= n; ++i) ans = (ans + (ll)f[m][i] * C(n, i)) % mod;
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 6960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        final long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Integer[] p = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
        Arrays.sort(p, new Comparator<Integer>() {
            @Override
            public int compare(Integer x, Integer y) {
                if (a[x] != a[y]) {
                    return -Long.compare(a[x], a[y]);
                } else {
                    return Integer.compare(x, y);
                }
            }
        });
        long[] res = new long[n];
        int c = p[0];
        long s = a[p[0]];
        for (int i = 1; i < n; i++) {
            if (p[i] < c) {
                res[c] = s - i * a[p[i]];
                s = (i + 1) * a[p[i]];
                c = p[i];
            } else {
                s += a[p[i]];
            }
        }
        res[c] = s;
        for (int i = 0; i < n; i++) {
            out.println(res[i]);
        }

    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


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

string S;

int main() {
    cin >> S;
    int k = S.length();

    int win = 0;
    for (int i = 0; i < k; i++) {
        if (S[i] == 'o') win++;
    }

    if (15 - k + win >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		if(S.equals("SUN")) {
			System.out.println(7);
		}else if(S.equals("MON")) {
			System.out.println(6);
		}else if(S.equals("TUE")) {
			System.out.println(5);
		}else if(S.equals("WED")) {
			System.out.println(4);
		}else if(S.equals("THU")) {
			System.out.println(3);
		}else if(S.equals("FRI")) {
			System.out.println(2);
		}else if(S.equals("SAT")) {
			System.out.println(1);
		}

	}

}

Measured memory_bytes: 22100
class UF():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

n,m,k=map(int,input().split())
uf=UF(n)
F=[[]for _ in range(n)]
P=[0]*n
B=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
    F[a-1].append(b-1)
    F[b-1].append(a-1)
for i in range(k):
    c,d=map(int,input().split())
    if uf.same(c-1,d-1):
        B[c-1]-=1
        B[d-1]-=1
for i in range(n):
    P[i]=uf.size(i)-1+B[i]-len(F[i])
print(*P)
        


Measured memory_bytes: 112288