akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

    ll ans = 0;

    ll max_i;

    for (int i = 1; i <= n; i++)
    {
        max_i = n / i;
        ans += (max_i * (max_i + 1) * i) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    double v[N];
    double a[N];
    a[0] = 1;

    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    sort(v, v + N);

    for(int i = 1; i < N; i++){
        a[i] = 2 * a[i-1];
    }

    double sum = v[0] / a[N-1];

    for(int i = 1; i < N; i++){
        sum += v[i] / a[N-i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var a, b, c int
	var i int

	fmt.Scan(&a, &b, &c)

	for ; i < c; i++ {
		if b-a >= 0 {
			b -= a
		} else {
			break
		}
	}
	fmt.Println(i)
}

Measured memory_bytes: 512
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
const double pi=3.141592653589793238;
int main() {
    FAST;
    double a, b, x, s;
    cin >> a >> b >> x;
    s = x / a;
    if(s < a * b / 2.0){
        double th = atan(b * b / (2.0 * s));
        th *= 180 / M_PI;
        printf("%.7lf", th);
    } else {
        double th = atan(2.0 *(a * b - s)/ (a * a));
        th *= 180 / M_PI;
        printf("%.7lf", th);
    }
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main() {
  int a, b, c;
  cin>>a>>b>>c;
  if (a == b && b == c && c == a) {
    cout<<"No"<<endl;
  } else if (a != b && b != c && c != a) {
    cout<<"No"<<endl;
  } else {
    cout<<"Yes"<<endl;
  }

}

Measured memory_bytes: 764
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll A[510],K;
int N;


bool check(ll x){
    vector<ll> V(N);
    ll sum=0;
    for(int i=0;i<N;i++){
        V[i]=A[i]%x;
        sum+=V[i];
    }
    //cout<<sum<<endl;
    sort(V.begin(),V.end(),greater<ll>());
    ll ans=110000000000,sam=0;
    for(int i=0;i<N;i++){
        sam+=x-V[i];
        sum-=V[i];
        ans=min(ans,max(sam,sum));
    }
    if(ans<=K) return true;
    else return false;
}

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

    ll sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    } 
    ll ans=1;
    for(ll i=1;i*i<=sum;i++){
        if(sum%i==0){
            if(check(i)) ans=max(ans,i);
            if(check(sum/i)) ans=max(ans,sum/i);
        }
    }
    cout<<ans<<endl;
}



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

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

vector<vector<int> > t, r;
vector<string> vec;

int bfs(int x){
  map<int,int> d;
  d[x]=0;
  queue<int> q;
  q.push(x);
  while(!q.empty()){
    int t = q.front();
    q.pop();
    for(int i = 0; i < 4; ++i){
      int xp = dx[i] + (t / w);
      int yp = dy[i] + (t % w);
      if(xp >= 0 && yp >= 0 && xp < h && yp < w){
	if(vec[xp][yp] == '.'){
	  if(!d.count(xp * w + yp)){
	    d[xp * w + yp] = d[t] + 1;
	    q.push(xp * w + yp);
	  }
	}
      }
    }
  }
  int res = 0;
  for(auto x : d){
    res = max(res, x.second);
  }
  return res;
}
int main(){
  cin>>h>>w;
  string s;
  vec.resize(h);
  for(int i = 0; i < h; ++i){
    cin>>vec[i];
  }
  int res = 0;
  for(int x = 0; x < w * h; ++x)if(vec[x/w][x%w]!='#')res = max(res, bfs(x));
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int counts = 1,maxn = -INF;
int head[MAXN];
struct node{
	int to;
	int next;
	int color;
}edge[MAXN];

void addedge(int a,int b)
{	
	edge[counts].to = b;
	edge[counts].color = 0;
	edge[counts].next = head[a];
	head[a] = counts++;
}

void dfs(int u,int c)
{
	int tmp = 1;
	for(int i = head[u];i != 0;i = edge[i].next){
		int v = edge[i].to;
		if(tmp == c)
			tmp++;
		edge[i].color = tmp;
		maxn = max(maxn,tmp);
		dfs(v,tmp);
		tmp++;
	}
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		addedge(a,b);
	}
	dfs(1,0);
	printf("%d\n",maxn);
	for(int i = 1;i < counts;i++){
		printf("%d\n",edge[i].color);
	}
	return 0;
}

Measured memory_bytes: 3968
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
    c = c - b;
    a = a - d;
  }
  if(c <= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a = 0, b = 0, ab = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'B' && s[s.length() - 1] == 'A') ab++;
        else if (s[0] == 'B') b++;
        else if (s[s.length() - 1] == 'A') a++;
        string::size_type pos = s.find("AB");
        while (pos != string::npos) {
            cnt++;
            pos = s.find("AB", pos + 2);
        }
    }
    // cout << a << " " << b << " " << ab << " " << cnt << endl;
    if (a == 0 && b == 0 && ab > 0) cout << cnt + ab - 1 << endl;
    else {
        int tmpa = a, tmpb = b;
        cnt += min(a, ab);
        cnt += min(b, ab);
        a -= ab;
        b -= ab;
        ab -= max(tmpa, tmpb);
        // cout << a << b << ab << endl;
        if (ab > 0) cnt += ab;
        if (a > 0 && b > 0) cnt += min(a, b);
        cout << cnt << endl;
    }
    return 0;
}


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

