akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 10001
#define MO 998244353
int fac[MAXN],inv[MAXN],x,y,n,dp[MAXN][MAXN];
char a[MAXN],b[MAXN];
int C(int n,int m)
{
	return 1LL*fac[n]*inv[m]%MO*inv[n-m]%MO;
}
void Pre()
{
	fac[0]=inv[1]=inv[0]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=1LL*fac[i-1]*i%MO;
	for(int i=2;i<MAXN;i++)
		inv[i]=1LL*(MO-MO/i)*inv[MO%i]%MO;
	for(int i=1;i<MAXN;i++)
		inv[i]=1LL*inv[i]*inv[i-1]%MO;
}
int main()
{
	Pre();
	scanf("%s%s",a,b);
	n=strlen(a);
	for(int i=0;i<n;i++)
		if(a[i]=='1'||b[i]=='1')
		{
			if(a[i]=='1'&&b[i]=='1') x++;
			else y++;
		}
	y/=2;
	dp[0][0]=1;
	for(int i=1;i<=y;i++) dp[0][i]=1LL*fac[i]*fac[i]%MO;
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++)
			dp[i][j]=1LL*(1LL*dp[i-1][j]*i%MO+1LL*dp[i][j-1]*j%MO)*j%MO;
	int ans=0;
	for(int i=0;i<=x;i++)
		(ans+=1LL*dp[x-i][y]*fac[i]%MO*fac[i]%MO*C(x,i)%MO*C(x+y,i)%MO)%=MO;
	printf("%d\n",ans);
}

Measured memory_bytes: 387712
def search_prev(X, P):
    while X >= min(P):
        if not P.__contains__(X):
            return X
        else:
            X -= 1
    return X


def search_next(X, P):
    while X <= max(P):
        if not P.__contains__(X):
            return X
        else:
            X += 1
    return X


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

    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))

    xp = search_prev(X, P)
    dxp = X - xp
    xn = search_next(X, P)
    dxn = xn - X

    if dxp <= dxn:
        print(xp)
    else:
        print(xn)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9152
S = input()
odd = ['R','U','D']
even = ['L','U','D']

odd_s = S[0::2]
even_s = S[1::2]
o,e = True,True
for i in odd_s:
    if i not in odd:
        o = False
for i in even_s:
    if i not in even:
        e = False
        
if o and e:
    print("Yes")
else:
    print("No")


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    cin >> n;
    rep(q, n){
        vii v; vbb b;
        rep(i, 9){
            vi r; vb l;
            rep(j, 9){
                int m; cin >> m; r.pb(m); l.pb(true);
            }
            v.pb(r); b.pb(l);
        }
        rep(i, 9){
            pair<bool, pair<int, int> > p[11];
            rep(j, 11) p[i].first = false;
            rep(j, 9){
                if(!p[v[i][j]].first){p[v[i][j]].first = true; p[v[i][j]].second = mp(i, j);}
                else {b[i][j] = false; pii x = p[v[i][j]].second; b[x.first][x.second] = false;}
            }
        }
        rep(i, 9){
            pair<bool, pair<int, int> > p[11];
            rep(j, 11) p[j].first = false;
            rep(j, 9){
                if(!p[v[j][i]].first){p[v[j][i]].first = true; p[v[j][i]].second = mp(j, i);}
                else {b[j][i] = false; pii x = p[v[j][i]].second; b[x.first][x.second] = false;}
            }
        }
        rep(i, 3)rep(j, 3){
            pair<bool, pair<int, int> > p[11];
            rep(l, 11) p[l].first = false;
            rep(k, 3)rep(l, 3){
                if(!p[v[i*3+k][j*3+l]].first){p[v[i*3+k][j*3+l]].first = true; p[v[i*3+k][j*3+l]].second = mp(i*3+k, j*3+l);}
                else {b[i*3+k][j*3+l] = false; pii x = p[v[i*3+k][j*3+l]].second; b[x.first][x.second] = false;  }
            }
        }

        rep(i, 9){
            rep(j, 9){
                cout << (b[i][j]?" ":"*") << v[i][j];
            }
            cout << endl;
        }
        if(q != n-1) cout << endl;
    }
}

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

int main() {
    int n, A[10001], q, T[501], key;
    int c = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }

    for (int i = 0; i < q; i++) {
        key = T[i];
        for (int j = 0; j < n; j++) {
            if (A[j] == key) {
                c++;
                break;
            }
        }
    }
    cout << c << endl;
}



Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll A, B, C, ans;

