akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: usize = read();
    let a: usize = read();
    let b: usize = read();
    println!("{}", (x - a) % b);
}

Measured memory_bytes: 4352
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    ll max = (int)sqrt(N);
    cout << max*max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n,vector<int>(d,0));
    REP(i,n) REP(j,d){
        cin>>x[i][j];
    }
    int cnt=0;
    REP(i,n){
        for(int j=i+1;j<n;j++){
            int ans = 0;
            REP(k,d){
                ans += abs(x[i][k]-x[j][k]) * abs(x[i][k]-x[j][k]);
            }
            if((int)sqrt(ans)==sqrt(ans)) cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define ll long long int
#define mod 1000000007


ll fac(int n)
{
    ll ans = 0;
    for(int i = 1; i*i<=n;i++)
    {
        if(n%i==0)
        {
            int j = n/i;
            if(j!=i)
                ans+=2;
            else
                ans+=1;
        }
    }
    return ans;
}
int n;

void solve()
{
    cin>>n;
    
    ll ans = 0;
    
    for(int c = 1;c<n;c++)
    {
        int k = n-c;
        ans += fac(k);
    }
    
    cout<<ans;
}

int main()
{
    sync;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}







Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0,b=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    a[i]--;
  }
  for(int i=0;i<=n;i++){
    b=a[b];
    c++;
    if(b==1){
      cout<<c;
      return 0;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const int NAX=1005;
const long long  MOD=(long long)(998244353);

Int N,M,K;
Int X,Y,Z;
Int H,W;
Int perform(Int x){
    return (x*(x+1))/2LL;
}
vector<Int> A;
vector<int> adj[MAXN];
using D=long double;

bool inRange(Int a,Int b){
    return a*b<=0;
}

long long C[NAX][NAX];
const D pi=3.14159265359;


long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}
long long fac[MAXN];
void fillFac(){
    fac[0]=1;
    for(int i=1;i<MAXN;++i){
        fac[i]=((fac[i-1]%MOD)*(i%MOD))%MOD;
    }
}

long long ModInv(long long x){
    return ModExpo(x,MOD-2,MOD);
}

long long FermatLast(long long n,long long r){
    if(r>n) return 0;
    if(!r) return 1;
    return (fac[n] * ModInv(fac[r]) % MOD * ModInv(fac[n - r]) % MOD) % MOD;
}

Int performMod(Int x){
    Int y=((x%MOD)*((x+1)%MOD))%MOD;
    return (y*ModInv(2))%MOD;
}

Int madd(Int x,Int y){
    return (x+y)%MOD;
}

Int mmul(Int x,Int y){
    return ((x%MOD)*(y%MOD))%MOD;
}


bool isMSB(int bit,Int x){
    return (int)(floor(log2l(x)))==bit;
}
bool VIS[MAXN];
void dfs(int u){
    VIS[u]=true;
        for(auto &v:adj[u]){
            if(!VIS[v]){
                dfs(v);
            }
        }
}
int main()
{
    cin>>N>>M;
    for(int i=0;i<M;++i){
        int u,v;
        cin>>u>>v;
        --u;--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans=0;
    memset(VIS,false,sizeof(VIS));
    for(int i=0;i<N;++i){
        if(!VIS[i]){
            dfs(i);
            ++ans;
        }
    }
    assert(ans>=1);
    if(ans) --ans;
    cout<<ans<<"\n";
}


Measured memory_bytes: 19356
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	long double x1,y1;
    long double x2,y2;
    
    cin>>x1>>y1>>x2>>y2;
    long double result;
    result = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
    cout.setf(ios::fixed);
    cout<<setprecision(8)<<result<<endl;
    
    
	return 0;
}

Measured memory_bytes: 3260
s = input()
n = len(s)
cntr = 0
cntl = 0
ansr = [0]*n
for i in range(n):
    if s[i] == 'R':
        cntr += 1
    if s[i] == 'L':
        ansr[i] += cntr//2
        ansr[i-1] += (cntr - ansr[i])
        cntr = 0

ansl = [0]*n
for i in range(n-1,-1,-1):
    if s[i] == 'L':
        cntl += 1
    if s[i] == 'R':
        ansl[i] += cntl//2
        ansl[i+1] += (cntl - ansl[i])
        cntl = 0

ans = [0]*n
for i in range(n):
    ans[i] = ansl[i] + ansr[i]

ans_str = [str(i) for i in ans]
print(' '.join(ans_str))

Measured memory_bytes: 82808
N = int(input())
K = int(input())
x_list = map(int,input().split())
x_move  = 0

# x_listごとにループ
for xi in x_list:
	# x_listと(K-xi)の比較
    # 小さい方を選んで2倍して足す
    x_move += min(xi,K-xi)*2
    
#出力
print(x_move)

Measured memory_bytes: 2940
import java.util.concurrent.LinkedBlockingDeque

fun main(args: Array<String>) {
    data class Route(val x: Int, val y: Int, val length: Int)

    fun genNext(x: Int, y: Int, length: Int, maze: List<MutableList<Char>>, queue: LinkedBlockingDeque<Route>) {
        maze[y][x] = '#'
        queue.offer(Route(x, y, length + 1))
    }

    val (h, w) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val maze: List<MutableList<Char>> = 0.until(h).map {
        readLine()?.toMutableList() ?: return
    }
    val queue = LinkedBlockingDeque<Route>()
    var max = 0
    0.until(h).forEach { y ->
        0.until(w).forEach loop@{ x ->
            if (maze[y][x] == '#') {
                return@loop
            }
            val mazeCopy = maze.map { it.toMutableList() }
            genNext(x, y, 0, mazeCopy, queue)
            while (queue.isNotEmpty()) {
                val route = queue.poll()
                val length = route.length

                max = Math.max(max, length)

                val xx = route.x
                val yy = route.y
                // 上
                val up = yy - 1
                if (up >= 0 && mazeCopy[up][xx] != '#') {
                    genNext(xx, up, length, mazeCopy, queue)
                }
                // 左
                val left = xx - 1
                if (left >= 0 && mazeCopy[yy][left] != '#') {
                    genNext(left, yy, length, mazeCopy, queue)
                }
                // 右
                val right = xx + 1
                if (right < w && mazeCopy[yy][right] != '#') {
                    genNext(right, yy, length, mazeCopy, queue)
                }
                // 下
                val down = yy + 1
                if (down < h && mazeCopy[down][xx] != '#') {
                    genNext(xx, down, length, mazeCopy, queue)
                }
            }
        }
    }
    println(max - 1)
}


Measured memory_bytes: 42292
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}



void solve(){
ll n;
cin>>n;
vector<ll> v(n);
for(ll i=0;i<n;i++)cin>>v[i];
ll ans=0;

for(ll i=1;i<n;i++){
	 if(v[i]<v[i-1])
          {
              ans+=v[i-1]-v[i];
              v[i]=v[i-1];
          }
}
cout<<ans<<endl;

	
	
	return;
}




int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 4776
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(a) sort(a.begin(), a.end()) //reverse()で反転
#define lower(a, n) lower_bound(a.begin(), a.end(), n);
#define upper(a, n) upper_bount(a.begin(), a.end(), n);
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int sum(int a){
  if(a == 0) return 0;
  return sum(a - 1) + a;
}
int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int xMove = tx - sx;
  int yMove = ty - sy;
  rep(i, xMove) cout << 'R';
  rep(i, yMove) cout << 'U';
  rep(i, xMove) cout << 'L';
  rep(i, yMove + 1) cout << 'D';
  rep(i, xMove + 1) cout << 'R';
  rep(i, yMove + 1) cout << 'U';
  cout << "LU";
  rep(i, xMove + 1) cout << 'L';
  rep(i, yMove + 1) cout << 'D';
  cout << 'R' << endl;
}

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