const int MOD = 1e9+7;

long long modpow(long long a, long long b){
	long long c = 1;
	while(b > 0){
		if(b & 1) c = c * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return c;
}

int main() {
	
	int m,n;
	cin >> m >> n;
	cout << modpow(m,n) << endl;
}



Measured memory_bytes: 3112
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200000+100;
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 go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
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*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int Inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=Inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int n,k,c,f[N],g[N];
char s[N];
vi p;

int main()
{
	n=read();k=read();c=read()+1;
	scanf("%s",s+1);
	rep(i,1,n) if (s[i]=='o') p.pb(i);
	int len=p.size(),mx=p[len-1];
	rep(i,0,len-1) g[i]=n+1;
	per(i,len-1,0)
	{
		int now=p[i],nxt=now+c;
		if (nxt>mx) f[i]=1;
		else 
		{
			int pos=lower_bound(p.begin(),p.end(),nxt)-p.begin();
			f[i]=f[pos]+1;g[i]=pos;
		}
	}
	//rep(i,0,len-1) cout << f[i] << " ";cout << endl;
	//rep(i,0,len-1) cout << g[i] << " ";cout << endl;
	int now=0,cnt=0,pre=0;
	while (1)
	{
		if (now>mx) break;
		int replace;
		if (now) replace=g[pre]+1;else replace=1;
		//cout << "chk " << now << " " << replace << endl;
		if (f[replace]+cnt<k) printf("%d\n",p[now]);
		pre=now;now=g[now];cnt++;
	}
	return 0;
}
	



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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,m,p,ans=0,dis[N],head[N],nex[N],to[N],wi[N];
bool vis[N],vv[N];
ll num[N];
ll tot=1;void add(ll u,ll v,ll w){to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;}
ll spfa()
{
    memset(dis,inf,sizeof(dis));
    queue<ll>q;
    q.push(1);
    vis[1]=true;num[1]=1;
    dis[1]=0;
    while(!q.empty())
    {
        ll u=q.front();q.pop();
        vis[u]=false;
        for(ll i=head[u];i;i=nex[i])
        {
            ll v=to[i];
            if(!vv[v]) continue;
            if(dis[v]>dis[u]+wi[i])
            {
                dis[v]=dis[u]+wi[i];
                if(!vis[v])
                {
                    vis[v]=true;
                    num[v]++;
                    if(num[v]>n) return -1;
                    q.push(v);
                }
            }
        }
    }
    return max(0ll,dis[n]*-1);
}
int top,s[N];
void dfs(ll u)
{
    vis[u]=true;
    for(ll i=head[u];i;i=nex[i])
    {
        ll v=to[i];
        if(!vis[v]) dfs(v);
        if(vv[v]) vv[u]=true;
    }
}
int main()
{
    scanf("%lld%lld%lld",&n,&m,&p);
    for(ll i=1;i<=m;i++)
    {
        ll u,v,w;
        scanf("%lld%lld%lld",&u,&v,&w);
        add(u,v,w-p);
    }
    vv[n]=true;
    for(int i=1;i<=n;i++)
    {
        memset(vis,false,sizeof(vis));
        dfs(i);
    }
    memset(vis,false,sizeof(vis));
    for(ll i=2;i<=tot;i++) wi[i]*=-1;
    printf("%lld\n",spfa());
}


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

int main()
{
    std::string s;
    std::cin >> s;

    int r = 0,b=0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0')
            r++;
        else
            b++;
    }

    std::cout << std::min(r,b)*2 << std::endl;
    return 0;
}


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

bool check_adjacent(const vector<vector<int> > &p, int preV, int nextV){
	for(int x: p.at(preV)) {
		if(x == nextV)
			return true;
	}
	return false;
}

