akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int WIDTH = 4400;
const int DEBUG = 0;

struct State {
	int score;
	int prevs;
	int sousa;
	int Last[29];
};

bool operator<(const State& a1, const State& a2) {
	if (a1.score < a2.score) return true;
	return false;
}

int N;
int C[29], S[409][29];
int cnts[409];
int Last[409];
int BORDER;
State G[409][WIDTH + 9];
State H[(WIDTH * 26) + 9];

int getscore(vector<int> vec) {
	for (int i = 1; i <= 26; i++) Last[i] = 0;
	int t = 0;
	for (int i = 0; i < vec.size(); i++) {
		Last[vec[i]] = i + 1; t += S[i + 1][vec[i]];
		for (int j = 1; j <= 26; j++) t -= C[j] * ((i + 1) - Last[j]);
	}
	return t;
}

void solve(int pos, int num, int i) {
	int NewScore = G[pos][num].score;
	NewScore += S[pos + 1][i];
	for (int j = 1; j <= 26; j++) {
		if (i != j) NewScore -= C[j] * ((pos + 1) - G[pos][num].Last[j]);
	}
	if (NewScore < BORDER) return; // 門前払い

	H[cnts[pos + 1]].score = NewScore;
	H[cnts[pos + 1]].prevs = num;
	H[cnts[pos + 1]].sousa = i;
	for (int j = 1; j <= 26; j++) H[cnts[pos + 1]].Last[j] = G[pos][num].Last[j];
	H[cnts[pos + 1]].Last[i] = pos + 1;
	cnts[pos + 1]++;
}

int main() {
	// 入力
	if (DEBUG == 0) {
		cin >> N;
		for (int i = 1; i <= 26; i++) cin >> C[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) cin >> S[i][j];
		}
	}
	else {
		N = 365;
		for (int i = 1; i <= 26; i++) C[i] = rand() % 101;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) S[i][j] = ((rand() % 32768) * 32768 + (rand() % 32768)) % 20001;
		}
	}

	// ビームサーチ
	G[0][0].prevs = -1; cnts[0] = 1;
	for (int i = 0; i < N; i++) {
		// 適当に 800 個サンプリングする
		BORDER = -(1 << 28);
		for (int t = 0; t < 800; t++) {
			int r1 = rand() % cnts[i], r2 = (rand() % 26) + 1;
			solve(i, r1, r2);
		}
		vector<int> R;
		for (int j = 0; j < 800; j++) R.push_back(H[j].score);
		sort(R.begin(), R.end());
		reverse(R.begin(), R.end());
		if (cnts[i] == WIDTH) BORDER = R[R.size() / 15];
		else BORDER = -(1 << 28);

		// 枝刈りする
		cnts[i + 1] = 0;
		for (int j = 0; j < cnts[i]; j++) {
			for (int k = 1; k <= 26; k++) solve(i, j, k);
		}
		sort(H, H + cnts[i + 1]);
		reverse(H, H + cnts[i + 1]);
		cnts[i + 1] = min(cnts[i + 1], WIDTH);
		for (int j = 0; j < cnts[i + 1]; j++) G[i + 1][j] = H[j];
	}

	// 復元
	vector<int> Answer; int cx = 0;
	for (int i = N; i >= 1; i--) {
		Answer.push_back(G[i][cx].sousa);
		cx = G[i][cx].prevs;
	}
	reverse(Answer.begin(), Answer.end());

	// 山登り法
	vector<int> R;
	for (int i = 1; i <= N; i++) R.push_back(Answer[i - 1]);
	int CurrentMax = getscore(R), S = 0;
	for (int t = 1; t <= 80000; t++) {
		if (rand() % 10 < 5) {
			int v1 = rand() % (N - 1);
			swap(R[v1], R[v1 + 1]);
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; S = 0; }
			else { swap(R[v1], R[v1 + 1]); S += 1; }
		}
		else {
			int v1 = rand() % N, v2 = rand() % 26 + 1;
			int moto = R[v1];
			R[v1] = v2;
			int CandMax = getscore(R);
			if (CurrentMax <= CandMax) { CurrentMax = CandMax; S = 0; }
			else { R[v1] = moto; S += 1; }
		}
	}
	for (int i = 1; i <= N; i++) cout << R[i - 1] << endl;
	return 0;
}

