akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
ll abs(ll a,ll b){
    return(a>b?a-b:b-a);
}

int main(){
    int n;
    cin >> n;
    vi a(n);
    rp(i,n){
        cin >> a.at(i);
    }
    if(n%2==0){
        mrp(i,n/2){
            cout << a.at(2*i+1) << ' ';
        }
        rp(i,n/2-1){
            cout << a.at(2*i) << ' ';
        }
        cout << a.at(n-2) << endl;
    }else if(n%2==1){
        mrep(i,n/2,0){
            cout << a.at(2*i) << ' ';
        }
        rep(i,0,n/2-1){
            cout << a.at(2*i+1);
            if(i<n/2-1){
                cout << ' ';
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 2944
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
    int n;

    cin >> n;
    int a[105];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int m = -1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            m = max(m, abs(a[i] - a[j]));
        }
    }

    cout << m << endl;

    return 0;
}


Measured memory_bytes: 3560
hash = {}
sep = "#"*20
(1..4).each do |b|
    (1..3).each do |f|
        (1..10).each do |r|
            hash["#{b}#{f}#{r}"]=0
        end
    end
end

gets.chomp.to_i.times do
    b,f,r,v = gets.chomp.split.map(&:to_i)
    hash["#{b}#{f}#{r}"] += v
end

(1..4).each do |b|
    (1..3).each do |f|
        (1..10).each do |r|
            print " " + hash["#{b}#{f}#{r}"].to_s
        end
        puts
    end
    puts sep unless b > 3
end

Measured memory_bytes: 6104
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]


for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if i > 0 and s[i-1][j] == "#":
                continue
            elif i < H-1 and s[i+1][j] == "#":
                continue
            elif j > 0 and s[i][j-1] == "#":
                continue
            elif j < W - 1 and s[i][j+1] == "#":
                continue

            else:
                print("No")
                exit(0)

print("Yes")


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

mod = 998244353
n,m,k = map(int,input().split())
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod




res = 0

tmp = m*pow(m-1,n-k-1,mod)

for r in range(n-k-1,n):
    res = (res + tmp*mod_comb_k(n-1,r,mod)%mod)%mod
    tmp = tmp*(m-1)%mod

print(res)

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

int main(void) {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        int x = (int)pow(2, i);
        if (x <= n) ans = x;
        else break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  std::vector<ll> v(NN);

  for (size_t i = 0; i < NN; i++) {
    std::cin >> v[i];
  }

  std::sort(v.begin(), v.end());

  // for (size_t i = 0; i < NN; i++) {
  //   std::cout << v[i] << '\n';
  // }

  ll sum, r_num, l_num;
  ll small = 0, big = 0;
  for (size_t i = 0; i < NN; i++) {
    if (i == 0) {
      r_num = v[small];
      l_num = v[small];
      sum = 0;
      small += 1;
    }else{
      if (i%4 == 1 || i%4 == 2) {
        if (i%4 == 1) {
          sum += abs(r_num - v[NN -1 - big]);
          r_num = v[NN -1 - big];
          big +=1;
        }else{
          sum += abs(l_num - v[NN -1 - big]);
          l_num = v[NN -1 - big];
          big +=1;
        }
      }else{
        if (i%4 == 3) {
          sum += abs(r_num - v[small]);
          r_num = v[small];
          small +=1;
        }else{
          sum += abs(l_num - v[small]);
          l_num = v[small];
          small +=1;
        }
      }
    }
  }

  std::sort(v.begin(), v.end(), std::greater<int>());

  ll sum2;
  small = 0, big = 0;
  for (size_t i = 0; i < NN; i++) {
    if (i == 0) {
      r_num = v[small];
      l_num = v[small];
      sum2 = 0;
      small += 1;
    }else{
      if (i%4 == 1 || i%4 == 2) {
        if (i%4 == 1) {
          sum2 += abs(r_num - v[NN -1 - big]);
          r_num = v[NN -1 - big];
          big +=1;
        }else{
          sum2 += abs(l_num - v[NN -1 - big]);
          l_num = v[NN -1 - big];
          big +=1;
        }
      }else{
        if (i%4 == 3) {
          sum2 += abs(r_num - v[small]);
          r_num = v[small];
          small +=1;
        }else{
          sum2 += abs(l_num - v[small]);
          l_num = v[small];
          small +=1;
        }
      }
    }
  }

  if (sum < sum2) {
    sum = sum2;
  }

  std::cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int fn(0);
if(a!=2)
{
if((b!=30&&b!=31)||d!=1)
fn=1;
}
if(a==2&&b!=28)
fn=1;
if(a==12&&c!=1)
fn=1;
if(c-a!=1&&a!=12)
fn=1;
if(a<=7&&a!=2)
{
if(a%2==1&&b!=31)
fn=1;
if(a%2==0&&b!=30)
fn=1;
}
else if(a>7)
{
if(a%2==0&&b!=31)
fn=1;
if(a%2==1&&b!=30&&a!=8)
fn=1;
}
if(fn==0)
cout<<1;
else
cout<<0;
}


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


