akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!


"""
Dijkstra法: 単一始点最短路（距離が正）
g: g[i] = [(子、距離),...]の隣接リスト
start: 始点
"""
from heapq import heappush, heappop
def dijkstra(g,start): #g: 隣接リスト
    dist = [1e18]*(len(g)) #初期化
    q = [(0,start)] #(そこまでの距離、点)
    dist[start] = 0
    pending = len(g)-1
    while q and pending:
        c,v = heappop(q)
        if dist[v] < c: continue
        pending -= 1
        for to, cost in g[v]:
            if dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(q, (dist[to], to))
    return dist


n,m,R = [int(i) for i in input().split()]
r = [int(i)-1 for i in input().split()]

inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
    a,b,c = [int(i) for i in input().split()]
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))


dvec = [None]*R
for i, ri in enumerate(r):
    dvec[i] = dijkstra(g, ri)

m = {ri:i for i, ri in enumerate(r)}    

ans = inf
import itertools
for x in itertools.permutations(r):
    c = 0
    for i, xi in enumerate(x):
        if i > 0:
            c += dvec[m[xi]][x[i-1]]
    if c < ans:
        ans = c
            
print(ans)














Measured memory_bytes: 56408
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String c = sc.next();
		
		char a = c.charAt(0);
		int b = (int)a;
		b++;
		a = (char)b;
		System.out.println(a);
	}

}


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

