akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
backa=0
frontb=0
backafrontb=0
ans=0
for i in range(n):
    s=list(ss())
    for j in range(len(s)-1):
        if s[j]+s[j+1]=="AB":
            ans+=1
    if s[0]=="B" and s[-1]=="A":
        backafrontb+=1
    elif s[0]=="B":
        frontb+=1
    elif s[-1]=="A":
        backa+=1
#print(backa,frontb,backafrontb,ans)

if backafrontb>0:
    ans+=backafrontb-1

    if backa>0:
        ans+=1 
        backa-=1
    if frontb>0:
        ans+=1
        frontb-=1
    ans+=min(backa,frontb)
else:
    ans+=min(backa,frontb)


print(ans)



Measured memory_bytes: 66156
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var re float64

	for index := 0; index < n; index++ {
		var val float64
		var coin string

		fmt.Scan(&val)
		fmt.Scan(&coin)

		switch coin {
		case "JPY":
			re += val
		case "BTC":
			re += val * 380000
		}

	}
	fmt.Printf("%.9f\n", re)
}


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

int main(){
    ll n, i, j;
    cin >> n;
    ll h = sqrt(n);
    for(i = h; i >= 1; i--){
        j = n / i;
        if(i * j == n){
            break;
        }
    }
    cout << i + j - 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

namespace ABC173
{

  class D_ChatInACircle
  {
  public:
    D_ChatInACircle() = default;
    ~D_ChatInACircle() = default;

    void Run()
    {
      int N = {};
      std::cin >> N;

      std::vector<int> comfort = {}; // comfort

      for (int i = 0; i < N; ++i)
      {
        int c = 0;
        std::cin >> c;
        comfort.push_back(c);
      }

      std::sort(comfort.begin(), comfort.end(), [](auto a, auto b) {return a > b; });

      long long sum = 0;
      for (int i = 0; i < N-1; ++i)
      {
        int index = (i+1)/ 2;
        sum += comfort.at(index);
      }
      std::cout << sum << std::endl;
    }
  };
}
int main()
{

  ABC173::D_ChatInACircle prob;
  prob.Run();

  return 0;
}


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

int main(){
    int S,h,m,s;
    cin >> S;
    
    h=S/3600;
    S%=3600;
    m=S/60;
    S%=60;
    s=S;
    
    cout << h <<":" << m << ":" << s << endl;
    
    return 0;
    
    
}


Measured memory_bytes: 3084
#include<cmath>
#include<vector>
#include<climits>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<unordered_map>
using namespace std;

#define ld long double
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)

const int N=200;

struct hash_pair{
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};

void sieve(){
	bool prime[N+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=N;p++){
		if(prime[p] == true){
			for(int i=p*p;i<=N;i+=p)
				prime[i] = false;
		}
	}
}

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

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	int A[3][3],n,a,check = false;
	unordered_map<int,bool> U;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>A[i][j];
			if(U.find(A[i][j]) == U.end())
				U[A[i][j]] = false;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(U.find(a) != U.end())
			U[a] = true;
	}
	for(int i=0;i<3;i++){
		if(U[A[i][0]] == true && U[A[i][1]] == true && U[A[i][2]] == true)
		check = true;
	}
	for(int i=0;i<3;i++){
		if(U[A[0][i]] == true && U[A[1][i]] == true && U[A[2][i]] == true)
		check = true;
	}
	if(U[A[0][0]] == true && U[A[1][1]] == true && U[A[2][2]] == true)
		check = true;
	if(U[A[2][0]] == true && U[A[1][1]] == true && U[A[0][2]] == true)
		check = true;
	check ? cout<<"Yes" : cout<<"No";

	return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
DP = [float('inf')]*(N)
DP[0] = 0
for i in range(N-1):
    DP[i+1] = min(DP[i+1],DP[i]+abs(h[i]-h[i+1]),DP[i-1]+abs(h[i+1]-h[i-1]))
print(DP[-1])

Measured memory_bytes: 13980
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int d = N.length();
		int[][] dp = new int[d+1][2];
		dp[0][1] = 1;
		for(int i = 1; i <= d; i++) {
			int x = Character.getNumericValue(N.charAt(i-1));
			dp[i][0] = Math.min(dp[i-1][0] + x, dp[i-1][1] + 10 - x);
			dp[i][1] = Math.min(dp[i-1][0] + x + 1, dp[i-1][1] + 9 - x);
		}
		System.out.println(dp[d][0]);
	}

}