int main(){

    int n,ans=1;
    cin >> n;
    int tmp = 1;
    for(int i = 0;i < n;i++){
        //cout << i << endl;
        tmp = i*i;
        if(tmp > n){
            ans = (i-1)*(i-1);
            break;
        }
    }
    cout << ans << endl;


    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  vector<pair<int,int>>cb(m);
  for(int i=0;i<n;i++) cin >> a.at(i);
  for(int i=0;i<m;i++) cin >> cb.at(i).second >> cb.at(i).first;
  sort(a.begin(),a.end());
  sort(cb.begin(),cb.end(),greater());
  int64_t ans=0;
  int p=0;
  for(int i=0;i<n;i++){
    if(cb.at(p).second==0&&p<cb.size()-1) p++;
    if(cb.at(p).second>0&&cb.at(p).first>a.at(i)){
      ans+=cb.at(p).first;
      cb.at(p).second--;
    }else{
      ans+=a.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4316
#include <iostream>
using namespace std;
int main()
{
    int n,w[1000]={},total=99999999,o=0,p=0;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>w[i];
    }
    for (int i=0; i<=n-1; i++)
       {
           for (int k=0; k<=i; k++)
           {
               o=w[k]+o;
           }
           for (int z=i+1; z<n; z++)
           {
                p=w[z]+p;
           }
           if (o-p>=0)
           {
               if (o-p<total)
               {
                   total=o-p;
               }
           }
           if (o-p<0)
           {
               int num;
               num =p-o;
               if (num<total)
               {
                   total=num;
               }
           }
           o=0;
           p=0;
       }
    cout<<total;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l;
string s[101];
int main(){
	cin>>n>>l;
	for(int i=1;i<=n;i++)cin>>s[i];
	sort(s+1,s+1+n);
	for(int i=1;i<=n;i++)cout<<s[i];
	cout<<endl;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*
--------------------------------------------

	Optimizer

--------------------------------------------
*/
//#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
--------------------------------------------
 
	Utility Algorithm

-------------------------------------------- 
*/

template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}
 
template <typename T1>
T1 euclideanAlgorithm(T1 a, T1 b) {
    T1 a_tmp = a;
    T1 b_tmp = b;
 
    if (a_tmp > b_tmp) {
        swapAlgorithm<T1>(a_tmp, b_tmp);
    }
 
    T1 r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

template <typename T2>
T2 getLCM(T2 a, T2 b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

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);
    }
};

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b;
    cin >> a >> b;

    if(a > b) {
        REP(a) cout << b;
    }
    else {
        REP(b) cout << a;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,c=map(int, input().split())
if c - a - b < 0:
    print("No")
else:
    if a**2 + b**2 + c**2 - 2*a*b - 2*b*c - 2*c*a > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 2940
N = int(input())

X = []
Y = []
h = []
for i in range(N):
    a,b,c = map(int,input().split())

    if c > 0:
        p = i
    X.append(a)
    Y.append(b)
    h.append(c)

for Cx in range(101):
    for Cy in range(101):
        works = True
        H = h[p] + abs(X[p] - Cx) + abs(Y[p] - Cy)
        for i in range(N):
            if h[i] != max(H - abs(X[i] - Cx) - abs(Y[i] - Cy), 0):
                works = False
                break
        
        if works:
            print(Cx,Cy,H)
            quit()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x, a, b;
		
		x = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		
		sc.close();
		
		int min = Math.abs(x - a);
		int tmp = Math.abs(x - b);
		if(min < tmp)System.out.println("A");
		else System.out.println("B");
		
	}

}


Measured memory_bytes: 22740
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

const long mod = 1000000007;
const long indlim = 5368709119;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	bool isprime[100009] = {}; for (int i = 2; i <= 100000; i++) isprime[i] = true;
	for (int i = 2; i * i <= 100000; i++) if (isprime[i] == true) for (int j = 2; i * j <= 100000; j++) isprime[i * j] = false;

	bool islike2017[100009] = {}; for (int i = 3; i <= 100000; i = i + 2) if (isprime[i] && isprime[(i + 1) / 2]) islike2017[i] = true;

	long numoflike[100009] = {}; for (int i = 1; i <= 100000; i++) numoflike[i] = numoflike[i - 1] + islike2017[i];

	long Q; cin >> Q;
	long l, r; 
	for (int i = 1; i <= Q; i++) { cin >> l >> r; cout << numoflike[r] - numoflike[l - 1] << endl;}

}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;




