akhauriyash/Code-Regression huggingface dataset:
name = ['A', 'B', 'C', 'D', 'E']
shop = []

while True:
    a,b = map(int, input().split())
    if a == 0 and b == 0:
        break
    shop.append(a+b)
    if len(shop) == 5:
        m = max(shop)
        print(name[shop.index(m)], m)
        shop = []  
    


Measured memory_bytes: 5604
/// @author MUSTAFA MOGHAZY
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a [32+4];
int main()
{
 string s; cin>>s;
 for(int i=0; i<s.size(); ++i){
    ++a[ s[i] - 96];
 }
 for(int i=1; i<=32; ++i){
    if(a[i]%2==1){
        cout<<"No\n";
        return 0;
    }
 }
 cout<<"Yes\n";
}


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

int main(){
  int N;cin>>N;
  int S=0;
  int n=N;
  const int X=10;
  while(n>0){
    S+=n%X;
    n/=X;
  }
  cout<<(N%S==0?"Yes":"No")<<endl;
}
    

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll dp[105][100050];

int main () {
  int N, W;
  cin >> N >> W;
  vi w(N), v(N);
  rep(i,N) cin >> w[i] >> v[i];

  rep(i,N) {
    rep(j,W+1) {
      chmax(dp[i+1][j], dp[i][j]);
      if (j+w[i] > W) continue;
      chmax(dp[i+1][j+w[i]], dp[i][j]+v[i]);
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}

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

int main(void) {
	int n;
	long long int p = 1;
	const int mod = 1000000007;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		p *= i;
		while (p > mod) {
			p %= mod;
		}
	}
	cout << p << endl;
	return 0;
}

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

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

using namespace std;
const ll inf = 1LL << 60;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    vector<vector<ll>> c(M);
    Rep (i, M) {
        cin >> a[i] >> b[i];
        Rep (j, b[i]) {
            ll ce;
            cin >> ce;
            ce--;
            c[i].push_back(ce);
        }
    }

    vector<vector<pair<ll, ll>>> graph(1<<N, vector<pair<ll, ll>>());
    Rep (i, 1<<N) {
        Rep (j, M) {
            ll to = i;
            Rep (k, b[j]) {
                to |= (1ll << c[j][k]);
            }
            graph[i].push_back(make_pair(to, a[j]));
        }
    }

    priority_queue<pair<ll, ll>> que;
    vector<ll> dist(1<<N, inf);
    dist[0] = 0;
    que.push(make_pair(0, 0));

    while (que.size()) {
        auto p = que.top(); que.pop();
        ll v = p.second;
        if (dist[v] < -p.first) continue;
        for (auto e : graph[v]) {
            if (dist[e.first] > dist[v] + e.second) {
                dist[e.first] = dist[v] + e.second;
                que.push(make_pair(-dist[e.first], e.first));
            }
        }
    }

    if (dist[(1ll<<N)-1] == inf) cout << -1 << endl;
    else cout << dist[(1ll<<N)-1] << endl;
}

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

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

    ll ans = 0;
    for (int i = 1; i <= N; i++){
        ll k = N / i;
        ans += i * k * (1 + k) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define INF 0x3f3f3f3f
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
using namespace std;


int main()
{
  fast
  ll n;
  cin >> n;
  ll w;
  cin >> w;
  ll arr[n+1];
  ll value[n+1];
  fr(i,0,n)cin>>arr[i+1],cin>>value[i+1];
  ll dp[w+1][n+1];
  fr(i,0,w+1)
  {
      fr(j,0,n+1)
      {
          if(i==0||j==0)
          {
              dp[i][j]=0;
          }
          else 
          {
              if(i>=arr[j])
              {
                  dp[i][j]=max(dp[i-arr[j]][j-1]+value[j],dp[i][j-1]);
              }   
              else
              {
                  dp[i][j]=dp[i][j-1];
              }
          }
      }
  }
  cout << dp[w][n];

  return 0;
}


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

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) { data.assign(sz, -1); }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) { return (-data[find(k)]); }
};