int main(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	vector<vector<int> > p(n);
	for(int i=0; i < m; i++) {
		scanf("%d%d", &a, &b);
		p.at(a-1).push_back(b-1);
		p.at(b-1).push_back(a-1);
	}
	vector<int> v(n);
	for(int i=0; i < n; i++)
		v.at(i) = i;

	int ans = 0;
	do {
		if(v.at(0) != 0) continue;
		int preV = 0;
		for(int i=1; i < n; i++) {
			if(check_adjacent(p, preV, v.at(i))) {
				if(i == n-1) ans++;
				preV = v.at(i);
				continue;
			}else{
				break;
			}
		}
	} while(next_permutation(v.begin(), v.end()));
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}

int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    double t;
    cin>>t;
    double ans=t/3;
    cout<<ans*ans*ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define rep(i,beg,end) for(int i=(beg);i<(end);i++)
typedef long long LL;
using namespace std;

long long dp[30005];
int main(){
	memset(dp,0x3f,sizeof dp);
	long long h,n,a[1004],b[1004];
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;a[0]*i<30005;i++){
		dp[a[0]*i]=b[0]*i;
	}
	LL minnt=0x3f3f3f3f3f3f3f3f;
	for(int i=30004;i>=0;i--){
		minnt=min(minnt,dp[i]);
		dp[i]=minnt;
	}
	for(int i=1;i<n;i++){
		for(int j=0;a[i]*j<30005;j++){
			dp[a[i]*j]=min(dp[a[i]*j],b[i]*j);
		}
		LL minn=0x3f3f3f3f3f3f3f3f;
		for(int j=30004;j>=0;j--){
			minn=min(minn,dp[j]);
			dp[j]=minn;
			//cout<<dp[i][j]<<"\n";
		}
		for(int j=0;j<30005;j++){
			if(j-a[i]>=0)
				dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
			//else dp[i][j]=min(dp[i][j],dp[j]);
		}
		minn=0x3f3f3f3f3f3f3f3f;
		for(int j=30004;j>=0;j--){
			minn=min(minn,dp[j]);
			dp[j]=minn;
			//cout<<dp[i][j]<<"\n";
		}
	}
	long long ans=0x3f3f3f3f3f3f3f3f;
	for(int i=h;i<30005;i++)
		ans=min(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,x,dp[2009][2009],ans,tmp[2009];
signed main(){
    cin>>n>>x;
    r(i,n)cin>>dp[0][i],ans+=dp[0][i];
    for(int i=1;i<n;i++){
        int s=0;
        r(j,n)dp[i][j]=dp[i-1][j];
        r(j,n){
            tmp[j]=min(dp[i][j],dp[i][(j-1+n)%n]);
            s+=tmp[j];
        }
        r(j,n)dp[i][j]=tmp[j];
        ans=min(ans,s+x*i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 31616
using System;
class Class1
{
    static void Main(string[] args)
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                Console.WriteLine("{0}x{1}={2}", i, j, i * j);
            }
        }
    }
}

Measured memory_bytes: 5548
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = B = 0
for i,v in enumerate(list(itertools.permutations(range(1,N+1))), 1):
    if list(v) == P:
        A = i
    elif list(v) == Q:
        B = i
    else:
        pass

print(abs(A-B) if A != 0 and B != 0 else 0)

Measured memory_bytes: 8052
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int main()
{
        int N;
        cin >> N;
        bool ok = false;
        for (int i = 1; i < 10; i++)
        {
                if (N % i != 0)
                {
                        continue;
                }
                int j = N / i;
                if (1 <= j && j <= 9)
                {
                        ok = true;
                        break;
                }
        }
        if (ok)
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	n, k := scanInt(), scanInt()
	a := scanInts(n)
	answer := lights(n, k, a)
	for i, v := range answer {
		if i == n-1 {
			fmt.Printf("%d\n", v)
		} else {
			fmt.Printf("%d ", v)
		}

	}
}

func lights(n, k int, a []int) []int {
	tmp := make([]int, n)
	for i := 0; i < k; i++ {
		tmp = count(a)
		same := true
		for j := 0; j < n; j++ {
			if tmp[j] != a[j] {
				same = false
			}
		}
		if same {
			return tmp
		}
		a = tmp
	}
	return a
}

func count(a []int) []int {
	count := make([]int, len(a))
	for i := 0; i < len(a); i++ {
		l := max(i-a[i], 0)
		r := min(i+a[i], len(a)-1)
		count[l]++
		if r < len(a)-1 {
			count[r+1]--
		}
	}
	for i := 1; i < len(count); i++ {
		count[i] += count[i-1]
	}
	return count
}
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func debug(a ...interface{}) {
	fmt.Println(a...)
}


Measured memory_bytes: 13504
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
// #define fill(x, v) memset(x, v, sizeof(x))
#define FER(i,a,b) for(int i=int(a); i< int(b); ++i)
#define IFR(i,a,b) for(int i=int(a); i>=int(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
/*
// #define N 21000000
// #define M 19
// #define mod3 9
#define mod  998244353
#define mod1 1000000007
#define mod2 1000000009
*/
#define mody 998244353
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 3000000000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<vi> vv;
typedef vector<ii> vii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}
/*
inline ll add(ll a, ll b) { return a+b < mod? a+b : a+b-mod;}
inline ll rem(ll a, ll b) { return a >= b? a - b: a- b + mod;}
inline ll mul(ll a, ll b) { return (long long) a*b%mod;}
inline void Mul(ll &a, ll b) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p){
    ll ret;
    for(ret = 1; p; p>>=1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1);
    return ret;
}
*/

