akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N + 1];
		int[] d = new int[N + 1];
		for (int i=1; i <= N; i++) {
			h[i] = in.nextInt();
			d[i] = INF;
		}
		d[1] = 0;
		d[2] = Math.abs(h[2] - h[1]);
		for(int i=3; i<=N; i++) {
			d[i] = Math.min(d[i-1] + Math.abs(h[i-1]-h[i]), d[i-2] + Math.abs(h[i-2]-h[i])); 
		}
		System.out.println(d[N]);
	}
}

Measured memory_bytes: 60132
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
struct node{int to,nxt;}sq[1001000];
int all,head[500500],d[500500];
int n,m,k,x[500500],y[500500],ord[500500],ans[500500],seg[2002000];
priority_queue<int,vector<int>,greater<int> > q;

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

void build(int id,int l,int r)
{
	seg[id]=maxd;
	if (l==r) return;
	int mid=(l+r)>>1;
	build(id<<1,l,mid);build(id<<1|1,mid+1,r);
}

void modify(int id,int l,int r,int pos,int val)
{
	if (l==r)
	{
		seg[id]=min(seg[id],val);
		return;
	}
	int mid=(l+r)>>1;
	if (pos<=mid) modify(id<<1,l,mid,pos,val);
	else modify(id<<1|1,mid+1,r,pos,val);
	seg[id]=min(seg[id<<1],seg[id<<1|1]);
}

int query(int id,int l,int r,int ql,int qr)
{
	if ((l>=ql) && (r<=qr)) return seg[id];
	int mid=(l+r)>>1,ans=maxd;
	if (ql<=mid) ans=min(ans,query(id<<1,l,mid,ql,qr));
	if (qr>mid) ans=min(ans,query(id<<1|1,mid+1,r,ql,qr));
	return ans;
}

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];d[v]++;head[u]=all;
}

void toposort()
{
	rep(i,1,n)
		if (!d[i]) q.push(i);
	int tot=0;
	while (!q.empty())
	{
		int u=q.top();q.pop();ord[++tot]=u;
		for (int i=head[u];i;i=sq[i].nxt)
		{
			int v=sq[i].to;d[v]--;
			if (!d[v]) q.push(v);
		}
	}
}

