akhauriyash/Code-Regression huggingface dataset:
def c_grand_garden(N, H):
    ans = 0
    H.append(0)
    for k in range(N):
        ans += max(H[k] - H[k + 1], 0)
    return ans

N = int(input())
H = [int(i) for i in input().split()]
print(c_grand_garden(N, H))

Measured memory_bytes: 3060
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b!= c) printf("Yes\n");
  else if(b==c && c!= a) printf("Yes\n");
  else if(c==a && a!= b) printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

using namespace std;

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

    vector <int> v(n/2 + 1);
    vector <int> w(n/2 + 1);
    for(int i = 0; i < n / 2; i++){
        cin >> v[i] >> w[i];
    }

    sort(v.begin(), v.end());
    sort(w.begin(), w.end());

    //最頻値と2番目の頻繁な回数・値を求める
    int count = 1;
    int countv1 = 0, countv2 = 0;
    int v1, v2;
    
    for(int i = 0; i < n/2; i++){
        if (v[i] == v[i + 1]) {
            count += 1;
        }else{
            count = 1;
        }

        if (countv1 < count) {
            countv1 = count;
            v1 = v[i];
        }else if (countv2 <= count) {
            countv2 = count;
            v2 = v[i];
        }        
    }
    
    count = 1;
    int countw1 = 0, countw2 = 0;
    int w1, w2;

    for(int i = 0; i < n/2; i++){
        if (w[i] == w[i + 1]) {
            count += 1;
        }else{
            count = 1;
        }

        if (countw1 < count) {
            countw1 = count;
            w1 = w[i];
        }else if (countw2 <= count) {
            countw2 = count;
            w2 = w[i];
        }        
    }

    if (v1 != w1) {
        cout << n - (countv1 + countw1) << endl;
    }else{
        if (countv1 == countv2 || countw1 == countw2) {
            cout << n - (countv1 + countw1) << endl;
        }else{
            if (n - (countv1 + countw2) < n - (countv2 + countw1)){
                cout << n - (countv1 + countw2) << endl;
            }else{
                cout << n - (countv2 + countw1) << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int x,a;
    cin>>x>>a;
    if(x<a){
        cout<<0<<endl;

    }else{
        cout<<10<<endl;
    }




    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if 2*max(l[i],l[j],l[k])<l[i]+l[j]+l[k] and len({l[i],l[j],l[k]})==3:
        ans+=1
print(ans)

Measured memory_bytes: 9204
import itertools
N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
lis=list(itertools.permutations(list(range(1,N+1))))
tmp1=0
tmp2=0
a=0
b=0
for v in lis:
    tmp=list(v)
    if tmp==p:
        a=tmp1+1
    if tmp==q:
        b=tmp2+1
    tmp1+=1
    tmp2+=1
print(abs(a-b))

Measured memory_bytes: 8180
fun main(args: Array<String>) = IO().exec {
    val ab = LongArray(2){long()}
    val k = int()
    for (i in k) {
        ab[i%2] = ab[i%2] / 2 * 2
        ab[1-i%2] += ab[i%2] / 2
        ab[i%2] = ab[i%2] / 2
    }
    println("${ab[0]} ${ab[1]}")
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 31392
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        print(s);
    } else {
        cout << s.substr(0, k) << "...\n";
    }

    return 0;
}



Measured memory_bytes: 3656
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 100005;
int n, m;
char a[10][10];
void input() {
    RI(n, m);
    REP(i, n) 
        REP(j, m) {
            char c;
            while((c=getchar()) == '\n');
            a[i][j] = c;
        }
}

void solve() {
    queue<pair<int,int>> q;
    q.push({0,0});
    a[0][0] = '.';
    while (!q.empty())
    {
        int i=q.front().first, j=q.front().second;
        q.pop();
        if(a[i+1][j] == '#') {
            a[i+1][j] = '.';
            q.push({i+1, j});
        } else if(a[i][j+1] == '#') {
            a[i][j+1] = '.';
            q.push({i, j+1});
        }
    }

    #ifdef DEBUG
    REP(i, n) {
        REP(j, m)
        {
            printf("%c", a[i][j]);
        }
        printf("\n");
    }
    #endif

    REP(i, n) REP(j, m) if(a[i][j] == '#') {
        printf("Impossible\n");
        return;
    }
    printf("Possible\n");
}

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

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

//それぞれのセル間の数値の差が行列ごとに一定ならばOK
int main(){
	vector<vector<int>> c;

	for (int i = 0; i < 3; i++){
		vector<int> vc;
		for(int j = 0; j < 3; j++){
			int tc;
			cin >> tc;
			vc.push_back(tc);
		}
		c.push_back(vc);
	}

	//縦列の検証
	bool isPassed = true;
	for (int j = 0; j < 2; j++){
		int d = c[0][j + 1] - c[0][j];	//初期値,他の列と比較して全て等しければOK
		if (isPassed){
			for (int i = 1; i < 3; i++){
				if (d != c[i][j + 1] - c[i][j]){
					isPassed = false;
					break;
				}
			}
		}
	}

	//横列の検証
	for (int i = 0; i < 2; i++){
		int d = c[i + 1][0] - c[i][0];	//初期値,他の列と比較して全て等しければOK
		if (isPassed){
			for (int j = 1; j < 3; j++){
				if (d != c[i + 1][j] - c[i][j]){
					isPassed = false;
					break;
				}
			}
		}
	}

	if (isPassed){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
typedef pair<ll,ll>pll;
const  ll MAX=100000000;
int main()
{



   ll t;

   cin>>t;

   ll ac=0,wa=0,tle=0,re=0;

   while(t--)
   {
       string str;
       cin>>str;

    if(str=="AC")ac++;
    else if(str=="WA")wa++;
    else if(str=="TLE")tle++;
     else if(str=="RE")re++;


   }

   cout<<"AC x "<<ac<<endl;
     cout<<"WA x "<<wa<<endl;
       cout<<"TLE x "<<tle<<endl;
         cout<<"RE x "<<re<<endl;


}



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

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1) cin >> b[i];
    int ans = 0;
  	
    for(int i=n-2; i>=0; --i){
      	bool flag=true;
        if(i == n-2) {
            ans += b[i];
            flag=false;
        }
      	if(i == 0){
          ans += b[i];
        }
        if(flag) ans += min(b[i],b[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
int z=0;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
signed main(){
    int x;cin>>x;
    if(x==3||x==5||x==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 505; 
struct Station{
	int C, S, F;
}sta[MAX_N];
int sum[MAX_N],ans[MAX_N];

int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		sum[1] = 0; 
		for(int i = 1; i < n; i++){
			scanf("%d%d%d",&sta[i].C,&sta[i].S,&sta[i].F);
			sum[i+1] = sum[i] + sta[i].C;
		}
	
		for(int i = 1; i < n; i++){
			int temp, arr = sta[i].S + sta[i].C;
			for(int j = i + 1; j < n; j++){
				if(sta[j].S < arr){
					int t = (arr - sta[j].S) % sta[j].F;
					if(t == 0) temp = arr;
					else temp = arr + sta[j].F - t;	
				}else{
					temp = sta[j].S;
				}
				arr = temp + sta[j].C;
			}
			ans[i] = arr;
		}
		
		ans[n] = 0;
		for(int i = 1; i <= n; i++){
			printf("%d\n",ans[i]);
		}
	}
	return 0;
}

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

long long n, m, k, t = 0;
long long p[200001], q[200001], r[200001];
const long long M = 998244353;

long long pow(long long a, long long b) {
	long long w = 1, x = a;

	while (b) {
		if (b & 1)
			w = w * x % M;

		x = x * x % M;
		b >>= 1;
	}

	return w;
}

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

	p[0] = 1;
	q[0] = 1;
	r[0] = 1;

	for (long long i = 1; i < n; i++) {
		p[i] = p[i - 1] * i % M;
		q[i] = pow(p[i], M - 2);
		r[i] = r[i - 1] * (m - 1) % M;
	}
	
	for (long long j = 0; j <= k; j++) {
		long long s = m;

		s = (((s * p[n - 1] % M) * q[j] % M) * q[n - j - 1] % M) * r[n - j - 1] % M;
		t = (t + s) % M;
	}

	cout << t << endl;
}


Measured memory_bytes: 8236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N+1,0);
    for(ll i=0;i<N;i++)cin>>A[i+1];
    vector<ll> until(N+1,0);
    for(ll i=1;i<=N;i++)until[i]=(until[i-1]+A[i])%M;
    Map Ma;
    for(ll i=0;i<=N;i++)Ma[until[i]]++;
    ll ans=0;
    for(auto p: Ma){
        ll x=p.second;
        ans+=x*(x-1)/2;
    }
    print(ans)
    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   string s;cin>>s;
   string t = s;
   reverse(ALL(s));
   cout<<(s==t?"Yes":"No");
}



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

using namespace std;

int a[200100];
int suf[200100], pre[200100];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
    {
        char c;
        scanf(" %c", &c);
        if(c == 'R') a[i] = 1;
        else a[i] = 0;
    }
    pre[0] = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(a[i] == 0) pre[i] = pre[i-1] + 1;
    }
    suf[n+1] = 0;
    for(int i = n; i >= 1; --i)
    {
        if(a[i] == 1) suf[i] = suf[i+1]+1;
    }
    int ans = 0;
    int l = 1, r = n;
    while(l < r)
    {
        while(a[l] && l < r) l++;
        while(!a[r] && l < r) r--;
        if(l != r)
        {
            swap(a[l], a[r]);
            ans++;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 6172
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int score[] = {0, 0, 60, 70, 80};
  int n;
  cin>>n;
  while(n--) {
    int ba[5][5];
    REP(y,5)
      REP(x,5)
      cin >> ba[x][y];
    int dp[4][1<<2*4];          // dp[i][S] = i ツ行ツ姪堋づ個スツイツッツチツづーツ湘ウツ妥粘 ツづ可つオツつスツづつォツづ景 ツ行ツ姪堋づ慊づづ個スツコツアツづ個催妥・ツ値
                                // S ツづ債、ツビツッツトツ療アツづーツ２ツビツッツトツつクツづつづ可閉ェツつッツつスツづつォツ、i ツ氾板姪堋づ個グツδ仰ーツプツつェi ツ古つ姪堋づ個スツイツッツチツづーツ可スツ嘉アツ可淞つオツつスツつゥツづーツ表ツつキ
    memset(dp,0,sizeof(dp));
    REP(S, 1<<2*4) {
      REP(x,5) {
        int sc = ba[x][0];
        if (sc==0) continue;
        if (x>0) sc += S>>2*x-2 & 3;
        if (x<4) sc += S>>2*x & 3;
        while(sc>4) sc -= 4;
        dp[0][S] += score[sc];
      }
    }
    for (int i=1; i<4; ++i) {
      REP(S, 1<<2*4) {          // ツ１ツ行ツ前ツづ個スツイツッツチツづ個湘ウツ妥板。
        REP(T, 1<<2*4) {        // ツ個サツ催敖づ個行ツづ個スツイツッツチツづ個湘ウツ妥板。
          int now = dp[i-1][S];
          REP(x,5) {
            int sc = ba[x][i];
            if (sc==0) continue;
            if (x>0) sc += (S>>2*x-2 & 3) + (T>>2*x-2 & 3);
            if (x<4) sc += (S>>2*x & 3) + (T>>2*x & 3);
            while(sc>4) sc -= 4;
            now += score[sc];
          }
          dp[i][T] = max(dp[i][T], now);
        }
       }
    }
    int ans = 0;
    REP(S, 1<<2*4) {
      int now = dp[3][S];
      REP(x,5) {
        int sc = ba[x][4];
        if (sc==0) continue;
        if (x>0) sc += S>>2*x-2 & 3;
        if (x<4) sc += S>>2*x & 3;
        while(sc>4) sc -= 4;
        now += score[sc];
      }
      ans = max(ans, now);
    }
    cout << ans << endl;
  }
}

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


int binary_search(int N, int K, vector<int> &A) {
  double eps = 1e-6;
  double ng = 0, ok = 1e+9 + 1;

  while (ok - ng > eps) {
    double mid = (ok + ng) / 2;
    int n_cut = 0;
    for (int a: A) {
      n_cut += (int) ceil(a / mid) - 1;
    }
    if (n_cut <= K) {
      ok = mid;
    }
    else {
      ng = mid;
    }
  }
  return (int) ceil(ng);
}


int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int ans = binary_search(N, K, A);
  cout << ans << endl;
  return 0;
}

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

const int INF = 1e12;

signed main() {
    int n;
    cin >> n;

    vector<int> item;
    item.push_back(1);
    for(int i = 1;;i++){
        if(pow(6,i) > n) break;
        item.push_back(pow(6,i));
    }

    for(int i = 1;; i++){
        if(pow(9,i) > n) break;
        item.push_back(pow(9,i));
    }
    
    int m = item.size();
    vector<vector<int>> dp(m + 1, vector<int>(n + 1,INF));
    dp[0][n] = 0;
    for(int i = 0; i < m; i++){
        for(int j = n; j >= 0; j--){
            if(j - item[i] >= 0) dp[i][j - item[i]] = min(dp[i][j - item[i]], dp[i][j] + 1);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[m - 1][0] << endl;

}

Measured memory_bytes: 11264
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())

d = make_divisors(n)
# print(d)
ans = n
for i in d:
    ans = min(ans, n//i - 1 + i - 1)
print(ans)

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    ll ans = 0;
    rep(i,n){
        // cout << bi << endl;
        int bi = b[i];
        ll anum = distance(a.begin(), lower_bound(a.begin(), a.end(), bi));
        ll cnum = distance(upper_bound(c.begin(), c.end(), bi), c.end());
        ans += anum*cnum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
    ll h;
    cin >>h;
    
    int t=0;
    while(h){
        h /= 2LL;
        t++;
    }
    
    ll ans = 1;
    rep(i,t)ans *= 2;
    ans--;
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.math, std.typecons;
  
  int n; rd(n);
  auto a=new long[][](n, n);
  foreach(i; 0..n) a[i]=readln.split.to!(long[]);

  auto d=new long[][](n, n);
  const inf=to!long(1e18);
  foreach(i; 0..n)foreach(j; 0..n) d[i][j]=a[i][j];
  foreach(_; 0..n)foreach(i; 0..n)foreach(j; 0..n){
    d[i][j]=min(d[i][j], d[i][_]+d[_][j]);
  }
  foreach(i; 0..n)foreach(j; 0..n){
    if(d[i][j]<a[i][j]){
      writeln("-1"); return;
    }
  }
  auto edge=new Tuple!(long, int, int)[](0);
  foreach(i; 0..n)foreach(j; 0..i){
    edge~=tuple(a[i][j], i, j);
  }
  sort!("a[0]>b[0]")(edge);
  foreach(e; edge)foreach(k; 0..n){
    if(e[1]!=k && e[2]!=k && e[0]==a[e[1]][k]+a[k][e[2]]){
      a[e[1]][e[2]]=a[e[2]][e[1]]=inf;
    }
  }
  long sm=0;
  foreach(i; 0..n)foreach(j; 0..i){
    if(a[i][j]!=inf) sm+=a[i][j];
  }

  writeln(sm);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 7548
#include<stdio.h>
#include<limits.h>

int main(){
    long long int n;
    long long int vehicle[5];
    scanf("%lld %lld %lld %lld %lld %lld", &n, &vehicle[0], &vehicle[1], &vehicle[2], &vehicle[3], &vehicle[4]);
    long long int min = LLONG_MAX;
    for(int i=0; i<5; i++){
        if(min > vehicle[i]){
            min = vehicle[i];
        }
    }
    printf("%lld", (n + (min-1))/min + 4);

    return 0;
}

Measured memory_bytes: 128
/*
Vim: :pc -> close scratch window
How to lambda 
  ex) sort(begin(cont),end(cont),[](dat a,dat b) {return a.l<b.l;});
  XXX:lambda different from fun obj
lower_bound/upper_bound
  1 2 2 2 3 3
    ^lb   ^ub
*/
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORR(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>struct DPS{int a,b,c;vector<T> S;
DPS(int A,int B,int C,T s){a=A;b=B;c=C;S.resize(a*b*c,s);}
T& operator()(int A,int B,int C) {return S[A*b*c+B*c+C];}};
int N,M;
typedef pair<int,int> Pii;
ll MOD = 1000*1000*1000+7;
vector<ll> ftDat;
void add(int i,ll v) {
  while(i<ftDat.size()) {
    ftDat[i] += AS_MOD(v,MOD);
    MODDING(ftDat[i],MOD);
    i += i & -i;
  }
}
ll sum(int i) {
  ll ret=0;
  while(i>0) {
    ret += ftDat[i];
    MODDING(ret,MOD);
    i-=i& -i;
  }
  return ret;
}
int main(int argc, char **argv, char **envp) {
  cin >> N >> M;
  vector<int> xs;
  vector<int> ys;
  ftDat.resize(N+30);
  xs.resize(N);
  ys.resize(M);
  REP(i,N) {
    int x;
    scanf("%d", &x);
    xs[i]=x;
  }
  REP(i,M) {
    int y;
    scanf("%d", &y);
    ys[i]=y;
  }
  vector<Pii> Piis;
  vector<int> tB;
  Piis.reserve(N);
  tB.reserve(N);
  for(int i=0,j=1;i<N&&j<M;++j) {
    while(i<N&&xs[i]<ys[j-1])++i;
    while(i<N&&xs[i]<ys[j]) {
      tB.push_back(xs[i]);
      i++;
    }
    FOR(it,tB) {
      Piis.push_back(Pii(*it-ys[j-1],ys[j]-*it));
    }
    tB.clear();
  }
  {
    sort(ALL(Piis), [](Pii a,Pii b){return a.fi < b.fi;});
    int prev=-1,p=0;
    for(int i=0;i<Piis.size();++i){
      if (prev == Piis[i].fi) {
        Piis[i].fi=p;
      } else {
        prev = Piis[i].fi;
        Piis[i].fi=++p;
      }
    }
    prev=-1,p=0;
    sort(ALL(Piis), [](Pii a,Pii b){return a.se != b.se ? a.se < b.se : a.fi < b.fi;});
    for(int i=0;i<Piis.size();++i){
      if (prev == Piis[i].se) {
        Piis[i].se=p;
      } else {
        prev=Piis[i].se;
        Piis[i].se=++p;
      }
    }
  }
  vector<Pii> Piis2;
  Piis2.reserve(N);
  {
    FOR(it,Piis) {
      if (Piis2.empty() || *Piis2.rbegin() != *it) {
        Piis2.pb(*it);
      }
    }
  }
  vector<Pii> tP;
  vector<ll> tD;
  tP.reserve(N);
  tD.reserve(N);
  int prev=-1;
  add(1,1);
  for(int i=0;i<=Piis2.size();++i) {
    if (i < Piis2.size() && prev==Piis2[i].se) {
      tP.push_back(Piis2[i]);
    } else {
      FOR(it, tP) {
        tD.pb(sum(it->first));
      }
      for(int j=0;j<tP.size();++j) {
        add(tP[j].fi+1,tD[j]);
      }
      tD.clear();
      tP.clear();
      if (i<Piis2.size() ){
        prev = Piis2[i].se;
        tP.push_back(Piis2[i]);
      }
    }
  }


  cout << sum(N+10) << endl;
  return 0;
}


Measured memory_bytes: 3456
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

ll n,k,ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> k;
    for(int b=k+1;b<=n;b++){
        ll t=n/b;
        ans+=t*(b-k);
        if(n%b!=0){
            if(k) ans+=max(0ll,n%b-k+1);
            else ans+=max(0ll,n%b);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
sum = 0
for i in range(1, N+1):
	sum += L + i - 1
min = 5000000000000000
mintaste = 0
for i in range(1, N+1):
	taste = sum - (L+i-1)
	if abs(sum-taste) < min:
		min = abs(sum-taste)
		mintaste = taste
print(mintaste)

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
const int   N   = 1e5 + 5;
struct  poi {
    int X, Y, idx;
}   A;
vector<poi> P;
int n, R, C;
int check(int x,int y)  {
    if(x == 0)  return  1;
    if(y == 0)  return  2;
    if(x == R)  return  3;
    if(y == C)  return  4;
    return  0;
}
void input()    {
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if(check(x1,y1) && check(x2,y2))    {
        A.X = x1, A.Y = y1, A.idx = P.size();
        P.push_back(A);
        A.X = x2, A.Y = y2, A.idx = P.size() - 1;
        P.push_back(A);
    }
}
bool cmp(poi A,poi B)   {
    int a = check(A.X,A.Y);
    int b = check(B.X,B.Y);
    if(a != b)  return  a < b;
    if(a == 1)  return  A.Y > B.Y;
    if(a == 2)  return  A.X < B.X;
    if(a == 3)  return  A.Y < B.Y;
    return  A.X > B.X;
}
int main()  {
    cin >> R >> C >> n;
    while(n--)  input();
    sort(P.begin(),P.end(),cmp);
    stack<int>  st;
    for(int i = 0 ; i < P.size() ; ++i) {
        int x = P[i].idx;
        if(st.empty() || x != st.top())
            st.push(x);
        else    st.pop();
    }
    if(st.size())   cout << "NO";
    else            cout << "YES";
}

Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct mod_fac{
    private:
        vector<ll> f,i_f;
        int n;ll MOD;
    public:
        void init(int n,ll m){
            MOD=m;
            f.resize(n+1,0);
            i_f.resize(n+1,0);
            f[0]=1;
            rep(i,n){
                f[i+1]=f[i]*(i+1)%MOD;
            }
            i_f[n]=power(f[n],MOD-2);
            per(i,n){
                i_f[i]=(i_f[i+1]*(i+1))%MOD;
            }
        }

        ll power(ll a ,ll x){
            if (x==0) return 1;
            if (x==1) return a%MOD;
            if (x==2) return (a*a)%MOD;
            if (x%2==1) return (a*power(power(a,(x-1)/2),2))%MOD;
            if (x%2==0) return (power(power(a,x/2),2))%MOD;
        }

        ll fac(int x){
            return f[x];
        }

        ll invfac(int x){
            return i_f[x];
        }

        ll comb(int m,int k){
            if (m<0 or k<0) return 0;
            if (m<k) return 0;
            return (((f[m]*i_f[k])%MOD)*i_f[m-k])%MOD;
        }
};

int h,w,a,b;
ll ans=0;
int main(){
    cin >> h >> w >> a >> b;
    mod_fac m;m.init(h+w,mod);
    rep(k,h-a){
        ans+=m.comb(b+k-1,k)*m.comb(h-k+w-b-2,h-k-1);
        ans%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(value) value.begin(),value.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(value) cerr << #value << " is " << value << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
   
    //a.erase(unique(a.begin(),a.end()),a.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man =(int)2e6+2 ,inf =1e18;
    const int mod=1e9+7;

    long long binpow(int a,int b,int m)
    {   
        a %= m;int res = 1;
        while (b > 0)
        { 
            if (b & 1)res=(res*a)%m;
            a=(a*a)%m  ;    b/=2; 
        }
        return res;
    }
    int modinv(int n,int m)
    {
        return binpow(n,mod-2,m);
    }

/*......................................................................................................................*/


signed main()
{
    fast;
    int x,k,d;
    
    cin>>x>>k>>d;
    if(x<0)x=-x;
    if(x/d>k)
    {
        cout<<x-k*d<<endl;
    }
    else
    {
        int kk=x/d;
        if(kk%2==k%2)cout<<x-kk*d<<endl;
        else cout<<abs(x-(kk+1)*d)<<endl;
    }
    
}   



Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,m;
void Main(){   
    cin>>n;
    if(n<3){
        cout<<-1<<endl;
    }
    else if(n==3){
        cout<<"aa.\n..b\n..b\n";
    }
    else{
        m=n;
        char S[1000][1000];
        For(i,0,1000) For(j,0,1000) S[i][j]='.';
        while(n>7){
            S[n-4][n-4]='a';S[n-4][n-3]='a';S[n-4][n-2]='c';S[n-4][n-1]='d';
            S[n-3][n-4]='b';S[n-3][n-3]='b';S[n-3][n-2]='c';S[n-3][n-1]='d';
            S[n-2][n-4]='e';S[n-2][n-3]='f';S[n-2][n-2]='g';S[n-2][n-1]='g';
            S[n-1][n-4]='e';S[n-1][n-3]='f';S[n-1][n-2]='h';S[n-1][n-1]='h';
            n-=4;
        }
        if(n==4){
            S[0][0]='a';S[0][1]='a';S[0][2]='c';S[0][3]='d';
            S[1][0]='b';S[1][1]='b';S[1][2]='c';S[1][3]='d';
            S[2][0]='e';S[2][1]='f';S[2][2]='g';S[2][3]='g';
            S[3][0]='e';S[3][1]='f';S[3][2]='h';S[3][3]='h';
        }
        else if(n==5){
            S[0][0]='a';S[0][1]='a';S[0][2]='b';S[0][3]='b';S[0][4]='c';
            S[1][0]='h';S[1][1]='i';S[1][2]='i';S[1][3]='.';S[1][4]='c';
            S[2][0]='h';S[2][1]='.';S[2][2]='.';S[2][3]='j';S[2][4]='d';
            S[3][0]='g';S[3][1]='.';S[3][2]='.';S[3][3]='j';S[3][4]='d';
            S[4][0]='g';S[4][1]='f';S[4][2]='f';S[4][3]='e';S[4][4]='e';
        }
        else if(n==6){
            S[0][0]='a';S[0][1]='a';S[0][2]='b';S[0][3]='g';S[0][4]='g';S[0][5]='.';
            S[1][0]='d';S[1][1]='.';S[1][2]='b';S[1][3]='.';S[1][4]='.';S[1][5]='h';
            S[2][0]='d';S[2][1]='c';S[2][2]='c';S[2][3]='.';S[2][4]='.';S[2][5]='h';
            S[3][0]='e';S[3][1]='e';S[3][2]='.';S[3][3]='i';S[3][4]='i';S[3][5]='j';
            S[4][0]='.';S[4][1]='.';S[4][2]='f';S[4][3]='l';S[4][4]='.';S[4][5]='j';
            S[5][0]='.';S[5][1]='.';S[5][2]='f';S[5][3]='l';S[5][4]='k';S[5][5]='k';
        }
        else if(n==7){
            S[0][0]='a';S[0][1]='a';S[0][2]='b';S[0][3]='b';S[0][4]='c';S[0][5]='c';S[0][6]='.';
            S[1][0]='g';S[1][1]='g';S[1][2]='.';S[1][3]='i';S[1][4]='i';S[1][5]='.';S[1][6]='d';
            S[2][0]='.';S[2][1]='.';S[2][2]='h';S[2][3]='.';S[2][4]='.';S[2][5]='j';S[2][6]='d';
            S[3][0]='.';S[3][1]='.';S[3][2]='h';S[3][3]='.';S[3][4]='.';S[3][5]='j';S[3][6]='e';
            S[4][0]='k';S[4][1]='k';S[4][2]='.';S[4][3]='m';S[4][4]='m';S[4][5]='.';S[4][6]='e';
            S[5][0]='.';S[5][1]='.';S[5][2]='l';S[5][3]='.';S[5][4]='.';S[5][5]='n';S[5][6]='f';
            S[6][0]='.';S[6][1]='.';S[6][2]='l';S[6][3]='.';S[6][4]='.';S[6][5]='n';S[6][6]='f';
        }
        For(i,0,m){
            For(j,0,m){
                cout<<S[i][j];
            }
            cout<<endl;
        }
    }
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

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

  int e[2] = {4, 7};
  bool dp[MAX_N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j <= N; j++) {
      if (j % e[i] == 0 || (j - e[i] > 0 && dp[j - e[i]])) {
        dp[j] = true;
      }
    }
  }

  if (dp[N]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  // if ((N % 4 % 7) == 0 || (N % 7 % 4) == 0) {
  //   cout << "Yes" << endl;
  // }
  // else {
  //   cout << "No" << endl;
  // }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
int ed[200][220];

void solve(int l, int r, int tl, int tr) {
	int n = (r - l);
	if (n % 2 == 1) {
		for (int i = 1; i <= n - 1; ++i) {
			for (int j = 0; j < n; ++j)
				ed[l + j][tl - 1 + i] = l + (j + i) % n;
		}
		return;
	}
	if (n == 4) {
		ed[l][tl] = l + 1;
		ed[l][tl + 1] = l + 3;
		ed[l][tl + 2] = l + 2;
		ed[l + 1][tl] = l + 2;
		ed[l + 1][tl + 1] = l + 0;
		ed[l + 1][tl + 2] = l + 3;
		ed[l + 2][tl] = l + 0;
		ed[l + 2][tl + 1] = l + 1;
		ed[l + 2][tl + 2] = l + 3;
		ed[l + 3][tl] = l + 2;
		ed[l + 3][tl + 1] = l + 1;
		ed[l + 3][tl + 2] = l + 0;
		return;
	}
	int m = n / 2;
	solve(l, l + m, tl, tl + m - 1);
	solve(l + m, r, tl + m - 1, tr - 1);
	for (int i = 0; i < m - 1; ++i) {
		for (int j = 0; j < m; ++j)
			ed[l + m + j][tl + i] = l + (j + i) % m;
	}
	for (int i = 0; i < m - 1; ++i) {
		for (int j = 0; j < m; ++j)
			ed[l + j][tl + m - 1 + i] = l + m + (j + i + 1) % m;
	}
	for (int i = 0; i < m; ++i)
		ed[l + i][tr - 1] = l + m + i;
	for (int i = 0; i < m; ++i)
		ed[l + m + i][tr - 1] = l + (i + m - 1) % m;
}

int main() {
	int n;
	cin >> n;
	if (n == 2) {
		cout << -1 << "\n";
		return 0;
	}
	solve(0, n, 0, n - 1);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j)
			cout << ed[i][j] + 1 << " ";
		cout << "\n";
	}
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main() {
	int h, w, d, q, in1, in2;
	cin >> h >> w >> d;
	vi vh(h*w+1), vw(h*w+1);
	vi ans(h*w + 1);
	rep(i, h*w) {
		cin >> in1;
		vh[in1] = (i / w);
		vw[in1] = (i % w);
	}
	range(i,1,h*w-d+1) {
		ans[i + d] = ans[i] + abs(vh[i + d] - vh[i]) + abs(vw[i + d] - vw[i]);
	}
	cin >> q;
	rep(i,q) {
		cin >> in1 >> in2;
		cout << ans[in2]-ans[in1] << endl;
	}
}


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

int main() {
	string s,t;
  	cin>>s>>t;
  	vector<int> a(26,-1);
  	vector<int> b(26,-1);
  
  	for(int i=0;i<s.size();i++){
      	char ch1=s[i];
      	char ch2=t[i];
      	if(a[ch1-'a']==-1){
        	a[ch1-'a']=ch2-'a';
        }else if(a[ch1-'a']!= ch2-'a'){
        	cout<<"No"<<endl;
          	return 0;
        }
      	if(b[ch2-'a']==-1){
        	b[ch2-'a']=ch1-'a';
        }else if(b[ch2-'a']!= ch1-'a'){
        	cout<<"No"<<endl;
          	return 0;
        }
    }
  cout<<"Yes"<<endl;  
}


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

int main()
{
  int w, a, b;
  cin >> w >> a >> b;
  
  if (a+w >= b && b+w >= a) cout << 0 << endl;
  else if (a+w < b) cout << b-(a+w) << endl;
  else if (b+w < a) cout << a-(b+w) << endl;
}

Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0:
        break
    a = input()
    b = a.split()
  
    x = 0
    for i in range(N//2):
        if b[2 * i] == 'lu' and b[(2 * i)+1] == 'ru':
            x += 1
        if b[2 * i] == 'ru' and b[(2 * i)+1] == 'lu':
            x += 1
        if b[2 * i] == 'ld' and b[(2 * i)+1] == 'rd':
            x += 1
        if b[2 * i] == 'rd' and b[(2 * i)+1] == 'ld':
            x += 1
    print(x)


Measured memory_bytes: 5612
package main

import "fmt"

func main() {
	var a, b, x, r int
	fmt.Scan(&a, &b)
	x = a * b
	r = b % a

	for {
		if r == 0 {
			break
		}
		b = a
		a = r
		r = b % a
	}

	fmt.Println(x / a)
}


Measured memory_bytes: 512
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,w,h,x,y;
vpi wall;

signed main(){
    I(h); I(w); I(n);
    REP(i,n){
        I(x); I(y);
        x--; y--;
        wall.eb(x,y);
    }
    if (!n){
        cout << h << endl;
        return 0;
    }
    sort(all(wall));

    int ret = -1;
    int capable = 0;
    REPS(i,h){
        pi lp = mp(i,0);
        auto lit = *lower_bound(all(wall), lp);
        if (lit.first == i && lit.second <= capable){
            ret = i;
            break;
        }
        lp = mp(i,capable);
        lit = *lower_bound(all(wall), lp);
        capable += lit.first != i || lit.second != capable + 1;
    }
    if (ret < 0) ret = h;
    cout << ret << endl;
    
}

Measured memory_bytes: 6384
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	a, b := nextInt(), nextInt()

	fmt.Println(max(a-b*2, 0))
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}

func max(n, m int) int {
	if n >= m {
		return n
	}
	return m
}


Measured memory_bytes: 640
import sys
for l in sys.stdin:
 d=[{'o':1,'x':-1,'s':0}[s]for s in l.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print(['dx'[-3 in a],'o'][3 in a])


Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

int main(void){
    IOS;
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        int x; cin >> x;
        if (x&1 && i&1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> p(n);
	rep (i, q) {
	  int a;
	  cin >> a;
	  p[a - 1]++;
	}
	rep (i, n) {
	  if (k - q + p[i] <= 0) cout << "No" << endl;
	  else cout << "Yes" << endl;
	}
    
    return 0;
}



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

int main(){
  int n; cin >> n;
  vector<int> d;
  for(int i=0; i<n; i++){
    int a; cin >> a;
    d.push_back(a);
  }
  sort(d.begin(),d.end());
  
  cout << d[n/2]- d[n/2-1] << endl;
}

    

Measured memory_bytes: 892
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	double yen = 0, btc = 0;
	for (int i = 0; i < n; i++) {
		double x;
		string u;
		cin >> x >> u;

		if (u == "JPY") {
			yen += x;
		} else if (u == "BTC") {
			btc += x;
		}
	}

	yen += btc * 380000.0;
	printf("%.10lf\n", yen);
	return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
a=[]
while k>1:
    a.append(k)
    k/=2
a.append(k/2)
ans=0
c=0
b=n
while n>=1:
    if n>=a[c]:
        ans+=(2**(-c))*(1/b)
        n-=1
    else:
        c+=1
print(ans)


Measured memory_bytes: 65584