akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second
 
struct circle { point p; double r; };
 
const double eps = 1e-9;
int sign(double x) { return x < -eps ? -1 : x > eps; }
 
// circle-circle intersection
vector<point> intersect(circle C, circle D){
	double d = abs(C.p - D.p);
	if (sign(d - C.r - D.r) > 0) return {};      
	if (sign(d - abs(C.r - D.r)) < 0) return {}; 
	double a = (C.r*C.r - D.r*D.r + d*d) / (2*d);
	double h = sqrt(C.r*C.r - a*a);
	point v = (D.p - C.p) / d;
	if (sign(h) == 0) return {C.p + v*a};         
	return {C.p + v*a + point(0,1)*v*h,           
			C.p + v*a - point(0,1)*v*h};
}
 
int main(){
 
	int n, k;
	cin >> n >> k;
	vector<pair<point, double>> a(n);
	for (auto &i : a)
	{
		int x, y, c;
		cin >> x >> y >> c;
		i.F = { x, y };
		i.S = c;
	}
 
	auto f = [&](double x)
	{
		vector<point> v;
		vector<circle> c;
		for (auto i : a)
		{
			v.push_back(i.F);
			c.push_back({ i.F, x / i.S });
		}
		for (int i = 0; i < n; ++i)
			for (int j = i+1; j < n; ++j)
				for (auto z : intersect(c[i], c[j]))
					v.push_back(z);
		for (auto p : v)
		{
			int cnt = 0;
			for (auto i : c)
				cnt += abs(p - i.p) <= i.r + eps;
			if (cnt >= k)
				return true;
		}
		return false;
	};
 
	double l = 0, r = 1e6;
	for (int it = 200; it--; )
	{
		double md = (l + r) / 2.0;
		if (f(md))
			r = md;
		else
			l = md;
	}
	cout << setprecision(20) << fixed << l << '\n';
 
	return 0;
}

Measured memory_bytes: 512
function main(input) {
  // 入力値（文字列）をスペースで区切る
  const inputList = input.split(/\s/);
  const numOfW = formatNum(inputList[0]);
  const numOfH = formatNum(inputList[1]);
  const numOfX = formatNum(inputList[2]);
  const numOfY = formatNum(inputList[3]);
  
  // 面積
  const area = numOfW * numOfH;

  // 最適な分割方法が複数あるかを判定
  const result = numOfW / 2 === numOfX && numOfH / 2 === numOfY ? 1 : 0;
  console.log(`${(area / 2).toFixed(6)} ${result}`);
};

// 文字列を数値に変換
function formatNum(str) {
  return Number(str);
};

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


Measured memory_bytes: 7372
#include<iostream>

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

int main() {
    int N;
    long A[100000], ans;
    std::cin >> N;
    for (int i = 0 ; i < N ; ++i) {
        std::cin >> A[i];
        if (i == 0) {
            ans = A[0];
        } else {
            ans = gcd(ans, A[i]);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    if (n <= 999)
    {
        cout << "ABC"  << "\n";
    }
    else
    {
        cout << "ABD"  << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    max=a[-1]
    check=[0 for i in range(max+10)]
    sum=0
    #print(a)
    if len(a)==1:
        print(1)
        exit()
    if a[0]==1:
        if a[1]==1:
            print(0)
        else:
            print(1)
        exit()
    for i in range(n):
        if check[a[i]]==0:
            sum+=1
            j=1
            x=a[i]*j
            while x<max+1:
                check[x]=1
                j+=1
                x=a[i]*j
            if i<n-1 and a[i+1]==a[i]:
                sum-=1
        else:
            continue
    print(sum)
        
    
    
if __name__=="__main__":
    main()

Measured memory_bytes: 157056
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int sz;
    sz = str.size();
    int mx=0;
    int scr=0;
    for(int i=0; i<sz; i++){
        if(str[i]=='I'){
            scr++;
        }else if(str[i]=='D'){
            scr--;
        }
        mx = max(mx,scr);
    }
    cout << mx << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

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

        long modA = (long)Math.pow(10, 9) + 7;

        long ans = 0;
        long total = 0;
        long a;
        for (int i = 0; i < n; i++) {
            a = Long.parseLong(sc.next());
            ans += total * a;
            ans %= modA;
            total += a;
            total %= modA;
        }
        System.out.print(ans);
    }
}


Measured memory_bytes: 59120
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int a[] = new int[n]; 
       for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){
            System.out.println("DENIED");
            return;
        }
       }
       System.out.println("APPROVED");
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