inline void read(ll &x){cin>>x;}

int main(){
	fastio;
	ll n, k; read(n), read(k);
	vi tnt, froz;
	FER(i, 0, n) {
		ll x; read(x);
		tnt.pb(x);
	}
	FER(i, 0, n){
		ll x; read(x);
		froz.pb(x);
	}
	sort(all(froz)), sort(all(tnt));
	reverse(all(froz));
	ll ini = -1, fin = 1LL<<42;
	FER(i, 0, 100){
		if(ini + 1 == fin) break;
		ll mid = (ini+fin)>>1, cur = 0;
		FER(i, 0, n){
			cur += max(tnt[i] - mid/froz[i], 0LL);
		}
		if(cur > k) ini = mid;
		else fin = mid;
	}
	cout<<ini+1<<"\n";
	return 0;
}

Measured memory_bytes: 7980
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
int main(){
    long long int a,res=0,maxx=0;
      cin>>a;
      vector<long long int>vec;
      for(int i=1;i<=a;i++){
        long long int x;
        cin>>x;
        vec.push_back(x-i);
      }
      sort(vec.begin(),vec.end());
       maxx=vec[a/2];
      for(int i=0;i<a;i++){
            res+=abs(vec[i]-maxx);
      }
      cout<<res<<endl;

}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std; 
int main()
{
	int n,k,i;
	long long s=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		s+=n/i*max(0,i-k)+max(0,n%i-k+1);
	if(k==0)
		s-=n-k;
	printf("%lld",s);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    long ans = 0;
    for(int i = 0; i < n; i++) {
      String s = sc.next();
      char[] c = s.toCharArray();
      Arrays.sort(c);
      String s2 = new String(c);
      if(map.containsKey(s2)) {
        ans += (long)map.get(s2);
        map.put(s2, map.get(s2) + 1);
      } else {
        map.put(s2, 1);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 52508
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> d(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        if (i > 0 && d[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
        ++c[d[i]];
    }
    int ans = 1;
    for (int i = 1; i < n; ++i)
        for (int j = 0; j < c[i]; ++j)
            ans = 1LL * ans * c[i - 1] % P;
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<fstream>

#define rep(i,a,N) for(int i=0+a;i<N;i++)
#define lint long long int
#define SIZE 100005
#define pb push_back
#define MP make_pair

using namespace std;

int main(){
	vector<long long int> v;
	vector<long long int> vs;
	lint n;
	cin>>n;
	lint c;
	rep(i,0,n){
		cin>>c;
		v.pb(c);
	}
	sort(v.begin(),v.end());
	vs.pb(v[0]);
	rep(i,1,n){
		vs.pb(v[i]+vs[i-1]);
		if(vs[i]>3000000000)
			vs[i]=3000000001;
	}
	lint ans=0;
	rep(i,0,n-1){
		if(vs[i]*2>=v[i+1])ans++;
		else ans=0;
	}
	ans++;

	cout<<ans;

return 0;
}

Measured memory_bytes: 2548
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial

def main():
    As = []
    for _ in range(3):
        A = list(map(int, input().split()))
        As.append(A)
    N = int(input())
    Bs = set([int(input()) for _ in range(N)])

    is_success = False
    for A in As:
        if len(Bs & set(A)) == 3:
            is_success = True

    for i in range(3):
        C = Bs & set([A[i] for A in As])
        if len(C) == 3:
            is_success = True

    D = set([As[0][0], As[1][1], As[2][2]])
    if len(Bs & D) == 3:
        is_success = True
    D = set([As[0][2], As[1][1], As[2][0]])
    if len(Bs & D) == 3:
        is_success = True

    if is_success:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
n=int(input())
txy=[[0, 0, 0]]+[list(map(int, input().split())) for i in range(n)]
def C(txy0, txy1):
    xx=txy1[1]-txy0[1]
    yy=txy1[2]-txy0[2]
    tt=txy1[0]-txy0[0]
    if xx+yy<=tt and (xx+yy-tt)%2==0:
        return True
    return False
if all(C(txy[i], txy[i+1]) for i in range(n)):
    print('Yes')
else:
    print('No')

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

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}


int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (b%a == 0 ? a+b : b-a) << endl;
}


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

using namespace std;

#define ll long long

int main() {
	ll t,d;
	int cnt = 0;
	cin>>t>>d;
	d*=d;
	while(t--){
		ll x1,y1;
		cin>>x1>>y1;
		x1*=x1;
		y1*=y1;
		if(x1+y1<=d)
			cnt++;
}
cout<<cnt;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  int lst[n];
  for (int i=0; i<n; i++){
      cin >> lst[i];
  }
  int colors = 1;
  multiset<int> cur;
  cur.insert(lst[0]);
  for (int i=1; i<n; i++){
      //cout << i << endl;
      // get the highest lowest element that's at the front of a stream
      // if there is no stream with elements below, start new one
      multiset<int>::iterator lower = cur.lower_bound(lst[i]);
      if (lower == cur.end()){
          lower--;
      }
      if (lower == cur.begin() && *lower >= lst[i]){
          colors++;
          cur.insert(lst[i]);
          continue;
      }
      bool dont = false;
      while (*lower >= lst[i]){
          lower--;
          if (lower == cur.end() && *lower >= lst[i]){
              dont = true;
              colors++;
              cur.insert(lst[i]);
              break;
          }
      }
      if (!dont){
          cur.erase(lower);
          cur.insert(lst[i]);
      }
      
  }
  cout << colors;
  return 0; 
 
} 


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;


int main() {
	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;
}

Measured memory_bytes: 256
n = int(input())
x = [int(x) for x in input().split()]

ans = 0
ans2 = 0
for i in range(n-1):
    if x[i] >= x[i+1]:
        ans +=1
    else:
        if ans2 < ans:
            ans2 = ans
        ans = 0
if ans2 < ans:
    ans2 = ans
print(ans2)

Measured memory_bytes: 14252
n = int(input())

L6 = []
for i in range(1, 100):
  if 6**i <= n:
    L6.append(6**i)
  else:
    break

L9 = []
for i in range(1, 100):
  if 9**i <= n:
    L9.append(9**i)
  else:
    break

dp = [0] * (n+1)
    
for i in range(1, n+1):
  dp[i] = dp[i-1] + 1
  for l6 in L6:
    if i - l6 >= 0:
      dp[i] = min(dp[i], dp[i - l6] + 1)
  for l9 in L9:
    if i - l9 >= 0:
      dp[i] = min(dp[i], dp[i - l9] + 1)
print(dp[n])
      
  

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
vector<int> a;

void input(){
    cin >> n;
    a.resize(n);
    for(int i=0;i<n;i++) cin >> a[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    sort(a.begin(), a.end());
    int mx = a[n-1];
    int tmp = mx / 2;
    vector<pair<int, int>> res(n);
    for(int i=0;i<n;i++){
        res[i].first = a[i];
        if(mx % 2) res[i].second = min(abs(tmp - a[i]), abs(tmp+1 - a[i]));
        else res[i].second = abs(tmp - a[i]);
    }
    sort(res.begin(), res.end(), [](const auto& x, const auto& y){return x.second < y.second;});
    // for(int i=0;i<n;i++) cout << res[i].first << ' ' << res[i].second << endl; 
    cout << mx << ' ' << res[0].first << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int h,w,k;
  cin>>h>>w>>k;

  vector<string> v(h);
  rep(i,h) cin>>v[i];

  vector<vector<int>> ans(h,vector<int>(w, -1));

  // find first
  int ini = 0;
  rep(i,h){
    rep(j,w) if(v[i][j]  == '#'){ini = i; i=h;j=w;}
  }

  int nx = 1;

  rep(i,ini,h){
    // find first
    int ij = -1;
    rep(j,w) if(v[i][j]=='#'){ ij = j; j=w;}
    if(ij == -1){
      ans[i] = ans[i-1];
    } else {
      rep(j,ij) ans[i][j] = nx;
      rep(j,ij,w){
        if(v[i][j]=='#') ans[i][j] = nx++;
        else ans[i][j]  = ans[i][j-1];
      }
    }
  }

  rep(i,ini) ans[i] = ans[ini];

  rep(i,h)  rep(j,w) cout << ans[i][j] << " \n"[j==w-1];

  return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop();
void p(int x);
int t, stack[1000];




int main(){
  int a,b;
  t = 0;

  char s[100];
  while(scanf("%s",s)!=EOF){
  if(s[0]=='+'){

    a=pop();
    b=pop();
    p(a+b);

  }

  else if(s[0]=='-'){
    b=pop();
    a=pop();
    p(a-b);
  }

  else if(s[0]=='*'){

    a=pop();
    b=pop();
    p(a*b);
  }
  else{
    p(atoi(s));
  }
}
printf("%d\n",pop());

return 0;
}


int pop(){
  t--;

  return stack[t+1];
}


void p(int x){
  stack[++t]=x;
}



Measured memory_bytes: 2128
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).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; }

int N;
int F[100][10];
ll P[100][11];

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

    cin >> N;

    rep(i, N)
    {
        rep(j, 10)
        {
            cin >> F[i][j];
        }
    }

    rep(i, N)
    {
        rep(j, 11)
        {
            cin >> P[i][j];
        }
    }

    ll ans = -INF;

    for (int b = 1; b < (1 << 10); b++)
    {
        ll p = 0;

        rep(i, N)
        {
            int count = 0;

            rep(j, 10)
            {
                //両方のお店が営業している時間帯をカウント
                if (F[i][j] == 1 && (b >> j) & 1) count++;
            }

            p += P[i][count];
        }

        chmax(ans, p);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//package com.company;
//import javax.print.attribute.IntegerSyntax;
import java.util.*;
import java.lang.*;


class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner in = new Scanner(System.in);


        int N = in.nextInt();
        int M = in.nextInt();
        int R = in.nextInt();

        int [] r1 = new int[R];

        for(int i=0; i<R; i++){
            r1[i] = in.nextInt();
        }

       int [][] b = new int[N+1][N+1];
        for(int i =0; i<=N; i++){
            for(int j =0; j<=N; j++){
                if(i==j) b[i][j] = 0;
                else b[i][j] = (int)1e9;
            }
        }

        for(int i = 0; i<M; i++){
            int u = in.nextInt();
            int v = in.nextInt();
            int c = in.nextInt();

            b[u][v]=c;
            b[v][u] = c;

        }


        for (int k=0; k <= N; ++k)
            for (int i=0; i<=N; ++i)
                for (int j=0; j<=N; ++j)
                    b[i][j] = Math.min(b[i][j], b[i][k] + b[k][j]);



        int ans = 0;
        Arrays.sort(r1);
        for(int i =0; i<R-1; i++){
            ans += b[r1[i]][r1[i+1]];
        }

        while(next_permutation(r1)){
            int ans1= 0;
            for(int i =0; i<R-1; i++){
                ans1 += b[r1[i]][r1[i+1]];
            }
            ans = Math.min(ans, ans1);
        }

        System.out.println(ans);



    }

    static boolean next_permutation(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
            if (p[a] < p[a + 1])
                for (int b = p.length - 1;; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        return false;
    }
}

Measured memory_bytes: 46960
def c_many_formulas(S):
    import itertools
    # 文字数-1個の演算子の列と解釈(1は'+',0は空文字)
    string = itertools.product('01', repeat=len(S) - 1)
    ans = 0
    for s in string:
        operator = ['+' if x == '1' else '' for x in s] + ['']  # 空文字を番兵
        tmp = ''  # 数字の間に演算子を入れた文字列(数式と解釈する)
        for value, op in zip(S, operator):
            tmp += (value + op)  # 末尾には番兵(空文字)が入るので問題ない
        ans += eval(tmp)
    return ans

S = input().strip()
print(c_many_formulas(S))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	long int a,b,c,d,prod;
	cin >> a >> b >> c >> d;
	prod = a * c;
	if(b*d > prod)
		prod = b*d;
	if(a*d > prod)
		prod = a * d;
	if(b*c > prod)
		prod = b*c;		
	cout <<	prod << endl;		
}

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

int main()
{
	int N, K, Q;
	scanf("%d%d%d", &N, &K, &Q);
	std::vector<int> points(N, K - Q);
	for (int i{}; i < Q; i++)
	{
		int A;
		scanf("%d", &A);
		A--;
		points[A]++;
	}
	int count{};
	for (auto& e: points)
		if (e > 0) puts("Yes");
		else puts("No");

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
      long long n,m,r,l;
      long long ans=0;
      long long a[100000];
      long long b[100000];
      long long c[100000];
      long long cnt[100001];
      long long p[100000];
      cin>>n>>m;
      REP(i,100001)cnt[i]=0;
      REP(i,m){
            cin>>p[i];p[i]--;
            if(i==0)continue;
            r=p[i-1];l=p[i];
            if(r>l)swap(r,l);
            cnt[r]++;
            cnt[l]--;
      }
      REP(i,n)cnt[i+1]+=cnt[i];
      REP(i,n-1){
            cin>>a[i]>>b[i]>>c[i];
            if(a[i]*cnt[i]>b[i]*cnt[i]+c[i])ans+=b[i]*cnt[i]+c[i];
            else ans+=a[i]*cnt[i];
      }
      printf("%lld\n",ans);
}

Measured memory_bytes: 5056
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll N, P, Q;
ll C[500000];
ll d[500000];

int main() {
  scanf("%lld%lld%lld", &N, &P, &Q);
  ll init = 0;
  for (ll i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
    d[i] = i * P + C[i];
    init += C[i];
  }
  sort(d, d + N);
  ll sum = init, ans = init;
  for (ll i = 0; i < N; i++) {
    sum += 2 * P * i + P * Q - d[i];
    ans = max(ans, sum);
  }
  printf("%lld\n", ans);
}



Measured memory_bytes: 10588
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int s = S.length();
    String T = sc.next();
    int t = T.length();
    char d = T.charAt(0);
    int count = 0;
    String ans = "UNRESTORABLE";
    for(int i = s-t; i >= 0; i--){
      char c = S.charAt(i);
      boolean check = true;      
      String SP = S.substring(i, i+t);
      for(int j = 0; j < t; j++){
        if(SP.charAt(j) != '?' && SP.charAt(j) != T.charAt(j)){
          check = false;
          break;
        }
      }

      if(check){
        ans = S.substring(0, i) + T + S.substring(i+t,s);
        ans = ans.replace("?", "a");
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
n, k = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]

answer = 10**100
sortx = sorted(lst, key = lambda x: x[0])
for a, pt1 in enumerate(sortx[:n-k+1]):
    for b, pt2 in enumerate(sortx[a+k-1:]):
        #print(a,b)
        sorty = sorted(sortx[a:a+k+b], key = lambda x: x[1])
        sorty_len = len(sorty)
        for c, pt3 in enumerate(sorty[:sorty_len-k+1]):
            #print(len(sorty), c, k)
            pt4 = sorty[c+k-1]
            #print(pt1, pt2, pt3, pt4)
            if pt3[1] <= pt1[1] and pt3[1] <= pt2[1] and pt4[1] >= pt1[1] and pt4[1] >= pt2[1]:
                answer = min(answer, (pt2[0] - pt1[0]) * (pt4[1] - pt3[1]))
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

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

    lint a, v; cin>>a>>v;
    lint b, w; cin>>b>>w;
    lint t; cin>>t;
    if (v <= w) {
        cout<<"NO";
        return 0;
    }
    lint ma = t*(v-w);
    if (ma >= abs(a-b)) cout<< "YES";
    else cout<< "NO";
}


Measured memory_bytes: 3648
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残すな
//数値計算 基本はdouble
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

ll dig(ll N) {//桁数
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}

ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N; cin >> N;
	ll A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	ll r = gcd(A[0],A[1]);
	for (int i = 2; i < N; i++) {
		r = gcd(r, A[i]);
	}

	cout << r << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[m], sum = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
    sum = sum + a[i];
  }
  int day = n - sum;
  if (day < 0) {
    printf("-1");
  } else {
    printf("%d", day);
  }
  return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());//int型
		int K = Integer.parseInt(sc.next());
		String sline = sc.next();
		String[] sl = new String[N];
		for (int i=0; i<N; i++){
			sl[i] = String.valueOf(sline.charAt(i));
		}
		
		sl[K-1] = sl[K-1].toLowerCase();
		for (int i=0; i<N; i++){
			System.out.print(sl[i]);
		}
	}

}


