akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define dbg(x) cerr << #x << ":" << x << " "
#define dbgl(x) cerr << #x << ":" << x << "\n"
#define dbgv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int cc(vi a) {
	int res = 0, max_h = 0;
	for (int ai : a) {
		if (max_h < ai) {
			res++;
			max_h = ai;
		}		
	}
	return res;
}

int main () {
	int N, K; cin >> N >> K;
	vi a(N); rep(i, N) cin >> a.at(i);
	ll ans = 1000000000LL * 15;
	rep(k, 1 << N) {		
		int x = k; vi b = a;
		ll temp = 0;
		int max_h = 0;
		rep(t, N) {			
			if (x & 1) {				
				if (max_h >= b.at(t)) {
					temp += max_h + 1 - b.at(t);
					b.at(t) = max_h + 1;
					max_h++;
				} else max_h = b.at(t);
			}
			x >>= 1;
		}
		if (cc(b) >= K) ans = min(ans, temp);
	}				
	cout << ans << endl;
}

Measured memory_bytes: 256
k, n = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
a.append(k + a[0])
tmp = 0
maxi = 0
end = 0
for i, aa in enumerate(a):
    l = aa - tmp
    if l > maxi:
        maxi = l
        end = i
    tmp = aa
print(k - (a[end] - a[end - 1]))

Measured memory_bytes: 26436
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	ll n;
	cin >> n;
	double a = sqrt(n);
	ll b = a;
	int M = 1e8;
	for(ll i = 1; i <= b; i++){
		if(n%i == 0){
			ll s1 = i;
			ll s2 = n/i;
			int c1= 1;
			int c2 = 1;
			while(s1 >= 10){
				s1 /= 10;
				c1++;
			}
			while(s2 >= 10){
				s2 /= 10;
				c2++;
			}
			M = min(M, max(c1, c2));
		}
	}
	cout << M  << endl;
}


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

int main()
{
	int n;
	cin >>n;
	int dp[3]={0,0,0};
	int ac[3];
	for (int day = 0; day < n; ++day)
	{
		cin >> ac[0] >>ac[1] >>ac[2] ;
		int temp[3]={0,0,0};
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(i!=j)
				{
					temp[i] = max(temp[i],dp[j]+ac[i]);
				}
			}
		}
		dp[0]=temp[0];
		dp[1]=temp[1];
		dp[2]=temp[2];
	}
	cout << *max_element(dp,dp+3) ;

	return 0;
}

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

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

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 200*1000+10;
const ll inf = 1000000000000000000;
ll dp[maxn][2];
int a[maxn], n;

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		dp[i][0] = dp[i][1] = -inf;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[1][0] = 0;
	dp[1][1] = a[0];
	for (int i = 2; i <= n; i++)
	{
		if (i & 1)
		{
			dp[i][0] = max(dp[i - 1][0], a[i - 1] + dp[i - 2][0]);
			dp[i][1] = a[i - 1] + dp[i - 2][1];
		}
		else
			dp[i][0] = max(dp[i - 1][1], a[i - 1] + dp[i - 2][0]);
	}
	cout << dp[n][0];
	return 0;
}


