akhauriyash/Code-Regression huggingface dataset:
class Node
    attr_accessor :parent, :rank

    def initialize(n)
      @parent = n
      @rank = 0
    end
  end

class UnionFindTree
  attr_accessor :count
  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x

    return @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  def parents
    @nodes.map(&:parent)
  end
end

n,m,k=gets.chomp.split.map(&:to_i)

uft = UnionFindTree.new(n+1)

flist = Hash.new{|hash, key| hash[key] = []}

m.times do
  a,b=gets.chomp.split.map(&:to_i)
  uft.unite(a,b)
  flist[a] << b
  flist[b] << a
end

blist = Hash.new{|hash, key| hash[key] = []}

k.times do
  c,d=gets.chomp.split.map(&:to_i)
  blist[c] << d
  blist[d] << c
end


h = Hash.new(0)

1.upto(n) do |i|
  h[uft.find(i)] += 1
end

list = []
1.upto(n) do |i|
  ans=h[uft.find(i)]-1
  ans -= flist[i].size
  blist[i].each do |v|
    ans -= 1 if uft.same?(i,v)
  end
  list << ans
end
puts list.join(" ")


Measured memory_bytes: 45932
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli comb(lli d, lli c, lli& ans){
	lli sum = 0;
	while(c > 0){
		if(c%2 == 1){
			sum = sum + d;
			if(sum >= 10){
				ans += 2;
				sum = sum - 9;
			}
		}
		c = c/2;
		if(c == 0)
			break;
		d = d*2;
		if(d >= 10){
			ans += 2 * c;
			d = d-9;
		}
		else	ans += c;
	}
	return sum;
}
lli solve(){
	lli m;
	cin>>m;
	lli sum = 0;
	lli ans = 0;
	lli c, d;
	loop(i, 0, m){
		cin>>d>>c;
		sum += c*d;
      ans += c;
	}
  	ans = ans - 1 + (sum-1)/9 ;
	cout<<ans<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(M)]

d = defaultdict(int)
c = {}
for p, y in sorted(l, key=lambda x: x[1]):
  d[p] += 1
  c[y] = str(p).zfill(6) + str(d[p]).zfill(6)

for p, y in l:
  print(c[y])

Measured memory_bytes: 49484
#include<bits/stdc++.h>
#define M 300
#define N 50
using namespace std;
int n,ax[N],ay[N],bx[N],by[N],k,ans,minx,miny;
map<int,int> X,Y;
vector<int> x,y;
bool used[M][M];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};

void init(int sx,int sy,int gx,int gy,int a){
  while(!(sx==gx&&sy==gy)){
    used[sy][sx]=true;
    sy+=dy[a],sx+=dx[a];
  }
  used[sy][sx]=true;
}