int N, M;
bool solve(UnionFind uf) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (uf.find(i) != uf.find(j)) return true;
        }
    }
    return false;
}

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

    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    int ans = 0;
    for (int i = 0; i < M; i++) {
        UnionFind uf(N);
        for (int j = 0; j < M; j++) {
            if (i == j) continue;
            uf.unite(a[j], b[j]);
        }
        if (solve(uf)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    vector<char> arares;
    cin >> N;
    range(i, 0, N) {
        char tmp;
        cin >> tmp;
        arares.emplace_back(tmp);
    }
    unordered_set<char> distinct_arares;
    for (const char arare : arares) {
        distinct_arares.emplace(arare);
    }
    // cout << arares << "\n";
    // cout << distinct_arares << "\n";
    cout << (distinct_arares.size() == 3 ? "Three" : "Four") << "\n";
}

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

int main() {
    long long int n, m, ans = 1;
    cin >> n >> m;
    for(long long int i = 1; i*i <= m; ++i) {
        if(m%i == 0) {
            if(i <= m/n) ans = max(ans, i);
            if(m/i <= m/n) ans = max(ans, m/i);
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
package main
 
import (
    b "bufio"
    f "fmt"
    o "os"
    // s "strconv"
)

var sc = b.NewScanner(o.Stdin)
type Cards [52]int

func FindMissingCards(n int) [52]int {
	var cards Cards
		for i := 0; i < len(cards); i++{
			cards[i] = i + 1
		}


	var st string
	var nm int

		for i := 0; i < n; i++ {
			f.Scan(&st)
			f.Scan(&nm)
			cdid := ( 13 * stTOnum(st) + nm ) - 1
			cards[cdid] = 0
		}

	return cards
}

func stTOnum(st string) int {
	var stid int

	switch st {
	case "S": stid = 0
	case "H": stid = 1
	case "C": stid = 2
	case "D": stid = 3
	default : stid = 0
	}

	return stid
}

func main(){
	suits := []string{"S", "H", "C", "D"}
	var n int
	f.Scan(&n)
	cds := FindMissingCards(n)

		for i := 0; i < 13 * 4; i++ {
			if cds[i] != 0 {
				f.Println(suits[i / 13], i % 13 + 1)
			}
		}

}


Measured memory_bytes: 1148
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


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

	int x = max(a, c);
	int y = min(b, d);

	if (y - x <= 0) {
		cout << 0 << rt;
	}
	else {
		cout << y - x << rt;
	}

	please AC;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include "math.h"
#include "stdio.h"

using namespace std;

int main(){
    int n;
    double x[100],y[100];
    double man = 0,euclid = 0,p3 = 0,chbi = 0;
    cin >> n;
    
    for(int i = 0;i < 2;++i){
        for(int j = 0;j < n;++j){
            if(i == 0){
                cin >> x[j];
            }
            else{
                cin >> y[j];
            }
        }
    }
    
    for(int i = 0;i < n;++i){
        man += fabs(x[i] - y[i]);
        euclid += pow(fabs(x[i] - y[i]),2);
        p3 += pow(fabs(x[i] - y[i]),3);
        chbi = max(fabs(x[i] - y[i]),chbi);
    }
    euclid = sqrt(euclid);
    p3 = pow(p3,1.0 / 3.0);
    
    printf("%.8lf\n%.8lf\n%.8lf\n%.8lf\n",man,euclid,p3,chbi);
}


Measured memory_bytes: 3408
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  ll N, A, B;
  cin >> N >> A >> B;
  ll pre;
  cin >> pre;

  ll ans = 0;

  REP(i, N - 1) {
    ll X;
    cin >> X;
    if ((X - pre) * A < B) {
      ans += (X - pre) * A;
    } else {
      ans += B;
    }

    pre = X;
  }

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

Measured memory_bytes: 256
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

void solve(int w1,int w2, int s1, int s2, int solute, int volume){
	int WS = w1*100, S = 0;
	int wend = volume/100;
	double maxper = 0.0;
	rp(iw, 1, wend+1) rp(jw, 0, wend+1){
		int w = w1*iw + w2*jw;
		if(w > wend) break;
		int send = volume - w*100;
		irp(is, send, -1) irp(js, send, -1){
			int s = s1*is + s2*js;
			if(s > send || s > solute*w) continue;
			int ws = w * 100 + s;
			if(ws > volume) continue;
			double per = 100.0*s/ws;
			if(maxper >= per) break;
			maxper = per;
			WS = ws;
			S = s;
			break;
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& e : a) {
    cin >> e;
  }
  sort(a.rbegin(), a.rend());
  int ascore = 0, bscore = 0;
  for (int i = 0; i < n; ++i) {
    if (i%2) {
      bscore += a[i];
    } else {
      ascore += a[i];
    }
  }
  cout << ascore - bscore << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int w = input.nextInt();
		int h = input.nextInt();
		while(w != 0 && h != 0){
		    for(int i = 0; i < w; i ++){
		        for(int j = 0; j < h; j ++)
		            System.out.print("#");
		        System.out.println();
		    }
		    System.out.println();
		    w = input.nextInt();
		    h = input.nextInt();
		}
	}
}


Measured memory_bytes: 37400
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; }

template<class T>
bool chmin(T &a, const T &b) { if (a > b) { a = b; return a; } return a; }

const int MOD = 1000000007;
int main() {
    ll n; cin >> n;
    vector<ll> a(n), s(n+1); 

    rep(i, n) {
        cin >> a[i];
        s[i+1] = s[i] + a[i];
    }

    ll ans = 0;
    rep(i, n) {
        ll sum = (s[n] - s[i+1])%MOD;
        ans += a[i] * sum;
        ans = ans % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6368
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int PN = 12;
const int KM = 1 << (PN - 1);
ll dat[1 << PN];

ll check(int L, int R, int A, int l, int r) {
	if (dat[A] == 1ll << 60) return 1ll << 60;
	if (L <= l && r <= R) return dat[A];
	if (r <= L || R <= l) return 1ll << 60;
	return min(check(L, R, A * 2, l, (l + r) >> 1), check(L, R, A * 2 + 1, (l + r) >> 1, r));
}

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

	fread_unlocked(cn, 1, cm, stdin);
	int N = getint(), K = getint(), Q = getint();
	ll A[2002];
	int LR[2002] = {};
	rep1(i, N) {
		A[i] = ((ll)getint() << 11) + i;
		dat[KM + i] = A[i];
	}
	for (int i = KM - 1; i > 0; i--) {
		dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
	}

	priority_queue<int> q;
	int kotae = 1e9;
	int saishou = 2e9;
	sort(A + 1, A + N + 1);
	const int m = (1 << 11) - 1;

	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 11;
		int k = A[i] & m;

		int l = !LR[k - 1] ? k : LR[k - 1];
		int r = !LR[k + 1] ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		int kosuu = min(K - 1, r - k) + min(K - 1, k - l) + 1;
		int abureta = max(0, kosuu - K + 1);

		rep(i, abureta) {
			ll tmp = min(check(l, r + 1, 2, 0, KM >> 1), check(l, r + 1, 3, KM >> 1, KM));
			q.push(tmp >> 11);
			int C = (tmp & m) + KM;
			dat[C] = 1ll << 60;
			C >>= 1;
			for (int j = KM >> 1; C != j; j >>= 1, C >>= 1) {
				dat[C] = min(dat[C * 2], dat[C * 2 ^ 1]);
			}
		}

		while (q.size() >= Q) {
			int tmp = q.top();
			chmin(saishou, tmp);
			q.pop();
		}
		chmin(kotae, saishou - a);
	}

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
#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;
string s;
void run() {
	int len = s.size();
	for (int i = 0; i < len; ++i) {
		if ((i & 1) && s[i] == 'R') return out("No");
		if ((i & 1) == 0 && s[i] == 'L') return out("No");
	}
	out("Yes");
}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> Pair;
int main()
{
    int n;
    cin>>n;
    vector<Pair> p(n);
    rep(i,n)cin>>p[i].first>>p[i].second;
    vector<int> r(n);
    rep(i,n)r[i]=i;

    double ans=0;
    int count=0;
    do 
    {
        double L=0;
        rep(i,r.size()-1)
        {
            int x=p[r[i]].first-p[r[i+1]].first;
            int y=p[r[i]].second-p[r[i+1]].second;
            L+=sqrt(pow(x,2)+pow(y,2));
        }
        count++;
        ans+=L;
    } while (next_permutation(r.begin(), r.end()));
    ans=ans/count;
    printf("%.10f",ans);

    return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  string temp;
  bool ok = false;
  for(int i = 0; i< S.size(); i++){
    temp[0] = S[S.size() - 1];
    for(int j = 1; j < S.size(); j++){
      temp[j] = S[j - 1];
    }
    for(int j = 0; j < S.size(); j++){
      S[j] = temp[j];
    }
    if(S == T){
      ok = true;
      break;
    }
  }
  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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!{
        r: i32
    }
    println!("{}", r * r);
}


Measured memory_bytes: 4352
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int n; // 200'000
    cin >> n;

    auto a = vector<large>(n);
    for (int i = 0; i < n; ++i) {
        long double d;
        cin >> d;
        a[i] = (large)round(d * 1'000'000'000);
    }
    auto two = vector<int>(n);
    auto five = vector<int>(n);
    for (int i = 0; i < n; ++i) {
        auto x = a[i];
        int cnt = 0;
        while (x % 2 == 0) {
            x /= 2;
            cnt++;
        }
        two[i] = min(18, cnt);

        cnt = 0;
        while (x % 5 == 0) {
            x /= 5;
            cnt++;
        }
        five[i] = min(18, cnt);
    }

    auto grid = array< array<int, 19>, 19 >{};
    for (int i = 0; i < n; ++i) {
        grid[two[i]][five[i]]++;
    }

    auto count = 0LL;
    for (int i = 0; i < n; ++i) {
        const auto t0 = two[i];
        const auto f0 = five[i];

        for (int t = 18 - t0; t <= 18; ++t) {
            for (int f = 18 - f0; f <= 18; ++f) {
                count += grid[t][f];
            }
        }

        if (18 - t0 <= t0 && 18 - f0 <= f0) {
            // Exclude i-th
            count--;
        }
    }

    cout << (count / 2) << endl;
    return 0;
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;
    
    VB left(n, false), right(n, false);
    
    while (m--) {
        int u, v;
        cin >> u >> v; u--; v--;
        
        if (u == 0) left[v] = true;
        if (v == n-1) right[u] = true;
    }
    
    FOR(i,0,n-1) if (left[i] && right[i]) {
        cout << "POSSIBLE";
        return 0;
    }
    
    cout << "IMPOSSIBLE";

    return 0;
}

/*************************************************************************/


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

int main() {
  int n,a,b,s,ans=0;
  cin >> n >> a >> b;
  for(int i=1 ;i<=n ;i++){
    s = 0;
    int _i = i;
    while(_i){
      s += _i%10;
      _i /= 10;
    }
    if(s>=a && s<=b){
      ans += i;
    }
  }
  cout << ans << endl;
}

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

using ll = long long;

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


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  string s; cin >> s;
  int n = s.size();

  vector<int> greater_(n + 1, 0), less_(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '<') {
      greater_[i + 1] = greater_[i] + 1;
    }
  }
  //debug(greater_);
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '>') {
      less_[i] = less_[i + 1] + 1;
    }
  }
  //debug(less_);
  vector<int64> ans(n + 1);
  for (int i = 0; i < n + 1; ++i) {
    ans[i] = static_cast<int64>(max(greater_[i], less_[i]));
  }
  //debug(ans);
  cout << accumulate(ans.begin(), ans.end(), int64()) << endl;

  return 0;
}

