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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N;
    cin >> N;
    set<string> st;
    rep(i, 0, N) {
        string q;
        cin >> q;
        string s;
        cin >> s;
        if (q == "insert") {
            st.insert(s);
        } else {
            if (st.find(s) != st.end()) // set::contains()はC++20以降
                cout << "yes\n";
            else
                cout << "no\n";
        }
    }
}



Measured memory_bytes: 29064
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int N = 1e5 + 7;
int dp[N];
int visited[N];

int dfs(int v,vector<int>adjlist[],int n){
	visited[v] = true;
	for(auto it: adjlist[v]){
		if(!visited[it]){
			dfs(it,adjlist,n);
		}
		dp[v] = max(dp[v],1+dp[it]);
	}
}


int32_t main()
{	
	Fast_IO
	#ifdef __WIN32 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w",stdout);
	#endif
	int n,m;
	cin>>n>>m;
	vector<int>adjlist[n];
	while(m--){
		int a,b;
		cin>>a>>b;
		adjlist[a-1].push_back(b-1);
	}		
	for(int i=0;i<n;i++){
		if(!visited[i]){
			dfs(i,adjlist,n);
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		ans = max(ans,dp[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 9984
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	while (1) {
		auto n = readln.chomp.to!int;
    if (!n) break;
    auto f = new bool[][](n, n);
    auto a = new int[][](n, n);
    auto b = new int[][](n, n);
    foreach (i; 0..n) {
      a[i] = readln.chomp.split.map!(to!int).array;
      auto m = a[i].reduce!(min);
      foreach (j; 0..n) {
        b[j][i] = a[i][j];
        if (a[i][j] == m) {
          f[i][j] = 1;
        }
      }
    }
    int res;
    foreach (j; 0..n) {
      auto m = b[j].reduce!(max);
      foreach (i; 0..n) {
        if (b[j][i] == m && f[i][j]) {
          res = m;
        }
      }
    }
    res.writeln;
	}
}

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

using namespace std;

const int N = 500005;

int n, p[2][N];
char s[N];

int main() {
    scanf("%s", s);
    n = strlen(s);
    for (int id = 0; id < 2; ++id) {
        int j = 0;
        for (int i = 1; i < n; ++i) {
            while (j > 0 && s[i] != s[j]) j = p[id][j - 1];
            if (s[i] == s[j]) ++j;
            p[id][i] = j;
        }
        reverse(s, s + n);
    }
    int len = n - p[0][n - 1];
    if (len == n || n % len != 0) {
        cout << 1 << endl << 1 << endl;
        return 0;
    }
    if (len == 1) {
        cout << n << endl << 1 << endl;
        return 0;
    }
    int cnt = 0;
    for (int i = 0; i < n - 1; ++i) {
        int pos = n - (i + 1) - 1;
        int len[2] = {i + 1 - p[0][i], n - i - 1 - p[1][pos]};
        if ((len[0] == i + 1 || (i + 1) % len[0] != 0) && ((n - i - 1) % len[1] != 0 || len[1] == n - i - 1)) {
            ++cnt;
        }
    }
    cout << 2 << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  string S; cin >> S;
  int N = S.size();
  bool flag = false;
  string ans;
  if (N < 26) {
    flag = true;
    ans = S;
    set <char> data;
    rep(i,N) data.insert(S[i]);
    rep(i,26) {
      if (!data.count(char(i + 'a'))) {
        ans.push_back(char(i + 'a'));
        break;
      }
    }
  } else if (N == 26) {
    set<char> data;
    for (int i = 25; i > 0; i--) {
      data.insert(S[i]);
      if (S[i-1] < S[i]) {
        flag = true;
        ans = S.substr(0,i-1);
        for (auto j : data) {
          if (j > S[i-1]) {
            ans.push_back(j);
            break;
          }
        }
        break;
      }
    }
  }

  if (flag) cout << ans << endl;
  else cout << -1 << endl;
}

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

a.sort()
ans = 0
hoge = a[0]
count = 1
for i in range(1,N):
     if a[i] == hoge:
         count += 1
     else:
         if count >= hoge:
             ans += count-hoge
         else:
             ans += count
         hoge = a[i]
         count = 1
if count >= hoge:
    ans += count - hoge
else:
    ans += count

print(ans)


Measured memory_bytes: 14820
#include <stdio.h>

typedef	unsigned long long ull;

ull temp[100000];    /* 最小でも配列と同じサイズの領域が必要 */
ull op_temp[100000];    /* 最小でも配列と同じサイズの領域が必要 */

void MergeSort(ull x[], ull op[], ull left, ull right)
{
    ull mid, i, j, k;
	
    if (left >= right)              /* 配列の要素がひとつなら */
        return;                     /* 何もしないで戻る */

                                    /* ここでは分割しているだけ */
    mid = (left + right) / 2;       /* 中央の値より */
    MergeSort(x, op, left, mid);        /* 左を再帰呼び出し */
    MergeSort(x, op, mid + 1, right);   /* 右を再帰呼び出し */

      /* x[left] から x[mid] を作業領域にコピー */
    for (i = left; i <= mid; i++){
        temp[i] = x[i];
		op_temp[i] = op[i];
	}
      /* x[mid + 1] から x[right] は逆順にコピー */
    for (i = mid + 1, j = right; i <= right; i++, j--){
        temp[i] = x[j];
		op_temp[i] = op[j];
	}

    i = left;         /* i とj は作業領域のデーターを */
    j = right;        /* k は配列の要素を指している */

    for (k = left; k <= right; k++)    /* 小さい方から配列に戻す */
        if (temp[i] <= temp[j]){        /* ここでソートされる */
			op[k] = op_temp[i];
            x[k] = temp[i++];
		}
        else{
			op[k] = op_temp[j];
            x[k] = temp[j--];
		}
}

int main(void)
{
	ull n, m;
	ull a[100000], b[100000];
	ull buy_m=0, sum_money=0;
	ull i, j;
	
	scanf("%lld %lld", &n, &m);
	for(i=0; i<n; i++)
		scanf("%lld %lld", &a[i], &b[i]);
	
	MergeSort(a, b, 0,n-1);
	//for(i=0; i<n; i++)
	//	printf("%lld %lld\n", a[i], b[i]);

	for(i=0; i<n; i++){
		if(buy_m+b[i] < m){
			buy_m += b[i];
			sum_money += a[i]*b[i];
		}
		else{
			ull diff_m = m-buy_m;
			sum_money += a[i]*diff_m;
			break;
		}
	}

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

	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

bool solve(vector<ll> v,ll idx){
    ll sz=v[idx];
    bool f=true;
    for(int i=0;i<(int)v.size();i++){
        if(i==idx) continue;
        if(v[i]<=2*sz){
            sz+=v[i];
        }
        else{
            f=false;
            break;
        }
    }
    return f;
}

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

    int n;cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    ll low=0,high=n-1;
    for(int i=0;i<30;i++){
        ll mid=low+(high-low)/2;
        if(solve(a,mid)){
            high=mid;
        }
        else low=mid;
    }
    if(solve(a,low)) cout<<n-low<<endl;
    else cout<<n-low-1<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<P> hp1(n);
	REP(i,n) cin>>hp1[i].first>>hp1[i].second;
	vector<P> sorting(n);
	REP(i,n) {
		sorting[i].first=hp1[i].first+hp1[i].second;
		sorting[i].second=i;
	}
	sort(ALL(sorting));
	vector<P> hp(n);
	REP(i,n) {
		hp[i]=hp1[sorting[i].second];
	}
	vector<vector<ll>> dp(n,vector<ll>(n+1,INF*INF));
	dp[0][0]=0;
	dp[0][1]=hp[0].second;
	FOR(i,1,n) {
		REP(j,n+1) {
			if(j==0) dp[i][j]=0;
			else {
				if(hp[i].first>=dp[i-1][j-1]) dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+hp[i].second);
				else dp[i][j]=dp[i-1][j];
			}
		}
	}
	ll ret=0;
	REP(i,n+1) {
		if(dp[n-1][i]!=INF*INF) ret=i;
	}
	cout<<ret<<endl;
}



Measured memory_bytes: 196096
#include<stdio.h>

int main()
{
      int inputK,inputN,firstRow[3],secondRow[3],thirdRow[3];
      
      // Create a array for every row in a bingo and fill it with values
      scanf("%d%d%d",&firstRow[0],&firstRow[1],&firstRow[2]);
    
      scanf("%d%d%d",&secondRow[0],&secondRow[1],&secondRow[2]);
    
      scanf("%d%d%d",&thirdRow[0],&thirdRow[1],&thirdRow[2]);
      
      // Check if values in bingo are the same with the input
      scanf("%d",&inputN);
      for(int i=0;i<inputN;i++)
      {
        scanf("%d",&inputK);
          
        for(int j=0;j<3;j++)
        {
          if(firstRow[j]==inputK) firstRow[j]=1;
        }
        for(int j=0;j<3;j++)
        {
          if(secondRow[j]==inputK) secondRow[j]=1;
        }
        for(int j=0;j<3;j++)
        {
          if(thirdRow[j]==inputK) thirdRow[j]=1;
        }
          
      }
      
      // Print 'Yes' if you have bingo, 'No' if there are no same values in row / columns / curves
      if((firstRow[0]==1 && firstRow[1]==1 && firstRow[2]==1) || (secondRow[0]==1 && secondRow[1]==1 && secondRow[2]==1) || (thirdRow[0]==1 && thirdRow[1]==1 && thirdRow[2]==1))
         {
          printf("Yes\n");
          }
      else if((firstRow[0]==1 && secondRow[0]==1 && thirdRow[0]==1) || (firstRow[1]==1 && secondRow[1]==1 && thirdRow[1]==1) || (firstRow[2]==1 && secondRow[2]==1 && thirdRow[2]==1))
      {
          printf("Yes\n");
      }
      else if((firstRow[0]==1 && secondRow[1]==1 && thirdRow[2]==1) || (firstRow[2]==1 && secondRow[1]==1 && thirdRow[0]==1))
      {
         printf("Yes\n");
      }
      else
      {
         printf("No\n");
      }
      return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>

#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++)
#define all(x) (x).begin(),(x).end()

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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;




int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  int h,w;
  cin>>h>>w;
  int d[10][10];
  rep(i,10)rep(j,10)cin>>d[i][j];
  rep(k,10)rep(i,10)rep(j,10)chmin(d[i][j],d[i][k]+d[k][j]);
  int res=0;
  rep(i,h)rep(j,w){int a;cin>>a;if(a>=0)res+=d[a][1];}
  cout<<res<<endl;
  return 0;

}


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

using lint = long long;

vector<vector<int>> edges;
array<int, 100015> dp, seen;
int result;

void dfs(int v) {
    seen[v] = 1;
    for (int u : edges[v]) {
        if (!seen[u]) dfs(u);
        dp[v] = max(dp[v], 1 + dp[u]);
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    edges.resize(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
    }
    for (int i = 0; i < n; ++i) if (!seen[i]) dfs(i);
    for (int i = 0; i < n; ++i) result = max(result, dp[i]);
    cout << result << '\n';
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;
vector<int> arr, brr;
vector<vector<int>> dp;

int solve(int i, int j)
{
    if (j <= 0)
        return 0;
    if (i < 0)
        return INF;

    if (dp[i][j] != -1)
        return dp[i][j];

    dp[i][j] = min(solve(i - 1, j), brr[i] + solve(i, j - arr[i]));

    return dp[i][j];
}

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

    arr.assign(n, 0);
    brr.assign(n, 0);

    for (int i = 0; i < n; i++)
    {
        cin >> arr[i] >> brr[i];
    }

    dp.assign(n, vector<int>(h + 1, -1));

    cout << solve(n - 1, h) << endl;
}

Measured memory_bytes: 39424
function Main(input) {
  input = input.split("\n");
  var S = input[0].split("/");
  var ans = "Heisei";
  if(parseInt(S[0])>=2020||(parseInt(S[0])>=2019&&parseInt(S[1])>=5)){
    ans ="TBD";
  }


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

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

    int    n;
    int    s[1000];
    double ans = 0;
    while (cin >> n, n) {
        double sum      = 0;
        double ave      = 0;
        double variance = 0;
        rep(i, n) {
            cin >> s[i];
            sum += s[i];
        }
        ave = sum / n;
        rep(i, n) { variance += (s[i] - ave) * (s[i] - ave) / n; }
        ans = sqrt(variance);
        cout << ans << "\n";
    }

    return 0;
}



Measured memory_bytes: 3280
elems = STDIN.read.lines.map { |x| x.split(/\s+/).map(&:to_i) }[1..-1]
a = elems.shift.sort
elems.sort! { |x, y| y[1] <=> x[1] }
b, max_c = elems.shift

for i in 0...a.size
  if a[i] < max_c
    b.times { |j| a[i + j] = max_c if (i + j < a.size) and (a[i + j] < max_c) }
    break if elems.size == 0
    b, max_c = elems.shift
    i += b
  end
end
puts a.reduce { |s, x| s + x }

Measured memory_bytes: 31080
#include <iostream>
#include<math.h>
using namespace std;

int main() {
  int n,m,i,a[1000000],add=0;
  cin>>n>>m;
  for(i=0;i<m;i++){
    cin>>a[i];
    add+=a[i];
  }
  
  
  n-=add;
  if(n>=0){
    cout<<n<<endl;
  }else{
    cout<<"-1"<<endl;
  }
  
  
}



Measured memory_bytes: 3204
/*
	************	************    ************	***      ***	************	***               ***
	************	************    ************	****     ***	************	 ***             ***
	***      ***	***      ***    ***      ***	*****    ***	***      ***	  ***           ***
	***      ***	***      ***    ***      ***	******   ***	***      ***	   ***         ***
	************	************    ************	*** ***  ***	************	    ***       ***
	************	************    ************	***  *** ***	************	     ***     ***
	***				***   ***       ***      ***	***   ******	***      ***	      ***   ***
	***				***    ***      ***      ***	***    *****	***      ***	       *** ***
	***				***     ***     ***      ***	***     ****	***      ***	        *****
	***				***      ***    ***      ***	***      ***	***      ***	         ***
*/

#define named(blockname) goto blockname; \
                         blockname##_skip: if (0) \
                         blockname:

#define break(blockname) goto blockname##_skip
// #include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define readarr(a,n) for (int i=0; i<n; i++) {cin>>a[i];}
#define printarr(a,n) for (int i=0; i<n; i++) {cout<<a[i]<<' ';}
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vint vector <int>
#define pb push_back
#define pf push_front
#define endl "\n"

signed main() {
	
	fast ;
	
	ll q ;
	// cin >> q ;
	q = 1 ;
	while(q--)
	{
		ll a ;
		cin>>a ;
		set<string> s ;
		
		for (ll i = 0; i < a; i++)
		{
			string n ;
			cin >> n ;
			s.insert(n) ;
		}
		cout << s.size() ;
	}
	
	return 0;
}

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

int rec(int n, string base) {
  if (base.length() == n) {
    cout << base << endl;
    return 0;
  } else {
    int cmax = *max_element(base.begin(),base.end()) - 'a' + 1;
    if (base.empty()) cmax=0;
    rep(i,cmax+1) {
      char c = 'a' + i;
      rec(n, base + c);
    }
  }  
}
int main() {
  int n;cin>>n;
  rec(n,"");
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>

// This algorithm runs in O(nk)
void Frog2(int& n, int& k, int stones[])
{
    int minCost[n];
    minCost[0] = 0;

    for (int i = 1; i < n; i++) minCost[i] = __INT_MAX__;

    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j <= std::min(n - 1, i + k); j++)
        {
            minCost[j] = std::min(minCost[j], minCost[i] + abs(stones[j] - stones[i]));
            // printf("minCost[j]: %d\n", minCost[j]);
            // printf("j: %d\n", j);
        }
    }

    printf("%d\n", minCost[n-1]);
}

int main()
{   
    int n;
    int k;

    scanf("%d", &n);
    scanf("%d", &k);

    int stones[n];

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

    Frog2(n, k, stones);

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    double x;
    string v;
    
    double ans=0;
    for(int i=0;i<N;++i){
        cin>>x>>v;
        if(v=="JPY"){
           ans+=x;
        }
        else if(v=="BTC"){
            ans+=x*380000;
        }
      
    }
      cout<<ans<<endl;
}

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

typedef long long ll;

int main(){
    int n, k;
    ll l, r;
    cin >> n >> k >> l >> r;

    ll a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];

    int left = n/2;
    int right = n - left;

    vector<ll> va[left+1], vb[right+1];

    for(int i = 0; i < 1<<left; i++){
        ll sum = 0;
        int popcnt = 0;
        for(int j = 0; j < left; j++){
            if(i>>j & 1)    sum += a[j], popcnt++;
        }
        va[popcnt].push_back(sum);
    }

    for(int i = 0; i < 1<<right; i++){
        ll sum = 0;
        int popcnt = 0;
        for(int j = 0; j < right; j++){
            if(i>>j & 1)    sum += a[left+j], popcnt++;
        }
        vb[popcnt].push_back(sum);
    }

    for(int i = 0; i <= left; i++)   sort(va[i].begin(), va[i].end());
    for(int i = 0; i <= right; i++)  sort(vb[i].begin(), vb[i].end());

    ll ans = 0;
    for(int i = 0; i <= left; i++){
        if(i + right < k)   continue;
        if(i > k)   break;

        for(int j = 0; j < va[i].size(); j++){
            ll tmp = va[i][j];
            ans += max(0ll, (ll)(upper_bound(vb[k-i].begin(), vb[k-i].end(), r-tmp) - 
                            lower_bound(vb[k-i].begin(), vb[k-i].end(), l-tmp)));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 23436
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0;
  char b[5];
  cin>>b;
  for(int i=0;i<4;i++){
    if(b[i]=='+')
      a++;
    else
      a--;
  }
  cout<<a<<endl;
  return(0);
}

Measured memory_bytes: 256
h,w=map(int,input().split())

if h>=3 and w>=3:
    print((h-2)*(w-2))
elif w==2 or h==2:
    print(0)
elif w==1 and h>=3:
    print(h-2)
elif h==1 and w>=3:
    print(w-2)
else:
    print(1)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define pair pair<int,int>
typedef long long ll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

class UnionFind{
    vector<int> par; vector<int> r_size;
    public:
        UnionFind(int N) : par(N),r_size(N){
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

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

        int find(int x){
            if(par[x] == x)return x;
            return par[x]=find(par[x]);
        }

        //xとyとが所属する集合を併呑する
        void unite(int x,int y){
            int rx = find(x); int ry = find(y);
            if(rx == ry) return;
            if(r_size[rx]<r_size[ry]) swap(rx,ry);
            r_size[rx] += r_size[ry];
            par[ry] = rx;
        }

        bool same(int x, int y){
            int ry = find(x); int rx = find(y);
            return rx == ry;
        }

        int el_size(int x){
            return r_size[find(x)];
        }
};

int main(){
    int n,m; cin>>n>>m; int a,b;
    vector<pair> input(m); rep(i,m){cin>>a>>b; input[i].first = --a; input[i].second = --b;}

    int ans = 0;
    rep(i,m){
        UnionFind graph(n);
        rep(j,m){
            if(j != i)graph.unite(input[j].first,input[j].second);
        }
        if(graph.el_size(0) < n)ans++;
    }
    cout<<ans<<endl; return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> ans(n);
  rep(i,n-1) {
    int a;
    cin >> a;
    a--;
    ans[a]++;
  }
  for (auto x : ans) {
    cout << x << endl;
  }
  return(0);
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int count_5 = 0,count_7 = 0;
    for(int i = 0;i < 3;i++)
    {
        if(a[i] == 5)
        {
            count_5++;
        }
        else if(a[i] == 7)
        {
            count_7++;
        }
    }
    if(count_5 == 2 && count_7 == 1)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
    
    return 0;
}

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



int main() {
  int N,i,j;
  cin>>N;
  vector<int> a(N,0);
  vector<int> state(N,0);
  for(i=0;i<N;i++){
    cin>>a.at(i);
  }
  int index=1;
  int ret=-1;
  int count=0;
  while(1){
    if (index==a.at(index-1)){
      ret=-1;
      break;
    }else{
      index=a.at(index-1);
      count++;
      if(index==2){
        ret=count;
        break;}
  }
  if(count>N)break;
}
cout<<ret<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
//#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

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

int mod ;

class numberTheory{

public:
    numberTheory(){}

    pii extendedEuclid(i64 a, i64 b) { // returns x, y | ax + by = gcd(a,b)

        if(b == 0) return pii( a >= 0 ? 1 : -1 , 0LL);
        else {
            pii d = extendedEuclid(b, a % b);
            return pii(d.yy, d.xx - d.yy * (a / b));
        }

    }

    i64 modularInverse(i64 a, i64 n) {
        pair<i64,i64> ret = extendedEuclid(a, n);
        return ((ret.xx % n) + n) % n;
    }


    i64 bigMod(i64 a, i64 n , i64 m)
    {
        if(n==0) return 1 ;
        i64 ret = bigMod(a,n/2,m) ;
        ret = (ret*ret)%m ;
        if(n%2) ret = (ret*a)%m ;
        return ret ;
    }
};

const i64 N = 200000 ;

i64 fact[N+5] , invFact[N+5] ;

i64 C(i64 n, i64 r)
{
    if( n<0 || r<0 || r>n ) return 0 ;
    i64 ret = (fact[n]*invFact[r])%mod ;
    return (ret*invFact[n-r])%mod ;
}

void preprocess()
{
    numberTheory nt ;

    fact[0] = 1 ;
    for(i64 x=1 ; x<=N ; x++) fact[x] = (fact[x-1]*x)%mod ;

    invFact[N] = nt.modularInverse(fact[N],mod) ;

    for(i64 x=N-1 ; x>=0 ; x--) invFact[x] = (invFact[x+1]*(x+1) )%mod ;
}

numberTheory nt ;
int n ;

int p1[3005] , p2[3005*3005] ;
int st[3005][3005] ;

int s(int n , int k)
{
    return (st[n][k] + 1LL*(k+1)*st[n][k+1])%mod ;
}

int f(int k )
{
    i64 ans = 0 ;

    for(int i=0 ; i<=k ; i++)
    {
        int ret = ( 1LL*p1[n-k]*p2[i*(n-k)] )%mod ;
        ret = (1LL*ret*(( st[k][i] + 1LL*st[k][i+1]*(i+1) )%mod) )%mod ;
    //    ret = (1LL*ret*nt.bigMod(2,1LL*i*(n-k),mod))%mod ;

        ans = (ans+ret) ;
    }

    return ans%mod ;
}

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

    preprocess() ;

    st[0][0] = 1 ;

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=i ; j++) st[i][j] = ( st[i-1][j-1] + 1LL*j*st[i-1][j] )%mod ;
    }

    for(int i=0 ; i<=n ; i++) p1[i] = nt.bigMod( 2 , nt.bigMod(2,i,mod-1) , mod ) ;
    p2[0] = 1 ;
    for(int i=1 ; i<=n*n ; i++) p2[i] = (2LL*p2[i-1])%mod ;

    int ans = nt.bigMod( 2 , nt.bigMod(2,n,mod-1)  , mod ) ;
  //  cout<<ans<<endl ;

    for(int i=1 ; i<=n ; i++)
    {
        int ret = (1LL*C(n,i)*f(i))%mod ;
      //  cout<<ret<<endl ;
        if( i%2 == 1 ) ans = (ans-ret)%mod ;
        else ans = (ans+ret)%mod ;
    }

    ans = (ans%mod + mod)%mod ;

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

    return 0 ;
}


Measured memory_bytes: 72704
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    ll T;
    cin >> T;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]>>B[i]
    ;}
    //dp[i][j]はi番目までをみて、j分以下かかるときの最大食量
    vector<vector<ll>> dp(N, vector<ll>(T+1, 0));
    //dp2[i][j]はi番目までをみて、j分以下かかるときの最大食量
    vector<vector<ll>> dp2(N, vector<ll>(T+1, 0));
    for(ll i=0;i<N;i++){
     for(ll j=0;j<=T;j++){
         if(i==0){
            if(j>=A[0])dp[i][j]=B[0];
         }
         else{
             if(j<A[i])dp[i][j]=dp[i-1][j];
             else dp[i][j]=max(dp[i-1][j],dp[i-1][j-A[i]]+B[i]);
         }
     ;}
    ;}
    for(ll i=N-1;i>=0;i--){
     for(ll j=0;j<=T;j++){
         if(i==N-1){
            if(j>=A[N-1])dp2[i][j]=B[N-1];
         }
         else{
             if(j<A[i])dp2[i][j]=dp2[i+1][j];
             else dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i]);
         }
     ;}
    ;}
    ll ans=0;
    for(ll i=0;i<N;i++){
     for(ll j=0;j<=T-1;j++){
         if(i!=0&&i!=N-1)
         ans=max(ans,B[i]+dp[i-1][j]+dp2[i+1][T-1-j]);
         else if(i==0){
             ans=max(ans,B[i]+dp2[i+1][T-1-j]);
         }
         else if(i==N-1){
             ans=max(ans,B[i]+dp[i-1][j]);
         }
     ;}
    ;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int h, n;
    cin >> h >> n;
    while(n--){
        int x;
        cin >> x;
        h -= x;
    }
    if(h <= 0) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int hundred = N / 100;
        int one = N % 10;
        
        System.out.println((hundred == one)? "Yes" : "No");
    }
}


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

