akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
arr.freeze
sorted_arr = arr.dup.sort
L_median = sorted_arr[n/2]
S_median = sorted_arr[(n/2)-1]
arr.each do |num|
  if num >= L_median
    puts S_median
  elsif num <= S_median
    puts L_median
  end
end


Measured memory_bytes: 36976
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int q[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(a>=b)
	{
		k--;
		b*=2;
	}
	while(b>=c)
	{
		c*=2;
		k--;
	}
	if(k>=0)cout<<"Yes\n";
	else cout<<"No\n";



}


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

int main()
{
    int num, min, count, *arr;
    scanf("%d", &num);
    arr = (int*) malloc(num * sizeof(int));
    
    count=0;
    for (int i=0; i<num ; i++)
    {
        scanf("%d", &arr[i]);
        if (i==0 || arr[i] < min)
        {
            count++;
            min = arr[i];
        }
    }
    printf("%d", count);

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

string str;

void reset()
{
}

void input()
{
	int ans =0 , temp = 0;
	cin>>str;
	UP(i,0,str.length())
	{
		if(str[i] == 'R')
		{
			temp++;
			ans = max(ans, temp);
		}
		else
		{
			temp = 0;
		}
	}
	cout<<ans<<endl;
}

void solve()
{
}

void LetsRock()
{
	solve();	
}

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

	input();
	reset();
	LetsRock();
	
	return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>
#define ll int
ll exgcd(ll p,ll q,ll*x,ll*y){
	ll tx,ty,t,x2=0,y2=1;
	*x=1;*y=0;
	while(q){
		tx=*x-p/q*x2;*x=x2;x2=tx;
		ty=*y-p/q*y2;*y=y2;y2=ty;
		t=p%q;p=q;q=t;
	}
	return p;
}

int main(){
	int p,q;
	scanf("%d%d",&p,&q);
	ll a,b;
	exgcd(p,q,&a,&b);	
	printf("%d %d\n",a,b);
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int A, B, C, X;
int main() {
    std::cin >> A >> B >> C >> X;

    int cnt = 0;
    for(int i=0; i<=A; ++i) {
        for(int j=0; j<=B; ++j) {
            for(int k=0; k<=C; ++k) {
                int v = i*500 + j*100 + k*50;
                if(v == X) {
                    cnt++;
                }
            }
        }
    }
    std::cout << cnt << std::endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N:=readInt()
	println(180*(N-2))
}

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


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Q = int(input())
N = [input() for i in range(0,Q)]

integer = lambda x: int(x) if x != '' else 0
for n in N:
    ans = '0' if int(n) // 10 == 0 else str(n)
    count = 0
    while int(ans) // 10 > 0:
        count += 1
        tmp = 0
        for i in range(1,len(ans)):
            tmp = max(tmp,integer(ans[:i]) * integer(ans[i:]))
        ans = str(tmp)
    else:
        print(count)

Measured memory_bytes: 6728
s = raw_input()
if "eraser" in s:
    s = s.replace("eraser","")
if "erase" in s:
    s = s.replace("erase","")
if "dreamer" in s:
    s = s.replace("dreamer","")
if "dream" in s:
    s = s.replace("dream","")
if len(s) == 0:
    print "YES"
else:
    print "NO"


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 2.01e14;
const double eps = 1e-8;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;
    vector<long double> x(N),y(N);
    vector<char> d(N);
    rep(i,0,N) cin >> x[i] >> y[i] >> d[i];

    auto f=[&](long double t){
        long double xmin=inf64,xmax=-inf64,ymin=inf64,ymax=-inf64;
        rep(i,0,N){
            long double xx=x[i],yy=y[i];
            if(d[i]=='R') xx+=t;
            else if(d[i]=='L') xx-=t;
            else if(d[i]=='U') yy+=t;
            else yy-=t;
            chmin(xmin,xx);
            chmax(xmax,xx);
            chmin(ymin,yy);
            chmax(ymax,yy);
        }
        return (xmax-xmin)*(ymax-ymin);
    };

    long double lb=0,ub=4.1e8;
    rep(i,0,200){
        auto a=(lb+lb+ub)/3;
        auto b=(lb+ub+ub)/3;
        if(f(a)>f(b)){
            lb=a;
        }else{
            ub=b;
        }
    }

    long double ans=min(f(lb),f(0));

    i64 loop=1000;
    rep(i,-loop,loop){
        if(max(i64(0),i64(lb)+i) == 0){
            ++loop;
            continue;
        }
        chmin(ans,f(i64(lb)+i));
    }
    loop=1000;
    rep(i,-loop,loop){
        if(max((long double)0,(long double)(i64(lb)+0.5*i)) == 0){
            ++loop;
            continue;
        }
        chmin(ans,f(i64(lb)+0.5*i));
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
class Tree{
private:
  int n;//number of node
  int m;
  vector<vector<int>> edge;// edge does not have cost.
  vector<vector<pair<int,int>>> edge2;// edge has cost.
  vector<bool> col;
  vector<bool> f;
public:  
  //*****Constructor************
  Tree(int n_){
    n = n_;
    edge.resize(n);
  }

  Tree(int n_,int m_,vector<int> a,vector<int> b){
    n = n_;
    m = m_;
    edge.resize(n);
    rep(i,m){
      edge[a[i]].push_back(b[i]);
      edge[b[i]].push_back(a[i]);
    }
  }

  Tree(int n_,int m_,vector<int> a,vector<int> b,vector<int> c){
    n = n_;
    m = m_;
    edge2.resize(n);
    rep(i,m){
      edge2[a[i]].push_back(make_pair(b[i],c[i]));
      edge2[b[i]].push_back(make_pair(a[i],c[i]));
    }
  }  
  //*******************************************
  bool bipa_check(int v,bool color)
  {
    f[v] = true;
    col[v] = color;
    for(auto& w:edge[v]){
      if(f[w]){
	if(col[w] == color) return false;
      }
      else if(!bipa_check(w,!color)) return false;
    }
    return true;
  }

  void solve(){
    col.assign(n,0);
    f.assign(n,0);
    bipa_check(0,0);
    int x = 0,y = 0;
    vector<int> xvec,yvec;
    rep(i,n){
      if(col[i]){
	x++;
	xvec.push_back(i);
      }
      else{
	y++;
	yvec.push_back(i);	
      }
    }
    int n0 = n/3,n1 = (n+2)/3,n2 = (n+1)/3;
    vector<int> res(n,0);
    if(n1+n2<=x){
      rep(i,n1){
	res[xvec[i]] = i*3+1;
      }
      rep(i,n2){
	res[xvec[i+n1]] = i*3+2;
      }      
    }
    else if(n1+n2<=y){
      rep(i,n1){
	res[yvec[i]] = i*3+1;
      }
      rep(i,n2){
	res[yvec[i+n1]] = i*3+2;
      }            
    }
    else if(n1<=x){
      rep(i,n1){
	res[xvec[i]] = i*3+1;
      }
      rep(i,n2){
	res[yvec[i]] = i*3+2;
      }      
    }
    else if(n2<=x){
      rep(i,n2){
	res[xvec[i]] = i*3+2;
      }
      rep(i,n1){
	res[yvec[i]] = i*3+1;
      }      
    }
    int z = 3;
    rep(i,n){
      if(res[i]==0){
	res[i] = z;
	z += 3;
      }
    }
    rep(i,n) cout << res[i] << " ";
    cout  << "\n";
  }
  
};



int main()
{
  int n;cin >> n;
  vector<int> a(n-1),b(n-1);
  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
  }
  Tree tr(n,n-1,a,b);
  tr.solve();
  return 0;
}


Measured memory_bytes: 16484
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int in[6];
	while(cin>>in[0]){
		rep(i,5)cin>>in[i+1];
		int a=in[0]*3600+in[1]*60+in[2],b=in[3]*3600+in[4]*60+in[5];
		b-=a;
		cout<<b/3600<<" "<<(b%3600)/60<<" "<<b%60<<endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001

int list[MAX][3];

int com(const void *a, const void *b){
  return list[*(int*)a][1] - list[*(int*)b][1];
}

int main(){
  int n,m,
      i,
      t[MAX],
      rank[MAX];
  
  scanf("%d%d", &n, &m);
  
  for(i=0;i<m;i++){
    scanf("%d%d", &list[i][0], &list[i][1]);
    list[i][2] = 0;
  }
  for(i=0;i<m;i++){t[i]=i;}
  for(i=1;i<=n;i++){rank[i]=0;}
  
  qsort(t,m,sizeof(int),com);
  for(i=0;i<m;i++){
    rank[list[t[i]][0]]++;
    list[t[i]][2] = rank[list[t[i]][0]];
  }
  
  for(i=0;i<m;i++){
    printf("%06d%06d\n", list[i][0], list[i][2]);
  }
  
  return 0;
}

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll f(string s){
	ll a=0;
	rep(i,s.size()){
		a*=2;
		a+=s[i]-'0';
	}
	return a;
}
int main(){
	int q;
	cin>>q;
	cin>>hex;
	while(q--){
		vi in(9);
		rep(i,9)cin>>in[i];
		string out="";
		int kr=0;
		rep(i,32){
			int t=kr;
			rep(j,8)if(in[j]&1ll<<i)t++;
			if(t%2==(in[8]>>i&1)){
				out="0"+out;
				kr=t/2;
			}else{
				out="1"+out;
				kr=(8-t+2*kr)/2;
			}
		}
		cout<<hex<<f(out)<<endl;
	}
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC043 A - キャンディーとN人の子供イージー
// 2020.06.15

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = N*(N+1)/2;
  cout << ans << endl;
}

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

// ------ Class ------ //
class Graph2 {
public:
	// ------ Variables ------ //
	static const long long INF = 1000000000000000000;
	int V, E; vector<vector<pair<int, long long> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, long long> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, long long> > >(v)) {}
	Graph2(vector<vector<pair<int, long long> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, long long w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, long long w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, long long> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	long long minspan() {
		vector<long long> d(V, INF);
		vector<bool> used(V, false);
		priority_queue<pair<long long, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<long long, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second; que.push(make_pair(-d[v], v));
				}
			}
		}
		long long sum = 0;
		for (int i = 0; i < V; i++) sum += d[i];
		return sum;
	}
};