Measured memory_bytes: 8732
/*
ID: wangyuxi20040901
TASK:  ()
LANG: C++
DATE: 20200419 20:21:12
*///using CRLF, UTF-8

#include <cstdio>
#include <algorithm>
#include <cstring>
#define pr printf
#define F(i, j, k) for(register ll i = j, kkllkl = k; i <= kkllkl; ++i)
#define G(i, j, k) for(register ll i = j, kkllkl = k; i >= kkllkl; --i)
#define clr(a, v) memset((a), v, sizeof(a))
using namespace std;
typedef long long ll;

#define isd(x) (('0' <= (x) && (x) <= '9') || (x) == '-')
ll rd() {
    ll ans = 0, sign = 1; char c = getchar();
    while(!isd(c)) c = getchar();
    if(c == '-') sign = -1, c = getchar();
    while(isd(c)) ans = (ans << 3) + (ans << 1) + c - '0', c = getchar();
    return sign == 1 ? ans : -ans;
}

/* --------------------------CSYZ1921------------------------- */

const ll N = 10005;
ll n, m, a;

int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    n = rd(); m = rd();
    F(i, 1, m) {
        a = rd();
        n -= a;
    }
    if(n >= 0) pr("%lld\n", n);
    else pr("-1\n");
    return 0;
}
/*
*/

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