bool ok(ll n, ll k) {
    while (n >= k) {
        if (n % k == 0)
            n /= k;
        else
            n -= k;
    }
    return n == 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    set<ll> st;
    st.emplace(2);
    st.emplace(n);
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ll t = n;
            while (t % i == 0) {
                t /= i;
            }
            if (t == 1 || (t - 1) % i == 0) {
                st.emplace(i);
            }
        }
    }
    for (ll i = 1; i * i <= n; i++) {
        if ((n - 1) % i == 0) {
            st.emplace((n - 1) / i);
          st.emplace(i);
        }
    }
  st.erase(1);
    cout << st.size() << '\n';
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from itertools import accumulate

n, m, k = map(int, input().split())
la = [0] + list(map(int, input().split()))
lb = list(map(int, input().split()))
# n,m,k=3,4,240
# la = [60, 90, 120]
# lb = [80, 150, 80, 150]

la = list(accumulate(la))
lb = list(accumulate(lb))


# x =bisect_right(lb, 600)
# print(lb)
# print(x)


answer = 0
for ia, a in enumerate(la):
    if a <= k:
        ib = bisect_right(lb, k - a)
        answer = max(answer, ia + ib)


print(answer)







Measured memory_bytes: 43228
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt(), B= sc.nextInt(), C= sc.nextInt(), D= sc.nextInt(),
    E= sc.nextInt(), t=0, last = 0;
    int a = A % 10, b = B % 10, c = C % 10, d = D % 10, e = E % 10;
    if(a == 0 && b == 0 && c == 0 && d== 0 && e== 0) {
      t = A + B + C + D + E;
    } else {
      int[] X = { a, b, c, d, e }; 
      Arrays.sort(X);
      for(int i= 0; i<5; i++) {
        if(X[i] != 0) {
          last = X[i];
          break;
        }
      }
      if(a==0) {
        t += A;
      } else {
        t = t + A - a + 10;
      }
      if(b==0) {
        t += B;
      } else {
        t = t + B - b + 10;
      }
      if(c==0) {
        t += C;
      } else {
        t = t + C - c + 10;
      }
      if(d==0) {
        t += D;
      } else {
        t = t + D - d + 10;
      }
      if(e==0) {
        t += E;
      } else {
        t = t + E - e + 10;
      }
      t = t-10 + last;
    }
    System.out.println(t);
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  
  int ans = 0;
  
  for (int i = 1; i <= n - 2; i++) {
    if ((p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1)) || (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))) {
      ans++;
    }
  }
  
  cout << ans;  
}

Measured memory_bytes: 256
import sys
import math
MOD = 10 ** 9 + 7

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a):
    x = extgcd(a,MOD)[0]
    return (MOD+x%MOD)%MOD

input = sys.stdin.readline
n,a,b = map(int,input().split())
x1 = 1

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
x11 = 1
for i in range(1,a+1):
    x11 = x11 * i % MOD
x1 = x1 * mod_inv(x11) % MOD

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
x21 = 1
for i in range(a+1,b+1):
    x21 = x21 * i % MOD
x2 = x2 * mod_inv(x21) % MOD

t = []
nn = n
while nn > 0:
    t.append(nn % 2)
    nn //= 2
x0 = 1
for i in range(len(t)):
    x0 = x0 ** 2
    x0 = x0 % MOD
    if t[len(t)-i-1] == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)