void dfs(int px,int py){
  used[py][px]=true;
  for(int i=0;i<4;i++){
    int nx=px+dx[i],ny=py+dy[i];
    if(nx<0||ny<0||M<=nx||M<=ny)continue;
    if(used[ny][nx])continue;
    dfs(nx,ny);
  }
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    X.clear();
    Y.clear();
    x.clear();
    y.clear();
    minx=miny=(1e9);
    memset(used,0,sizeof(used));
    for(int i=0;i<n;i++){
      cin>>ax[i]>>ay[i]>>bx[i]>>by[i];
      minx=min(minx,min(ax[i],bx[i]));
      miny=min(miny,min(ay[i],by[i]));
    }
    for(int i=0;i<n;i++){
      ax[i]=ax[i]-minx+1;
      bx[i]=bx[i]-minx+1;
      ay[i]=ay[i]-miny+1;
      by[i]=by[i]-miny+1;
      x.push_back(ax[i]);
      x.push_back(bx[i]);
      y.push_back(ay[i]);
      y.push_back(by[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    k=0;
    for(int i=1;i<(int)x.size();i++){
      if(x[i]-x[i-1]==1)X[x[i]]=x[i]+k+1,k++;
      else if(x[i]-x[i-1]>2)X[x[i]]=x[i-1]+k+2,k-=x[i]-(x[i-1]+2);
      else X[x[i]]=x[i]+k;
    }
    k=0;
    for(int i=1;i<(int)y.size();i++){
      if(y[i]-y[i-1]==1)Y[y[i]]=y[i]+k+1,k++;
      else if(y[i]-y[i-1]>2)Y[y[i]]=y[i-1]+k+2,k-=y[i]-(y[i-1]+2);
      else Y[y[i]]=y[i]+k;
    }
    for(int i=0;i<n;i++){
      if(X.find(ax[i])!=X.end())ax[i]=X[ax[i]];
      if(Y.find(ay[i])!=Y.end())ay[i]=Y[ay[i]];
      if(X.find(bx[i])!=X.end())bx[i]=X[bx[i]];
      if(Y.find(by[i])!=Y.end())by[i]=Y[by[i]];
      init(ax[i],ay[i],ax[i],by[i],0);
      init(ax[i],ay[i],bx[i],ay[i],1);
      init(bx[i],by[i],bx[i],ay[i],2);
      init(bx[i],by[i],ax[i],by[i],3);
    }
    ans=0;
    for(int i=0;i<M;i++)
      for(int j=0;j<M;j++)
	if(!used[i][j])ans++,dfs(j,i);
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l;
  cin >> n >> l; 
  vector<string> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  sort(s.begin(), s.end(), [](string a, string b) {
    return a + b < b + a;
  });
  for (int i = 0; i < n; ++i) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
using namespace __gnu_pbds; 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;

typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int N = 3e5 + 123;

int n, m, l;

int a[N];
map < int , int > cnt;
int dp[104][104];
char ch[103][103];
main(){

	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	set <pii> b,w;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> ch[i][j];
	for(int i = 0 ; i < 101;i++)
		for(int j = 0; j < 101;j++)
			dp[i][j]=1e15;
	    		
	if(ch[1][1]=='#')
		dp[1][1] = 1;
	else dp[1][1] = 0;
	for(int i = 1 ;i <= n; i++){
		for(int j = 1;j <= m;j++){	
			if(i + j == 2)
				continue;
			int tmp = 1e15;
			if(ch[i][j] == '.'){
				dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1]);
			}
			else{
				if(ch[i - 1][j] == '.')
					dp[i][j] = dp[i - 1][j] + 1;
				else dp[i][j] = dp[i - 1][j];
				if(ch[i][j - 1] == '.')
					dp[i][j] = min(dp[i][j - 1] + 1,dp[i][j]);
				else dp[i][j] = min(dp[i][j] , dp[i][j - 1]);
			}
		}
	}
	//if(ch[i][j] == '.')
	ret(dp[n][m]);
}
 


Measured memory_bytes: 384
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    A = list(int(_) for _ in input().split())
    dict = {}
    for a in A:
        if a in dict:
            dict[a] += 1
        else:
            dict[a] =1
    sum = 0
    for v in dict.values():
        if v >=2:
           sum += v -1
    if sum%2 == 0:
        ans = len(dict)
    else:
        ans = len(dict) - 1
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 17640
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2612&lang=jp
#define INF 1<<30
#define H 19
#define W 15
typedef long long ll;
typedef pair<int, int> pii;
int ans = INF;
int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
int dy[8] = { 0,-1,-1,-1,0,1,1,1 };

bool check(int x, int y, vector<vector<char>>& masu,int& dir) {
	int nx = x + dx[dir], ny = y + dy[dir];
	if (masu[nx][ny] != 'X')return false;
	while (true) {
		nx += dx[dir]; ny += dy[dir];
		if (masu[nx][ny] == 'X')continue;
		if (masu[nx][ny] == '#')return false;
		if (masu[nx][ny] == '.')return true;
	}
	return false;
}

void erase_move(int&x, int&y, vector<vector<char>>& masu, int& dir) {
	while (true) {
		x += dx[dir]; y += dy[dir];
		if (masu[x][y] == 'X') {
			masu[x][y] = '.';
			continue;
		}
		if (masu[x][y] == '.')return ;
	}
}

void dfs(int x, int y,int cnt,vector<vector<char>>& masu) {
	if (cnt + 1 >= ans) return;
	for (int dir = 0; dir < 8; dir++) {
		if (!check(x, y, masu, dir))continue;
		auto new_masu = masu;
		int new_x = x, new_y = y;
		erase_move(new_x,new_y, new_masu, dir);
		
		if (new_x >= 19) {
			ans = min(ans, cnt + 1);
			return;
		}

		dfs(new_x, new_y, cnt + 1, new_masu);
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	vector<vector<char>> masu(H + 2, vector<char>(W + 2,'#'));
	int sx, sy;
	/* input */
	masu[H + 1][0] = masu[H + 1][W + 1] = '.';
	for (int i = 1; i <= H+1; i++){
		for (int j = 1; j <= W; j++){
			if (i == H + 1) masu[i][j] = '.';
			else {
				cin >> masu[i][j];
				if (masu[i][j] == 'O') { sx = i; sy = j; masu[i][j] = '.'; }
			}
		}
	}

	int f = 0;
	for (int i = sx + 1; i <= H; i++) {
		for (int j = 1; j <= W;j++) {
			if (masu[i][j] == 'X') { f = 0; break; }
			if(j == W)f++;
		}
		if (f == 2) {
			cout << -1 << endl; return 0;
		}
	}

	dfs(sx, sy, 0, masu);
	cout << (ans == INF ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 3188
x,y = map(int,input().split())
res = 0
if x == 1 and y == 1:
    res += 400000
if x == 1:
    res += 300000
if x == 2:
    res += 200000
if x == 3:
    res += 100000
if y == 1:
    res += 300000
if y == 2:
    res += 200000
if y == 3:
    res += 100000
print(res)

Measured memory_bytes: 3064
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    ll n,k;
    cin >> n >> k;
    if(n<k)
    {
        cout<<min(n,abs(n-k))<<endl;
        return 0;
    }
    else
    {
        n%=k;
        cout<<min(n,abs(n-k))<<endl;
    }
}


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

using namespace std;

int main(){
	int t[5];
	for(int i = 0; i < 5; i++){
		cin >> t[i];
	}
	int ans = 100000;
	int a[5] = {0, 1, 2, 3, 4};

    do{
        int Time = 0;
        for(int i = 0; i < 5; i++){
            if (Time % 10 != 0) {
                Time += 10 - (Time % 10);
            }
            Time += t[a[i]];
        }
        ans = min(ans, Time);
    }while(next_permutation(a, a + 5));
	cout << ans << '\n';
	
}

Measured memory_bytes: 256
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

xy.sort(key=lambda x: x[0] + x[1])
mn1, mx1 = xy[0], xy[-1]
xy.sort(key=lambda x: x[0] - x[1])
mn2, mx2 = xy[0], xy[-1]

li = [mn1, mx1, mn2, mx2]
ans = 0
for x1, y1 in li:
    for x2, y2 in li:
        dist = abs(x1 - x2) + abs(y1 - y2)
        ans = max(ans, dist)

print(ans)


Measured memory_bytes: 54832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

bool flag = 1;
char s[N];
vector<int> g[N];
int tot,w,len;
void connect(int fa,int now,int num) {
	if (num <= 1)return;

	if (w % 2 == 0 && w / 2 == num) {
		f(i, 1, num - 1)g[now].push_back(++tot);
	}
	else if (num >= w / 2 + 1) {
		bool yy = 1;
		if (w % 2) {
			rf(i, num - 1, w / 2 + 1)if (s[i] == '1') {
				int tmp = w - tot - i;
				f(i, 1, tmp) {
					g[now].push_back(++tot);
				}
				g[now].push_back(++tot);
				connect(now, tot, i); yy = 0;
				break;
			}
		}
		else {
			rf(i, num - 1, w / 2 )if (s[i] == '1') {
				int tmp = w - tot - i;
				f(i, 1, tmp) {
					g[now].push_back(++tot);
				}
				g[now].push_back(++tot);
				connect(now, tot, i); yy = 0;
				break;
			}
		}
		if (yy) {
			while (tot < w)g[now].push_back(++tot);
		}
	}
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	scanf("%s", s+1);
	w = strlen(s + 1); flag = 1;
	if (s[w] == '1')flag = 0;
	f(i, 1, w)if (s[i] == '1') {
		if (s[w - i] != '1') {
			flag = 0;
		}
	}
	f(i, 1, w / 2)if (s[i] == '1')len++; else break;
	if (len == 0)flag = 0;
	else {
		tot = len + 1;
		f(i, 1, len)g[i].push_back(i + 1);
		connect(len,len+1, w - len);
	}

	if (flag) {
		f(i, 1, w)if (g[i].size()) {
			for (auto it : g[i])
				cout << i << " " << it << '\n';
		}
	}
	else cout << -1;
}

Measured memory_bytes: 26748
N = int(input())
a_li = list(map(int, input().split()))
a_li.sort(reverse=True)
alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0 :
        alice += a_li[i]
    else :
        bob += a_li[i]
print(alice - bob)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
long long abs1(long long a){
	if(a>0)return a;
	else return -a;
}
int main(){
	long long n,a[200051],sum=0,he=0,ans=1111111111111111111;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
}
for(int i=1;i<n;i++){
	he+=a[i];
	ans=min(ans,abs1(sum-2*he));
}
cout<<ans;
} 

Measured memory_bytes: 1792
#include <stdio.h>

typedef struct _Point {
	double x;
	double y;
} Point;

static Point
sub_vector(const Point* a, const Point* b)
{
    Point ret;
    ret.x = a->x - b->x;
    ret.y = a->y - b->y;

    return ret;
}

int
main(void)
{
	char line[80];

	Point a;
	Point b;
	Point c;
	Point p;
	
	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf",
				   &(a.x), &(a.y), &(b.x), &(b.y), &(c.x), &(c.y),
				   &(p.x), &(p.y)) == 8) {

			Point ab = sub_vector(&b, &a);
			Point bp = sub_vector(&p, &b);
			
			Point bc = sub_vector(&c, &b);
			Point cp = sub_vector(&p, &c);
			
			Point ca = sub_vector(&a, &c);
			Point ap = sub_vector(&p, &a);
			
		    double c1 = ab.x * bp.y - ab.y * bp.x;
		    double c2 = bc.x * cp.y - bc.y * cp.x;
		    double c3 = ca.x * ap.y - ca.y * ap.x;
    
        	bool rt = (c1 > 0 && c2 > 0 && c3 > 0) ||
        			  (c1 < 0 && c2 < 0 && c3 < 0);

			printf("%s\n", (rt ? "YES" : "NO"));
		}
	}

	return 0;
}