using namespace std;

int main(){
  int N, sum_a=0, sum_b=0, a[100];

  cin >> N;
  for(int i=0; i<N; i++)  cin >> a[i];

  sort(a, a+N, greater<int>());
  
  for(int i=0; i<N; i=i+2) sum_a+=a[i];
  for(int i=1; i<N; i=i+2) sum_b+=a[i];

  cout << sum_a - sum_b << endl;

}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll d,n;
    cin >> d >> n;
    if(d==0){
        if(n==100) cout << 101 << "\n";
        else cout << n << "\n";
    }else if(d==1){
        if(n==100) cout << 10100 << "\n";
        else cout << n*100 << "\n";
    }else{
        if(n==100) cout << 1010000 << "\n";
        else cout << n*10000 << "\n";
    }
    return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int k, t = 0, ans = 0;
    cin >> k;
    do {
        bool f = true;
        for (int i = 0; i <= 9; ++i) {
            if ((t + k * i) % 10 == 7) {
                t = (t + k * i) / 10;
                f = false;
                break;
            }
        }
        if (f) {
            ans = -1;
            break;
        }
        ans++;
    } while (t > 0);

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N+1);

  for(int i = 1; i <= N; i++){
    cin >> v[i];
  }

  int i = 1;
  int cnt = 0;
  int flag = 0;
  for(int j = 1; j <= N; j++){
    cnt++;
    if(v[i] == 2){
      flag = 1;
      break;
    }
    else{
      i = v[i];
    }
  }

  if(flag){
    cout << cnt << endl;
  }
  else{
    cout << "-1" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
ans = 1

for i in range(N):
  ans = ans * A[i]
  if abs(ans) > 10**18:
    ans = -1
    break
c = 1
for i in range(N):
  if A[i] == 0:
    c = 0
    break
print(ans*c)


Measured memory_bytes: 21652
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
const int mod = 998244353;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<int>l(n), r(n);
	rep(i, k) {
		cin >> l[i] >> r[i];
	}
	vector<ll>dp(n);
	vector<ll>sum(n+1);
	dp[0] = 1;
	sum[0] = 0;

	rep(i, n) {
		if (i == 0)continue;
		sum[i] = sum[i - 1] + dp[i-1];
		//cout << sum[i] << endl;
		rep(j, k) {
			if (l[j] > i)continue;
			int kk = min(r[j], i)+1;
			//cout << kk << " ";
			dp[i] += sum[i - l[j] + 1] - sum[i - kk+1 ];
			
		}
		dp[i] %= mod;
		//cout << dp[i] <<" "<< sum[i]<<endl;
	}
	//cout << endl;
	cout << dp[n-1];
	return 0;
}

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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int x[101],y[101],a[101];
    int xma = 0;
    int yma = 0;
    int xmi = w;
    int ymi = h;
    for (int i=1; i<=n; i++) {
        cin >> x[i] >> y[i] >> a[i];
        if (a[i] == 1) xma = max(x[i], xma);
        else if (a[i] == 2) xmi = min(x[i], xmi);
        else if (a[i] == 3) yma = max(y[i], yma);
        else if (a[i] == 4) ymi = min(y[i], ymi);
    }
    if (xmi <= xma || ymi <= yma) {
        cout << 0 << endl;
        return 0;
    }
    else {
        int ans = (xmi - xma) * (ymi - yma);
        cout << ans << endl;
        return 0;
    }
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  ll x;
  cin >> N >> x;
  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(i < N-1){
      if(x >= v[i]){
        ans++;
        x -= v[i];
      } else{
        break;
      }
    } else { 
      if( x == v[i]){
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

class unionfind
{
public:
  vector<int> parent;

  unionfind(int N)
  {
    parent = vector<int>(N, -1);
  }

  int root(int X)
  {
    if (parent.at(X) < 0) return X;
    return parent.at(X) = root(parent.at(X));
  }

  int size(int X)
  {
    return -parent.at(root(X));
  }

  bool unite(int X, int Y)
  {
    int x = root(X);
    int y = root(Y);
    if (x == y) return false;
    
    if (size(x) < size(y)) swap(x, y);
    parent.at(x) += parent.at(y);
    parent.at(y) = x;
    return true;
  }
};

signed main()
{
  int N;
  cin >> N;
  vector<pair<int, int>> x(N);
  vector<pair<int, int>> y(N);
  for (int i = 0; i < N; i++)
  {
    cin >> x.at(i).first >> y.at(i).first;
    x.at(i).second = i;
    y.at(i).second = i;
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  vector<tuple<int, int, int>> E;
  for (int i = 0; i < N - 1; i++)
  {
    E.push_back(make_tuple(x.at(i + 1).first - x.at(i).first, 
                           x.at(i).second, x.at(i + 1).second));
    E.push_back(make_tuple(y.at(i + 1).first - y.at(i).first, 
                           y.at(i).second, y.at(i + 1).second));
  }

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

  unionfind uf(N + 10);
  
  int ans = 0;
  for (int i = 0; i < E.size(); i++)
  {
    if (uf.unite(get<1>(E.at(i)), get<2>(E.at(i))))
      ans += get<0>(E.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 11632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D,N;
  cin>>D>>N;
  if(D==0 && N!=100){
    cout<<N<<endl;
  }
  else if(D==0 && N==100){
    cout<<101<<endl;
  }
  else if(D==1 && N!=100){
    cout<<100*N<<endl;
  }
  else if(D==1 && N==100){
    cout<<10100<<endl;
  }
  else if(D==2 && N!=100){
    cout<<10000*N<<endl;
  }
  else if(D==2 && N==100){
    cout<<1010000<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
struct cordinates{
	int x,y;
};
cordinates compmul(int a,int b,int c,int d){
	int ans1,ans2;
	ans1=a*c;
	ans1-=b*d;
	ans2=b*c;
	ans2+=a*d;
	cordinates ans;
	ans.x=ans1;
	ans.y=ans2;
	return ans;
}
int main() {
	cordinates a,b;
	sd(a.x);sd(a.y);sd(b.x);sd(b.y);
	cordinates c,d;
	int k1,k2;
	k1=b.x-a.x;
	k2=b.y-a.y;
	d=compmul(k1,k2,0,1);
	d.x+=a.x;
	d.y+=a.y;
	k1=a.x-d.x;
	k2=a.y-d.y;
	c=compmul(k1,k2,0,1);
	c.x+=d.x;
	c.y+=d.y;
	pds(c.x);pds(c.y);pds(d.x);pds(d.y);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&b>0){
		c-=b;
		if(c>0)
			a-=d;
		else{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3620
import collections
n=int(input())
a=list(map(int,input().split() ))
absa=[]
za=[]
for i in range(n):
    za.append(a[i]-(i+1))
#print(za)
#print(sum(za))
za.sort()
z=sum(za)
#print(z)
if n%2==1:
    b=za[n//2]
else:
    b=(za[n//2-1]+za[n//2])//2

#print(b)
for i in range(n):
    absa.append(abs(a[i]-(b+(i+1))))
#print(absa)
print(sum(absa))


Measured memory_bytes: 27660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll M = 1e6;
const double eps = 1e-6;

ll a[N],res[20];

inline void print(ll *x){
	bool f = 0;
	for(int i = 9;i >= 0;--i){
		if(f) printf("%06lld",x[i]);
		else if(x[i]) printf("%lld",x[i]),f = 1;
	}
	return ;
}

inline bool mul(ll p){
	ll temp[20] = {0};
	ll c[20] = {0};
	
	int pos = 0;
	while(p) temp[pos++] = p%M,p /= M;
	//print(temp);
	
	for(int i = 0;i < 10;++i)
		for(int j = 0;j < 10;++j)
			c[i+j] += res[i]*temp[j];
	ll x = 0ll;
	for(int i = 0;i < 10;++i){
		res[i] = (c[i]+x)%M;
		x = (c[i]+x)/M;
	}
	//print(res);
	
	if(res[3] > 1) return 0;
	if(res[3] == 1 && (res[2] || res[1] || res[0])) return 0;
	return 1;
}

int main()
{
	int n;
	scanf("%d",&n);
	bool f = 0;
	for(int i = 1;i <= n;++i){
		scanf("%lld",&a[i]);
		if(!a[i]) f = 1;
	}
	
	if(f){
		printf("0\n");
		return 0;
	}
	
	res[0] = 1ll;
	for(int i = 1;i <= n;++i){
		if(!mul(a[i])){
			printf("-1\n");
			return 0;
		}
	}
	print(res);
	return 0;
}

Measured memory_bytes: 4568
import Control.Monad
import Control.Monad.ST
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map as M
import Data.Array.ST
import Data.Array.IArray

mapFromList :: Ord a => [(a,a)] -> M.Map a [a]
mapFromList []           = M.empty
mapFromList ((x1,x2):xs) = M.insertWith (\[a] b -> a:b) x1 [x2]
                         $ M.insertWith (\[a] b -> a:b) x2 [x1]
                         $ mapFromList xs

solve :: Int -> [(Int,Int)] -> [(Int,Int)] -> ST s (STUArray s Int Int)
solve n a p = do
    let m = mapFromList a
        ia = listArray (1,n) $ map (\i ->
            M.findWithDefault [] i m) [1..n] :: Array Int [Int]
    ma <- newArray (1,n) 0
    mapM_ (\(a,b) -> do
        v <- readArray ma a
        writeArray ma a (b + v)) p
    dfs ia ma 1 (-1)
    return ma
  where
    dfs :: Array Int [Int] ->  STUArray s Int Int -> Int -> Int -> ST s ()
    dfs ia ma i p = do
        pv <- readArray ma i
        forM_ (filter (/=p) (ia!i)) (\j -> do
            cv <- readArray ma j
            writeArray ma j (cv + pv)
            dfs ia ma j i)

main :: IO ()
main = do
    let tuple [a,b] = (a,b)
    [n,q] <- map read . words <$> getLine :: IO [Int]
    a <- replicateM (n-1) $ tuple
        . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    p <- replicateM q $ tuple
        . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    mapM_ print . elems $ runSTUArray $ solve n a p


Measured memory_bytes: 123772
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    double L;
    cin >> L;
    cout << fixed << setprecision(10) << L / 3.0 * L / 3.0 * L / 3.0;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

template<class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class TIn, class TOut = null_type>
using order_tree = tree<TIn, TOut, less<TIn>, rb_tree_tag,
	tree_order_statistics_node_update>;

constexpr int INF = 2000000010;
constexpr ll LLINF = 9000000000000000010LL;

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

	int n;
	cin >> n;
	int last = -1, ans = 0, c;
	while (n--) {
		cin >> c;
		if (c == last) {
			++ans;
			last = -1;
		} else last = c;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int w, a, b;
    
    cin >> w >> a >> b;
    
    if((a-w <= b)&&(b <= a+w)) {
        cout << "0\n";
    } else if(a+w < b) {
        cout << b-(a+w) << "\n";
    } else {
        cout << a-(b+w) << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m=0;
	int a[102],i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a[i]);
	}
	for(i=0,j=1;j<n;i++,j++)
	{
		if(a[i]==a[j])
		{
			a[j]=0;
			m++;
		}
	}
	printf("%d",m);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,min,min1,min2;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>b)
        min1=b;
    else
        min1=a;
    if(c>d)
        min2=d;
    else
        min2=c;
    min=min1+min2;
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t x; cin >> x;
	int64_t a = 100;
	for(int i = 1; ; ++i) {
		a = a + a / 100;
		if(a >= x) {
			cout << i << '\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	long long N, T;
	cin>> N >> T;
	long long Time = 0;
	long long l = 0, r = 0;
	while (N--){
		long long Ti = 0;
		cin>> Ti;
		if (Ti < l && Ti + T >= l){
			l = Ti;
		} else if (Ti <= r && Ti + T > r){
			r = Ti + T;
		} else{
			Time += r - l;
			l = Ti;
			r = Ti + T;
		}
	}
	Time += r - l;
	cout<< Time <<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
    #define ll long long int
    #define FF first
    #define SS second
    #define mp make_pair
    #define pb push_back
    #define pii pair<int,int>
    #define pll pair<long long int,long long int>
    #define sd(x) scanf("%d",&x)
    #define slld(x) scanf("%lld",&x)
    #define pd(x) printf("%d\n",x)
    #define plld(x) printf("%lld\n",x)
    #define pss printf
    #define MOD 1000000007
    #define INF 1e18
    #define eps 0.00001
    #define endl '\n'
    #define debug(n1) cout<<n1<<endl
    const int N = 1e5;  // limit for array size
    ll n;  // array size
     
    /*template<typename T>
    using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
     
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int rand(int l, int r){
        uniform_int_distribution<int> uid(l, r);
        return uid(rng);
    }
    */
    int main(){
        unordered_map<string,ll>mpp;
        ll n;cin>>n;
        string s;
        for(int i=0;i<n;i++){
        	cin>>s;
        	sort(s.begin(),s.end());
        	mpp[s]++;
		}
		
		ll ans=0;
		unordered_map<string, ll>::iterator itr; 
		for(itr=mpp.begin();itr!=mpp.end();itr++){
			ll temp=itr->second;
			ans+=(temp*(temp-1))/2;
		}
		cout<<ans<<endl;
    	return 0;
    }

Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1e9+7;
vector<int> a(100005,0);

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int x;
    cin>>x;
    a[x]++;
  }
  if(n%2==0){
    ll ans=1;
    for(int i=1;i<=n/2;i++){
      if(a[2*i-1]!=2){
        cout<<0<<endl;
        return 0;
      }
      ans = ans<<1;
      ans = ans % mod;
    }
    cout<<ans<<endl;
  }
  else{
    ll ans=1;
    if(a[0]!=1){
      cout<<0<<endl;
      return 0;
    }
    for(int i=1;i<=n/2;i++){
      if(a[2*i]!=2){
        cout<<0<<endl;
        return 0;
      }
      ans = ans << 1;
      ans = ans % mod;
    }
    cout<<ans<<endl;
  }
return 0;
}

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

using namespace std;

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl

const int maxn = (int)3e5+5;
typedef long long ll;

int main()
{
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //cout << "Fi Amanillah" << endl;
    string s,t;
    cin >> s >> t;
    int cnt=0;
    for(int i=0 ; i<(int)s.size() ; i++){
      if(s[i]!=t[i]){
         cnt++;
      }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3832
object Main {
  def main(args: Array[String]): Unit = {
    val Array( animals_num, total_foots_num ) = io.StdIn.readLine.split(" ").map{_.toInt}
    var flag = false

    ( 0 to animals_num ).foreach{ i =>
      val turtles_num = animals_num - i
      val cranes_num  = i
      if( turtles_num*4 + cranes_num*2 == total_foots_num ) flag = true
    }

    if ( flag ) println( "Yes" )
    else        println( "No" )
  }
}

Measured memory_bytes: 54740
import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [tuple(map(int, input().split())) for i in range(Q)]

d = collections.defaultdict(int)

S = sum(A)

for x in A:
    d[x] += 1

for B, C in BC:
    diff = C - B
    S += d[B]*diff
    d[C] += d[B]
    d[B] = 0
    print(S)


Measured memory_bytes: 35660