akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

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

        static void A()
        {
            var NAB = ReadIntInputs();
            Console.WriteLine(Math.Min(NAB[0] * NAB[1], NAB[2])); 
        }

        public static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0)
                throw new Exception("0未満");

            if (start > stop || (start == 0 && stop == 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        public static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        public static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        public static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IList<int> ReadIntInputs()
        {
            return Read().Split(' ').Select(int.Parse).ToList();
        }

        public static int ReadInt()
        {
            return int.Parse(Read());
        }

        public static IList<string> ReadInputs()
        {
            return Read().Split(' ').ToList();
        }
    }
}

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

// 左に落ちないならtrue
bool CL(int x, int Q, int N, string S, vector<char> t, vector<char> d){
    for(int i=0; i<Q; i++){
        if(S[x-1]==t[i]){
            if(d[i]-'L'==0){
                x = x-1;
            }else{
                x++;
            }
        }
        if(x < 1){
            return false;
        }
        if(x > N){
            return true;
        }
    }
    return true;
}

// 右に落ちないならtrue
bool CR(int x, int Q, int N, string S, vector<char> t, vector<char> d){
    for(int i=0; i<Q; i++){
        if(S[x-1]==t[i]){
            if(d[i]-'L'==0){
                x--;
            }else{
                x++;
            }
        }
        if(x < 1){
            return true;
        }
        if(x > N){
            return false;
        }
    }
    return true;
}


int main(){
    int N,Q;
    string S;
    cin >> N >> Q >> S;
    vector<char>t(Q);
    vector<char>d(Q);
    for(int i=0; i<Q; i++){
        cin >> t[i] >> d[i];
    }

    // 左に落ちない最小値ubL
    int lbL=0, ubL = N + 1;
    while( ubL-lbL > 1 ){
        int mid = (lbL+ubL)/2;
        if(CL(mid, Q, N, S, t, d)){
            ubL = mid;
        }else{
            lbL = mid;
        }
    }

    // 右に落ちない最大値lbR
    int lbR=0, ubR = N + 1;
    while( ubR-lbR > 1 ){
        int mid = (lbR + ubR) / 2;
        if (CR(mid, Q, N, S, t, d)) {
            lbR = mid;
        } else {
            ubR = mid;
        }
    }

    int ans;
    ans = lbR - ubL + 1;
    if(lbR == 0){
        cout << 0;
    }else if(ubL == N + 1){
        cout << 0;
    }else{
        cout << ans;
    }
    return 0;
}

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

#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> pii;
const int maxn = 3e5 + 10;
const int maxm = 1e6 + 10 ;
const int inf=0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int st=(1<<20)-1;
const int mod = 1e9+7;
const double eps = 1e-5;
const int vec[2][2]={1,0,0,1};

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

inline ll sv(ll x) {
    ll ans=1;
    for(int i=1;i<=x;i++) {
        ans*=i;
        ans%=mod;
    }
    return ans;
}

int a[maxn];
ll pre[maxn],suf[maxn];
priority_queue<int> q;
int main() {
#ifdef LOCAL
    freopen("input.txt","r",stdin);
#endif // LOCAL
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n,m;
    n=read();
    m=n*3;
    for(int i=1;i<=m;i++) {
        a[i]=read();
    }
    ll sum=0;
    for(int i=1;i<=n;i++) {
        q.push(-a[i]);
        sum+=a[i];
    }
    pre[n]=sum;
    for(int i=n+1;i<=m-n;i++) {
        q.push(-a[i]);
        sum+=a[i];
        sum+=q.top();
        pre[i]=sum;
        q.pop();
    }
    while(!q.empty()) q.pop();
    sum=0;
    for(int i=m;i>m-n;i--) {
        q.push(a[i]);
        sum+=a[i];
    }
    suf[m-n+1]=sum;
    for(int i=m-n;i>n;i--) {
        q.push(a[i]);
        sum+=a[i];
        sum-=q.top();
        suf[i]=sum;
        q.pop();
    }
    ll ans=-INF;
    for(int i=n;i<=m-n;i++) {
        ans=max(ans,pre[i]-suf[i+1]);
    }
    cout<<ans;
    return 0;
}
//校园网真tm卡


Measured memory_bytes: 4728
N,M=map(int,input().split())
G=[list(map(int,input().split())) for _ in range(M)]
mi=0
ma=float("inf")
for i in range(M):
    if G[i][0]>mi:
        mi=G[i][0]
    if G[i][1]<ma:
        ma=G[i][1]
    #print(mi,ma)
