akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	
	int n = read.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	
	foreach(i; 1 .. n){
		int a = read.to!int - 1;
		Node par = nodes[a];
		par.sons ~= nodes[i];
	}
	
	int ans = nodes[0].value;
	
	ans.writeln;
	
}

class Node{
	int id;
	int _value;
	Node[] sons;
	bool hasValue = 0;
	this(int id){
		this.id = id;
	}
	int value(){
		if(! hasValue){
			_value = 0;
			sons.sort!"a.value>b.value"();
			foreach(i, nd; sons){
				_value = max(_value, nd.value + i + 1).to!int;
			}
			hasValue = 1;
		}
		return _value;
	}
}

Measured memory_bytes: 26108
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    vector<char> vec{'M', 'A', 'R', 'C', 'H'};
    map<char, long long> mp;
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < vec.size(); j++) {
            if(s[0] == vec[j]) mp[vec[j]]++;
        }
    }
    long long ans = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = i+1; j < 4; j++) {
            for (int l = j+1; l < 5; l++) {
                ans += mp[vec[i]] * mp[vec[j]] * mp[vec[l]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll  long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define vll vector<ll>
#define vlll vector<vll>
void findDivisors(ll n) 
{ 
  
    // Array to store the count 
    // of divisors 
    ll div[n + 1]; 
    memset(div, 0, sizeof div); 
  
    // For every number from 1 to n 
    for (ll i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (ll j = 1; j * i <= n; j++) 
            div[i * j]++; 
    } 
  
    // Print the divisors 
    ll ans=0;
    for (int i = 1; i <= n; i++) 
    ans+=i*div[i];
    cout<<ans<<endl;
         
} 
  
// Driver code 
int main() 
{ 
    ll n;
    cin>>n;
    findDivisors(n); 
  
    return 0; 
} 

Measured memory_bytes: 81724
#include<iostream>
#define maxn 105
using namespace std;

bool a[maxn];

int main(){
    int n,k;
    cin>>n>>k;
    int d;
    for(int i=1;i<=k;i++){
    	cin>>d;
    	for(int j=1;j<=d;j++){
    		int res;
    		cin>>res;
    		a[res] = 1;
		}
	}
	int tot =0;
	for(int i=1;i<=n;i++){
		if(a[i]==0) tot++;
	}
	cout<<tot<<endl;
	return 0;
} 

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,int> P;
P a[100005];
int n,m;
int sti;
int en;
int N;
P mpop();
void mpush(P);
int main(){
  cin >> n >> m;
  N=n;
  en=n-1;
  for(int i=0;i<n;i++){
    cin >> a[i].first >> a[i].second;
  }
  int co=0;
  while(n!=0){
     P x=mpop();
     n--;
     if(x.second<=m){
       co+=x.second;
       cout << x.first << " " << co << endl;
     }
     else{
       co+=m;
       x.second-=m;
       mpush(x);
       n++;
     }
  }
  return 0;
}
P mpop(){
  P re;
  // cout << "pop" << endl;
  while(a[sti].second==-1){
    sti++;
    if(sti>=N)sti=0;
  }
  re = a[sti];
  a[sti].second=-1;
  while(a[sti].second==-1&&n!=1){
    sti++;
    if(sti>=N)sti=0;
  }
  return re;
}
void mpush(P p){
  //cout << "push" << endl;
  en++;
  if(en==N)en=0;
  a[en]=p;
  while(a[sti].second==-1){
    sti++;
    if(sti>=N)sti=0;
  }
}

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

int main(void){
	int n;
	scanf("%d", &n);
	int *a = malloc(sizeof(int) * n);
	int sum = 0;
	a[n - 1] = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", a + i);
		sum ^= a[i];
		//a[i] ^= a[(i + n - 1) % n];
	}
	for(int i = 0; i < n; i++){
		printf("%d\n", sum ^ a[i]);
	}
	return 0;
}


Measured memory_bytes: 3300
#include<stdio.h>
#define   MAX 100
#define   BLACK 2
#define   GRAY 1
#define   WHITE 0
#define   INFTY 5000000

int n, Mi[MAX][MAX];

int function()
{
   int k, MinMinu;
   int di[MAX], pi[MAX], color[MAX];
   int i, u, sum = 0;

   for (i=0; i<n; i++){
      di[i] = INFTY;
      pi[i] = -1;
      color[i] = WHITE;
   }

   di[0] = 0;

   while (1){
      MinMinu = INFTY;
      k = -1;
      for (i=0; i<n; i++){
         if (MinMinu>di[i] && color[i]!=BLACK){
            k = i;
            MinMinu = di[i];
         }
      }
      if (k==-1)
         break;
      color[k] = BLACK;
      for (u=0; u<n; u++){
         if (color[u]!=BLACK && Mi[k][u]!=INFTY){
            if (di[u]>Mi[k][u]){
               di[u] = Mi[k][u];
               pi[u] = k;
               color[u] = GRAY;
            }
         }
      }
   }

   for (i=0; i<n; i++){
      if (pi[i]!=-1)
         sum += Mi[i][pi[i]];
   }
   return sum;
}

/*
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d",M[i][j]);
if(j != n)
{
printf(" ");
}
}
printf("\n");
}
*/

int main()
{
   int i, j, k;

   scanf("%d", &n);

   for (i=0; i<n; i++){
      for (j=0; j<n; j++){
         scanf("%d", &k);
         Mi[i][j] = (k==-1) ? INFTY : k;
      }
   }

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

   return 0;
}



Measured memory_bytes: 2084
from collections import deque

LARGE = 10 ** 9 + 7


def solve(n, a_list, b_list):
    # root at 0
    g = [[] for _ in range(n)]
    for i in range(n - 1):
        a = a_list[i] - 1
        b = b_list[i] - 1
        g[a].append(b)
        g[b].append(a)

    parent = [-1] * n
    children = [[] for _ in range(n)]
    depth = [0] * n

    # find parent
    queue = deque([0])
    while len(queue) > 0:
        p = queue.popleft()
        for q in g[p]:
            if q == parent[p]:
                continue
            parent[q] = p
            children[p].append(q)
            depth[q] = depth[p] + 1
            queue.append(q)

    # weight
    weight = [1] * n
    deeper = list(sorted([[i, depth[i]] for i in range(n)], key=lambda x: x[1], reverse=True))
    for i, _ in deeper:
        for j in children[i]:
            weight[i] += weight[j]

    # calc
    res_array = [0] * n
    # P(i is not hole | i is white) = (other than one child( + parent) are all white)
    for i in range(1, n):
        for j in children[i]:
            res_array[n - 1 - weight[j]] += 1
        res_array[weight[i] - 1] += 1
        res_array[n - 1] -= len(children[i])
    for j in children[0]:
        res_array[n - 1 - weight[j]] += 1
    res_array[n - 1] -= len(children[0]) - 1
    # print(res_array)

    res_a = pow(2, n - 1, LARGE) * n
    res_a %= LARGE
    # print(res_a)
    for i in range(n):
        res_a -= pow(2, n - i - 1, LARGE) * res_array[i]
        res_a %= LARGE
        # print(res_a)
    res_b = pow(2, n, LARGE)

    res = res_a * pow(res_b, LARGE - 2, LARGE) % LARGE
    # print(res_a, res_b)
    return res


def main():
    n = int(input())
    a_list = [0] * (n - 1)
    b_list = [0] * (n - 1)
    for i in range(n - 1):
        a, b = map(int, input().split())
        a_list[i] = a
        b_list[i] = b
    res = solve(n, a_list, b_list)
    print(res)


def test():
    assert solve(3, [1, 2], [2, 3]) == 125000001
    assert solve(4, [1, 2, 3], [2, 3, 4]) == 375000003
    assert solve(4, [1, 1, 1], [2, 3, 4]) == 250000002


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 127268
line = input()

MM_set = set([i+1 for i in range(12)])

first = int(line[:2])
second = int (line[2:])
if first in MM_set and second in MM_set:
  print("AMBIGUOUS")
elif first in MM_set and second not in MM_set:
  print("MMYY")
elif not first in MM_set and second in MM_set:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int N,K;
int R,S,P;
string T;

#define MAXN 100000
ll score[MAXN];
int main(){
    char data[MAXN*2+1];
    cin >> N >> K >> R >> S >> P >> T;
    rep(i,N)score[i] = 0;
    rep(i,2*N){
        data[i] = 0;
    }
    rep(i,N){
        if(T[i]=='s'){
            T[i] = 'r';
            
        }else if(T[i]=='r'){
            T[i]='p';
        }else T[i]='s';
    }
    for(int i=0;i<N;i++){
        if(T[i]=='s')score[i] = S;
        if(T[i]=='r')score[i] = R;
        if(T[i]=='p')score[i] = P;
    }

    ll ans = 0;
    for(int i=0;i<N;i++){
        if(T[i]=='s' && data[i]!='s'){
            ans += S;
            data[i+K]='s';
        }else if(T[i]=='r' && data[i]!= 'r'){
            ans += R;
            data[i+K]='r';
        }else if(T[i]=='p' && data[i]!= 'p'){
            ans += P;
            data[i+K]='p';
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=a[:]
b.sort()
if a == b:
    print("YES")
    sys.exit()
for i in range(n):
    for j in range(i+1,n):
        a[i],a[j]=a[j],a[i]
        if a==b:
            print("YES")
            sys.exit()
        a[i],a[j]=a[j],a[i]
print("NO")

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

int main(){
    int N, ans = 0;
    cin >> N;
    vector<int> P(N+1);
    for(int i = 1; i <= N; ++i) cin >> P[i];
    int buf = 2*pow(10,6);
    for(int i = 1; i <= N; ++i){
        if(buf >= P[i]){
            buf = P[i];
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    string s;
    int K;
    cin >> s >> K;
    set<string> ss;
    rep(i, s.size()){
        for(int j = 1; j <= K && i + j <= s.size(); j++){
            string tmp = s.substr(i, j);
            ss.insert(tmp);
        }
    }
    string ans;
    auto i = ss.begin();
    for(int j = 0; j < K - 1; j ++){
        i ++;
    }
    cout << *i << endl;

    return 0;
}


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


Measured memory_bytes: 2100
values1 = raw_input()
values2 = raw_input()
values3 = raw_input()

n,m,X,Y = values1.split(" ")
X = int(X)
Y = int(Y)
x =sorted([int(i) for i in values2.split(" ")]+[X])
y = sorted([int(i) for i in values3.split(" ")]+[Y])

if x[-1]<y[0]:
	print("No War")
else:
	print("War")

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

using namespace std;

int main()
{
    int n, k,price[1001],total = 0;

    cin >> n >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> price[i];
    }

    sort(price,price+n);

    for(int i = 0; i < k; i++)
        total = total + price[i];

    cout << total;
}

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

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

using namespace std;

using ll = unsigned long long int;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<ll> s(n, 0);
  rep(i, m)
  {
    int tmp;
    cin >> tmp;
    s[tmp] = 1;
  }
  ll dp[n+1] = {0};
  ll mod = 1000000007;
  dp[0] = 1;
  if (s[1] == 1) dp[1] = 0;
  else dp[1] = 1;
  for(int i = 2; i <= n; ++i){
    if (s[i - 1] == 1) dp[i - 1] = 0;
    if (s[i - 2] == 1) dp[i - 2] = 0;
    dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

//redが行きうる全ての箱の個数

int main(){
    ll n,m;cin>>n>>m;
    vector<bool> possible(100010,0);
    vector<ll> how_many(n,1);//箱にあるボールの個数
    possible[0]=true;

    for(ll i=0;i<m;i++){
        ll x,y;cin>>x>>y;
        x--;y--;
        if(possible[x]==true && how_many[x]>0){possible[y]=true;}
        if(how_many[x]>0){how_many[x]--;how_many[y]++;}
        if(how_many[x]==0){possible[x]=false;}
    }

    ll ans=0;
    for(ll i=0;i<n;i++){
        if(possible[i] && how_many[i]>0){ans++;}
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
int data[15],p,n;
p=0;
while(scanf("%d",&n)!=EOF){
   if(n==0){printf("%d\n",data[p-1]);data[p-1]=0;p--;}
   else {
      data[p]=n;p++;
   }
}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
 
using namespace std;
 
 
#define MAXN 200001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a[MAXN], b[MAXN];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i]--;
    b[a[i]] = i;
  }
  int cur = 0, ans = 0;
  for (int i = 1; i < n; ++i) {
    if (b[i]>b[i-1]) {
      cur++;
    } else {
      ans = max(ans, cur);
      cur = 0;
    }
  }
  ans = max(ans, cur);
  cout << n-ans-1 << endl;
  return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(input())
restrict = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i):
	global restrict
	if not restrict:
		return min_number
	for s in range(10):
		if (str(s) not in d_ng_list) and str(s) >= n_price[i]:
			if s > int(n_price[i]):
				restrict = False
			return str(s)
	#if not found
	restrict = False
	return str(min_number+min_number)

def rec_cal_pay(answer, i, restrict):
	if i == n_length-1:
		answer += find_number(i)
		print(answer)
		return
	else:
		c = find_number(i)
		rec_cal_pay(answer+c, i+1, restrict)

rec_cal_pay(answer, 0, restrict)


Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		int n = sc.nextInt();
		calc(n);
	}
	public void calc(int n){
		int counter = 0;
		String ans = "NO";
		for(int i = 0; i < n; i++){
			String s = sc.next();
			if(s.equals("A")) counter++;
			else if(s.equals("Un")) counter--;
			
			if(counter < 0) break; 
		}
		
		if(counter == 0) ans = "YES";
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 26276
#include <iostream>
using namespace std;
#define min(x,y) (x>y?y:x)

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

	for(int i=0;i<n;i++){
		int x,y,b,p,sum=0,ssum=0;
		cin>>x>>y>>b>>p;
		sum=x*b+y*p;
		if(b>=5 && p>=2){sum*=4;sum/=5;cout<<sum<<endl;continue;}
		else if(b<5){
			ssum=(p<2?sum+x*(5-b)+y*(2-p):sum+x*(5-b));
			ssum*=4;ssum/=5;
		}else if(p<2){
			ssum=sum+y*(2-p);
			ssum*=4;ssum/=5;
		}
		cout<<min(sum,ssum)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#define DEBUG
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define F first
#define S second 
#define pb push_back
 
#define endl "\n"
 
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
 
#ifdef DEBUG
    #define dbg(s) {s;}
#endif
 
#ifndef DEBUG
    #define dbg(s)
#endif
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, x-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}
 
#define i32 int32_t
#define int ll
 
#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define all(v) (v).begin(),(v).end()
 
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 998244353;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}
 
const int maxn = 3e6 + 7;
 
const ll inf = 1e9 + 7;

ll fact[maxn];
ll facti[maxn];

void precalc()
{
    fact[1] = 1;
    fact[0] = 1;
    facti[1]=1;
    facti[0] = 1;
    for(ll i=2;i<maxn;i++)
    {
        fact[i] = (fact[i-1]*1ll*i)% mod;
        facti[i] = modexp(fact[i],mod-2);
    }
}

ll C(ll n, ll k)
{
    if(k<0)
        return 0;
    if(n<k)
        return 0;
    ll ans = (((fact[n]*facti[n-k])%mod) *facti[k])%mod;
    return ans;
}

i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);
 
    IOS; 
    precalc();
    
    ll n,m;
    cin>>n>>m;
    
    ll total = C(m+m+m+n-1,n-1);
    
    ll part1 = 0;
    ll u,v,sum;
    for(ll k=m+m+1;k<=m+m+m;k++)
    {
        u = m+m+m-k;
        v = (C(u+n-2,n-2)*n)%mod;
        part1+=v;
        part1%=mod;
    }
    //cout<<part1<<endl;
    ll part2 = 0;
    for(ll k=m+1;k<=n;k++)
    {
        u = C(n,k);
        sum= m+m+m-k;
        if(sum%2)
            continue;
        sum/=2;
        v = C(sum+n-1,n-1);
        sum= (u*v)%mod;
        part2+=sum;
    }
    part2%=mod;
    
    
    ll ans = total + mod - part1 + mod - part2;
    ans%=mod;
    
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 47232
S = input()
def dfs(i, formula, ans_formula):
    # ベースケース
    if i == len(formula):
        ans_formula.append(formula)
        return formula

    # +を入れる場合
    dfs(i+2, formula[:i] + '+' + formula[i:], ans_formula)
    
    # +を入れない場合
    dfs(i+1, formula, ans_formula)

ans_formula = []
dfs(1, S, ans_formula)

ans = 0
for i in range(len(ans_formula)):
    ans += sum(list(map(int, ans_formula[i].split('+'))))

print(ans)

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

int main() {
  for(int W, H, N; cin >> W >> H >> N && (W|H|N); ) {
    N *= 2;
    vector<double> x(N), y(N);
    for(int i = 0; i < N; ++i) {
      cin >> x[i] >> y[i];
    }
    x.push_back(W);
    y.push_back(0);
    x.push_back(W);
    y.push_back(H);

    vector<double> ys = y;
    for(int i = 0; i < x.size(); ++i) {
      for(int j = i+1; j < x.size(); ++j) {
        double a = (y[i] - y[j]) / (x[i] - x[j]);
        double b = y[i] - a * x[i];
        if(0 < b && b < H) ys.push_back(b);
      }
    }
    sort(ys.begin(), ys.end());
    double res = 0;
    for(int i = 0; i+1 < ys.size(); ++i) {
      double m = (ys[i] + ys[i+1]) / 2.0;
      vector<pair<double, int> > v;
      for(int j = 0; j < N; ++j) {
        v.push_back(make_pair((y[j] - m) / x[j], j));
      }
      sort(v.begin(), v.end());
      int s = v[N/2-1].second;
      int t = v[N/2].second;
      double y1 = (y[s] - m) / x[s] * W + m;
      double y2 = (y[t] - m) / x[t] * W + m;
      double w = min((double)H, y2) - max(0.0, y1);
      if(w <= 0.0) continue;
      res += (ys[i+1] - ys[i]) * w / pow((double)H, 2.0);
    }
    printf("%.10f\n", res);
  }
  return 0;
}

Measured memory_bytes: 1396
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();

		while(a>0&&c>0) {
			a-=d;
			c-=b;
		}

		if (c<=0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	    scan.close();	
    }
}

Measured memory_bytes: 35800
# ITP_11_C
class Dice :
    def __init__(self, dice) :
        self.dice = dice
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]

    def check_dice(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def dice_top(self):
        print(self.dice[0])
    
dice1 = Dice(list(map(str, input().split())))
dice2 = Dice(list(map(str, input().split())))

judge = dice1.check_dice(dice2)
if judge == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5572
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <istream>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define vec vector<int>a(n)
#define soot(a) sort(a.begin(),a.end())
/*int n;
cin >> n;
vector<int>a(n);
rep0(i, n - 1)cin >> a[i];*/
using namespace std;
int main() {
int n;
cin >> n;
vector<long long int >a(n);
rep0(i, n - 1)cin >> a[i];
soot(a);
cout << a[n - 1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
//************************
//*  Date: 2018.11.2     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,ans;
double t,a,tmp[1010],mn=(double)1e9;

int main()
{
	cin>>n>>t>>a;
	rep(i,n)
	{
		cin>>tmp[i];
		tmp[i]=t-tmp[i]*(double)0.006;
		if(abs(tmp[i]-a)<mn)
		{
			mn=abs(tmp[i]-a);
			ans=i+1;
		}
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))

r = list(map(int, input().split()))
for i in range(X):
    r.append(p[A-i-1])
for i in range(Y):
    r.append(q[B-i-1])
r.sort()

print(sum(r[len(r) - X - Y:]))

Measured memory_bytes: 23200
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int arr[26];

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		arr[s[i] - 'A']++;
	int cnt = 0;
	for (int i = 0; i < 26; i++)
		if (arr[i] == 2)cnt++;
	if (cnt == 2)printf("Yes");
	else
		printf("No");
}

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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) cout << "Left" << endl;
    else if (a + b == c + d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];

    unordered_set<string> s;
    rep(i, N) s.insert(S[i]);
    cout << s.size() << endl;
}


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

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

    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
        data.at(i) -= i;
    }

    sort(data.begin(), data.end());

    int64_t b = 0, min = 0;
    if (n % 2 == 0){
        int64_t min1 = 0, min2 = 0;
        b = data.at(n / 2);
        for (int i = 0; i < n; i++){
            min1 += abs(data.at(i) - b);
        }
        b = data.at(n / 2 - 1);
        for (int i = 0; i < n; i++){
            min2 += abs(data.at(i) - b);
        }

        min = (min1 < min2 ? min1 : min2);
    }
    else{
        b = data.at(n / 2);
        for (int i = 0; i < n; i++){
            min += abs(data.at(i) - b);
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		String[] a = new String[n];
		for(int i=0;i<n;i++){
			a[i]=scan.next();
		}
		scan.close();
		for(int i=n-1;i>=1;i--){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
	}

}

Measured memory_bytes: 17332
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;
typedef tree<
        pair<int, int>, // change type
        null_type,
        less<pair<int, int> >, // change type
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);


int n, m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    cin >> n >> m;
    vector<int> a(m);
    rep(i,0,m)
        cin >> a[i];
    sort(all(a));
    vector<int> diff(m);
    rep(i,1,m)
    {
        diff[i] = a[i] - a[i - 1];
    }
    sort(all(diff));
    ll ans = 0;
    for (int i = 0; i < sz(diff) - n + 1; ++i)
        ans += diff[i];
    cout << ans;

    return  0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll H,W,D,Q;
    cin >> H >> W >> D;
    vector<vector<ll>> A(H,vector<ll>(W));
    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
        }
    }
    cin >> Q;
    vector<ll> L(Q), R(Q);
    rep(i,Q){
        cin >> L[i] >> R[i];
    }
    map<ll,Pll> mp;
    rep(i,H){
        rep(j,W){
            mp[A[i][j]] = Pll(i,j);
        }
    }
    vector<ll> S(H*W+1);
    rep(i,H*W+1){
       if(i-D>=0){
           S[i] = S[i-D] + abs(mp[i].fi - mp[i-D].fi) + abs(mp[i].se - mp[i-D].se);
       } 
    }
    rep(i,Q){
        cout << S[R[i]] - S[L[i]] << endl;
    }
}