Measured memory_bytes: 23764
n = int(input())
l = []

for i in range(n):
    l.append(input())

    
print('AC x ' + str(l.count('AC')))
print('WA x ' + str(l.count('WA')))
print('TLE x ' + str(l.count('TLE')))
print('RE x ' + str(l.count('RE')))

Measured memory_bytes: 79312
def sub():
    items = [int(input()) for _ in range(6)]
    N = int(items[0])
    ds = [int(e) for e in items[1:]]
    k = min(ds)
    
    nb_pack, m = divmod(N, k)
    if m != 0:
        nb_pack = nb_pack + 1
    wait = nb_pack - 1 + 5
    print(wait)

sub()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>
#include <limits>
using namespace std;

int main()
{
	int N = 0;
	std::vector<long> A;

	//数
	cin >> N;
	long min = std::numeric_limits<long>::max();
	int minusNum = 0;
	for (int i = 0; i < N; i++) {
		long tmp;
		cin >> tmp;
		A.push_back(tmp);
		if (min > abs(tmp)) {
			min = abs(tmp);
		}
		if (tmp < 0) {
			minusNum++;
		}
	}

	//変換する
	bool ischanged = false;
	if (minusNum % 2 == 0) {
		for (int i = 0; i < N; i++) {
			A[i] = A[i] < 0 ? A[i] * -1 : A[i];
		}
	} else {
		for (int i = 0; i < N; i++) {
			if (abs(A[i]) == min && !ischanged) {
				ischanged = true;
				A[i] = A[i] < 0 ? A[i] : A[i]*-1;
			} else {
				A[i] = abs(A[i]);
			}
		}
	}

	long sum = accumulate(A.begin(), A.end(), 0L);

	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 1400
s=input()
n=len(s)
abc=list(map(chr,range(97,123)))

for x in abc:
    if x*2 in s:
        d=s.index(x*2)
        print(d+1,d+2)
        exit()

for i in range(n-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        exit()

print(-1,-1)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.HUPC_day2
{
    class F
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            long[] aArray = ReadLongs();
            long[] bArray = ReadLongs();

            int length = 200000 + 10;
            long sum = 0;
            int[] cnts = new int[length];
            long aMax = 0;
            for(int i = 0; i < n; i++)
            {
                sum += aArray[i];
                aMax = Max(aMax, aArray[i]);
                cnts[aArray[i]]++;
            }
            for(int i = 1; i < length; i++)
            {
                cnts[i] += cnts[i - 1];
            }

            Array.Sort(bArray);
            List<long[]> bList = new List<long[]>();
            for(int i = 0; i < m; i++)
            {
                if (bList.Count == 0) bList.Add(new long[2] { bArray[i], 1 });
                else
                {
                    if (bList[bList.Count - 1][0] == bArray[i])
                    {
                        bList[bList.Count - 1][1]++;
                    }
                    else
                    {
                        bList.Add(new long[2] { bArray[i], 1 });
                    }
                }
            }

            long res = 0;
            for (int i = 0; i < bList.Count; i++)
            {
                long cnt = 0;
                for (int j = 1; j * bList[i][0] <=aMax; j++)
                {
                    long maxIndex = Min(aMax, (j + 1) * bList[i][0] - 1);
                    cnt += (cnts[maxIndex]
                        - cnts[j * bList[i][0] - 1]) * j;
                }
                res += (sum - cnt * bList[i][0]) * bList[i][1];
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 39492
#!python3

def LI():
    return list(map(int, input().split()))

# input
K = int(input())
S = input()


def main():
    n = len(S)
    ans = S
    if n > K:
        ans = S[:K] + "..."
    print(ans)


if __name__ == "__main__":
    main()


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

int main(void){
  string s;
  string t; 
  cin>>s; 
  cin>>t;
  int n = s.size();
  int m = t.size();
  int dp[3010][3010] = {0};
  
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      }else{
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  string ans = "";
  while(n > 0 && m > 0){
    if(dp[n][m] == dp[n-1][m]){
      --n;
    }else if(dp[n][m] == dp[n][m-1]){
      --m;
    }else{
      ans = s[n-1] + ans;
      --n;
      --m;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ab[3];
	cin>>a>>b;
	ab[0]=(a+b);
	ab[1]=(a-b);
	ab[2]=(a*b);
	sort(ab,ab+3);
	cout<<ab[2]<<endl;
}



Measured memory_bytes: 256
N = int(input())
F = list()
P = list()
ans = - 10**10
for i in range(N):
  F.append(list(map(int, input().split())))
for i in range(N):
  P.append(list(map(int, input().split())))
for i in range(1, 1<<10):
  shop = list()
  cnt = [0]*N
  tmp = 0
  for j in range(10):
    if i>>j & 1:
      shop.append(j)
  for s in range(N):
    for p in shop:
      if(F[s][p] == 1):
        cnt[s] += 1
    tmp += P[s][cnt[s]]
  ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 41200
#include <stdio.h>
int main(void){
    int a,b,c,i;
    scanf("%d %d %d",&a,&b,&c);
    i = b;
    b = a;
    a = i;
    i = c;
    c = a;
    a = i;
    printf("%d %d %d",a,b,c);
    return 0;
}

Measured memory_bytes: 128