Measured memory_bytes: 39152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
//#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll MOD,p;
ll a[3010],b[3010];
ll temp[3010];
int main(){
	scanf("%lld",&MOD);
	p=MOD;
	rep(i,0,MOD){
		int y;
		scanf("%d",&y);
		if(y){
			rep(j,0,p+1)temp[j]=0;
			temp[p]=1;
			temp[1]=-1;
			//x^p-xをx-yで割る
			for(int j=p-1;j>=0;j--){
				b[j]=(b[j]+temp[j+1])%MOD;
				temp[j]=(temp[j]+temp[j+1]*i)%MOD;
			}
		}
	}
	rep(j,0,p)printf("%d ",(MOD-b[j])%MOD);
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] y = new int[n];

		for(int i=0; i<n; i++){
			y[i] = sc.nextInt();
		}

		int t = 0;

		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				t += y[i] * y[j];
			}
		}
		System.out.println(t);
	}

}


Measured memory_bytes: 23764
#include<stdio.h>
#include<stdlib.h>
int n,m;
int a[1001];
int b[510000];
bool f[1001][1001];
int i,j;
int ans;
int c;
 
int max(int a,int b){
    if(a>=b)return a;
    else return b;
}
 
int comp(const void *a,const void *b){
    int p=*(int*)a;
    int q=*(int*)b;
    return p-q;
}
 
int search(int num){
    int r=0;
    int l=c;
    int mid;
    for(int k=0;k<25;k++){
        mid=(int)(r+l)/2;
        if(num-b[mid+1]>=0&&num-b[mid]>num-b[mid+1])mid=mid+1;
        if(b[mid]>num)l=mid;
        else r=mid;
    }
    return mid;
}
 
int main(){
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0&&m==0)return 0;
        ans=0;
        c=0;
        for(i=0;i<n;i++)scanf("%d",&a[i]);
        a[n]=0;
        for(i=0;i<n+1;i++)for(j=0;j<n+1;j++)f[i][j]=false;
        for(i=0;i<n+1;i++)for(j=0;j<n+1;j++){
            if(!f[j][i]&&a[i]+a[j]<=m){
                b[c++]=a[i]+a[j];
                f[i][j]=true;
            }
        }
        qsort(b,c,sizeof(int),comp);
        for(i=0;i<c;i++){
            if(m-b[i]>=0){
                ans=max(ans,b[search(m-b[i])]+b[i]);
            }
        }
        printf("%d\n",ans);
    }
}

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

int main() {
  int N,L;
  cin >> N >> L;
  
 vector<string> S(N); 
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    cout << S.at(i);
  }  
  cout << "\n";
}

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

typedef long long ll;

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

int main() {
	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		ll A, B, C, D; cin >> A >> B >> C >> D;
		if (A < B) {
			cout << "No" << endl;
			continue;
		}
		else if (D < B) {
			cout << "No" << endl;
			continue;
		}
		else if (C > B) {
			cout << "Yes" << endl;
			continue;
		}

		ll G = gcd(B, D);
		if (A % G + B - G > C) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N,M=[int(i) for i in input().split()]
AC,WA=[False]*N,[0]*N
for i in range(M):
    p,s=input().split()
    p=int(p)-1
    if AC[p]==False:
        if s=="AC":
            AC[p]=True
        if s=="WA":
            WA[p]+=1
    else:
        continue

ans_AC=AC.count(True)
ans_WA=0
for i in range(N):
    if AC[i]:
        ans_WA+=WA[i]
print(ans_AC,ans_WA)

Measured memory_bytes: 4596
import java.util.*;

public class Main {
    
    private static int[] parent;
    private static int[] size;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        parent = new int[N];
        size = new int[N];
        for (int i = 0; i < N; i++) {
            parent[i] = i;
            size[i] = 1;
        }

        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < M; i++) {
            int A = sc.nextInt()-1;
            int B = sc.nextInt()-1;
            graph.get(A).add(B);
            graph.get(B).add(A);
            unite(A, B);
        }

        List<Set<Integer>> block = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            block.add(new HashSet<>());
        }
        for (int i = 0; i < K; i++) {
            int C = sc.nextInt()-1;
            int D = sc.nextInt()-1;
            block.get(C).add(D);
            block.get(D).add(C);
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < N; i++) {
            int tmp = size[root(i)] - 1 - graph.get(i).size();
            for (int f : block.get(i)) {
                if (same(i, f)) tmp--;
            }
            ans.append(tmp).append(i == N-1 ? '\n' : ' ');
        }
        System.out.print(ans);
    }

    private static int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    private static void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry ) return;
        parent[rx] = ry;
        size[ry] += size[rx];
    }

    private static boolean same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll x, a;
	cin >> x >> a;

	cout << ((x < a) ? 0 : 10) << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(string S) {
  bool pred = S.find("AC") != S.npos;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,K;cin>>N>>K;
  vector<long>X(N),Y(N);for(long i=0;i<N;i++)cin>>X[i]>>Y[i];
  long ans=LONG_MAX;
  for(long a=0;a<N;a++)for(long b=a;b<N;b++)for(long c=b;c<N;c++)for(long d=c;d<N;d++){
    long y1=min(min(Y[a],Y[b]),min(Y[c],Y[d]));
    long y2=max(max(Y[a],Y[b]),max(Y[c],Y[d]));
    long x1=min(min(X[a],X[b]),min(X[c],X[d]));
    long x2=max(max(X[a],X[b]),max(X[c],X[d]));  
    long count=0;
    for(long i=0;i<N;i++)count+=(y1<=Y[i]&&Y[i]<=y2&&x1<=X[i]&&X[i]<=x2);
    if(count>=K)ans=min(ans,(y2-y1)*(x2-x1));
  }
  cout<<ans;
}




