akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define ll long long int
#define MOD 1000000007LL
using namespace std;

int main() {
    ll n,t;
    cin>>n>>t;
    ll a;
    ll b[114514];
    cin>>a;
    ll m=a;
    ll ma=0;
    for(int i=1;i<n;i++){
        cin>>a;
        b[i]=(t/2)*(a-m);
        m=min(m,a);
        ma=max(ma,b[i]);
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        if(b[i]==ma){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
import random, time
start = time.time()
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
#貪欲初期解
t = []
memo = [0 for _ in range(26)]
for i in range(d):
    scores = []
    for j in range(26):
        delta_score = 0
        delta_score += s[i][j]
        for k in range(26):
            if j == k:
                continue
            delta_score -= c[k] * (i+1 - memo[k])
        scores.append((delta_score, j))

    scores.sort(key=lambda x: -x[0])
    choice = scores[0][1]
    t.append(choice)
    memo[choice] = i+1

#局所探索
def delta_scoring(t, x, y):
    delta_score = 0
    before_ti, after_ti = 0, d+1
    before_y, after_y = 0, d+1

    for i in range(x):
        if t[i] == t[x]:
            before_ti = i+1
        if t[i] == y:
            before_y = i+1

    for i in range(x+1, d):
        if t[i] == t[x]:
            after_ti = i+1
            break
    for i in range(x+1, d):
        if t[i] == y:
            after_y = i+1
            break

    delta_score -= s[x][t[x]]
    delta_score += s[x][y]
    delta_score -= c[t[x]] * (x + 1 - before_ti) * (after_ti - x - 1)
    delta_score += c[y] * (x + 1 - before_y) * (after_y - x - 1)

    return delta_score

while time.time() - start < 1.0:
    x = random.randint(0, d-1)
    y = random.randint(0, 25)
    if delta_scoring(t, x, y) > 0:
        t[x] = y


for i in range(d):
    print(t[i] + 1)

Measured memory_bytes: 81924
#include <stdio.h>

int main(void)
{
	char input[1004] = {'\0'};
	int i;
	
	if (fgets(input, 1002, stdin) != NULL) {
		i = strlen(input) - 1;
		if (input[i-1] == 's') {
			input[i] = 'e';
			input[i+1] = 's';
			input[i+2] = '\0';
		} else {
			input[i] = 's';
			input[i+1] = '\0';
		}
		printf("%s", input);
	}
	return 0;
}

Measured memory_bytes: 1644
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}


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

	vector<int>vec(n);
	rep(i, n) {
		cin >> vec[i];
	}

	int ans = abs(x - vec[0]);
	rep(i, n) {
		int a = abs(x - vec[i]);
		ans = gcd(ans, a);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main() {
	int a, b, c, d, e, f;
	scanf("%d %d %d %d %d %d", &a, &b, &c,&d,&e,&f);
	if (a + b * 5 + c * 10 + d * 50 + e * 100 + f * 500 >= 1000)
		printf("1\n");
	else printf("0\n");
	return 0;
}


Measured memory_bytes: 2612
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

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

typedef long long ll;

using namespace std;

const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  ll n;
  cin >> n;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];

  ll ans=1e+18;
  for(ll i=1; i<=100; i++){
    ll tmp=0;
    rep(j,n){
      tmp+=pow(x[j]-i,2);
    }
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;

#define MAXN 100
struct point{
    int x,y;
}R[MAXN+5],B[MAXN+5];
int N;

bool vis[2*MAXN+5];
int Match[2*MAXN+5];
vector<int> G[2*MAXN+5];
bool dfs(int u){
    for(int i=0;i<int(G[u].size());i++){
        int v=G[u][i];
        if(!vis[v]){
            vis[v]=1;
            if(!Match[v]||dfs(Match[v])){
                Match[v]=u;
                Match[u]=v;
                return 1;
            }
        }
    }
    return 0;
}

int Solve(){
    int Ans=0;
    for(int i=1;i<=N;i++)
        if(!Match[i]){
            memset(vis,0,sizeof vis);
            Ans+=dfs(i);
        }
    return Ans;
}

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d%d",&R[i].x,&R[i].y);
    for(int i=1;i<=N;i++)
        scanf("%d%d",&B[i].x,&B[i].y);
    int Ans=0;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=N;j++)
            if(R[i].x<B[j].x&&R[i].y<B[j].y)
                G[i].push_back(j+N);
    N*=2;
    printf("%d",Solve());
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    double ans = 1. * ((n + 1) / 2) / n;

    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll a[200005];
int u[200005], v[200005];

ll dp[200005];
vector<int> G[200005];
bool used[200005];
int ans[200005];

const ll INF = 2e15;

void dfs(int v, int d){
    used[v] = true;
    auto p = lower_bound(dp, dp+N+4, a[v]);
    int dif = p-dp;
    ll pre = dp[dif];
    dp[dif] = min(a[v], dp[dif]);
    ans[v] = lower_bound(dp, dp+N+4, INF)-dp;
    for(int to : G[v]){
        if(!used[to]){
            dfs(to, d+1);
        }
    }
    dp[dif] = pre;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N-1; i++){
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
        G[u[i]].push_back(v[i]);
        G[v[i]].push_back(u[i]);
    }
    for(int i = 0; i <= 200004; i++) dp[i] = INF+i; 
    // dp[0] = a[0];
    // ans[0] = 1;
    dfs(0, 1);
    for(int i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 34472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    double t = A;
    int ans = 0;
    while (t < T + 0.5)
    {
        t += A;
        ans += B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
/// ye tec khaphan ke yadam bemone : age jayi didi soale masir hamiltoni mikhad rasasho bokon yal oilery;https://mobomovie1.top/series/%D8%AF%D8%A7%D9%86%D9%84%D9%88%D8%AF-%D8%B3%D8%B1%DB%8C%D8%A7%D9%84-%D9%81%D8%B1%DB%8C%D9%86%D8%AC-fringe-2008-2013-%D8%A8%D8%A7-%D8%B2%D9%8A%D8%B1%D9%86%D9%88%D9%8A%D8%B3-%D9%81%D8%A7%D8%B1/
/// age ye ja mikhasti to dp az ozv i k ta entekhab koni bejash ye log bezan (nominal) hamoon 2**k va o 1 ent kon
const int N=2e5+100,inf=1e9+100;
ll t[N];
ll a[N];
ll c[N];
int32_t main(){
    sync;
    ll n,m;
    cin >> n >> m;
    ll ans=0;
    for (int i=1;i<=n;i++){
        ll x;
        cin >> x;
        c[i]=x;
        if (!t[x]){
            t[x]++;
            a[x]++;
            if (a[x]==1)
                ans++;
          //  cout << x << endl;
        }
        else{
            t[x]++;
            if (x-t[x]+1>0 && a[x-t[x]+1]==0){
                ans++;
            }
            if (x-t[x]+1>0)
                a[x-t[x]+1]++;
          //  cout << x << " " << x-t[x]+1 << endl;
        }
    }
   // cout << ans << endl;
    for (int i=0;i<m;i++){
        ll id,x;
        cin >> id >> x;
        ll v=c[id];
        if (v-t[v]+1>0)
            a[v-t[v]+1]--;
        if (v-t[v]+1>0 && a[v-t[v]+1]==0){
            ans--;
        }
       // for (int j=1;j<=5;j++){
         //   cout << j << " " << t[j] << " " << a[j] << " " << ans << endl;
        //}
        t[v]--;
        //cout << endl;
        c[id]=x;
        t[x]++;
        if (x-t[x]+1>0 && a[x-t[x]+1]==0){
            ans++;
        }
        if (x-t[x]+1>0)
            a[x-t[x]+1]++;
       // for (int j=1;j<=5;j++){
         //   cout << j << " " << t[j] << " " << a[j] << endl;
        //}
        cout << n-ans << '\n';
    }

}


Measured memory_bytes: 8336
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
double a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    double dp[n+1][n+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0){
                dp[i][j]=(1-a[i-1])*dp[i-1][j];
            }
            else{
                dp[i][j]=a[i-1]*dp[i-1][j-1]+(1-a[i-1])*dp[i-1][j];
            }
        }
    }
    double ans=0;
    for(int i=0;i<=n;i++){
        if(n/2<i){
            ans+=dp[n][i];
        }
    }
    cout <<setprecision(15) <<ans << "\n";
}



Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  vector<vector<ll>> dp(s.size() + 1, vector<ll>(2, INF));
  dp[0][0] = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 2; j++) {
      if (j == 1 && s[i] == '9')
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][1]);
      int d = s[i] - '0' + j;
      dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + d);
      dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - d));
    }
  }
  cout << min(dp[s.size()][0], dp[s.size()][1] + 1) << endl;
}


