akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long int N, P, A[50], dp[2], d;

int main(){
    scanf("%lld%lld", &N, &P);
    dp[0] = 1;
    for(int i = 0; i < N; ++i){
        scanf("%lld", A + i);
        if(A[i] & 1)dp[0] = dp[1] = dp[0] + dp[1];
        else{*dp *= 2; dp[1] *= 2;}
    }
    cout << dp[P] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int GCD(int,int);
    int a,b;
    cin>>a>>b;
    cout<<GCD(b,a%b)<<endl;
    return 0;
}
int GCD(int a,int b)//假设a>b
{
    if(b == 0)
        return a;
    int c = a-b;
    GCD(c,b%c);

}



Measured memory_bytes: 3108
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn lcm(a: usize, b: usize) -> usize {
    let g = gcd(a, b);
    a / g * b
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input!(n: usize, m: usize, s: chars, t: chars);

    let g = gcd(n, m);
    let x = n / g;
    let y = m / g;
    let a = lcm(x, y) / y;
    let b = lcm(x, y) / x;
    // l = i*lcm = i * n/gcd *m
    // a*l/n = i*y *a
    // b*l/m = i*x *b
    // a=lcm(x,y)/y

    for x in 0.. {
        let i = n / g * x;
        let j = m / g * x;
        if i >= s.len() || j >= t.len() {
            break;
        }
        if s[i] != t[j] {
            println!("-1");
            return;
        }
    }
    println!("{}", lcm(n, m));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

ll a[10009][3];
int main() {
    int N,M;
    cin >> N >> M;
    ll maximum=0LL;
    ll ans=0LL;
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
        }
    }

    vector<ll>sum(N);
    for(int i=0; i<8; i++) {
        for (int j = 0; j < N; j++) {
            ll cake=0LL;

            for(int k=0; k<3; k++){
                if(i>>k & 1){
                    cake+=a[j][k];
                }else{
                    cake-=a[j][k];
                }
            }
            sum[j]=cake;
        }
        sort(sum.begin(), sum.end());
        reverse(sum.begin(), sum.end());
        maximum=0LL;
        rep(l,M){
            maximum+=sum[l];
        }
        ans=max(maximum,ans);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> check(n);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      check[a-1] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!check[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
# include <iostream>
# include <cstdio>
using namespace std;
const int N = 2e5 + 12;
const int inf = 0x3f3f3f3f;
int n,head[N],dt,du[N],bac[N],que[N],rt,a[N],tot,p;char str[N];bool w[N];
struct Edge{int to,nex;}edge[N << 1];
void Add(int u,int v){edge[++dt] = (Edge){v,head[u]};head[u] = dt;du[u]++;}
void Dfs(int u,int pre)
{
    if(str[u] == 'W')w[u] = true;
    for(int i = head[u];i;i = edge[i].nex)if(edge[i].to != pre)
    {
        Dfs(edge[i].to,u);
        if(!w[edge[i].to])du[u]--,du[edge[i].to]--;
        w[u] |= w[edge[i].to];
    }
    if(w[u])tot++;
}
void rebuild()
{
    for(int i = 1;i <= n;i++)if(str[i] == 'W')rt = i;
    Dfs(rt,-1);
    for(int i = 1;i <= n;i++)if(w[i])a[i] = (str[i] == 'B') ^ (du[i] & 1),p += !a[i];
}
int dp[N][2],f[N];
void dfs(int u,int pre)
{
    f[u] = (tot - 1) * 2 + p;
    dp[u][0] = a[u] ? -1 : 1;
    for(int i = head[u];i;i = edge[i].nex)if(edge[i].to != pre && w[edge[i].to])
    {
        dfs(edge[i].to,u);
        f[u] = min(f[u],f[edge[i].to]);
        f[u] = min(f[u],(tot - 1) * 2 + p - dp[u][0] - dp[edge[i].to][1] - 1);
        f[u] = min(f[u],(tot - 1) * 2 + p - dp[u][1] - dp[edge[i].to][0] - 1);
        dp[u][0] = max(dp[u][0],dp[edge[i].to][0] + 1 + (a[u] ? -1 : 1));
        dp[u][1] = max(dp[u][1],dp[edge[i].to][1] + 1 + (a[u] ? -1 : 1));
    }
}
int main()
{
    
    scanf("%d",&n);int x,y;
    for(int i = 1;i < n;i++)scanf("%d %d",&x,&y),Add(x,y),Add(y,x);
    scanf("%s",str + 1);rebuild();dfs(rt,-1);
    printf("%d\n",!tot ? tot : f[rt]);
}



Measured memory_bytes: 13056
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll a, b; cin >> a >> b;
  ll mx=max(a,b); int p[mx+1], q[mx+1];
  fill(p, p+mx+1, 0); fill(q, q+mx+1, 0);
  for(ll i=2; i<=mx; i++) {
    while(a%i==0) a/=i, p[i]++;
  }
  for(ll i=2; i<=mx; i++) {
    while(b%i==0) b/=i, q[i]++;
  }
  ll an = 1;
  for(ll i=2; i<=mx; i++) {
    int nd = max(p[i], q[i]);
    while(nd>0) an*=i, nd--;
  }
  cout << an << endl;
}

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

 
int main() {
        int n;
        cin >> n;
        vector<vector<int>> a(n,vector<int>(n-1,0));
        rep(i,n){
                rep(j,n-1){
                        cin >> a[i][j];
                        a[i][j] --;
                }
                reverse(a[i].begin(),a[i].end());
        }

        vector<P> q;

        auto ok = [&](int i){
                if(a[i].size() == 0) return;
                int j = a[i].back();
                if(a[j].back() == i){
                        if(i > j ) swap(i,j);
                        q.push_back(P(i,j));
                }
        };

        int day = 0;
        rep(i,n){
                ok(i);
        }
        while(!q.empty()){
                day ++;
                vector<P> prevq;
                sort(q.begin(),q.end());
                q.erase(unique(q.begin(),q.end()),q.end());
                swap(q,prevq);
                for(P game:prevq){
                        a[game.first].pop_back();
                        a[game.second].pop_back();
                }
                for(P game:prevq){
                        ok(game.first);
                        ok(game.second);
                }
        }

        rep(i,n){
                if(a[i].size() != 0){
                        cout << -1 << endl;
                        return 0;
                }
        }

        cout << day << endl;

        return 0;
}





Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define REP(i, r) for(int i =(int)0; i < (int)r; ++i)

using namespace std;
typedef long long ll;
const int Nmax = 102;
const int Vmax = 1e5 + 112;
const ll inf = 1e18 + 112;

int n, w[Nmax], v[Nmax], W;
ll f[Nmax][Vmax], ans;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> W;
    FOR(i, 1, n) {
        cin >> w[i] >> v[i];
    }
    FOR(i, 0, n) REP(j, Vmax) {
        f[i][j] = inf;
    }
    f[0][0] = 0;
    FOR(i, 1, n) REP(j, Vmax) {
        f[i][j] = f[i - 1][j];
        if (j - v[i] >= 0) {
            f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]);
        }
        if (i == n && f[i][j] <= W) {
            ans = j;
        }
    }
    cout << ans;
}