class C
{
    static int[,] m=new int[101,101];
    static int[] p=new int[101];
    public static void Main() {
        int n = int.Parse(System.Console.ReadLine());
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < n; i++) {
            string x = Console.ReadLine();
            string y = Console.ReadLine();
            output.AppendLine(LCSLength(x, y).ToString());
        }
        Console.Write(output);
    }
    public static int LCSLength(string x, string y) {
        int m = x.Length;
        int n = y.Length;
        x = " " + x;
        y = " " + y;
        int max = 0;
        int[,] c = new int[1001, 1001];
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                if (x[i] == y[j]) {
                    c[i, j] = c[i - 1, j - 1] + 1;
                }else if (c[i - 1, j] >= c[i, j - 1]) {
                    c[i, j] = c[i - 1, j];
                } else {
                    c[i, j] = c[i, j - 1];
                }
                max = Math.Max(max, c[i, j]);
            }
        }
        return max;
    }
}


Measured memory_bytes: 34936
#include <stdio.h>
#include <string.h>
#define N 4
#define MAX 1000
#define INF -1



typedef struct {
  int ban[N*N], sp, MD, p[N][N];  
}Record;



void IDA(Record); 
int Manhat(Record);
int dfs(int, int);





int cnt = 0, ans[N][N], size, limit, stack[N], time, path[100];
int dx[4] = {0, -1, 0, 1}; //四方向
int dy[4] = {1, 0, -1, 0}; //四方向
int MDT[N*N][N*N];
char dir[4] = {'r','u','l','d'}; //右、上、左、下
char an[100];
Record data, in;


int main () {
  int i, j, k = 0, m = 0, l = 0;


  for(i = 0 ; i < N*N ; i++) {
    for(j = 0 ; j < N*N ; j++) {
      m = i / N - j / N;
      l = i % N - j % N;

      if(m < 0) m = -1 * m;
      if(l < 0) l = -1 * l;
      MDT[i][j] = m + l;
    }
  }



  for(i = 0 ; i < N*N ; i++) {
      scanf("%d",&in.ban[i]);

      if(in.ban[i] == 0) {
	in.ban[i] = N*N;
	in.sp = i;
      }
    
      //if(i * j != (N-1)*(N-1)) ans[i][j] = ++k;
  }

  IDA(in);
 

  printf("%d\n",strlen(an));

  return 0;
}



int Manhat(Record A) {
  int d = 0, i;
  
  for(i = 0 ; i < N * N ; i++) {
    if(A.ban[i] == N*N) continue;
    d += MDT[i][A.ban[i]-1];
  }

  return d;
}






int dfs(int def, int prev) {
  int sx = 0, sy = 0, i, j, tx = 0, ty = 0, max = 0, min = 0, t1;
  Record tmp;

  //printf("test\n");
  if(data.MD == 0) return 1;

  if(def + data.MD > limit) return -1;

  sx = data.sp / N;
  sy = data.sp % N;

  for(i = 0 ; i < 4 ; i++) {
    tx = sx + dx[i];
    ty = sy + dy[i];

    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;

    if(prev > i) {
      max = prev;
      min = i;
    }

    else {
      max = i;
      min = prev;
    }

    if(max - min == 2) continue;

    tmp = data;
    data.MD -= MDT[tx * N + ty][data.ban[tx * N + ty]-1]; //正解に近づいているか
    data.MD += MDT[sx * N + sy][data.ban[tx * N + ty]-1];
    t1 = data.ban[tx * N + ty];
    data.ban[tx * N + ty] = data.ban[sx * N + sy];
    data.ban[sx * N + sy] = t1;

    data.sp = tx * N + ty;

    if(dfs(def + 1, i) == 1) {
      path[def] = i;
      return 1;
    }

    data = tmp;
  }
  

  return -1;
}


void IDA(Record A) {
  int i, cnt = 0, j = 0;
  
  in.MD = Manhat(in);

  for(limit = in.MD ; limit <= 100 ; limit++) {
    data = in;

    if(dfs(0, -100) == 1) {
      for(i = 0 ; i < limit ; i++) {
   
	an[j] = dir[path[i]];
	j++;
      }
      //printf("test\n");
      an[j] = '\0';
      return;
    }

  }
  
}