Measured memory_bytes: 256
#include <iostream>

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    ll N;
    cin >> N;
    cout << N * (N - 1) / 2 << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  if(N % 2 == 0){
    cout << 0.5000000000 << endl;
  }
  
  else{
    int x = N / 2 + 1;
    
    double A;
    A = (double)x;
    cout << A / N << endl;
  }
  

}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	_, m := readI(), readI()
	acp := make(map[int]bool)
	ac := 0
	ngp := make(map[int]int)
	for i := 0; i < m; i++ {
		p, s := readI(), readS()
		if !acp[p] {
			if s == "AC" {
				acp[p] = true
				ac++
			} else {
				ngp[p]++
			}
		}
	}

	ng := 0
	for k := range acp {
		ng += ngp[k]
	}
	fmt.Println(ac, ng)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 8160
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[101];
char c[2];
int p[100];
int ABS(int a){return a<0?-a:a;}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		for(int i=0;i<a;i++)str[i]='#';
		str[a]=0;
		bool ok;
		for(int i=0;i<b;i++){
			scanf("%s",c);
			switch(c[0]){
				case 'A':
					for(int j=0;j<a;j++)
						if(str[j]=='#'){
							str[j]='A';
							break;
						}
					break;
				case 'B':
					ok=false;
					for(int j=a-1;j>=0;j--){
						if(str[j]=='#'&&(j==0||str[j-1]!='A')&&str[j+1]!='A'){
							ok=true;
							str[j]='B';
							break;
						}
					}
					if(!ok){
						for(int j=0;j<a;j++)
							if(str[j]=='#'){
								str[j]='B';
								break;
							}
					}
					break;
				case 'C':
					if(i==0){
						str[a/2]='C';
					}else{
						for(int j=0;j<a;j++){
							if(str[j]!='#'){
								if(str[j+1]=='#'){
									str[j+1]='C';
									break;
								}else if(j&&str[j-1]=='#'){
									str[j-1]='C';
									break;
								}
							}
						}
					}
					break;
				case 'D':
					for(int j=0;j<a;j++)p[j]=9999;
					for(int j=0;j<a;j++){
						if(str[j]!='#'){
							for(int k=0;k<a;k++)p[k]=min(p[k],ABS(j-k));
						}
					}
					int at=0;
					int cost=0;
					for(int j=0;j<a;j++){
						if(cost<p[j]){at=j;cost=p[j];}
					}
					str[at]='D';
					break;
			}
			//	printf("%s\n",str);
		}
		printf("%s\n",str);
	}
}