// ------ Main ------ //
int n, a;
int main() {
	cin >> n; Graph2 g(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> a;
			if(a != -1) g.add1(i, j, a);
		}
	}
	cout << g.minspan() << endl;
}

Measured memory_bytes: 3160
#include <iostream> // cin, cout, cerr, clog
#include <set> // sets
#include <iterator> //iterators
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

struct Roadwork {
  ll s,t,x;
  Roadwork(ll ss, ll tt, ll xx) : s(ss), t(tt), x(xx) {}
};

ll ans[200001];
int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  ll n,q;
  std::cin >> n >> q;
  std::vector<Roadwork> RW;
  RW.reserve(n);
  std::set<ll> P;
  rep(i,n) {
    ll s,t,x;
    std::cin >> s >> t >> x;
    RW.emplace_back(s-x,t-x,x);
  }
  std::unordered_map<ll,ll> um;
  rep(i,q) {
    ll d;
    std::cin >> d;
    P.insert(d);
    um[d] = i;
    ans[i] = -1;
  }
  std::sort(RW.begin(),RW.end(),[](Roadwork a, Roadwork b) {
    if (a.x==b.x) return a.s<b.s;
    return a.x < b.x;
  });
  for(auto r:RW) {
    while(P.size()>0) {
      auto p = P.lower_bound(r.s);
      if(p==P.end()) break;
      if(r.t<=(*p)) break;
      ans[um[(*p)]] = r.x;
      P.erase(p);
    }
  }
  rep(i,q) std::cout << ans[i] << "\n";

  return 0;
}