int main(void){
    const long long int mod=1000000007;
    long long int n,m=0,a[200005],plsum=0,misum=0,pl=0,mi=0,cou=0;
    cin>>n;
    for(long long int i=1;i<1000000;i++){
        cou++;
        m+=i;
        if(m>=n){break;}
    }
    cout<<cou;
}


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

int main( void )
{
    int a, b;
    cin >> a >> b;
    if ( a * b % 2 != 0 )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())

import math
g = math.gcd(a,b)

"""
gを素因数分解したときの素因数のリストの要素数 + 「1」を含める

g == 1のとき
1
g != 1のとき
素因数リストの要素数 +1
"""



def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


gdlist = prime_factorize(g)
if gdlist ==[]:
    print(1)
else:
    print(len(set(gdlist))+1)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

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 << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}


int main(){
    ll n; cin >> n;
    vector<ll> p(n);
    rep(i,n) cin >> p[i];
    vector<ll> q(n);
    rep(i,n) cin >> q[i];
    vector<ll> test(n);
    iota(all(test),1);
    ll a,b;
    // print(test);
    ll cnt = 0;
    do{
        if(test == p)a = cnt;
        if(test == q)b = cnt;
        cnt++;
    }while(next_permutation(all(test)));
    cout << abs(a - b) << endl;
}

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