Measured memory_bytes: 7560
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    int n;
    cin >> n;
    ll s=0,su=0;
    vector<ll> a(n),b(n+1),c(n+1);
    priority_queue<ll> qq;
    priority_queue<ll,vector<ll>,greater<ll>> q;
    rep(i,n){
        ll f;
        cin >> f;
        s+=f;
        q.push(f);
    }
    rep(i,n){
        ll f;
        cin >> f;
        a.at(i)=f;
    }
    rep(i,n){
        ll f;
        cin >> f;
        su+=f;
        qq.push(f);
    }
    b.at(0)=s;c.at(n)=su;
    rep(i,n){
        q.push(a.at(i));
        s+=a.at(i);
        s-=q.top();
        q.pop();
        b.at(i+1)=s;
    }
    rep(i,n){
        qq.push(a.at(n-i-1));
        su+=a.at(n-i-1);
        su-=qq.top();
        qq.pop();
        c.at(n-i-1)=su;
    }
    ll ans=-INF;
    rep(i,n+1){
        ans=max(ans,b.at(i)-c.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  int n; cin >> n;
  int c[n], s[n], f[n], ans[n+1];
  for(int i=1; i<n; i++){
    cin >> c[i] >> s[i] >> f[i];
  }

  for(int i=1; i<=n; i++) ans[i]=0;
  for(int i=1; i<=n; i++){
    for(int j=i; j<n; j++){
      if(ans[i]>=s[j]) ans[i]=f[j]*ceil((float)ans[i]/f[j]);
      else ans[i]=s[j];
      ans[i]+=c[j];
    }
  }
  for(int i=1; i<=n; i++) cout << ans[i] << endl;

  return 0;

}


Measured memory_bytes: 256
n=int(input())
cnt=[0]*(n+1)
a=list(map(int,input().split()))
for i in range(n):
  cnt[a[i]]+=1 
ans=0  
for i in range(1,n+1):
  if cnt[i]>=1:
    ans+=cnt[i]*(cnt[i]-1)//2
for i in range(n):
  print(ans-cnt[a[i]]+1)
  

Measured memory_bytes: 33876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
char c;
string tmp,s[1000];
vector<string>s1,s2;
void END(){
  cout<<"no"<<endl;
  exit(0);
}
int main(){
  cin>>w>>h;
  rep(i,h){
    tmp="";
    rep(j,w)cin>>c,tmp+=c;
    if(tmp[0]=='0')s1.push_back(tmp);
    else s2.push_back(tmp);
  }
  if(abs((int)s1.size()-(int)s2.size())>1)END();
  if(s1.size()<s2.size())swap(s1,s2);
  rep(i,w){
    rep(j,h){
      if(j%2==0)s[i]+=s1[j/2][i];
      else s[i]+=s2[j/2][i];
    }
  }
  s1.clear();
  s2.clear();
  rep(i,w){
    if(s[i][0]=='0')s1.push_back(s[i]);
    else s2.push_back(s[i]);
  }
  if(abs((int)s1.size()-(int)s2.size())>1)END();
  if(s1.size()<s2.size())swap(s1,s2);
  rep(i,w)s[i]="";
  rep(i,h){
    rep(j,w){
      if(j%2==0)s[i]+=s1[j/2][i];
      else s[i]+=s2[j/2][i];
    }
  }
  rep(i,h)rep(j,w){
    rep(k,4){
      int y=i+dy[k];
      int x=j+dx[k];
      if(y<0||x<0||y>=h||x>=w)continue;
      if(s[i][j]==s[y][x])END();
    }
  }
  cout<<"yes"<<endl;
}

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

typedef long long ll;

int main(){
    int a, b, c;

    cin >>  a >>b >> c;
    if (a == b && b == c){
        if (a % 2 == 0){
            cout << -1 << endl;
            return 0;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }

    if (a%2 || b % 2 || c % 2){
        cout << 0 << endl;
        return 0;
    }

    int cnt = 0;

    while (!(a % 2 || b % 2 || c % 2)){
        int a_s = a / 2;
        int b_s = b / 2;
        int c_s = c / 2;
        a = b_s + c_s;
        b = c_s + a_s;
        c = a_s + c_s;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

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

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}




void oneCase () {
    char a, b;
    cin >> a >> b;
    if (a == 'H') {
        cout << b << "\n";
    } else {
        if (b == 'H') {
            cout << 'D' << "\n";
        } else {
            cout << 'H' << "\n";
        }
    }
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

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

class Program
{
	public static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split(' ');
		List<int> tasks = new List<int>();
		int cost = 0;
		for (int i = 0; i < str.Length;i++){
			tasks.Add(int.Parse(str[i]));
		}
		tasks.Sort();
		for (int i = 0; i < tasks.Count - 1;i++){
			cost += tasks[i + 1] - tasks[i];
		}
		Console.WriteLine(cost);
	}
}


Measured memory_bytes: 11092
using System;
using System.Linq;

namespace _2216
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                int a = x[1] - x[0];
                int b = a / 1000;
                a = a % 1000;
                int c = a / 500;
                a = a % 500;
                int d = a / 100;
                Console.WriteLine(d + " " + c + " " + b);
            }
        }
    }
}