Measured memory_bytes: 25800
N = int(input())
word = [str(input()) for i in range(N)]
dic = {}
for i in word:
  if i in dic:
    dic[i] += 1
  else:
    dic[i] = 1
max_num = max(dic.values())
can_word = []
for i,j in dic.items():
  if j == max_num:
    can_word.append(i)
can_word.sort()
for i in can_word:
  print(i)

Measured memory_bytes: 38432
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

vll NUM = {2, 5, 5, 4, 5, 6, 3, 7, 6};

string smax(string s1, string s2){
  if(s1.size() > s2.size()) return s1;
  if(s2.size() > s1.size()) return s2;
  REP(i, s1.size()){
    if(s1[i]>s2[i]) return s1;
    if(s2[i]>s1[i]) return s2;
  }
  return s1;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;
  vll A(M);
  REP(i, M){
    cin >> A[i];
  }

  sort(A.begin(), A.end(), greater<ll>());

  vector<string> dp(N+1, "");
  REP(i, N+1){
    REP(j, M){
      ll pos = i-NUM[A[j]-1];
      if(pos<0) continue;
      if(pos>0 && dp[pos].size()==0) continue;
      dp[i] = smax(dp[i], to_string(A[j])+dp[pos]);
    }
  }

  cout << dp[N] << "\n";

  return 0;
}