Measured memory_bytes: 11968
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var k = cin.nextInt();
            var snk = new int[n];
            for (int i = 0; i < k; i++)
            {
                var d = cin.nextInt();
                var a = cin.ArrayInt(d);

                foreach (var item in a)
                {
                    snk[item - 1]++;
                }
            }

            var ans = 0;
            for (int i = 0; i < snk.Count(); i++)
            {
                if (snk[i] == 0) ans++;
            }

            
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 28356
#include<stdio.h>
#define N 100
#define GRAY 1
#define WHITE 0
#define BLACK 2

void dfs_visit(int );
void dfs();
void M_scan(int *);

int M[N][N];
int d[N],f[N],color[N];
int t,n;

int main(){

  M_scan(&n);
  dfs();

  return 0;
}

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++t;

  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE) dfs_visit(v);
  }
  color[u]=BLACK;
  f[u]=++t;
}

void dfs(){
  int u=0;
  for(u=0;u<n;u++) color[u]=WHITE;
  t=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
    }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

void M_scan(int *n){
  int m,i,j;
  int nm,cn;
  int nn;
  scanf("%d",&(*n));
  nn=*n;
  for(i=0;i<nn;i++){
    for(j=0;j<nn;j++) M[i][j]=0;
  }
  for(i=0;i<nn;i++){
    scanf("%d %d",&nm,&m);
    for(j=0;j<m;j++){
      scanf("%d",&cn);
      M[nm-1][cn-1]=1;
    }
  } 
}



