akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    double n, m; cin >> n >> m;
    vector<double> a(n);
    double sum = 0;
    bool ok = true;
    for(int i=0; i<n; ++i){cin >> a[i]; sum += a[i];}
    sort(a.begin(), a.end(), greater<int>());
    for(int i=0; i<m; ++i){
        if(a[i] < (sum/4/m)){ok = false; break;}
    }
    if(ok){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}   


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
  int i;
  int sum;
  int price;
  int amount;

  while (1){

    scanf("%d", &amount);

    if (amount == 0){
      break;
    }

    sum = 0;

    for(i = 0; i < 9; i++){
      scanf("%d", &price);
      sum += price;
    }
    printf("%d\n", amount - sum);
  }

  return (0);
}

Measured memory_bytes: 600
#include <stdio.h>

int main() {
	int i,x,y;

	while (1) {
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0) break;

		if (x > y) {
			printf("%d %d\n", y, x);
		}
		else if (x < y || x == y) {
			printf("%d %d\n", x, y);
		}
	}

	return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int a,b; cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;
}


Measured memory_bytes: 3648
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import scipy as sp

def main():
    try:
        input_list = input().split()
        N = int(input_list[0])
        K = int(input_list[1])
        print(N-K+1);
    except:
        pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 12508
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    int num = stoi(a + b);
    for (int i = 0; i <= 1000; i++){
        if (i * i == num){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),m=in.nextInt(),t=in.nextInt();
		int time=0,A[]=new int[n];
		boolean inlib=true;
		for(int i=0;i<n;i++)A[i]=in.nextInt();
		for(int i=0;i<n;i++) {
			if(inlib) {
				time+=m;
				inlib=false;
				//System.out.println("go entrance");
			}
			else if(i>0 && A[i]-A[i-1]<2*m)time+=A[i]-A[i-1];
			if(i<n-1 && A[i+1]-A[i]>=2*m) {
				time+=m;
				inlib=true;
				//System.out.println("go lib");
			}
			if(i==n-1 && t-A[i]<m)time+=t-A[i];
			else if(i==n-1)time+=m;
			
			//System.out.printf("i=%d time=%d\n",i,time);
		}
		System.out.println(t-time);
	}

}



Measured memory_bytes: 26380
#include<iostream>

using namespace std;