print(max(ma-mi+1,0))

Measured memory_bytes: 59992
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

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

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 h, w;
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    i64 a = 0, mi = h * w;
    for (i64 i = 0; i < h; ++i) {
        a += w;
        i64 b, c;
        if ((h * w - a) % 2 == 0) {
            mi = min(mi, max(a, (h * w - a) / 2) - min(a, (h * w - a) / 2));
        }
        else {
            b = (h * w - a - min(h - i - 1, w)) / 2;
            c = h * w - a - b;
            mi = min(mi, max({a, b, c}) - min({a, b, c}));
        }
    }
    a = 0;
    for (i64 i = 0; i < w; ++i) {
        a += h;
        if ((h * w - a) % 2 == 0) {
            mi = min(mi, max(a, (h * w - a) / 2) - min(a, (h * w - a) / 2));
        }
        else {
            i64 b = (h * w - a - min(w - i - 1, h)) / 2;
            i64 c = h * w - a - b;
            mi = min(mi, max({ a, b, c }) - min({ a, b, c }));
        }
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>

using namespace std;

#define ll long long
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define plp pair <int, pll >
#define pb push_back


int main(){
    ll int n,y,j;

while(cin>>n>>y){
        bool yes=0;

        for(int i=0;i<=n;i++){

            for(int k=0;k<=n;k++){
                    if(i+k<=n){

j=n-(i+k);

if(i*10000+k*5000+j*1000==y){

    yes=1;

cout<<i<<" "<<k<<" "<<j<<endl;
break;
}
                    }

            }
            if(yes){
                break;
            }
        }




if(!yes){


    cout<<"-1 -1 -1\n";
}


}



}


Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, K = map(int, input().split())
dA = [list(map(int, input().split())) for _ in range(2*K)]

d = defaultdict(int)
for i, da in enu(dA):
    if i%2 == 0:
        pass
    else:
        for a in da:
            d[a] = d[a]|1

print(N-sum(d.values()))




Measured memory_bytes: 9492
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
ll f[300] = {0, 300000, 200000, 100000};
int main()
{
    ll x, y, s = 0;
    cin >> x >> y;
    s = f[x] + f[y];
    if (x == 1 && y == 1)
        s += 400000;
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

int a,b,add,sub,mul;
cin>>a>>b;

add = a+b;
sub = a-b;
mul = a*b;

if(add >= sub && add >= mul)
    cout<<add<<endl;
else if(sub >= add && sub >= mul)
    cout<<sub<<endl;
else
    cout<<mul<<endl;
return 0;
    }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    for(int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }
    int max_a = *max_element(a.begin(), a.end());
    vector<int> b_large;
    for(int i = 0; i < N; ++i) {
        if (b[i] > max_a)
            b_large.push_back(b[i]);
    }
    sort(b_large.begin(), b_large.end(), greater<int>());
    int ret = 0;
    for(auto it = b_large.begin(); it != b_large.end(); it++) {
        H -= *it;
        ret++;
        if (H <= 0) {
            cout << ret << endl;
            return 0;
        }
    }
    ret += (H + (max_a-1) )/max_a;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;


int main(){

    string s;
    cin >> s;

    if(s == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3600
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        k: usize
    }

    let mut possibility = 0.0;
    for i in 1..n + 1 {
        if i >= k {
            possibility += 1.0 / n as f64;
        } else {
            let mut coin_head_enpower = 1;
            while coin_head_enpower * i < k {
                coin_head_enpower *= 2;
            }

            possibility += 1.0 / ((n * coin_head_enpower) as f64);
        }
    }

    println!("{}", possibility);

    let mut ans = 0;
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

using namespace std;

#define ll long long;
#define fo(i,n) for(int i=0;i<n;i++)

int n,ans;

void solve() {
    int n,ans = 0; cin >>n;
    int arr[2*n];
    fo(i,2*n){
        cin >> arr[i];
    }
    sort(arr,arr+2*n);
    for(int i =0; i < 2*n; i +=2){
        ans +=arr[i];
    }
    cout <<ans;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    
    
    return 0;
}


Measured memory_bytes: 3620
#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 rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#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 int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = INF;
    for(int i = -100; i <= 100; i++){
        ll temp = 0;
        rep(j,n)temp += (i - a[j]) * (i - a[j]);
        chmin(ans, temp);
    }
    cout << ans << endl;
}

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

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

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

int main(){
    int n,q;
    cin >> n;
    vector<int> a(n);
    vector<int> d(100007,0);
    rep(i,n){
        int a;
        cin >> a;
        d.at(a)++;
    }
    cin >> q;
    vector<pair<int,int>> bc;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        pair<int,int> p(b,c);
        bc.push_back(p);
    
    }
    ll ans = 0;
    rep(i,100007) ans += i * d.at(i);
    rep(i,q){
        int b = bc.at(i).first;
        int c = bc.at(i).second;
        int t = d.at(b);
        d.at(b) = 0;
        d.at(c) += t;
        ans += c * t - b * t;
        cout << ans << endl;
    }
}

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

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

  while (n--) {
    int x, y, a, b;
    cin >> x >> y >> a >> b;

    int ans = 1001001001;

    for (int i = 0; i < 7; ++i) {
      if (i < a) continue;
      for (int j = 0; j < 7; ++j) {
        if (j < b) continue;
        int d = i * x + j * y;
        if (i >= 5 && j >= 2) d -= d / 10 * 2;

        ans = min(ans, d);
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 3076
from collections import deque
import pprint
H,W=map(int,input().split())
table=[list(input()) for _ in range(H)]
d=deque()
dp=[[float("inf") for _ in range(W)] for _ in range(H)]
dp[0][0]=1
d.append([0,0])
seen=[[0 for _ in range(W)] for _ in range(H)]
seen[0][0]=1
blnum=0
for i in range(H):
    for j in range(W):
        if table[i][j]=="#":
            blnum=blnum+1
while len(d)!=0:
    v=d.popleft()
    x=v[0]
    y=v[1]
    if x!=0:
        if (table[x-1][y]==".")and(seen[x-1][y]==0):
            d.append([x-1,y])
            seen[x-1][y]=1
            dp[x-1][y]=min(dp[x-1][y],dp[x][y]+1)
    if x!=H-1:
        if (table[x+1][y]==".")and(seen[x+1][y]==0):
            d.append([x+1,y])
            seen[x+1][y]=1
            dp[x + 1][y] = min(dp[x + 1][y], dp[x][y] + 1)
    if y!=0:
        if (table[x][y-1]==".")and(seen[x][y-1]==0):
            d.append([x,y-1])
            seen[x][y-1]=1
            dp[x][y-1]=min(dp[x][y-1],dp[x][y]+1)
    if y!=W-1:
        if (table[x][y+1]==".")and(seen[x][y+1]==0):
            d.append([x,y+1])
            seen[x][y+1]=1
            dp[x][y+1]=min(dp[x][y+1],dp[x][y]+1)
    #pprint.pprint(dp)
    #print(d)
    #input()
if dp[H-1][W-1]==float("inf"):
    print("-1")
else:
    print(H*W-dp[H-1][W-1]-blnum)

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s == "abc") {
    cout << "Yes" << endl;
  } else if (s == "acb") {
    cout << "Yes" << endl;
  } else if (s == "bac") {
    cout << "Yes" << endl;
  } else if (s == "bca") {
    cout << "Yes" << endl;
  } else if (s == "cab") {
    cout << "Yes" << endl;
  } else if (s == "cba") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())
ans=""
ans+="R"*(tx-sx)
ans+="U"*(ty-sy)
ans+="L"*(tx-sx)
ans+="D"*(ty-sy+1)
ans+="R"*(tx-sx+1)
ans+="U"*(ty-sy+1)
ans+="LU"
ans+="L"*(tx-sx+1)
ans+="D"*(ty-sy+1)
ans+="R"
print(ans)

Measured memory_bytes: 81428
temparr = input()
temparr = temparr.split()
n = int(temparr[0])
k = int(temparr[1])
temparr = input()
import math
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
arr = sorted(arr)
#print(arr)

left = 1
right = arr[-1] + 1
ans = arr[-1]
while left <= right:
    mid = (left + right) // 2 
    count = 0 
    for i in arr :
        if i <= mid:
            continue 
        else:
            count += math.ceil(i / mid) - 1 
    if count <= k :
        right = mid - 1 
        if mid < ans:
            ans = mid 
    else:
        left = mid + 1 
print(ans)







Measured memory_bytes: 101628
#include <stdio.h>

int main() {
  int answer;
  int number[3];
  scanf("%d %d %d", &number[0], &number[1], &number[2]);
  if(number[0] >= number[1] && number[0] >= number[2]) answer = number[1] + number[2];
  else if(number[1] >= number[2] && number[1] >= number[0]) answer = number[0] + number[2];
  else answer = number[0] + number[1];
  printf("%d\n", answer);
  return 0;
}


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

int main()
{
    string s;
    cin >> s;

    int n = s.size();
    vector<ll> sum(n + 1);
    sum[0] = 0;
    ll pow = 1;
    for (int i = 1; i <= n; i++, pow = (pow * 10) % 2019)
        sum[i] = ((s[(n - 1) - (i - 1)] - '0') * pow + sum[i - 1]) % 2019;

    vector<ll> cnt(2019, 0);
    rep (i, n + 1)
        cnt[sum[i]]++;

    ll ans = 0;
    rep (i, 2019)
        ans += cnt[i] * (cnt[i] - 1) / 2;

    cout << ans << endl;
    return 0;
}

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

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

/*long C(long n, long r){
    if(n < r) return 0;
    long p[n+1][n+1];
    p[0][0] = 1;
    for(int i = 1; i <= n; i++){
        p[i][0] = 1;
        p[i][i] = 1;
        for(int j = 1; j <= i-1; j++){
            p[i][j] = p[i-1][j] + p[i-1][j-1];
        }
    }
    return p[n][r];
}*/

int N;
int A[20];
int x[20][20];
int y[20][20];
 
int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
 
void solve() {
    int n, m;
    cin >> n >> m;
    int ans = (n - 1)*(m-1);
    cout << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = [i for i in range(M)]
Y = [0] * M
def par(i):
    if X[i] == i:
        return i
    t = par(X[i])
    X[i] = t
    return t
c = 0
for _ in range(N):
    Z = [int(a) - 1 for a in input().split()][1:]
    i = Z[0]
    for j in Z:
        if Y[j] == 0:
            c += 1
            Y[j] = 1
        pi = par(i)
        pj = par(j)
        if pi != pj:
            X[pj] = pi
            c -= 1
if c == 1:
    print("YES")
else:
    print("NO")

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int answer = 0;
  int count = 0;
  for (char c : S) {
    if (c == 'R') {
      count++;
      answer = max(answer, count);
    } else {
      count = 0;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M);
	for(int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
	}
	vector<int> p(N + 1);
	for(int i = 0; i < M; ++i) {
		++p[L[i] - 1];
		--p[R[i]];
	}
	int sum = 0, ans = 0;
	for(int i = 0; i < N; ++i) {
		sum += p[i];
		if(sum == M) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4244
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  vector<int> A,B;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      if(N%2==0&&i+j==N+1) continue;
      if(N%2==1&&i+j==N) continue;
      A.push_back(i);
      B.push_back(j);
    }
  }

  cout<<A.size()<<endl;
  for(int i=0;i<A.size();i++) cout<<A[i]<<" "<<B[i]<<endl;

  return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>
#include <chrono>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

int main() {

    string S;
    cin >> S;

    vector<int> a;
    for (int i = 0, j = 0; i < S.size(); i = j) {
        while (j < S.size() && S[i] == S[j])j++;
        a.push_back(j - i);
    }

    vector<int> ans(S.size(), 0);

    int sum = 0;
    for (int i = 0; i < a.size() / 2; i++) {
        int R = a[i * 2];
        int L = a[i * 2 + 1];
        ans[sum + R - 1] += (R + 1) / 2;
        ans[sum + R] += R / 2;
        ans[sum + R ] += (L + 1 ) / 2;
        ans[sum + R - 1] += L / 2;
        sum += R + L;
    }

    for(auto x: ans) cout << x  <<  " ";

}





































Measured memory_bytes: 1528
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ll = int64_t; using ld = long double;
 
// -----------------------------------------------------------------------------

void solve() {
    int n, k; cin >> n >> k;
    int p = 0;
    while (n > 0) {
        n /= k; ++p;
    }
    cout << p << '\n';
}


int main() {
    fast_io; cin_exception;
    int t = 1; // cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
}

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

long h,w,k;
char c[10][10];
bool red[10][10];
long ans;

void judge() {
	long num=0;
	for(long i=1;i<=h;++i)
		for(long j=1;j<=w;++j)
			if(red[i][j]==0 && c[i][j]=='#')
				++num;
	if(num==k) {
		++ans;
/*		for(long i=1;i<=h;++i) {
			for(long j=1;j<=w;++j)
				cout<<red[i][j];
			cout<<endl;
		}*/
	}
}

void dfs_w(long now) {
	if(now>w) {
		judge();
		return;
	}
	bool backup[10][10];
	memcpy(backup,red,sizeof(red));
	
	dfs_w(now+1);
	for(long i=1;i<=h;++i)
		red[i][now]=1;
	dfs_w(now+1);
	
	memcpy(red,backup,sizeof(red));
}

void dfs_h(long now) {
	if(now>h) {
		dfs_w(1);
		return;
	}
	bool backup[10][10];
	memcpy(backup,red,sizeof(red));
	
	dfs_h(now+1);
	for(long i=1;i<=w;++i)
		red[now][i]=1;
	dfs_h(now+1);
	
	memcpy(red,backup,sizeof(red));
}

int main() {
	cin>>h>>w>>k;
	register long i,j;
	for(i=1;i<=h;++i)
		for(j=1;j<=w;++j) {
			c[i][j]=getchar();
			if(c[i][j]!='.' && c[i][j]!='#')
				--j;
		}
	
	dfs_h(1);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3588
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Harshad
 */

#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long int ll;
using namespace std;

class a {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n; in>>n;
        int k; in>>k;
        bool like[10];
        memset(like, true, sizeof(like));
        f(i, k) {
            int temp;
            in >> temp;
            like[temp] = false;
        }
        rep(i, n, 10*n){
            int temp = i;
            while(temp){
                if(!like[temp%10])
                    break;
                temp/=10;
            }
            if(temp==0){ out<<i; break;}
        }
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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


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

using namespace std;

int main() {
  int N, X, T;
  
  cin >> N >> X >> T;
  
  if (N % X == 0) {
    cout << (N / X) * T << endl;
  } else {
    cout << (N / X + 1) * T << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2005;
const int ha=1000000007;
int jc[maxn*maxn],ni[maxn*maxn];
int n,k,f[maxn][maxn];
 
inline int add(int x,int y){
    x+=y;
    return x>=ha?x-ha:x;
}
 
inline int ksm(int x,int y){
    int an=1;
    for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
    return an;
}
 
inline void init(){
    jc[0]=1;
    for(int i=1;i<=4004000;i++) jc[i]=jc[i-1]*(ll)i%ha;
    ni[4004000]=ksm(jc[4004000],ha-2);
    for(int i=4004000;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
}
 
inline int getC(int x,int y){
    return jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;
}
 
inline void dp(){
    f[0][0]=1;
    for(int i=0;i<=n;i++)
        for(int j=i;j>=0;j--) if(f[i][j]){
            f[i+1][j+1]=add(f[i+1][j+1],f[i][j]*(ll)(n-i)%ha*(ll)getC(k*(i+1)-j-2,k-2)%ha);
            if(j) f[i][j-1]=add(f[i][j-1],f[i][j]);
        }
     
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=i;j++) printf("%d ",f[i][j]);
        puts("");
    }
    */
}
 
int main(){
    init();
    scanf("%d%d",&n,&k);
    if(k==1) puts("1");
    else{
        dp();
        printf("%d\n",f[n][0]);
    }
    return 0;
}
/*
仅有一个序列中的每一个白球都能在其后方匹配到一个是其颜色里出现第一次的彩球，
这个序列才合法。

    从后向前dp,
    
    f[i][j] 表示 已经完整出现过 i种颜色的球，
    并且还剩j种颜色的球没有被匹配的方案数。
     
    考虑加入一种新球的话:
    f[i+1][j+1] += f[i][j] * (n-i) * C(k*(i+1)-j-2,k-2)
     
    考虑加入一种白球的话:
    f[i][j-1] += f[i][j]
     
    初始化 f[0][0] = 1
*/

Measured memory_bytes: 46464
def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = 0
	rest = A[0]
	for i in range(N):
		if rest >= B[i]:
			ans += B[i]
			rest = A[i+1]
		elif (rest < B[i]) & (rest + A[i+1] >= B[i]):
			ans += B[i]
			rest = rest + A[i+1] - B[i]
		else:
			ans += (rest + A[i+1])
			rest = 0
	print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19228
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int A, B;
  cin >> A >> B;
  if (A <= 8 && B <= 8) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;
 
signed main(){
    fast;
    int k,a,b;
    cin >> k >> a >> b;
    int f = 0;
    for(int i=a ; i<=b ; i++){
        if(i%k == 0){
            f = 1;
        }
    }
    if(f){
        cout << "OK" << endl;
    }
    else
        cout << "NG" << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main()
{
	int A, B;
	string S;
	cin >> A >> B >> S;
	REP(i, A)
	{
		if ('0' <= S[i] && S[i] <= '9')continue;
		else
		{
			cout << "No" << endl;
			return 0;
		}
	}
	if (S[A] != '-')
	{
		cout << "No" << endl;
		return 0;
	}
	for (int i = A + 1; i <= A+B; i++)
	{
		if ('0' <= S[i] && S[i] <= '9')continue;
		else
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ALDS1
{
    class Program
    {
        static void Main()
        {
            long l = long.Parse(Console.ReadLine()) - 1;
            long min = long.Parse(Console.ReadLine());
            long max = -999999999;
            for (int i = 0; i < l; i++)
            {
                var a = long.Parse(Console.ReadLine());
                var b = a - min;
                if (b > max) max = b;
                if (a < min) min = a;
            }
            Console.WriteLine(max);
        }
    }
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<int> ant(5);
    rep(i, 5) cin >> ant[i];
    int k;
    cin >> k;
    for (int i = 0; i < 5; ++i) {
        for (int j = i + 1; j < 5; ++j) {
            if (ant[j] - ant[i] > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int a;
scanf("%d",&a);
if(a==25){printf("Christmas");}
else if(a==24){printf("Christmas Eve");}
else if(a==23){printf("Christmas Eve Eve");}
else{printf("Christmas Eve Eve Eve");}
}

Measured memory_bytes: 128
n, k = map(int, input().split())
count = [0] * n
for _ in range(k):
    kosu = int(input())
    pos = list(map(int, input().split()))
    for i in pos:
        count[i-1] +=1
ans = [True if i == 0 else False for i in count]
print(sum(ans))

Measured memory_bytes: 9000
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define REPR(i, n) for(int i = int(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

struct mint {
private:
    ll x;
public:
    mint(ll x = 0) :x(x%MOD) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend ostream& operator<<(ostream& os, const mint& n) {
        return os << n.x;
    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> s(n), t(m);
    REP(i, n) {
        cin >> s[i];
    }
    REP(i, m) cin >> t[i];
    // dp[i][j] : s[:i+1] t[:j+1] の組数
    vector<vector<mint>> dp(n + 1, vector<mint>(m + 1, 1));
    dp[0][0] = 1;
    REP(i, n) {
        REP(j, m) {
            dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
            if (s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + 1] -= dp[i][j];
        }
    }
    cout << dp[n][m] << endl;
    getchar(); getchar();
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    cout << 2 * (64 - __builtin_clzl(N - 1)) << endl;
    vector<unsigned long> ev, od;
    string S(N, '0');
    {
        vector<unsigned long> to(N), tr(N);
        iota(to.begin(), to.end(), 0UL);
        for(unsigned long i{1}, j{N / 2 + ((N & 3) != 0) + ((N & 3) == 1)}; j < N; i += 2, j += 2){
            swap(to[i], to[j]);
            S[i] = S[j] = '1';
        }
        for(unsigned long i{0}; 2 * i < N; ++i)tr[to[i]] = 2 * i;
        for(unsigned long i{0}; 2 * i + 1 < N; ++i)tr[to[N - 1 - i]] = 2 * i + 1 + (N & 1);
        for(unsigned long j{0}, i; j < N; ++j){
            cin >> i;
            if(i & 1)od.push_back(tr[i]);
            else ev.push_back(tr[i]);
        }
    }
    string sep(N + 5, '1');
    sep[0] = '0';
    sep[1] = sep.back() = ' ';
    sep[N + 2] = '\n';
    for(unsigned long i{2}; i < N; i <<= 1){
        string T(N, '0');
        vector<unsigned long> e1, e2, o1, o2;
        for(unsigned long j{0}; j < (N + 1) / 2; ++j)if(ev[j] & i){
            T[j] = '1';
            e2.push_back(ev[j]);
        }else{
            e1.push_back(ev[j]);
        }
        for(unsigned long j{0}; j < N / 2; ++j)if(od[j] & i){
            T[j + (N + 1) / 2] = '1';
            o1.push_back(od[j]);
        }else{
            o2.push_back(od[j]);
        }
        copy(e1.begin(), e1.end(), ev.begin());
        copy(e2.rbegin(), e2.rend(), ev.rbegin());
        copy(o1.begin(), o1.end(), od.begin());
        copy(o2.rbegin(), o2.rend(), od.rbegin());
        cout << sep << T << endl;
    }
    cout << sep << S << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
#define mod 1000000007
#define pb push_back
int main()
{
    ll n;
    cin>>n;
    vi arr(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vi dp(n+1,0);
    dp[n]=0;
    dp[n-1]=abs(arr[n]-arr[n-1]);
    dp[n-2]=min(abs(arr[n-1]-arr[n-2])+dp[n-1],abs(arr[n]-arr[n-2]));
    for(ll i=n-2;i>=1;i--)
    {
        dp[i]=min(abs(arr[i]-arr[i+1])+dp[i+1],abs(arr[i]-arr[i+2])+dp[i+2]);
    }
    cout<<dp[1]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

vector<int> osa_k;
const int MAX = 1000010;
vector<int> sieve(int n) {
  vector<int> res(n);
  iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i <= n; i++) {
    if (res[i] < i)
      continue;
    for (int j = i*2; j < n; j+=i)
      res[j] = i;
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  osa_k = sieve(MAX);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<bool> used(MAX);
  bool flag = true;
  rep(i, n) {
    set<int> st;
    int num = a[i];
    while (num > 1) {
      st.insert(osa_k[num]);
      num /= osa_k[num];
    }
    for (auto e : st) {
      if (used[e]) {
        flag = false;
        break;
      }
      used[e] = true;
    }
    if (!flag)
      break;
  }
  if (flag) {
    cout << "pairwise coprime\n";
    return 0;
  }
  int g = a[0];
  for (int i = 1; i < n; i++)
    g = gcd(a[i], g);
  if (g == 1)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
  return 0;
}

Measured memory_bytes: 11224
import numpy as np

N, K = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int,input().split())))
MOD = 10 ** 9 + 7

def mat_mul(A, B):
    A1, A2 = A >> 15, A & (1 << 15) - 1
    B1, B2 = B >> 15, B & (1 << 15) - 1
    X = np.dot(A1, B1) % MOD
    Y = np.dot(A2, B2) % MOD
    Z = (np.dot(A1 + A2, B1 + B2) - X - Y) % MOD
    return ((X << 30) + (Z << 15) + Y) % MOD
 
def mat_power(A, N):
    P = np.eye(A.shape[0], dtype=np.int64)
    while N:
        if N & 1:
            P = mat_mul(P, A)
        A = mat_mul(A, A)
        N >>= 1
    return P

A2 = np.array(A)
print((np.sum(mat_power(A2,K))%MOD))

Measured memory_bytes: 27580
"use strict";

let isSeen = []
const moveX = [-1,0,1,-1,1,-1,0,1]
const moveY = [-1,-1,-1,0,0,1,1,1]

function dfs(c,x,y,w,h) {
    isSeen[y][x] = 1
    //console.log(`x=${x}, y=${y}`)
    for(let i=0; i<moveX.length; i++) {// assume moveX.length is the same with moveY.length
        const newX = x+moveX[i]
        const newY = y+moveY[i]
        if(newX <0 || newX > w-1) continue;
        if(newY <0 || newY > h-1) continue;
        if(isSeen[newY][newX]===1) continue;
        if(c[newY][newX]===0) continue;
        
        //console.log(`  i=${i}, newX=${newX}, newY=${newY}`)
        //break
        dfs(c,newX,newY,w,h)
    }
    
}

function main(arg) {

    let input = arg.trim().split("\n");
    //console.log(input)
    while(true) {
        const w = parseInt(input[0].split(" ")[0]);
        const h = parseInt(input[0].split(" ")[1]);
        if(w===0 && h===0)break
        const inp = input.slice(1,h+1)
        const c = inp.map(i=>i.split(" ").map(n=>parseInt(n)));
        
        //console.log(inp)
        //console.log(`w=${w}, h=${h}`)
        for(let i=0; i<=h; i++) {
            input.shift()
        }
        //console.log(input)
        //console.log(input[0].split(" "))
        //return
        //continue
        isSeen = []
        c.forEach(cc=> {
            let arr = []
            cc.forEach(ccc=> {
                arr.push(0)
            })
            isSeen.push(arr)
        })
        
        let count = 0
        for(let x=0; x<w; x++) {
            for(let y=0; y<h; y++) {
                if(isSeen[y][x]===1) continue;
                if(c[y][x]===0) continue;
                dfs(c,x,y,w,h);
                ++count;
                //console.log(`***** count up to ${++count} *****`)
            }
        }
        
        console.log(count)
    }

}

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


Measured memory_bytes: 18512
//
//  main.cpp
//  CP
//
//  Created by Shiv Pavan Raj on 22/02/20.
//  Copyright © 2020 Shiv Pavan Raj. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;


int main(int argc, const char * argv[]) {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    int n,m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ull n,m;
	cin >> n >> m;
	if(2*n>=m)cout << m/2/*+(n-m/2)/2 */<< endl;
	else cout << n+(m-2*n)/4 << endl;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

void solve()
{
	double xa1, xa2, xb1, xb2;
	double ya1, ya2, yb1, yb2;
	while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2)
	{
		if(xa2 < xb1 || xb2 < xa1)
		{
			cout << "NO" << endl;
		}
		else if(yb2 < ya1 || ya2 < yb1)
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p;
  vector<int> q;
  for ( int i = 0; i < n; i++ ) {
    int t;
    cin >> t;
    p.push_back(t);
  }
  for ( int i = 0; i < n; i++ ) {
    int t;
    cin >> t;
    q.push_back(t);
  }

  vector<vector<int>> permutation;
  vector<int> tmp;
  for ( int i = 1; i <= n; i++ ) {
    tmp.push_back(i);
  }
  do {
    permutation.push_back(tmp);
  } while ( next_permutation(tmp.begin(), tmp.end()) );

  cout << abs(find(permutation.begin(), permutation.end(), p) - find(permutation.begin(), permutation.end(), q)) << endl;
  return 0;
}


Measured memory_bytes: 6308
#include <iostream>

int xCeil(int x) {
  int mod = x % 10;
  if (mod == 0) {
    return x;
  } else {
    return x - mod + 10;
  }
}

int modCeil(int x) {
  int mod = x % 10;
  if (mod == 0) {
    return 10;
  } else {
    return mod;
  }
}

int main() {
  int x[5];
  for (int i = 0; i < 5; ++i) {
    std::cin >> x[i];
  }
  if (x[0] % 10 == 0 && x[1] % 10 == 0 && x[2] % 10 == 0 && x[3] % 10 == 0 && x[4] % 10 == 0) {
    std::cout << x[0] + x[1] + x[2] + x[3] + x[4] << "\n";
    return 0;
  }
  int sum = 0;
  int minMod = 9;
  for (int i = 0; i < 5; ++i) {
    sum += xCeil(x[i]);
    if (modCeil(x[i]) < minMod) {
      minMod = modCeil(x[i]);
    }
  }
  std::cout << sum - 10 + minMod << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1234567;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

struct edge{
    int a;
    int b;
    int c;
    int d;
};

int N,M,Q;
vector<edge> vec(100);
int ret = 0;

void dfs(vector<int> cnt) {
    if(cnt.size() == N) {
        int cnt2 = 0;
        for(int i = 0;i < Q;i++) {
            if(cnt.at(vec.at(i).b) - cnt.at(vec.at(i).a) == vec.at(i).c) {
                cnt2 += vec.at(i).d;
            }
        }
        ret = max(ret,cnt2);
        return;
    }
    if(cnt.empty()) {
        for(int i = 1;i <= M;i++) {
            cnt.push_back(i);
            dfs(cnt);
            cnt.pop_back();
        }
        return;
    }
    for(int i = cnt.at(cnt.size() - 1);i <= M;i++) {
        cnt.push_back(i);
        dfs(cnt);
        cnt.pop_back();
    }
}

int main() {
    ll A,B,N;
    cin >> A >> B >> N;
    if(N >= B - 1) {
        cout << A * (B - 1) / B - A * ((B - 1) / B) << endl;
    }
    else {
        cout << A * N / B - A * (N / B) << endl;
    }
}

Measured memory_bytes: 3636
#include <stdio.h>
#define N 2000

int solve(int ,int );
int a[N];
int n;

int main()
{
  int b;
  int i=0, m=0, q=0;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&b);
    
    if(solve(0,b) == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  
  res = solve(i + 1, m) || solve(i + 1, m - a[i]);
  return res;
}

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

int main()
{
    using namespace std;

    string str;

    cin >> str;
    //cout << str << endl;

    if (str[2] == str[3] && str[4] == str[5])
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256