Measured memory_bytes: 2104
A, B, C, K = list(map(int, input().strip().split()))
sum = 0

# for i in range(K):
# 	if A > 0:
# 		sum += 1
# 		A -= 1
# 	elif B > 0:
# 		B -= 1
# 	else:
# 		sum -= 1
# 		C -= 1

# print(sum)

if K <= A:
	sum += K
	print(sum)
else:
	sum += A
	K -= A
	if K <= B:
		print(sum)
	else:
		K -= B
		sum -= K
		print(sum)
	




	

Measured memory_bytes: 9180
#include<iostream>
#include<vector>
using namespace std;
const long long int mod=1e9+7;


long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {

int can_use_color_num;
if (from==-1) {
can_use_color_num=K-1;
}
else {
can_use_color_num=K-2;
}
if (K<graph[now].size()) {
return 0;
}
else {
long long int case_num=1;
for (auto e : graph[now]) {
if(e==from)continue;

case_num*=can_use_color_num;
can_use_color_num--;
case_num%=mod;
}
for (auto e : graph[now]) {
if(e==from)continue;

case_num *=dfs(K,graph,e,now);
case_num %= mod;
}
return case_num;
}
}

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

vector<vector<int>>graph(N);
for (int i = 0; i < N - 1; ++i) {
int a,b;cin>>a>>b;a--;b--;

graph[a].push_back(b);
graph[b].push_back(a);
}