Measured memory_bytes: 55940
K = int(input())
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = 0
a = []
glist = [[0 for i in range(K+1)] for j in range(K+1)]
for i in range(1,K+1):
    for j in range(1,K+1):
        g = gcd(i,j)
        a.append(g)
        glist[i][j] = g

for i in a:
    for j in range(1,K+1):
        ans += glist[i][j]
print(ans)
            

Measured memory_bytes: 73064
#include<bits/stdc++.h>
#define int long long
using namespace std;


signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	vector<int>dp(n, 1);
	for (int i = 1; i < n; i++) {
		if (a[i] <= a[i - 1])dp[i] = dp[i - 1] + 1;
	}
	int mx = 0;
	for (auto now : dp)mx = max(mx, now);
	cout << mx - 1;
	return 0;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)

typedef long long ll;
const int INF = 100000000;
double EPS = 1e-10;

const int M = 100;
const int N = 100;
int m, n;
int xm[M], ym[M];
int xn[N], zn[N];

//特定の平面で切った時の断面で幅が有界なものの値を計算
double width(int *X, int *Y, int k, double x) {
	double lb = INF, ub = -INF;
	for (int i=0; i<k; i++) {
		double x1 = X[i], y1 = Y[i], x2 = X[(i+1)%k], y2 = Y[(i+1)%k];

		//i-thの辺と交点を持つか調べる
		if ((x1-x)*(x2-x) <= 0 && x1 != x2) {
			double y = y1 + (y2-y1)*(x-x1)/(x2-x1);
			lb = min(lb, y);
			ub = max(ub, y);
		}
	}
	return max(0.0, ub-lb);
}