int main(){

  int n;

  int n0,n1,st;
  //initialize
  n0=0;
  n1=1;
  
  //load number
  cin >>n;
  //fibonacci
  for(int i=1;i<=n;i++){
    st=n0+n1;
    n0=n1;
    n1=st;
  }
  //print
  cout <<st<<endl;
  return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	line := ""
	var A, B, C, D int
	fmt.Scan(&line)
	fmt.Sscanf(line, "%1d%1d%1d%1d", &A, &B, &C, &D)
	for i := 0; i < 8; i++ {
		x := A
		ans := fmt.Sprintf("%d", A)

		if (i & 1) > 0 {
			x += B
			ans = fmt.Sprintf("%s+%d", ans, B)
		} else {
			x -= B
			ans = fmt.Sprintf("%s-%d", ans, B)
		}

		if (i & 2) > 0 {
			x += C
			ans = fmt.Sprintf("%s+%d", ans, C)
		} else {
			x -= C
			ans = fmt.Sprintf("%s-%d", ans, C)
		}

		if (i & 4) > 0 {
			x += D
			ans = fmt.Sprintf("%s+%d=7", ans, D)
		} else {
			x -= D
			ans = fmt.Sprintf("%s-%d=7", ans, D)
		}

		if x == 7 {
			fmt.Println(ans)
			break
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  char str[51];
  int i, j;

  while(scanf("%s", str) != EOF){
    for(i = 0; str[i] != '\0'; i++){
      if(str[i] == '@'){
	i += 2;
	for(j = str[i-1]-'0'; j > 0; j--){
	  printf("%c", str[i]);
	}
      }else{
	printf("%c", str[i]);
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 524
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    L = sorted(in_nl())

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                    if L[k] < L[i] + L[j]:
                        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67812
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string s;
    while (cin >> s, s != "-")
    {
        int n = s.length(), m;
        cin >> m;
        for (int i = 0; i < m; i++)
        {
            int h;
            cin >> h;
            string sub = s.substr(h, n - h) + s.substr(0, h);
            s = sub;
        }
        cout << s << endl;
    }
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin() (x).end()
#define rall(x) (x).rbegin() (x).rend()
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;

void B(){
	/**int n; cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	if(n<3)cout<<0<<endl;
	else{
		int nt=0;
		for(int i=0; i<n-1; i++){
			int a=arr[i];
			for(int j=i+1; j<n; j++){
				int b=arr[j];
				for(int k=j+1; k<n; k++){
					int c=arr[k];
					if(a!=b && b!=c && c!=a){
						if(a+b>c && a+c>b && c+b>a){
							nt++;
						}
					}
				}
			}
		}
		cout<<nt<<endl;
	}*/
}

int main(){
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll dv=x/d, n=x%d, m=abs(n-d);
	if(k>=dv){
		k-=dv;
		cout<<(k%2==0?n:m)<<endl;
	}
	else{
		cout<<abs(x-(k*d))<<endl;
	}
}



Measured memory_bytes: 3612
//atcoder 176 A
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, k, t, x;
	cin >> n >> k >> t;
	if (n % k == 0) x = n / k;
	else x = n / k + 1;
	cout << x * t << endl; 
} 

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; }

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> D(K);
    rep(i,K) cin >> D[i];
    for (size_t i = N; i <= 10*N; i++)
    {
        bool flag = false;
        rep(j,GetDigit(i)){
            rep(k,K){
                int a = i/pow(10,j);
                if(a%10 == D[k]){
                    flag = true;
                }
                if(flag) break;
            }
            if(flag) break;
        }
        if(!flag){
            cout << i << endl;
            break;
        }
    }
    
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    bool can = false;
    for (int i=0; i<=n; ++i) {
        for (int j=0; j<=m; ++j) {
            if (i*j + (n-i)*(m-j) == k) can = true;
        }
    }
    cout << (can ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

if x in [1, 3, 5, 7, 8, 10, 12]:
    x_j = 1

elif x in [2]:
    x_j = 2

elif x in [4, 6, 9, 11]:
    x_j = 3

if y in [1, 3, 5, 7, 8, 10, 12]:
    y_j = 1

elif y in [2]:
    y_j = 2

elif y in [4, 6, 9, 11]:
    y_j = 3

if (x_j == y_j):
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9136
#include <stdio.h>

int main(){
    int a, x;
    0 <= a <= 9;
    0 <= x <= 9;

    scanf("%d %d", &x, &a);
    if(x < a){
        printf("%d", 0);
    }else if(a <= x){
        printf("%d", 10);
    }
    return 0;
}    


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    int count0=0;
    int count1=0;
    for(char i:s){
        if(i=='0')count0++;
        else count1++;
    }
    cout << 2*min(count0,count1) <<endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

ll table_5[120][5],index_10,leftTable[120],rightTable[120],m_data[10] = {0,1,2,3,4,5,6,7,8,9};
ll* table_10;

void calc10(){

	int select_num = 5,num,loc_left[5],loc_right[5],left_index,right_index,index,calc[5],value;

	index_10 = 0;

	for(int i = 0; i < 1024;i++){
		num = 0;
		for(int k = 0; k < 10; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		//??°???????????????????????????
		for(int k = 0; k < 10; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		calc[0] = m_data[loc_left[0]],calc[1] = m_data[loc_left[1]],calc[2] = m_data[loc_left[2]],calc[3] = m_data[loc_left[3]],calc[4] = m_data[loc_left[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			leftTable[left_index++] = value;
		}

		calc[0] = m_data[loc_right[0]],calc[1] = m_data[loc_right[1]],calc[2] = m_data[loc_right[2]],calc[3] = m_data[loc_right[3]],calc[4] = m_data[loc_right[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			rightTable[right_index++] = value;
		}

		for(int k = 0; k < 120; k++){
			for(int p = 0; p < 120; p++){
				table_10[index_10++] = 100000*leftTable[k] + rightTable[p];
				//printf("%lld\n",table_10[index_10-1]);
			}
		}
	}
}


int main(){

	table_10 = new ll[3628800];

	int index_5 = 0;

	for(int a = 0; a < 5; a++){
		for(int b = 0; b < 5; b++){
			for(int c = 0; c < 5; c++){
				for(int d = 0; d < 5; d++){
					for(int e = 0; e < 5; e++){
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e){
							table_5[index_5][0] = a,table_5[index_5][1] = b,table_5[index_5][2] = c,table_5[index_5][3] = d,table_5[index_5][4] = e;
							index_5++;
						}
					}
				}
			}
		}
	}

	calc10();

	ll tmp,base_num = 0,length,maximum = -1,ans,val;

	char buf[11];

	scanf("%s",buf);

	for(length = 0;buf[length] != '\0';length++);

	for(int i = 0; i < length; i++){
		base_num = 10*base_num + buf[i] - '0';
	}

	ll S = pow(10,length),S2 = pow(10,length-1);

	for(int i = 0; i < 3628800; i++){
		val = table_10[i]%S;
		tmp = min(abs(val-base_num),S-abs(val-base_num));
		if(tmp > maximum){
			maximum = tmp;
			ans = val;
		}else if(tmp == maximum){
			if(ans > val){
				ans = val;
			}
		}
	}

	if(ans/S2 == 0)printf("0");
	printf("%lld\n",ans);

	return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e5 + 4;
const int N = 21;

int n;
ll v[T];
ll acum[T][N];

bool noRep(int l, int r) {
    for(int i = 0; i < N; i++)
        if(acum[r][i]-acum[l-1][i] > 1) return 0;
    return 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;

    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        for(ll j = 1, casa = 0; j <= v[i]; j <<= 1, casa++)
            acum[i][casa] += ((v[i]&j) > 0);
        for(int j = 0; j < N; j++) acum[i][j] += acum[i-1][j];
    }

    int l = 1;
    int r = 1;
    ll ans = 0;

    while(r <= n) {
        while(l < r and (!noRep(l,r))) l++;
        while(r < n and noRep(l,r+1)) ans += (r-l+1), r++;
        ans += (r-l+1);
        r++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 34688
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a%2==0||b%2==0||c%2==0){
    printf("0\n");
  }else{
    printf("%lld\n",min(a*1ll*b,min(a*1ll*c,b*1ll*c)));
  }
  return 0;
}


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

using namespace std;

int main() {
    bool good = true;
    bitset<30> ok;
    ok.reset();
    string s;
    cin >> s;
    for(auto c: s)
        ok[c - 'A'] = true;
    if(ok['N' - 'A']) if(!ok['S' - 'A']) good = false;
    if(ok['S' - 'A']) if(!ok['N' - 'A']) good = false;
    if(ok['W' - 'A']) if(!ok['E' - 'A']) good = false;
    if(ok['E' - 'A']) if(!ok['W' - 'A']) good = false;
    cout << (good ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
n=int(input())
if(n==0):
    print(0)
else:
    sum=0
    temp=n//500
    n=n-(temp*500)
    sum+=(temp*1000)
    if(n==0):
        print(sum)
    else:
        temp=n//5
        sum+=(temp*5)
        print(sum)


Measured memory_bytes: 2940
def A_TakandHotels():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    ans = 0
    if K < N:
        ans = X * K + (N-K) * Y
    else:
        ans = X * N
    print(ans)
    
if __name__ == "__main__":
    A_TakandHotels()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    string S;
    long K;
    cin >> S >> K;
    if(K>=100)K=100;
    repi(i,K){
        if(S.at(i) != '1'){
            cout << S.at(i) << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a, b;

    while (cin >> a >> b, a != 0 && b != 0) {

        int dp[17][17] = { 0 };
        int n;
        cin >> n;
        dp[1][1] = 1;

        for (int i = 1; i <= n; i++) {
            int x, y;
            cin >> x >> y;
            dp[x][y] = -1;
        }

        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= b; j++) {

                if (dp[i][j] != -1) {
                    if (j != 1 && dp[i][j - 1] != -1) {
                        dp[i][j] += dp[i][j - 1];
                    }

                    if (i != 1 && dp[i - 1][j] != -1) {
                        dp[i][j] += dp[i - 1][j];
                    }
                }
            }
        }
        cout << dp[a][b] << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 60) - 1;
int MOD = 1e9+7;
main(){
    string S;
    ll K;
    cin >> S >> K;
    string str = S + S + S;
    ll cnt = 0, ans = 0;
    rep(i,1,S.size()){
        if(S[i] == S[i-1]){
            S[i] = '*';
            cnt++;
            i++;
        }
    }
    ans = cnt * K;
    if(S[0] == S.back()){
        ans += K - 1;
    }
    //cout << ans << endl;

    
    int sub = 0;
    rep(i,1,str.size()){
        if(str[i] == str[i-1]){
            sub++;
            i++;
        }
    }
    //cout << cnt * 3 + 2 << endl;
    //cout << sub << endl;
    
    ll num = INF;
    if(cnt * 3 + 2 > sub){
        num = cnt + (sub - cnt) * ((K-1)/2);
        if(K % 2 == 0)num += cnt + 1;
    }
    //cout << ans << endl;
    //cout << num << endl;
    ans = min(ans, num);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int x,n;
	cin >> n;
	for(x=1;x<50001;x++){
            int y = (int)(x*1.08); 
	    if(y==n){ cout << x << endl;
            return 0;}
        }
        cout << ":(" << endl;

	return 0;
}

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

int main(){
	ll n,a,b,c;
	cin >> n >> a >> b >> c;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	if(a + b + c == 0){
		cout << "No" << endl;
		return 0;
	}
	string ans = "";
	bool ok = true;
	rep(i,n){
		if(s[i] == "AB"){
			if(a == 0 && b == 0){
				ok = false;
				break;
			} else if (a == 0){
				a++; b--;
				ans.push_back('A');
			} else if (b == 0){
				b++; a--;
				ans.push_back('B');
			} else if (i < n-1 && s[i+1] == "BC"){
				b++; a--;
				ans.push_back('B');
			} else {
				a++;
				b--;
				ans.push_back('A');
			}
		}else if(s[i] == "AC"){
			if(a == 0 && c == 0){
				ok = false;
				break;
			} else if (a == 0){
				a++; c--;
				ans.push_back('A');
			} else if (c == 0){
				c++; a--;
				ans.push_back('C');
			} else if (i < n-1 && s[i+1] == "BC"){
				c++; a--;
				ans.push_back('C');
			} else {
				a++;
				c--;
				ans.push_back('A');
			}
		}else if(s[i] == "BC"){
			if(b == 0 && c == 0){
				ok = false;
				break;
			} else if (b == 0){
				b++; c--;
				ans.push_back('B');
			} else if (c == 0){
				c++; b--;
				ans.push_back('C');
			} else if (i < n-1 && s[i+1] == "AB"){
				b++; c--;
				ans.push_back('B');
			} else {
				c++;
				b--;
				ans.push_back('C');
			}
		}
	}
	if(ok){
		cout << "Yes" << endl;
		rep(i,n){
			cout << ans[i] << endl;
		}
	}else{
		cout << "No" << endl;
	}
    return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int ans = 0;
  if (n % 2 == 0 && x == n / 2 && m % 2 == 0 && y == m / 2) ans++;
  cout << fixed << setprecision(10);
  cout << double(n) * double(m) / 2.0 << ' ' << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3804
import sys
import itertools
import numpy
input = sys.stdin.readline
Sa = input()
Ta = input()
S = ['0'] * len(Sa)
T = ['0'] * len(Ta)
for i in range(len(Sa)) :
    S[i] = Sa[i]
for i in range(len(Ta)) :
    T[i] = Ta[i]
ans = {}
for cs,ct in zip(S,T) :
    if cs not in ans.keys() and ct not in ans.values() :
        ans[cs] = ct
    else :
        try :
            if ans[cs] == ct :
                continue
            else :
                print("No")
                break
        except KeyError :
            print("No")
            break
else :
    print("Yes")

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

int main()
{
  int N, K; cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];

  vector<int> dp(N+2, INT_MAX / 2);
  dp[0] = 0;

  for (int i = 0; i < N-1; i++)
  {
    for (int j = 1; j <= K; j++)
    {
      if (i + j >= N) continue;
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }

  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using P = pair<ll,int>;
const P NG(-1,-1);

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

    vector<int> t(n);
    vector<ll> d(n);
    rep(i,n){
        cin >>t[i] >>d[i];
        --t[i];
    }

    vector<P> mx(n,NG);
    rep(i,n){
        mx[t[i]] = max(mx[t[i]], {d[i],i});
    }

    vector<P> TOP;
    rep(i,n){
        if(mx[i]==NG) continue;
        TOP.pb(mx[i]);
    }
    sort(all(TOP));
    reverse(all(TOP));
    int T = TOP.size();

    ll rem_sum = 0;
    multiset<P> ms;
    rep(i,n){
        ms.insert({d[i],i});
        rem_sum += d[i];

        if(ms.size()>k){
            auto itr = ms.begin();
            rem_sum -= itr->fi;
            ms.erase(itr);
        }
    }

    ll ans = 0;
    ll top_sum = 0;
    for(ll x=1; x<=k; ++x){
        if(x > T) break;

        P add = TOP[x-1];

        top_sum += add.fi;
        int idx = add.se;

        if(ms.count(add)){
            ms.erase(add);
            rem_sum -= add.fi;
        }
        else{
            auto itr = ms.begin();
            rem_sum -= itr->fi;
            ms.erase(itr);
        }

        // printf(" x %d :: top %lld rem %lld\n",x,top_sum,rem_sum);
        ans = max(ans, top_sum+rem_sum+x*x);
    }

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


Measured memory_bytes: 9844
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    av = sum(a)/n
    aa = list(map(lambda x: abs(x - av), a))
    aa = list(zip(aa, range(n)))
    aa.sort()
    print(aa[0][1])
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll a[10011];
int main()
{ll n,b=0;cin>>n;
fo(i,0,n)cin>>a[i];
fo(i,0,n)if(a[i]%2==0)
while(a[i]%2==0){
	a[i]/=2;b++;
}
cout<<b;
system("pause");
return 0;
}

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

int main() {
  int n,p;
  cin >> n;
  string s,v,ans;
  cin >> s;
  //p = s.size;
  if(n%2 != 0){ans = "No";}
  v = s.substr(0,n/2);
  if(v + v == s){ans = "Yes";}
  else{ans = "No";}
  cout << ans << endl;
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using ld = long double;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int64 N, K, X, Y;
	cin >> N >> K;
	cin >> X >> Y;
	if(N <= K){
		cout << X*N << endl;
	}else{
		cout << X*K+Y*(N-K) << endl;
	}
}


Measured memory_bytes: 256
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,odr):
        if   odr=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif odr=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif odr=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif odr=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]

label = list(map(int, input().split()))
d1 = dice(label)
d2 = list(map(int, input().split()))
for odr in 'EEENEEENEEESEEESEEENEEEN':
    if d1.get_label() == d2:
        print('Yes')
        break
    d1.roll(odr)
else:
    print('No')


Measured memory_bytes: 5608
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(list) (list.begin()), (list.end())

using namespace std;
typedef long long ll;
const int MOD = 10000007;
const long double PI = 3.14159265358979323846264338327950L;

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

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

vector<long long> divisor(long long n) { // don't sort
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  return (ret);
}

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

void execute() {
  int n;
  cin >> n;
  int ans = 0, mini = MOD;
  REP(i, 0, n) {
    int a;
    cin >> a;
    mini = min(mini, a);
    if (a == mini) {
      ans += 1;
    }
  }
  cout << ans << endl;
}

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

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

  execute();

  return (0);
}


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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int n, q;
    int count = 0;
    vector<int> s, t;
    cin >> n;
    REP(i,n){
        int x;
        cin >> x;
        s.push_back(x);
    }
    cin >> q;
    REP(j, q){
        int x;
        cin >> x;
        t.push_back(x);
    }
    sort(ALL(s));
    REP(i, q){
        if(binary_search(ALL(s), t[i]))
            count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1800
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
string a,b,st;
double q,zf,xs,i;
int main()
{
	cin>>a>>b;
	st=a+b;
	for (i=0;i<st.size();i++) q=q*10+st[i]-48;
	zf=trunc(sqrt(q));
	xs=sqrt(q);
	if(zf==xs) cout<<"Yes"; else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<30, stdin), p1 == p2) ? EOF : *p1++)
char buf[1<<30], *p1 = buf, *p2 = buf;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int ab[100001];
int main(int argc, char *argv[])
{
	int i;
	int n = read(),m = read();
	for (i = 0; i < m; ++i) {
		int a = read(),b = read();
		if (*(ab+b) < a) {*(ab+b) = a;}
	}
	int ans = 0;
	int k = 1;
	for (i = 1; i <= n; ++i) {
		if (k <= *(ab+i)) {
			k = i;
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main() {
  string ss, left, right, end;
  int times, in;

  while (true)
  {
    cin >> ss;
    if (ss == "-") { break; }

    cin >> times;
    for (int i = 0; i < times; i++)
    {
      cin >> in;

      right = ss.substr(0, in);
      left = ss.substr(in, ss.size()-1);
      
      ss = left + right;
    }

    cout << ss << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
}


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

using namespace std;

string s;
int u[1000], n;

int main(){
      cin >> s;

      if(s == "zyxwvutsrqponmlkjihgfedcba"){
            puts("-1");
            return 0;
      }

      n = s.size();

      for(int i = 0; i < n; i ++)
            u[s[i] - 'a'] = 1;

      if(n < 26){
            for(int i = 0; i < 26; i ++){
                  if(!u[i]){
                        s += char(i + 'a');
                        break;
                  }
            }
      } else {
            memset(u, 0, sizeof(u));
            string ans;
            for(int i = n - 1; i >= 0; i --){
                  u[s[i] - 'a'] = 1;
                  int cnt = 0;
                  for(int j = s[i] - 'a' + 1; j <= 26; j ++){
                        cnt += u[j];
                  }

                  if(cnt){
                        for(int j = 0; j < i; j ++)
                              ans += s[j];
                        for(int j = s[i] - 'a' + 1; j <= 26; j ++){
                              if(u[j]){
                                    ans += char(j + 'a');
                                    break;
                              }
                        }
                        break;
                  }
            }
            s = ans;
      }
      cout << s << endl;
}


Measured memory_bytes: 256
s=input()
import re
import copy

s1=re.sub('(A)','1',s)
s2=re.sub('(BC)','2',s1)
s3=re.sub('\D+','3',s2)

s=list(s3.split('3'))

ans=0
for i in s:
    count=0
    tmp=map(int,list(i))
    tmp=list(tmp)
    tmp2=copy.copy(tmp.reverse())
    for j in tmp:
        if j==2:
            count+=1
        elif j==1:
            ans+=count
print(ans)




Measured memory_bytes: 68080
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long int n;
    int m;
    cin >> n >> m;
    long long int time_sum = 100*(n-m) + 1900*(m);
    cout << (long long int)(time_sum * pow(2.0, (double)m)) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int num = r * 100 + g * 10 + b * 1;
        
        System.out.println((num % 4 == 0)? "YES" : "NO");
    }
}


Measured memory_bytes: 20820
#include<iostream>

using namespace std;

int MAX_N = 1000;

int main()
{
    // スペース区切りの整数の入力
    long long N,K;
    cin >> N >> K;

    long long x,pre_x;
    x = N;
/*
    if (K == 1 || N == 0)
    {
        cout << 0 << endl;
        return 0;
    }
*/
/*
    while (x > 0)
    {
        x = x - K;
    }
    */

    x = N % K;
    pre_x = abs(x - K);
/*
    pre_x = x + K;
    x = abs(x);
*/

    if (x>=pre_x)
    {
        cout << pre_x << endl;
    }else
    {
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	//auto tokens = split(my_readln());
	auto N = my_readln().to!ulong();
	ulong[] A, B;
	long[] C;
	foreach (token; split(my_readln()))
	{
		A ~= token.to!ulong;
	}
	foreach (i, token; split(my_readln()))
	{
		B ~= token.to!ulong;
		C ~= A[i] - B[$-1];
	}
	auto index = new ulong[C.length];
	makeIndex(C, index);

	long ans;
	long want;
	foreach (i, ci; index)
	{
		if (C[ci] >= 0)
		{
			ans = i;
			break;
		}
		want -= C[ci];
	}
	foreach_reverse (i, ci; index)
	{
		if (want <= 0)
		{
			ans += index.length - i - 1;
			break;
		}
		if (C[ci] <= 0)
		{
			ans = -1;
			break;
		}
		want -= C[ci];
	}

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 12008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
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; }



int main(int argc, char const *argv[]) {
  int a[10],sum=0;
  rep(i,5){
    std::cin >> a[i];
    sum+=a[i];
  }
  int ans=INF;
  for(int i=0; i<5; i++){//i:最後の料理
    int res=a[i];
    for(int j=0; j<5; j++){
      if(j!=i){
        if(a[j]%10==0) res+=a[j];
        else res+=a[j]+10-a[j]%10;
      }
    }
    ans=min(ans,res);
  }
  std::cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s0 = list(["." for _ in range(w+2)])
s1 = [list("." + input() + ".") for _ in range(h)]
s = []
s.append(s0)
s = s + s1
s.append(s0)
a = [-1,0,1]
b = [-1,0,1]
for i in range(1,h+1) :
    for j in range(1,w+1):
        if not s[i][j] == "#":
            cnt = 0
            for ii in range(3):
                for jj in range(3):
                    if s[i+a[ii]][j+a[jj]] == "#":
                        cnt +=1
            s[i][j] = str(cnt)
for i in range(1,h+1) :
    for j in range(1,w+1):
        print(s[i][j],end="")
    print()

Measured memory_bytes: 3572
N = int(input())
ans = [0 for i in range(10 ** 4 + 1)]
for i in range(1,100):
    for i2 in range(1,100):
        for i3 in range(1,100):
            k = i**2 + i2 ** 2 + i3 ** 2 + i * i2 + i2 * i3 + i3 * i
            if k <= 10 ** 4:
                ans[k] += 1
for i in range(N):
    print(ans[i+1])


Measured memory_bytes: 9432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int n,m,homework_days=0;
cin>>n>>m;
for (int i = 0; i < m; i++)
{
    int days;
    cin>>days;
    homework_days+=days;
}

if (homework_days<=n)
{
    cout<<n-homework_days<<endl;
}
else
{
    cout<<-1<<endl;
}

    return 0;
}

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


int main() {
	int N, M; cin >> N >> M;
	vector<int>vs;
	for (int i = 0; i < M; ++i) {
		int a, b; cin >> a >> b;
		vs.push_back(max(0, b - N));
	}
	sort(vs.begin(), vs.end());
	int ans = accumulate(vs.begin(), vs.end() - 1, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef pair<double, double> Pd;
typedef pair<double, Pd> PPd;

int par[200];
int ran[200];
double x[200];
double y[200];
double z[200];
double r[200];

void init(int n){
  for(int i = 0; i < n; i++){
    par[i]  = i;
    ran[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){ 
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ran[y] > ran[x]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ran[y] == ran[x]) ran[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n;
  while(cin >> n && n){
    for(int i = 0; i < n; i++){
      scanf("%lf%lf%lf%lf", &x[i], &y[i], &z[i], &r[i]);
    }
    init(n);
    priority_queue<PPd, vector<PPd>, greater<PPd> > que;
    for(int i = 1; i < n; i++){
      for(int j= 0; j < i; j++){
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	double dz = z[i] - z[j];
	que.push(PPd(sqrt(dx*dx + dy*dy + dz*dz) - r[i] - r[j], Pd(i, j)));
      }
    }
    double res = 0;
    while(!que.empty()){
      PPd ppd = que.top();
      que.pop();
      if(!same(ppd.second.first, ppd.second.second)){
	unite(ppd.second.first, ppd.second.second);
	res += max(0.0, ppd.first);
      }
    }
    cout << fixed << setprecision(3) << res << endl;
  }
  return 0;
}

Measured memory_bytes: 0
r, g, b, n = gets.split.map(&:to_i)
cnt = 0
(0..n/r).each { |i|
  (0..n/g).each { |j|
    cnt += 1 if ((n - (i * r + j * g)) %  b).zero? && n-(i * r + j * g) >= 0
  }
}
puts cnt

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

int main() {
  char C;
  cin >> C;
  string S = "abcdefghijklmnopqrstuvwxyz";
  for (int i = 0; i < 25; i++) {
    if (C == S.at(i)) {
      cout << S.at(i + 1) << endl;
      break;
    }
  }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

// 頂点数、辺数
ll v, e;
const ll MAX_N = 100001;
// 隣接リスト
vector<ll> g[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列、優先順を格納
vector<ll> ans;

void dfs(ll u) {
  if(used[u]) return;
  used[u] = true;
  for(auto& i: g[u]) dfs(i);
  // 帰りがけ順で追加
  ans.push_back(u);
}

void tsort() {
  for(ll i = 0; i < v; i++) dfs(i);
  reverse(ans.begin(), ans.end());
}

int main()
{
  cin >> v, e;
  ll s, t;
  ll i;
  ll m;
  cin >> m;
  vector<ll> a(v + m), b(v + m), parent(v);
  for(i = 0; i < v + m; i++) {
    cin >> s >> t;
    a[i] = s;
    b[i] = t;
    g[s].push_back(t);
  }
  tsort();
  vector<ll> judge(v);
  vector<ll> compare(v);
  
  for(i = 0; i < v; i++){
    compare[ans[i] - 1] = i;
  }
  for(i = 0; i < v + m; i++){
    if(judge[b[i] - 1] == 0){
      judge[b[i] - 1]++;
      parent[b[i] - 1] = a[i];
    }
    else if(compare[parent[b[i] - 1] - 1] < compare[a[i] - 1])
      parent[b[i] - 1] = a[i];
  }
  for(i = 0; i < v; i++)
     cout << parent[i] << endl;
  return 0;
}

Measured memory_bytes: 14452
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	int count1 = 0;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] != s[i + 1])count1++;
	}
	cout << count1 << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> num;
  if(s[0] == '0') num.emplace_back(0);
  int i = 0;
  while(i < n){
    int j = 0;
    while(i+j < n && s[i] == s[i+j]) j++;
    num.emplace_back(j);
    i += j;
  }
  if(s.back() == '0') num.emplace_back(0);
  int m = num.size();
  vector<int> sum(m+1, 0);
  REP(i, m) sum[i+1] = sum[i] + num[i];
  int ans = 0;
  for(int l = 0; l <= m; l+=2){
    int r = l + 2*k+1;
    if(m <= r) r = m;
    chmax(ans, sum[r] - sum[l]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1272
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b
  
def solve():
    N = int(single_input())
    ans = 0
    c = 1
    while N - c > pow(c, 2):
        if (N - c) % c == 0: ans += (N - c) // c
        c += 1
    print(ans)
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3440
import math
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
ans = x[1] - x[0]
for i in range(1, N):
    ans = math.gcd(ans, x[i+1] - x[i])

print(ans)


Measured memory_bytes: 20508
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

signed main()
{
	int N;
	char S[100];
	cin >> N;
	string s;
	cin >> s;
	REP(i, N) S[i] = s.at(i);

	stack<int> st;
	int cnt = 0;
	REP(i, N)
	{
		if (S[i] == '(')
		{
			st.push(i);
		}
		if (S[i] == ')')
		{
			if (st.size() > 0)
			{
				st.pop();
			}
			else
			{
				cnt++;
			}
		}
	}

	REP(i, cnt)
	{
		cout << '(';
	}
	cout << s;
	REP(i, st.size())
	{
		cout << ')';
	}
	cout << endl;
}

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

if n == 0:
    print(0)
    exit()


reverse_ans = []
i = 0
base = -2

while n != 0:
    if n % (base**(i+1)) == 0:
        reverse_ans.append(0)
    else:
        reverse_ans.append(1)
        n -= base**i

    i += 1

ans = reverse_ans[::-1]
print(*ans, sep ='')

Measured memory_bytes: 3064
from collections import deque
import itertools
import copy

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

def solve(s):
    d = ((1, 0), (-1, 0), (0, -1), (0, 1))
    queue = deque([s])
    steps = [[-1 for _ in range(W)] for _ in range(H)]
    steps[s[0]][s[1]] = 0

    while len(queue) > 0:
        current = queue.popleft()
        cy = current[0]
        cx = current[1]
        for i in d:
            ny = cy+i[0]
            nx = cx+i[1]
            # はみ出さないかつ通路であるかつ通ってない
            if (0<=ny<H and 0<=nx<W) and S[ny][nx]=='.' and steps[ny][nx] < 0:
                queue.append([ny, nx])
                steps[ny][nx] = steps[cy][cx] + 1
        
    return max([max(i) for i in steps])

maxStep = 0
for s in itertools.product(range(H), range(W)):
    if S[s[0]][s[1]] == '.':
        maxStep = max(solve([s[0], s[1]]), maxStep)

print(maxStep)

Measured memory_bytes: 3444
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
G = [[] for i in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  a-=1;b-=1
  G[a].append(b)
  G[b].append(a)


que = collections.deque()
que.append(0)
visited = [-1] * n
visited[0] = 0
while que:
  way = que.popleft()
  for gi in G[way]:
    if visited[gi] == -1:
      visited[gi] = way + 1
      que.append(gi)
# print(*visited)
for vi in visited:
  if vi == -1:
    print("No")
    exit()
else:
  print("Yes")
  for i in range(1,n):
    print(visited[i])

Measured memory_bytes: 93096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        long minVal= Long.MAX_VALUE;

        long N  =sc.nextLong();

        for (int i = 0; i <5 ; i++) {
            long a  =sc.nextLong();
            if( a < minVal){
                minVal = a;
            }
        }

        ans = 4+ (long)Math.ceil((double)N/minVal);

        System.out.println(ans);
    }

}


Measured memory_bytes: 23252
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = SR(3)
    for i in range(3):
        print(s[i][i], end="")
    print()
    return

#B
def B():
    a, b = LI()
    ans = 0
    for i in range(a, b + 1):
        x = str(i)
        for k in range(len(x)//2):
            if x[k] != x[-k - 1]:
                break
        else:
            ans += 1
    print(ans)
    return

#C
def C():
    n, m = LI()
    if n == m == 1:
        print(1)
        return
    if n == 1 or m == 1:
        print(max(n - 2, m - 2))
        return
    if n == 2 or m == 2:
        print(0)
        return
    print(n * m - n * 2 - (m - 2) * 2)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 39152