using namespace std;

const int N = 100000 + 77;
int n , m , t , d[N];
vector < int > V;
int Ev[N] , Eu[N] , Par[N];
int Find(int x) {
   return Par[x] == 0 ? x : (Par[x] = Find(Par[x]));
}
inline bool Merge(int v , int u) {
   v = Find(v);
   u = Find(u);
   if(v == u)
      return 1;
   Par[v] = u;
   return 0;
}
int main() {
   scanf("%d %d" , & n , & m);
   for(int i = 1;i <= m;++ i)
      scanf("%d %d" , Ev + i , Eu + i) , ++ d[Ev[i]] , ++ d[Eu[i]];
   for(int i = 1;i <= n;++ i) {
      if(d[i] == 4)
         V.push_back(i) , ++ t;
      if(d[i] & 1)
         return ! printf("No\n");
   }
   for(int i = 1;i <= n;++ i)
      if(d[i] > 4)
         return ! printf("Yes\n");
   if(t <= 1)
      return ! printf("No\n");
   if(t >= 3)
      return ! printf("Yes\n");
   for(int i = 1;i <= m;++ i)
      if(d[Ev[i]] == 2 && d[Eu[i]] == 2)
         Merge(Ev[i] , Eu[i]);
   for(int i = 1;i <= m;++ i)
      if((Ev[i] == V[0] && Eu[i] != V[1]) || (Eu[i] == V[0] && Ev[i] != V[1]))
         if(Merge(Ev[i] , Eu[i]))
            return ! printf("Yes\n");
   memset(Par , 0 , sizeof(Par));
   reverse(V.begin() , V.end());
   for(int i = 1;i <= m;++ i)
      if(d[Ev[i]] == 2 && d[Eu[i]] == 2)
         Merge(Ev[i] , Eu[i]);
   for(int i = 1;i <= m;++ i)
      if((Ev[i] == V[0] && Eu[i] != V[1]) || (Eu[i] == V[0] && Ev[i] != V[1]))
         if(Merge(Ev[i] , Eu[i]))
            return ! printf("Yes\n");
   return ! printf("No\n");
   return 0;
}


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool check = false;
  if((a % k) == 0 || (b % k) == 0) check = true;
  else {
    int x = a / k;
    if(k * (x + 1) < b) {
      check = true;
    }
  }
  if(check) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	char a[50][50], b[50][50];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	bool flag;
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			flag = true;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (b[k][l] != a[k + i][l + j]) {
						flag = false;
						break;
					}
				}
				if (flag == false) {
					break;
				}
			}
			if (flag == true) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