Measured memory_bytes: 2108
def gcd(x, y):
    while y!=0:
        x, y = y, x%y
    return x

def process():
    n = int(raw_input().strip())
    if n%2 == 0:
        print str(n)+' '+str(n)+' '+str(n>>1)
        return
    for x in xrange(max(n>>1, 1), 3501):
        for y in xrange(x, 3501):
            b = n*x*y
            a = 4*x*y-n*x-n*y
            if a>0 and (b%a)==0:
                print str(x)+' '+str(y)+' '+str(b/a)
                return

process()

Measured memory_bytes: 2568
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    int a = n / 2;
    double t;
    if (n % 2 == 0) {
        t = (double)a / n * 1.0;
        
    } else {
        t = (double)(a + 1) / n * 1.0;
    }
    printf("%.10f\n", t);
    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "climits"
int num;
long long int magic;
int slime[2000];
int cost[2000];
long long int ans = LLONG_MAX;
long long box = 0;
int main() {
	scanf("%d %lld",&num, &magic);
	for (int i = 0; i < num; i++) {
		scanf("%d", &slime[i]);
	}
	for (int i = 0; i < num; i++) {
		cost[i] = slime[i];
	}
	for (long long int i = 0; i < num; i++) {
		for (int j = 0; j < num; j++) {
			if (cost[(j + i) % num] > slime[j])cost[(j + i) % num] = slime[j];
		}
		box = 0;
		for (int j = 0; j < num; j++) {
			//printf("%d ",cost[j]);
			box += cost[j];
		}
	//	printf("\n");
		if (ans > box + magic*i)ans = box + magic*i;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin>>N;
    vector<int> a(N),b(N);
    cin>>a>>b;

    int cnt=0,cnt2=0;
    REP(i,N) {
        if(a[i]<b[i]) {
            cnt+=(b[i]-a[i])/2;
        }
        if(a[i]>b[i]) cnt2+=a[i]-b[i];
    }
    if(cnt2>cnt) {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 384
def selection_sort a
  n = a.size
  0.upto(n - 1) do |i|
    mini = i
    i.upto(n - 1) do |j|
      mini = j if a[j] < a[mini]
    end
    unless i == mini
      a[i], a[mini] = a[mini], a[i]
      yield if block_given?
    end
  end
  a
end

n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)
cnt = 0

puts selection_sort(a) { cnt += 1 }.join(' ')
puts cnt

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)2e3+1;

void setIO(string name)
{
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}

int shortest[MAXN][MAXN];
int dp[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //setIO("");
    int n;
    int x, y;
    cin >> n >> x >> y;
    x--; y--;
    for(int i=0; i<n-1; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            shortest[i][j] = j-i;
            shortest[i][j] = min(shortest[i][j], abs(x-i) + 1 + abs(y-j));
            shortest[i][j] = min(shortest[i][j], abs(y-i) + 1 + abs(x-j));
            dp[shortest[i][j]]++;
        }
    }
    for(int i=1; i<=n-1; i++)
    {
        cout << dp[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 15360
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      string str;
      cin>>str;
      set<char> c;
      for(int i=0;i<str.length();i++)
        c.insert(str[i]);
      if(c.size()==2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


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

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

  ll ans;
  double mini=1e20;
  for(int i=0;i+1<n;i++){
    double dist= abs( v[n-1]/2.0 - v[i] );
    if( mini > dist ){
      mini = dist;
      ans=v[i];
    }
  }

  cout<<v[n-1]<<' '<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    LL(N);
    VEC(ll,d,N);

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

    cout << d.at(N/2) - d.at((N/2) -1) << endl;


}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define maxn 200020
#define ll long long
using namespace std;
int n,a[maxn];
map<int,int>mp;
inline bool check(int x){
	mp.clear();
	for(int i=2;i<=n;++i){
		if(a[i]>a[i-1])continue;
		if(x==1)return 0;
		++mp[a[i]];
		map<int,int>::iterator it=mp.upper_bound(a[i]);
		while(it!=mp.end())mp.erase(it),it=mp.upper_bound(a[i]);
		int pos=a[i];
		while(pos&&mp[pos]==x){
			mp[pos]=0;
			++mp[--pos];
		}
		if(!pos)return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	int l=1,r=n,mid=(l+r)>>1;
	while(l<r){
		if(check(mid))r=mid;
		else l=mid+1;
		mid=(l+r)>>1;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define P int
using namespace std;
string s;
int p;
P bns1();
P g_A(){
  P r=0;
  if(s[p]=='('){
    p++;
    r=bns1();
    p++;
  }
  else{
    while(isdigit(s[p])){
      r=r*10+(s[p]-'0');
      p++;
    }
  }
  return r;
}
P bns2(){
  P res=g_A();
  while(s[p]=='*'||s[p]=='/'){
    int t=p++;
    if(s[t]=='*')res*=g_A();
    if(s[t]=='/')res/=g_A();
  }
  return res;
}
P bns1(){
  P res=bns2();
  while(s[p]=='+'||s[p]=='-'){
    int t=p++;
    if(s[t]=='+')res+=bns2();
    if(s[t]=='-')res-=bns2();
  }
  return res;
}
int main(){
  int ans,n;
  cin>>n;
  while(n--){
    cin>>s;
    p=0;
    P ans=bns1();
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    long n,m;
    bool fl=true;
    cin >> n >> m;
    // スペース区切りの整数の入力
    for(int i=m/n;i>0;i--){
      if(m%i==0){
        cout<< i;
        break;
      }
    }
}

Measured memory_bytes: 256
import sys

n, k, *x = map(int, sys.stdin.read().split())

def main():
    res = float('inf')
    for i in range(n - k + 1):
        j = i + k - 1
        if x[i] < 0:
            d = -x[i] if x[j] <= 0 else min(-x[i], x[j]) * 2 + max(-x[i], x[j])
        else:
            d = x[j]
        res = min(res, d)
    print(res)
    
if __name__ ==  '__main__':
    main()

Measured memory_bytes: 14052
public class Main {
    public static void main(String[] args) {
      	java.util.Scanner sc = new java.util.Scanner(System.in);
      	final int A = sc.nextInt();
        final int B = sc.nextInt();

        final boolean isDivisor = B % A == 0;
        if (isDivisor){
            output(A+B);
        }else{
            output(B-A);
        }
    }

    private static void output(int i) {
        System.out.println(i);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int L; 
      cin >> L;
      int64_t a = 2;
      int64_t b = 1; 
      int64_t c; 
	  for(int i=1; i<=L; i++ ){
        c=b; 
        b = a+b; 
        a=c;  
      }
      cout << a << endl; 
    }

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

int main(){
    int n;
    cin >> n;
    bool ok = false;
    rep(i,10){
        rep(j,10){
            if(n==i*j) ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"basic.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    map<int, int> factors;
    for(int i=2;i<=n;i++){
        int num = i;
        for(int j=2;j<=n;j++){
            while(num % j == 0){
                num /= j;
                factors[j]++;
            }
        }
    }
    ll ans = 1;
    for(auto p : factors){
        ans = ans * (p.second + 1) % M;
    }
    prints(factors);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int temp;
    vector<int> A(4);
	cin >> temp;

    for(int i=0;i<4;i++){
        A[i] = temp % 10;
        temp = temp / 10;
    }

    int sum;
    string ans;
    for(int i=0;i<8;i++){
        sum = A[3];
        ans = "";
        for(int j=2;j>=0;j--){
            if((i>>j) & 1){
                sum = sum + A[j];
                ans = '+' + ans;
            }else{
                sum = sum - A[j];
                ans = '-' + ans;
            }
        }
        if(sum == 7){
            break;
        }
    }

    for(int i=3;i>=1;i--){
        cout << A[i] << ans[i-1];
    }
    cout << A[0] << "=7" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

		for(int i = 0; i < totalFlower; ++i) {
			flowersHeight[i] = scanner.nextInt();
		}

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

}


Measured memory_bytes: 23252
#ABC075

h,w = list(map(int,input().split()))
s = [list(input()) for _ in range(h)]

d = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
for i in range(h):
    for j in range(w):
        
        if s[i][j] == ".":
            count = 0
            for k in range(8):
                
                if 0 <= i+d[k][0] <= h-1 and 0 <= j+d[k][1] <= w-1:
                    
                    if s[i+d[k][0]][j+d[k][1]] == "#":
                        count += 1
            
            s[i][j] = str(count)


s = ["".join(s[i]) for i in range(h)]
for i in range(h):
    print(s[i])

Measured memory_bytes: 3188
import sys

def solve(n):
    ans = 0

    for k in range(1, int(n*(n+1)/2)+1):
        left = k * (k-1) / 2
        right = k * (k + 1) / 2

        # sys.stderr.write("%d %d %d %d\n" % (k, left, n, right))

        if (left < n) and (n <= right):
            ans = k
            break

    return ans


def main():
    n = int(sys.stdin.readline())
    ans = solve(n)
    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
let dbg = Printf.printf "[debug]%s"

let id = fun x -> x

let scanf fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr;
  arr

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let between n x m = n <= x && x < m

let () =
  let memo = Array.make 45 0  in
  List.iter (fun i ->
      memo.(i) <-
        if i = 0 then 1
        else if i = 1 then 1
        else memo.(i-2) + memo.(i-1))
    (0++^45);
  let n =  scanf "%d" id in
  Printf.printf "%d\n" memo.(n)



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

int main() {
  int N,A,B;
  cin >> N >> A >> B;  
  int ans;
  
  for (int i=1;i<N+1;i++) {
    string y = to_string(i);
    int y_sum = 0;
    for (int j=0; j<y.size(); j++) {
      //cout << (int) y.at(j) << endl;
      y_sum += (int) y.at(j) - '0';
    }
    //cout << y_sum << endl;
    if ((y_sum >=A ) && (y_sum <=B )) {
      //cout << y_sum << endl;
      ans+=i;
    }
  }
  

  cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {

	var answer = "Yes";
	var input = input.split('\n');
	var shiritori_length = input[0];
	var shiritori_array = [];

	for (var i = 0; i < shiritori_length; i++) {
	  	if(shiritori_array.indexOf(input[i+1]) != -1){
			answer = "No";
			break;
		}
	  	shiritori_array.push(input[i+1])

	  	//末尾チェック
	  	if(i > 0){
	  		//前の語尾と先頭の文字が一致するか
	  		if(shiritori_array[i-1].slice(-1) != shiritori_array[i].slice(0,1) ){
	  			answer = "No";
	  			break;
	  		}
	  		//重複チェック
	  		/*
	  		for (var j = 0; j < shiritori_array.length - 1; j++) {
	  			if(input[i+1] == shiritori_array[j]){
	  				answer = "No";
		  			break;
	  			}  		
	  		}
			*/		
	  	}
  	
	}

	console.log(answer);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] list = new int[N];
		for (int i = 0; i < N; i++) {
			list[i] = in.nextInt();
		}
		int count = 0;
		Boolean flag = true;
		flag = Check(list, flag);
		while (flag) {
			for (int i = 0; i < N; i++) {
				list[i] = list[i] / 2;
			}
			flag = Check(list, flag);
			count++;
		}
		System.out.println(count);
	}

	private static Boolean Check(int[] list, Boolean flag) {
		for (int i = 0; i < list.length; i++) {
			if (list[i] % 2 == 1) {
				flag = false;
			}
		}
		return flag;
	}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
int main()
{
    int n,a[4850],f[9];
    while(scanf("%d",&n)==1)
    {
        int cnt=0,sum=0;
        memset(f,0,sizeof(f));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=0; i<n; i++)
        {
            if(a[i]>=1&&a[i]<=399)
                f[1]=1;
            if(a[i]>=400&&a[i]<=799)
                f[2]=1;
            if(a[i]>=800&&a[i]<=1199)
                f[3]=1;
            if(a[i]>=1200&&a[i]<=1599)
                f[4]=1;
            if(a[i]>=1600&&a[i]<=1999)
                f[5]=1;
            if(a[i]>=2000&&a[i]<=2399)
                f[6]=1;
            if(a[i]>=2400&&a[i]<=2799)
                f[7]=1;
            if(a[i]>=2800&&a[i]<=3199)
                f[8]=1;
            if(a[i]>3199)
                cnt++;
        }
        for(int i=1; i<9; i++)
        {
            if(f[i]==1)
                sum++;
        }
        cnt+=sum;
        if(sum==0)
            sum=1;
        printf("%d %d\n",sum,cnt);
    }
    return 0;
}

Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,odc=0;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%2==1) odc++;
  }
  if(odc%2==0) cout << "YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int num[n+1];
    int i;
    for(i=0;i<=n-1;i++) scanf("%d",&num[i]);
    int j,k;
    for(j=0;j<=n-1;j++){
        int v=num[j];
        k=j-1;
        while(k>=0 && v<num[k]){
            num[k+1]=num[k];
            k--;
        }
        num[k+1]=v;
        
        int a;
        for(a=0;a<=n-2;a++) printf("%d ",num[a]);
        printf("%d\n",num[n-1]);
    }

    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python3
def primes(n):
    m = 1297
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and i % 5 == 2][:n]


print(*primes(int(input())))


Measured memory_bytes: 9392
N=int(input())
A=list(map(int,input().split()))
#print("A",A)

S=[abs(A[0])]
for i in range(1,N):
  S.append(S[i-1]+abs(A[i]-A[i-1]))
#print("S",S)

A=A[::-1]
G=[abs(A[0])]
for i in range(1,N):
  G.append(G[i-1]+abs(A[i]-A[i-1]))
G=G[::-1]
#print("G",G)
A=A[::-1]

for i in range(N):
  if i==0:
    print(G[i+1]+abs(A[i+1]))
  elif i==N-1:
    print(S[i-1]+abs(A[i-1]))
  else:
    print(S[i-1]+G[i+1]+abs(A[i+1]-A[i-1]))

Measured memory_bytes: 17064
import java.util.*;

class Main{
	public static void main(String[] Args){
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		Deque dqa = new Deque(q);
		for(int i = 0; i < q; i++){
			int op = sc.nextInt();
			if(op == 0){
				int d = sc.nextInt();
				int x = sc.nextInt();
				if(d == 0) dqa.push_front(x);
				else dqa.push_back(x);
			}else if(op == 1){
				int p = sc.nextInt();
				System.out.println(dqa.get(p));
			}else{
				int d = sc.nextInt();
				if(d == 0) dqa.pop_front();
				else dqa.pop_back();
			}
		}
	}
}

class Deque{
	private int[] arr;
	private int front, rear;
	Deque(int n){
		arr = new int[n];
		front = 0;
		rear = 0;
	}
	public void push_front(int x){
		front = (front + arr.length - 1) % arr.length;
		arr[front] = x;
	}
	public void push_back(int x){
		arr[rear] = x;
		rear = (rear + 1) % arr.length;
	}
	public int pop_front(){
		int ret = arr[front];
		front = (front + 1) % arr.length;
		return ret;
	}
	public int pop_back(){
		int ret = arr[rear];
		rear = (rear + arr.length - 1) % arr.length;
		return ret;
	}
	int get(int p){
		return arr[(front + p + arr.length) % arr.length];
	}
}



Measured memory_bytes: 294616
gets
a = gets.split.map(&:to_i)
start_arr = []
end_arr = []

tmp1 = a[0]
tmp2 = a[-1]
a.size.times do |i|
  tmp1 = tmp1.gcd(a[i])
  start_arr << tmp1
  tmp2 = tmp2.gcd(a[-1 - i])
  end_arr << tmp2
end
end_arr.reverse!
# p a
# p start_arr
# p end_arr
m = 1
a.size.times do |i|
  if i == 0
    # p [end_arr[i+1]]
    m = [end_arr[i+1], m].max
  elsif i == a.size-1
    # p [start_arr[i-1]]
    m = [start_arr[i-1], m].max
  else
    # p [start_arr[i-1].gcd(end_arr[i+1]), m]
    m = [start_arr[i-1].gcd(end_arr[i+1]), m].max
  end
end
p m


Measured memory_bytes: 12704
import java.util.*;

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

		int N = scanner.nextInt();

		int m = 0;

		for (int i = 1; i <= N; i++) {
			if((i % 2) == 1) {
				m++;
			}
		}
		
		System.out.println((float) m / N);

	}
}


Measured memory_bytes: 23764
# 最小公倍数(ユーグリッド互除法)
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd( b, a % b)

K = int(input()) + 1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  ans += gcd(h,gcd(h,h))

  for i in range(h+1, K):
    ans += (gcd(h,gcd(h,i)) * 3)
    ans += (gcd(h,gcd(i,i)) * 3)

    for j in range(i+1, K):
      ans += (gcd(h,gcd(i,j)) * 6)

print(ans)

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);

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

    sort(vec.begin(), vec.end());
    cout << vec.at(n-1) - vec.at(0) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 2e5;
int n, a[maxn], b[maxn];
int cnt1, cnt2;
int c[maxn], d[maxn];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
  }
  int ans = 0;
  for (int k = 0; k < 30; ++k) {
    long long cnt = 0;
    for (int t1 = 0; t1 <= 1; ++t1) {
      for (int t2 = 0; t2 <= 1; ++t2) {
        cnt1 = cnt2 = 0;
        for (int i = 0; i < n; ++i) {
          if ((a[i] >> k & 1) == t1) {
            c[cnt1++] = a[i] & (1 << k) - 1;
          }
          if ((b[i] >> k & 1) == t2) {
            d[cnt2++] = b[i] & (1 << k) - 1;
          }
        }
        //if (!cnt1 || !cnt2) continue;
        sort(d, d + cnt2);
        long long tmp = 0;
        for (int i = 0; i < cnt1; ++i) {
          tmp += cnt2 - (lower_bound(d, d + cnt2, (1 << k) - c[i]) - d);
        }
        if (t1 + t2 & 1) {
          cnt += (long long)cnt1 * cnt2 - tmp;
        } else {
          cnt += tmp;
        }
      }
    }
    if (cnt & 1) {
      ans |= 1 << k;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<unordered_map>
#include<cstdlib>
 
#include<unordered_map>
#include<algorithm>
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
 
#define ii pair<long long,long long>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>

#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;

 
typedef long long ll;
typedef vector< int> vi;
typedef long double ld;

const int MAX = 1e2 + 10;
const int maxn = 2e4+100;

 



int n, a[maxn];

int main (){
 //~ in
 fast_io
 
 cin >> n;
 for(int i = 0  ;i < n;i++){
		cin >> a[i];
	}
		
	sort ( a, a + n);
	long long cnt = 0;
	for(int i = 0 ;i < n;i++){
		for( int j = i + 1;j < n ;j++){	
			if ( a[i]+a[j] > a[j+1] ){
				int idx = lower_bound ( a + j + 1 , a + n , a[i]+a[j] ) - a;
				cnt += (idx-(j+1));
			}
		}
	}
	
	cout << cnt << '\n';
	return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B;
    cin >> A >> B;
    cout << (A - 1)* (B -1) << endl;
}


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

namespace _012_APointinaTriangle
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				double[] numArray = inputStr.Split (' ').Select (str => double.Parse (str)).ToArray ();

				Vector2[] trianglePoint = new Vector2[3];
				trianglePoint[0] = new Vector2 (numArray[0], numArray[1]);
				trianglePoint[1] = new Vector2 (numArray[2], numArray[3]);
				trianglePoint[2] = new Vector2 (numArray[4], numArray[5]);

				Vector2 point = new Vector2 (numArray[6], numArray[7]);

				double result1 = Vector2.CrossProduct (trianglePoint[0], trianglePoint[1], point);
				double result2 = Vector2.CrossProduct (trianglePoint[1], trianglePoint[2], point);
				double result3 = Vector2.CrossProduct (trianglePoint[2], trianglePoint[0], point);

				bool isSameDirect = Math.Sign (result1) == Math.Sign (result2) && Math.Sign (result1) == Math.Sign (result3);

				if (isSameDirect)
					Console.WriteLine ("YES");
				else
					Console.WriteLine ("NO");
			}
		}
	}

	class Vector2
	{
		public Vector2 ( double x, double y )
		{
			this.X = x;
			this.Y = y;
		}

		public double X { private set; get; }
		public double Y { private set; get; }

		public static double CrossProduct ( Vector2 trianglePoint, Vector2 trianglePoint2, Vector2 point )
		{
			Vector2 subVector = new Vector2 (trianglePoint.X - trianglePoint2.X, trianglePoint.Y - trianglePoint2.Y);
			Vector2 distance = new Vector2 (point.X - trianglePoint.X, point.Y - trianglePoint.Y);

			return distance.X * subVector.Y - distance.Y * subVector.X;
		}
	}
}