void solve(long long N)
{
    switch (to_string(N).back()) {
    case '2':
    case '4':
    case '5':
    case '7':
    case '9':
        cout << "hon\n";
        break;
    case '0':
    case '1':
    case '6':
    case '8':
        cout << "pon\n";
        break;
    case '3':
        cout << "bon\n";
        break;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3852
typedef long long ll;

typedef long double ld;

#include <bits/stdc++.h>

using namespace std;

const ll MOD = 1e9+7;

int main() {

    ll n,k;

    std::cin >> n>>k;

    vector<ll> a(n);

    ll cntz = 0;

    ll cntn = 0;

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

        std::cin >> a[i];

        if(a[i]==0)cntz++;

        if(a[i]<0)cntn++;

    }

    sort(a.begin(),a.end());

    if(k==1){

        std::cout << (a[n-1]+MOD)%MOD << std::endl;

        return 0;

    }

    // 負で終わるケースを除く

    if(a[n-1]<0){

        if(k%2==1){

            ll ans = 1;

            for (int i = 0; i < k; i++) {

                ans *= a[n-1-i]+MOD;

                ans %= MOD;

            }

            std::cout << ans << std::endl;

            return 0;

        }

    }

    if(k==n){

        ll ans =1;

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

            ans *= a[i]+MOD;

            ans %= MOD;

        }

        std::cout << ans << std::endl;

        return 0;

    }

    

    if(n-cntz<k){

        std::cout << 0 << std::endl;

        return 0;

    }

    

    if(cntz+cntn==n&&k%2==1){

        std::cout << 0 << std::endl;

        return 0;

    }

    

    ll nowk = k;

    ll cur = n-1;

    priority_queue<ll,vector<ll>,greater<ll>> pq;

    while(nowk){

        if(a[cur]>0){

            pq.push(a[cur]);

            cur--;

            nowk--;

        }else{

            break;

        }

    }

    if(nowk%2==1){

        pq.pop();

        nowk++;

    }

    // nowkは2の倍数

    ll add = 1;

    for (int i = 0; i < cntn/2; i++) {

        // 入れるしかなかったら入れる

        if(nowk>=2){

            add *= a[i*2]+MOD;

            add %= MOD;

            add *= a[i*2+1]+MOD;

            add %= MOD;

            nowk-=2;

        }else{

            // 先客がいる

            if(pq.size()>=2){

                auto n1 = pq.top();pq.pop();

                auto n2 = pq.top();pq.pop();

                if(n1*n2<(-1*a[i*2])*(-1*a[i*2+1])){

                    add *= a[i*2]+MOD;

                    add %= MOD;

                    add *= a[i*2+1]+MOD;

                    add %= MOD;

                }else{

                    pq.push(n1);

                    pq.push(n2);

                    break;

                }

            }else{

                break;

            }

        }

    }

    

    while(pq.size()){

        auto tmp = pq.top();pq.pop();

        add *= tmp+MOD;

        add %= MOD;

    }

    

    std::cout << add << std::endl;

}



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