Measured memory_bytes: 74356
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

vector<pair<ll,ll>> factors;
#include <queue>
void getPrimeFactorize(ll n_max) {
    for (long long a = 2; a * a <= n_max; ++a) {
        if (n_max % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (n_max % a == 0) {
            ++ex;
            n_max /= a;
        }

        // その結果を push
        factors.push_back({a, ex});
    }

    // 最後に残った数について
    if (n_max != 1) factors.push_back({n_max, 1});
}
void checkval(ll fi){
    cout << factors[fi].first << " " << factors[fi].second;
    cout << endl;

}
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    getPrimeFactorize(N);

    ll ans = 0;

    rep(fi,factors.size()){
        ll base = 1;
        while(factors[fi].second>=base){
            //checkval(fi);
            ans++;
            factors[fi].second-=base;
            base++;
        }
    }
    cout << ans << endl;

    

}

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

#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl "\n"
const int MAX = 1e2+5;
const ll MAX2 = 11;
const ll MOD = 1000000000;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

ll tc,n,k,x[128],y,z,a,b,sz,tmp,id,res;
string s,t;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    t = "KIHBR";
    cin>>s;
    for(auto i:s){
    	if(i=='A'){
    		if(z||b==1||b==2)return cout<<"NO\n",0;
    		z = 1;
		}
		else if(b!=5&&t[b]==i)z = 0, b++;
		else return cout<<"NO\n",0;
	}
	if(b!=5)cout<<"NO\n";
	else cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 256
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    int ans = 10000;
    REP(i, n)REP(j, n){
        if(i == j) continue;
        int p = x[j] - x[i], q = y[j] - y[i];
        
        int cnt = 0;
        REP(k, n)REP(l, n){
            if(x[k] + p == x[l] && y[k] + q == y[l]){
                cnt++;
            }
        }
        
        ans = min(ans, n - cnt);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A + 1);
  int min_a = INT_MAX;
  for (int i = 1; i <= A; i++) {
    cin >> a[i];
    min_a = min(min_a, a[i]);
  }
  vector<int> b(B + 1);
  int min_b = INT_MAX;
  for (int i = 1; i <= B; i++) {
    cin >> b[i];
    min_b = min(min_b, b[i]);
  }
  int ans = min_a + min_b;
  for (int i = 1; i <= M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << "\n";
  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string a, b;
    cin >> a >> b;
    int x = stoi(a + b);
    for (int i = 0; i * i <= x;i++){
        if(i*i==x){
            cout << "Yes"
                 << "\n";
            return 0;
        }
    }
    cout << "No"
         << "\n";
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int x, t;
    cin >> x >> t;

    cout << max(x-t, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    // -(N_0-3K)-0------(N_0-2K)-------(N_0-K)-------N_0--
    //  (N_0%K-K)        N_0 % K
    long long N, K;
    std::cin >> N >> K;
    long long right = N % K;
    long long left = right - K;
    std::cout << std::min(right, -left) << std::endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int main() {

	int A, B;

	cin >> A >> B;
	
	if (A == 1)A = 14;
	if (B == 1)B = 14;
	if (A > B)cout << "Alice" << endl;
	else if (A < B)cout << "Bob" << endl;
	else cout << "Draw" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 1000005;
#ifndef LOCAL
#define cerr if(0)cout
#endif
ll A[MAXN], dp[MAXN];
int32_t main() 
{
	IAMSPEED
	int n; cin >> n;
	FOR(i,1,n) cin >> A[i];
	int ans = 0;
	FOR(i,1,n) {
		if(A[i]<=A[i-1])dp[i]=dp[i-1]+1;
		else dp[i] = 1;
		chmax(ans,dp[i]);
	}
	cout << ans-1;
}


Measured memory_bytes: 5116
#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 rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)
	long long rcv[3005][3005];
	long long p[3005][3005][4];


int main() {
	int R;
	int C;
	int K;
	int x;
	int y;
	long long z;
	long long ans;


	cin >> R >> C >> K;

	rep(i, R+2){
		rep(j, C+2){
			rcv[i][j]=0;
			rep(kk, 4) p[i][j][kk]=0;
		}
	}

	rep3(i, 1, K) {
		cin >> x >> y >> z;
		rcv[x][y]=z;
	}

	rep3(i, 1, R) {
		rep3(j, 1, C) {
			z=rcv[i][j];
			if((p[i][j][2]>0)&&(p[i][j][3]<p[i][j][2]+z))p[i][j][3]=p[i][j][2]+z;
			if((p[i][j][1]>0)&&(p[i][j][2]<p[i][j][1]+z))p[i][j][2]=p[i][j][1]+z;
			if(p[i][j][1]<p[i][j][0]+z)p[i][j][1]=p[i][j][0]+z;
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][0]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][1]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][2]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][3]);
			p[i][j+1][0]=max(p[i][j+1][0],p[i][j][0]);
			p[i][j+1][1]=max(p[i][j+1][1],p[i][j][1]);
			p[i][j+1][2]=max(p[i][j+1][2],p[i][j][2]);
			p[i][j+1][3]=max(p[i][j+1][3],p[i][j][3]);
		}
	}
	ans=max(p[R][C][0],p[R][C][1]);
	ans=max(ans,p[R][C][2]);
	ans=max(ans,p[R][C][3]);

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


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