Measured memory_bytes: 79232
#include <stdio.h>

int m, n, h, i, j;

int main() {
    // insert code here...
    for(;;){
        scanf("%d", &m);
        scanf("%d", &n);
        bool x[7368791];
        if(m == 0 && n == 0) break;
        for(h = 0; h< 7368791;h++){
            x[h] = 0;
        }
        for(i = m;i<=7368791;i++){
                if(x[i] == 0){
                    if(n == 0){
                        printf("%d\n",i);
                        break;
                    }
                    n--;
                    for(j = i; j<7368791;j += i){
                        x[j] = 1;
                    }
                }
        }
    }
    return 0;
}



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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N;
vi g[MN];

pii dfs(int v, int p)
{
	int t = 0, num = 0;
	bool lf = 1;
	int mark = 0;
	int cnt = 0;

	for (int to : g[v]) if (to != p) {
		pii res = dfs(to, v);

		t += res.fi;

		lf = 0;
		if (!res.se) {
			++num;
		} else {
			++mark;
			++cnt;
		}
	}

	if (lf) {
		return mp(0, 0);
	}

	if (num) {
		t += num - 1;
		mark += num - 1;
/*
		if (p == -1) {
			if (mark == 1) {
				t++;
			}
		}*/
	}

	return mp(t, mark);
}