Measured memory_bytes: 1052
#include<bits/stdc++.h>
using namespace std;
int cnt[109];
int main(){
  int n,sum,ans=10000000;
  int a[109];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=-100;i<=100;i++){
    sum=0;
    for(int j=0;j<n;j++){
      sum+=(a[j]-i)*(a[j]-i);
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return(0);
}


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

int main(){
	int H,W;
	while(1){
		cin >> H >> W ;
		if(H==0&&W==0)return 0;
		for(int i=0;i<W;i++){
			cout << "#" ;
		}
		cout << endl;
		for(int i=0;i<H-2;i++){
			cout << "#" ;
			for(int i=0;i<W-2;i++){
				cout << "." ;
			}
			cout << "#" << endl ;
		}
		for(int i=0;i<W;i++){
			cout << "#" ;
		}
		cout << endl << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
//#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, h, w, S = 1e9 - 1;
int get(int i, int j) {
	if(i%h == 0 && j%w == 0) return S/(h*w-1) + (S%(h*w-1));
	if(i%h == h-1 && j%w == w-1) return -(S + 1);
	return S/(h*w-1);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> h >> w;
	if(!(n%h)&&!(m%w)) return cout << "No", 0;
	cout << "Yes\n";
	ll sm = 0;
	for(int i = 0; i < n; i++, cout << "\n")
		for(int j = 0; j < m; j++) {
			sm += get(i, j);
			cout << get(i, j) << " ";
		}
	assert(sm > 0);
}


Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;

bool g(string s) {
  for(int i = 0; i < sz(s); i++) if(s[i] != s[sz(s)-1-i]) return false;
  return true;
}

void solve() {
  int a, b;
  cin >> a >> b;
  cout << (a*(a-1) + b*(b-1)) / 2 << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Slient_voice

#define ordered_set tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update>
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 10 + 3e3;

LL n, a[MaxN], d1[MaxN][MaxN], b[MaxN], k, d2[MaxN][MaxN], kq;

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i) cin >> a[i] >> b[i];
    for(int i = 1 ; i <= n ; ++i)
    for(int j = 1 ; j <= k ; ++j){
        d1[i][j] = d1[i - 1][j];
        if(j >= a[i]) d1[i][j] = max(d1[i][j], d1[i - 1][j - a[i]] + b[i]);
    }
    for(int i = n ; i > 0 ; --i)
    for(int j = 1 ; j <= k ; ++j){
        d2[i][j] = d2[i + 1][j];
        if(j >= a[i]) d2[i][j] = max(d2[i][j], d2[i + 1][j - a[i]] + b[i]);
    }
    for(int i = 1 ; i <= n ; ++i)
    for(int j = 0 ; j <= k - 1 ; ++j)
    kq = max(kq, d1[i - 1][j] + d2[i + 1][k - 1 - j] + b[i]);
    cout << kq << endl;

    return 0;
}

Measured memory_bytes: 141696
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//using namespace std;

#define MAX 5000000
#define INFTY 1000000001

int L[MAX/2+2], R[MAX/2+2], count, S[MAX];

void merge(int S[], int left, int mid, int right){
  int n1, n2, j=0, k;
  n1 = mid - left;
  n2 = right - mid;
  //L[0...n1], R[0...n2] を生成
  for(int i=0; i<n1; i++) L[i]=S[left+i];
  for(int i=0; i<n2; i++) R[i]=S[mid+i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  int i=0;
  for(k=left; k<right; k++){
    count++;
    if(L[i]<=R[j]) S[k] = L[i++];
    else S[k] = R[j++];
  }
}

void mergeSort(int S[], int left, int right){
  int mid;
  if(left+1<right){
    mid = (left + right)/2;
    mergeSort(S, left, mid);
    mergeSort(S, mid, right);
    merge(S, left, mid, right);
  }
}

int main(){
  int n, i, j;

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

  mergeSort(S, 0, n);

  for(j=0; j<n; j++){
    if(j!=0) printf(" ");
    printf("%d", S[j]);
  }
  printf("\n");

  printf("%d\n", count);
  
  return 0;
}



Measured memory_bytes: 5772
import sys
bbn=1000000007
	
#+++++

		
def main():
	n = int(input())
	sa = input()
	sb = input()
	ll=[]
	i=0
	while i < n:
		if sa[i] == sb[i]:
			ll.append(1)
		else:
			ll.append(2)
			i+=1
		i+=1
	
	val= 3 if ll[0]==1 else 6
	vv=[[2,2],[1,3]]
	for pre, now in zip(ll,ll[1:]):
		val *= vv[pre-1][now-1]
		val = val % bbn
		
	print(val)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
  int a, b;
  cin >> a >> b;
  int res = 0;
  for( int i = a; i <= b; ++i ){
    if( i % 10 == i / 10000 % 10 && i / 10 % 10 == i / 1000 % 10 ) ++res;
  }
  cout << res << endl;
  return 0;
}


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

const int MOD = 1e9+7;
int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	int d;
	std::cin >> d;
	std::vector<std::vector<int> > dp(n,std::vector<int>(d,0));
	int xx = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<s[i]-'0';j++) {
			dp[i][(xx+j)%d] += 1;
		}
		xx = (xx+s[i]-'0')%d;
	}
	if(xx==0) dp[n-1][0]++;
	for(int i=1;i<n;i++) {
		for(int j=0;j<d;j++) {
			for(int k=0;k<10;k++) {
				dp[i][j]+=dp[i-1][((j-k)%d+d)%d];
				dp[i][j]%=MOD;
			}
		}
	}
	int ans = dp[n-1][0];
	std::cout << (ans+MOD-1)%MOD << '\n';

}