int main()
{
	int n,c;

	while(cin >> n){
		c = 0;
		if(n < 37){
			for(int i=0;i<10;++i){
				for(int j=0;j<10;++j){
					for(int k=0;k<10;++k){
						for(int l=0;l<10;++l){
							if(i+j+k+l == n)
								++c;
						}
					}
				}
			}

			cout << c << endl;

		}else{
			cout << 0 << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  if (n < 3) {
    cout << 0 << ln;
    return 0;
  }

  vector<int> r, g, b;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      r.push_back(i);
    } else if (s[i] == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }

  if (r.size() > 0 && g.size() > 0 && b.size() > 0) {
  } else {
    cout << 0 << ln;
    return 0;
  }

  ll total = r.size() * g.size() * b.size();

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int li = i - j;
      int ri = i + j;
      if (li < 0 || ri > n - 1) {
        continue;
      }

      set<char> st;
      st.insert(s[i]);
      st.insert(s[li]);
      st.insert(s[ri]);
      if (st.size() >= 3) {
        total--;
      }
    }
  }

  cout << total << ln;

  return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
typedef long long ll;

ll gcd(ll a, ll b) {
  ll t;
  while(b) t = a % b, a = b, b = t;
  return a;
}

int main(void) {
  ll i, j, a, b, n, m = 1e5, ans = 1;
  scanf("%lld%lld", &a, &b);
  n = gcd(a, b);
  bool p[m];
  for(i = 0; i < m; ++i) p[i] = true;
  for(i = 2; i * i < m; ++i) if(p[i]) for(j = 2; i * j < m; ++j) p[i * j] = false;
  for(i = 2; i * i <= n; ++i) {
    if(!(n % i)) ++ans;
    while(!(n % i)) n /= i;
  }
  if(n != 1) ++ans;
  printf("%lld", ans);
  return 0;
}

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

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

Measured memory_bytes: 3564
n = int(input())
a_list = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(n-1):
    if a_list[i+1] < a_list[i]:
        money += stock*a_list[i]
        stock = 0
    elif a_list[i+1] > a_list[i]:
        new_stock = money//a_list[i]
        money -= new_stock*a_list[i]
        stock += new_stock

print(money+stock*a_list[n-1])


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

using namespace std;

/*
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;*/

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void printV(vi v) {
    for (int i = 0; i<v.size(); ++i) cout << v.at(i) << " ";
    cout << "\n";
}

//g++ -std=c++11 -O2 -Wall c.cpp