int main()
{
	n=read();k=read();
	rep(i,1,n) 
	{
		x[i]=read();
		y[x[i]]=i;
	}
	build(1,1,n);
	per(i,n,1)
	{
		int pos=query(1,1,n,max(1,y[i]-k+1),y[i]);
		if (pos<=n) add(y[i],y[pos]);
		pos=query(1,1,n,y[i],min(y[i]+k-1,n));
		if (pos<=n) add(y[i],y[pos]);
		modify(1,1,n,y[i],i);
	}
	toposort();
	rep(i,1,n) ans[ord[i]]=i;
	rep(i,1,n) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 30976
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  if((b-a)%2==0)cout<<"Alice"<<endl;
  else cout<<"Borys"<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
I = [[int(i) for i in input().split()] for j in range(N)]

current, time = (0, 0), 0
for i in range(N):
    dist = abs(current[0] - I[i][1]) + abs(current[1] - I[i][2])
    if dist > I[i][0] - time or (I[i][0]- time - dist) % 2 == 1:
        print("No")
        break
    current, time = (I[i][1], I[i][2]), I[i][0]
else:
    print("Yes")

Measured memory_bytes: 21108
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n, m;

struct Edge {
    int to, id;
    Edge(int to, int id): to(to), id(id) {}
};
V< V<Edge> > edges;

V<int> es;
bool dfs(int fr, int to, int par) {
    if (fr == to) return true;
    else {
        for (Edge e: edges[fr]) {
            if (e.to == par) continue;
            if (dfs(e.to, to, fr)) {
                es.emplace_back(e.id);
                return true;
            }
        }
        return false;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    edges.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(Edge(b, i));
        edges[b].emplace_back(Edge(a, i));
    }

    cin >> m;
    vll cst(m, 0);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        es.clear();
        dfs(a, b, -1);
        for (int j = 0; j < es.size(); j++) cst[i] ^= (1LL << es[j]);
    }

    ll ans = 1LL << (n - 1);
    for (int state = 1; state < (1 << m); state++) {
        ll tmp = 0;
        for (int i = 0; i < m; i++) if ((state >> i) & 1) tmp |= cst[i];
        int white = __builtin_popcountll(tmp);
        if (__builtin_popcount(state) & 1) ans -= 1LL << (n - 1 - white);
        else ans += 1LL << (n - 1 - white);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
// #define MOD 1000000007
#define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
} 


void solve(void)
{
  int n;cin>>n;
  int res = 0;
  for (int i = 1; i <= n; i++)
  {
    if(i%2 ==0 )continue;

    if(divisor(i).size() == 8)
    {
      res++;
    }
  }
  cout<<res<<endl;
  
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

bool palin(const int x) {
    int r = 0;
    int t = x;
    while(t) {
        r = r * 10 + t % 10;
        t /= 10;
    }
    return r==x;
}

int main() {
    int a, b;
    cin >> a >> b;
    int ct = 0;
    for(int x=a; x<=b; x++) {
        if(palin(x)) ct++;
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(lambda x: int(x), input().split()))

d = []

for i in range(1, n):
    if h[i-1] >= h[i]:
        d.append(1)
    else:
        d.append(0)

max_len = 0
cur_len = 0

for i in range(len(d)):
    if d[i] == 0:
        cur_len = 0
    else:
        cur_len += 1
    max_len = max(max_len, cur_len)

print(max_len)

Measured memory_bytes: 15020
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())

x = a + e == b + d and b + f == c + e and d + h == e + g and e + i == f + h
print('YNeos'[0 if x else 1::2])


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N, M = map(int, input().split())
a = []
b = []
c = []
d = []

for i in range(N):
    a_v, b_v = map(int, input().split())
    a.append(a_v)
    b.append(b_v)

for i in range(M):
    c_v, d_v = map(int, input().split())
    c.append(c_v)
    d.append(d_v)

for i in range(N):
    res_id = 0
    res = 10000000000
    for j in range(M):
        j_res = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if j_res < res:
            res_id = j
            res = j_res
    print(res_id + 1)


Measured memory_bytes: 4564
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    static long[] dp;

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        dp = new long[1 << n];
        int[][] w = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                w[i][j] = in.nextInt();
            }
        }

        long[] costMask = new long[1 << n];
        for (int mask = 0; mask < (1 << n); mask++) {
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (((mask & (1 << i)) != 0) && ((mask & (1 << j)) != 0)) {
                        costMask[mask] += w[i][j];
                    }
                }
            }
        }

        Arrays.fill(dp, Long.MIN_VALUE / 2);
        dp[0] = 0;
        for (int mask = 0; mask < (1 << n); mask++) {
            int antiMask = ((1 << n) - 1) ^ mask;
            solve(mask, antiMask, costMask);
        }
        out.println(dp[(1 << n) - 1]);
        out.close();
    }

    private static void solve(int mask, int antiMask, long[] costMask) {
        for (int x = antiMask; ; x = x - 1 & antiMask) {
            dp[mask ^ x] = Math.max(dp[mask ^ x], dp[mask] + costMask[x]);
            if (x == 0) break;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A<10 && B<10) {
			System.out.println(A*B);
		} else {
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(void) {
	int cnt = 0, H[10000], W[10000];
	int i, j, k;
	
	do{
		scanf("%d %d", &H[cnt], &W[cnt]);
		cnt++;
	} while(H[cnt-1] != 0 && W[cnt-1] != 0);
	
	for(i = 0; i < cnt-1; i++) {
		for(j = 0; j < H[i]; j++){
			for(k = 0; k < W[i]; k++) {
				if(j== 0 || j==H[i]-1) {
					printf("#");
				} else if(k==0 || k==W[i]-1) {
					printf("#");
				} else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

struct edge
{
	int from;
	int to;
	i64 cost;
};

vector<edge> edges;

int n;
int m;

int main()
{
	cin >> n >> m;
	for(int i = 0;i < m;i++)
	{
		int a,b;
		i64 c;
		cin >> a >> b >> c;
		edges.push_back({a,b,-c});
	}

	vector<i64> dist(n + 1, (1LL << 60));
	dist[1] = 0;

	for(int c = 0;c < n - 1;c++)
	{
		for(auto& e : edges)
		{
			dist[e.to] = min(dist[e.to],dist[e.from] + e.cost);
		}
	}

	vector<bool> negative(n + 1,false);

	for(int c = 0;c <= n;c++)
	{
		for(auto& e : edges)
		{
			if(dist[e.to] > dist[e.from] + e.cost)
			{
				dist[e.to] = dist[e.from] + e.cost;
				negative[e.to] = true;
			}
			if(negative[e.from])
			{
				negative[e.to] = true;
			}
		}
	}

	if(negative[n])
	{
		cout << "inf" << endl;
	}
	else
	{
		cout << -dist[n] << endl;
	}
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll x,y;
    Scll2(x,y);
    int cnt = 0;

    while(x <= y){
        cnt++;
        x *= 2;
    }

    printf ("%d\n", cnt);

    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MOD=1e6+3;
ll Q,fact[MOD],ifact[MOD];
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if(m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>Q;
	fact[0]=1;
	REP(i,MOD-1){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	ifact[MOD-1]=minv(fact[MOD-1]);
	for(ll i=MOD-2;i>=0;i--){
		ifact[i]=ifact[i+1]*(i+1)%MOD;
	}
	REP(q,Q){
		ll x,d,n;
		cin>>x>>d>>n;
		if(d==0){
			cout<<mpw(x,n)<<endl;
		}else if(n>=MOD){
			cout<<0<<endl;
		}else{
			x*=minv(d);
			x%=MOD;
			ll ans;
			if(x+n-1>=MOD){
				ans=0;
			}else if(x==0){
				ans=0;
			}else{
				ans=fact[x+n-1]*ifact[x-1]%MOD;
			}
			ans*=mpw(d,n);
			ans%=MOD;
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 16512
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	multiset<int> s1,s2;
	int n;
	cin >> n;
	pp a[n];
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin >> x >> y;
		a[i] = {x,y};
		s1.insert({x+y});
		s2.insert({x-y});
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		int tmp = a[i].ff+a[i].ss;
		ans=max(ans,tmp-*s1.begin());
		tmp = a[i].ff-a[i].ss;
		ans = max(ans,tmp-*s2.begin());		
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 25484
import math
import sys
ans=float(0)
a, b, x =map(float, input().split())

if x==a*a*b:
    ans=0

    ans=math.degrees(ans)

    print('{:.7f}'.format(ans))
    sys.exit()
c=(2*x/a/a)-b
if c > 0:
    ans=math.atan(a/(b-c))

else:
    ans=math.atan(2*x/a/b/b)
ans=math.degrees(ans)
ans=90-ans
print('{:.7f}'.format(ans))


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


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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;


    ll result = 0;

    result = a*c;
    result = max(result, b*d);
    result = max(result, a*d);
    result = max(result, b*c);


    std::cout << result << "\n";


	return 0;
}

Measured memory_bytes: 3644
N = int(input())
a = [int(x) for x in input().split()]

cumsum = [0] * N
cumsum[0] = a[0]
for i in range(1, N):
    cumsum[i] = cumsum[i-1] + a[i]

dp = [[0] * N for _ in range(N)]

for j in range(1, N):
    for i in range(N-1):
        if i + j >= N:
            break
        minimum = float('inf')
        for k in range(j):
            #print('i:',i,' j:',j,' k:',k,' i+k:',i+k,' j-k:',j-k)
            temp = dp[i][k] + dp[i+k+1][j-k-1]
            if minimum > temp:
                minimum = temp
        dp[i][j] = minimum + (cumsum[i+j] - cumsum[i-1] if i > 0 else cumsum[i+j])

print(dp[0][N-1])

Measured memory_bytes: 43740
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
    char line[128];
    char sp[] = " ";
    char *tok;
    int a, b, c, d, e, f;
    double x, y;

    while(gets(line) != NULL)
    {
        tok = (char*)strtok(line, sp);
        a = atoi(tok);
        tok = (char*)strtok(NULL, sp);
        b = atoi(tok);
        tok = (char*)strtok(NULL, sp);
        c = atoi(tok);
        tok = (char*)strtok(NULL, sp);
        d = atoi(tok);
        tok = (char*)strtok(NULL, sp);
        e = atoi(tok);
        tok = (char*)strtok(NULL, sp);
        f = atoi(tok);

        /* dx + bd/a y = cd/a
         * dx + ey     = f
         *
         * (e - bd/a)y = f - cd/a
         * y = (af - cd)/(ae - bd)
         *
         * x = c/a - b/a y
         */

         y = (1.0*a*f - 1.0*c*d)/(1.0*a*e - 1.0*b*d);
         x = 1.0*c/a - 1.0*b/a*y;

         printf("%.3f %.3f\n", x, y);
         
    }
    return 0;
}

Measured memory_bytes: 572
use proconio::input;

fn main() {
    input! {
        h: usize,
        w: usize,
        mut a: [[u8; w]; h],
    };
    let mut o = vec![];
    for i in 0..h {
        for j in 0..w {
            if a[i][j] % 2 != 0 {
                if j + 1 < w && a[i][j + 1] % 2 != 0 {
                    a[i][j] -= 1;
                    a[i][j + 1] += 1;
                    o.push((i, j, i, j + 1));
                } else if i + 1 < h && a[i + 1][j] % 2 != 0 {
                    a[i][j] -= 1;
                    a[i + 1][j] += 1;
                    o.push((i, j, i + 1, j));
                } else {
                    if j + 1 < w {
                        a[i][j] -= 1;
                        a[i][j + 1] += 1;
                        o.push((i, j, i, j + 1));
                    } else if i + 1 < h {
                        a[i][j] -= 1;
                        a[i + 1][j] += 1;
                        o.push((i, j, i + 1, j));
                    }
                }
            }
        }
    }
    println!("{}", o.len());
    for (y_i, x_i, y_j, x_j) in o.iter() {
        println!("{} {} {} {}", y_i + 1, x_i + 1, y_j + 1, x_j + 1);
    }
}


Measured memory_bytes: 7008
use proconio::input;

fn main() {
    input! {
        mut n: i64,
    }

    if n == 0 {
        println!("0");
        return;
    }

    let mut ans = vec![];

    while n != 0 {
        let mut temp = - n / 2;
        if n % 2 == 0 {
            ans.push('0');
        } else {
            ans.push('1');
            if n < 0 {
                temp += 1;
            }
        }
        n = temp;
    }

    let ans = ans.into_iter().rev().collect::<String>();

    println!("{}", ans);

}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
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 pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,x[110];
signed main(){
  int ans = INF;
  cin>>n;rep(i,n)cin>>x[i];
  repd(i,1,101){
    int sum = 0;
    rep(j,n)sum += (x[j]-i)*(x[j]-i);
    chmin(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
a,b,k=map(int,input().split())
l=[]

for i in range(1,(min(a,b))+1):
	if a%i==0 and b%i==0:
		l.append(i)
l.sort(reverse=True)
if a==1 or b==1:
    l=[1,1]
print(l[k-1])


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
char P[1000005],str[1000005];
int main(){
    int n,f=1;
    for(int i=0;i<1000000;i++){
        if(f==1)P[i]='I';
        else P[i]='O';
        f*=-1;
    }
    while(cin>>n,n){
        int len;
        cin>>len;
        cin>>str;
        int cnt=0;
        for(int i=0;i<len;i++){
            if(i+1+2*n>len)break;
            if(!strncmp(str+i,P,n*2+1))cnt++;
        }
        cout<<cnt<<endl;
    }


}

Measured memory_bytes: 3124
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimize("02")
using namespace std;
const int maxn=1e5+5;
long double n,ans;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	cout<<fixed<<setprecision(12);
	ans=n/3;
	cout<<ans*ans*ans;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

def func(fr, to, ignore):
    debug(fr, to, ignore)
    if fr == to:
        return 0
    res = c[fr][to]
    for md in range(10):
        if md in ignore:
            continue
        nignore = deepcopy(ignore)
        nignore.append(md)
        if tmp[fr][md] < inf:
            fr_md = tmp[fr][md]
        else:
            fr_md = func(fr, md, nignore)
        if tmp[md][to] < inf:
            md_to = tmp[md][to]
        else:
            md_to = func(md, to, nignore)
        debug(fr, md, to, fr_md, md_to)
        res = min(res, fr_md + md_to)
    tmp[fr][to] = res
    return res

h, w = MAP()
c = [LIST() for _ in range(10)]
a = [LIST() for _ in range(h)]

d = [[inf for _ in range(10)] for _ in range(10)]
tmp = [[inf for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j in range(10):
        debug('a', i, j)
        d[i][j] = func(i, j, [i, j])
for i in range(10):
    debug(d[i])
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == -1:
            continue
        ans += d[a[i][j]][1]
        debug(d[a[i][j]][1])
print(ans)

Measured memory_bytes: 65620
from sys import stdin

def func(n):
    if n % 2:
        ret = 3 * n + 1
    else:
        ret = n // 2
    return ret

def main():
    S = int(input())

    if S in (1, 2, 4):
        print(4)
    else:
        prev = S
        i = 2
        while 1:
            n = func(prev)
            if n == 4:
                print(i + 3)
                break
            prev = n
            i += 1

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3060
#include <atcoder/dsu>
#include <iostream>

using namespace std;
using namespace atcoder;

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  dsu D(n);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      D.merge(u, v);
    else
      cout << int(D.same(u, v)) << '\n';
  }
  return 0;
}

Measured memory_bytes: 3880
def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    B = [0] * (N + 1)
    for i in range(N,0,-1):
        B[i] = A[i]
        j = 2
        while i * j < (N + 1):
            B[i] ^= B[i * j]
            j += 1

    ans = []
    for i in range(1,N+1):
        if B[i] == 1:
            ans.append(i)
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()

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

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);

    int s;
    cin >> s;
    int a = s / 100, b = s % 100;
    if(a >= 1 && a<= 12) a = 1; else a = 0;
    if(b >= 1 && b<= 12) b = 1; else b = 0;
    if(a && b) cout << "AMBIGUOUS" << endl;
    if(a && !b) cout << "MMYY" << endl;
    if(!a && b) cout << "YYMM" << endl;
    if(!a && !b) cout << "NA" << endl;


    return 0;
}

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

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

    if(d != 0)cout << setprecision(10) << fixed << 2.0 * ( n - d ) * (m - 1) / pow(n, 2) << endl;
    else cout << setprecision(10) << fixed <<  n * (m - 1) / pow(n, 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
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;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

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

int main(){
  ll N;
  IN(N);
  vll B(N-1);
  REP(i,N-1) IN(B[i]);
  vll A(N, INFLL);
  REP(i,N-1){
    A[i] = min(A[i], B[i]);
    A[i+1] = min(A[i+1], B[i]);
  }
  ll ans = 0;
  REP(i,N) ans += A[i];
  OUT(ans);

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# 二分木
import bisect

n = int(input())
a = []

for _ in range(n):
    ai = int(input()) * -1
    i = bisect.bisect_right(a,ai)
    if(i==len(a)):
        a.append(ai)
    else:
        a[i] = ai

print(len(a))

Measured memory_bytes: 7072
N,M,X = list(map(int,input().split()))
books = [list(map(int,input().split())) for i in range(N)]

ans = float('inf')
for i in range(2**N):
    rikai = [0]*M
    onedan = 0
    for j in range(N):
        if (i>>j) & 1:
            onedan += books[j][0]
            for k in range(1,M+1):
                rikai[k-1] += books[j][k]
    for r in rikai:
        if r < X:
            break
    else:
        ans = min(ans,onedan)

if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9220
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <deque>
#include <queue>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct Pair
{
    int I;
    int U;
};
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (a[a[i] - 1] == i + 1)
        {
            count++;
        }
    }
    cout << count / 2 << endl;
    return 0;
}

Measured memory_bytes: 892
import numpy as np
import sys 

N, M = map(int, input().split())
AB = np.array(sys.stdin.read().split(), np.int64)
A = AB[::2]
B = AB[1::2]
E = np.zeros([N+1, N+1], np.int64)

np.add.at(E,(A,B),1)
np.add.at(E,(B,A),1)

def dfs(E):
	flg = np.zeros(1+N)
	flg[0] = 0
	q = [1]

	while q:
		cp = q.pop()
		flg[cp] = 1

		for n in range(1,N+1):
			if flg[n] == 0 and E[cp][n] == 1:
				flg[n] = 1
				q.append(n)

	if flg.sum() == N:
		return 0
	else:
		return 1

ans = 0
for i in range(1,N+1):
	for j in range(i+1,N+1):
		if E[i,j] == 0:
			continue

		E[i,j] = 0
		E[j,i] = 0

		ans += dfs(E)

		E[i,j] = 1
		E[j,i] = 1

print(ans)

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout << #x << "=" << x << endl
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}

int main()
{
    //open();
    int a,b,c,d,e,f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);

    a*=100;
    b*=100;
    set<int> set1;
    for(int i=0;;i++){
        if(i*a>f) break;
        for(int j=0;;j++){
            int tmp = i*a+j*b;
            //if(!tmp) continue;
            if(tmp>f) break;
            set1.insert(tmp);
        }
    }

    set<int> set2;
    for(int i=0;;i++){
        if(i*c>f) break;
        for(int j=0;;j++){
            int tmp = i*c+j*d;
            //if(!tmp) continue;
            if(tmp>f) break;
            set2.insert(tmp);
        }
    }

    //cout<<set1.size()<<' '<<set2.size()<<endl;
    double maxx = 0;
    int ans1 = a , ans2 = 0;
    set<int>::iterator it1,it2;
    for(it1=set1.begin();it1!=set1.end();it1++)
    {
        for(it2=set2.begin();it2!=set2.end();it2++)
        {
            int num1 = *it1,num2 = *it2;

            int sum = num1+num2;
            if(sum>f) break;
            if(e*sum<(100+e)*num2) break;
            //de(sum);
            double buf = 1.0*num2/sum;
            if(buf>maxx){
                ans1=sum;
                ans2=num2;
                maxx=buf;
            }
        }
    }
    printf("%d %d\n",ans1,ans2);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ll n,res=0;
    cin >> n;

    FOR(i,1,n+1){
        if((i%3==0) || (i%5==0)){
            res += 0;
        }else{
            res += i;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    int n;
    cin>>n>>s;
    for(int i=0;i<s.length();i++){
        int a=s[i]-'A';
        a+=n;
        a%=26;
        s[i]=a+'A';
    }
    cout<<s<<endl;
    return 0;
    }


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int gcd(int x,int y){
        if (x<y)gcd(y,x);
        if (x%y==0)return y;
        return gcd(y,x%y);
    }
	public static void main(String[] args)  {
         Scanner scan =new Scanner(System.in);

         int n=Integer.parseInt(scan.next());
         int[] x = new int [n+1];
         for(int i = 0; i < n+1; ++i){
             x[i] = Integer.parseInt(scan.next());
         }
         Arrays.sort(x);
         int ans=x[1]-x[0];
         for (int i=0;i<n;++i){
             ans=gcd(ans,x[i+1]-x[i]);
         }
         System.out.print(ans);


}
}
//end

Measured memory_bytes: 47372
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    string s;
    scan(s);
    yes(check(s));
}

bool check(string s) {
    return s[2] == s[3] && s[4] == s[5];
}

unittest {
    assert(check("coffee"));
    assert(!check("iphone"));
    assert(check("sippuu"));
}


void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string s;
    while(cin >> s, s[0] != '0'){
        int l = 0, r = 0;
        int i = 1;
        if(s[0] == '0') break;
        while(s[i]){
            if(s[i++] == 'A') l++;
            else r++;
        }
        if(l > r) l++;
        else r++;
        cout << l << ' ' << r << endl;
    }
}

Measured memory_bytes: 1180
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;

#[fastout]
fn main() {
  input! {
    h: usize,
    w: usize,
    mut vals: [[usize;w];h]
  }
  
  let mut result: Vec<(usize, usize, usize, usize)> = vec![];
  
  for r in 0..h-1 {
    for c in 0..w {
      if vals[r][c] % 2 == 1 {
        vals[r][c] -= 1;
        vals[r+1][c] += 1;
        result.push((r+1, c+1, r+2, c+1));
      }
    }
  }

  let r = h-1;
  for c in 0..w-1 {
    if vals[r][c] % 2 == 1 {
      vals[r][c] -= 1;
      vals[r][c+1] += 1;
      result.push((r+1, c+1, r+1, c+2));
    }
  }
  
  println!("{}", result.len());
  for (r, c, nr, nc) in result {
    println!("{} {} {} {}", r, c, nr, nc);
  }
}

Measured memory_bytes: 8760
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <bits/stdc++.h>
#include <complex>
#include <numeric>
#include <climits>
#include <stack>
#include <clocale>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <ctime>
#include <deque>
#include <queue>
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define rept(i,n)for(int i=0;i<(int)(n);i++)
#define fi first
#define se second
using namespace std;
int n;
string r;
int main(){
	cin>>n;
	cin>>r;
	int q;
	cin>>q;
	while(q--)
	{
		int k;
		cin>>k;
		long long ret=0;
		ll dm=0;
		int d=0;
		int m=0;
		for(int i=0;i<n;i++)
		{
			if(r[i]=='C')ret+=dm;
			else if(r[i]=='D')d++;
			else if(r[i]=='M'){
				dm+=d;
				m++;
			}
			if(i>=k-1)
			{
				int p=i-k+1;
				if(r[p]=='D')
				{
					dm-=m;
					d--;
				}
				else if(r[p]=='M')m--;
			}		
		}
	    cout<<ret<<endl;
	}
	return 0;
}


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

int main(void){
  int N, D;
  cin >> N >> D;
  vector<int> X(N * D);
  for(int i = 0; i < N * D; i++){
    cin >> X[i];
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      int sum = 0;
      for(int k = 0; k < D; k++){
        sum += pow((X[D * i + k] - X[D * j + k]), 2);
      }
     float dist =  pow((float)sum, 0.5);
      if(floor(dist) == dist) count++;
    }
  }
  cout << count;
 return 0; 
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> div = divisor(N);
    ll mi = INF;
    rep(i, div.size()) {
        ll tmp = div[i] + (N / div[i]) - 2;
        mi = min(mi, tmp);
    }
    print(mi);
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		int x, y, z;
		int count = 0;

		for(x=0;x<=k;x++){
			for(y=0;y<=k;y++){
				if(x+y<=s && s-x-y<=k)count++;
			}
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 9684
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll dif = abs(a - b);
    for(ll i = 0; i <= n - 1; i++){
        ll lar = d * i - c * (n - 1 - i);
        if(lar >= dif && lar - dif <= (d - c) * (n - 1)){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    map<string, int> data;
    int N; cin >> N;
    F0R(i, N) {
        string S; cin >> S;
        data[S]++;
    }

    int best = 0;
    vector<string> V;
    for (auto it = data.begin(); it != data.end(); it++) {
        if (it->s > best) {
            best = it->s; V.clear();
        }
        if (it->s == best) {
            V.pb(it->f);
        }
    }
    sort(all(V));

    F0R(i, sz(V)) {
        cout << V[i] << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main() {
  int N,K,A=0;
  cin >> N >> K;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(2*x<K)
      A+=x;
    else
      A+=K-x;
  }
  cout << 2*A << endl;
}

Measured memory_bytes: 256
//                                                   ¯\_(ツ)_/¯               
  //#pragma GCC optimize("Ofast")												 
 //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")  
//#pragma GCC optimize("unroll-loops")                                             
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=1e6+5,MOD=998244353;
 
using namespace std;

string str;
int ans;
int main() {

		cin>>str;

		stack<char>s;

		for(auto x : str){

			 if(!s.empty() && s.top() !=x  )s.pop(),ans+=2;
			 else s.push(x);
		}

		printf("%d\n",ans );	
	
}

Measured memory_bytes: 512
#include <iostream>
#include<vector>
using namespace std;
int main(void){
  int N,answer;
  std::cin >> N;
  vector<int> height(N);
  for (int i = 0; i < N; i++)
  {
      cin>>height[i];
  }
  int max=height[0];
  answer=1;
  for (int i = 1; i < N; i++)
  {
      if (max<= height[i])
      {
          max=height[i];
          answer++;
      }
      
  }
  cout<<answer<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ARC065_D___連結
{
    class Program
    {
        static void Main(string[] args)
        {
            var NKL = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NKL[0]; var K = NKL[1]; var L = NKL[2];

            var connectingRoad = new UnionFind(N);
            for (int i = 0; i < K; i++)
            {
                var pq = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                connectingRoad.unite(pq[0], pq[1]);
            }

            var connectingTrain = new UnionFind(N);
            for (int i = 0; i < L; i++)
            {
                var rs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                connectingTrain.unite(rs[0], rs[1]);
            }

            var sameRootCount = new Dictionary<long, int>();
            for (int i = 1; i < N + 1; i++)
            {
                long root = (long)connectingRoad.root(i) + (long)connectingTrain.root(i) * 1000000;
                if (sameRootCount.ContainsKey(root)) sameRootCount[root]++;
                else sameRootCount.Add(root, 1);
            }

            var result = new int[N];
            for (int i = 0; i < N; i++) result[i] = sameRootCount[(long)connectingRoad.root(i + 1) + (long)connectingTrain.root(i + 1) * 1000000];

            Console.WriteLine(String.Join(" ", result));
        }
    }
    public class UnionFind
    {
        private int[] parents;
        // 同じ根に属する枝の数を格納する
        private int[] rootCount;

        public int RootCount(int branch)
        {
            return rootCount[root(branch)];
        }

        public UnionFind(int count)
        {
            parents = new int[count + 1];
            rootCount = new int[count + 1];
            for (int i = 0; i < count + 1; i++)
            {
                parents[i] = i;
                rootCount[i] = 1;
            }
        }

        public int root(int N)
        {
            if (parents[N] == N) return N;
            return parents[N] = root(parents[N]);
        }

        //木を併合する際に、枝の数も合算する
        public void unite(int X, int Y)
        {
            int rootX = root(X);
            int rootY = root(Y);
            if (rootX == rootY) return;
            rootCount[rootX] += rootCount[rootY];
            parents[rootY] = rootX;
        }

        public bool sameRoot(int X, int Y)
        {
            return root(X) == root(Y);
        }
    }
}


Measured memory_bytes: 35240
#include <stdio.h>
int main(void)
{
    int a[5], k, i, max=-1, min=1000;
    for(i=0;i<5;i++){
        scanf("%d", &a[i]);
    }
    scanf("%d", &k);
    for(i=0;i<5;i++){
        if(max<a[i]) max=a[i];
        if(min>a[i]) min=a[i];
    }
    if(max-min<=k) printf("Yay!\n");
    else printf(":(\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

// ARC 80-C
// http://arc080.contest.atcoder.jp/tasks/arc080_a

public class Main {
	
	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int num4 = 0;
		int num2 = 0;
		
		for (int i = 0; i < N; i++) {
			int n = in.nextInt();
			if (n % 4 == 0) {
				num4++;
			} else if (n % 2 == 0) {
				num2++;
			}
		}
		
		String answer = "No";
		
		if (num4 >= N / 2) {
			answer = "Yes";
		} else {
			int remain = N - num4 * 2;
			if (remain <= num2) {
				answer = "Yes";
			}
		}
		
		System.out.println(answer);
	}
}


Measured memory_bytes: 48496
# coding: utf-8
import math
n, k, s = map(int,input().split())
#T = list(map(int,input().split()))
A = [str(s)] * k
if s==10**9:
    A += [str(s-1)] * (n-k)
else:
    A += [str(s+1)] * (n-k)
    
print(' '.join(A))

Measured memory_bytes: 65792