Measured memory_bytes: 1012
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author palayutm
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            if (n > m) {
                int t = n;
                n = m;
                m = t;
            }
            if (n == 1 && m == 1) {
                out.println(1);
                return;
            }
            if (n == 1) {
                out.println(m - 2);
                return;
            }
            out.println((long) (n - 2) * (m - 2));

        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream out) {
            super(out);
        }

        public OutputWriter(Writer out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 20820
H, W = map(int, input().split())
s = []
for k in range(H):
    s.append(input())

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

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


int main()
{
	int a1, a2, a3, maxNum, midNum, minNum;
	cin >> a1 >> a2 >> a3;
	maxNum = max(a1, max(a2, a3));
	minNum = min(a1, min(a2, a3));
	if (a2 >= a1) {
		if (a3 <= a1)midNum = a1;
		else if (a3 >= a2)midNum = a2;
		else midNum = a3;
	}
	else if (a2 < a1) {
		if (a3 <= a2)midNum = a2;
		else if (a3 >= a1)midNum = a1;
		else midNum = a3;
	}
	cout << maxNum*10+midNum +minNum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,w,a,b,d[10001];
int main(void){
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        for(int j=w;j>=b;j--)d[j]=max(d[j],d[j-b]+a);
    }
    cout<<d[w]<<endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long    ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second

#define fore(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
#define forr(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
ll faster_in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
const lldb PI = acos(-1);
#define tam 3200
const ll MOD=1e9+7;
ll dp[3000][3000];
ll func(int pos,int lastdig)
{
    if (lastdig<0|| lastdig>=10)
        return 0;
    if (pos==0)
        return 1;
    if (dp[pos][lastdig]!=-1)
        return dp[pos][lastdig];
    ll res=0;
    res+=func(pos-1,lastdig-1);
  	res+=func(pos-1,lastdig);
  	res+=func(pos-1,lastdig+1);
    return dp[pos][lastdig]=res;
}

ll kth;
void print(int pos,int lastdig)
{
    if (lastdig==10)
        assert(false);
    cout<<lastdig;
    if (pos==0)
        {
            cout<<endl;
            exit(0);
            return;
        }
    if (lastdig>0 && kth<=func(pos-1,lastdig-1)){
        print(pos-1,lastdig-1);
        return;
    }
    kth-=func(pos-1,lastdig-1);
    if (kth<=func(pos-1,lastdig))
    {
        print(pos-1,lastdig);
        return;
    }
    kth-=func(pos-1,lastdig);
    print(pos-1,lastdig+1);
}
int main()
{    
    memset(dp,-1,sizeof dp);
    
    cin>>kth;
    forr(digs,1,100)
    {
        forr(lastdig,1,10)
        {
          	//cout<<"resta es "<<kth-func(digs-1,lastdig)<<endl;
            //cout<<func(digs-1,lastdig)<<"--";
            if (kth <= func(digs-1,lastdig))
            {
                print(digs-1,lastdig);
                return 0;
            }
			//cout<<func(digs-1,lastdig)<<","<<kth<<"  ";
            kth-=func(digs-1,lastdig);
        }
        //cout<<kth<<" "<<digs<<endl;
    }

}
// PLUS ULTRA!


Measured memory_bytes: 70528
N, M = map(int, input().split())
suki=[0]*M # これが最終的にNになったら皆好きてこと
for i in range(N):
  tmp=list(map(int, input().split()))
  for val in tmp[1:]:
    suki[val-1]+=1

ans=suki.count(N)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL ex(LL x, LL y) { return (y == 0 ? 1 : x * ex(x, y - 1)); }
LL digit(LL x, LL y, LL b = 10) { return x / ex(b, y) % b; }

int n, a[3], l[8];

int main() {
	cin >> n;
	inc(i, 3) { cin >> a[i]; }
	inc(i, n) { cin >> l[i]; }
	
	int ans = 1e6;
	inc(i, ex(4, n)) {
		vector<int> v(4);
		int s = 0;
		inc(j, n) {
			int d = digit(i, j, 4);
			if(d != 3 && v[d] != 0) { s += 10; }
			v[d] += l[j];
		}
		inc(k, 3) { s += abs(v[k] - a[k]); }
		
		bool f = true;
		inc(k, 3) { f &= (v[k] != 0); }
		if(f) { setmin(ans, s); }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int a = vs[0];  // 白 .
			int b = vs[1];  // 黒 #

			int h = 100;
			int w = 100;
			char[][] board = new char[h][];
			for (int i = 0; i < h; i++) {
				board[i] = new char[w];
			}
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					board[i][j] = i < h / 2 ? '.' : '#';
				}
			}

			int x = 0;
			int y = 0;
			for (int i = 1; i < b; i++) {
				board[y][x] = '#';
				x += 2;
				if (x >= w) {
					x = 0;
					y += 2;
				}
			}

			x = w - 1;
			y = h - 1;
			for (int i = 1; i < a; i++) {
				board[y][x] = '.';
				x -= 2;
				if (x < 0) {
					x = w - 1;
					y -= 2;
				}
			}

			Console.WriteLine($"{h} {w}");
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					Console.Write(board[i][j]);
				}
				Console.WriteLine();
			}

		}
	}
}


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