Measured memory_bytes: 29568
#include <stdio.h>
int main(){
    int N, X, T;
    int t;
    scanf("%d %d %d", &N, &X, &T);
    if(N%X == 0){
        t = (N/X) * T;
    }
    else{
        t = (N/X + 1) * T; 
    }
    printf("%d", t);
    return 0;
}

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

#include <algorithm>

using namespace std;

int main(){
  
  int n,ans,t,co;
  ans=0;
 co=-10;
  cin>>n;
vector<int> a(n);
 vector<int> b(n);
  vector<int> c(n-1);
 for(int i=0; i<a.size(); i++){
    cin>>a.at(i);
 }
  for(int i=0; i<b.size(); i++){
    cin>>b.at(i);
 }
  for(int i=0; i<c.size(); i++){
    cin>>c.at(i);
 }
  
  
   for(int i=0; i<a.size(); i++){
     t=a.at(i);
     
     ans+=b.at(t-1);
     if(t-co==1)ans+=c.at(t-2);
   co=t;
 }
  
  cout<<ans<<endl;
  
  
  
  
  
  
  
}

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


void solve(long long N, long long Y){
    string ans = "-1 -1 -1";
    for (int x = 0; x <= N; x++) {
        for (int y = 0; y <= N - x; y++) {
            int z = N - (x + y);
            if (10'000*x + 5'000*y + 1'000*z == Y) ans = to_string(x) + " " + to_string(y) + " " + to_string(z);
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long Y;
    scanf("%lld",&Y);
    solve(N, Y);
    return 0;
}


Measured memory_bytes: 256
import numpy as np

D = int(input())
c = np.array( list(map(int, input().split())) )
#
s = [[] for i in range(D)]
for i in range(D):
  s[i] = np.array( list(map(int, input().split())) )
#
v = 0
cc =  np.array( [0]*26 )
last = np.array( [-1]*26 )
for d in range(D):
  cc += c
  av = s[d] - sum( cc ) + cc
  av2 = av + cc*min((D-d-1),2)
  m = max(av2)
  for t in range(26):
    if av2[t] == m:
      cc[t] = 0
      v += av[t]
      print(t+1)
      break
#
#print( v )


Measured memory_bytes: 27300
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int l = Integer.parseInt(in.next());

            int r = l + n - 1;

            int ans = 0;

            if (r <= 0) ans = r;
            else if (l >= 0) ans = l;
            else ans = 0;

            ans = (r + l) * (r - l + 1) / 2 - ans;
            // 出力
            out.println(ans);

        }

    }
}



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

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