bool flag[1000000] = {};

int main() {

  vector< long long int > sosu;

  for ( long long int i = 2; i < 1000000; i++ ) {
    if ( flag[i] == false ) {
      for ( long long int j = 1; j * i < 1000000; j++ ) {
	flag[ j * i ] = true;
	sosu.push_back( i );
      }
    }
  }

  long long int a, d, n;

  while( true ) {

    cin >> a >> d >> n;

    if ( a == 0 && d == 0 && n == 0 ) break;

    long long int cnt = 1;

    while( true ) {

      if ( binary_search( sosu.begin(), sosu.end(), a ) ) {
	if ( cnt == n ) {
	  cout << a << endl;
	  break;
	}
	cnt++;
      }
      a += d;

    }

  }

  return 0;

}

Measured memory_bytes: 35608
use proconio::{input,fastout};
use num::pow::pow;

fn main() {
    input! {
        x: i64,
    }

    for i in -130..130 {
        let target = pow(i, 5) + x;

        for j in i+1..130 {
            if target == pow(j, 5) {
                println!("{} {}", j, i);
                return;
            }
        }
    }
}


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

std::vector<std::string> caseList;
int n, m, x;

void dfs(std::string c, int dim)
{
    if(dim == n)
    {
        caseList.push_back(c);
        return;
    }
    
    dfs(c + '1', dim + 1);
    dfs(c + '0', dim + 1);
}