int main () {
   int n;
   cin>>n;
   int arr[n+1];
   for(int i=0;i<n+1;i++)
   {
     arr[i]=0;
   }
   for(int i=0;i<n-1;i++)
   {
     int s;
     cin>>s;
     arr[s]+=1;
   }
   for(int i=1;i<=n;i++)
   {
     cout<<arr[i]<<endl;
   }


}


Measured memory_bytes: 4364
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
int main() {
    int N;
    cin >> N;
    vector<int> B(N);
    rep(i, 0, N - 1) { cin >> B[i]; }
    int res = B[0] + B[N - 2];
    rep(i, 0, N - 2) { res += min(B[i], B[i + 1]); }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int A[2000000];
int n;

int Partition(int,int);


int main(){
  int i,k;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  k=Partition(1,n);
  for(i=1;i<=n;i++){
    if(k==i) printf("[%d] ",A[i]);
    else if(i==n) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  return 0;
}
 

int Partition(int p,int r){
  int x,i,j,y;

  x = A[r];
  i = p-1;
  for(j = p;j<=r-1;j++){
    if( A[j] <= x){ i = i+1;
    y=A[i];
    A[i]=A[j];
    A[j]=y;
    }
  }
    y=A[i+1];
    A[i+1] =A[r];
    A[r]=y;
    return i+1;
}

Measured memory_bytes: 992
#include <iostream>

using namespace std;

const int MAX_LENGTH = 50;

int map[MAX_LENGTH][MAX_LENGTH];

void dfs(int x, int y) {
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (y + i >= 0 && MAX_LENGTH > y + i && x + j >= 0 && MAX_LENGTH > x + j && map[y+i][x+j] == 1) {
				map[y+i][x+j] = 0;
				dfs(x + j, y + i);
			}
		}
	}

	return;
}

int main() {
	while (true) {
		int w, h, count;
		cin >> w >> h;
		if (w == 0) {
			break;
		}
		for (int i = 0; i < MAX_LENGTH; i++) {
			for (int j = 0; j < MAX_LENGTH; j++) {
				map[i][j] = 0;
			}
		}
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> map[i][j];
			}
		}
		
		count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == 1) {
					map[i][j] = 0;
					dfs(j, i);
					count++;
					/*
					for (int k = 0; k < h; k++) {
						for (int l = 0; l < w; l++) {
							cout << map[k][l] << " ";
						}
						cout << endl;
					}
					cout << endl;
					*/
				}
			}
		}
		cout << count << endl;
	}

	return 0;
}

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

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

    int x, a;
    cin >> x >> a;
    if(x < a){
        cout << 0;
    } else {
        cout << 10;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  ll x,k,d; cin>>x>>k>>d;
  x=abs(x);
  ll y=x%d;
  ll z=x/d;
  ll ans;
  if(x/d>=k){
    ans=x-k*d;
    cout<<ans<<endl;
    return 0;
  }
  if((abs(k-z))%2==0) cout<<y<<endl;
  else cout<<d-y<<endl;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int n;
vector<vector<vector<double> > > memo;

double solve(int a, int b, int c)
{
    if(a == 0 && b == 0 && c == 0)
        return 0.0;
    if(memo[a][b][c] > -0.5)
        return memo[a][b][c];

    vector<int> v = {0, a, b, c};
    double ans = 1.0;
    for(int i=1; i<=3; ++i){
        if(v[i] > 0){
            double tmp = v[i] / (double)n;
            -- v[i];
            ++ v[i-1];
            tmp *= solve(v[1], v[2], v[3]);
            ans += tmp;
            -- v[i-1];
            ++ v[i];
        }
    }
    ans *= n / (double)(a + b + c);

    return memo[a][b][c] = ans;
}

int main()
{
    cin >> n;
    vector<int> v(3);
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        ++ v[a-1];
    }

    memo.assign(n+1, vector<vector<double> >(n+1, vector<double>(n+1, -1.0)));
    printf("%.10f\n", solve(v[0], v[1], v[2]));

    return 0;
}