Measured memory_bytes: 9644
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long x,y,cnt=0;
  cin >> x >> y;
  while(x<y) {
    x*=2;
    cnt++;
  }
  if(x==y) {
    cout << 1+cnt << endl;
  }
  if(x>y) {
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define max 100005
#define int long long

using namespace std;

int n, m, ans, p[max], a[max], b[max], c[max], ct[max];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ans = 0;

    cin >> n >> m;

    for(int i = 1; i <= m; i++)
    {
        cin >> p[i];
        if(i > 1)
        {
            if(p[i - 1] >= p[i])
                for(int j = p[i]; j < p[i - 1]; j++)
                    ct[j]++;
            else
                for(int j = p[i - 1]; j < p[i]; j++)
                    ct[j]++;
        }
    }

    for(int i = 1; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];

    for(int i = 1; i < n; i++)
        ans += min(a[i] * ct[i], c[i] + b[i] * ct[i]);

    cout << ans << '\n';
}

Measured memory_bytes: 7036
import sys

L, = map(int, sys.stdin.readline().split())

N = 1
while True:
    if L < 2 ** N:
        break
    N += 1
#print(N)

res = []
for i in range(N-1):
    res.append((i+1, i+2, 0))
    res.append((i+1, i+2, 2**i))

i = N-1
m = 2 ** (N-1)
while i >= 1:
    a = 2**(i-1) - 1
    if a + m <= L-1:
        res.append((i, N, m))
        m = a+m+1
    i -= 1

#print('----')
print(N, len(res))
for i, j, d in res:
    print(i, j, d)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline 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<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