n = int(input())
l = []
for i in range(n):
  s, p = input().split()
  p = -int(p)
  l.append([s, p])
  
ans = (sorted(l, key=itemgetter(0, 1)))
for i in range(n):
  print(l.index(ans[i]) + 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{long long i,j,sum,x,y,z,n,t,d,m,k,l,p,w;
x=0;y=0;z=0;w=0;t=0;
cin>>n>>m>>k;
bool b[n],c[m];
l=pow(2,n);p=pow(2,m);
char a[n][m];
for(i=0;i<n;i++)
{for(j=0;j<m;j++){
cin>>a[i][j];
}}
for(x=0;x<l;x++)
{for(y=0;y<p;y++){z=0;
for(i=0;i<n;i++){b[i]=0;}
for(i=0;i<m;i++){c[i]=0;}
t=x;i=0;
while(t>0)
{if(t%2==0)
b[i]=0;
else b[i]=1;
t=t/2;i=i+1;}
t=y;i=0;
while(t>0)
{if(t%2==0)
c[i]=0;
else c[i]=1;
t=t/2;i=i+1;}
for(i=0;i<n;i++)
{for(j=0;j<m;j++)
{if(a[i][j]=='#'&&b[i]==0&&c[j]==0)z=z+1;}}
if(z==k)w=w+1;}}
cout<<w;
return 0;
}


Measured memory_bytes: 4104
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int N, A;
	cin >> N >> A;

	if ( ( N % 500 ) <= A )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,k,m,i,a[100010],b[100010],c[100010];
  scanf("%lld %lld",&n,&k);
  m=(n+1)/2;
  for(i=0;i<m;i++){
    c[i]=k+2*n+i;
    a[i]=k+i*2;
    b[i]=k+n+m-i-1;
  }
  for(i=m;i<n;i++){
    c[i]=k+2*n+i;
    a[i]=k+(i-m)*2+1;
    b[i]=k+n+n-1-(i-m);
  }
  for(i=0;i<n;i++){
    if(a[i]+b[i]>c[i]){
      printf("-1\n");
      return 0;
    }
    }//*/
  for(i=0;i<n;i++)printf("%lld %lld %lld\n",a[i],b[i],c[i]);
  return 0;
}


Measured memory_bytes: 4480
<?php
fscanf(STDIN, "%d %d", $n, $m);
$mod = 10 ** 9 + 7;
$d = abs($n - $m);
if ($d > 1) exit('0');
if ($d == 1) {
	if ($n > $m) list($n, $m) = [$m, $n];
	$a = fact($n);
	$b = $a * $m % $mod;
	echo $a * $b % $mod;
} else {
	$a = fact($n);
	$b = $a * $a % $mod;
	echo $b * 2 % $mod;
}

function fact($n) {
	global $mod;
	if ($n == 0) {
		return 1;
	}
	return $n * fact($n - 1) % $mod;
}

Measured memory_bytes: 27128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  int L[K], R[K];
  for(int i=0;i<K;++i) cin>>L[i]>>R[i];
  int DP[N+1], sumDP[N+1];
  for(int i=0;i<=N;++i) {
    DP[i] = 0;
    sumDP[i] = 0;
  }
  DP[1] = 1;
  sumDP[1] = 1;
  for(int i=2;i<=N;++i) {
    for(int j=0;j<K;++j) {
      if(i-L[j]<0) continue;
      if(i-R[j]-1<0) DP[i] += sumDP[i-L[j]];
      else DP[i] += (sumDP[i-L[j]]-sumDP[i-R[j]-1]+mod1)%mod1;
      DP[i] %= mod1;
    }
    sumDP[i] = (DP[i]+sumDP[i-1])%mod1;
  }
  cout<<DP[N]<<endl;
}



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