Measured memory_bytes: 206068
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set> 
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int n,k,b; 
 cin>>n>>k;
 int a[n+1],x=n;
 memset (a,0,sizeof(a));
 for (int i=1;i<=n;i++){
 cin>>a[i];
 if (i==0)
 b=a[i];
 if (a[i]<b);
 b=a[i];}
 for (int i=1;i<=n;i++)
 if (a[i]==b)
 x--; 
 cout<<(x+k-2)/(k-1);
 system("pause");
 return 0; 
 }

Measured memory_bytes: 888
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}

int n,m;
int c[21];
int dp[21][50001];//pos,yen/min
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>m;
	rep(i,m)cin>>c[i];
	rep(i,n+1)dp[0][i]=i*c[0];
	REP(i,1,m){
		REP(j,1,n+1){
			if(j-c[i]>=0)
				dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1);
			else 
				dp[i][j]=dp[i-1][j];
		}
	}
/*	rep(i,m){
		REP(j,1,n+1)p(dp[i][j]);
		cout<<endl;
	}*/
	P(dp[m-1][n]);
	return 0;
}

Measured memory_bytes: 7076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  n = n % 10;

  switch (n) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
  }
}

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

int main(){
  int n,a,b; cin>>n>>a>>b;
  int x=b/a;
  int pre; cin>>pre;
  ll ans=0;
  for(int i=1;i<n;i++){
    int now; cin>>now;
    if(now-pre>x){
      ans+=b;
    }else{
      ans+=(now-pre)*a;
    }pre=now;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
arr = [10] * N
for _ in range(M):
  idx, num = map(int, input().split())
  if arr[idx - 1] == 10:
    arr[idx - 1] = num
  else:
    if arr[idx - 1 ] != num:
      print(-1)
      exit()

if arr[0] == 0:
  if N == 1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
elif arr[0] == 10:
  if N == 1:
    print(0)
    exit()
  else:
    arr[0] = 1
  
for i in range(N):
  if arr[i] == 10:
    arr[i] = 0

for i in arr:
  print(i,end="")


Measured memory_bytes: 61908
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n), cnt(n, 0);
    for (auto& x : xs) {
        std::cin >> x;
        ++cnt[--x];
    }

    std::set<int> ss;
    for (int x = 0; x < n; ++x) ss.insert(x);

    std::vector<int> ans;
    ans.reserve(n);

    int out = -1;
    while (ss.size() > 6) {
        int x = *ss.begin();
        if (x == out) {
            if (ss.size() == 1) {
                std::cout << -1 << std::endl;
                return;
            } else {
                x = *(++ss.begin());
            }
        }

        int k = ss.size();
        int y = xs[x];
        if (ss.count(y) && cnt[y] == k - 1) x = y;

        ss.erase(x);
        ans.push_back(x);
        --cnt[xs[x]];
        out = xs[x];
    }

    std::vector<int> rem(ss.begin(), ss.end());
    do {
        auto tmpans = ans;
        for (auto x : rem) ans.push_back(x);

        bool ok = true;
        for (int i = 0; i < n - 1; ++i) {
            if (ans[i + 1] == xs[ans[i]]) ok = false;
        }

        if (ok) {
            for (auto x : ans) std::cout << x + 1 << " ";
            std::cout << std::endl;
            return;
        }

        ans = tmpans;
    } while (std::next_permutation(rem.begin(), rem.end()));
    std::cout << -1 << std::endl;
}

int main() {
    // int q;
    // std::cin >> q;
    // while (q--) solve();
    solve();
    return 0;
}


Measured memory_bytes: 6656
from collections import deque

n = int(input())
b = list(map(int, input().split()))

l = []

a = deque(l)

while b:
    memo = []
    for i in range(len(b)):
        if b[i]-1 == i:
            memo.append(i)
    if memo ==[]:
        print(-1)
        exit()
    a.appendleft(memo[-1]+1)
    b = b[:memo[-1]] + b[memo[-1]+1:]

for i in range(len(a)):
    print(a[i])

Measured memory_bytes: 3316
#![allow(unused_imports)]pub mod pcl{}
use std::io::stdin;
macro_rules ! eprintln { ( $ ( $ args : tt ) * ) => { { use std :: io :: prelude ::*; writeln ! ( std :: io :: stderr ( ) , $ ( $ args ) * ) . unwrap ( ) ; } } ; }
fn main() {
    let (n, k, c) = {
        let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        let sp: Vec<_> = s
            .split_whitespace()
            .map(|x| x.parse::<usize>().unwrap())
            .collect();
        (sp[0], sp[1], sp[2] + 1)
    };
    let works: Vec<_> = {
        let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        s.chars().map(|ch| ch == 'o').collect()
    };
    let mut after = Vec::new();
    let mut d = 0;
    for _ in 0..k {
        while !works[d] {
            d += 1;
        }
        after.push(d);
        d += c;
    }
    let mut before = Vec::new();
    let mut d = n - 1;
    for _ in 0..k {
        while !works[d] {
            d -= 1;
        }
        before.push(d);
        d = d.saturating_sub(c);
    }
    before.reverse();
    assert_eq!(after.len(), before.len());
    eprintln!("after: {:?}", after);
    eprintln!("before: {:?}", before);
    for i in 0..k {
        if before[i] == after[i] {
            println!("{}", before[i] + 1);
        }
    }
}