void solve() {
    ll  a, b, c, d;
    cin >>a>>b>>c>>d;

    vector<ll> v = {a*c, a*d, b*c, b*d};
    ll max = a*c;
    for (int i = 1; i<4; ++i) {
        if (v.at(i) > max) max = v.at(i); 
    }
    cout << max << "\n";

/*
    if (b<0) { // a <0
        if (c < 0) {
            x = a; y = c;
        } else { // c peut être < 0
            x = b; y = c;
        }
    } else {
        if (c<0) {
            x = b; y = c;
        } else {

        }
    }*/
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        solve();


    /**
     * ALGORITHME DE TRI ET EN LEVER LES DUPLICATES
     * set<int> s( v.begin(), v.end() );
     * v.assign( s.begin(), s.end() );
     * */
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll c[n][3];
    for(int i=0;i<n;i++)cin>>c[i][0]>>c[i][1]>>c[i][2];
    ll dp[n][3];
    for(int i=0;i<n;i++)dp[i][0]=dp[i][1]=dp[i][2]=0;
    dp[0][0]=max(c[0][1],c[0][2]);
    dp[0][1]=max(c[0][0],c[0][2]);
    dp[0][2]=max(c[0][0],c[0][1]);
    for(int i=1;i<n;i++){
             dp[i][0]=max(dp[i-1][1],dp[i-1][2])+c[i][0];
             dp[i][1]=max(dp[i-1][0],dp[i-1][2])+c[i][1];
             dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i][2];
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>

#define PI 3.14159265359	

using namespace std;

int main(){
	int n, m, l;
	long long sum;
	cin >> n >> m >> l;
	vector<vector<int> > a(n, vector<int>(m)), b(m, vector<int>(l));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++) cin >> a[i][j];
	}
	for (int i = 0; i < m; i++){
		for (int j = 0; j < l; j++) cin >> b[i][j];
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < l; j++){
			sum = 0;
			for (int k = 0; k < m; k++){
				sum += a[i][k] * b[k][j];
			}
			cout << sum;
			if (j != l - 1) cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  string comp5 = "",comp6="",comp7="";
 
  cin >> S;
  string t = S;
  while(t.size()>=5) {
    for(int i=-4;i<=0;i++) {
      comp5+=t.at(t.size()+i-1);
    }
    
    if(t.size()>=6){
      for(int l=-5;l<=0;l++) {
        comp6+=t.at(t.size()+l-1);
      }
    }
    
    if(t.size()>=7){
      for(int j=-6;j<=0;j++) {
        comp7+=t.at(t.size()+j-1);
      }
    }
    /*cout << comp5 << endl;
    cout << comp6 << endl;
    cout << comp7 << endl;
    */
    if(comp5=="dream" || comp5=="erase") {
      for(int i=0;i<5;i++){
        t.pop_back();
      }
      comp5="";
      comp6="";
      comp7="";
    }else if(t.size()>=6 && comp6=="eraser") {
      for(int l=0;l<6;l++){
        t.pop_back();
      }
      comp5="";
      comp6="";
      comp7="";
    }else if(t.size()>=7 && comp7=="dreamer") {
      for(int j=0;j<7;j++){
        t.pop_back();
      }
      comp5="";
      comp6="";
      comp7="";
    }else break;
  }
  if(t.size()==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    p0_list = np.array([float(item) for item in input().split()])
    p1_list = 1 - p0_list

    dp = np.zeros((N+1, N+1), dtype='float')
    dp[0, 0] = 1

    for i in range(N):
        dp[i+1][:-1] += dp[i][:-1] * p1_list[i]
        dp[i+1][1:]  += dp[i][:-1] * p0_list[i]

    print(np.sum(dp[N, (N+1)//2:]))

if __name__ == "__main__":
    main()    



Measured memory_bytes: 82776
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll a, b, x;
        in >> a >> b >> x;
        out << (b / x + 1) - (a == 0 ? 0 : (a - 1) / x + 1) << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i=0; i<M; i++) cin >> a[i] >> b[i];
  map<int, int> dict;
  for (int i=0; i<M; i++) {
    if (dict.count(a[i])) dict[a[i]]++;
    else dict[a[i]] = 1;
    if (dict.count(b[i])) dict[b[i]]++;
    else dict[b[i]] = 1;
  }
  for (auto p: dict) {
    auto value = p.second;
    if (value%2!=0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,h)rep(j,w) {
        if (s[i][j] == '#') continue;
        int cnt = 0;
        for (int k=-1; k<=1; k++) {
            if (i+k<0 || i+k>h-1) continue;
            for (int l=-1; l<=1; l++) {
                if (j+l<0 || j+l>w-1) continue;
                if (s[i+k][j+l] == '#') cnt++;
            }
        }
        s[i][j] = '0' + cnt;
    }
    rep(i,h)rep(j,w) {
        cout << s[i][j];
        if (j == w-1) cout << endl;
    }
} 

Measured memory_bytes: 3632
require 'pp'
class PriorityQueue
  def initialize(&cmp)
    # topとbottomの関係を書く. デフォルトでは大きい順に出てくる
    @cmp = cmp || Proc.new { |bottom, top| bottom < top }
    @heap = []
  end

  def size
    @heap.size
  end

  # def empty?
  #   @heap.size == 0
  # end

  # def inspect # デバック用 # ブロック月ソートは嘘になってしまう
  #   tmp = Proc.new { |a,b| @cmp.call(a, b) ? 1 : 0 }
  #   @heap.sort(&tmp).inspect
  # end

  def push(x)
    @heap << x
    index = size - 1
    while(p_i = ((index+1)/2)-1; @cmp.call(@heap[p_i],@heap[index]))
      @heap[p_i], @heap[index] = @heap[index], @heap[p_i]
      index = p_i
      break if index == 0
    end
    self
  end

  def pop
    case size
    when 0 then return nil
    when 1 then return @heap.delete_at(0)
    when 2 then return @cmp.call(@heap[1], @heap[0]) ? @heap.delete_at(0) : @heap.delete_at(1)
    end
    popped = @heap[0]
    @heap[0] = @heap.delete_at(-1)
    index = 0
    loop do
      break if index*2 + 1 >= size || index*2 + 2 >= size
      if @cmp.call(@heap[index*2 + 2], @heap[index*2 + 1]) && @cmp.call(@heap[index], @heap[index*2 + 1])
        @heap[index*2 + 1], @heap[index] = @heap[index], @heap[index*2 + 1]
        index = index*2 + 1
      elsif !(@cmp.call(@heap[index*2 + 2], @heap[index*2 + 1])) && @cmp.call(@heap[index], @heap[index*2 + 2])
        @heap[index*2 + 2], @heap[index] = @heap[index], @heap[index*2 + 2]
        index = index*2 + 2
      else
        break
      end
    end
    popped
  end

  alias :<< :push

  # private
  #
  # def swap!(a, b)
  #   @heap[a], @heap[b] = @heap[b], @heap[a]
  #   nil
  # end

  # def parent_index(i)
  #   ((i+1)/2)-1
  # end
  #
  # def left_child_index(i)
  #   i*2 + 1
  # end
  #
  # def right_child_index(i)
  #   i*2 + 2
  # end
  #
  # alias :pi :parent_index
  # alias :lci :left_child_index
  # alias :rci :right_child_index
end

pq = PriorityQueue.new { |bottom, top| bottom[1] < top[1] }
n, m = gets.split.map &:to_i
ab = []
n.times do |i|
  ab << gets.split.map(&:to_i) # 日、金
end

ab = ab.group_by{|a|a[0]}
res = 0
1.upto m do |i|
  if ab[i]
    ab[i].each{|a|pq << a}
  end
  tmp = pq.pop
  res += tmp ? tmp[1] : 0
end
p res


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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e9 + 7;
const int N = 1e6 + 7;
const int M = 26;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,q;
int c[N];
int t[N];
int res[N];
int last[N];
vector < pair < int , int > > qr[N];

void upd( int x , int y )
{
    while( x < N ){
        t[x] += y;
        x += x & -x;
    }
}

int get( int x )
{
    int res = 0;
    while( x > 0 ){
        res += t[x];
        x -= x & -x;
    }
    return res;
}

void solve1()
{
    cin >> n >> q;
    for( int i = 1; i <= n; i++ )cin >> c[i];
    for( int i = 1; i <= q; i++ ){
        int l,r;
        cin >> l >> r;
        qr[r].push_back({ l , i });
    }
    for( int i = 1; i <= n; i++ ){
        if( last[c[i]] != 0 )upd( last[c[i]] , -1 );
        upd( i , 1 );
        last[c[i]] = i;
        for( auto x : qr[i] ){
            res[x.se] = get( i ) - get( x.fi - 1 );
        }
    }
    for( int i = 1; i <= q; i++ ){
        cout << res[i] << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 45044
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, l;
    cin >> n >> l;

    int s=0;
    int mi = 100*200;
    int mi_id = 0;
    for(int i=0; i<n; i++) {
        s +=(l+i);
        if (mi > abs(l+i)) {
            mi = min(mi, abs(l+i));
            mi_id = i;
        }
    }
    if ( l<=0 && 0<l+n) {
        cout << s << endl;
    }
    else {
        cout << s-(l+mi_id) << endl;
    }

    return 0;
}

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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int>> e(n);
  for (int i = 0; i < m; i++) {
    int s, t;
    scanf("%d %d", &s, &t);
    e[s - 1].emplace_back(t - 1);
  }

  double ans = n - 1;
  for (int i = 0; i + 1 < n; i++) {
    if (e[i].size() < 2) continue;

    vector<double> f(n);
    f[n - 1] = 0;
    for (int j = n - 2; j >= 0; j--) {
      double s = 0, maxp = 0; 
      for (int k = 0; k < e[j].size(); k++) {
        double v = f[e[j][k]];
        s += v;
        maxp = max(v, maxp);
      }
      if (j == i)
        f[j] = (s - maxp) / (e[j].size() - 1) + 1;
      else
        f[j] = s / e[j].size() + 1;
    }

    ans = min(f[0], ans);
  }
  printf("%lf\n", ans);

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <numeric>
#include <cmath>
using namespace std;
int gcd(int a,int b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

int main()
{
    long long A, B, C, D; cin >> A >> B >> C >> D;
    long long nc, nd, ncd;
    long long CD = C * D / gcd(C, D);
    if(A % C == 0) nc = B/C - A/C + 1;
    else nc = B/C - A/C;
    if(A % D == 0) nd = B/D - A/D + 1;
    else nd = B/D - A/D;
    if(A % CD  == 0) ncd = B/CD - A/CD + 1;
    else ncd = B/CD - A/CD;

    cout << B - A + 1 - (nc + nd - ncd) << "\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    ll X, A, B; cin >> X >> A >> B;
    if(B - A <= 0) cout << "delicious" << endl;
    else if(B - A <= X) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	string s, t;
	cin >> s;
	cin >> t;
	for(int i = s.size() - t.size(); i >= 0; i--){
			for(int j = 0; j < t.size(); j++){
					if(s[i+j] != '?' && s[i+j] != t[j])break;
					if(j == t.size() - 1){
							for(int k = 0; k < t.size(); k++){
									s[i + k] = t[k];
							}
							for(int k = 0; k < s.size(); k++){
									if(s[k] == '?')cout << 'a';
									else cout << s[k];
							}
							cout << endl;
							return 0;
					}
			}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n; std::string s;
    std::cin >> n >> s;
    std::vector<int> w(n + 1), b(n + 1);
    for (int i = 0; i < n; i++) {
        w[i + 1] = w[i] + (s[i] == '.');
        b[i + 1] = b[i] + (s[i] == '#');
    }
    int ret = b[n];
    for (int i = 1; i <= n; i++) {
        ret = std::min(ret, b[i - 1] + w[n] - w[i - 1]);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    ll n;
    cin >> n;
    ll r = 0;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }
    Sort(a);
    
    r = a[n/2] - a[n/2-1];
    
    mes(r);
    
    
    
    
}

Measured memory_bytes: 4048
n = int(input())
if n % 2 == 1:
	print(0)
	exit()
 
# 5の倍数で割り切れる回数
result = 0
i = 1
while True:
	result += n // ((5 ** i) * 2)
	i += 1
	if n < ((5 ** i) * 2): break
 
# 結果出力
print(result)


Measured memory_bytes: 2940
h,w=map(int,input().split())
S=[]
ans=0
ans1=0
W=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(h):
  S.append(input().split())
for k in range(h):
  for j in range(w):
    if S[k][j]=='snuke':
      ans=j
      ans1=str(k+1)
print(W[ans]+ans1)  

Measured memory_bytes: 3064
S = input()
T1 = "01"*int(len(S)/2+1)
T2 = "10"*int(len(S)/2+1)
count1 = 0
count2 = 0
for s,t1,t2 in zip(S,T1,T2):
    if s != t1:
        count1 += 1
    if s != t2:
        count2 += 1
print(min(count1,count2))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define xx          exit(0);
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) {
    return (ll)(log(x) / log(base));
}
vec v[100005]; ll m,n, in[100005],out[100005];
void dfs1(ll x, ll pr, ll m)
{
	ll y=v[x].size(),z;
	in[x]=1;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr){
			dfs1(z,x,m);
			in[x] = (in[x]*(1+in[z]))%m;
		}
	}
}
void dfs2(ll x, ll pr, ll m)
{
	vec s;
	ll y=v[x].size(),z,j;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr) s.pb((1+in[z])%m);
	}
	ll n=s.size();
	if(n==0) return ;
	ll pre[n+1],suf[n+2];
	pre[0]=1; suf[n+1]=1;
	repi(i,1,n) pre[i] = (pre[i-1]*s[i-1])%m;
	per(i,n,1) suf[i] = (suf[i+1]*s[i-1])%m;
	j=0;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr){
			out[z] = (1+(out[x]*((pre[j]*suf[j+2])%m))%m)%m;
			j++;
			dfs2(z,x,m);
		}
	}
	s.clear();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll k,i,j,w;
    	cin>>n>>m;
    	rep(i,0,n-1){
		    cin>>j>>k;
    		v[j].pb(k);
    		v[k].pb(j);
		}
		dfs1(1,0,m);
		out[1]=1;
		dfs2(1,0,m);
		repi(i,1,n){
			cout<<(in[i]*out[i])%m<<'\n';
		}
	}
	return 0;
}