int c()
{
    std::cin >> n >> m >> x;
    dfs("", 0);
    
    std::vector<std::vector<int>> books;
    for(int i = 0; i < n; i++)
    {
        std::vector<int> myBook(m + 1);
        for(int k = 0; k < m + 1; k++)
        {
            std::cin >> myBook[k];
        }
        books.push_back(myBook);
    }
    
    bool isOK = false;
    long long minValue = 100000000;
    
    for(int i = 0 ; i < caseList.size(); i++)
    {
        std::string myCase = caseList[i];
        long long myCost = 0;
        std::vector<int> mySkill(m + 1, 0);
        for(int k = 0; k < myCase.length(); k++)
        {
            if(myCase[k] == '1')
            {
                std::vector<int> myBook = books[k];
                myCost += myBook[0];
                for(int l = 1; l <= m; l++)
                {
                    mySkill[l] += myBook[l];
                }
            }
        }
        
        bool myBookOk = true;
        for(int k = 1; k <= m; k++)
        {
            if(mySkill[k] < x)
            {
                myBookOk = false;
            }
        }
        
        if(myBookOk)
        {
            isOK = true;
            if(myCost < minValue)
            {
                minValue = myCost;
            }
        }
    }
    
    if(!isOK)
    {
        minValue = -1;
    }
    
    std::cout << minValue << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    c();
    return 0;
}

Measured memory_bytes: 3700
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;

vector<vector<int>> calc_next(const string &s) {
    int n = s.size();
    vector<vector<int>> nxt(n + 1, vector<int>(26, n));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) nxt[i][j] = nxt[i + 1][j];
        nxt[i][s[i] - 'a'] = i;
    }
    return nxt;
}

int main() {
    string s; cin >> s;
    string t = s; reverse(t.begin(), t.end());
    auto ns = calc_next(s);
    auto nt = calc_next(t);
    int n = s.size();
    vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        for (int k = 0; k < 26; k++) {
            int ni = ns[i][k] + 1, nj = nt[j][k] + 1;
            if (ni + nj > n) continue;
            (dp[ni][nj] += dp[i][j]) %= MOD;
        }
    }
    long long res = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; i + j <= n; j++) {
            int cnt = 1;
            for (int k = 0; k < 26; k++) if (ns[i][k] + 1 + j <= n) cnt++;
            (res += dp[i][j] * cnt % MOD) %= MOD;
        }
    }
    cout << res - 1 << endl;
    return 0;
}


Measured memory_bytes: 34892
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
int pom[MAX][26];
pii father[MAX];
bool O[MAX];
int last[26];
string ans="";
queue<int>q;
int32_t main()
{
  BOOST;
  string s;
  cin>>s;
  int n=sz(s);
  fill(last,last+26,n+1);
  for (int i=n-1;i>=0;i--){
  	for (int j=0;j<26;j++)pom[i+1][j]=last[j];
  	last[s[i]-'a']=i+1;
  }
  for (int i=0;i<26;i++)pom[0][i]=last[i];
  O[0]=true;
  q.push(0);
  while (!q.empty()){
  	int akt=q.front();
  	q.pop();
  	if (akt==n+1){
  		break;
  	}
  	for (int i=0;i<26;i++){
  		int nekst=pom[akt][i];
  		//cout<<"TERAZ "<<akt<<" "<<char(i+97)<<" "<<nekst<<"\n";
  		if (!O[nekst]){
  			O[nekst]=true;
  			q.push(nekst);
  			father[nekst]=mp(akt,i);
  		}
  	}
  }
  
  int akt=n+1;
  while (akt){
  	ans+=char(97+father[akt].nd);
  	akt=father[akt].st;
  }
  
  
  
  
  reverse(ans.begin(),ans.end());
  cout<<ans;
  return 0;
}