Measured memory_bytes: 4608
#include <stdio.h>
int main()
{
    int N,i,j,count=0;
    int a[200000];
    int min;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&a[i]);
    min=a[0];
    for(i=0;i<N;i++){
        if(a[i]<=min){
            count++;
            min=a[i];
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 896
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, m = ril()
if m == n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n), t(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> t[i];
    int ans = 0;
    rep(i, n){
        if(v[i] > t[i]){
            ans += v[i]-t[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 3030000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
//const int mod = 1e9 + 7;
//const int mod = 998244353;
int mod;

ll dp[6010][12010];

int main(){
	int n; cin >> n >> mod;
	int N = 3*n;
	dp[0][N] = 1;
	rep(i,N){
		rep(j,2*N+1){
			(dp[i+1][j+1] += dp[i][j]) %= mod;
			if(j > 0) (dp[i+2][j-1] += dp[i][j] * (i+1)) %= mod;
			(dp[i+3][j] += dp[i][j] * (i+1) * (i+2)) %= mod;
		}
	}
	ll ans = 0;
	REP(j,N,2*N+1){
		ans += dp[N][j];
	}
	ans %= mod;
	cout << ans << "\n";
}

Measured memory_bytes: 566808
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

n, w = map(int, readline().split())
wv = [tuple(map(int, readline().split())) for i in range(n)]
dp = defaultdict(int)
dp[0] = 0

for ww, v in wv:
    for xw, xv in list(dp.items()):
        if ww + xw <= w:
            dp[ww + xw] = max(dp[ww + xw], v + xv)
print(max(dp.values()))


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;



int main(){
    int x[4];
    for(int i = 0; i < 4; i++){
        x[i] = 0;
    }
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        x[a] += 1;
        x[b] += 1;
    }

    int c1 = 0, c2 = 0;
    for(int i = 0; i < 4; i++){
        if(x[i] == 1){
            c1++;
        }
        else if(x[i] == 2){
            c2++;
        }
    }

    if(c1 == 2 && c2 == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }


    return 0;

}


Measured memory_bytes: 256
MOD = 1000000007
N, M = gets.split.map(&:to_i)
a = []
c = []
c[0] = 1
M.times do |i|
  a[i] = gets.to_i
end

i=0
1.upto N do |j|
  if a[i] == j
    c[j] = 0
    i += 1
  else
    if j == 1
      c[j] = 1
    else
      c[j] = (c[j-1] + c[j-2]) % MOD
    end
  end
  if c[j] == 0 and c[j-1] == 0
    # puts "#{c}"
    puts 0
    exit
  end
end

# puts "#{c}"
puts c[N]

Measured memory_bytes: 3400
n = int(input())
a = [0] * n
mx = 0
mx_i = 0
mx2 = 0
for i in range(n):
    aa = int(input())
    a[i] = aa
    if mx < aa:
        mx = aa
        mx_i = i
a[mx_i] = 0
mx2 = max(a)
a[mx_i] = mx

for i, aa in enumerate(a):
    if aa == mx:
        print(mx2)
    else:
        print(mx)


Measured memory_bytes: 12508
//verma_ankit484

#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<vector<ll> > vc;
vector<ll> d;
void dfs(ll v) {
	for(ll i = 0; i < vc[v].size(); i++) {
		if(d[vc[v][i]] != -1) {
			d[v] = max(d[v], 1+d[vc[v][i]]);
		}
		else {
			dfs(vc[v][i]);
			d[v] = max(d[v], 1+d[vc[v][i]]);
		}
	}
	d[v] = max(d[v], 0ll);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef AV
	freopen("int.txt", "r", stdin);
	#endif
	ll n, m;
	cin >> n >> m;
	vc.resize(n+1);
	d.assign(n+1, -1);
	for(ll i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		vc[a].push_back(b);
	}
	for(ll i = 1; i <= n; i++) {
		if(d[i] == -1) dfs(i);
	}
	ll mx = 0;/*
	for(ll i = 0; i <= n; i++) {
		cout << d[i] << ' ';
	}
	cout << endl;*/
	for(ll i = 1; i <= n; i++) {
		mx = max(mx, d[i]);
	}
	cout << mx << '\n';
	return 0;
}


Measured memory_bytes: 7936
import sys

L = []
"""
while True:
    l = input()
    if l == "":
        break
    else:
        L.append(list(map(int,l.split())))
        print(L)
"""
N,K = list(map(int,input().split()))

#print(N,K)

for a in range(2 * K):
    n = list(map(int,input().split()))
    L.append(n)

#print("End",L)

Num = list(range(1, N + 1, 1))
#print(Num)
new_L = L[1::2]
#print(new_L)

new_LL = sum(new_L, [])
for n in new_LL:
    if n in Num:
        Num.remove(n)

print(len(Num))

Measured memory_bytes: 9156
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

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;

// <editor-fold>

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// vector出力
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}
// vector入力
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
struct Pos {
  int x, y;
};
// 任意の個数の変数をスペース区切りで出力します
void dump() {
  cout << endl;
}
template <class Head, class... Tail>
void dump(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) != 0)
    cout << " ";
  dump(std::move(tail)...);
}
// </editor-fold>

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b - a) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b;
    cin >> a >> b;
    string op;
    if(a == b) op = "==";
    else if(a > b) op = '>';
    else op = '<';
    cout << "a " << op << " b" << endl;
}