int main() {
	cin >> N;

	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		g[a].pb(b); g[b].pb(a);
	}

	if (N == 2) {
		puts("1");
		return 0;
	}

	bool f = 0;

	rep(i, N) {
		if ((int)g[i].size() >= 3) {
			f = 1;
		}
	}

	if (!f) {
		puts("1");
		return 0;
	}

	int r = -1;
	rep(i, N) {
		if (r == -1 || g[r].size() < g[i].size()) {
			r = i;
		}
		//cout << "show " << i << " " << dfs(i, -1).fi << endl;
	}

	cout << dfs(r, -1).fi << endl;

	return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
struct dat { double x, y, arg; };
#pragma warning disable 4997

void knapsack(int n, int m, vi v, vi w) {
	vvi dp(n + 1, vi(m + 1, 0));
	Loop1(i, n) {
		Loop1(j, m) {
			if (j - w[i] < 0) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	int buf = dp[n][m];
	Loopr(j, m) {
		if (dp[n][j] < buf) {
			cout << dp[n][j + 1] << endl;
			cout << j + 1 << endl;
			break;
		}
	}
	return;
}

int main() {
	int W, N, cnt = 0;
	while (cin >> W, W) {
		cnt++;
		cin >> N;
		vi v(N + 1), w(N + 1);
		Loop1(i, N) {
			scanf("%d,%d", &v[i], &w[i]);
		}
		cout << "Case " << cnt << ":" << endl;
		knapsack(N, W, v, w);
	}
	return 0;
}

Measured memory_bytes: 6908
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <set>
#include <cmath>
#include <limits>
#include <map>

#include <numeric>
#include <type_traits>

using namespace std;
const long long INF = (long long) (1e18)+1;
vector<vector<long long>> nums;
long long n, m, x;
long long ans = -1;

void rec(long long current_p, int current_i, vector<long long> current, vector<vector<long long>> nums) {
  bool check = true;
  for (auto a : current) {
    if (a < x) check = false;
  }
  if (check) {
    if (ans == -1) ans = current_p;
    else ans = min(ans, current_p);
    return;
  } else {
    for (int i = current_i+1; i<n; ++i) {
      // cout << "i: " << i << endl;
      vector<long long> temp = current;
      for (int j=0; j<m; ++j) {
        temp[j] += nums[i][j+1];
      }
      rec(current_p+nums[i][0], i, temp, nums);
    }
  }
}

int main() {
  cin >> n >> m >> x;
  nums.resize(n);
  
  for (int i=0; i<n; ++i) {
    vector<long long> temp(m+1);
    cin >> temp[0];
    for (int j=1; j<=m; ++j) {
      cin >> temp[j];
    }
    nums[i] = temp;
  }

  for (int i=0; i<n; ++i) {
    // cout << "first loop " << i << endl;
    long long temp = 0;
    temp += nums[i][0];
    vector<long long> current(m);
    for (long long j=0; j<m; ++j) {
      current[j] = nums[i][j+1];
    }
    rec(temp, i, current, nums);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
int ans=0;
void solve(int n , int val , int r , int x  , int y){
  //cout << n << " " << val << "++\n";
  if(val > r) return;
  if(n == -1) {
    int k = val&x;
    int kk = val&y;
    //cout << val << " " << k << " " << kk  << "+++\n";
    if(((val&x) !=0) && ((val&y)!=0)){
      if(ans==0) ans =val;
      else if(log(ans&x) + log(ans&y) < log(val&x) + log(val&y)) ans=val;
      else if(log(ans&x) + log(ans&y) == log(val&x) + log(val&y)){
       // cout << ans << " " << val << "++\n";
        if(ans > val) ans=val;
      }
    }
    return;
  }
  int m = val + (1LL<<n);
  solve(n-1,m,r , x,y);
  solve(n-1,val,r,x,y);
}
int32_t main(){  
  int a,b,c,k;
  int ans = 0;
  cin >> a >> b >> c >> k;
  ans+=min(a,k);
  k = k - min(a,k);
  k = k - min(b,k);
  ans-=min(c,k);
  cout << ans << "\n";
}
/*
10010
01011
11000

16+
*/

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
    ll n;
    cin >> n;
    vector <ll> v(n);
    rep(i, n) cin >> v.at(i);
    ll min = v.at(0), max = v.at(1)-v.at(0);
    for (ll i = 1; i < n; i++) {
        if (max < v.at(i)-min) max = v.at(i)-min;
        if (min > v.at(i)) min = v.at(i);
    }
    cout << max << endl;
}


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

int main ()
{
    int n;
    cin >> n;
    while (n--) {
        string st, rs;
        set<string> ss;

        cin >> st;
        rs = st;
        rs[0] = st[st.size() - 1];
        ss.insert(st);
        for (int i = 1; i < st.size(); i++) {
            string tmp1 = st.substr(0, st.size() - i);
            string tmp2 = st.substr(st.size() - i, i);
            rs[i] = st[st.size() - 1 - i];
            ss.insert((string)(tmp2 + tmp1));
        }

        for (int i = 1; i < st.size(); i++) {
            string tmp0 = st.substr(i, st.size() - i);
            string tmp1 = st.substr(0, i);
            string tmp2 = rs.substr(0, rs.size() - i);
            string tmp3 = rs.substr(rs.size() - i, i);
            ss.insert((string)(tmp0 + tmp3));
            ss.insert((string)(tmp1 + tmp2));
            ss.insert((string)(tmp3 + tmp0));
            ss.insert((string)(tmp2 + tmp1));
            ss.insert((string)(tmp3 + tmp2));
        }

        cout << (int)(ss.size()) << endl;
    }

    return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;

ll n , k;
vector<vll> tmp;
void mult(vector<vll> &a , vector<vll> &b){
    vector<vll> c(n , vll(n));
    for(int i = 0 ;i < n;i++){
        for(int j = 0 ;j < n ; j++){
            for(int k = 0 ;k < n; k++){
                c[i][j] += a[i][k]*b[k][j];
                if(c[i][j] >= Mod)
                    c[i][j] %= Mod;
            }
        }
    }
    a = c;
}

void power(vector<vll> &a , ll y){
    if(y == 1)
        return;
    else
    {
        power(a , y/2);
        mult(a , a);
        if(y&1)
            mult(a , tmp);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> n >> k;
    vector<vll> A(n , vll(n));
    for(int i = 0 ;i < n; i++){
        for(int j = 0 ;j < n ; j++)
            cin >> A[i][j];
    }

    tmp = A;

    power(A , k);

    ll ans = 0;
    for(auto it : A){
        for(auto x : it)
            ans = (ans + x)%Mod;
    }
    cout << ans << endl;

    return 0;
}

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

int N;
vector<int> H;

int solve();
// int buf(vector<int> vs);

int main(){
  cin >> N;
  H = vector<int>(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  solve();
}

int solve(){
  int now = 0;
  int counter = 0;
  int max = 0;
  for(int i = 0; i<N; i++){
    if(H.at(i) <= now ){
      counter++;
    }else{
      if(max < counter ){
        max = counter;
      }
      counter = 0;
    }
    now = H.at(i);
  }
  if(max < counter ){
    max = counter;
  }
  // cout << v.size() <<endl;
  cout << max << endl;
  return 0;
}
//
// int buf(vector<int> vs){
//   for(int i =0; i< vs.size(); i++){
//     cout << v.at(i)<< " ";
//   }
//   cout << endl;
//   return 0;
// }


Measured memory_bytes: 768
#include<stdio.h>

int main(){
    
    int a;    

    int b;
    
    int x;    

    int y;

    scanf("%d %d", &a, &b);

    x = a * b;

    y = 2 * (a + b);

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

Measured memory_bytes: 2608
#include <iostream>
#include <string>
#include <vector>

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

int main(){
  int y,m,d;
  char a,b;
  cin >> y >> a >> m >> b >> d;
  cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  string S;
  cin >> S;
  int P = 0;
  int G = 0;
  for (int i = 0; i < int(S.size()); i++) {
    if (S.at(i) == 'p') {
      P++;
    }
    else {
      G++;
    }
  }
  cout << (P + G) / 2 - P << endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MM = 500;
const ll M = 998244353;
const int MN = 100100;
bitset<MM> bs[MM][2];
ll mul(ll a, ll b) {
	return (a*b)%M;
}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(ac,b);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll wor[MM][3];
vvi g[3];
int ro[3];
ll po[MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	memset(wor,0,sizeof(wor));
	int n;
	cin >> n;
	po[0] = 1;
	ll B = bp(10,18);
	for(int i=1;i<MN;i++) {
		po[i] = mul(po[i-1],B);
	}
	for(int i=0;i<3;i++) {
		g[i].assign(n,vi());
		int m;
		cin >> m;
		for(int j=0;j<m;j++) {
			int a,b;
			cin >> a >> b;a--;b--;
			if(a < b) {swap(a,b);}
			g[i][a].push_back(b);
		}
		int ctr = 0;
		vi cu,nu;
		for(int j=0;j<n;j++) {
			cu.push_back(j);
		}
		bitset<MN> ko;
		while(!cu.empty()) {
			ko.reset();
			nu.clear();
			for(int j=cu.size()-1;j>=0;j--) {
				int u = cu[j];
				if(ko[u]) {
					nu.push_back(u);continue;}
				wor[ctr][i] += po[u+1];
				if(wor[ctr][i] >= M) {wor[ctr][i] -= M;}
				for(int k=0;k<g[i][u].size();k++) {
					ko.set(g[i][u][k]);
				}
			}
			ctr++;
			cu = nu;
			reverse(cu.begin(),cu.end());
		}
		ro[i] = ctr;
	}
	ll res = 0;
	for(int i=0;i<ro[0];i++) {
		for(int j=0;j<ro[1];j++) {
			int re = i^j;
			if(re < ro[2]) {
				res += mul(wor[i][0],mul(wor[j][1],wor[re][2]));
			}
		}
	}
	res %= M;
	cout << res << '\n';
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll X;
    cin >> X;

    ll res = 0;
    res += (X/500)*1000;
    res += ((X%500)/5)*5;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,a,b[30]={0};
  int c,i,j;
  char s[100010];
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%s",s);
    b[s[0]-'A']++;
  }
  for(c=0;1;c++){
    for(i=0;i<26;i++){
      a=b[i];
      for(j=i;j&&b[j-1]<a;j--)b[j]=b[j-1];
      b[j]=a;
    }
    //for(i=0;i<26;i++)printf("%d ",b[i]);printf("\n");
    for(i=0;b[i];i++);
    if(i<m)break;
    for(i=0;i<m;i++)b[i]--;
  }
  printf("%d\n",c);
  return 0;
}
	


Measured memory_bytes: 128
open System 
open System.Text

type Explicit =          
    static member inline ($) (_:int32, _:Explicit) = int
    static member inline ($) (_:int64, _:Explicit) = int64

let inline convert (value:'a): 'b = 
    (Unchecked.defaultof<'b> $ Unchecked.defaultof<Explicit>) value

let inline fromInt (x: int): 'a = convert x

module NumericLiteralG =
    let inline FromZero(): ^a = LanguagePrimitives.GenericZero
    let inline FromOne(): ^a = LanguagePrimitives.GenericOne
    let inline FromInt32 n = fromInt n

let R() = Console.ReadLine()

let f (n: int) (m: int) =
    if n < m then 
        Seq.initInfinite (fun _ -> n)
        |> Seq.take m 
    else 
        Seq.initInfinite (fun _ -> m)
        |> Seq.take n 
    |> Seq.fold (fun (acc: StringBuilder) x -> acc.Append x) (StringBuilder())
    |> fun x -> x.ToString()
        
let N, M = let t = R().Split() |> Array.map (string >> int) in t.[0], t.[1]

f N M 
|> printfn "%s"

Measured memory_bytes: 29880
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
using std::swap;

int main()
{
	int a, b, t,u,i;
	cin >> a >> b >> t;
	i = (t + 0.5) / a;
	u = i*b;
	cout << u << "\n";
	return 0;	
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
    int N;
    void solve()
    {
        N = cin.nextint;
        var H = new HashSet<int>();
        for (int i = 0; i < N; i++)
        {
            int d = cin.nextint;
            if (H.Contains(d))
            {
                H.Remove(d);
            }
            else
            {
                H.Add(d);
            }
        }
        WriteLine(H.Count);
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 19408
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x: f64);
    let mut ret = 100.;
    let mut count = 0;
    while ret < x {
        ret *= 1.01;
        ret = ret.floor();
        count += 1;
    }
    println!("{}", count);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2696
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {
    int r=0, g=0, b=0, n=0;
    scanf("%d %d %d %d", &r, &g, &b, &n);
    int count = 0;
    for (int i=0; i<=n/r; i++) {
        int buf = n-r*i;
        for (int j=0; j<=buf/g; j++) {
            int buf2 = buf - g*j;
            if (buf2%b == 0) count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
N,A,B=input().split(' ')
N,A,B = [int(N),int(A),int(B)]
SUM = 0

for i in range(N+1):
	I = str(i)
	array = list(map(int, list(I)))
	s = sum(array)
	#print(s)
	if A <= s and s <= B:
		#print(i)
		SUM += i
print(SUM)

Measured memory_bytes: 3060
S = input()
dp = [[0]*13 for _ in [0]*-~len(S)]
dp[0][0] = 1
mod = 10**9 + 7

for i, s in enumerate(S):
    if s == '?':
        d = dp[i+1]
        for j in range(13):
            for k in range(10):
                x = (j*10+k) % 13
                d[x] = (d[x] + dp[i][j]) % mod
    else:
        for j in range(13):
            dp[i+1][(j*10+int(s)) % 13] = dp[i][j]
print(dp[-1][5] % mod)


Measured memory_bytes: 88792
from collections import defaultdict, Counter

H, W, N = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ctr = defaultdict(int)
for a, b in X:
    for k in range(3):
        for l in range(3):
            if 1 <= a - k <= H - 2 and 1 <= b - l <= W - 2:
                ctr[(a - k, b - l)] += 1

d = Counter(ctr.values())
for i in range(10):
    if i == 0:
        print((H - 2) * (W - 2) - sum(d.values()))
    else:
        print(d[i])


Measured memory_bytes: 170316
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,x,s=0;
    cin >> n >> k;
    
    for(int i=0; i<n; i++){
        cin >> x;
        if(x < k-x) s += 2 * x;
        else s += 2 * (k-x);
    }
    
    cout << s << "\n";
}

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

int main()
{
string s ;
cin >> s ;
rep(i,s.size()/2){
  if(s[i]!=s[s.size()-1-i])ans++;
}

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

Measured memory_bytes: 256
N=int(input())
def count753(s):
  if int(s)>N:
    return 0
  if all(s.count(c)!=0 for c in '753'):
    ret=1
  else:
    ret=0
  for i in '753':
    ret+=count753(s+i)
  return ret
print(count753('0'))

Measured memory_bytes: 2940
N = int(input())
S = []
for i in range(N):
    S.append(int(input()))

memo = {}


def solve(ind, points):
    # ending
    if ind == N:
        if points % 10 == 0:
            return 0
        else:
            return points

    if memo.get((ind, points)) is not None:
        return memo[(ind, points)]

    # transition
    ret = max(solve(ind=ind + 1, points=points + S[ind]), solve(ind=ind + 1, points=points))
    memo[(ind, points)] = ret

    return ret

print(solve(ind=0, points=0))

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

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

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

   int A,B,C,D,E,F;
   cin>>A>>B>>C>>D>>E>>F;
   set<int>wator;
   for(int i=0;100*A*i<=F;i++){
      for(int j=0;100*A*i+100*B*j<=F;j++){
         wator.insert(100*A*i+100*B*j);
      }
   }
   set<int>sato;
   for(int i=0;i*C<=F;i++){
      for(int j=0;i*C+j*D<=F;j++){
         sato.insert(i*C+j*D);
      }
   }
   double MAX = -INF;
   int ans_a;
   int ans_b;
   for(auto it1:wator){
      for(auto it2:sato){
         if(it1 !=0 &&it1+it2<=F && it2*100<=it1*E){
            if(MAX < (double)(100*it2)/(it1+it2)){
               MAX = (double)(100*it2)/(it1+it2);
               ans_a = it1+it2;
               ans_b = it2;
            }
         }
      }
   }
   cout<<ans_a<<" "<<ans_b<<endl;
   return 0;
}


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

int main(){
	int n, cnt;
	while ( cin >> n ){
		cnt = 0;
		for ( int a = 0; a < 10; ++a ){
			for ( int b = 0; b < 10; ++b ){
				for( int c = 0; c < 10; ++c ){
					for ( int d = 0; d < 10; ++d ){
						if( n == a+b+c+d ) ++cnt;
					}
				}
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let count = s
        .chars()
        .map(|e| if e == '1' { 1 } else { 0 })
        .fold(0, |acc, x| acc + x);
    println!("{}\n", count);
}

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

int main() {
   int N,M,K;
   cin >> N >> M >> K;
   long long A[N],B[M];
   for (int i=0; i<N; i++) {
       cin >> A[i];
       if (i!=0) A[i]+=A[i-1];
   }
   for (int i=0; i<M; i++) {
       cin >> B[i];
       if (i!=0) B[i]+=B[i-1];
   }
   int total=0;
   for (int i=0; i<=N; i++) {
       int count=0;
       if (i==0) {
           if (K<B[M-1]) total=lower_bound(B,B+M,K)-B;
           else total=M;
       }
       else {
       if (A[i-1]>K) break;
       if (K>=A[i-1]+B[M-1]) count=i+M;
       else {
           int a=lower_bound(B,B+M,K-A[i-1])-B;
       count=i+a;
       }
       if (count>total) {
           total=count;
       }
       }
   }
   cout << total << endl;
}

Measured memory_bytes: 6740
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  s <- group . sort <$> getLine
  putStrLn $ if all (\x -> length x `mod` 2 == 0) s then "Yes" else "No"


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

int main () {
  int H , W ;
  cin >> H >> W ;
  
  char mass[H+2][W+2] ;
  for(int i = 1 ; i <= H ; i++ ) {
    for(int j = 1 ; j <= W ; j++ ) {
      cin >> mass[i][j] ;
      if(mass[i][j] != '#') mass[i][j] = '0' ;
    }
  }
  
  for(int i = 1 ; i <= H ; i++ ) {
    for(int j = 1 ; j <= W ; j++ ) {
      if(mass[i][j] != '#') {
        for(int k = -1 ; k <= 1 ; k++ ) {
          for(int l = -1 ; l <= 1 ; l++ ){
            if(mass[i+k][j+l] == '#') mass[i][j] += 1 ;
          }
        }
        cout << mass[i][j] ;
      } else {
        cout << mass[i][j] ;
      }
      if( j == W ) cout << endl ;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
valls = list(map(int,input().split()))
 
money = 1000
have = 0

for i in range(N-1):
    if valls[i] < valls[i+1]:   
        have += money // valls[i]
        money = money % valls[i]
    elif valls[i] > valls[i+1]:
        money = money + have*valls[i]
        have = 0

money = money + have*valls[-1]
print(money)

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
 
 
 
int main(){
  long long int N,M;
  cin >> N >> M;
  if(N >= 2 && M >= 2){
    cout << (N - 2) * (M - 2) << endl;
  }
  else{
    if(N == M){
      cout << 1 << endl;
    }
    else{
      cout << (N > 1 ? N - 2 : M - 2 )<< endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a := scanInts(n)

	ans := 0

	for i := 0; i < 60; i++ {
		c0, c1 := 0, 0
		for _, e := range a {
			if e >> uint(i) & 1 == 0 {
				c0++
			} else {
				c1++
			}
		}
		ans = (ans+((c0*c1%mod)*((1 << uint(i))%mod)%mod))%mod
	}

	fmt.Println(ans)
}

const mod = 1000000007


Measured memory_bytes: 6912
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

const INF = 1000000001000

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = nextLine()
	}

	alpha := map[string]int{}

	for _, abc := range "abcdefghijklmnopqrstuvwxyz" {
		alpha[string(abc)] = INF
	}

	for _, ss := range s {
		m := map[string]int{}
		for _, abc := range "abcdefghijklmnopqrstuvwxyz" {
			m[string(abc)] = 0
		}

		for _, sss := range ss {
			m[string(sss)]++
		}

		for k, v := range m {
			alpha[k] = min(v, alpha[k])
		}
	}
	var ans []string
	for k, v := range alpha {
		if v != 0 {
			ans = append(ans, strings.Repeat(k, v))
		}
	}
	sort.Strings(ans)
	fmt.Println(strings.Join(ans, ""))

}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 768
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int N, T;
  cin >> N >> T;
  vector<Pi> AB(N);
  FOR(i, N) cin >> AB[i].first >> AB[i].second;
  vector<ll> dp(T);
  sort(ALL(AB), [](const Pi& l, const Pi& r) {
    return l.second == r.second ? l.first > r.first : l.second > r.second;
  });
  ll ans = 0;
  FORIN(target, 1, min(N, 70)) {
    FOR(i, T) dp[i] = 0;
    FORIN(i, 1, N + 1) {
      for (int j = T - 1; j >= 0; --j) {
        if (j >= AB[i - 1].first && i != target)
          dp[j] = max(dp[j], dp[j - AB[i - 1].first] + AB[i - 1].second);
      }
    }
    ans = max(ans, dp[T - 1] + AB[target - 1].second);
  }
  sort(ALL(AB), [](const Pi& l, const Pi& r) {
    return l.first == r.first ? l.second > r.second : l.first > r.first;
  });
  FORIN(target, 1, min(N, 70)) {
    FOR(i, T) dp[i] = 0;
    FORIN(i, 1, N + 1) {
      for (int j = T - 1; j >= 0; --j) {
        if (j >= AB[i - 1].first && i != target)
          dp[j] = max(dp[j], dp[j - AB[i - 1].first] + AB[i - 1].second);
      }
    }
    ans = max(ans, dp[T - 1] + AB[target - 1].second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;

int main() {
  cin >> N;
  int rawN = N;
  int SN = 0;
  while (N) {
    SN += N % 10;
    N /= 10;
  }

  if (rawN % SN == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    int ans = a[n - 1] - a[0];
    rep(i,n - 1){
        ans = min(ans, k - abs(a[i] - a[i + 1]));
    }
    cout << ans << endl;
}


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

int main()
{
    int N, L, tmp,count=0,out=0;
    cin >> N>>L;
    
    vector<string> str(N);
    vector<int> num(N);
    for (int i = 0; i < N;i++){
        cin >> str.at(i);
    }

    for (int i = 0; i < N;i++){
        for (int j = 0; j < N;j++){
            tmp = str.at(i).compare(str.at(j));
            if(tmp>0){
                count++;
            }
        }
        num.at(i) = count;
        //cout << num.at(i) << endl;
        count = 0;
    }
    for (int i = 0; i < N;i++){
        for (int j = 0; j < N;j++){
            if(i==num.at(j)){
                cout << str.at(j);
            }
        }
    }
    cout << endl;

    /*
    vector<vector<char>> str(N, vector<char>(L));
    for (int i = 0; i < N;i++){
        for (int j = 0; j < L;j++){
            cin >> str.at(i).at(j);
        }
    }
    tmp = strcmp(str.at(0).at(0), str.at(1).at(0));
    */


}

Measured memory_bytes: 256