Measured memory_bytes: 9448
N=int(input())
count=1
if N<105:
    print(0)
else:
    for i in range(107,N+1,2):
        if i%2==1:
            c=0
            for j in range(1,i+1,2):
                if i%j==0:
                    c+=1
            if c==8:
                count+=1
    print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n,a,b;cin >> n >> a >> b;
    if((b-a)%2 == 1){
        cout << "Borys"<< endl;
    }
    else cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
c = input()

l = 0
r = N-1
ans = 0
while True:
  while l<r and c[l]=="R":
    l += 1
  while l<r and c[r]=="W":
    r -= 1
  if l>=r:
    break
  l += 1
  r -= 1
  ans += 1
print(ans)


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string s,t;
    cin>>s>>t;
    bool a=true;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            a=false;
            break;
        }
    }
    if(a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;

int atcoder(){
    //入力
    ll h,w,H,W;
    cin >> h >> w >> H >> W;
    cout << (h-H)*(w-W) << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int k,n;
  cin>>n>>k;
  int p[n],ans=0;
  for(int i=0;i<n;i++)cin>>p[i];
  sort(p,p+n);
  for(int i=0;i<k;i++)
  {
    ans+=p[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
a, b, c = map(int, input().split())
k = int(input())

count = 0
flag = 1

while 1:
  if count > k:
    flag = 0
    break
  if b > a:
    break
  b = 2 * b
  count += 1
  

while 1:
  if count > k:
    flag = 0
  if c > b:
    break
  c = 2 * c
  count += 1
  
if flag == 0:
  print("No\n")
else:
  print("Yes\n")

Measured memory_bytes: 8868
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const double INF = 10000000000000000.0;  // 10の16乗
const ll MAX_N = 100010;

double dist(double x1, double y1, double x2, double y2) {  // (x1, y1) と (x2, y2) のユークリッド距離
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}

int main() {
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;

    ll n;
    cin >> n;

    vector<double> x(n+2), y(n+2), r(n+2);
    x[0] = xs, y[0] = ys, r[0] = 0.0;
    exrep(i, 1, n) {
        cin >> x[i] >> y[i] >> r[i];
    }
    x[n+1] = xt, y[n+1] = yt, r[n+1] = 0.0;

    vector<vector<pair<ll, double>>> G(n+2);  // 辺の重みがすべて0以上のグラフ
    exrep(i, 0, n) {
        exrep(j, i+1, n+1) {
            double cost = max(0.0, dist(x[i], y[i], x[j], y[j]) - (r[i] + r[j]));
            G[i].pb(make_pair(j, cost));
            G[j].pb(make_pair(i, cost));
        }
    }

    // ダイクストラ法。計算量はO((V+E)*log(V))
    vector<double> dist(n+2, INF);  // dist[v] : 頂点svから頂点vへの最短距離
    priority_queue<pair<double, ll>, vector<pair<double, ll>>, greater<pair<double, ll>>> prQ;
    const ll sv = 0;  // 始点となる頂点
    dist[sv] = 0.0;
    prQ.push(make_pair(0.0, sv));  // (頂点svからの最短距離, 頂点番号)
    while(!prQ.empty()) {
        auto p1 = prQ.top();
        prQ.pop();
        ll v = p1.second;
        if(dist[v] < p1.first) {
            continue;
        }
        for(auto p2 : G[v]) {
            ll u = p2.first;
            double cost = p2.second;
            if(dist[u] > dist[v] + cost) {
                dist[u] = dist[v] + cost;
                prQ.push(make_pair(dist[u], u));
            }
        }
    }

    exout(dist[n+1]);
    re0;
}

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

#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define fill(a, z) memset(a, z, sizeof(a))
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << z << ' '
#define cnl(z) cout << z << '\n'
#define printclock cerr << "Time : " << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms\n";
#define M 1000000007
#define M2 998244353
#define MAXN 300005
#define INF 1000000000000
#define endl "\n"
#define iip(t) \
	int t;     \
	cin >> t;
#define iip2(a, b) \
	int a, b;      \
	cin >> a >> b;
#define dip(a) \
	double a;  \
	cin >> a;
#define dip2(a, b) \
	double a, b;   \
	cin >> a >> b;
#define garr(ip)       \
	for (auto &x : ip) \
		cin >> x;
#define parr(ip)          \
	for (auto &x : ip)    \
		cout << x << " "; \
	cout << endl;
#define test   \
	int _t;    \
	cin >> _t; \
	while (_t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vp;

int modExp(int base, int exponent, int MOD = M)
{
	if (exponent == 0)
		return 1;
	int curr = modExp(base, exponent >> 1);
	curr = (curr * curr) % MOD;
	if (exponent & 1)
		curr = (curr * base) % MOD;
	return curr;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	iip(n);
	vi arr(n + 1);
	rlt(i, 1, n)
	{
		iip(T);
		arr[T]++;
	}
	rep(i, 1, n)
		cnl(arr[i]);
}

Measured memory_bytes: 4772
from heapq import heappush, heappop


def dijkstra(edges, size, source):
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_u, u = heappop(pq)
        visited[u] = True
        for v, weight, _ in edges[u]:
            if not visited[v]:
                new_dist = dist_u + weight
                if distance[v] > new_dist:
                    distance[v] = new_dist
                    heappush(pq, (new_dist, v))
    return distance


while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break
    edges = [[] for i in range(N)]

    for i in range(M):
        u, v, d, c = map(int, input().split())
        u -= 1
        v -= 1
        edges[u].append((v, d, c))
        edges[v].append((u, d, c))

    dist = dijkstra(edges, N, 0)
    ans = 0
    for u in range(1, N):
        cost = 1000
        for v, d, c in edges[u]:
            if dist[u] == dist[v] + d:
                cost = min(cost, c)
        ans += cost
    print(ans)



Measured memory_bytes: 12772