Measured memory_bytes: 3148
#include<iostream>
#include<cstdio>
#include<algorithm>


using namespace std;

const int INF=1e+8;

typedef struct{
	int start,end;
}jikan;

int jikanShori(int h,int m,int s){
	return h*3600+m*60+s;
}


//比較関数
int comp(const void *c1,const void *c2){
	jikan jikan1=*(jikan *)c1;
	jikan jikan2=*(jikan *)c2;
	
	int tmp1=jikan1.end;
	int tmp2=jikan2.end;
	
	return tmp1-tmp2;
}

int main(){
	int n,cnt,ans;
	int h,m,s;
	jikan interval[10001];
	
	
	while(cin>>n,n){
		cnt=1;
		ans=1;
		for(int i=0;i<10001;i++){
			interval[i].start=INF;
			interval[i].end=INF;
		}
		
		for(int i=0;i<n;i++){
			scanf("%d:%d:%d",&h,&m,&s);
			interval[i].start=jikanShori(h,m,s);
			scanf("%d:%d:%d",&h,&m,&s);
			interval[i].end=jikanShori(h,m,s);
		}
		
		qsort(interval,n+1,sizeof(jikan),comp);
		
		for(int i=0;i<n;i++){
			cnt=1;
			for(int j=i+1;j<n;j++){
				if(interval[i].end>interval[j].start){
					cnt++;
				}
			}
			ans=max(ans,cnt);
		}
		
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1428
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var a = abcd[0];
            var b = abcd[1];
            var c = abcd[2];
            var d = abcd[3];
            long counta = 0;
            long countb = 0;
            var aaa1 = (a - 1) / c;
            var aaa2 = (a - 1) / d;
            var aaa3 = (a - 1) / ((c * d) / Gcd(c, d));
            counta = a - 1 - (aaa1 + aaa2 - aaa3);
            var bbb1 = b / c;
            var bbb2 = b / d;
            var bbb3 = b / ((c * d) / Gcd(c, d));
            countb = b - (bbb1 + bbb2 - bbb3);
            Console.WriteLine(countb - counta);
        }
        public static long Gcd(long a, long b)
        {
            return a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        }

        private static long GcdRecursive(long a, long b)
        {
            return b == 0 ? a : GcdRecursive(b, a % b);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n=s.length();
    if (s[n-1]=='s') s+="es";
    else s+="s";
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3632
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end

def max(a, b)
  a > b ? a : b
end

def dfs(i)
  return if @used[i]
  @used[i] = true
  @graph[i].each do |n|
    dfs(n)
  end
  @v << i
end

def tsort()
  N.times do |i|
    dfs(i)
  end
  @v.reverse
end

N, M = gets.split.map(&:to_i)
XY = M.times.map{gets.split.map(&:to_i)}

@used = Array.new(N, false)
@v = []
@graph = Array.new(N){[]}
M.times do |i|
  x, y = XY[i]
  @graph[x - 1] << y - 1
end

topo = tsort()
dp = Array.new(N, 0)
topo.each do |i|
  @graph[i].each do |j|
    dp[j] = max(dp[j], dp[i] + 1)
  end
end

puts dp.max

Measured memory_bytes: 107588
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, M = (int(_) for _ in input().split())
    if N==1 and M==1:
        print(1)
        return
    if N==1 or M==1:
        print(N*M - 2)
        return 
    print((N-2)*(M-2))
    
if __name__ == '__main__':
    main()


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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    ll n;
    cin >> n;
    vll a(n);
    vllll x(n), y(n);
    rep(i, 0, n)
    {
        cin >> a[i];
        rep(j, 0, a[i])
        {
            ll t1, t2;
            cin >> t1 >> t2;
            t1--;
            x[i].push_back(t1);
            y[i].push_back(t2);
        }
    }

    ll m = 0;
    rep(i, 1, 1 << n)
    {
        bool f = true;
        ll cnt = 0;
        rep(j, 0, n)
        {
            cnt += ((i >> j) & 1);
            if ((i >> j) & 1)
            {
                rep(k, 0, a[j])
                {
                    if (y[j][k] != ((i >> x[j][k]) & 1))
                        f = false;
                }
            }
        }
        if (f)
            m = max(m, cnt);
    }
    cout << m << endl;
}

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

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


int main(){
    vector<int>A(5);
    rep(i,5){
        cin >> A.at(i);
        if(A.at(i)==0){
            cout << i+1 << endl;
            break;
        }
    }

    
}

Measured memory_bytes: 3540
N , T = map(int, input().split())
ans = 0
c_l = []
for i in range(N):
	c, t = map(int, input().split())
	if t <= T:
		c_l.append(c)
if len(c_l) ==0:
	ans = 'TLE'
else:
	ans = min(c_l)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

double d;
int main(int argc,char const* argv[])
{
  cin >> d;
  double ans=d*sqrt(2);
  for(int x=1;x<=10;x++)
    {
      if(d*d-x*x>=0)
	{
	  double y=sqrt(max(0.0,d*d-x*x));
	  ans=max(ans,x+(y<1.0 ? 1.0 : y) );
	}
    }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}



Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r=0,b=0,i,n;
	char c;
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		c=getchar();
		if(c=='R')
			r++;
		else
			b++;
	}
	if(r>b)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