int main()
{
  std::cin >> A >> B >> C;

  while( true )
  {
    if( (A&1) || (B&1) || (C&1) )
      break;

    if( A == B && B == C )
    {
      std::cout << -1 << std::endl;

      return 0;
    }

    ll tA = A, tB = B, tC = C;

    A = (tB+tC)/2, B = (tA+tC)/2, C = (tA+tB)/2;

    ++ans;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int n;
int a[10100];

int main(){
  std::cin >> n;
  int res = 0;
  rep(i,1,n+1){
    std::cin >> a[i];
    res+=a[i]-1;
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        if(n<(n-s.replaceAll("R", "").length())*2){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
for x in b:
    for i in range(3):
        for j in range(3):
            if x == A[i][j]:
                A[i][j] = '*'
if ( A[0][0]==A[0][1]==A[0][2]=='*'
        or A[1][0]==A[1][1]==A[1][2]=='*'
        or A[2][0]==A[2][1]==A[2][2]=='*'
        or A[0][0]==A[1][0]==A[2][0]=='*'
        or A[0][1]==A[1][1]==A[2][1]=='*'
        or A[0][2]==A[1][2]==A[2][2]=='*'
        or A[0][0]==A[1][1]==A[2][2]=='*'
        or A[0][2]==A[1][1]==A[2][0]=='*' ):
            print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        task_deque = deque()
        _input = sys.stdin.readlines()

        for i in range(array_length):
            l_arg = _input[i].split()
            action = l_arg[0]
            if len(l_arg) > 1:
                value = l_arg[-1]
            # print(action, 'v', value)

            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                try:
                    task_deque.remove(value)
                except Exception as e:
                    pass
        print(" ".join(task_deque))


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Measured memory_bytes: 214216
#include<cstdio>
int a,b;
char s[1001][1001];
int main(){
	scanf("%d%d",&a,&b);
	a--;
	b--;
	printf("100 100\n");
	for(int i=1;i<=100;i++)
		for(int j=1;j<=100;j++)
			if (i<=50)s[i][j]='#';
			else s[i][j]='.';
	for(int i=1;i<=100;i+=2)
		for(int j=1;j<=100;j+=2)
			if (a){
				s[i][j]='.';
				a--;
			}
	for(int i=100;i;i-=2)
		for(int j=100;j;j-=2)
			if (b){
				s[i][j]='#';
				b--;
			}
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++)printf("%c",s[i][j]);
		printf("\n");
	}
} 

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
    int x; cin >> x;
    for (int i = x; i < 1000000; i++) {
        bool p = true;
        for (int j = 2; j < x; j++) {
            if (i % j == 0) p = false;
        }
        if (p) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    ll A[N];
    rep(i, N) cin >> A[i];
    sort(A, A+N, greater<ll>());
    ll ans = P;
    ll sum = 0;
    rep2(i, P, N-1){
        if(A[i]+M < A[P-1]) break;
        ll d = A[i]+M-A[P-1];
        if(M*(P-1+N-i)+sum+d*(i-P+1) >= M*V){ans++, sum += A[P-1]-A[i];}
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int a, b;
    cin >> a >> b;
    if (a + b >= 10) {
        print("error");
    } else {
        print(a + b);
    }

    return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
ans=0

if a <= c:
  if b <= c:
    pass
  elif b <= d:
    ans = b-c
  else:
    ans = d-c
else:
  if d <= a:
    pass
  elif d <= b:
    ans = d-a
  else:
    ans = b-a
print(ans)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//BST(Binary Search Tree):二分探索木

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *NIL, *root;

//挿入操作
void insert(int key) {
    Node *x, *y, *z;
    
    // initialize
    z = new Node;  // 新しい要素のメモリ確保
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    y = NIL;
    x = root;

    // rootから適切な位置まで二分木をたどる
    while (x != NIL) {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }

    // 新しい要素を配置する場所を決定
    z->parent = y;  
    if (y == NIL) root = z;  // もともと木が存在しなかった場合
    else if (z->key < y->key) y->left = z;
    else y->right = z;    
}

//探索
Node* find(int key) {
  Node *x;

  x = root;
  while (x != NIL && x->key != key) {
    if (key < x->key) x = x->left;
    else x = x->right;
  }
  
  return x;        
}

// 先行順巡回
void preorder(Node* node) {
    if (node == NIL) return;
    cout << " " << node->key;
    if (node->left != NIL) preorder(node->left);
    if (node->right != NIL) preorder(node->right); 
}

// 中間順巡回
void inorder(Node* node) {
    if (node == NIL) return;
    if (node->left != NIL) inorder(node->left);
    cout << " " << node->key;
    if (node->right != NIL) inorder(node->right);
}

void print() {
    inorder(root);
    cout << endl;
    preorder(root);
    cout << endl;
}

//AOJ Binary Search Tree I, Binary Search Tree II, 

int main() {
    int i, m, key;
    string command;

    cin >> m;
    for (i = 0; i < m; i++) {
        cin >> command;
        if (command == "insert") {
            cin >> key;
            insert(key);
        }
        else if(command == "find") {
            cin >> key;
            if (find(key) != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        }
        else print();
    }

    return 0;
}


Measured memory_bytes: 21916
#include <iostream>

int N, M;

int main() {
  using namespace std;
  cin >> N >> M;
  if (N == 1 || M == 1) {
    int t = N * M;
    if (t == 1) cout << 1;
    else cout << (t - 2);
  } else {
    cout << (N - 2) * (long long)(M - 2);
  }

  cout << endl;
  return 0;
}


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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

const int N = 1e5;

int p[N+1];

void init() {
  for (int i = 0; i <= N; i++) {
    p[i] = i;
  }
}

int par(int x) {
  return p[x] == x ? x : p[x] = par(p[x]);
}

void unite(int a, int b) {
  a = par(a);
  b = par(b);
  if (a != b) {
    p[b] = a;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<pair<int, int>> X(n), Y(n);
  for (int i = 0; i < n; i++) {
    cin >> X[i].first >> Y[i].first;
    X[i].second = Y[i].second = i;
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  
  vector<pair<int, pair<int, int>>> e;
  
  for (int i = 1; i < n; i++) {
    e.push_back({X[i].first - X[i-1].first, {X[i].second, X[i-1].second}});
    e.push_back({Y[i].first - Y[i-1].first, {Y[i].second, Y[i-1].second}});
  }
  
  sort(e.begin(), e.end());
  //db(e);
  init();
  
  ll ans = 0, cnt = 0;
  for (int i = 0; i < (int)e.size(); i++) {
    if (par(e[i].second.first) != par(e[i].second.second)) {
      unite(e[i].second.first, e[i].second.second);
      ans += e[i].first;
      cnt++;
      if (cnt == n-1) break;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8784
n = int(input())
red =[]
blue =[]
for i in range(n):
    x, y = map(int, input().split(' '))
    red.append(x + y*1000)
for i in range(n):
    x, y = map(int, input().split(' '))
    blue.append(x*1000 + y)
red.sort()
blue.sort()
ans = 0
red = red[::-1]
for b in blue:
    flag = True
    for r in red:
        if (r%1000 < b//1000) and (r//1000 < b%1000) and flag:
            flag = False
            red[red.index(r)]=9999999999
            ans +=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void mx_self(ll &a,ll b){
	a=max(a,b);}
int main(){
	ll an=0,n,w;cin>>n>>w;vector<ll> dp(w+1);
	for(int u=0;u<n;u++){
		ll wei,val;cin>>wei>>val;
		for(int pre_wei=w-wei;pre_wei>=0;pre_wei--){
			mx_self(dp[pre_wei+wei],dp[pre_wei]+val);
		}
	}
	for(ll x:dp)an=max(an,x);
	cout<<an;
}


Measured memory_bytes: 3964
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,m,A[101],s;
int main(void){
	register int i;
	n=read(),m=read();
	for(i=1;i<=m;++i)
		A[i]=read(),s+=A[i]&1;
	if(s>2)
		return puts("Impossible"),0;
	if(s<=2){
		if(s>=1&&!(A[i]&1))	
			for(i=2;i<=m;++i)
				if(A[i]&1){
					swap(A[1],A[i]);
					break;
				}
		if(s==2&&!(A[m]&1))	
			for(i=2;i<m;++i)
				if(A[i]&1){
					swap(A[m],A[i]);
					break;
				}
	}
	for(i=1;i<=m;++i)
		printf("%d ",A[i]);
	putchar('\n');
	if(m==1){
		if(A[1]==1)
			printf("%d\n%d",1,1);
		else printf("%d\n%d %d",2,1,A[1]-1);
		return 0;
	}
	if(A[m]==1){
		printf("%d\n",m-1);
		printf("%d ",A[1]+1);
		for(i=2;i<m;++i)
			printf("%d ",A[i]);
		return 0;
	}
	printf("%d\n",m);
	printf("%d ",A[1]+1);
	for(i=2;i<m;++i)
		printf("%d ",A[i]);
	printf("%d ",A[m]-1);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 500005
#define M 100000000
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

void solve()
{

    string s,t;
    cin>>s>>t;
    lli s1=sz(s),s2=sz(t);
    lli ans=s2;
    for(lli i=0;i<s1;i++)
    {
        if((i+s2-1)<s1)
        {
            lli ct=0;
            for(lli j=i,k=0;k<s2;k++,j++)
            {
                if(s[j]!=t[k])
                    ct++;
            }
            ans=min(ans,ct);
        }
    }


    cout<<ans;
}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (a == b) {
        for (int i = 0; i < a; ++i)
            cout << b;
    }
    else {
        if (a < b)
            swap(a, b);
        for (int i = 0; i < a; ++i)
            cout << b;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main(){
  ll a,v;cin>>a>>v;
  ll b,w;cin>>b>>w;
  ll t;cin>>t;
  if(v<=w){
    cout<<"NO"<<endl;
    return 0;
  }
  if(abs(b-a)>t*(v-w)){
    cout<<"NO"<<endl;
    return 0;
  }
  cout<<"YES"<<endl;
  return 0;
}
  

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

int main(){
    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2) {
        cout << - 1 << endl;
        exit(0);
    }
    int m = (n - 1) * (n - 2) / 2 - k;
    cout << n - 1 + m << endl;
    for (int i = 2; i <= n; i++) cout << 1 << " " << i << endl;
    int x = 2; int y = 3;
    while (m){
        cout << x << " " << y << endl;
        if (y == n){
            x++; y = x + 1;
        }
        else y++;
        m--;
    }
}

Measured memory_bytes: 256
import sys
import numpy as np 

n = int(input())
h = []
for _ in range(n):
    a, b, c = map(int, input().split())
    h.append([a, b, c])

x, y, z = 0, 0, 0
for a, b, c in h:
    x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c

print(max(x, y, z))

Measured memory_bytes: 31672
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int n,m;
vector<int> G[1000];
bool input(){
    scanf("%d%d",&n,&m);
    if(n == 0 && m == 0)
        return false;
    REP(i,n)
        G[i].clear();

    REP(i,m){
        int a,b;
        scanf("%d%d",&a,&b);

        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }
    return true;
}

bool used[1000];

void solve(){
    REP(i,n)
        used[i] = false;
    used[0] = true;
    queue<int> que;

    int c = 0;
    REP(i,G[0].size()){
        que.push(G[0][i]);
        used[G[0][i]] = true;
        c++;
    }
    while(!que.empty()){
        int d = que.front();
        que.pop();
        REP(i,G[d].size()){
            if(!used[G[d][i]]){
                c++;
                used[G[d][i]] = true;
            }
        }
    }
    printf("%d\n",c);
}

int main(){
    while(input())
    solve();
}

Measured memory_bytes: 3384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder_ABC140
{
    class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var a = cin.ReadIntArray(n);
            var b = cin.ReadIntArray(n);
            var c = cin.ReadIntArray(n-1);
            var score = 0;
            for (int i = 0; i < n; i++)
            {
                score += b[a[i]-1];
                if (i < n - 1)
                {
                    if (a[i + 1] == a[i] + 1)
                    {
                        score += c[a[i]-1];

                    }
                }
            }
            WriteLine($"{score}");
        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
;; E - Handshake

(defun main ()
  (let* ((N (read)) ; 人数
         (M (read)) ; 握手回数
         (A (loop repeat N collect (read)))) ; ゲストのパワー
    (princ (solve N M A))
    (fresh-line)))

(defparameter *max-A* (expt 10 5))

(defun solve (N M A-list)
  (setf A-list (sort A-list #'<)) ; 昇順
  (let ((A (make-array N :initial-contents A-list)) ; 配列化
        (suffix-sum (make-array (1+ N) :initial-element 0)))
    ; 以降の要素の総和
    (loop for i from (1- N) downto 0
      do (setf (aref suffix-sum i)
               (+ (aref suffix-sum (1+ i)) (aref A i))))
    (labels
      ((find-guest (h)
         "幸福度 h 以上の最小のゲスト"
         (bin-search 0 N #'(lambda (x) (< (aref A x) h))))
       (count-handshake (h)
         "幸福度 h 以上の握手の個数"
         (loop for x across A
               ; xと同時に握手すると幸福度 h 以上になる最小のゲスト
               for y = (find-guest (- h x))
               sum (- N y))) ; y以降の人数
       (sum-handshake (h)
         "幸福度 h 以上の握手の総幸福度"
         (loop for x across A
               for y = (find-guest (- h x))
               sum (+ (* (- N y) x) (aref suffix-sum y)))))
      ; 幸福度 h 以上の握手の個数が M 以下になる最小の h
      (let ((h (bin-search 2 (1+ (* 2 *max-A*))
                 #'(lambda (h) (> (count-handshake h) M)))))
        (+ (sum-handshake h) ; 幸福度 h 以上の握手の総幸福度
           ; 残りの握手は幸福度 h - 1
           (* (- M (count-handshake h)) (1- h)))))))

(defun bin-search (low high <-than-target)
  "low: 探索範囲の左端, high: 探索範囲の右端+1,
   (<-than-target i)が偽になる最小のiを返す."
  (if (>= low high)
      low
      (let* ((mid (+ low (ash (- high low) -1))))
        (if (funcall <-than-target mid)
            (bin-search (1+ mid) high <-than-target)
            (bin-search low mid <-than-target)))))

(main)


Measured memory_bytes: 61928
#include<stdio.h>
int main(void)
{
	int X,A,B;
	scanf("%d%d%d",&X,&A,&B);
	if(B<=X) printf("delicious\n");
	if(X+A>=B&&B>A)printf("safe\n");
	if(X+A<B) printf("dangerous\n");
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
A = gets.split.map(&:to_i)

q = gets.to_i
m = gets.split.map(&:to_i)

def solve(i, m)
  if (m == 0)
    return true
  elsif (i >= N)
    return false
  end

  # A[i]を使用するか、しないか
  (solve(i + 1, m) || solve(i + 1, m - A[i]));
end

m.each do |mi|
  puts solve(0, mi) ? 'yes' : 'no'
end



Measured memory_bytes: 6868
// That was so silly...
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long ll; 

const int Maxv = 200010; 

ll sum[Maxv], ans = 1ll << 60, res; 
int n, m; 

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

    for (int i = 1; i <= n; i++) {
        scanf("%lld", &sum[i]); 
        sum[i] += sum[i - 1]; 
    }

    for (int i = 1; i <= n; i++) {
        res = 1ll * (i + n) * m; 

        for (int j = n, tmp = 0; j > 0; j -= i, tmp++) {
            ll val = (tmp ? (tmp << 1) + 3 : 5) * (sum[j] - sum[std::max(j - i, 0)]); 
            res += val;

            if (res >= ans) break; 
        }

        ans = std::min(ans, res); 
    }

    printf("%lld\n", ans); 

    return 0; 
}

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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd<<11)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

//化相等关系为不等关系，dp[i][j]表示右端点至多为i的时候，和为j的子序列左端点的和
//滚动掉一维，

const int MAXN = 3'005;

const int MOD = 998244353;

void modadd(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int modmul(int a, int b){return 1ll*a*b%MOD;}

int dp[MAXN];

int n, s;

int A[MAXN];

int main(){
    n=read();s=read();
    for(int i=1;i<=n;++i)A[i]=read();

    int ans=0;

    for(int i=1;i<=n;++i){
        int t=dp[s];
        for(int j=s;j>=1;--j){//反向，不然会更新错误
            if(j==A[i])modadd(dp[j],i);
            if(j>A[i]){
                modadd(dp[j],dp[j-A[i]]);
            }
        }
        modadd(ans,modmul(dp[s]-t+MOD,n-i+1));//差分表示右端点恰好为i的时候，其和为s的多端点的和
    }
    cout<<ans;

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d)
    cout << "Left" << endl;
  else if (a+b == c+d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char S[4];
	char mem[4];
	
	gets(S);
	
	if(S[2] != '\0'){
		mem[0]=S[2];
		mem[1]=S[1];
		mem[2]=S[0];
		mem[3]='\0';
		
		puts(mem);
	}else{
		puts(S);
	}
	
	return 0;
}

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

int main() {
  int n, a, f = 0, o = 0;
  cin >> n;
  vector<int> c(8);
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(a >= 3200)
      f++;
    else
      c[a / 400]++;
  }
  for(auto x : c)
    if(x)
      o++;
  if(!f)
    cout << o << ' ' << o << endl;
  else
    cout << max(o, 1) << ' ' << o + f << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> h(n);
  for(int i = 0;i < n;i++)cin >> h[i];

  sort(h.begin(),h.end());

  ll ans = 0;
  for(int i = 0;i < n;i++){
    if(i < n - k)ans += h[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[105];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int res=0;
	for(int i=0;i<n;i++){
		int mini=i;
		for(int j=i;j<n;j++)
			if(a[j]<a[mini])mini=j;
		if(i!=mini)res++;
		swap(a[i],a[mini]);
	}
	for(int i=0;i<n-1;i++)cout<<a[i]<<' ';cout<<a[n-1]<<endl;
	cout<<res<<endl;
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

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

	string s;
	cin >> s;

	map<ll, ll> mp;
	mp[0] = 1;

	reverse(all(s));

	ll now = 0, ten = 1;
	for (auto si : s) {
		now = (now + (si - '0') * ten) % 2019;
		ten *= 10;
		ten %= 2019;
		mp[now]++;
	}

	ll ans = 0;
	for (auto m : mp) {
		ans += m.second * (m.second - 1) / 2;	//mC2
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 3800
package main

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

var Parts = []string{"dream", "dreamer", "erase", "eraser"}

func main() {
	S := ReadString()
	dp := make([]bool, len(S)+1)
	dp[0] = true
	for i := 0; i < len(S); i++ {
		if !dp[i] {
			continue
		}
		for _, part := range Parts {
			if i+len(part) <= len(S) && S[i:i+len(part)] == part {
				dp[i+len(part)] = true
			}
		}
	}
	if dp[len(S)] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


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

int main(){

    int i, j, k, m, d, cnt = 0;
    cin >> m >> d;
    int d1 = d % 10, d10 = d / 10;
    // cout << d1 << " " << d10 <<endl;


    for(i = 1; i <= m; i++ ){
        for(j = 1; j <= d; j++){            
            int d1 = j % 10, d10 = j / 10;
            if(d1 < 2 || d10 < 2) continue;
            if(d1 * d10 == i) cnt++;
        }
    }

    cout << cnt <<endl;
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  if(n/100 == n%10)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int main(){
      int a,b,c,n;
      while(cin>>a>>b>>c&&a&&b&&c){
            cin>>n;
            int x[1000],y[1000],z[1000],r[1000];
            int f[a+b+c];
            REP(i,a+b+c)f[i]=2;
            int k=0;
            REP(i,n){
                  cin>>x[k]>>y[k]>>z[k]>>r[k];x[k]--;y[k]--;z[k]--;
                  if(r[k]==1){
                        f[x[k]]=f[y[k]]=f[z[k]]=1;
                  }else k++;
            }
            bool update=true;
            while(update){
                  update=false;
                  REP(i,k){
                        if(f[x[i]]==1&&f[y[i]]==1&&f[z[i]]==2){f[z[i]]=0;update=true;}
                        else if(f[x[i]]==1&&f[y[i]]==2&&f[z[i]]==1){f[y[i]]=0;update=true;}
                        else if(f[x[i]]==2&&f[y[i]]==1&&f[z[i]]==1){f[x[i]]=0;update=true;}
                  }
            }
            REP(i,a+b+c)cout<<f[i]<<endl;
      }
}

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


int main(){
  string S;
  cin >> S;
  int l = S.size();

  int64_t ans = 0;
  for (int i=0; i<(1<<(l-1)); i++){ // bitで全探索
    int64_t cur = S[0]-'0';

    for (int j=0; j<l-1; j++){
      if (i & (1<<j)) { 
        ans += cur;
        cur = S[j+1]-'0';
      } else {
        cur = 10 * cur + (S[j+1]-'0');
      }
    }
    ans += cur;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int b;
	int a[10] = {0};

	while (cin >> b) {
		if (b == 0) {
			for (int i = 9; i >= 0; i--) {
				if (a[i] != 0) {
					cout << a[i] << endl;
					a[i] = 0;
					break;
				}
			}
		} else {
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0) {
					a[i] = b;
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,5)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass




s=input()
if s[-1]=="s":
    print(s+"es")
else:
    print(s+"s")






endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")


Measured memory_bytes: 10524
C_list=[]
for _ in range(3):
    C_list.append(list(map(int,input().split())))

from itertools import combinations

ans='Yes'
for r in combinations(range(3),2):
    for c in combinations(range(3),2):
        if C_list[r[0]][c[0]]-C_list[r[1]][c[0]] != C_list[r[0]][c[1]]-C_list[r[1]][c[1]]:
            ans='No'
            break
        if C_list[r[0]][c[0]]-C_list[r[0]][c[1]] != C_list[r[1]][c[0]]-C_list[r[1]][c[1]]:
            ans='No'
            break
print(ans)

Measured memory_bytes: 62144
import java.util.Scanner;

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 - 1; i++) {
			a[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 0; i <= n - 3; i++) {
			if (a[i] < a[i + 1] && a[i + 1] < a[i + 2]) {
				ans++;
			}

			if (a[i] > a[i + 1] && a[i + 1] > a[i + 2]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

#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(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    unsigned long long N, M;
    cin >> N >> M;

    unsigned long long ans;
    if (N >= 3 && M >= 3) {
        ans = (N - 2) * (M - 2);
    } else {
        int x, y;
        x = min(N, M);
        y = max(N, M);

        if (y == 1)
            ans = 1;
        else if (x == 2)
            ans = 0;
        else {
            ans = x * (y - 2);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#https://linus-mk.hatenablog.com/entry/2019/05/26/234642
#pythonのfloatは2^56->10^17乗程度しか精度が出ない。
#int(a/2)
N,A,B = list(map(int, input().split()))
diff = B-A

if diff %2 == 0:
    # print(int(diff/2))ではダメ
    print(diff//2)
else:
    edge=min(N-B,A-1)
    if diff==1:
        print(edge+1)
    else:
        after=(diff-1)//2
        print(edge+after+1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,a,b;
  cin >> n >> a >> b;
  vector<int> v(n);
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int small=0;
  int middle=0;
  int large=0;
  for(int i = 0; i < n; i++) {
    if(v[i]<=a){
      small++;
    }else if(v[i]>a&&v[i]<=b){
      middle++;
    }else{
      large++;
    }
  }
  int minimum = min({small,middle,large});
  cout << minimum;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

bool pr[1000000];

void erato(bool pr[1000000]){
	for(int k = 0;k<1000000;k++){
		if(k==0||k==1){
			pr[k] = false;
		}
		else{
			int flag = 1;
			for(int m=2;m*m<=k;m++){
				if(k%m==0){
					flag=0;
					break;
				}
			}
			if(flag){
				pr[k] = true;
			}
			else{
				pr[k] = false;
			}
		}
	}
}

int main(){
	int a, d, n, i, now;
	erato(pr);
	while(1){
		cin >> a >> d >> n;
		if(!n)break;
		i=0;
		now = a;
		while(1){
			if(pr[now]) i++;
			if(i==n)break;
			else now += d;
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7

vll prime_factrize(ll n){
    vll prime_factrize_ret;
    ll temp=n;
    for(ll i=2;i*i<=n;i++){
        while(temp%i==0){
            prime_factrize_ret.push_back(i);
            temp/=i;
        }
    }
    if(temp!=1) prime_factrize_ret.push_back(temp);
    return prime_factrize_ret;
}

ll fast_pow(ll n,ll a,ll mod){
    ll res=1;
    while(a>0){
        if(a&1) res=res*n%mod;
        n=n*n%mod;
        a>>=1;
    }
    return res;
}

ll mod_inv(ll n, ll mod){
    return fast_pow(n,mod-2,mod);
}

ll comb(ll n, ll r, ll mod){
    ll temp=1;
    for(int i=r+1;i<=n;i++){
        temp=(temp*i)%mod;
    }
    ll temp2=1;
    for(int i=2;i<=n-r;i++){
        temp2=(temp2*i)%mod;
    }
    return temp*mod_inv(temp2,mod)%mod;
}

struct UnionFind {
    vector<int> r;
    int num;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
        num=N;
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        num--;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    bool same(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return true;
        else return false;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    vi a(m);
    vi b(m);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vll ans(m+1);
    ans[m]=n*(n-1)/2;
    UnionFind uf(n);
    for(int i=1;i<=m;i++){
        //cout << a[m-i] << " " << b[m-i] << endl;
        if(uf.root(a[m-i])!=uf.root(b[m-i])){
            ans[m-i]=ans[m-i+1]-uf.size(a[m-i])*uf.size(b[m-i]);
        }else{
            ans[m-i]=ans[m-i+1];
        }  
        uf.unite(a[m-i],b[m-i]);
    }
    for(int i=1;i<=m;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int Q;
  cin >> Q;
  while( Q-- ) {
    string s = "";
    for(int i=0; i<8; i++) {
      char c;
      cin >> c;
      if( c == '0' ) s += "0000";
      if( c == '1' ) s += "0001";
      if( c == '2' ) s += "0010";
      if( c == '3' ) s += "0011";
      if( c == '4' ) s += "0100";
      if( c == '5' ) s += "0101";
      if( c == '6' ) s += "0110";
      if( c == '7' ) s += "0111";
      if( c == '8' ) s += "1000";
      if( c == '9' ) s += "1001";
      if( c == 'a' ) s += "1010";
      if( c == 'b' ) s += "1011";
      if( c == 'c' ) s += "1100";
      if( c == 'd' ) s += "1101";
      if( c == 'e' ) s += "1110";
      if( c == 'f' ) s += "1111";
      // cout << s << endl;
    } 

    long long int sum = 0;
    long double sum2 = 0;
    for(int i=24; i>0; i--) {
      if( s[i] == '1' ) {
	sum += pow(2.0, 24-i);
      }
    }
    for(int i=25; i<32; i++) {
      if( s[i] == '1' ) {
	sum2 += pow(0.5, i-25+1);
      }
    }
   
    long long int tmp = (long long int)sum2;
    if( sum2 - (long double)tmp > 0 ) {
      if( s[0] == '1' ) {
	cout << '-';
      }
      string add = "";
      while( 1 ) {
	if( sum2 == 0 ) break;
	sum2 *= 10;
	tmp = (long long int)sum2;
	add += '0' + tmp;
	sum2 -= (long double)tmp;
      }
	
      cout << sum << '.' << add << endl;
    } else {
      if( s[0] == '1' ) {
	cout << '-';
      }
      cout << sum << ".0" << endl; 
    }
  }
  
}

Measured memory_bytes: 3176
#include <stdio.h>
#define INF 1000000000
int N,c[100],r[100],A[100],m[100][100],p[200],s;
int Min(int x,int y){
  int tmp;
  if(x>=y) return y;
  else return x;
}


int matrixCO(){
  int n,i,l,k,q,j;
  n=s;

  for(l=2;l<=n;l++){
    for(i=1;i<n-l+1;i++){
      j=i+l-1;
      m[i][j]=INF;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=Min(m[i][j],q);
      }
    }
  }
  return m[i][j];

}

	
int main(){

  int i,min;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&r[i]);
    scanf("%d",&c[i]);
    p[s]=r[i];
    s++;
    A[i]=r[i]*c[i];
  }
  p[s]=c[i-1];
  s++;
  
  min=matrixCO();
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
 
int main(){
  int n,co=0,v[50],c[50];
  
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",&v[i]);
  for(int i=0;i<n;i++)    
    scanf("%d",&c[i]);
    
  for(int i=0;i<n;i++){
    if(v[i]>c[i]){
      co+=v[i]-c[i];
    }
  }
  
  printf("%d\n",co);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int qpow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1) ans*=a;
		a*=a;
		b>>=1; 
	}
	return ans;
}
int main()
{
	int n;
	cin>>n;
	int len=0;
	int t=n;
	while(n)
	{
		len++;
		n/=10;
	}
	int ans=0;
	for(int i=1;i<len;i++)
	{
		if(i&1) ans+=9*qpow(10,i-1);
	}
	if(len&1) ans+=t-qpow(10,len-1)+1;
	cout<<ans<<endl;
	return 0; 
} 

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

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

	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	for (ll &x : a)
		cin >> x;
	for (ll &x : b)
		cin >> x;

	ll sum = 0, ans = 0;
	for (int i = 0; i < n; ++i)
		if (a[i] < b[i]) {
			++ans;
			sum += b[i] - a[i];
		}

	vector<ll> v;
	for (int i = 0; i < n; ++i)
		if (a[i] > b[i])
			v.push_back(a[i] - b[i]);

	sort(v.begin(), v.end());
	while (sum > 0 && !v.empty()) {
		sum -= v.back();
		v.pop_back();
		++ans;
	}
	if (sum > 0)
		cout << -1;
	else
		cout << ans;
	return 0;
}


Measured memory_bytes: 2428