void solve() {
	//区間の端点を列挙
	int min1 = *min_element(xm, xm+m), max1 = *max_element(xm, xm+m); 
	int min2 = *min_element(xn, xn+n), max2 = *max_element(xn, xn+n); 
	vector<int> xs;
	for (int i=0; i<m; i++) xs.push_back(xm[i]);
	for (int i=0; i<n; i++) xs.push_back(xn[i]);
	sort(xs.begin(), xs.end());

	double res = 0.0;
	for (int i=0; i+1<xs.size(); i++) {
		double a = xs[i], b = xs[i+1], c = (a+b)*0.5;
		if (min1<=c && c<=max1 && min2<=c && c<=max2) {
			//二つの立体が交差しない場合,cが少なくとも一方の立体に含まれない
			//ので計算対象から除外(上のif文はこのため)
			//Simpson
			double fa = width(xm, ym, m, a) * width(xn, zn, n, a);
			double fb = width(xm, ym, m, b) * width(xn, zn, n, b);
			double fc = width(xm, ym, m, c) * width(xn, zn, n, c);
			res += (b-a)/6.0 * (fa + fc*4.0 + fb);
		}
	}
	printf("%.10f\n", res);
}

int main() {
	int i, j;

	while (1) {
		scanf("%d%d ", &m, &n);
		if (!m && !n) break;
		for (i=0; i<m; i++) scanf("%d%d ", xm+i, ym+i);
		for (i=0; i<n; i++) scanf("%d%d ", xn+i, zn+i);
		solve();
	}

	return 0;
}