#define int unsigned long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int A;
long double B;
    cin >> A >> B;
long double D = A;
long double res = A*B;
int otro = res;
B*=100.0;
int c = B;


    int temp = A*B;
if(otro > temp/100)cout << otro << '\n';
    else cout << temp/100 << '\n';

    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
int x[MAXN], y[MAXN], t[MAXN], n;
int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	int pt = 0, px = 0, py = 0, possible = 1;
	for (int i=1; i<=n; i++) {
		int mint = (abs(x[i]-px) + abs(y[i]-py)), tdiff = t[i] - pt;
		if (tdiff < mint) {
			cout << "No" << endl;
			return 0;
		}
		else if ((tdiff-mint)%2 == 1) {
			cout << "No" << endl;
			return 0;
		}
		pt = t[i];px = x[i];py = y[i];
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
fun main(args: Array<String>) {
    var a = 0
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map { it.toInt() }
    val sortedl = l.sorted()
    for (i in 0 until n) {
        if(l[i] != sortedl[i]) a += 1
    }
    println(if(a == 0 || a == 2) "YES" else "NO")
}

Measured memory_bytes: 37944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll


signed main() {
  int N; cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  
  sort(all(A));
  sort(all(B));
  
  if(N%2 == 1) {
    cout << 1-A[(N-1)/2]+B[(N-1)/2] << endl;
  }
  if(N%2 == 0) {
    cout << 1 - (A[N/2]+A[N/2-1]) + (B[N/2]+B[N/2-1]) << endl;
  }
  

}

Measured memory_bytes: 6428
// https://atcoder.jp/contests/abc079/tasks/abc079_c

#include <iostream>
#include <vector>
#include <tuple>
#include <bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;

struct C1 {
    ll A_{};
    ll B_{};
    ll C_{};
    ll D_{};
    explicit C1(string str) {
        A_ = str[0] - '0';
        B_ = str[1] - '0';
        C_ = str[2] - '0';
        D_ = str[3] - '0';
    }
    string resolve() {
        for(ull i=0; i < 1 << 3; ++i) {
            bitset<3> bs(i);
            if (7 == A_ +
                             (bs[2] ? 1 : -1) * B_ +
                             (bs[1] ? 1 : -1) * C_ +
                             (bs[0] ? 1 : -1) * D_
            ) {
                return to_string(A_) +
                        (bs[2] ? "+" : "-") + to_string(B_) +
                        (bs[1] ? "+" : "-") + to_string(C_) +
                        (bs[0] ? "+" : "-") + to_string(D_) + "=7";
            }
        }
        std::abort();
    }
};

int main() {
    string str{};
    cin >> str;
    C1 c{move(str)};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char s[200001];
    char t[200001];
    scanf("%200000s", s);
    scanf("%200000s", t);
    int count = 0;
    for (int i = 0; i < 200000; ++i) {
        if(s[i] != t[i]){
            count++;
        } else if(s[i] == '\0') {
            break;
        }
    }
    printf("%d", count);
    return 0;
}


Measured memory_bytes: 2112
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
	int n, m, q;
	string a, b;//two sequences
	int M[1010][1010] = { { 0 } };//Memory matrix

	cin >> q;
	for (int l = 0; l < q; l++)
	{
		cin >> a >> b;
		n = a.length();
		m = b.length();
		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= m; j++)
			{
				if (a[i] == b[j])
				{
					M[i + 1][j + 1] = M[i][j] + 1;
				}
				else
				{
					M[i + 1][j + 1] = max(M[i][j + 1], M[i + 1][j]);
				}
			}
		}

		cout << M[n][m] << endl;//The time complexity equals to O (n * m)
	}
	return 0;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int h, w; scanf("%d%d", &h, &w); auto a = make_v<int>(h, w);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) scanf("%d", &a[i][j]);
	
	std::vector<std::pair<int, int>> A, B;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w - 1; j++) {
			if(!(a[i][j] % 2)) continue;
			A.push_back({i + 1, j + 1});
			B.push_back({i + 1, j + 2});
			a[i][j + 1]++; a[i][j]--;
		}
	}
	for(int i = 0; i < h - 1; i++) {
		if(!(a[i][w - 1] % 2)) continue;
		A.push_back({i + 1, w});
		B.push_back({i + 2, w});
		a[i][w - 1]--; a[i + 1][w - 1]++;
	}
	
	printf("%d\n", (int)A.size());
	for(int i = 0; i < A.size(); i++) printf("%d %d %d %d\n", A[i].first, A[i].second, B[i].first, B[i].second);
	return 0;
}