void fail() {
    cout << "Impossible" << endl;
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll N, L;
    cin >> N >> L;

    vector<ll> a(N);
    forn(i, N)
        cin >> a[i];

    int k = -1;
    forn(i, N - 1)
        if (a[i] + a[i + 1] >= L)
            k = i;

    if (k == -1)
        fail();

    cout << "Possible" << endl;
    forn(i, k)
        cout << i + 1 << endl;
    for (int i = N - 2; i > k; i--)
        cout << i + 1 << endl;
    cout << k + 1 << endl;
}


Measured memory_bytes: 1664
def DP(n, k):
    if k == 0:
        return 1
    elif n < 10 and k == 1:
        return n
    elif n < 10 and k != 0:
        return 0
    else:
        q, r = n//10, n % 10
        return DP(q, k)+r*DP(q, k-1)+(9-r)*DP(q-1, k-1)


n = int(input())
k = int(input())
print(DP(n, k))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin>>n;
    ll t,a;

    rep(i,n){
        ll x,y;
        cin>>x>>y;
        if(i==0){
            t=x,a=y;
        }
        else{
            if(t<=x&&a<=y){
                t=x,a=y;
            }
            else{
                ll bt=(t+x-1)/x,ba=(a+y-1)/y;
                t=x*max(bt,ba);a=y*max(bt,ba);
            }
        }
    }
    cout<<(t+a)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int shojikin = sc.nextInt();
		int cake = sc.nextInt();
		int donuts = sc.nextInt();
		shojikin = shojikin - cake;
		int amari = shojikin%donuts;
		System.out.println(amari);
	}
}

Measured memory_bytes: 23380
import sys
sys.setrecursionlimit(10**7)

def main():
  n, m = map(int, input().split())
  G = [[] for _ in range(n)]
  for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
  q = int(input())
  vdc = [list(map(int, input().split())) for _ in range(q)][::-1]
  dp = [[0]*11 for _ in range(n)]
  def dfs(v, d, c):
    if dp[v][d]:
      return dp[v][d]
    if d == 0:
      dp[v][d] = c
      return
    for u in G[v]:
      dfs(u, d-1, c)
    dfs(v, d-1, c)
    dp[v][d] = c
  for v, d, c in vdc:
    dfs(v-1, d, c)
  for i in range(n):
    print(dp[i][0])
if __name__ == "__main__":
  main()

Measured memory_bytes: 62328
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        while (A[i] % 2 == 0) {
            ans++;
            A[i] /= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

var (
	N, K int
	h, dp []int
)

func solve(n int) int {
	if dp[n] != -1 {
		return dp[n]
	}

	if n == 0 {
		dp[n] = 0
	} else if n == 1 {
		dp[n] = int(math.Abs(float64(h[n] - h[n-1])))
	} else {
		var ans = int(math.Pow(10, 9))
		for i := 1; i <= K; i++ {
			if n - i < 0 {
				break
			}
			var cost =  solve(n - i) + int(math.Abs(float64(h[n-i]-h[n])))
			ans = int(math.Min(float64(ans), float64(cost)))
		}

		dp[n] = ans
	}

	return dp[n]
}

func main() {
	fmt.Scan(&N, &K)
	h = make([]int, N)
	dp = make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&h[i])
	}
	for i := 0; i < N; i++ {
		dp[i] = -1
	}

	fmt.Println(solve(N - 1))
}