int main () {
  int n;
  cin >> n;
  vector<long> a (n + 1);
  vector<long> b (n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];
  long ans = 0;
  for(int i = 0; i < n; i++) {
    if (a[i] < b[i] ) {
      ans  += a[i];
      b[i] -= a[i];
      if (a[i + 1] < b[i]) {
        ans += a[i + 1];
        a[i + 1] = 0;
      } else {
        ans += b[i];
        a[i + 1] -= b[i];
      }
    } else {
      ans += b[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
n=int(input())
a,b=map(int, input().split(" "))
P=list(map(int, input().split(" ")))
c1=0
c2=0
c3=0
for i in P:
    if i <= a:
        c1+=1
    elif i <= b:
        c2+=1
    else:
        c3+=1
print(min(c1,c2,c3))
    

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


void solve(long long N) {
	cout << N * N * N << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define For(i, a, b) for (i = a; i <= b; i++)
using namespace std;
const int N = 2005, PYZ = 1e9 + 7;
int n, m, K, f[N][N], ans;
int main() {
	int i, j, k; cin >> n >> m >> K; For (i, 1, K - 1) f[i][K - i] = 1;
	For (i, 1, n) For (j, 1, m) {
		if (!f[i][j]) continue;
		For (k, 0, K - 1) if (i + k <= n && j + K - 1 - k <= m)
			f[i + k][j + K - 1 - k] = (f[i + k][j + K - 1 - k] + f[i][j]) % PYZ;
		if ((i - 1) % (K - 1) == (n - 1) % (K - 1) && (j - 1) % (K - 1) == (m - 1) % (K - 1))
			ans = (ans + f[i][j]) % PYZ;
	}
	cout << ans << endl; return 0;
}

Measured memory_bytes: 15872
def main():
    n, k = map(int, input().split())
    if k == 0:
        print(n ** 2)
        exit()
    cnt = 0
    for i in range(1, n+1):
        p, r = divmod(n, i)
        cnt += max(0, p * (i - k)) + max(0, r - k + 1)
    
    print(cnt)
if __name__=='__main__':
    main()

Measured memory_bytes: 39408
def check(switches, s, pp)
	s.each.with_index do |a, i|
		on = 0
		a.each do |light|
			on += 1 if switches[light - 1] == 1
		end
		return false if on % 2 != pp[i]
	end
	true
end

n, m = gets.chomp.split.map(&:to_i)
s = []
m.times do
	k = gets.chomp.split.map(&:to_i)
	k.shift
	s.push(k)
end
pp = gets.chomp.split.map(&:to_i)

result = 0;
[0, 1].repeated_permutation(n) do |switches|
	result += 1 if check(switches, s, pp)
end
puts result


Measured memory_bytes: 1916
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    REP(i,n){
        int x = in();
        if (x % 2 == 0){
            if (x % 3 != 0 && x % 5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
/*
phu lki ...
*/

#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<long long,long long>
#define ll long long
#define ff first
#define ss second
#define horse_power ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
ll n,k;

void solve(){
   cin>>n;
   vector<ll> h(n+1),dp(n+1,0);
   for(int i=1;i<=n;i++)
      cin>>h[i];
   dp[1]=0;
   dp[2]=abs(h[2]-h[1]);
   // cout<<dp[1]<<" "<<dp[2]<<" ";
   for(int i=3;i<=n;i++)
   {
       dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
  // cout<<dp[i]<<" ";
   }
   cout<<dp[n]<<"\n";


}

int main(){
horse_power
int t=1;
//cin>>t;
while(t--){
solve();
}


}


Measured memory_bytes: 1792
import itertools
a = list(map(int, list(input())))
for op in itertools.product(["+","-"], repeat=3):
  ans = a[0]
  for i in range(3):
    if op[i] == "+":
      ans += a[i+1]
    else:
      ans -= a[i+1]
  if ans == 7:
    print("{}{}{}{}{}{}{}=7".format(a[0],op[0],a[1],op[1],a[2],op[2],a[3]))
    break

Measured memory_bytes: 3064
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for j in range(max(0, i-K), i):
        # print(i, j, )
        dp[i] = min(dp[i], dp[j] + abs(H[i]-H[j]))

# print(*dp)
print(dp[N-1])


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

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    int sum=2e9;
    for(int i=0;i<n;i++)
    {
       // cout<<i<<" "<<i+k-1<<endl;
        if(i+k-1<n)sum=min(sum,arr[i+k-1]-arr[i]);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
# define M_PI          3.141592653589793238
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b,c,d=0;
    cin>>a;
    map<ll,ll>m;
    for(int i=0; i<a-1; i++)
    {
        cin>>b;
        m[b]++;
    }
    for(int i=1; i<=a; i++)
    {
        cout<<m[i]<<endl;
    }
}


Measured memory_bytes: 16116
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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

long long int gcd(long long int a, long long int b) { //最大公約数
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

long long int lcm(long long int a, long long int b) { //最小公倍数
	long long int g = gcd(a, b);
	return a / g * b;
}


int main(void) {
	
	long long int n;
	long long int p;

	cin >> n;
	vector<long long int> a(n);
	FOR(i, 0, n - 1) {
		cin >> a[i];
	}
	p = a[0];
	FOR(i, 1, n - 1) {
		p = gcd(p, a[i]);
	}
	cout << p << endl;



	return 0;
}

Measured memory_bytes: 1024
#include <iostream> 
using namespace std;
int main() {
    int x[5], k, YN = 0;
    for (int i = 0; i < 5; i++) cin >> x[i];
    cin >> k;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (i != j) {
                if (x[i] - x[j] > k) {
                    YN = 1;
                    break;
                }
            }
        }
    }
    
    if (YN) cout << ":(" << endl;
    else cout << "Yay!" << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0, i##_len=(N); i<i##_len; i++)
#define RREP(i, N) for(int i=1, i##_len=(N); i<i##_len; i++)
#define REPP(i, N) for(int i=0, i##_len=(N); i<=i##_len; i++)
#define RREPP(i, N) for(int i=1, i##_len=(N); i<=i##_len; i++)
#define P(x) cout << (x)
using ll = long long;
using namespace std;

int n;
double a, s;

int main() {
    cin >> n;
    REP(i, n) {
        cin >> a;
        s += 1/a;
    }

    cout << 1/s;

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.readline


def bfs(G, v, dist):
    queue = deque([v])
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + 1
                queue.append(u)


def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    G = [[] for _ in range(N)]
    for i in range(N - 1):
        G[i].append(i + 1)
        G[i + 1].append(i)
    G[X].append(Y)
    G[Y].append(X)

    ans = [0] * N
    for i in range(N):
        dist = [-1] * N
        dist[i] = 0
        bfs(G, i, dist)
        for j in range(i + 1, N):
            ans[dist[j]] += 1

    print(*ans[1:], sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 4204
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  int MOD = 1000000007;
  vector<int> A(N);
  long long sum=0;
  for(int i=0; i<N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    sum %= MOD;
  }
  
  long long ans=0;
  for(int i=0; i<N; i++) {
    sum -= A.at(i);
    if(sum <0) sum += MOD;
    
    ans += A.at(i) * sum;
    ans %= MOD;
  }
    cout << ans << endl;
}

Measured memory_bytes: 4020
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

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

  ll ans = 0;
  for(ll i=k+1;i<=n;i++){
	ans += max(i-k,0LL)*(n/i);
	if(k <= n%i && n%i != 0) ans += n%i-max(k-1,0LL);
	//cout << i << ":" << ans << endl;
  }

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


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      long n = Long.parseLong(st.nextToken());
     st = new StringTokenizer(br.readLine());
     long prod = 1;
     boolean fail = false;
      for(int i = 0; i < n; i++){
        long next = Long.parseLong(st.nextToken());
        if(next == 0){
          prod = 0;
          fail = false;
          break;
        }
        if(((long)Math.pow(10,18))/prod < next){
          fail = true;
        }
        else
          prod *= next;
      }
     if(fail)
       out.println(-1);
     else
       out.println(prod);
      out.close();
   }
}



Measured memory_bytes: 48008
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SLR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if args else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N, A = LI()
    X = LI()

    dp = make_list(N+1, N+1, 2501)
    dp[0][0][0] = 1

    for i in range(1, N+1):
        for k in range(i+1):
            for s in range(2501):
                if X[i-1] > s:
                    dp[i][k][s] = dp[i-1][k][s]
                else:
                    dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-X[i-1]]

    print(sum(dp[N][k][k * A] for k in range(1, N+1)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 127828
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;

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

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

bool com(const int &a,const int &b){
    return a>b;
}

int N,K;
#define MAXN 200001
int H[MAXN];

int main(){
    cin >> N >> K;
    rep(i,N)cin >> H[i];
    sort(H,H+N,com);
    ll sum = 0;
    for(int i=K;i<N;i++){
        sum += H[i] ;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import math
n= int(input())

l = list(map(int,input().split()))
l.sort(reverse = True)

ans = 1
if 0 in l:
  print(0)
else:
  for i in range(n):
    ans *= l[i]
#    print(ans)
    if ans > 10**18:
      break
  print(ans if ans <= 10**18 else -1)


Measured memory_bytes: 22336
N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    j=i-1
    insertion_A=A[i]
    while j >= 0:
        if A[j] > insertion_A: 
            A[j+1] = A[j] 
        else:
            break
        j -= 1
    A[j+1]=insertion_A
    print(*A)



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

const int OP_LEN = 20;

typedef struct _node {
  int num;
  struct _node *left;
  struct _node *right;
} node;

node *tree = NULL;

node *make_node(int num)
{
  node *v = (node *)malloc(sizeof(node));
  v->num = num;
  v->left = NULL;
  v->right = NULL;
  return v;
}

void insert_body(node *tree, int num)
{
  node *l = tree->left;
  node *r = tree->right;
  if (num <= tree->num) {
    if (l == NULL)
      tree->left = make_node(num);
    else
      insert_body(l, num);
  } else {
    if (r == NULL)
      tree->right = make_node(num);
    else
      insert_body(r, num);
  }
}

void insert(int num)
{
  if (tree == NULL)
    tree = make_node(num);
  else
    insert_body(tree, num);
}

void print_tree(node *tree)
{
  if (tree == NULL) {
    printf("*");
  } else {
    printf("(%d ", tree->num);
    print_tree(tree->left);
    printf(" ");
    print_tree(tree->right);
    printf(")");
  }
}

void inorder(node *tree)
{
  if (tree == NULL) return;
  inorder(tree->left);
  printf(" %d", tree->num);
  inorder(tree->right);
}

void preorder(node *tree)
{
  if (tree == NULL) return;
  printf(" %d", tree->num);
  preorder(tree->left);
  preorder(tree->right);
}

void print()
{
  // print_tree(tree); printf("\n");
  inorder(tree); printf("\n");
  preorder(tree); printf("\n");
}

bool find_body(node *tree, int num)
{
  if (tree == NULL) return false;
  if (tree->num == num) return true;
  if (num <= tree->num) return find_body(tree->left, num);
  return find_body(tree->right, num);
}

bool find(int num)
{
  return find_body(tree, num);
}

int main()
{
  int n; scanf("%d", &n);
  while (n--) {
    char op[OP_LEN]; scanf("%s", op);
    if (op[0] == 'i') {
      int num; scanf("%d", &num);
      insert(num);
    } else if (op[0] == 'f') {
      int num; scanf("%d", &num);
      printf("%s\n", find(num)?"yes":"no");
    } else {
      print();
    }
  }
  return EXIT_SUCCESS;
}




Measured memory_bytes: 15652
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    print(min(n%k,-n%k))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int t;
	t=1;
	while(t--)
	{
		string s;
		cin >> s;
		int ans=0;
		for(int i=0;i<s.size();i++)
		{
			ans+=(s[i]-'0');
		}
		if(ans%9==0)
		cout << "Yes";
		else
		cout << "No";
	}
}




Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
ll MOD = 998244353;
ll mod = 998244353;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void C_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long nCr(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll x, ll n, ll mod)
{
    if (n == 0)
        return 1;
    ll res = modpow(x * x % mod, n / 2, mod);
    if (n & 1)
        res = res * x % mod;
    return res;
}

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

    ll N, M, K;
    cin >> N >> M >> K;

    C_init();


    ll ans = 0;

    for (int k = 0; k <= K; k++) {
        ans += (((M * nCr(N - 1, k)) % mod) * modpow(M - 1, N - k - 1, mod)) % mod;
        ans %= mod;
    }


    cout << ans << endl;
}


Measured memory_bytes: 237976
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	a++; b++; c++;
	int t = 0;
	rep(i, a) {
		rep(j, b) {
			rep(k, c) {
				if (500 * i + 100 * j + 50 * k == x) t++;
			}
		}
	}
	cout << t << endl;
}

Measured memory_bytes: 256
while True:
    price = int(input())
    change = 1000 - price
    n = 0

    if price == 0:
        break

    if change >= 500:
        change -= 500
        n += 1
    while change >= 100:
        change -= 100
        n += 1
    if change >= 50:
        change -= 50
        n += 1
    while change >= 10:
        change -= 10
        n += 1
    if change >= 5:
        change -= 5
        n += 1
    while change >= 1:
        change -= 1
        n += 1
    
    print(n)


Measured memory_bytes: 5588
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);

  int i;
  int b, f, r, v;
  int A[3][10] = {0}, // 1?£?
      B[3][10] = {0}, // 2?£?
      C[3][10] = {0}, // 3?£?
      D[3][10] = {0}; // 4?£?
  for (i = 0; i < n; ++i)
  {
    scanf("%d %d %d %d",&b ,&f ,&r ,&v);
    switch (b){
      case 1:
        A[f-1][r-1] += v;
        break;
      case 2:
        B[f-1][r-1] += v;
        break;
      case 3:
        C[f-1][r-1] += v;
        break;
      case 4:
        D[f-1][r-1] += v;
        break;
    }
  }

  int j, k;
  // ?£?????????????for
  for(i = 0; i < 4; ++i)
  {
    // ???????????????for
    for(j = 0; j < 3; ++j)
    {
      // ??¨?±?????????????for
      for(k = 0; k < 10; ++k)
      {
        switch (i){
          case 0:
            // ??????????????????????????????????????§???????????????
            if(k == 9) {
              printf(" %d\n", A[j][k]);
            }
            else {
              printf(" %d", A[j][k]);
            }
            break;
          case 1:
            if(k == 9) {
              printf(" %d\n", B[j][k]);
            }
            else {
              printf(" %d", B[j][k]);
            }
            break;
          case 2:
            if(k == 9) {
              printf(" %d\n", C[j][k]);
            }
            else {
              printf(" %d", C[j][k]);
            }
            break;
          case 3:
            if(k == 9) {
              printf(" %d\n", D[j][k]);
            }
            else {
              printf(" %d", D[j][k]);
            }
            break;
        }
      }
    }
    // ?£??????????????????????????????????????????°????????????
    // ???????????????????£??????´??????????????????????????????
    if(i != 3){
      printf("####################\n");
    }
  }

  return 0;
}

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

ll mod_pow(ll x, ll n){
    ll ans = 1;
    while(n){
        if(n & 1) ans = ans*x;
        x = x*x;
        n >>= 1;
    }
    return ans;
}

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

    ll cnt = 0;
    while(h > 0) {
        h /= 2;
        cnt++;
    }
    ll ans = mod_pow(2, cnt) - 1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

ds = defaultdict(int)
dt = defaultdict(int)

for i in range(N):
  ds[S[i]] += 1
for i in range(M):
  dt[T[i]] -= 1
  
keys = []
i = 0
for key in ds.keys():
  keys.append(key)
for key in dt.keys():
  keys.append(key)

ans = 0
for s in keys:
  ans = max(ans, ds[s] + dt[s])
print(ans)

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

const int MAXN = 2e5 + 6.66;
int arr[MAXN];
int rev[MAXN];
int lsl[MAXN];
int lsr[MAXN];

int main() {
  int N;scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", arr + i);
  for(int i = 1; i <= N; i++) rev[arr[i]] = i;
  if(N == 1) {
    printf("0\n");
    return 0;
  }
  lsl[1] = 1;
  for(int i = 2; i <= N; i++)
    if(rev[i - 1] < rev[i]) lsl[i] = lsl[i - 1] + 1;
    else lsl[i] = 1;
  lsr[N] = 1;
  for(int i = N-1; i > 0; i--)
    if(rev[i + 1] > rev[i]) lsr[i] = lsr[i + 1] + 1;
    else lsr[i] = 1;
  int ans = min(N - lsl[N], N - lsr[1]);
  for(int i = 1;i<N;i++)
    ans = min(ans, N - (rev[i] < rev[i + 1] ? lsl[i] + lsr[i + 1] : max(lsl[i], lsr[i + 1])));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

typedef long long ll;

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())

using namespace std;

const int N = 100100;
const ll inf = (long long) 1.01e18;
const ll mod = 1e9 + 7;
vector<pair<int,int> > g[N];
bool used[N];



void solve(){
    int a,b;
    cin >> a >> b;
    if (a <= 9 && b <= 9)
        cout << a * b << endl;
    else
        cout << -1 << endl;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t;

    solve();
    return (0);
}


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

int main() {
  string S;
  cin >> S;
  int count_a=0, count_b=0, count_c=0;
  for (int i=0; i<3; i++) {
    if (S.at(i)=='a') {
      count_a++;
    }
    else if (S.at(i)=='b') {
      count_b++;
    }
    else {
      count_c++;
    }
  }
  string ans = "Yes";
  if (count_a>1 || count_b>1 || count_c>1) {
    ans = "No";
  }
  cout << ans << endl;
}

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

int main() {
  vector<ll> A(100001);
  ll N;cin >> N;
  ll sum =0;
  rep(i,N){
    ll X;cin >> X;
    A.at(X)++;
    sum += X;
  }
  ll Q;cin >> Q;
  rep(i,Q){
    ll B,C;
    cin  >> B >> C;
    int kari = A.at(B);
    A.at(B) = 0;
    A.at(C) += kari;
    sum = sum - kari*B+kari*C;
    cout << sum << endl;
  }
}

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

bool has_key(char key) {
  char c[] = {'A', 'C', 'G', 'T'};
  for (int i = 0; i < 4; ++i) {
    if(c[i] == key) {
      return true;
    }
  }
  return false;
}

int main(){
  string s;
  cin >> s;
  int ans = 0;
  int max = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if(has_key(s[i])) {
      ans++;
      if(max < ans) max = ans;
    }
    else ans = 0;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n, k = map(int, input().split())
p = (1.00 + np.array(list(int(i) for i in input().split()))) / 2
temp = np.sum(p[:k])
ans = temp

for i in range(k, n):
	temp += (p[i] - p[i - k])
	ans = max(ans, temp)

print('{:.10f}'.format(ans))


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

int N, K;
string S;

int main() {
    cin >> N >> K >> S;
    vector<pair<int, int>> zero;
    zero.push_back(make_pair(0, 0));
    bool flag = false;
    int left = 0, right = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '0' && !flag) {
            left = i;
            flag = true;
        }
        if (S[i] == '1' && flag) {
            right = i;
            flag = false;
            zero.push_back(make_pair(left, right));
        }
    }
    if (flag) {
        zero.push_back(make_pair(left, N));
    }
    zero.push_back(make_pair(N, N));
    if (zero.size() <= K + 2) {
        cout << N << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < zero.size() - K - 1; i++) {
        int tmp = zero[i + K + 1].first - zero[i].second;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}





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

int main(){
    long long n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++){
        cout<<s<<" ";
    }
    if(s<1000000000){
        for(int i=k;i<n;i++){
            cout<<1000000000<<" ";
        }
    }
    else{
        for(int i=k;i<n;i++){
            cout<<1<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 1280
function main(input) {
  const formatted_input = input.split('\n');
  const N =  parseInt(formatted_input[0].split(' ')[0]);
  const M =  parseInt(formatted_input[0].split(' ')[1]);

  As=[];
  for(var i=0;i<N;i++){
    var tmp_as = formatted_input[1+i].split(' ').map(x => parseInt(x))
    As.push(tmp_as);
  }

  var sorted_As = As.sort(function(a, b){
    return a[0]-b[0];
  })

//  console.log(N);
//  console.log(M);
//  console.log(As);
//  console.log(sorted_As);

  var result = 0;
  var tmp_count = 0;
  for(var i = 0;i<N;i++){
    var shortage = M-tmp_count;
    if(sorted_As[i][1] >= shortage){
      result += sorted_As[i][0]*shortage;
      break;
    }else{
      tmp_count+=sorted_As[i][1];
      result += sorted_As[i][0] * sorted_As[i][1];
    }
  }
  

  console.log(result);

}

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



Measured memory_bytes: 50208
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 5e4+5;
int arr[105];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int num;
    cin>>num;
    for(int i =0;i<num;i++)
    {
        cin>>arr[i];
    }
    sort(arr, arr+num);
    int cnt=0;
    for(int i =0;i<num-2;i++)
    {
        for(int j =i+1;j<num-1;j++)
            for(int k =j+1;k<num;k++)
            {
                if(arr[i]+arr[j]>arr[k]&&arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[i]!=arr[k])
                    cnt++;
            }
    }
    cout<<cnt<<endl;
    
    
}


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

int N, K;
// vector<vector<int> > B(4020, vector<int>(4020, 0));
// vector<vector<int> > W(4020, vector<int>(4020, 0));
vector<vector<int> > memo(2020, vector<int>(2020, 0));

void imos(int x1, int y1, int x2, int y2) {
    memo[y1][x1]++;
    memo[y2][x1]--;
    memo[y1][x2]--;
    memo[y2][x2]++;
}

int main() {
    cin >> N >> K;
    int K2 = K * 2;
    for(int i = 0; i < N; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= K2;
        y %= K2;
        // 黒の領域の累積和をいもす法で計算する
        if( ((x/K&1) ^ (y/K&1)) ^ (c=='B')) {
            /*
            黒の始点が左上か右下，白の始点が右上か左下にあれば以下の模様になる
            # # . . . . # #
            # # . . . . # #
            . . # # # # . .
            . . # # # # . .
            . . # # # # . .
            . . # # # # . .
            # # . . . . # #
            # # . . . . # #
            */
            int x00 = x % K + 1, y00 = y % K + 1;   // 中心位置にあるK*K矩形の左上
            int x11 = x00 + K, y11 = y00 + K;       // 中心位置にあるK*K矩形の右下

            imos(0, 0, x00, y00);
            imos(x11, 0, K2, y00);
            imos(x00, y00, x11, y11);
            imos(0, y11, x00, K2);
            imos(x11, y11, K2, K2);
        } else {
            /*
            それ以外は
            . . # # # # . .
            . . # # # # . .
            # # . . . . # #
            # # . . . . # #
            # # . . . . # #
            # # . . . . # #
            . . # # # # . .
            . . # # # # . .
            */
            int x00 = x % K + 1, y00 = y % K + 1;   // 中心位置にあるK*K矩形の左上
            int x11 = x00 + K, y11 = y00 + K;       // 中心位置にあるK*K矩形の右下

            imos(x00, 0, x11, y00);
            imos(0, y00, x00, y11);
            imos(x11, y00, K2, y11);
            imos(x00, y11, x11, K2);
        }
    }

    for(int y = 0; y < K2; y++) {
        for(int x = 1; x < K2; x++) {
            memo[y][x] += memo[y][x-1];
        }
    }

    for(int y = 1; y < K2; y++) {
        for(int x = 0; x < K2; x++) {
            memo[y][x] += memo[y-1][x];
        }
    }

    int ans = -1e9+1;
    for(int y = 0; y < K2; y++) {
        for(int x = 0; x < K2; x++) {
            ans = max(ans, memo[y][x]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

a=0
b=0
c=0
t=0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            Y=500*a+100*b+50*c
            if Y==X:
                t=t+1

print(t)

Measured memory_bytes: 3060
int n, m, rm, ans[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int x, y; n--;) {
    scanf("%d%d", &x, &y);
    int b = y + 1;
    for (int j = 1; j * j <= m; j++) {
      int tx = (x + j - 1) / j, ty = y / j;
      ans[tx]++;
      ans[ty + 1 < b ? ty + 1 : b]--;
      b = tx;
    }
    for (int i = 1; i < b; i++) {
      if ((x - 1) / i < y / i) {
        ans[i]++;
        ans[i + 1]--;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    ans[i] += ans[i - 1];
    printf("%d\n", ans[i]);
  }
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
while(1){

 int a, b, i;
 char op;

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

 switch( op ){

 case '+' : 
 printf("%d\n", a + b);
 break;
 case '-' : 
 printf("%d\n", a - b);
 break;
 case '*' : 
 printf("%d\n", a * b);
 break;
 case '/' : 
 printf("%d\n", a / b);
 break;
 case '?' : 
 return 0;
 break;

 }
}
 return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <cmath>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

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

int main(){
	string a, b, result;
	bool honest = false;
	gets(a) gets(b)
	if (a == "H"){
		if (b == "H"){
			honest = true;
		}
	}else{
		if (b == "D"){
			honest = true;
		}
	}
	result = honest? "H":"D";
	puts(result)
}


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

const int MAX_V = 15;

int V, E;
int dist[MAX_V][MAX_V];
int dp[1<<MAX_V][MAX_V];
int s;
const int INF = 1000000;

int rec (int S, int v){
    if(dp[S][v] != -1) return dp[S][v];

    if(S == (1<<V)-1 && v == s) return dp[S][v] = 0;

    int res = INF;
    for(int u = 0; u < V; u++){
        if(!(S>>u & 1)){
            res = min(res, rec(S | (1<<u),u) + dist[v][u]);
        }
    }

    return dp[S][v] = res;
}

int main(){
    rep(i, MAX_V) rep(j, MAX_V) dist[i][j] = INF;
    cin >> V >> E;
    rep(i, E){
        int from, to, cost;
        cin >> from >> to >> cost;
        dist[from][to] = cost;
    }

    int res = INF;
    rep(i,V){
        memset (dp, -1, sizeof(dp));
        s = i;
        res = min(res, rec(0, i));
    }
    cout << (res == INF ? -1 : res) << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	ll n, m;
	cin >> n >> m;

	cout << abs(n - 2) * abs(m - 2) << endl;
	// 4 6 4
	// 6 9 6
	// 4 6 4

	// 4 6 6 6 4
	// 6 9 9 9 6
	// 6 9 9 9 6 
	// 4 6 6 6 4
	return 0;
}


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

ll N,P,Q;
ll C[500005];
ll D[500005];
ll ans,sum,x;

int main(){
  cin>>N>>P>>Q;
  for(int i=0;i<N;i++){
    scanf("%lld",&C[i]);
    D[i]=(Q-i)*P-C[i];
    sum+=C[i];
  }
  sort(D,D+N);
  reverse(D,D+N);
  ans=sum;
  
  for(int i=0;i<N;i++){
    sum+=D[i];
    x+=2*i*P;
    ans=max(ans,sum+x);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9068
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        long N=sc.nextInt(),A=sc.nextInt(),B=sc.nextInt();
        if(A>B){
            System.out.println(0);
            return;
        }
        if(N==1){
            System.out.println(A==B?1:0);
            return;
        }
        long min=A*(N-1)+B,max=B*(N-1)+A;
        System.out.println(max-min+1);
    }
}

Measured memory_bytes: 35708
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static final boolean debugMode = false;

	static final long DIV_INF = 1000000007l;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = readLong(sc);
		long b = readLong(sc);
		long c = readLong(sc);
		long k = readLong(sc);

		if (k <= a) {
			System.out.println(k);
			return;
		} else if (k <= a + b) {
			System.out.println(a);
		} else {
			System.out.println(a - (k - a - b));
		}

	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static Long readLong(Scanner sc) {
		return Long.parseLong(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class KrmlUtil {
	// a >= b
	static int gcd(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

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

	// a >= b
	static long gcd(long a, long b) {
		while (true) {
			if (b == 0)
				break;

			long mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// a >= b
	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static BigInteger gcd(BigInteger a, BigInteger b) {
		return a.gcd(b);
	}

	static BigInteger lcm(BigInteger a, BigInteger b) {
		return a.divide(a.gcd(b)).multiply(b);
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 35628
N = int(input())
A = list(map(int, input().split(' ')))

A2 = sorted([A[i]-i-1 for i in range(len(A))])
median = A2[len(A)//2]

ans = 0
for i in range(len(A)):
    ans += abs(A2[i]-median)
print(ans)


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

int main() {
string S;
  cin >> S;
  int Ra = -1;
  int Rb = -1;
  int La = -1;
  int Lb = -1;
  int N = S.length();
  for(int a = 0;a < N;a++){
    if(S[a] == 'R'){
     if(Ra == -1){
      Ra = a; 
     }else if(La == -1){
       
     }else{
       Lb = a - 1;
      //計算、出力
       for(int b = 0;b < Rb - Ra;b++)cout << 0 << " ";
       if((Rb - Ra) % 2 == 0){
         cout << (Lb - Ra + 2) / 2 << " " << Lb - Ra + 1 - ((Lb - Ra + 2) / 2) << " ";
       }
       if((Rb - Ra) % 2 == 1){
         cout << Lb - Ra + 1 - ((Lb - Ra + 2) / 2) << " " << (Lb - Ra + 2) / 2 << " ";
       }
       for(int b = 0;b < Lb - La;b++)cout << 0 << " ";
       
       Ra = a;
       Rb = -1;
       La = -1;
       Lb = -1;
     }
    }else{
     if(La == -1){
      Rb = a - 1;
       La = a;
     }else if(Lb == -1){
       
     }
    }
  }
  Lb = N - 1;
  for(int b = 0;b < Rb - Ra;b++)cout << 0 << " ";
       if((Rb - Ra) % 2 == 0){
         cout << (Lb - Ra + 2) / 2 << " " << Lb - Ra + 1 - ((Lb - Ra + 2) / 2) << " ";
       }
       if((Rb - Ra) % 2 == 1){
         cout << Lb - Ra + 1 - ((Lb - Ra + 2) / 2) << " " << (Lb - Ra + 2) / 2 << " ";
       }
       for(int b = 0;b < Lb - La;b++)cout << 0 << " ";
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    int a;
    map<int, int> m;
    rep(i, n) {
        cin >> a;
        m[a + 1]++;
        m[a]++;
        m[a - 1]++;
    }
    int ans = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        chmax(ans, it->second);
    }
    cout << ans << endl;
}

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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 T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

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

Measured memory_bytes: 892
#include <iostream>
using namespace std;
 
int main(){
    int H,W;
    while(cin >> H >> W,H||W){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << "#";
        }
        cout << endl;
    }
    cout << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3068