Measured memory_bytes: 47704
import numpy as np


def solve(n, k, h_list):
    dp = np.zeros(n, dtype=int)

    for end in range(1, n):
        start = max(0, end - k)
        dp[end] = np.min(dp[start:end] + np.abs(h_list[end] - h_list[start:end]))

    return dp[n - 1]


def main():
    n, k = map(int, input().split())
    h_list = np.array(input().split(), dtype=int)

    ans = solve(n, k, h_list)
    print(ans)


main()

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  int ans = 0;
  
  for(int i = 0; i < n; i++){
  	int p = 0;
    
  	while(a[i]%2 == 0) {
      a[i] /= 2; p++;
    }
  
  	b[i] = p;
  }
  
  sort(b.begin(), b.end());
  
  ans = b[n-1];
  
  cout << b[0] << endl;
  /*cout << b[1] << endl;
  cout << b[2] << endl;*/
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
   int N, M;
   int sum=0, A[10000];
   scanf("%d %d", &N, &M);
   
   for(int i = 0; i < M; i++) {
      scanf("%d", &A[i]);
   }
   for(int i = 0; i < M; i++) {
      sum = sum + A[i];
   }
   if(sum > N) {
      printf("-1");
   }else {
      printf("%d", N-sum);
   }
   printf("\n");
   return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n = 0;
    cin >> n;

    vi a(n, 0);
    rep(i,0,n){
        cin >> a[i];
    }

    sort(all(a));
    int cnt = 0;
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            if(a[i] == a[j]) continue;
            rep(k,j+1,n){
                if(a[j] == a[k]) continue;
                if(a[i]+a[j] > a[k]) ++cnt;
            }
        }
    }

    cout << cnt << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3852
#include <iostream>
#include <cstdio>
#define INF 1e+15
#define int long long
using namespace std;

signed main(){
	int n,m;
	while(scanf("%lld %lld",&n,&m),n){
		int riku[200][200],kai[200][200],r,z[1000],dp[1001][200];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				riku[i][j] = INF;
				kai[i][j] = INF;
			}
			riku[i][i] = 0;
			kai[i][i] = 0;
		}
		for(int i = 0;i < m;i++){
			int x,y,t;
			char s;
			scanf("%lld %lld %lld %c",&x,&y,&t,&s); x--;y--;
			if(s == 'L'){
				riku[x][y] = min(riku[x][y],t);
				riku[y][x] = min(riku[y][x],t);
			}else{
				kai[x][y] = min(kai[x][y],t);
				kai[y][x] = min(kai[y][x],t);
			}
		}
		for(int k = 0;k < n;k++){
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					riku[i][j] = min(riku[i][j],riku[i][k] + riku[k][j]);
					kai[i][j] = min(kai[i][j],kai[i][k] + kai[k][j]);
				}
			}
		}
		scanf("%lld",&r);
		for(int i = 0;i < r;i++){
			scanf("%lld",&z[i]); z[i]--;
			for(int j = 0;j < n;j++) dp[i][j] = INF;
		}
		dp[0][z[0]] = 0;
		for(int i = 1;i < r;i++){
			for(int j = 0;j < n;j++){
				for(int k = 0;k < n;k++){
					dp[i][k] = min(dp[i][k],dp[i - 1][j] + riku[z[i - 1]][j] + kai[j][k] + riku[k][z[i]]);
				}
				dp[i][j] = min(dp[i][j],dp[i - 1][j] + riku[z[i - 1]][z[i]]);
			}
		}
		int mi = INF;
		for(int i = 0;i < n;i++) mi = min(mi,dp[r - 1][i]);
		cout << mi << endl;
	}
	return 0;
}