int L,a[25],cnt;
int main()
{
	int L=read();
	reg int i,j,N=0,M=0;
	for(i=0;i<=20;++i)if(L>>i&1)a[++cnt]=i-1,++M;
	N=a[cnt]+2;M=M+N*2-3;
	printf("%d %d\n",N,M);
	a[0]=-1;
	for(i=1;i<=cnt;++i)
	{
		for(j=a[i-1];j<a[i];++j)
			printf("%d %d %d\n",j+2,j+3,0),
			printf("%d %d %d\n",j+2,j+3,(1<<(j+1)));
		if(i==cnt) break;
		printf("%d %d %d\n",a[i]+2,N,L-(1<<a[i]+1));
		L-=1<<a[i]+1;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  int f=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      int x=i*m;
      x+=(n-i-i)*j;
      f|=x==k;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7; // 998244353
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}



int main() {
	ll W, H; cin >> W >> H;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	REP(i, W) {
		ll p; cin >> p;
		pq.push({ p,0 });
	}
	REP(i, H) {
		ll q; cin >> q;
		pq.push({ q,1 });
	}
	VL cnt(2);
	cnt[0] = W+1;
	cnt[1] = H+1;
	ll ans = 0;
	while (!pq.empty()) {
		ll cost = pq.top().first;
		int axis = pq.top().second;
		pq.pop();
		ans += cnt[(axis + 1) % 2] * cost;
		cnt[axis]--;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6256
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	char a[4]; cin >> a;
	int s = 0;
	s += (a[0] == '1');
	s += (a[1] == '1');
	s += (a[2] == '1');

	cout << s << endl;

	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,D;
  cin>>N>>D;
  vector<vector<int>>X(N,vector<int>(D));
  for(int x=0;x<N;x++){
    for(int d=0;d<D;d++){
      cin>>X[x][d];
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ll res=0;
      for(int d=0;d<D;d++){
        res+=(X[i][d]-X[j][d])*(X[i][d]-X[j][d]);
      }
      bool ok=false;
      for(int k=0;k<=1600;k++){
        if(k*k==res)ok=true;
      }
      if(ok)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
mu = 1
if 0 in a:
    print(0)
else:
    fl=0
    for i in range(n):
        mu = mu*a[i]
        if mu>10**18:
            print(-1)
            fl=1
            break
    # print(mu)
    if fl==0:
        print(mu)


Measured memory_bytes: 21640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    vector<vector<ll>> g(n+1);
    vector<p> vp;
    for(ll i = 0; i < n-1; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        vp.push_back(p(a, b));
    }
    ll c[n+1];
    c[0] = 0;
    for(ll i = 1; i <= n; i++)
        cin >> c[i];
    sort(c, c+(n+1));
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    que.push(1);
    dist[1] = 1;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+1;
            que.push(nv);
        }
    }
    vector<p> check;
    vector<ll> next(n+1);
    for(ll i = 1; i <= n; i++)
        check.push_back(p(dist[i], i));
    sort(check.begin(), check.end());
    for(ll i = 0; i < n; i++)
        next[check[i].second] = i+1;
    //for(ll i = 1; i <= n; i++)
      // cout << i << " " << next[i] << endl;
    ll ans = 0;
    ll sum[n+1];
    for(ll i = 0; i < n-1; i++){
        ll a = vp[i].first, b = vp[i].second;
        sum[a] = c[n-next[a]+1];
        sum[b] = c[n-next[b]+1];
        if(next[a]>next[b]){
            ans+=c[n-next[a]+1];
            //cout << c[n-next[a]+1] << endl;
        }
        if(next[a]<next[b]){
            ans+=c[n-next[b]+1];
            //cout << c[n-next[b]+1] << endl;
        }
    }
    cout << ans << endl;
    for(ll i = 1; i <= n; i++)
        cout << sum[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 1668
// https://atcoder.jp/contests/arc089/tasks/arc089_b

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, K;
  cin >> N >> K;

  VVL mat(2 * K, VL(2 * K));

  rep(i, N) {
    ll x, y;
    char c;
    cin >> x >> y >> c;

    if (c == 'W') y += K;

    x %= 2 * K;
    y %= 2 * K;

    mat[y][x]++;
  }

  VVL mat_sum(2 * K + 1, VL(2 * K + 1));
  rep(h, 2 * K) rep(w, 2 * K) {
    mat_sum[h + 1][w + 1] += mat_sum[h + 1][w] + mat[h][w];
  }
  rep(w, 2 * K) rep(h, 2 * K) mat_sum[h + 1][w + 1] += mat_sum[h][w + 1];

  auto ct_inside_square = [&](ll bl_h, ll bl_w) {
    if (bl_w > 2 * K || bl_h > 2 * K) return 0ll;
    ll tr_h = min(2 * K - 1, bl_h + K - 1);
    ll tr_w = min(2 * K - 1, bl_w + K - 1);
    if (tr_h < 0 || tr_w < 0) return 0ll;

    ll res = mat_sum[tr_h + 1][tr_w + 1] - mat_sum[tr_h + 1][max(0ll, bl_w)] -
             mat_sum[max(0ll, bl_h)][tr_w + 1] +
             mat_sum[max(0ll, bl_h)][max(0ll, bl_w)];

    return res;
  };

  ll res = 0;

  rep(h, K) rep(w, 2 * K) {
    ll r = 0;

    r += ct_inside_square(h, w);
    r += ct_inside_square(h + K, w + K);
    r += ct_inside_square(h - K, w + K);
    r += ct_inside_square(h + K, w - K);
    r += ct_inside_square(h - K, w - K);
    r += ct_inside_square(h - 2 * K, w);
    r += ct_inside_square(h, w - 2 * K);

    chmax(res, r);
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int comb(int n, int k)
{
  if(n<k || k<0) return 0;
  int table[n + 1][n + 1];
  for (int i = 0; i <= n; i++)
    table[i][0] = 1;
  for (int i = 1; i <= k; i++)
    table[i][i] = 1;

  for (int i = 2; i <= n; i++)
  {
    for (int j = 1; j < min(i, k + 1); j++)
    {
      table[i][j] = table[i - 1][j - 1] + table[i - 1][j];
    }
  }
  return table[n][k];
}


string s;
int k,N;

int rec(int i, int d, bool smaller)
{
  if(i==N){
    if(d==0) return 1;
    else return 0;
  }
  if(d==0) return 1;
  if(smaller) return comb(N-i,d) * pow(9, d);
  else{
    if(s[i]=='0') return rec(i+1, d, false);
    int tmp1 = rec(i+1, d, true);
    int tmp2 = rec(i+1, d-1, true) * (s[i]-'1');
    int tmp3 = rec(i+1, d-1, false);
    return tmp1+tmp2+tmp3;
  }
  
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> k;
  N = s.size();
  cout << rec(0, k, false) << endl;
  return 0;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int a, b, c = 0;
  for (int i = 0;i<=A;i++){
    a = X - 500 *i;
    if (a >=0){
      for (int j = 0; j <= B; j++){
        b = a - 100*j;
        if (b >=0 && b/50 <=C){
          c++;
          
          
        }
        else
          continue;
      }
    }
    else
      continue;
  }
  cout << c <<endl;
}

          
          

        

      

    

    
   

        

      
    

  


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
int main()
{
    int N, X;
    std::vector<int> m;
    std::cin >> N >> X;
    int tmp;
    for (int a = 0; a < N; a++) {
        std::cin >> tmp;
        m.push_back(tmp);
        X -= tmp;
    }
    std::cout << X / *std::min_element(m.begin(), m.end()) + N << std::endl;
}

Measured memory_bytes: 3636
package main

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

var cost = map[int]int{
	1: 2,
	2: 5,
	3: 5,
	4: 4,
	5: 5,
	6: 6,
	7: 3,
	8: 7,
	9: 6,
}

func main() {
	n, m := readInt(), readInt()

	matchNums := make([]matchNum, m)
	for i := range matchNums {
		a := readInt()
		matchNums[i] = matchNum{a, cost[a]}
	}

	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = -1
	}
	dp[0] = 0

	for i := 0; i < n+1; i++ {
		for _, x := range matchNums {
			if x.cost+i > n {
				continue
			}
			dp[i+x.cost] = max(dp[i+x.cost], dp[i]+1)
		}
	}

	sort.Sort(sort.Reverse(sortArray(matchNums)))

	ans := ""
	j := n
	for i := dp[n]; i > 0; i-- {
		for _, x := range matchNums {
			if j-x.cost >= 0 && dp[j-x.cost] == dp[j]-1 {
				ans += strconv.Itoa(x.num)
				j -= x.cost
				break
			}
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type matchNum struct {
	num  int
	cost int
}

type sortArray []matchNum

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].num < s[j].num }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

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

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

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

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

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

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 7552
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a;
  cin >> a;
  ll ans = a + a * a + a * a * a;
  cout << ans << endl;
  return 0;
}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int A,B,C;
  A = a.size()-1;
  B = b.size()-1;       
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

const int MAXN = 100, MAXV = 1000;
struct Item {
	int weight;
	int value;
}item[MAXN];

int dp[MAXV*MAXN + 10];
int main() {
	int n, W;
	cin>>n>>W;
	W++;
	for (int i=0; i<n; i++)
		cin>>item[i].weight>>item[i].value;
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	for (int i=0; i<n; i++)
		for (int j=MAXV*n-item[i].value; j>=0; j--)
			if (dp[j] && dp[j] + item[i].weight <= W) {
				if (dp[j+item[i].value] == 0 || dp[j+item[i].value] > dp[j] + item[i].weight)
					dp[j+item[i].value] = dp[j] + item[i].weight;
			}

	for (int i=MAXV*n; i>=0; i--)
		if (dp[i]) {
			cout<<i<<endl;
			break;
		}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    string s; cin>>s;
    string t=s.substr(5, 2);
    if(t=="01" || t=="02" || t=="03" || t=="04"){
        cout << "Heisei" << endl;
    }
    else cout << "TBD" << endl;
}

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

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

  int c=0;
  for(int i=22;i<=d;i++){
     if((i%10)>=2 && (i/10)*(i%10)<=m)c++;
  }
  cout<<c;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int64_t ans_s, ans_l;
  ans_l = a.at(N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (a.at(i)*2 == ans_l - 1) {
      ans_s = a.at(i);
      break;
    }
    else if (a.at(i)*2 > ans_l - 1) {
      if (i == 0) {
        ans_s = a.at(i);
        break;
      }
      else {
        if (ans_l - 1 - 2*a.at(i - 1) < 2*a.at(i) - ans_l + 1) {
          ans_s = a.at(i - 1);
          break;
        }
        else {
          ans_s = a.at(i);
          break;
        }
      }
    }
    else {
      if (i == ans_l - 2) {
        ans_s = a.at(i);
        break;
      }
    }
  }
  cout << ans_l << " " << ans_s << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= 0 || a >= 10){
        cout << "-1" << endl;
        return 0;
    }
    if(b <= 0 || b >= 10){
        cout << "-1" << endl;
        return 0;
    }
   cout << a * b << endl; 
   
   return 0;
}

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

int main() {
	long long n, m, d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(10) << (d == 0 ? (double)(m - 1) / n : (double)2 * (n - d)*(m - 1) / (n*n)) << endl;
}

Measured memory_bytes: 256
def main(x, y):
    if y in (x * 2, x * 4):
        print("Yes")
        return

    for i in range(x + 1):
        if ((x - i) * 2 + (i) * 4) == y:
            print("Yes")
            return

    print("No")


if __name__ == "__main__":
    x, y = map(int, input().split())

    main(x, y)


Measured memory_bytes: 9180
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#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>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //start from here

    read(x);
    int sum = 100;
    for (int i = 1;; i++)
    {
    	sum += (sum/100);
    	if(sum >= x) {cout << i; return 0;}
    }

    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<math.h>
using namespace std ;
using ll = long long ;
using vi = vector<int> ;
using vii = vector<vi> ;
using pii = pair<ll,ll> ;

int main(){
	ll n ; cin >> n ;
	vi x(n) ;
	for(int i=0;i<n;i++){
		cin >> x.at(i) ;
	}
	ll ans = 10000000 ;
	for(int i=1;i<=100;i++){
		ll sub = 0 ;
		for(int j=0;j<n;j++){
			sub += (x.at(j)-i)*(x.at(j)-i) ;
		}
		ans = min(ans,sub) ;
	}
	cout << ans << endl ;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String str=sc.next();
			Stack<Integer> st=new Stack<Integer>();
			for(int i=0;i<str.length();i++){
				if(st.isEmpty() || st.peek()==1 || str.charAt(i)=='S') st.add(str.charAt(i)=='S' ? 0 : 1);
				else st.pop();
			}
			System.out.println(st.size());
		}
	}
}