Measured memory_bytes: 9596
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>n;
	if(n==1)
	{
		cout<<0;
		return 0;
	}
	ll a[n];
	for(j=0;j<n;j++)
		cin>>a[j];
	sort(a,a+n,greater<ll>());
	ll s=0;
	s=s+a[0];
	c=2;
	for(j=1;j<n;j++)
	{
		if(c+2<=n)
		{
			s=s+2*a[j];
		    c=c+2;
		}
		else if(c+1<=n)
		{
			s=s+a[j];
			c+=1;
		}
		else
			break;
		
	}
	cout<<s;
}



	

		

Measured memory_bytes: 5204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		String s = sc.next();

		int []w = new int [n+1];
		int []b = new int [n+1];
		
		for(int i = 1 ; i <= n ;i++) {
			w[i] = w[i-1];
			b[i] = b[i-1];
			if(s.charAt(i-1) == '#') {
				b[i]++;
			}
			else {
				w[i]++;
			}
		}
		
		int min = n+1;
		for(int i = 0 ; i <= n ;i++) {
			int temp = b[i] + w[n] - w[i];
			//System.out.println(temp);
			min = Math.min(min,temp);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 30380
n=int(input())
l=[[0,0,0]]
for i in range(n):
    t,x,y=map(int,input().split())
    l.append([t,x,y])
c=0
for i in range(n):
    t=l[i+1][0]-l[i][0]
    x=l[i+1][1]-l[i][1]
    y=l[i+1][2]-l[i][2]
    if (x+y-t)%2!=0 or abs(x+y)>t:
        c+=1
        break
if c==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 19532
#include<iostream>


using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;
void merge(int A[], int n,int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;

	for (int i = 0; i < n1; i++)L[i] = A[left + i];
	for (int i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}

}

void mergeSort(int A[],int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n,left, mid);
		mergeSort(A,n, mid, right);
		merge(A, n,left, mid, right);
	}
}
int main() {
	int A[MAX], n, i;
	cnt = 0;
	cin >> n;
	for (i = 0; i < n; i++)cin >> A[i];

	mergeSort(A, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;

	cout << cnt << endl;


}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


double const eps = 1e-10;
double const pi = 3.1415926535;
ll const mod = 1e9+7;


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

    int a,b;
    cin >> a >> b;
    if ( a == 1 && b == 2 ) cout << 3;
    else if ( a == 2 && b == 1 ) cout << 3;
    else if ( a == 3 && b == 2 ) cout << 1;
    else if ( a == 2 && b == 3 ) cout << 1;
    else cout << 2;


    return 0;
    // 274751WM
}


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

using ll = long long int;

typedef pair<int, int> P;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;

ll l[MAX_N];
ll r[MAX_N];

ll min_r = INF;
ll max_l = -1L;

