akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  vector<long long> a;
  for (int i=0; i<n; i++) {
    long long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  vector<long long> sum;
  long long tmp=0;
  for (int i=0; i<n; i++) {
    tmp += a[i];
    sum.push_back(tmp);
  }

  long long min = 2000000000;
  for (int i=0; i<(int)sum.size()-1; i++) {
    long long p1 = sum[i];
    long long p2 = sum[sum.size()-1]-p1;
    if (abs(p1-p2) < min) {
      min = abs(p1-p2);
    }
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 4848
import collections

c = collections.Counter

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

even_v = [v[i] for i in range(n) if i % 2 == 0]
odd_v = [v[i] for i in range(n) if i % 2 == 1]

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)


def calc(x, y):
    return len(even_v) - x[1] + len(odd_v) - y[1]


def main():
    if c1[0] != c2[0]:
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        return len(odd_v)

    if calc(c1[0], c2[1]) < calc(c1[1], c2[0]):
        return calc(c1[0], c2[1])
    else:
        return calc(c1[1], c2[0])


print(main())


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

int main() {
	int n, t_l;
	cin >> n >> t_l;
	int c[n], t[n];
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
	}

	int ans = 1e8;
	for (int i = 0; i < n; i++) {
		if(t[i] <= t_l && c[i] < ans) {
			ans = c[i];
		}
	}
	if (ans == 1e8) {
		cout << "TLE" << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <stdio.h>
#include <vector>

unsigned readUnsigned() {
    int c;
    do { c = ::getchar_unlocked(); } while (c < '0');
    unsigned result = c - '0';
    while ((c = ::getchar_unlocked()) >= '0') {
        result *= 10;
        result += c - '0';
    }
    return result;
}

void writeUnsignedLn(unsigned x) {
    static const unsigned MAX_DIGITS = 10;
    static const unsigned BUF_SIZE = MAX_DIGITS + 1;
    static char buffer[BUF_SIZE] = {0};
    buffer[BUF_SIZE - 1] = '\n';
    unsigned i = BUF_SIZE - 1;
    do {
        buffer[--i] = x % 10 + '0';
        x /= 10;
    } while (x);
    ::fwrite_unlocked(buffer + i, 1, BUF_SIZE - i, stdout);
}

uint64_t N, L, T;
std::vector<uint64_t> xs, W;

std::vector<unsigned> solve() {
    std::vector<uint64_t> crossings(N);

    struct xid { uint64_t x, id; };
    std::vector<xid> left, right;
    for (unsigned n = 0; n <= 1; ++n) {
        for (unsigned i = 0; i < N; ++i) {
            if (W[i] == 1) {
                right.push_back({xs[i] + n*L, i});
            }
            else {
                left.push_back({xs[i] + n*L, i});
            }
        }
    }

    uint64_t numleft = left.size() / 2;
    uint64_t numright = right.size() / 2;

    for (unsigned i = 0, min = 0, max = 0; i < N; ++i) {
        if (W[i] != 1) {
            continue;
        }
        crossings[i] = (2 * T) / L * numleft;
        uint64_t lo = xs[i];
        uint64_t hi = xs[i] + 2 * T % L;
        for (; min < left.size() && left[min].x < lo; ++min);
        for (; max < left.size() && left[max].x < hi; ++max);
        crossings[i] += max - min;
    }

    for (unsigned i = 0, min = 0, max = 0; i < N; ++i) {
        if (W[i] != 2) {
            continue;
        }
        crossings[i] = (2 * T) / L * numright;
        uint64_t lo = xs[i] + L - 2 * T % L;
        uint64_t hi = xs[i] + L;
        for (; min < right.size() && right[min].x <= lo; ++min);
        for (; max < right.size() && right[max].x <= hi; ++max);
        crossings[i] += max - min;
    }

    std::vector<unsigned> result(N);
    for (unsigned i = 0; i < N; ++i) {
        if (W[i] == 1) {
            unsigned j = (i + crossings[i]) % N;
            unsigned t = (xs[i] + T) % L;
            result[j] = t;
        }
        else {
            unsigned j = (i - crossings[i] % N + N) % N;
            unsigned t = (xs[i] - T%L + L) % L;
            result[j] = t;
        }
    }
    return result;
}

int main() {
    N = readUnsigned();
    L = readUnsigned() * 2;
    T = readUnsigned() * 2;

    xs.resize(N);
    W.resize(N);
    for (unsigned i = 0; i < N; ++i) {
        xs[i] = readUnsigned() * 2;
        W[i] = readUnsigned();
    }

    std::vector<unsigned> result = solve();
    for (unsigned i = 0; i < N; ++i) {
        writeUnsignedLn(result[i] / 2);
    }
}


Measured memory_bytes: 8176
from collections import deque

H, W = map(int, input().split())
C0, C1 = map(int, input().split())
D0, D1 = map(int, input().split())

LARGEST = 999999999
ARR = []

for i in range(H):
    ARR.append(input())


def calculate(h, w, c0, c1, d0, d1, arr):
    c0 = c0 - 1
    c1 = c1 - 1
    d0 = d0 - 1
    d1 = d1 - 1

    status = []
    for i in range(H):
        tmp = [LARGEST] * W
        status.append(tmp)

    q = deque()

    q.append((c0, c1, 0))

    while len(q) > 0:
        hIndex, wIndex, index = q.popleft()

        if index > status[hIndex][wIndex]:
            continue

        sss = [(hIndex, wIndex - 1), (hIndex, wIndex + 1), (hIndex - 1, wIndex), (hIndex + 1, wIndex)]

        for sH, sW in sss:
            if sH < 0 or sH >= h or sW < 0 or sW >= w:
                continue

            if arr[sH][sW] == '#':
                continue

            tmpIndex = index
            if status[sH][sW] > tmpIndex:
                status[sH][sW] = tmpIndex
                q.insert(0, (sH, sW, tmpIndex))

        for _hIndex in range(hIndex - 2, hIndex + 3):
            for _wIndex in range(wIndex - 2, wIndex + 3):
                if (_hIndex < 0) or (_hIndex >= h) or (_wIndex < 0) or (_wIndex >= w):
                    continue

                if arr[_hIndex][_wIndex] == '#':
                    continue

                tmpIndex = index + 1

                if status[_hIndex][_wIndex] > tmpIndex:
                    status[_hIndex][_wIndex] = tmpIndex
                    q.append((_hIndex, _wIndex, tmpIndex))

    if status[d0][d1] == LARGEST:
        print(-1)
    else:
        print(status[d0][d1])


calculate(H, W, C0, C1, D0, D1, ARR)


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

int main(){
  int n;
  cin>>n;
  vector<int> v;
  REP(i,n){
    int a;
    cin>>a;
    v.push_back(a);
  }
  sort(ALL(v));
  int w;
  while(v.size()>=2){
    sort(ALL(v));
    w=v[0];
    for(auto it=v.begin()+1;it!=v.end();){
      *it=*it%w;
      if(*it==0){
        it=v.erase(it);
      }else{
        it++;
      }
    }
  }
  cout<<w<<endl;
}

Measured memory_bytes: 892
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	x*=f;
    return x;
}
#define MAXN 100
#define INF 0x3f3f3f3f
int a[MAXN+5];
int main(){
	int n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	int tmp=0;
	for(int i=1;i<=n-1;i++)
		tmp+=a[i];
	if(tmp<=a[n]) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<set<int>> matrix(200006);
vector<bool> visited(200006);
vector<set<int>> answer;
set<int> st;
void dfs(int v) {
    visited[v] = true;
    st.insert(v);
    // for(int i = 1; i <= matrix[v].size(); i++) {
    for(auto it = matrix[v].begin(); it != matrix[v].end(); it++) {
        if(visited[*it] == false) {
            st.insert(*it);
            dfs(*it);
        }
    }
}
int main(){
    int n, m; cin >> n >> m;
    matrix = vector<set<int>> (n + 1);
    visited = vector<bool> (n + 1);
    map<int, bool> check;
    for(int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        matrix[x].insert(y);
        matrix[y].insert(x);
        check[x] = true;
        check[y] = true;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(visited[i] == false) {
            dfs(i);
            ans++;
            st.clear();
        }
    }
    cout << ans - 1;
    return 0;
}


Measured memory_bytes: 26864
//https://atcoder.jp/contests/agc014/tasks/agc014_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll A,B,C; cin>>A>>B>>C;
    ll ans=0;
    auto check = [&](){
        return(A%2==1||B%2==1||C%2==1);
    };
    if (A==B&&B==C&&A%2==0){
        cout<<-1<<endl;
        return 0;
    }
    while(!check()){
        ll a=A,b=B,c=C;
        A=b/2+c/2;
        B=a/2+c/2;
        C=a/2+b/2;
#if LOCAL
        cout<<A<<","<<B<<","<<C<<endl;
#endif
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from copy import deepcopy
from itertools import combinations_with_replacement, product
from collections import deque
def input(): return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    ans = 0
    for H, W in product(range(h), range(w)):
        if s[H][W] == '#':
            continue
        s2 = deepcopy(s)
        s2[H][W] = 0
        d = deque()
        d.append([H, W])
        while d:
            Hn,Wn = d.popleft()
            for i, j in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
                if ((0 <= Hn+i < h) and (0 <= Wn+j < w)):
                    
                    if s2[Hn+i][Wn+j] != '.':
                        continue
                    s2[Hn+i][Wn+j] = s2[Hn][Wn] + 1
                    d.append([Hn+i, Wn+j])
                    if ans < s2[Hn+i][Wn+j]:
                        ans = s2[Hn+i][Wn+j]
        del s2

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9640
import java.util.Scanner;

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

		for(int i = 0;i < 5;i++) {
			if(scan.nextInt() == 0) {
				System.out.println(i + 1);
				break;
			}
		}
	}
}


Measured memory_bytes: 35744
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

#define IMF (1 << 29)

int N,M,R;
int graph[201][201];
int r[9];
int A,B,C;
int res;
bool used[9];

void dfs(int c, int las, int dist)
{
    if(c==R+1)
    {
        if(res > dist) res=dist;
        return;
    }
    for(int i=1;i<=R;i++) if(!used[i])
    {
        used[i]=true;
        if(las==-1)dfs(c+1,i,0);
        else dfs(c+1,i,dist+graph[r[las]][r[i]]);
        used[i]=false;
    }
}

int main()
{
    //入力
    cin >> N >> M >> R;
    //グラフの初期化
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) if(i != j) graph[i][j] = IMF;
    for(int i=1;i<=R;i++) cin >> r[i];
    //グラフを作る
    for(int i=1;i<=M;i++)
    {
        cin >> A >> B >> C;
        if(graph[A][B] > C) graph[A][B] = graph[B][A] = C;
    }
    //ワーシャルフロイド法
    for(int k=1; k<=N;k++)
        for(int i=1;i<=N;i++)
            for(int j=1;j<=N;j++)
                graph[i][j] = min(graph[i][j],graph[i][k]+graph[k][j]);
    res=IMF;
    //rの並べ方を調べる
    dfs(1,-1,0);
    //出力
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstring>
#include<climits>
using namespace std;
void File(){
	freopen("ARC91F.in","r",stdin);
	freopen("ARC91F.out","w",stdout);
}
template<typename T>bool chkmax(T &_,T __){return _<__ ? (_=__,1) : 0;}
template<typename T>bool chkmin(T &_,T __){return _>__ ? (_=__,1) : 0;}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define MREP(i,x) for(register int i=beg[x];i;i=E[i].last)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define inf INT_MAX
const int maxn=1000+10;
int n,a,k,ans;
int get_SG(int x){
	//cout<<x<<endl;
	if(x%k==0)return x/k;
	if((x-(x/k)-1)/k!=x/k)return get_SG(x-(x/k)-1);
	int b=x-x/k*k,t=b/((x/k)+1);
	return get_SG(x-t*((x/k)+1));
}
int main(){
	//File();
	cin>>n;
	REP(i,1,n){
		cin>>a>>k;
		ans^=get_SG(a);
	}
	if(ans)puts("Takahashi");
	else puts("Aoki");
	return 0;
}


Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n , ans=0;
	cin>> n ;
	cout<<n*(n-1)/2<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<queue>
using namespace std;
#define ll long long
#define PI 3.1415926535898
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, ans = 0;
	cin >> n;
	ans = (n-1)*n / 2;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[4], temp=0;
	for(int i=0; i<3; i++){
		scanf("%d", &a[i]);
	}
	
	if(a[0] > a[1]){
		temp = a[0];
		a[0] = a[1];
		a[1] = temp;
	}
	
	if(a[1] > a[2]){
		temp = a[1];
		a[1] = a[2];
		a[2] = temp;
	}
	
	if(a[0] > a[1]){
		temp = a[0];
		a[0] = a[1];
		a[1] = temp;
	}
	
	for(int i=0; i<3; i++){
		if(i==2)printf("%d\n", a[i]);
		else printf("%d ", a[i]);
	}
}


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