Measured memory_bytes: 1248
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve()
{
    int n ;
    cin >> n ;
    vector<pii> p;
    for(int i = 2 ; i * i <= n ; ++i){
        if(n % i) continue ;
        p.pb({i , 0});
        while(n % i == 0) p.back().ss++ , n /= i ;
    }
    if(n > 1) p.pb({n , 1});
    int ans = 0;
    for(pii x : p){
        int c = x.ss; 
        // cout << x.ff << ' ' << x.ss << '\n';
        int cur = 0;
        while( cur * (cur + 1) / 2 <= c ) cur++ ;
        cur--;
        ans += cur ;
    }
    cout << ans ;
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1 << 16;
const int MOD = 1e9 + 7;
vector<int> specials;
int memo[17][MAX], inv[MAX], inv_fat[MAX];
int fat[MAX], pot[17];

inline int add(int a, int b) {
	a += b;
	if(a >= MOD) {
		a -= MOD;
	}
	return a;
}

inline int sub(int a, int b) {
	a -= b;
	if(0 > a) {
		a += MOD;
	}
	return a;
}

inline int mult(int a, int b) {
	return (1LL * a * b) % MOD;
}

int f_exp(int x, int exp) {
	if(exp == 0) {
		 return 1;
	}
	else if(exp & 1) {
		return mult(x, f_exp(x, exp - 1));
	}
	return f_exp(mult(x, x), exp / 2);
}

inline int comb(int n, int k) {
	return mult(fat[n], mult(inv_fat[n - k], inv_fat[k]));
}

int n, m;
int roll(int index, int mask) {
	int &ans = memo[index][mask];
	if(~ans) {
		return ans;
	}

	int left = pot[n] - 1;
	fori(i, 0, n) {
		if(mask & (1 << i)) {
			left -= pot[i];	
		}
	}

	if(index == m) {
		int bits = __builtin_popcount(mask);

		ans = fat[left];
		if(bits & 1) {
			ans = ((-ans % MOD) + MOD) % MOD;
		}
	}
	else {
		int used = pot[n] - 1 - left;
		ans = roll(index + 1, mask);
		fori(i, 0, n) {
			if(!(mask & (1 << i))) {
				int available = pot[n] - specials[index] - used;
				int need = (1 << i) - 1;
				if(available >= need) {
					int cur = mult(comb(available, need), fat[need + 1]); 
					cur = mult(cur, roll(index + 1, mask | (1 << i)));
					ans = add(ans, cur);		
				}
			}
		}
	}
	
	return ans;
}

int main() {
	fat[0] = fat[1] = inv[1] = inv_fat[0] = inv_fat[1] = 1;
	fori(i, 2, MAX) {
	    fat[i] = mult(fat[i - 1], i);
	    int q = MOD / i, r = MOD % i;
	    inv[i] = mult(-q, inv[r]);
	    inv[i] += MOD;
	    inv_fat[i] = mult(inv_fat[i - 1], inv[i]);
	}


	pot[0] = 1;
	fori(i, 1, 17) {
		pot[i] = mult(pot[i - 1], 2);
	}

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

	specials.resize(m);
	fori(i, 0, m) {
		scanf("%d", &specials[i]);
	}

	sort(specials.begin(), specials.end(), greater<int>());

	memset(memo, -1, sizeof memo);

	int ans = roll(0, 0);
	ans = mult(ans, pot[n]);

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

	return 0;
}


Measured memory_bytes: 5500
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;
const int INF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,A[MAXN];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	FOR(i,1,N) cin>>A[i];
	FOR(i,1,N){
		if (A[i]==0) {
			cout<<0;
			exit(0);
		}
	}
	__int128 cur = 1;
	FOR(i,1,N){
		cur *= A[i];
		if (cur > INF){
			cout<<-1;
			exit(0);
		}
	}
	int ans = cur;
  if (ans > INF) cout<<-1;
	else cout<<ans;
}


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

int main(){
    int a;
    cin >>a;
    if(a%7 ==1) cout<<"fri";
    if(a%7 ==2) cout <<"sat";
    if(a%7 ==3) cout<<"sun";
    if(a%7 ==4) cout<<"mon";
    if(a%7 ==5) cout<<"tue";
    if(a%7 ==6) cout<<"wed";
    if(a%7 ==0) cout<<"thu";
    cout <<endl;
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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 MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{

    ll n;
    cin >> n;
    vll ans;
    rep(i, n + 1)
    {
        if (i == 0)
        {
            ans.pb(2);
        }
        if (i == 1)
        {
            ans.pb(1);
        }

        if (i >= 2)
        {
            ans.pb(ans[i - 1] + ans[i - 2]);
        }
    }
    cout << ans[n] << endl;
}


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

int main() {
	
	string s;
	cin >> s;
	bool flg{};
	if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)) flg=1;
	if(s.at(1)==s.at(2)&&s.at(3)==s.at(2)) flg=1;
	cout << (flg?"Yes":"No") << endl;
	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  cin >> n;
  map<char, ll> s;
  rep(i,n) {
    string t; cin >> t;
    char c = t[0];
    s[c]++;
  }
  ll ans = 0;
  char v[5] = {'M','A','R','C','H'};

  rep(i,3) {
    for (int j = i+1; j < 4; j++)
    {
      for (int k = j+1; k < 5; k++)
      {
        ans += s[v[i]] * s[v[j]] * s[v[k]];
      }
      
    }
    
  }
  cout  << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#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++)
typedef long long ll;

int main() {
    string C;
    string D;
    cin >> C >> D;
    if (C[0] == D[2] && C[1] == D[1] && C[2] == D[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B, C, D;
	int min;

	scanf("%d %d %d %d", &A, &B, &C, &D);
	
	min = A + C;
	if (min > A + D) min = A + D;
	if (min > B + C) min = B + C;
    if (min > B + D) min = B + D;

	printf("%d", min);

		return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> pl;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  sort(s.begin(),s.end());

  bool c=0;
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])
  c=1;

  cout<<(c==1?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){

  ll n;
  cin >> n;

  std::vector<ll> l(n);
  rep(i,n){
    cin >> l.at(i);
  }

  sort(all(l));

  ll h=0,w=0;
  for(ll j=n-2;j>=0;j--){
    if(l.at(j)==l.at(j+1) && h==0){
      h=l.at(j);
      j--;
    }
    else if(l.at(j)==l.at(j+1) && h!=0){
      w=l.at(j);
      j--;
    }
    else if(h*w!=0){
      break;
    }
  }


  ll rec;
  rec=h*w;
  cout << rec << endl;

  }


Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int min = Integer.MAX_VALUE, minIndex = -1;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] > max && i != minIndex) {
                max = arr[i];
            }
        }
        System.out.println(max - min);
    }
}


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