Measured memory_bytes: 5356
s = input()
t = input()

match = -1
if len(s) >= len(t):
    for i in range(len(s) - len(t) + 1):
        is_term_match = True
        for j in range(len(t)):
            if s[i + j] != "?" and s[i + j] != t[j]:
                is_term_match = False
                break
        if is_term_match:
            match = i

if match == -1:
    print("UNRESTORABLE")
else:
    s = s[0:match] + t + s[match + len(t):]
    for i in range(len(s)):
        if s[i] == "?":
            s = s[0:i] + "a" + s[i + 1:]
    print(s)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,k; cin>>n>>k;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    sort(h.begin(), h.end(), greater<>());
    ll ans = 0;
    for (int i = k; i < n; ++i) ans+=h[i];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int a, b;
    cin >> a >> b;
    string ans = "x";
    if (a + b == 15)  ans = "+";
    if (a * b == 15) ans = "*";
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
dt = [None] * n
for i in range(n):
    a, b = map(int, input().split())
    dt[i] = [b, a]
dt.sort()
t = 0
ans = True
for b, a in dt:
    if t + a > b:
        ans = False
    t += a
print(['No', 'Yes'][ans])


Measured memory_bytes: 35608
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m,k, s, t, q, ans, sum, a, d[1000000], last;
struct Edge { LL to,cost; };
vector<Edge>vec[100010];
string str, ss;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	if (n == 1 && m == 1)ans = 1;
	else if (m - 2 < 0)ans = n - 2;
	else if (n - 2 < 0)ans = m - 2;
	else	ans = (n - 2)*(m - 2); 
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(){
	string s,t;
	cin>>s>>t;
	int a=s.size();
	for(int i=0;i<a;i++){
		if(s[i]!=t[i]){
			cout<<"No";
			return 0;
			}
		}
	cout<<"Yes";
	}