Measured memory_bytes: 216960
use proconio::{fastout, input};
const MOD: i128 = 1_000_000_000 + 7;

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut pow10 = 1;
    let mut pow9 = 1;
    let mut pow8 = 1;
    for i in 1..=n {
        pow10 = pow10 * 10 % MOD;
        pow9 = pow9 * 9 % MOD;
        pow8 = pow8 * 8 % MOD;
    }

    println!("{}", (pow10 + 2 * (MOD - pow9) + pow8) % MOD);
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N;

void input() {
	cin>>N;
}

void solve() {
	N%=1000;
	N=(1000-N)%1000;
	cout<<N<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if ((a==b && a!=c) || (a==c && a!=b) || (c==b && a!=c)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int minSequenceSize(string x, string y)
{
    int x_len = x.size();
    int y_len = y.size();
    int map[x_len][y_len] = {};

    for (int i = 0; i < x_len; i++)
    {
        for (int j = 0; j < y_len; j++)
        {
            if (i == 0)
            {
                map[0][j] = 0;
                continue;
            }
            if (j == 0)
            {
                map[i][0] = 0;
                continue;
            }

            if (x[i] == y[j])
            {
                map[i][j] = map[i - 1][j - 1] + 1;
                continue;
            }

            if (x[i] != y[j])
            {
                map[i][j] = max(map[i - 1][j], map[i][j - 1]);
                continue;
            }
        }
    }
    return map[x_len - 1][y_len - 1];
}

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

    for (int i = 0; i < q; i++)
    {
        string x, y;
        cin >> x >> y;

        x = " " + x;
        y = " " + y;
        int ans = minSequenceSize(x, y);
        cout << ans << endl;
    }
}


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

#define debug(x) cout<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair

int n,a,x,y;
int b[100003];

int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		b[a-1]++;
		b[a+1]++;
		b[a]++;
	}
	for (int i=0;i<=100001;i++){
		if (b[i]>x) x=b[i];
	}
	cout<<x;
	return 0;
}

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