long long int answer=K*dfs(K,graph,0,-1);
answer%=mod;
cout<<answer<<endl;
return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll n,a,b,c,d,e;
void input(){
    fast_io();
    cin >> n >> a >> b >> c >> d >> e;
}

int solve(){
    ll bn = min({a,b,c,d,e});
    ll t = (n+bn-1)/bn;
    ll ans = t+4;
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
/*
[abc104] D - We Love ABC
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;
const ll MOD = 1e9 + 7;
const int K = 3;

string S;
int N;
ll dp[K + 1][MAX_N + 1];

ll solve() {
    dp[0][0] = 1;

    for (int k = 0; k <= K; k++) {
        for (int i = 1; i <= N; i++) {
            ll p = ((S[i - 1] == '?') ? 3 : 1) * dp[k][i - 1];
            ll q = (k > 0 && (S[i - 1] == ('A' + k - 1) || S[i - 1] == '?'))
                       ? dp[k - 1][i - 1]
                       : 0;
            dp[k][i] = (p + q) % MOD;
        }
    }

    return dp[K][N];
}

int main() {
    cin >> S;
    N = S.size();

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

long long calcGcd(long long a, long long b) {
    // a > bにする
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法*/
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

long long calcLcm(long long a, long long b) {
    // a > bにする
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    return a / calcGcd(a, b) * b;
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    // cまたはdで割り切れるものの個数を求め、それをa以上b以下の整数の個数から引く
    // cまたはdで割り切れるものの個数はベン図より
    // cで割り切れるものの個数+dで割り切れるものの個数 - cでもdでも割り切れるものの個数で求められる
    // 1からbまでの範囲の個数から1からaまでの範囲の個数を引けば求める範囲の個数となる

    // a以上b以下の整数の個数
    long long all = b - a + 1;

    // c, d, cとdで割り切れるものの個数
    long long divided_c, divided_d, divided_lcm;

    // b以下の個数 - a未満の個数
    divided_c = b / c - (a - 1) / c;
    divided_d = b / d - (a - 1) / d;
    divided_lcm = b / calcLcm(c, d) - (a - 1) / calcLcm(c, d);

    long long ans = all - (divided_c + divided_d - divided_lcm);

    cout << ans << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
string s,t,ans="";
int j;
int main()
{
    cin>>s>>t;
    if(s.length()<t.length())
	{
        cout<<"UNRESTORABLE";
        return 0;
    }
    for(int i=0;i<=s.length()-t.length();i++)
	{
        int k=i;
        string hsy=s;
        j=0;
        while(j<t.length())
		{
            if(hsy[k]=='?')
                hsy[k]=t[j];
            else if(s[k]!=t[j])
                break;
            k++;
            j++;
        }
        if(j==t.length())
		{
            for(int r=0;r<hsy.length();r++)
			{
                if(hsy[r]=='?')
                    hsy[r]='a';
            }
            if(ans=="")
                ans=hsy;
            else 
				ans=min(ans,hsy);
        }
    }
    if(ans=="")
        cout<<"UNRESTORABLE";
    else 
		cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
typedef map<ll, ll> Map;

int main(void) {
    ll a, b;
    cin >> a >> b;
    if(a<=0 && b>=0) {
        printf("Zero\n");
    }else if(a>0) {
        printf("Positive\n");
    }else {
        if((b-a)%2==0) {
            printf("Negative\n");
        }else {
            printf("Positive\n");
        }
    }
    
    
    
    
}


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

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

using namespace std;

void solve() {
    int h, w, d;
    cin >> h >> w >> d;
    if (d % 2) {
        rep(i, h) {
            rep(j, w) {
                cout << ((i + j) % 2 ? "R" : "Y");
            }
            cout << endl;
        }
        return;
    } else {
        d /= 2;
        rep(i, h) {
            rep(j, w) {
                string colors = "RGBY";
                int x = (j + i) / 2;
                int y = (w + i - j) / 2;
                int color = ((x / d) % 2) * 2 + (y / d) % 2;
                cout << colors[color];
            }
            cout << endl;
        }
    }
}

int main() {
    solve();
    return 0;
}


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

int main() {
	/*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
     cout<<max(a*c,max( b*d,max(a*d,b*c)) );
	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<long long, long long>> v;
	for(int i = 0; i < n; i++){
		long long x, l;
		cin >> x >> l;
		v.emplace_back(x-l, x+l-1);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	long long lim = -1e9-7;
	for(int i = 0; i < n; i++){
		if(v[i].first > lim){
			lim = v[i].second;
			ans++;
		}
		else lim = min(lim, v[i].second);
	}
	cout << ans << endl;
	return 0;
}

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

//  a < b ?
bool izryt(int h, int m, int d, int H, int M, int D) {
  if (h < H) return true;
  if (h > H) return false;

  if (m < M) return true;
  if (m > M) return false;

  return d < D;
}

void diff(int H, int h, int m, int d) {
  cout << h - H + 1 << " " << m << " " << d << endl;
}

void solve(int h, int m, int d) {
  if (izryt(h, m, d, 1868, 9, 8)) {
    cout << "pre-meiji" << endl;
  }

  else if (izryt(h, m, d, 1912, 7, 30)) {
    cout << "meiji ";
    diff(1868, h, m, d);
  }

  else if (izryt(h, m, d, 1926, 12, 25)) {
    cout << "taisho ";
    diff(1912, h, m, d);
  }

  else if (izryt(h, m, d, 1989, 1, 8)) {
    cout << "showa ";
    diff(1926, h, m, d);
  }

  else {
    cout << "heisei ";
    diff(1989, h, m, d);
  }
}

int main() {
  int h, m, d;
  while (cin >> h >> m >> d) {
    solve(h, m, d);
  }
}

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

int main() {
    int H,W;
    cin >> H >> W;
    int h,w;
    cin >> h >> w;
    cout << H*W - h*W - w*H + h*w<< endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

A = list(map(int, input().split()))

cnt = 0

for i in range(n - 1):
    min_i = i
    for j in range(i + 1, n):
        if A[min_i] > A[j]:
            min_i = j
    if min_i != i:
        A[min_i], A[i] = A[i], A[min_i]
        cnt += 1

print(' '.join(map(str, A)))
print(cnt)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << "Hello World" << endl;
  }else{
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;

int main(void){
  int a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node{
 int key;
 Node *right,*left,*parent;
};
Node *root,*NIL;
void insert(int k){
 Node *y=NIL;
 Node *x=root;
 Node *z;
 z=(Node *)malloc(sizeof(Node));
 z->key=k;
 z->left=NIL;
 z->right=NIL;
 while(x!=NIL){
  y=x;
  if(z->key<x->key) x=x->left;
  else x=x->right;
 }
 z->parent=y;
 if(y==NIL)root=z;
 else {
  if(z->key<y->key)y->left=z;
  else y->right=z;
 }
}
void inorder(Node *u){
 if(u==NIL)return;
 inorder(u->left);
 printf(" %d",u->key);
 inorder(u->right);
}
void preorder(Node *u){
 if(u==NIL)return;
 printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);
}
int main(){
 int n,i,x;
 string com;
 scanf("%d",&n);
 for(i=0;i<n;i++){
  cin>>com;
  if(com=="insert"){
   scanf("%d",&x);
   insert(x);
  }else if(com=="print"){
   inorder(root);
   printf("\n");
   preorder(root);
   printf("\n");
  }
 }
 return 0;
}


Measured memory_bytes: 26680
import kotlin.math.abs
import kotlin.math.max

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toLong() }
    val b = a.mapIndexed { i, l -> i to l }.sortedByDescending { it.second }.map { it.first }.toIntArray()
    val dp = Array(n + 1) { LongArray(n + 1) }

    for (i in 0 until n) {
        for (j in 0 until n) {
            if (i + j == n) break
            val idx = b[i + j]
            dp[i][j + 1] = max(dp[i][j] + a[idx] * abs(idx - j), dp[i][j + 1])
            dp[i + 1][j] = max(dp[i][j] + a[idx] * abs(n - 1 - idx - i), dp[i + 1][j])
        }
    }

    (0 until n)
            .map { dp[it][n - it] }
            .max()
            .let { println(it) }
}


Measured memory_bytes: 82988
#include<stdio.h>

void quicksort(int a[], int left, int right){
    int p;
	int L = left, R = right;
	int temp;
	p = a[(left + right) / 2];

	while (1){
		while (a[L] < p) L++; while (a[R] > p)
			R--;
		
		if (L >= R)
			break;

		temp = a[R];
		a[R] = a[L];
		a[L] = temp;

		L++;
		R--;
	}
	if (left < L - 1) quicksort(a, left, L - 1);
     if (right > R + 1)quicksort(a, R + 1, right); 
	
}

int main(){
    int a, b, n, i, j;
    int A[100000];
    int tmp;
    int x = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    quicksort(A, 0, n - 1);
    a = n/2;
    x = A[a] - A[a-1];
    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 512