Measured memory_bytes: 17208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M, Q;
vector<int> v[510];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    v[L].emplace_back(R);
  }  
  for (int i = 1; i <= N; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    for (int j = p; j <= q; j++) {
      ans += upper_bound(v[j].begin(), v[j].end(), q) - v[j].begin();
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2176
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[200111];
int n,k,q[600111],fr,rr;
int main()
{
	get2(n,k);scanf("%s",s+1);
	
	if(k>=2*n)k=(k-2*n)%2+2*n;
	
	for(int i=1;i<=n;i++)q[rr++]=s[i]-'A';
	
	int neg=0;
	for(int i=1;i<=k;i++)
	{
		if(q[fr]^neg==0)q[fr]^=1;
		else
		{
			neg^=1;
			fr++;
			q[rr++]=neg;
		}
	}
	for(int i=fr;i<rr;i++)putchar((q[i]^neg)+'A');
	
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a.begin(), a.end());

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i].second;
		if (sum > a[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

ll lcm(ll a, ll b){
    return a/__gcd(a, b)*b;
}

int main(){
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    ll l = 1;
    for (int i = 0 ; i < n ; ++i){
        cin >> a[i];
        a[i] /= 2;
        l = lcm(l, a[i]);
    }
    for (int i = 0 ; i < n ; ++i){
        if ((l/a[i])%2==0){
            cout << 0;
            return 0;
        }
    }
    ll y = m/l;
    cout << (y+1)/2;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
int n,w;
pair < ll , ll > a[200];
ll memo[101][401][101];
ll solve(int i,int sum,int k)
{
    if(i == n)
        return 0;
    ll &ret = memo[i][sum][k];
    if(ret != -1)
        return ret;
    ll x1 = 0 , x2 = 0;
    x1 = solve(i+1,sum,k);
    if(k > 0 && a[i].fr <= sum)
    {
        x2 = a[i].sc + solve(i+1,sum-a[i].fr,k-1);
    }
    return ret = max(x1,x2);
}
int main()
{
    memset(memo,-1,sizeof(memo));
   cin>>n>>w;
   ll minx = 1e9 , maxx = 0;
   for(int i=0;i<n;i++)
   {
       ll x,y;
       scanf("%I64d%I64d",&x,&y);
       minx = min(minx , x);
       maxx = max(maxx , x);
       a[i] = mp(x,y);
   }
   for(int i=0;i<n;i++)
   {
       a[i].fr-=minx;
   }
   ll ans = 0;
   for(ll i=1;i<=n;i++)
   {
       ll R = w - i * minx;
       R = min(R , 1LL * 400);
       if(R >= 0)
       ans = max(ans , solve(0,R,i));
   }
   cout<<ans;
}


Measured memory_bytes: 32256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int main() {
  cin >> K >> A;
  if(K * 500 < A) cout << "No";
  else cout << "Yes";
}



Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]
que = deque([])
dst = [[-1]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            que.append([i, j])
            dst[i][j] = 0

max_d = 0
while que:
    y, x = que.popleft()
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    for i in range(4):
        ny = y+dy[i]
        nx = x+dx[i]
        if ny < 0 or ny >= h or nx < 0 or nx >= w:
            continue
        if a[ny][nx] == '#':
            continue
        if dst[ny][nx] != -1:
            continue

        dst[ny][nx] = dst[y][x] + 1
        max_d = dst[y][x] + 1
        que.append([ny, nx])
print(max_d)


Measured memory_bytes: 141148
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int n;
  cin >> n;
  vector<double>x(n),y(n);
  vector<int>v(n);
  rep(i,n)v[i]=i;
  rep(i,n)cin >> x[i] >> y[i];
  auto dist=[&](int a,int b){
    double dx,dy;
    dx=x[a]-x[b];
    dy=y[a]-y[b];
    return pow(dx*dx+dy*dy,0.5);
  };
  double sum=0;
  do{
    rep(i,n-1)sum+=dist(v[i],v[i+1]);
  }while(next_permutation(v.begin(),v.end()));
  double fact=1;
  rrep(i,2,n+1)fact*=i;
  cout << fixed << setprecision(10) << sum/fact << endl;
}
  



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

int numPlates;
double memo[301][301][301];
double solve(int one, int two, int three) {
    if(one < 0 || two < 0 || three < 0) return 0;

    if(three == 0 && two == 0 && one == 0) return 0;

    if(memo[one][two][three] > 0) return memo[one][two][three];

    int remaining = one + two + three;

    double expVal = numPlates +
                    one*solve(one-1,two,three) + 
                    two*solve(one+1,two-1,three) +
                    three*solve(one,two+1,three-1);
    
    memo[one][two][three] = expVal/remaining;
    return memo[one][two][three];
}

int main() {
    cin >> numPlates;
    int one = 0, two = 0, three = 0;

    for(int i = 0; i < numPlates; i++) {
        int numSushi;
        cin >> numSushi;
        if(numSushi == 1) {
            one++;
        } else if(numSushi == 2) {
            two++;
        } else {
            three++;
        }
    }
    
    memset(memo, -1, sizeof memo);

    double result = solve(one, two, three);
	printf("%.15f", result);
    return 0;
}

Measured memory_bytes: 216308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N,K;
  cin>>N>>K;
  
  vector<ll>x(N+1);//範囲なしを含まなければならないのでx[0]を空白にする
 ll sum=0;
 for(ll i=1;i<=N;i++){
    cin>>x[i];
  }
  
  ll dp[N+1][N+1][N*K+1];//N*１~N*Kまでの和がわかればいいのでN*K+1で十分
  rep(i,N+1){// int dp[][][]型の配列の定義は全て０になるとは限らないので一旦全て０にする必要がある
    rep(j,N+1){
rep(k,N*K+2){
  dp[i][j][k]=0;
}
    }
  }

  dp[0][0][0]=1;
  for(ll j=0;j<=N;j++){//jはx[1]からx[j]まで使うという意味 x[0]は何も使わないという意味
    for(ll k=0;k<=N;k++){//そのうちk個使う
for(ll s=0;s<=N*K;s++){//上の条件で和sになるパターン数
 if(j>=1&&s<x[j]){//x[j]を足してsになるものが存在しない
dp[j][k][s]=dp[j-1][k][s];//x[j]を使わない
  }
else if(j>=1&&k>=1&&s>=x[j]){//x[j]を足してsになるものが存在する
dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[j]];//x[j]を使うパターンとx[j]を使うパターン
}

    }
    }
  }
  ll ans=0;
  for(ll i=1;i<=N;i++){
ans+=dp[N][i][K*(i)];//i個取った時平均がK*iになることを考える
    

}
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 51072
import sys
def input():
    return sys.stdin.readline()[:-1]

S = input()
r = False
l = False
f = False
L = len(S)
for i in range(L):
    s = S[i]
    if s=='R':
        if (i+1)%2==0:
            f = True
            break
        r = True
    elif s=='L':
        if (i+1)%2==1:
            f = True
            break
        l = True
if f:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int dist = B - A - 1;
    if (dist % 2 == 0)
    {
        cout << "Borys" << endl;
    }
    else
    {
        cout << "Alice" << endl;
    }
}


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

string s;
set<char> se;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		se.insert(s[i]);
	}
	if(se.size()==3)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  
  int m=n;
  int s=0;
  bool t=true;
  while (t) {
    s++;
    m/=10;
    if (m==0) t=false;
  }
  
  m=n;
  int u=0;
  for (int i=0; i<s; i++) {
    u+=m%10;
    m/=10;
  }
  
  if (n%u==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
Xsort = sorted(X)
med = (Xsort[N // 2] + Xsort[N // 2 - 1]) / 2
for i in range(N):
    if X[i] < med:
        print(Xsort[N // 2])
    else:
        print(Xsort[N // 2-1])
        

Measured memory_bytes: 25472
N = int(input())
K_MAX = 100

n = N
result = ""
for k in range(K_MAX):
    sign = (-1) ** k
    if n % 2 == 1:
        n = n - sign
        result = "1" + result
    elif n != 0:
        result = "0" + result
    else:
        break        
    n = n / 2
if len(result) == 0: result = "0"

print(result)

Measured memory_bytes: 3064
// Vicfred
// https://atcoder.jp/contests/abc161/tasks/abc161_d
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

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

    queue<long long> q;
    
    for(long long i = 1LL; i <= 9LL; i++)
        q.push(i);

    set<long long> lunlun;
    map<long long, int> visited;

    while(!q.empty()) {
        long long item = q.front();
        q.pop();

        if(lunlun.size() > k-1)
            break;

        if(visited.count(item) > 0)
            continue;

        visited[item] = 1;
        lunlun.insert(item);

        if(item%10LL != 0LL)
            q.push(item*10LL+item%10LL-1LL);
        q.push(item*10LL+item%10LL);
        if(item%10LL != 9LL)
            q.push(item*10LL+item%10LL+1LL);
    }

    cout << *(--lunlun.end()) << endl;
}



Measured memory_bytes: 16096
n = int(input())
s = list(input())
R,G,B = [],[],[]
for i in range(n):
    if s[i] == "R":
        R.append(i)
    elif s[i] == "G":
        G.append(i)
    else:
        B.append(i)
base = len(R) * len(G) * len(B)
B = set(B)
no_num = 0
for r in R:
    for g in G:
        y = max(r,g)
        x = min(r,g)
        tmp = int((x+y)/2)
        if (x+y)%2==0 and (tmp in B):
            no_num += 1
        tmp = 2*y-x
        if tmp in B:
            no_num += 1
        tmp = 2*x-y
        if tmp in B:
            no_num += 1
print(base-no_num)

Measured memory_bytes: 78832
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int A, B;
    cin >> A >> B;
    if(B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
}


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

int main(){
    int64_t N, K, i, happiness = 0;
    string S;
    cin >> N >> K;
    cin >> S;
    for(i = 0; i < N - 1; i++){
        if(S[i] == S[i+1])happiness++;
    }
    happiness += 2 * K;
    if(N > happiness)cout << happiness << endl;
    else cout << N-1 << endl;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int ans = Integer.MAX_VALUE;

    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }

    Arrays.sort(h);

    for (int i = 0; i < ((n - k) + 1); i++) {
      int a = h[(i + k) - 1] - h[i];
      ans = Math.min(ans, a);
    }

    System.out.println(ans);

  }
}

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

void testCase(){
    int n, m, a, sum = 0;
    cin>>n>>m;
    for(int i = 0; i < m; i++){
        cin>>a;
        sum += a;
    }
    if(sum > n) cout<<-1<<endl;
    else cout<<n-sum<<endl;
}

int main(){
    int t;
    t = 1;
    // cin>>t;
    while(t--){
        testCase();
    }
}



Measured memory_bytes: 3628
a,b,c,d,e,f=map(int,input().split())

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):#Aの投入数
  for j in range(31):#Bの投入数
      wat=(i*a+j*b)*100
      if wat<=f and wat:
          psug = min(f-wat,wat//100*e)
          for k in range(psug//c+1):
              l = (psug-c*k)//d
              sug = k*c+l*d
              rate = 100*sug/(wat+sug)
              if ans_rate<=rate and rate<=e and wat+sug<=f:
                  ans_wat = wat
                  ans_sug = sug
                  ans_rate = rate

print(ans_wat+ans_sug,ans_sug)

Measured memory_bytes: 3064