using namespace std;
using ll = long long;

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int sum = 0;
  rep(i, n) { sum = (sum + (s[i] - '0')) % 9; }
  cout << (sum == 0 ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

int main() {
    int n;
    string str;
    while(cin >> str) {
        int flag= 0;
        int len = str.size();
        if(str[0] != 'A') {
            cout << "WA" << endl;
            return 0;
        }
        if((str[1] <= 'z' && str[1] >= 'a') || str[1] == 'A' || str[1] == 'C') {
            for(int i = 2; i < len - 1; i++) {
                if(str[i] =='C' ) {
                    if(flag) {
                        cout << "WA" << endl;
                        return 0;
                    }
                    flag = 1;
                    continue;
                }
                if(str[i] >= 'a' && str[i] <= 'z') {
                    continue;
                } else {
                    if(str[i] != 'A') {
                        cout << "WA" << endl;
                        return 0;
                    }
                }
            }
            if(flag && ((str[len - 1] >= 'a' && str[len - 1] <= 'z')||str[len-1]=='A'||str[len - 1] == 'C')) {
                cout << "AC" << endl;
                return 0;
            } else {
                cout << "WA"  << endl;
                return 0;
            }
        } else {
            cout << "WA" << endl;
        }


    }
    return 0;
}


Measured memory_bytes: 256
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T>
void print_mat(T t) {
  rep (i, t.size()) {
    rep (j, t[0].size()) {
      cout << t[i][j];
    }
    cout << endl;
  }
}

template <typename T>
void print_vec(vector<T> t) {
  rep (i, t.size()) {
    cout << t[i] << " ";
  }
  cout << endl;
}


int main() {

  int a, d, n;
  int max = 1000001;  // ???????????????
  vector<int> prime(max);
  rep (i, max) prime[i] = 1;

  // ??¨????????????????????????
  prime[0] = 0;
  for (int i=2; i<=max; i++) {
    for (int j=2; i*j<max; j++) {
      prime[i*j-1] = 0;
    }
  }

  while (cin >> a >> d >> n && a && d && n) {
    int a_i = 0;

    for (int k=0; k<=max; k++) {
      if (prime[a+d*k-1]) {
        // cout << "match: " << a + d * k << "(" << prime[a+d*k-1] << ")" << endl;
        a_i++;
      } else {
        // cout << "not match: " << a + d * k << "(" << prime[a+d*k-1] << ")" << endl;
      }

      if (a_i == n) {
        cout << a+d*k << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 6596
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;

vector<vi> adjList(601);
double ans = 0;

int n, m;

vector<double> ex;
void check(int cur, int to){
    //cout << cur << " " << to <<endl;
    for(int i = n-1;i >= 1; i--){
        double sum  =0;
        for(int c: adjList[i]){
            if(i == cur && c == to)continue;
            sum += ex[c];
        }
        ex[i] = i == cur ? sum/(adjList[i].size() - 1) : sum/adjList[i].size(); 
        ex[i]++;
    }
    ans =min(ans, ex[1]);
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    cin >> n >> m;
    int u, v;
    FOR(i, m){
        cin >> u >> v;
        adjList[u].pb(v);
    }
    vector<int> skip(n);
    ex.resize(n+1);
    ex[n] = 0;
    for(int i = n-1; i >= 1; i--){
       double mx = 0;
       double sum = 0;
       int mv = 0;
       for(int c: adjList[i]){
           mx = max(mx, ex[c]);
           if(mx == ex[c])mv = c;
           sum += ex[c];
       } 
       skip[i] = mv;
       ex[i] = sum/adjList[i].size();
       ex[i]++;
    }


    ans= ex[1];
    FOR1(i, n-1)if(adjList[i].size() > 1)check(i, skip[i]);
    printf("%0.10f", ans);
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int w = 1;
  int q = 0;
  for(int i = 0; i < N; i++) {
    w = w * K;
    q++;
    if(N >= w) {
    }
    else {
      break;
    }
  }
  cout << q << endl;
}

Measured memory_bytes: 256
import collections


n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)

sss = set(s)
mx = 0
pl = []
for ss in sss:
    if c[ss] > mx:
        mx = c[ss]
        pl = [ss]
    elif c[ss] == mx:
        pl.append(ss)
pl = sorted(pl)
for i in pl:
    print(i)

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	int n;
	cin>>n;
	vi vs(n);
	for(int &x:vs) cin >> x;
	int s=vs[0];
	for(int i=1;i<n;++i){
		s^=vs[i];
	}
	for(int i=0;i<n;++i){
		cout<<(s^vs[i])<<" ";
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,m; cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    int q; cin >> q;
    vector<int> v(q), d(q), c(q);
    rep(i,q){
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }

    vector<int> ma(n,-1);
    vector<int> co(n,0);

    rrep(i,q){
        queue<pii> que; // (vertex, dist)
        que.push(pii(v[i], d[i]));

        while(!que.empty()){
            int cur = que.front().first;
            int dist = que.front().second;
            que.pop();

            if(ma[cur] >= dist) continue; 
            ma[cur] = dist;
            if(co[cur] == 0){
                co[cur] = c[i];
            }

            if(dist-1<0) continue;
            for(auto nxt : g[cur]){
                que.push(pii(nxt, dist-1));
            }
        }
    }

    rep(i,n){
        cout << co[i] << endl;
    }
}


Measured memory_bytes: 8952
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int K[200001];
int zentai, N;
ll kotae[200001];
int C[200001];
int E[400001], ne[400001], he[200001];
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
char dn[2400000], * di = dn;
inline void putint(ll X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[15];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

void dfs(int p, int mae) {
	int k = K[C[p]] + zentai;
	int k0 = k;
	for (int to = he[p]; to; to = ne[to]) {
		if (mae != E[to]) {
			dfs(E[to], p);
			int sa = K[C[p]] + zentai - k;
			kotae[C[p]] -= ll(sa) * (sa + 1) >> 1;
			k += sa;
		}
	}
	zentai++;
	K[C[p]] = k0 - zentai;
}


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


	N = getint();
	rep1(i, N) C[i] = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();

		E[k] =b;
		ne[k] = he[a];
		he[a] = k++;
		E[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}

	dfs(1, -1);
	ll n = ll(N) * (N + 1) / 2;
	rep1(i, N) {
		int sa = K[i] + zentai;
		putint(n + kotae[i] - (ll(sa) * (sa + 1) >> 1));
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 20860
#include<iostream>
#include<cstring>
using namespace std;

int t[1005];
bool used[10005][1000];

int main(){
	int n,m,r,q;
	int a,b,c,d;
	int i,j,k;
	while(cin>>n>>m){
		if(!n)break;
		memset(used,false,sizeof(used));
		cin>>r;
		for(i=0;i<r;i++){
			cin>>a>>b>>c>>d;
			a-=540,b--,c--;
			if(d==1)t[b]=a;
			else{
				for(j=t[b];j<a;j++)used[c][j]=true;
			}
		}
		cin>>q;
		for(i=0;i<q;i++){
			cin>>a>>b>>c;
			a-=540,b-=540,c--,d=0;
			for(j=a;j<b;j++)if(used[c][j])d++;
			cout<<d<<endl;
		}
	}
}



Measured memory_bytes: 12848
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;

int a[100010];

int main(){
    int n;cin>>n;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    int l=a[n-1];
    int diff=-1;
    int id=n-1;
    rep(i,0,n-1){
        if(min(a[i],l-a[i])>=diff){
            diff=min(a[i],l-a[i]);
            id = i;
        }
    }
    printf("%d %d\n",l,a[id]);
	return 0;
}



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

int main(){
	while(true){
		int N; cin >> N;
		
		if(N <= 0){
			break;
		}
		
		bool NA = true;
		
		int zeroCount = 0;
		
		for(int i=0; i<N; ++i){
			int k; cin >> k;
			
			if(k == 0){
				zeroCount++;
			}else if(k >= 2){
				NA = false;
			}
		}
		
		if( NA ){
			puts("NA");
		}else{
			cout << (N - zeroCount + 1) << endl;
		}
	}
}


Measured memory_bytes: 3096
using System;


class Program
{
    static void Main(string[] args)
    {

        
        string[] word = Console.ReadLine().Split(' ');
        int L = int.Parse(word[0]);
        int R = int.Parse(word[1]);
        int d = int.Parse(word[2]);
        
        int Count = 0;
        for(int i = L; L<=i && i <= R; i++)
        {
            if (i % d == 0)
            {
                       Count++;   
            }
        }
        Console.WriteLine(Count);


    }
}

Measured memory_bytes: 17828
S = input()
ans = 0
i = 0
while i < len(S)-1:
    if S[i] != S[i+1]:
        ans += 2
        if i==0:
            S = S[2:]
        else:
            S = S[:i] + S[i+2:]
            i -= 1
    else:
        i += 1
print(ans)


Measured memory_bytes: 90700
#include <iostream>
using namespace std;
 
int main()
{
  int a, b, k=1;
  cin >> a >> b;
  for(k=1;k<1000000000;k++){
    int c=0, d=0;
    if(a>b){
      c=a-k;
      d=b-k;
    }
    else{
      c=b-k;
      d=a-k;
    }
  
    if(c+d==0&&c-d==2*c){
      cout << k;
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    int k,x;
    cin>>k>>x;
    if(k*500>=x) dunk("Yes");
    else dunk("No");
}



Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int H, A;
  cin >> H >> A;
  int ans = (H + A - 1) / A;
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> v(n+2);
	for (int i=0; i<m; ++i){
		int a,b;	
		cin >> a >> b;
		v[a]++;
		v[b+1]--;
	}
	int cnt=0,sum=0;
	for (int i=0; i<=n; ++i){
		sum += v[i];
		if (sum == m) ++cnt;
	}
	cout << cnt;
   return 0;
}

Measured memory_bytes: 640
/*
Li-Chao Tree
Given a set of lines, answer queries of the form add a new line (k, c) = kx + c, and find the minimum across all lines
evaluated at x, both in logarithmic time. A segment tree is created over all points that can be queried.
Construction : O(max(x))
Query : O(log(max(x)))
Reference : https://cp-algorithms.com/geometry/convex_hull_trick.html
*/

#include <bits/stdc++.h>
using namespace std;

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

using point = complex<int>;
#define x real
#define y imag

const int MAXN = 1E6 + 100, INF = 5E15 + 5, LAR_INF = 	5E18; // points evaluated over [1 : MAXN]
point line[4 * MAXN];

int dot(point a, point b) {
	return (conj(a) * b).x();
}

int f(point a, int x) {
	return dot(a, {x, 1});
}

void build_tree(int v = 1, int l = 0, int r = MAXN) {
	line[v] = {0, LAR_INF};
	if(r - l == 1)
		return;
	int m = (l + r)/2;
	build_tree(2*v, l, m);
	build_tree(2*v + 1, m, r);
}


void add_line(point nw, int v = 1, int l = 0, int r = MAXN) {
	int m = (l + r)/2;
	bool left = f(nw, l) < f(line[v], l);
	bool mid = f(nw, m) < f(line[v], m);
	if(mid)
		swap(line[v], nw);
	if(r - l == 1)
		return;
	if(left != mid)
		add_line(nw, 2*v, l, m);
	else
		add_line(nw, 2*v + 1, m, r);
}

int get(int x, int v = 1, int l = 0, int r = MAXN) {
	int val = f(line[v], x);
	if(r - l == 1)
		return val;
	int m = (l + r)/2;
	if(x < m)
		val = min(val, get(x, 2*v, l, m));
	else
		val = min(val, get(x, 2*v + 1, m, r));
	return val;
}

void mini(int &x, int y) {
	x = min(x, y);
}

int32_t main() {
	fast();
	build_tree();
	int n, c;
	cin >> n >> c;
	vi h(n);
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vi dp(n);
	dp[0] = 0;
	add_line({-2*h[0], h[0] * h[0] + c + dp[0] + INF});
	for(int i = 1; i < n; i++) {
		dp[i] = h[i] * h[i] + get(h[i]) - INF;
		add_line({-2 * h[i], h[i] * h[i] + dp[i] + c + INF});
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 38144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int_Max 2147483647
#define ll_Max 9223372036854775807
#define REP(i,f,n) for(int i=f; i<(n); i++)
int xh[8] ={ 1,-1, 1,-1, 1,-1, 0, 0};
int yh[8] ={ 1,-1,-1, 1, 0, 0, 1,-1};

int main()
{
  int h, w;
  cin >> h >> w;
  string s[h];
  REP(i,0,h){
    cin >> s[i];
  }
  REP(i,0,h){
    REP(j,0,w){
      int cnt = 0;
      if(s[i][j] == '.'){
        REP(k,0,8){
          int x = j + xh[k], y = i + yh[k];
          if(x < 0 || w <= x)continue;
          if(y < 0 || h <= y)continue;
          if(s[y][x] == '#')cnt++;
        }
        cout << cnt;
      }else{
        cout << "#";
      }
    }
    cout << endl;
  }

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

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

int main(){
  double minv;
  while(cin >> minv){
    double t = minv/9.8;
    double height = 4.9 * t * t;
    int floor = height/5.0 + 1;

    //切り上げ
    double remainder = height - (floor-1) * 5.0;
    if(remainder>0) floor++;
    cout << floor << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
N=int(input())
x=0
y=0
for i in range(N):
    a,b=input().split() #pythonでは辞書も比較可能 
    if a<b:
        y+=3
    elif a==b:
        x+=1
        y+=1
    else:
        x+=3
print(x,y)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
double dp[N][N] , p[N];
int n;


int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i = 1 ; i <= n; i ++){
		cin>>p[i];
	}
	dp[1][1] = p[1];
	dp[1][0] = 1 - p[1];
	for(int i = 2 ; i <= n ; i ++){
		for(int j = 0 ; j <= n; j ++){
			if(j) dp[i][j] = dp[i-1][j-1]*p[i];
			dp[i][j] += dp[i-1][j]*(1-p[i]);
		}
	}
	double ans = 0.00000;
	for(int j = 0 ; j <= n ; j ++){
		if(j > (n-j)){
			ans += dp[n][j];
		}
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 70528
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextStr()
	if N[0] == '7' || N[1] == '7' || N[2] == '7' {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}


Measured memory_bytes: 1760
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;

typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

struct P {int x, y, z; P(int x, int y, int z):x(x), y(y), z(z){}};

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)

//FILE *in = freopen("B", "r", stdin);

int n, m;
char data[100][100];
int ch[100][100];

int mvx[4] = {0, 1, 0, -1};
int mvy[4] = {1, 0, -1, 0};

int maxn, maxm;

void input(){
	memset(data, 0, sizeof(data));
	memset(ch , 0, sizeof(ch));
	maxn = n*2+1;
	maxm = m*2 + 1;
	gets(data[0]);
	fill(data[0], data[0] + maxn, '1');
	for(int i = 1; i <= m * 2 - 1; i++) {
		gets(data[i]+1);
		data[i][0] = '1';
		data[i][maxn-1] = '1';
	}
	fill(data[maxm-1], data[maxm-1] + maxn, '1');
}

void process() {
	queue<P> que;
	que.push(P(1,1,1));
	ch[1][1] = 1;
	while(!que.empty()) {
		P cur = que.front(); que.pop();

		if(cur.x == maxn - 2 && cur.y == maxm-2) {
			printf("%d\n", cur.z);
			return;
		}

		for(int i = 0; i < 4; i ++) {
			if(cur.x + mvx[i]*2 >= 0 && cur.x + mvx[i]*2 <= maxn - 1 && cur.y + mvy[i]*2 >= 0 && cur.y + mvy[i]*2 < maxm
				&& data[cur.y + mvy[i]][cur.x + mvx[i]] != '1' && !ch[cur.y + mvy[i]*2][cur.x + mvx[i]*2]) {
					ch[cur.y + mvy[i]*2][cur.x + mvx[i]*2] = 1;
					que.push(P(cur.x + mvx[i]*2, cur.y + mvy[i]*2, cur.z + 1));
			}
		}
	}
	printf("0\n");
}

int main() {
	while(true){
		scanf("%d%d", &n, &m);
		if(n == 0 && m == 0)break;
		input();
		process();
	}
	return 0;
}

Measured memory_bytes: 1248
#include<iostream>
#include<cstdio>
#include<map>

std::map<int,int> mp;

int main()
{
	int i;
	int N,M;
	scanf("%d",&N);
	for(i=1;i<=N;i++)
	{
		int D;scanf("%d",&D);
		mp[D]++; 
	}
	scanf("%d",&M);
	bool ans=true;
	for(i=1;i<=M;i++)
	{
		int T;scanf("%d",&T);
		if(--mp[T]<0) {ans=false;break;}
	}
	if(ans) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	int n=nxi(),m=nxi();
	if(n>m) std::swap(n,m);
	if(n==1){
		printf("%d\n",m==1?1:m-2);
	}
	else{
		printf("%lld\n",(lint)(n-2)*(m-2));
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n,a,b;
  string str;
  cin >> str;
  if(str[0]==str[1] && str[1]==str[2]){
    cout <<"Yes\n";
    return 0;
  }
  if(str[3]==str[1] && str[1]==str[2]){
    cout <<"Yes\n";
    return 0;
  }

  cout << "No\n";
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
N = int(input())
mod = 10**9+7
prime = [2]
for i in range(3,N+1):
  if(all(i%p for p in prime)):
    prime.append(i)

ans = 1
for p in prime:
  tmp = N
  cnt = 0
  while tmp != 0:
    cnt += tmp//p
    tmp //= p
  ans = ans*(cnt+1) % mod
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
	int a,b;
	while(cin >> a >> b){
		if(a==0 && b==0)
			break;
		double x = static_cast<double>(a);
		double h = static_cast<double>(b);
		cout << setprecision(6) << fixed << x*x+2*x*sqrt(x*x/4+h*h) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string s;
	cin>>s;
	switch(s[0]){
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
			cout<<"vowel"<<endl;
			return 0;
		default:
			cout<<"consonant"<<endl;
			return 0;
	}
	return 0;
}

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


int main() { 
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n;
    cin >> n;
    string ans;
    while (n > 0) {
        n--;
        ans += ('a' + n % 26);
        n = n / 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3648
# include <bits/stdc++.h>
using namespace std;
# define ll long long
const int N = 2e5 + 10;
ll a[N] , b[N] , diff[N] , ans , k , n;
bool check(ll x){
	ll res = 0;
	for(int i = 0; i < n; i ++)
		res += max((ll)0, a[i] - x / b[i]);
	return res <= k;
}
int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i ++) cin >> a[i];
	for(int i = 0; i < n; i ++) cin >> b[i];
	sort(a , a + n);
	sort(b , b + n);
	reverse(b , b + n);
	ll l = 0 , r = a[n - 1] * b[0];
	while(l <= r){
		ll m = (l + r) >> 1;
		if(check(m)) r = m - 1 , ans = m;
		else l = m + 1;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3328
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String ans= "No";
    for (int i=1; i<10; i++) {
    	for (int j=1; j<10; j++) {
        	if (i*j == N) {
            	ans = "Yes";
                break;
            }
        }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35844
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)




int solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
   
    
    //cout<<a<<endl;
    ll temp = (c-a-b);
    if(temp<0)
    {
        cout<<"No"<<endl;
        return 0;
    }
    temp = temp*temp;

    
    ll flag = 4*a*b;
    
    cout<<(temp>flag?"Yes":"No")<<endl;
    
    //cout<<((temp*temp)>flag?"Yes":"No")<<endl;
    
    return 0;
}
int main()
{
    fio;

// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif


	
	ll t=1;
	//cin>>t;
	while(t--)
	{
	   
	    solve();
	}
	return 0;
}
    

Measured memory_bytes: 256
use std::collections::HashSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
  let mut sset = HashSet::new();
  input! {
    N: usize,
    L: usize,
    ss: [chars; N],
  }
  let mut pairs = vec![];
  for s in ss {
    let mut s: String = s.into_iter().collect();
    let mut srev: String = s.clone().chars().rev().collect();
    if sset.contains(&srev) {
      sset.remove(&srev);
      if s < srev {
        pairs.push(s);
      } else {
        pairs.push(srev);
      }
    } else {
      sset.insert(s);
    }
  }
  pairs.sort();
  let mut svec: Vec<_> = sset.into_iter().collect();
  svec.sort();
  let mut center = "".to_string();
  for s in svec {
    let srev: String = s.clone().chars().rev().collect();
    if s == srev {
      center = s;
      break;
    }
  }
  for s in &pairs {
    print!("{}", s);
  }
  print!("{}", center);
  for s in pairs.iter().rev() {
    let s: String = s.chars().rev().collect();
    print!("{}", s);
  }
  println!("");
}



Measured memory_bytes: 5064
x1, y1, x2, y2 = [ int(v) for v in input().split() ]

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)  
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

print(x3, y3, x4, y4)

Measured memory_bytes: 2940