inline bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  return a.first < b.first || (a.first == b.first && a.second > b.second);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &(l[i]), &(r[i]));
    // max_l = max(max_l, l[i]);
    // min_r = min(min_r, r[i]);
  }

  int max_l_ind = 0;
  int min_r_ind = 0;

  for (int i = 1; i < n; ++i) {
    if (l[i] > l[max_l_ind]) max_l_ind = i;
    if (r[i] < r[min_r_ind]) min_r_ind = i;
  }

  if (n == 2) {
    ll ans = (r[0] - l[0] + 1L) + (r[1] - l[1] + 1L);
    printf("%lld\n", ans);
    return 0;
  }

  ll ans = 0L;

  // for case that a part of group is singleton
  for (int i = 0; i < n; ++i) {
    if (i == min_r_ind || i == max_l_ind) continue;

    ans = max(ans, max(r[min_r_ind] - l[max_l_ind] + 1, 0LL) + r[i] - l[i] + 1L);
  }

  vector<pair<ll, ll>> p;

  for (int i = 0; i < n; ++i) {
    if (i == min_r_ind || i == max_l_ind) continue;

    pair<ll, ll> tmp;

    tmp.first = max(r[min_r_ind] - l[i] + 1L, 0LL);   // first: fixed right
    tmp.second = max(r[i] - l[max_l_ind] + 1L, 0LL);  // second: fixed left

    p.push_back(tmp);
  }

  ll score_fixed_right = r[min_r_ind] - l[min_r_ind] + 1L;
  ll score_fixed_left = r[max_l_ind] - l[max_l_ind] + 1L;

  sort(p.begin(), p.end(), cmp);

  ans = max(ans, score_fixed_left + p[0].first);

  for (int i = 0; i < p.size(); ++i) {
    ans = max(ans, p[i].second);
  }

  ll part = p[0].second;
  for (int i = 1; i < p.size(); ++i) {
    ans = max(ans, part + p[i].first);
    part = min(part, p[i].second);
  }

  ans = max(ans, score_fixed_right + part);

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3956
#include<iostream>
#include<cstdio>
#include<algorithm>
#include <cstring>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='R')
        cout<<"Sunny\n";
    if(s[0]=='C')
        cout<<"Rainy\n";
    if(s[0]=='S')
        cout<<"Cloudy\n";
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int N, W; cin >> N >> W;
	vector<int>v(N + 1), w(N + 1);
	rep(i, 1, N + 1)cin >> v[i] >> w[i];
	vector<int>dp(100 * 100 + 1, INF);
	dp[0] = 0;
	rep(i, 1, N + 1)rrep(j, v[i], dp.size()) {
		dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
	}
	int ans(0);
	rep(i, 0, dp.size()) {
		if (dp[i] <= W)ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int ans = 1000;
	int count;
	for (int i = 0; i <= (int)(s.length() - t.length()); i++) {
		count = 0;
		for (int j = 0; j < (int) t.length(); j++) {
			if (s[i+j] != t[j]) count++;
		}
		ans = min(ans, count);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int a, b;

    scanf("%d%d", &a, &b);

    if(a % 2 == 1 && b % 2 == 1){
        printf("Odd\n");
    }else{
        printf("Even\n");
    }

    return 0;
}

Measured memory_bytes: 1644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

bool cmp(const PQ<int> &a, const PQ<int> &b) {
    return a.top() < b.top();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    vector<PQ<int> > v;
    rep(i, n) {
        int t, d;
        cin >> t >> d;
        if(!mp.count(t)) {
            mp[t] = v.size();
            v.emplace_back(PQ<int>());
        }
        v[mp[t]].emplace(d);
    }
    sort(rall(v), cmp);

    ll ans = 0;
    PQG<int> pq;
    ll sum = 0;
    ll topsum = 0;
    for(int i = 0; i < min(k, (int)v.size()); i++) {
        topsum += v[i].top();
        v[i].pop();
        while(pq.size() < k-i-1 and !v[i].empty()) {
            pq.emplace(v[i].top());
            sum += v[i].top();
            v[i].pop();
        }
        if(pq.size() > k-i-1) {
            sum -= pq.top();
            pq.pop();
        }
        while(!v[i].empty()) {
            pq.emplace(v[i].top());
            sum += v[i].top();
            v[i].pop();
            sum -= pq.top();
            pq.pop();
        }
        chmax(ans, topsum+sum+ll(i+1)*(i+1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 14212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int n;
double p[3003];
double dp[3003][3003]; //dp[A][B].A＝ｎ,Bは正答数
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    dp[1][1] = 1-p[1];
    dp[1][2] = p[1];
    for(int i = 2; i <= n; i++){
        for(int j = 1; j <= n+1; j++){
            dp[i][j] = dp[i-1][j]*(1 - p[i]) + dp[i-1][j-1]*p[i]; 
        }
    }
    double res = 0;
    for(int i = n/2+1; i <= n; i++){
        res += dp[n][i+1];
    }
    cout << fixed << setprecision(10) << res << endl;
}



Measured memory_bytes: 70656
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	int index;
	int n;
	float t, a;
	float min;
	cin >> n >> t >> a;
	float h[n];
	for (i = 0; i < n; i++) 
		cin >> h[i];

	min = fabs(a - (t - h[0] * 0.006));
	index = 1;
	
	for (i = 1; i < n; i++) {
		if (min > fabs(a - (t - h[i] * 0.006))) {
			min = fabs(a - (t - h[i] * 0.006));
			index = i + 1;
		}
	}

	cout << index << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

struct xyz {
	int kyori;
	int index;
};

int main()
{
	int n, m;
	cin >> n >> m;
	
	vector<int> v(m);
	int sum = 0;
	for(int i = 0; i < m; i++) {
		cin >> v[i];
	}
	
	sort(ALL(v));
	
	vector<xyz> dist(m - 1);
	for(int i = 0; i < m - 1; i++) {
		dist[i].kyori = v[i + 1] - v[i];
		dist[i].index = i;
	}
	
	sort(ALL(dist), [](const xyz &a, const xyz &b){return a.kyori > b.kyori;});
	
	if(n >= m) {
		cout << 0 << endl;
	}
	else if(n == 1) {
		cout << v[v.size() - 1] - v[0] << endl;
	}
	else {
		int sum = v[v.size() - 1] - v[0];
		for(int i = 0; i < n - 1; i++) {
			sum -= dist[i].kyori;
		}
		cout << sum << endl;
	}
	
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;int a,m,l;main(){cin>>m>>m;pair<int,int>v[m];for(auto&x:v)cin>>x.second>>x.first;sort(v,v+m);for(auto&x:v)if(x.second>=l)l=x.first,a++;cout<<a;}

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

template <typename T>
class ModCalc{
public:
    ModCalc(T MOD){
        mod = MOD;
    }

    T add(T a, T b){
        return (a + b) % mod;
    }

    T sub(T a, T b){
        return (a - b) % mod;
    }

    T multi(T a, T b){
        return ((a % mod) * (b % mod)) % mod;
    }

    T power(T a, T n){
        T res = 1;
        while(n){
            if(n&1) res = multi(res, a);
            a = multi(a, a);
            n >>= 1;
        }
        return res;
    }

    T div(T a, T b){
        return multi(a, power(b, mod-2));
    }

    T comb(T n, T k){
        T res = 1;
        for(int i=0; i<k; i++){
            res = multi(res, n-i);
            res = div  (res, i+1);
        }
        return res;
    }

    T multicomb(T n, T k){
        return comb(n+k-1, k);
    }
private:
    T mod;
};

int main()
{
    int X, Y;
    cin >> X >> Y;
    auto n = (X + Y) / 3;
    if( (X+Y) % 3 > 0 || X - n < 0 || Y - n < 0){
        cout << 0 << endl;
        return 0;
    }
    auto mc = ModCalc<long long>(1000000007);
    cout<<mc.comb(n, X-n)<<endl;;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef vector<vector<ll>> vvl;
int main()
{
	string s,t;
	cin>>s>>t;
	t = t.substr(0,t.size()-1);
	if(s == t)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 3604
#N=int(input())
A,B,C,K = map(int,input().split())
#N=int(input())
#H = list(map(int,input().split()))
#S=str(input())
c=0
if K<=A:
    print(K)
elif K <= A+B:
    print(A)
elif K <= A+B+C:
    non=A+B+C-K
    min=C-non
    print(A-min)


Measured memory_bytes: 9164
N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]

root = [i for i in range(N + 1)]
comp_size = [1] * (N+1)
 
def root_find(x):
  y = root[x]
  if x == y:
    return x
  else:
    z = root_find(y)
    root[x] = z
    return z

def merge(x, y):
  #print(x, y)
  rx = root_find(x)
  ry = root_find(y)
  sx = comp_size[rx]
  sy = comp_size[ry]
  if rx == ry:
    return 0
  else:
    if sx >= sy:
      root[ry] = rx
      comp_size[rx] = sx + sy
    else:
      root[rx] = ry
      comp_size[ry] = sx + sy
    return sx * sy
    
for a, b in AB:
    merge(a, b)
#print(root)
#print(comp_size)

answer = []
for i in range(N + 1):
    answer.append(comp_size[root_find(i)] - 1)
#print(answer)

for a, b in AB:
    if root_find(a) == root_find(b):
        answer[a] -= 1
        answer[b] -= 1
for c, d in CD:
    if root_find(c) == root_find(d):
        answer[c] -= 1
        answer[d] -= 1
print(*answer[1:])

Measured memory_bytes: 115416
#include<stdio.h>
int main(){
	int a,b,c,d,p,x,y,r;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&p);
	if(c>p){
		y=b;
	}else{
		y=b+(p-c)*d;
	}
	x=a*p;
	if(y<x){
		r=y;
	}else{
		r=x;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define for_int register int
#define endl '\n'
#define ll long long
#define ld long double
using namespace std;
int main(){
	string s;
	cin>>s;
	int f=0;
	for(for_int i=0; i<s.length(); i++){
		if(s[i]=='C') {
			f=1;
		}
		if(f==1&&s[i]=='F'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (; ; )
            {
                var inputLine = Console.In.ReadLine();
                var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
                if (inputs.Length != 2)
                {
                    return;
                }

                var n = int.Parse(inputs[0]);
                var x = int.Parse(inputs[1]);
                if (n == 0 && x == 0)
                {
                    break;
                }

                int wayCount = 0;

                for (int i0 = 1; i0 <= n; ++i0)
                {
                    var remain0 = x - i0;   // よく読めばいらない
                    if (remain0 <= 0) break;

                    for (int i1 = i0 + 1; i1 <= n; ++i1)
                    {
                        var remain1 = remain0 - i1;
                        if (remain1 <= 0) break;

                        for (int i2 = i1 + 1; i2 <= n; ++i2)
                        {
                            var remain2 = remain1 - i2;
                            if (remain2 < 0) break;    // よく読めばいらない

                            if (remain2 == 0)
                            {
                                ++wayCount;
                            }
                        }
                    }
                }

                Console.WriteLine(wayCount);
            }
        }
    }
}



Measured memory_bytes: 15916
n=int(input())
blist = list(map(int, input().split()))

kazu=0

for i in range(n):
    if i==0:
        kazu+=blist[0]
    elif i==n-1:
        kazu+=blist[-1]
    else:
        kazu+=min(blist[i], blist[i-1])

print(kazu)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b, c, d, x, y, z, w;
	cin >> a >> b >> c >> d >> x >> y >> z >> w;
	
	int s1 = a * x + b * y, s2 = c * x + d * y;
	s1 += (a / 10) * z + (b / 20) * w;
	s2 += (c / 10) * z + (d / 20) * w;
	if(s1 == s2) cout << "even" << endl;
	else cout << (s1 > s2 ? "hiroshi" : "kenjiro") << endl;
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define fast_io ios :: sync_with_stdio(false);
using namespace std;

int main() {
	cout << fixed << setprecision(3);
	fast_io;
	int x, n, h;
	int cont = 0;
	cin >> n;
	int max = 0;
	while (n--) {
		cin >> h;
		if(h >= max) {
			cont++;
			max = h;
		} 
	}
	cout << cont;
	return 0;	
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;//ｎ台のロボットと、ｂのロボットがいるｘ座標ｋ
	cin >>n>>k;
	int length=0;

	for(int i=0;i<n;i++){
		int x;
		cin >>x;
//xとｋ－ｘの値の大小で処理を分ける。ｘのほうが大きければロボットｂが動く
		if(x>k-x){
			length += 2*(k-x);
		}
		else if (x <= k-x){
			length += 2*x;
		}
	}
	cout <<length<<endl;
}	


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = 0;

        for (int i = a; i <= b; i++) {
            String s = String.valueOf(i);
            if (s.charAt(0) == s.charAt(4) && s.charAt(1) == s.charAt(3)) {
                c++;
            }
        }
        System.out.print(c);
    }
}


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

int N;
int A,B,C;
vector<int> l;
int ans = 1001001001;

void dfs(vector<int> d){
    if(d.size()==N){
        vector<int> material(3,0);
        int point = 0;
        for(int i=0;i<N;i++){
            if(d[i]==3) continue;
            if(material[d[i]]!=0) point += 10;
            material[d[i]] += l[i];
        }
        if(material[0]*material[1]*material[2]==0) return;
        
        point += abs(A-material[0]) + abs(B-material[1]) + abs(C-material[2]);
        ans = min(ans,point);
        return;
    }

    for(int i=0;i<4;i++){
        d.push_back(i);
        dfs(d);
        d.pop_back();
    }
}

int main(void){
    cin >> N >> A >> B >> C;
    l.resize(N);
    for(int i=0;i<N;i++) cin >> l[i];
    dfs({});
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X, T;
    cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ATrain {
public:
	void solve(istream& in, ostream& out) {
        int a, b;
        in >> a >> b;
        out << a - b + 1 << endl;
	}
};

int main() {
	ATrain solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
    int f;
    int n;
    cin>>n;
    for(int i=n;i>0;i/=10)
    {
        f+=i%10;
    }
    if(n%f==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cerr<<#x<<"\n";  each(y,x) cerr<<y<<" "; cerr<<'\n';}
#define debug_vp(x) { cerr<<#x<<"\n";  each(y,x) cerr<<y.ff<<" "<<y.ss<<'\n'; cerr<<'\n';}
#ifndef BTW
	#define cerr if(false)cerr
#endif
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

string s[200];

int main(){
	fastio;
	int h,w,k;
	cin>>h>>w>>k;
	rep(i,h){
		cin>>s[i];
	}
	int res=1e9;
	rep(mask,(1<<(h-1))){
		set<int> dk;
		rep(i,h-1){
			if(mask&(1<<i)){
				dk.insert(i);	
			}
		}
		vi cnt(dk.size()+1);
		int ans=dk.size();
		rep(j,w) {
			int cur=0;
			rep(i,h){
				cnt[cur]+=(s[i][j]=='1');
				if(dk.count(i)) cur++;
			}
			if(*max_element(all(cnt))>k){
				ans++;
				cur=0;
				fill(all(cnt),0);
				rep(i,h){
					cnt[cur]+=(s[i][j]=='1');
					if(dk.count(i)) cur++;
				}
			}
		}
		if(*max_element(all(cnt))<=k){
			res=min(res,ans);
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

double toRadian(int degree)
{
    if( degree == 0 ) return (double)0;
    else return (degree / (180 / M_PI));
}

int main()
{
    int a, b, C;
    scanf("%d%d%d", &a, &b, &C);

    double S, L, h;
    S = (double)(a * b * sin(toRadian(C)) / 2);
    //L = (double)(2 * S);
    h = (double)(2 * S / a);
    double c = sqrt(pow(a, 2) - 2*a*b*cos(toRadian(C)) + pow(b, 2));
    L = (double)(a + b + c);
    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}

Measured memory_bytes: 684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;


class Main {
	public static void main(String[] args) throws IOException {
		DecimalFormat df1 = new DecimalFormat("0.000000");
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> iL = new ArrayList<Integer>();
		while(true){
			String s1 = new String(in.readLine());
			if(s1.equals("0")){
				break;
			}
			int num = Integer.parseInt(s1);
			String s2 = new String(in.readLine());
			String[] s2s = s2.split(" ");
			int sum = 0;
			for(int i = 0; i < s2s.length; i++){
				sum = sum + Integer.parseInt(s2s[i]);
			}
			iL.add(sum/(num-1));
		}
		for(Integer i : iL){
		
			System.out.println(i);
		}
		
	}

}

Measured memory_bytes: 31220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    string s; cin>>s;
    ll ans=0; ll k=0;
    for(int i=0;i<=s.size()-1;i++){
		if(s[i]=='W'){
			ans=ans+i-k;
			k++;
		}
	}
	cout<<ans<<endl;
    
}


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

using namespace std;

int gcd(int a, int b) {
  return !b ? a : gcd(b, a % b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (360 / gcd(n, 360)) << '\n';
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;

  int ans = H*W - (H*w + h*W - h*w);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define vi vector<long long>
#define pi pair<ll ,ll>
#define mkp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

ll n, ans=0;
vector<string> v(100000);

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
//freopen("B.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> v[i];
        sort(all(v[i]));
    }
    sort(v.begin(), v.begin()+n);
    ll sm=1;
    for(int i=0; i<n-1; i++)
    {
        if(v[i]==v[i+1])
        {
            sm++;
        }
        else
        {
            ans+=sm*(sm-1)/2;
            sm=1;
        }
    }
    cout << ans + sm*(sm-1)/2;
}



Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>

using namespace std;

int n,m;
int k[10],s[10][10],p[10];
int swch[10] = {0};
int ans = 0;
int enkh = 0;

void solve(int cnt,int sw[10]){
  if(cnt == -1){
    int flag = 1;
    for(int i = 0; i < m ; i++){
      if(!flag) break;
      int temp = 0;
      //printf("k[%d] = %d\n",i,k[i]);
      for(int j = 0; j < k[i]; j++){
        if(sw [ s[i][j]-1 ] == 1) temp++;
        //printf("s[%d][%d] = %d\n",i,j,s[i][j]);
      }
      temp = temp % 2;
      //printf("i:%d temp:%d\n",i,temp);
      if(p[i] == temp) flag = 1;
      else flag = 0;
    }

    if(flag) ans++;
    return ;
  }
  sw[cnt] = 0;
  solve(cnt-1,sw);
  sw[cnt] = 1;
  solve(cnt-1,sw);
  return ;
}

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

  for(int i = 0; i < m; i++){
    cin >> k[i];
    //printf("\nhere : k[%d] = %d\n",i,k[i]);
    for(int j = 0; j < k[i] ; j++){
      cin >> s[i][j];
    }
  }

  for(int i = 0; i < m ; i++)
    cin >> p[i];

  solve(n-1,swch);

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_8_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] CountCharacter = new int['z' - 'a' + 1];

            while (true)
            {
                string str = Console.ReadLine();
                if (str == null)
                    break;
                for (int i = 0; i < str.Length; i++)
                {
                    if ('a' <= str[i] && str[i] <= 'z')
                    {
                        CountCharacter[(str[i] - 'a')] += 1;
                    }
                    else if ('A' <= str[i] && str[i] <= 'Z')
                    {
                        CountCharacter[(str[i] - 'A')] += 1;
                    }
                }
            }

            for (int i = 0; i < ('z' - 'a' + 1); i++)
            {

                char Character = (char)('a' + i);
                Console.WriteLine("{0} : {1}", Character, CountCharacter[i]);
            }
        }
    }
}

Measured memory_bytes: 5616
from bisect import bisect_right
from itertools import product, chain

N = int(input())

# product("357", repeat=len(str(N)))
l = list(chain(*[[int("".join(m)) for m in product("357", repeat=i) if set(m) == {"3", "5", "7"}] for i in range(1, len(str(N))+1)]))
# print(l)
print(bisect_right(l, N))

Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    bool ok=false;
    if(n%10==9)ok=true;
    n/=10;
    if(n%10==9)ok=true;
    cout<<(ok==true?"Yes":"No")<<endl;
}


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

int N, a[300000];
long long int ans;

int comp(const void *p1, const void *p2) { return *(const int *)p1 - *(const int *)p2; }

int main(void) {
	int i, count;

	scanf("%d", &N);
	for (i = 0; i < 3 * N; i++) scanf("%d", &a[i]);
	qsort(a, N * 3, sizeof(int), comp);

	i = N * 3 - 1;
	count = 0;
	while (count < N) {
		ans += a[i - 1];
		i -= 2;
		count++;
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2556
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

const int VERY_LARGE_NUM = 1e8;

void dijkstra(int start_node_id, int size, const vector<vector<int>>& g,
              vector<int>& color, vector<int>& d) {
  d[start_node_id] = 0;
  color[start_node_id] = 1;
  while (1) {
    int min_cost = VERY_LARGE_NUM;
    int u = -1;
    for (int i = 0; i < size; i++) {
      if (color[i] != 2 && d[i] < min_cost) {
        min_cost = d[i];
        u = i;
      }
    }
    if (u == -1) break;
    color[u] = 2;
    for (int i = 0; i < size; i++) {
      if (g[u][i] > 0 && color[i] != 2) {
        if (d[i] > d[u] + g[u][i]) {
          d[i] = d[u] + g[u][i];
          color[i] = 1;
        }
      }
    }
  }
}

int main() {
  int n, u, k, c, v;
  cin >> n;
  vector<vector<int>> g(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      g[u][v] = c;
    }
  }
  debug(g);
  vector<int> color(n);
  vector<int> d(n, VERY_LARGE_NUM);
  dijkstra(0, n, g, color, d);
  for (int i = 0; i < n; i++) {
    cout << i << ' ' << d[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3136
_ = input()
a = input().split()
n = len(a)
if n % 2 == 0:
    a1 = list(reversed(a[1::2]))
    a2 = a[::2]
else:
    a1 = list(reversed(a[::2]))
    a2 = a[1::2]
print(" ".join(a1 + a2))

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >

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

int main() {
  int a,b;
  cin >> a >> b;
  rep(i,1000){
    if(b-a==(i+1)*(i+2)/2-i*(i+1)/2){
      cout << i*(i+1)/2-a << endl;
      return 0;
  }
}
  return 0;
}


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

using namespace std;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

void solve()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	for(auto&& i : a)
	{
		for(auto&& j : i)
		{
			cin >> j;
		}
	}
	string ans = "";
	int cnt = 0;
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w - 1; j++)
		{
			if(a[i][j] % 2)
			{
				cnt++;
				a[i][j + 1]++;
				ans += "" + to_string(i + 1)  + " " + to_string(j + 1) + " " + to_string(1 + i) + " " + to_string(j + 2) + "\n";
			}
		}
		if(i + 1 < h && a[i][w - 1] % 2)
		{
			cnt++;
			a[i + 1][w - 1]++;
			ans += "" + to_string(1 + i) + " " + to_string(w) + " " + to_string(i + 2) + " " + to_string(w) + "\n";
		}
	}
	cout << cnt << "\n";
	if(cnt)	cout << ans;
}

int main()
{
	solve();
}


Measured memory_bytes: 5124