long long elem_cnt[60];
long long patties[60];

long long cnt(long long num, int level) {
  if (level == 0) {
    return 1;
  } else {
    if (num == 1) {
      return 0;
    } else if (1 < num && num < elem_cnt[level] / 2 + 1) {
      return cnt(num - 1, level - 1);
    } else if (num == elem_cnt[level] / 2 + 1) {
      return patties[level - 1] + 1;
    } else if (elem_cnt[level] / 2 + 1 < num && num < elem_cnt[level]) {
      return patties[level - 1] + 1 + cnt(num - ( elem_cnt[level] / 2 + 1 ), level - 1);
    } else if (num == elem_cnt[level]) {
      return patties[level - 1] * 2 + 1;
    }
  }
}

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

  elem_cnt[0] = 1;
  patties[0] = 1;
  for (int i = 0; i <= N ; i++) {
    elem_cnt[i + 1] = 2 * elem_cnt[i] + 3;
    patties[i + 1] = 2 * patties[i] + 1;
  }
  cout << cnt(X, N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int h, w, c[15][15];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w;
	FOR(i, 10) FOR(j, 10) {
		cin >> c[i][j];
	}
	FOR(k, 10) FOR(i, 10) FOR(j, 10) {
		c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
	}
	int ret = 0;
	FOR(i, h) FOR(j, w) {
		int a;
		cin >> a;
		if (a!=-1) ret += c[a][1];
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int LB[100100], UB[100100], INF = 1<<30;
vector<int> adj[100100];

bool check(int v, int p, int r) {
    if (LB[v] == UB[v] && (LB[v] - r) % 2 != 0) return false;
    for (int u : adj[v]) if (u != p && !check(u, v, 1-r)) return false;
    return true;
}

bool dfs(int v, int p) {
    for (int u : adj[v]) {
        if (u == p) continue;
        if (!dfs(u, v)) return false;
        UB[v] = min(UB[v], UB[u]+1);
        LB[v] = max(LB[v], LB[u]-1);
    }
    return LB[v] <= UB[v];
}

void reconstruct(int v, int p, int val) {
    UB[v] = val;
    for (int u : adj[v]) {
        if (u == p) continue;
        reconstruct(u, v, val+1 <= UB[u] ? val+1 : val-1);
    }
}

int main() {
    int n; cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int k; cin >> k;
    
    for (int i = 0; i < n; i++) { LB[i] = -INF; UB[i] = INF; }
    while (k--) {
        int v, p; cin >> v >> p;
        v--;
        LB[v] = p;
        UB[v] = p;
    }
    if ((check(0, -1, 0) || check(0, -1, 1)) && dfs(0, -1)) {
        cout << "Yes\n";
        reconstruct(0, -1, UB[0]);
        for (int i = 0; i < n; i++) cout << UB[i] << endl;
    } else
        cout << "No\n";
}


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

int main() {
  string S;
  int N, K;
  
  cin >> N >> K;
  cin >> S;
  
  string answer = S;
  if (S.at(K-1) == 'A'){
    answer.at(K-1) = 'a';
  }else if (S.at(K-1) == 'B'){
    answer.at(K-1) ='b';
  }else{
    answer.at(K-1) ='c';
  }
  
  cout << answer <<endl;
    
}

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

int main() {
  int l,r;
  cin>>l>>r;
  int mod=2019;
  if(r-l<mod){
    int a=l%mod;
    int b=r%mod;
    if(a<b){
      int p=8101919;
      for(int i=a;i<b;i++){
        for(int j=i+1;j<=b;j++){
          p=min(p,(i*j)%mod);
        }
      }
      cout<<p<<endl;
    }
    else{
      cout<<0<<endl;
    }
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
function main()
  
  N = parse(Int, readline())
  A = map(x -> parse(Int, x), split(readline()))
  
  unshift!(A, 0)
  push!(A, 0)
  
  N += 2
  
  sum_abs = 0
  price = []
  
  for i in 1:N-1
    num = abs(A[i] - A[i+1])
    sum_abs	+= num
    push!(price, num)
  end
  
  for i in 1:N-2
    println(sum_abs - price[i] - price[i+1] + abs(A[i] - A[i+2]))
  end
  
end

main()

Measured memory_bytes: 153536
#include<bits/stdc++.h>
using namespace std;
    int a,b;
    string ans;
    void s(int x,int y,string ans){
        if(x==a && y==b){
            cout<<ans<<endl;
            return;
        }
        if(x==5 && y<4)return;
        if(y==5 && x<4)return;
        if(x==y && x==5)return;

        else{
            if(x<=a)s(x+1,y,ans+'A');
            if(y<=b)s(x,y+1,ans+'B');
        }

    }
int main(){
    cin>>a>>b;
    s(0,0,"");
    return 0;
}

Measured memory_bytes: 3116
#include <cstdio>
#include <algorithm>

int n, m;


int main(){
    while(scanf("%d %d", &n, &m) != EOF){
        if(n == 0 && m == 0) break;

        int p[1000];
        std::fill(p, p + 1000, 0);
        for(int i = 0; i < n; i++){
            scanf("%d", &p[i]);
            p[i] = -p[i];
        }

        std::sort(p, p + n);

        int ans = 0;
        for(int i = 0; i < n; i++){
            if((i + 1) % m == 0) continue;
            ans += p[i];
        }

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

    return 0;
}

Measured memory_bytes: 2824
import sys
import math

N = int(input())

ans = 0
for i in range (1,N+1):
    for j in range (1,i+1):
        for k in range (1,j+1):
            if i == j == k:
                ans += math.gcd(math.gcd(i,j),k)
            elif i == j or j== k:
                ans += 3*math.gcd(math.gcd(i,j),k)
            else:
                ans += 6*math.gcd(math.gcd(i,j),k)
            #print(i,j,k)
         
            
print(ans)


Measured memory_bytes: 9192
#include <iostream>
using namespace std;
int main() {
    int cnt=0,t1=0,t2=-1;
    int N;
    cin >> N;
    int A[N],B[N],C[N];
    for (int i=0; i<N;   i++) cin >> A[i];
    for (int i=0; i<N;   i++) cin >> B[i];
    for (int i=0; i<N-1; i++) cin >> C[i];
    for (int i=0; i<N; i++) {
        t1 = A[i];
        cnt += B[t1-1];
        if (t1 == t2+1) cnt += C[t2-1];
        t2 = t1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import re

s=input()

def isBoin(f):
  if f == "a" or f == "i" or f == "u" or f == "e" or f == "o":
    return True
  else:
    return False

n = s[0]
f = s[1]
if isBoin(n) == True:
  n += s[1]
  n += s[2]
else:
  n += s[1]
  n += s[2]
print(n)

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

int main(){
    string s;
    cin>>s;
    unordered_map<char,int> um;
    for(int i=0;i<s.size();++i){
        if(islower(s[i]))um[s[i]]++;
    }
    
    for(auto it = um.begin();it!=um.end();++it){
        if(it->second&1){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

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

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


int h, w, a[31][31];
P d[31][31];


ll dfs() {
	queue<P>q;
	q.push(P(0, 0));
	while (!q.empty()) {
		P p = q.front();
		q.pop();
		for (int i = 0;i < 4;i++) {
			int ni = p.fr + di[i], nj = p.sc + dj[i];
			if (ni < 0 || nj < 0 || ni >= h || nj >= w)continue;
			if (d[ni][nj].fr <= d[p.fr][p.sc].fr + a[ni][nj] + d[p.fr][p.sc].sc * 2 * a[ni][nj])continue;
			d[ni][nj].fr = d[p.fr][p.sc].fr + a[ni][nj] + d[p.fr][p.sc].sc * 2 * a[ni][nj];
			d[ni][nj].sc = d[p.fr][p.sc].sc + 1;
			q.push(P(ni, nj));
		}
	}
	return d[h - 1][w - 1].fr;
}

int main() {
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> a[i][j];
			if (i == 0 && j == 0)d[i][j] = P(0, 0);
			else d[i][j] = P(INF, INF);
		}
	}
	cout << dfs() << endl;
	return 0;
}


Measured memory_bytes: 3172
# -*- coding: utf-8 -*-

N, K = [int(i) for i in input().split()]
H = [int(input()) for i in range(N)]

sorted_H = sorted(H)
distance = 1000000000
for i in range(N-K+1):
    if sorted_H[i+K-1] - sorted_H[i]  < distance:
        distance = sorted_H[i+K-1] - sorted_H[i]
print(distance)


Measured memory_bytes: 8280
# エラトステネスの篩
N = int(input())


def make_prime_table(N):
    sieve = [0] * (N + 1)
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, N + 1):
        if sieve[i] != 0:
            continue
        sieve[i] = i
        for j in range(i * i, N + 1, i):
            if sieve[j] == 0:
                sieve[j] = i
    return sieve


def f(X):
    t = []
    a = X
    while a != 1:
        if len(t) != 0 and t[-1][0] == prime_table[a]:
            t[-1][1] += 1
        else:
            t.append([prime_table[a], 1])
        a //= prime_table[a]
    result = 1
    for _, n in t:
        result *= n + 1
    return result


prime_table = make_prime_table(N)
result = 0
for K in range(1, N + 1):
    result += K * f(K)
print(result)


Measured memory_bytes: 152496
#include <bits/stdc++.h>
using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(i, a, b) for (int i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int maxi1 = 0, maxi2 = 0, ii = 0;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        if (a > maxi1)
        {
            maxi2 = maxi1;
            maxi1 = a;
            ii = i;
        }
        else if (a > maxi2)
        {
            maxi2 = a;
        }
    }
    rep(i, 0, n)
    {
        if (i == ii)
        {
            cout << maxi2 << endl;
            continue;
        }
        cout << maxi1 << endl;
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
int main(){
	ll n, k, mod = 998244353;
	cin >> n >> k;
	ll l[k], r[k], a[n];
	for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
	for (int i = 0; i < n; i++){
		if (i == 0) a[i] = 1;
		else if (i == 1) a[i] = 0;
		else a[i] = a[i - 1];
		for (int j = 0; j < k; j++){
			if (i - l[j] >= 0) (a[i] += a[i - l[j]]) %= mod;
			if (i - r[j] - 1 >= 0) (a[i] += mod - a[i - r[j] - 1]) %= mod;
		}
	}
	printf("%lld\n", a[n - 1]);
}

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

using namespace std;

int main(void){
    string s;
    s.reserve(10e5+1);
    int ans = 0;

    cin >> s;

    //操作
    for(int i=0; i<s.length()/2; i++){
        if(s[i]==s[s.length()-1-i])
            continue;
        if(s[i] == 'x'){
            s.insert(s.end()-i, 'x');
            ans++;
        }else if(s[s.length()-i-1] == 'x'){
            s.insert(s.begin()+i, 'x');
            ans++;
        }
    }
    //チェック
    for(int i=0; i<s.length()/2; i++){
        if(s[i]!=s[s.length()-1-i]){
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i,n) for(int i=0;i<n;++i)
#define Fo(i,k,n) for(int i=k;i<n;++i)
typedef long long int lli;
int main(){
    FIO
    int N,X,T; cin>>N>>X>>T;
    if(N%X!=0) cout<<(N/X+1)*T<<endl;
    else cout<<(N/X)*T<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi a(n), b(n);
    ll cnt = 0;
    rep(i, n) cin >> a[i] >> b[i];

    for(ll i=n-1; i>=0; i--){
        if((a[i]+cnt)%b[i] == 0) continue;
        else cnt += (b[i] - ((a[i]+cnt)%b[i]));
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4768
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, cnt1, cnt2, cnt3, cnt;
string s;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		int len = s.length();
		if (s[0] == 'B' && s[len - 1] == 'A') {
			cnt1++;
		}
		else if (s[0] == 'B') {
			cnt2++;
		}
		else if (s[len - 1] == 'A') {
			cnt3++;
		}
		for (int j = 0; j < len - 1; j++) {
			if (s[j] == 'A' && s[j + 1] == 'B') cnt++;
		}
	}
	int ans = 0;
	if (cnt1)
		ans += cnt1 - 1;
	ans += min(cnt2, cnt3);
	if (cnt2 != cnt3 && cnt1) ans++;
	else if (cnt2 && cnt2 == cnt3 && cnt1) {
		ans++;
	}
	ans += cnt;
	cout << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N=int(input())
cost=[0]*(N+1)

h=[0]
hh=list(map(int,input().split(" ")))
h.extend(hh)
h[0]=h[1]
#print(h)

cost[1]=0
#print(cost)
  
for i in range(2,N+1):
  cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]))
  #print(i,cost[i-1],abs(h[i]-h[i-1]),cost[i-2],abs(h[i]-h[i-2]))
#print(cost)

print (cost[N])

Measured memory_bytes: 14748
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    double a[]=new double[n];
    double x=0;
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      x+=(1/a[i]);
    }
    sc.close();
    System.out.println((1/x));
  }
}

Measured memory_bytes: 21844
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        if (n<r||n<0||r<0) return 0;
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
 	ll i=0, j;
	for(i=0; i<=N; i++) {
	    j = K-A*i;
        if(j < 0) break;
		if(j%B) continue;
    	ans = (ans+(fact.comb(N,i)*fact.comb(N,j/B)%MOD))%MOD;
	}
    // ll g = gcd(A, B);
    // if(K%g==0) {
    //     ll ca=B/g, cb=A/g;
    //     size_t i=0, j;
    //     while((K-A*i)%B && i<=N) i++;
    //     j = (K-A*i)/B;
    //     while(i <= N && j >= 0 && j <= N) {
    //         ans = (ans+(fact.comb(N,i)*fact.comb(N,j)%MOD))%MOD;
    //         i += ca; j -= cb;
    //     }
    // }
    cout << ans << endl;
	return 0;
}


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

int main(void) {
	int a, b;
	int ans;
	char op;
	while(1) {
		scanf("%d %c %d", &a, &op, &b);
		if(op == '+') ans = a + b;
		else if(op == '-') ans = a - b;
		else if(op == '*') ans = a * b;
		else if(op == '/') ans = a / b;
		else if(op == '?') break;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

//using LL = long long;
using namespace std;

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

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n, A[100], mini, count = 0;
    cin >> n;
    for (int i = 0; i < n; i++)cin >> A[i];

    for (int i = 0; i < n - 1; i++){
        mini = i;
        for (int j = i + 1; j < n; j++){
            if (A[j] < A[mini])
                mini = j;
        }

        if (i != mini){
            count++;
            swap(A[i], A[mini]);
        }
    }

    for (int i = 0; i < n; i++){
        if (i) cout << ' ';
        cout << A[i];
    }
    cout << endl << count << endl;

    return 0;
}


Measured memory_bytes: 3100
n = int(input())
edges = {}
dist = {}
con = {}

for i in range(n-1):
  a, b, c = map(int, input().split())
  edges[frozenset([a, b])] = c
  if a not in con:
    con[a] = {}
  if b not in con:
    con[b] = {}
  con[a][b] = True
  con[b][a] = True

q, k = map(int, input().split())
## setup

dist[k] = 0
frontier = [k]
while len(dist.keys()) != n:
  frontier_new = []
  for f in frontier:
    for neigh in con[f]:
      if con[f][neigh]:
        dist[neigh] = dist[f] + edges[frozenset([neigh, f])]
        frontier_new.append(neigh)
        con[f][neigh] = False
        con[neigh][f] = False
  frontier = frontier_new[:]

for qq in range(q):
  x, y = map(int, input().split())
  print(dist[x] + dist[y])


Measured memory_bytes: 96280
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w=1):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

n,m=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(m)]

edgenum=[0]*(n+1)
edge=[[] for i in range(n+1)]

for i in range(m):
    x,y=xy[i]
    edgenum[x]+=1
    edge[y].append(x)
# print(edgenum)
# print(edge)

d=deque()
itta=[0]*(n+1)
for i in range(n):
    i+=1
    if edgenum[i]==0:
        d.append(i)
# print(d)

while d:
    now=d.popleft()
    # print(itta,now)
    # print(edgenum)

    for i in edge[now]:
        edgenum[i]-=1
        if edgenum[i]==0:
            d.append(i)
            itta[i]=max(itta[i],itta[now]+1)
# print(itta)
print(max(itta))

Measured memory_bytes: 71260
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int main() {
	int x, y;
	cin >>x>>y;
	int sol = 0;
	for (int i=0 ; i<2 ; i++) {
		for (int j=1 ; j<4 ; j++) {
			sol += (x<=j) * 100000;
		}
		swap(x, y);
	}
	sol += (x == y and x == 1) * 400000;
	printf("%d\n", sol);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long ll;

const int MAXN = 1E6 + 10;
const int MOD = 1E9 + 7;

ll f[MAXN], s[MAXN];

int main(){
	int n;
	scanf("%d", &n);
	if (n == 1){
		puts("1");
		return 0;
	}

	f[0] = s[0] = 1;
	f[1] = 1, s[1] = 2;
	for (int i = 2; i <= n; ++i){
		f[i] = (s[i - 1] - f[i - 2] + MOD) % MOD;
		s[i] = (s[i - 1] + f[i]) % MOD;
	}
	ll ans = (f[n] + f[n - 1] * (n - 1)) % MOD;
	ll t = (n - 1ll) * (n - 1) % MOD;
	for (int i = 0; i < n - 1; ++i)
		ans = (ans + (t + i + 1) * f[i]) % MOD;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 15744
#A, B = map(float, input().split())
s = input()
A = s.split()[0]
Q = int(A)
B = s.split()[1]
#B = float(B)
P = int(B[0])*100 + int(B[2])*10 + int(B[3])
T = Q*P
T = str(T)
ans = ''
if len(T)<3 or Q==0 or P==0:
    ans = '0'
else :
    ans = T[:-2]
print(ans)

Measured memory_bytes: 9204