Measured memory_bytes: 5336
def binary_search(num_list, key):
    left = 0
    right = len(num_list)
    while right > left:
        mid = (left + right)//2
        if num_list[mid] == key:
            return 1
        #前半部分に答えがある
        if num_list[mid] > key:
            right = mid
        #後半部分に答えがある
        elif num_list[mid] < key:
            left = mid + 1            
    return 0
            
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
    ans += binary_search(S, i)
print(ans)



Measured memory_bytes: 16708
#include <complex>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cfloat>
using namespace std;

#define X real()
#define Y imag()

#define fi first
#define se second

typedef complex<double> PT;
typedef PT VC;
typedef pair<PT,PT> LN;
typedef pair<PT,PT> SG;

const double EPS = 1e-8;

double dot_prod(VC a, VC b) {
	return a.X * b.X + a.Y * b.Y;
}
double cross_prod(VC a, VC b) {
	return a.X * b.Y - a.Y * b.X;
}

double dist_pts_line(PT p, LN l) {
	VC a, b;
	a = l.fi - p;
	b = l.se - p;
	return abs(cross_prod(a,b) / abs(l.fi-l.se));
}

// ??\??????????????????????????????

// ???????????´??????????????£???????????????false??????????????§??¨???
bool has_intersec_seg_seg(SG a, SG b) {
	VC va, vb, vc;
	bool res = true;
	for(int i = 0; i < 2; i++) {
		va = b.fi-a.fi; vb = b.se-a.fi; vc = a.se-a.fi;
		res = res && cross_prod(va, vc) * cross_prod(vb, vc) < EPS;
		swap(a,b);
	}
	res = res && abs(cross_prod(a.fi-a.se, b.fi-b.se)) > EPS;
	return res;
}

double dist_pts_seg(PT p, SG a) {
	double res;
	res = min(abs(a.fi-p), abs(a.se-p));
	if(dot_prod(a.se - a.fi, p - a.fi) > -EPS
			&& dot_prod(a.fi - a.se, p - a.se) > -EPS)
		res = min(res, dist_pts_line(p, a));
	return res;
}

double dist_seg_seg(SG a, SG b) {
	double res = DBL_MAX;
	for(int i = 0; i < 2; i++) {
		res = min(res, min(dist_pts_seg(a.fi,b), dist_pts_seg(a.se,b)));
		swap(a,b);
	}
	if(has_intersec_seg_seg(a,b))
		res = 0;
	return res;
}

/* //???????????????
int main() {
	SG a(PT(0,0),PT(0,2));
	SG b(PT(-1,1),PT(2,1));
	cout << dist_seg_seg(a,b) << endl;
} // */

//*
int N, M, L;
vector<vector<SG> > star;
double edge[120][120];

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

void init() {
	star.clear();
	rep(i,120) {
		rep(j,120)
			edge[i][j] = 1e9;
		edge[i][i] = 0;
	}
}

int main() {
	while(cin >> N >> M >> L, N || M || L) {
		init();
		M--; L--;
		rep(i,N) {
			int x, y, a, r;
			cin >> x >> y >> a >> r;
			vector<PT> tmp;
			double theta = (a+90) / 180.0 * M_PI;
			double phi = 360.0 / 5.0 / 180.0 * M_PI;
			rep(i,5) {
				tmp.push_back(polar((double)r, theta + phi * i) + PT(x,y));
			//	cout << tmp[i] << endl;
			}
			vector<SG> push;
			rep(i,5) {
				push.push_back(SG(tmp[i],tmp[(i+2)%5]));
			}
			star.push_back(push);
		}

		rep(i,N) {
			for(int j = i+1; j < N; j++) {
				double tmp = 1e9;
				rep(k,5) {
					rep(l, 5) {
						tmp = min(tmp, dist_seg_seg(star[i][k], star[j][l]));
					}
				}
				edge[i][j] = edge[j][i] = tmp;
			}
		}

		rep(i,N) {
			rep(j,N) {
				rep(k,N) {
					edge[j][k] = min(edge[j][k], edge[j][i] + edge[i][k]);
				}
			}
		}
		printf("%.10lf\n", edge[L][M]);
	}
}
// */

Measured memory_bytes: 1384