import Data.List

main = interact $ unlines . map (show' . mspf . read) . init . lines
 where show' (n,ns) = show n ++ ": " ++ unwords (map show ns)

mspf n = (n, sort (nub (msd n)))

msd n = msd' n [] msprimes
 where
  msd' n' ds pps@(p:ps)
   | p > n = ds
   | mod n' p /= 0 = msd' n' ds ps
   | otherwise = msd' n' ds ps ++ msd' (div n' p) (p:ds) pps

msprimes = 6 : 8 : union [13,20..] [15,22..]
 where
  union xxs@(x:xs) yys@(y:ys)
   | x<=y = if ismsp x then x : union xs yys else union xs yys
   | x>y = if ismsp y then y : union xxs ys else union xxs ys
  ismsp n = null [i | i <- takeWhile (\x -> x*x <= n) msprimes, mod n i == 0]

Measured memory_bytes: 9124
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <utility>
#include <random>
#include <chrono>

using namespace std;

#define ll long long

int r;

int main()
{
    scanf("%d", &r);
    double ans = 3.14159265358979323 * 2.0 * (double)r;
    printf("%.10f", ans);
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    int ans = 0;
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<N;i++){
        if(i%2==0){
            ans += a.at(i);
        }
        else ans -= a.at(i);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	string s;
	cin >> s;
	int a = -1, z = 0;
	REP(i, SIZE(s))
	{
		if (a < 0 && s[i] == 'A')
			a = i;
		if (s[i] == 'Z')
			z = i;
	}
	print(z - a + 1);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

int main() {
    string str;
    cin>>str;
    
    if(str=="SUN")cout<<7<<endl;
    if(str=="MON")cout<<6<<endl;
    if(str=="TUE")cout<<5<<endl;
    if(str=="WED")cout<<4<<endl;
    if(str=="THU")cout<<3<<endl;
    if(str=="FRI")cout<<2<<endl;
    if(str=="SAT")cout<<1<<endl;  

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
long long A,B,C,D;
cin >> A >> B >> C >> D;
  long long ans = C / B;
  if( C % B != 0){
    ans++;
  }
   long long ANZ = A / D;
  if( A % D != 0){
    ANZ++;
  }
  if( ans <= ANZ ){
    cout <<"Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

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

	int a, b;
	cin >> a >> b;

	for (int i = 0; i <= 1e6; ++i) {
		if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
			cout << i << '\n';
			return 0;
		}
	}
	cout << "-1\n";
}


Measured memory_bytes: 256