Measured memory_bytes: 3560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct edge {
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_) {
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty()) {
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
			continue;
		for (auto ed : graph_[thv]) {
			if (dist[ed.to] > ed.cost + thd) {
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>graph[123456];
LL dist[123456];

int main(void)
{
	int N, M, s, t;
	cin >> N >> M >> s >> t;
	--s; --t;
	for (int i = 0; i < M; ++i) {
		LL a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --b; --c;
		graph[a].push_back(edge(c, d));
		graph[a].push_back(edge(b, d));
		graph[b].push_back(edge(a, d));
		graph[b].push_back(edge(c, d));
		graph[c].push_back(edge(a, d));
		graph[c].push_back(edge(b, d));
	}
	dijkstra(graph, dist, N, s);
	cout << dist[t] << endl;
	return 0;
}



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll n ; 
  cin >> n ;
  intll  A[n+1] = {0};
  vector<intll> v(n);
  
 
  rep(i,n){ 
    cin >> v.at(i) ;
    A[v.at(i)] ++ ;
  }

  intll ans = 0;
  
  rep(i,n){
    if(A[i+1] >1){
     ans += A[i+1] * (A[i+1]-1) /2 ;
    }
  }
  
   rep(i,n){
     cout << ans - A[v.at(i)] + 1 <<endl;
   }
  
 
  
 
  
  
  
    
    
  
  


}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
using namespace std;
string a;
int d,n,mod=1e9+7;

int digitSum(int idx,int sum,bool tight,vector<vector<int> > &dp){
	if(idx==n)
		return sum==0?1:0;
	if(!tight&&dp[n-idx-1][sum]!=-1)
		return dp[n-idx-1][sum];
	int ans =0;
	int k = tight?a[idx]-48:10;
	for(int i=0;i<k;i++)
		ans = (digitSum(idx+1,(sum+i)%d,0,dp)+ans)%mod;
	if(tight){
		ans = (digitSum(idx+1,(sum+k)%d,1,dp)+ans)%mod;
	} else {
		dp[n-idx-1][sum] = ans;
	}
	return ans;
}

int main()
{	
	cin >> a >> d;
	n = a.size();
	vector<vector<int> > dp(n,vector<int>(d,-1));
	cout << (digitSum(0,0,1,dp)-1+mod)%mod;
    return 0;
}

Measured memory_bytes: 8396
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int cur,n;
string s;
void solve()
{
    cin>>s>>n;
    deque<char> dq;
    for(auto it:s)dq.pb(it);
    for(int i=0;i<n;i++)
    {
        int ope;
        cin>>ope;
        if(ope==1)cur=1-cur;
        else
        {
            int x;
            char c;
            cin>>x>>c;
            --x;
            if(x^cur)dq.push_back(c);
            else dq.push_front(c);
        }
    }
    if(cur)reverse(dq.begin(),dq.end());
    for(auto it:dq)cout<<it;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("STRWC.inp","r",stdin);
    //freopen("STRWC.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c){
    cout << 1 << endl;
  }else if (a == b || b == c || c == a ){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
vector<vector<int> >g;

vector<bool> flag;
vector<bool> ok;

vector<int>a;
bool dfs(int id,int pre){
    if(flag[id]){
        return ok[id];
    }
    bool res = 0;
    for(auto x:g[id]){
        if(x!=pre){
            if(a[id]>a[x]){
                bool p = dfs(x,id);
                if(!p)res = true;
            }
        }
    }
    flag[id] = true;
    ok[id] = res;
    return ok[id];
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    flag.resize(n);
    ok.resize(n);
    a.resize(n);
    rep(i,n)cin >> a[i];
    rep(i,n-1){
        int c,d;
        cin >> c >> d;
        c--;d--;
        g[c].push_back(d);
        g[d].push_back(c);
    }
    rep(i,n){
        dfs(i,-1);
    }
    rep(i,n){
        if(ok[i]){
            cout << i+1 << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    bool ans(true);
    rep(i,n){
        int x;  cin >> x;

        if(x%2==0){
            if (!(x % 3 == 0 || x % 5 == 0))
            {
                ans = false;
            }
        }
    }

    if(ans){
        puts("APPROVED");
    }else{
        puts("DENIED");
    }

    return 0;
}

Measured memory_bytes: 3592
#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++)
int main()
{
    string s;
    cin >> s;

    if(s=="Sunny") cout << "Cloudy" << endl;
    if(s=="Cloudy") cout << "Rainy" << endl;
    if(s=="Rainy") cout << "Sunny" << endl;

   

   return 0;
}

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

int main() {
	long long A, N, M, ANS = 0;
	cin >> A >> N >> M;
	for (long long P = A; pow(P, N) <= M; P++) {
		if (P == 0) continue;
		long long X = pow(P, N), Y = 0;
		while (X > 0) {
			Y += X % 10;
			X /= 10;
		}
		if (Y + A == P) ANS++;
	}
	cout << ANS << endl;
}


Measured memory_bytes: 3276