int main() {
    string N; cin >> N;
    int su = 0;
    for (int i = 0; i < N.size(); i++) {
        int num = (int)(N[i] - '0');
        su += num;
    }
    if (su%9 == 0 || su == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main(int argc, char const *argv[])
{
    int H, W; cin >> H >> W;
    char board[100][100];
    int I[100] = {};
    int J[100] = {};
    REP(i, H) {
        REP(j,W) {
            cin >> board[i][j];
            if (board[i][j] == '#') {
                I[i]++;
                J[j]++;
            }
        }
    }
    REP(i, H) {
        if (I[i] == 0) continue;
        REP(j, W) {
            if (J[j] == 0) continue;
            cout << board[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
    string s,t;
    while(cin>>s>>t)
    {
        int flag=1;
        for(int i=1;i<=s.length();i++)
        {
            char temp=s[s.length()-1];
            s.insert(0,1,temp);
            s.erase(s.end()-1);
            if(s==t)
            {
                flag=0;
                break;
            }
        }
        if(flag==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<ll>> dp(N+100, vector<ll>(N+100));
    for(int width = 1;width <= N; width++){
        for(int l = 0;l < N; l++){
            int r = l + width;
            if(r > N) continue;
            if((N&1) ^ (width&1)){
                // 後攻
                dp[l][r] = min(dp[l+1][r] - A[l], dp[l][r-1] - A[r-1]);
            }else{
                // 先行
                dp[l][r] = max(dp[l+1][r] + A[l], dp[l][r-1] + A[r-1]);
            }
        }
    }
    cout << dp[0][N] << endl;
    return 0;
}


Measured memory_bytes: 78472
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int N;
char C[4040];
int A[4040];
int dp[2020][2020]; // 白1~i、黒1~jまで目標を達成するのに必要な最小のスワップ回数
int pos[2][2020]; // W==1,B==0の数jの位置
vector<vector<int> > crsW(2002, vector<int>(4040, 0)); // 0~j番目で数がi以上
vector<vector<int> >  crsB(2002, vector<int>(4040, 0)); // 0~j番目で数がi以上
// 二次元累積和
// v は 1列目と1行目に0を追加した累積和を取りたいやつの配列
void integrate(vector<vector<int> >& v){
    const int n = v.size(), m = v[0].size();
    FOR(i,0,n) FOR(j,0,m-1) v[i][j+1] += v[i][j]; // 横足して行く
    FOR(i,0,n-1) FOR(j,0,m) v[i+1][j] += v[i][j]; // 縦足して行く - > これで2次元の累積和になる！！！
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>N;
  FOR(i,0,2*N){
    cin>>C[i]>>A[i];
    pos[C[i]=='W'][A[i]] = i + 1;
    if(C[i] == 'W') crsW[A[i]][i+1]++;
    else crsB[A[i]][i+1]++;
  }
  integrate(crsW);
  integrate(crsB);
  FOR(i,0,2020) FOR(j,0,2020) dp[i][j] = 1e9;
  dp[0][0] = 0;
  FOR(i,0,N+1){
    FOR(j,0,N+1){
      // 白のi+1を持ってくる
      int cross = 0;
      // W
      cross = crsW[N][pos[1][i+1]] - crsW[i+1][pos[1][i+1]];
      // B
      cross += crsB[N][pos[1][i+1]] - crsB[j][pos[1][i+1]];
      dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cross);
      // 黒のj+1を持ってくる
      // W
      cross = crsW[N][pos[0][j+1]] - crsW[i][pos[0][j+1]];
      // B
      cross += crsB[N][pos[0][j+1]] - crsB[j+1][pos[0][j+1]];
      dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cross);
    }
  }
  cout<<dp[N][N]<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n), ans(n, 0);
  rep(i,n) cin >> a[i];
  
  rep(i,30)
  {
    int cnt = 0;
    rep(j,n)
    {
      if((a[j] >> i) & 1) cnt++;
    }
    //cout << cnt << " ";
    rep(j,n)
    {
      if(cnt % 2 == 1)
      {
        if(((a[j] >> i) & 1) == 0)
        {
          ans[j] += (1 << i);
        }
      }
      else
      {
        if((a[j] >> i) & 1)
        {
          ans[j] += (1 << i);
        }
      }
    }
  }
  //cout << endl;
  rep(i,n) cout << ans[i] << "\n";
    
  
  return 0;
}

Measured memory_bytes: 4788
import itertools
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P_org = sorted(P)

N_l = list(itertools.permutations(P_org))
N_fac = math.factorial(N)

a = 1
b = 1
for x in range(N_fac):
    if (P == list(N_l[x])):
        a += x
    if (Q == list(N_l[x])):
        b += x    
        
print(abs(a-b))

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[200] ;

int main() {
  int n , alice = 0, bob = 0 ;
  scanf("%d", &n) ;

  for(int i = 0 ;i<n ; i++)scanf("%d", &a[i]) ;

  sort(a, a+n, greater<int>()) ;

  for(int i = 0 ;i<n ;i+=2)alice+=a[i] ;
  for(int i =1 ; i<n ; i+=2)bob+=a[i] ;

  printf("%d", alice - bob) ;
	
  return 0 ;
}

Measured memory_bytes: 256
O = input()
E = input()
P = ""
i=0
for i in range(min(len(O),len(E))):
    P+=O[i]
    P+=E[i]
if len(O)>len(E):
  P+=O[len(O)-1]
elif len(O)<len(E):
  P+=E[len(E)-1]
print(P)
  

Measured memory_bytes: 3060
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    x = input()
    if x in l:
        print('a')
    else:
        print('A')

main()




Measured memory_bytes: 9884