Measured memory_bytes: 27748
let n, t, a = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let hs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let f x = abs @@ 1000 * t - 6 * x - 1000 * a
let _ = Array.fold_left (fun (m, i) h -> min m (f h, i), i + 1) ((max_int, -1), 1) hs |> fst |> snd |> Printf.printf "%d\n"

Measured memory_bytes: 768
//ABC 155 E Payment
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1e9;

int dp[1000010][2];
    
int main() {
    string s;
    
    cin >> s;
    s +='0';
	//s = '0'+s+'0';
    reverse(s.begin(),s.end());
	s += '0';
    
	for(int i=0; i<s.size(); ++i)  
	  s[i] -= '0';
    
    dp[0][1] = INF;
    
	for(int i=1; i<=s.size()-1; ++i){
      dp[i][0]=min(dp[i-1][0]+s[i],dp[i-1][1]+s[i]+1);
      dp[i][1]=min(dp[i-1][0]+10-s[i],dp[i-1][1]+9-s[i]);
    }
    
    cout << dp[s.size()-1][0] << '\n';
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

long long mmod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

/* ----------- ANSWER ----------- */
/* ------------------------------ */
// Function to find common sub sequence in both strings
ll count_common_sub_sequence(vl &s1, vl &s2) {
    ll n1, n2;
    n1 = s1.size();
    n2 = s2.size();
    ll arr[n1 + 1][n2 + 1];

    for (int i = 0; i <= n1; i++) {
        for (int j = 0; j <= n2; j++) {
            arr[i][j] = 0;
        }
    }

    // for each character of S1
    for (int i = 1; i <= n1; i++) {
        // for each character in S2
        for (int j = 1; j <= n2; j++) {
            if (s1[i - 1] == s2[j - 1]) {
                arr[i][j] = 1 + ((arr[i][j - 1] + arr[i - 1][j]) % mod);
                arr[i][j] %= mod;
            } else {
                arr[i][j] =
                        mmod((arr[i][j - 1] + arr[i - 1][j]) % mod - (arr[i - 1][j - 1]) % mod,
                             mod);
                arr[i][j] %= mod;
            }
        }
    }

    return arr[n1][n2];
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n, m;
        cin >> n >> m;
        vl s(n), t(m);
        rep(i, n) cin >> s[i];
        rep(i, m) cin >> t[i];
        cout << (1 + count_common_sub_sequence(s, t)) % mod << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

lint fact[100010];

void factorial(lint n){
  fact[0]=1;
  for(int t=1;t<=n;t++){
    fact[t]=(t*fact[t-1])%MOD;
  }
}

int main(){
  lint N,M;
  cin>>N>>M;
  if(abs(N-M)>=2){
    cout<<0<<"\n";
    return 0;
  }
  if(N<M)swap(N,M);     //N-1<=M<=N

  factorial(100005);

  if(N==M){
    lint ans=((fact[N]%MOD)*(fact[N]%MOD))%MOD;
    cout<<(ans*2)%MOD<<"\n";
    return 0;
  }
  lint ans=((fact[N]%MOD)*(fact[N-1]%MOD))%MOD;
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}

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

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll n,max=0,ans=0;
    cin >> n;
    
    for (ll i=0;i<n;i++){
        ll x;
        cin >> x;
        if (x>=max){
            ans++;
            max=x;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc()
{
    return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
const int inf=1e9;
const int maxn=1e5+50;
const int maxm=1e5+50;
int n,m;
int ed;
int st;
int deg[maxn];
int head[maxn];
struct edge
{
    int to,nex,cap,flow;
    edge(int to=0,int nex=0,int cap=0,int flow=0):to(to),nex(nex),cap(cap),flow(flow){}
};
vector<edge> G;
inline void addedge(int u,int v,int c)
{
    G.push_back(edge(v,head[u],c)),head[u]=G.size()-1;
    G.push_back(edge(u,head[v],c)),head[v]=G.size()-1;
    ++deg[u],++deg[v];
}
namespace dinic
{
    int cur[maxn];
    int dis[maxn];
    bool bfs()
    {
        static int q[maxn]; int hd=0,tl=0;
        memset(dis,-1,sizeof(dis));
        q[tl++]=st;
        dis[st]=0;
        while(hd<tl)
        {
            int u=q[hd++];
            for(int i=head[u];~i;i=G[i].nex) if(G[i].cap!=G[i].flow)
            {
                int v=G[i].to; 
                if(dis[v]==-1)
                {
                    dis[v]=dis[u]+1;
                    q[tl++]=v;
                }
            }
        }
        return dis[ed]!=-1;
    }
    int dfs(int u,int flow)
    {
        if(u==ed||flow==0) return flow;
        int rec=flow;
        for(int &i=cur[u];~i;i=G[i].nex)
        {
            int v=G[i].to;
            if(dis[v]==dis[u]+1)
            {
                int d=dfs(v,min(flow,G[i].cap-G[i].flow));
                G[i].flow+=d;
                G[i^1].flow-=d;
                if((flow-=d)==0) break;
            }
        }
        return rec-flow;
    }
    int maxflow()
    {
        int flow=0;
        while(bfs())
        {
            memcpy(cur,head,sizeof(head));
            flow+=dfs(st,inf);
        }
        return flow;
    }
}
int main()
{
    read(n),read(m);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=m;++i)
    {
        int a,b; read(a),read(b);
        addedge(a,b,1);
    }
    for(int i=1;i<=n;++i) if(deg[i]&1) {puts("No"); return 0;}
    int cnt=0;
    for(int i=1;i<=n;++i) 
    {
        if(deg[i]>4) {puts("Yes"); return 0;}
        if(deg[i]==4) ++cnt;
    }
    if(cnt>=3) {puts("Yes"); return 0;}
    if(cnt<=1) {puts("No"); return 0;}
    for(int i=1;i<=n;++i) if(deg[i]==4) {st=i; break;}
    for(int i=n;i>=1;--i) if(deg[i]==4) {ed=i; break;} 
    puts(dinic::maxflow()==2?"Yes":"No");
    return 0;
}

Measured memory_bytes: 7024
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	
	string str;
	char *c = new char[200005];
	scanf("%s",c);//scanf("%s",&c[0]);
	str = c;
	//cout<<str;
//	cin>>str;
	//scanf("%s",&str[0]);
	//int len=strlen(str);
	int flag=1;
	while(flag==1)
	{
		if(str.empty()) break;
		int i = 0;
	//int len=str.length();
		flag=0;
	    while (!str.empty()&&i < str.length()-1)
	    {   
	            if (str[i]=='S'&&str[i+1]=='T')
	            {
	                str.erase(i,2);
	                flag=1; 
	                i--;
	                i--;
	                //cout<<"delete."<<endl;
	                //break;
	            }
	        ++i; 
	    } 
	}
    //cout << str.length() << endl;
    printf("%d\n",str.length());
    return 0;

 } 

Measured memory_bytes: 640
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger[] a = new BigInteger[n];
        for (int i = 0; i < n; i++) {
			a[i] = sc.nextBigInteger();
			if (a[i].compareTo(BigInteger.ZERO) == 0) {
				System.out.println(0);
				return;
			}
		}
        sc.close();

        BigInteger lim = BigInteger.valueOf(1000000000000000000L);
        BigInteger ans = BigInteger.ONE;
        for (int i = 0; i < n; i++) {
        	ans = ans.multiply(a[i]);
        	if (ans.compareTo(lim) > 0) {
        		System.out.println(-1);
        		return;
        	}
        }
        System.out.println(ans.toString());
    }
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    int pro=a*b;
    if(pro%2==0)
    {
        cout<<"Even"<<endl;
    }
    else
    {
        cout<<"Odd"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,cnt=0,ans=0;
  cin >> n;
  long long a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]<0){
      cnt++;
      a[i]*=-1;
    }
    b[i]=a[i];
    ans+=a[i];
  }
  if(cnt%2==1){
    sort(b,b+n);
    ans-=b[0]*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792