Measured memory_bytes: 20428
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  long long int k;
  cin>>k;
  vector<pair<int,int>> hoge(n);
  for(int i=0; i<n; i++){
    cin>>hoge.at(i).first>>hoge.at(i).second;
  }
  sort(hoge.begin(),hoge.end());
  for(int i=0; i<n; i++){
    k-=hoge.at(i).second;
    if(k<=0){
      cout<<hoge.at(i).first<<endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;

int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (b / a <= c)cout << b / a << endl;
	else cout << c << endl;
	
	return 0;
}





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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  sort(all(s));
  char ans=-1;
  for(int i=0;i<26;i++){
    char tar='a'+i;
    if(s.find(tar,0)==string::npos){
      ans=tar;
      break;
    }
  }
  if(ans==-1){
    cout<<"None"<<endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3708
/*
 * Created by Timothy Wang on 5/9/2020.
 * A - Iroha and Haiku (ABC Edition)
 * https://atcoder.jp/contests/abc042/tasks/abc042_a
 */
#include<bits/stdc++.h>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int lines[3];
    cin >> lines[0] >> lines[1] >> lines[2];
    int count7 = 0, count5 = 0;
    for(int i = 0; i < 3; i++) {
        if(lines[i] == 7) {
            count7++;
        }
        if(lines[i] == 5) {
            count5++;
        }
    }
    if(count7 == 1 and count5 == 2) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
}

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

using namespace std;

string O, E;

int main(void)
{
	cin >> O >> E;
	
	for(int i = 0; ; i++){
		if(O.size() == i) break;
		cout << O[i];
		if(E.size() == i) break;
		cout << E[i];
	}
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

void draw(vector<ll> x){
  for(auto v:x){
    cout << v << " ";
  }
  cout << endl;
  return;
}
          
void solve(void){
  
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  
  vector<ll> p(A), q(B), r(C);
  
  REP(i,A){
    cin >> p[i];
  }
  REP(i,B){
    cin >> q[i];
  }
  REP(i,C){
    cin >> r[i];
  }

  sort(ALL(p), greater<ll>());
  sort(ALL(q), greater<ll>());
  
//  draw(p);
//  draw(q);
  
  p.erase(p.begin()+X, p.end());
  q.erase(q.begin()+Y, q.end());
  p.insert(p.end(), ALL(q));
  p.insert(p.end(), ALL(r));
  sort(ALL(p), greater<ll>());
  
//  draw(p);

  ll sum=0;
  REP(i,X+Y){
    sum += p[i];
  }
  
  cout << sum << endl;
  
  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}


Measured memory_bytes: 5744
// g++ -std=c++11 test.cpp && ./a.out
// g++ -std=c++11 bfs.cpp && cat bfs.txt | ./a.out

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>

using namespace std;

#define INF (1<<29)
#define PRINT(A) {for (auto it=A.begin(); it != A.end(); ++it) {cout << *it << ' ';} cout << endl;}
#define SUM(A) accumulate(A.begin(), A.end(), 0)
#define MAX(A) *max_element(A.begin(), A.end())
#define BIT_LENGTH(N) floor(log2(N)) + 1
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define RREP(I, N) for (int I = N-1; I >= 0 ; --I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RREPP(I, A, B) for (int I = A; I > (B); --I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I

typedef vector<int> VI;
typedef map<int, int> MII;
typedef set<int> SI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

VI bitSums;

void add(int index, int value) {
    size_t i = index + 1;
    while (i < bitSums.size()) {
        bitSums[i] += value;
        i += (i & -i);
    }
}

int sum(int end) {
    int res = 0;
    int i = end+1;
    while (i != 0) {
        res += bitSums[i];
        i -= (i & -i);
    }
    return res;    
}

int range_sum(int start, int end) {        
    return sum(end) - sum(start-1);
}


int main() {
    int N, Q;
    cin >> N >> Q;
    VI C;
    VVI queries;
    REP(i, N) {
        int n;
        cin >> n;
        C.push_back(n);
    }
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        queries.push_back({i, l, r});
    }

    VI D(N, INF);
    unordered_map<int, int> last_index;
    REP(i, N) {
        if (last_index.find(C[i]) != last_index.end()) { //found
            D[last_index[C[i]]] = i;
        }
        last_index[C[i]] = i;
    }

    sort(queries.begin(), queries.end(), [](VI n1, VI n2) { return n1[2] < n2[2]; });
    bitSums = vector<int>(N+1, 0);
    unordered_map<int, int> goods;
    int right_most = 0;
    
    VI ans(Q, 0);
    for (auto query: queries) {
        int index, l, r;
        index = query[0];
        l = query[1] - 1;
        r = query[2] - 1;
        // cout << "R:" << r << endl;
        REPP(i, right_most, r+1) {
            // cout << "I:" << i << endl;
            if (D[i] > r) { // D[i] is good
                // cout << "GOOD:" << D[i] << endl;
                if (goods.find(C[i]) != goods.end()) { // already in good sets
                    add(goods[C[i]], -1);
                }
                goods[C[i]] = i;
                add(i, 1);
            }
        }
        // PRINT(bitSums);
        right_most = r + 1;
        ans[index] = range_sum(l, r);
        // break;
    }

    for (auto a: ans) {
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 78364
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> ii;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n, k;
    string str;

    cin>>n>>k;
    cin>>str;

    int same = 0, diff = 0;
    for(int i = 0; i < str.size() - 1; i++){
        if(str[i] == str[i+1])
            same++;
        else
            diff++;
    }

    int ans = same + min(k * 2, diff);

    cout<<ans<<endl;
    

    return 0;
}


Measured memory_bytes: 512
def getN():
    return int(input())

# def gcd(p, q):
#     if p % q == 0: return q
#     return gcd(q, p % q)

def gcd(p, q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p

def main():
    
    K = getN()

    result = 0

    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                result += gcd(gcd(i,j),k)
    
    print(result)

    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 68552
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    ps: [(i32, i32); n],
  }
  let mut ans = 1e100;
  for i in 0 .. n {
    for j in i+1 .. n {
      let dx1 = ps[j].0 - ps[i].0;
      let dy1 = ps[j].1 - ps[i].1;
      for k in j .. n {
        let dx2 = ps[k].0 - ps[i].0;
        let dy2 = ps[k].1 - ps[i].1;
        let center = if dx1 * dy2 == dx2 * dy1 {
          (
            (cmp::max(ps[i].0, cmp::max(ps[j].0, ps[k].0)) + cmp::min(ps[i].0, cmp::min(ps[j].0, ps[k].0))) as f64 / 2.0,
            (cmp::max(ps[i].1, cmp::max(ps[j].1, ps[k].1)) + cmp::min(ps[i].1, cmp::min(ps[j].1, ps[k].1))) as f64 / 2.0
          )
        } else {
          let det = (dx2 * dy1 - dx1 * dy2) as f64;
          let t = (-dx2 * dx1 + dx2 * dx2 - dy1 * dy2 + dy2 * dy2) as f64 / 2.0 / det;
          let dx1 = dx1 as f64;
          let dx2 = dx2 as f64;
          let dy1 = dy1 as f64;
          let dy2 = dy2 as f64;
          (
            (ps[i].0 as f64 + dx1 / 2.0 + t * dy1),
            (ps[i].1 as f64 + dy1 / 2.0 - t * dx1)
          )
        };
        let mut max = 0.0;
        for l in 0 .. n {
          let d = ((ps[l].0 as f64 - center.0).powi(2) + (ps[l].1 as f64 - center.1).powi(2)).sqrt();
          if d > max {
            max = d;
          }
        }
        if max < ans {
          ans = max;
        }
      }
    }
  }

  puts!("{:.15}\n", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
const int INF = 1000000000;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	int ans=(c-a+b);
	if(ans<0) co(0);
	else co(ans);
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

maxi = 0
ans = 0
for a in As:
    if a<maxi:
        ans += maxi-a
    maxi = max(a, maxi)

print(ans)

Measured memory_bytes: 94024
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

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

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

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

using namespace std;
typedef long long ll;

ll a, b, c, n, k, x;
string s;

int main()
{
  cin >> n;
  ll d[n];
  for (ll i = 0; i < n; i++)
  {
    cin >> d[i];
  }
  sort(d, d + n);

  ll num = 0;
  for (ll i = 0; i < n - 1; i++)
  {
    if (d[i] == d[i + 1])
    {
      num++;
    }
  }
  cout << n - num << endl;
}


Measured memory_bytes: 256