akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)
def dmatprint(mat):

    if debug == True:
        for row in mat:
            for col in row:
                print("{0:2d} ".format(col), end="")
            print("")
        print("")

def solve():
    H, W = map(int, input().split())
    s_arr = [[-1 for w in range(W)] for h in range(H)]
    for h in range(H):
        s_row = input()
        for w in range(W):
            if s_row[w] == ".":
                s_arr[h][w] = 0
            else:
                s_arr[h][w] = 1

    h_count = [[-1 for w in range(W)] for h in range(H)]
    w_count = [[-1 for w in range(W)] for h in range(H)]

    # w_countを埋める
    for h in range(H):
        row = s_arr[h]
        clearFlag = True
        for w, s in enumerate(row):
            if clearFlag:
                start = w
                end = w
            if s == 0:
                end = w
                clearFlag = False
            else:
                if clearFlag:
                    h_count[h][w] = -1
                else:
                    for iw in range(start, end+1):
                        w_count[h][iw] = end - start + 1
                clearFlag = True
        if clearFlag == False:
            for iw in range(start, max(end + 1, W)):
                w_count[h][iw] = end - start + 1

    # h_countを埋める
    for w in range(W):
        col = [row[w] for row in s_arr]
        clearFlag = True
        for h, s in enumerate(col):
            if clearFlag:
                start = h
                end = h
            if s == 0:
                end = h
                clearFlag = False
            else:
                if clearFlag:
                    h_count[h][w] = -1
                else:
                    for ih in range(start, end+1):
                        h_count[ih][w] = end - start + 1
                clearFlag = True
        if clearFlag == False:
            for ih in range(start, max(end+1, H)):
                h_count[ih][w] = end - start + 1

    dmatprint(h_count)
    dmatprint(w_count)
    mx_ans = 0
    for h in range(H):
        for w in range(W):
            if s_arr[h][w] == 0:
                ans = h_count[h][w] + w_count[h][w] - 1
                if ans >= mx_ans:
                    mx_ans = ans

    print(mx_ans)
    dmatprint(s_arr)
solve()

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

int main(){
    int n, m; cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<int>> py(100010);
    for(int i = 0; i < m; i++){
        cin >> p.at(i) >> y.at(i);
        py.at(p.at(i)).push_back(y.at(i));
    }
    for(int i = 0; i < n; i++){
        sort(py.at(i+1).begin(), py.at(i+1).end());
    }
    for(int i = 0; i < m; i++){
        int v = p.at(i);
        printf("%06d", v);
        int id = lower_bound(py.at(p.at(i)).begin(), py.at(p.at(i)).end(), y.at(i)) - py.at(p.at(i)).begin();
        printf("%06d\n", id+1);
    }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll a,b,c;

int main(){
	cin >> a >> b >> c;
	
	int cou=0;
	while(1){
		if(a%2+b%2+c%2){cout << cou << endl; return 0;}
		if(a==b and b==c){cout << -1 << endl; return 0;}
		
		int aa=a/2, bb=b/2, cc=c/2;
		a=bb+cc; b=cc+aa; c=aa+bb; cou++;
	}
	return 0;
}



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

using namespace std;

#define int long long 
#define INF 21000000000

signed main(){
		int n;
		cin >> n;
		vector<int> a;
		int cnt = 0;
		for(int i=1;i<n+1;i++){
				int tmp;
				cin >> tmp;
				tmp -= i;
				a.push_back(tmp);
		}
		sort(a.begin(),a.end());
		int b;
		if(n % 2 == 0) b = (a[n/2-1] + a[n/2]) / 2;
		else b = a[n/2];
		int ans = 0;
		for(auto& A : a){
				ans += abs(A - b);
		}
		cout << ans << endl;
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,k,x,y; cin >> n >> k >> x >> y;
    if (n < k) {
        cout << n * x << endl;
    }
    else {
        cout << k * x + (n - k) * y << endl; 
    }
    


}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int a[3][111];

signed main() {

    int n;
    cin >> n;

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

    int maxi = 0;

    for(int i = 0; i < n; i++) {
        int sum = 0;
        for(int j = 0; j <= i; j++)
            sum += a[0][j];
        for(int j = i; j < n; j++)
            sum += a[1][j];
        chmax(maxi, sum);
    }

    cout << maxi << endl;
  
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

//????°?????????\???????????§back?????????????????????
int main() {
    int n;
    list<int> l={0};
    while (scanf("%d",&n)!=EOF) {
        if (n==0) {
            printf("%d\n",l.front());
            l.pop_front();
        } else {
            l.push_front(n);
        }
    }
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N, M, C, an = 0;
	cin >> N >> M >> C;
	vector <ll> B(M);
	rep(i, M) {
		cin >> B.at(i);
	}
	rep(j, N) {
		ll p = C;
		rep(i, M) {
			ll a;
			cin >> a;
			p += a * B.at(i);
		}
		if (p > 0) {
			an++;
		}
	}
	cout << an << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii  = pair<int,int>;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define rep2(i,x,n) for(ll i=x; i<(n); i++)
#define MOD 1000000007
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
const double PI = 3.141593;
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);}   //最小公倍数
ll combination(ll n, ll r) {
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
    cout << "bust" << endl;
  }
  else
  {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include <iostream>
//#include <algorithm>
#include <limits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
int N;
vector<vector<vector<double>>> dp;
//cout <<fixed << setprecision(10)<< ans;で、小数精度10桁にできる
/*void printdp(int N,ll Vmax){
	rep(i,N+1){
		for(ll j=0;j<Vmax+1;j++){
			if(dp[i][j]==llMAX)continue;
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	return;
}*/
double culc(int a1,int a2,int a3){
	if(dp[a1][a2][a3]!=-1){
		return dp[a1][a2][a3];
	}
	double result = 0;
	if(a1>0){
		result += culc(a1-1,a2,a3)*a1;
	}
	if(a2>0){
		result += culc(a1+1,a2-1,a3)*a2;
	}
	if(a3>0){
		result+= culc(a1,a2+1,a3-1)*a3;
	}
	result +=N;
	result /=(a1+a2+a3);
	//dp[a1][a2][a3] = (culc(a1-1,a2,a3)*a1+culc(a1+1,a2-1,a3)*a2+culc(a1,a2+1,a3-1)*a3+N)*(1/(a1+a2+a3));
	dp[a1][a2][a3] = result;
	return result;
}
int main(void){
	int a;
	int a1=0,a2=0,a3=0;
	cin >> N;
	int sum;
	rep(i,N){
		cin >> a;
		if(a==1){
			a1++;
		}else if(a==2){
			a2++;
		}else{
			a3++;
		}
	}
	dp = vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
	dp[0][0][0] = 0;
	cout <<fixed << setprecision(10)<< culc(a1,a2,a3);
	return 0;
}

Measured memory_bytes: 216960
from collections import Counter
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    s = list(set(S))
    c = Counter(S)
    maxc = max(c.values())
    ans = []
    for i in range(len(s)):
        if c[s[i]] == maxc:
            ans.append(s[i])
    ans.sort()
    for i in range(len(ans)):
        print(ans[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 44908
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=3e5+10;
ll n,m,k,ans;
ll num[N],temp[N];
ll read() {
    ll y=0,flag=1;
    char ch=getchar();
    while( (ch>'9' || ch<'0') && ch!='-' ) ch=getchar();
    if(ch=='-') flag=-1,ch=getchar();
    while(ch>='0' && ch<='9') y=y*10+ch-'0',ch=getchar();
    return y*flag;
}
int main(){
    n=read(),m=read();
    if(n>=10||m>=10)cout<<-1;
    else cout<<n*m;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N, D, X;
	int A;
	cin >> N;
	cin >> D >> X;
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		for (int j = 1; j <= D; j += A) {
			sum++;
		}
	}
	cout << sum + X;
	return 0;
}


Measured memory_bytes: 256
shi_num = int(input())
words = [input() for _ in range(shi_num)]
result = [words[0]]
last_alph = words[0][-1]
for word in words[1:]:
    if (word not in result) and word[0] == last_alph:
        last_alph = word[-1]
        result.append(word)
    else:
        break

if len(result) == shi_num:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
  for (auto & x : v) is >> x;
  return is;
}

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    {os << (i > 0 ? "," : "") << v.at(i);}
  return os << "}";
}

inline auto iota(int n) {
  auto ret = std::vector< int >(n);
  std::iota(ret.begin(), ret.end(), 0);
  return ret;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k; std::cin >> n >> k;
  std::vector< int > x(n), y(n);
  rep(i, 0, n) std::cin >> x.at(i) >> y.at(i);
  auto ord = iota(n);
  std::sort(all(ord), [&x](auto i, auto j){ return x.at(i) < x.at(j); });
  auto cal = [&] (auto&& z) {
    std::sort(all(z));
    assert((int)z.size() >= k);
    auto it = z.begin(), jt = z.begin() + k - 1;
    int ret = 2e9;
    while (jt != z.end()) {
      cmn(ret, *jt - *it);
      it++, jt++;
    }
    return ret;
  };
  lint ret = 4e18;
  rep(l, 0, n) rep(r, l + k, n + 1) {
    auto width = x.at(ord.at(r - 1)) - x.at(ord.at(l));
    auto z = std::vector< int >(r - l);
    std::transform(ord.begin() + l, ord.begin() + r, z.begin(), [&y](auto x)
      { return y.at(x); });
    cmn(ret, (lint)width * cal(z));
  }
  std::cout << ret << std::endl;
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


using T = tuple<i64, i64, i64>;

int main() {
    i64 N; cin >> N;
    vector<T> con;
    vector<T> inc;
    vector<T> dec;
    vector<string> seq(N);
    auto f = [](char c) { return c == '(' ? 1 : -1; };

    REP(i, N) {
        string S; cin >> S;
        seq[i] = S;
        i64 h, m, hr;
        h = 0;
        m = 0;
        REP(j, S.length()) {
            h += f(S[j]);
            chmin(m, h);
        }

        if (h == 0) {
            con.emplace_back(m, h, i);
        } else if (h > 0) {
            inc.emplace_back(m, h, i);
        } else {
            dec.emplace_back(m - h, -1 * h, i);
        }
    }

    sort(inc.begin(), inc.end(), [](const T &t1, const T &t2){
        return get<0>(t1) > get<0>(t2);
    });
    sort(dec.begin(), dec.end(), [](const T &t1, const T &t2){
        return get<0>(t1) < get<0>(t2);
    });

    string ans = "";
    for (T t : inc) ans += seq[get<2>(t)];
    for (T t : con) ans += seq[get<2>(t)];
    for (T t : dec) ans += seq[get<2>(t)];
    //cout << ans << endl;

    i64 h = 0;
    bool ok = true;
    for (char c : ans) {
        h += f(c);
        if (h < 0) ok = false;
    }
    if (h != 0) ok = false;
    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 60724
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5+100;
const ll MOD = 1e9+7;
ll n;
ll a[N];
ll sum[N];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i] = sum[i-1]+a[i];
	}
	ll tot = sum[n];
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		ans = (ans + (a[i]*((tot - sum[i])%MOD))%MOD)%MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool ok(int v)
{
    string s = to_string(v);
    rep(i,s.size())if(s[i]!=s[0]+i) return false;
    return true;
}

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

    int ans = -1;
    rep(i,n)rep(j,i)
    {
        int v = a[i]*a[j];
        if(ok(v)) ans = max(ans,v);
    }

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

Measured memory_bytes: 3248
#include<stdio.h>
#include<string.h>
#include<queue>
#include<functional>
#include<algorithm>
using namespace std;
struct S{int i,c,r;};
struct C:binary_function<S,S,int>{int operator()(S l,S r){return l.c>r.c;}};
int main()
{
	int c,n,m,s,d,i,a,b,f,_=0x3f3f3f3f;
	int g[100][100];
	int x[100][11];
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&d),c)
	{
		memset(g,63,sizeof(g));
		memset(x,63,sizeof(x));
		for(i=0;i<m;++i)
		{
			scanf("%d%d%d",&a,&b,&f);
			g[a-1][b-1]=g[b-1][a-1]=f;
		}
		S p,t;
		p.c=0;
		p.r=c;
		p.i=s-1;
		priority_queue<S,vector<S>,C>q;
		q.push(p);
		while(!q.empty())
		{
			p=q.top();q.pop();
			if(x[p.i][p.r]<=p.c)continue;
			x[p.i][p.r]=p.c;
			for(i=0;i<n;++i)
			{
				if(g[p.i][i]==_)continue;
				if(p.r)
				{
					t=p;
					t.r--;
					t.c+=g[t.i][i]/2;
					t.i=i;
					q.push(t);
				}
				t=p;
				t.c+=g[t.i][i];
				t.i=i;
				q.push(t);
			}
		}
		printf("%d\n",*min_element(x[d-1],x[d]));
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main() {

	string s;
	int a[10000] = {};

	cin >> s;
	rep(i, 0, s.size()) {
		a[s[i]]++;
	}
	for (char c = 'a'; c <= 'z';c++) {
		if (a[c] == 0) {
			cout << c << endl;
			return 0;
		}
	}
	cout << "None" << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


int N;
vector<ll> a;
vector<vector<ll>> dp;

ll dfs(int l, int r)
{
    if(dp[l][r]!=INFL) return dp[l][r];
    ll resl = dfs(l+1, r);
    ll resr = dfs(l,r-1);
    return dp[l][r] = (r-l) % 2 != N % 2
      ? max(resl + a[l], resr + a[r])
      : min(resl - a[l], resr - a[r]);
}


int main()
{
    cin>>N;
    a.resize(N);
    REP(i,N)cin>>a[i];
 
    dp.resize(N,vector<ll>(N, INFL));
    REP(i,N)dp[i][i]=a[i] * (N%2==0?-1:1);

    cout << dfs(0,N-1) << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


bool isAll(string str) {
  char c = str[0];
  bool res = true;
  FOR (i, 1, str.size()) {
    if (str[i] != c) res = false;
  }
  return res;
}

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

  int ans = 1000;
  REP(i, 26) {
    char c = 'a' + i;
    if (s.find(c) != string::npos) {
      string now = s;
      int cnt = 0;
      string t;
      while (!isAll(now)) {
        REP (i, now.size() - 1) {
          if (now[i] == c || now[i + 1] == c) {
            t += c;
          } else {
            t += now[i];
          }
        }
        now = t;
        t = "";
        cnt++;
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 7");
            //5 6 7 8 9
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4 0");
            //-3 -2 -1 0 1 2 3
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1 100");
            //100
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = InputList[0].Split(' ').Select(pX => int.Parse(pX)).ToArray();
        int K = wkArr[0];
        int X = wkArr[1];

        var AnswerList = new List<string>();
        for (int I = X - (K - 1); I <= X + (K - 1); I++) {
            AnswerList.Add(I.ToString());
        }
        Console.WriteLine(string.Join(" ", AnswerList.ToArray()));
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		int[] list;
		int listSize;
		Scanner keyboard = new Scanner(System.in);
		Scanner integers;
		String inputString;
		
		//get input
		listSize = keyboard.nextInt();
		keyboard.nextLine();
		inputString = keyboard.nextLine();
		
		//initialize list
		list = new int[listSize];
		
		//get integers into our list
		integers = new Scanner(inputString);
		for(int i = 0; i < listSize; i++) {
			list[i] = integers.nextInt();
		}
		
		//output info
		for(int i = 1; i <= listSize; i++) {
			
			System.out.print("node " + i + ": ");
			System.out.print("key = " + list[i-1] + ", ");
			if(i > 1) System.out.print("parent key = " + list[(i/2) - 1] + ", ");
			if(2 * i <= listSize) System.out.print("left key = " + list[(2 * i) - 1] + ", ");
			if((2 * i) + 1 <= listSize) System.out.print("right key = " + list[(2 * i)] + ", ");
			System.out.println();
			
		}
		
		
		
		
	}

}


Measured memory_bytes: 27608
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	set<ll> X;
	READV(a);
	READV(b);
	READV(c);
	X.insert(a);
	X.insert(b);
	X.insert(c);
	if(sz(X)==2)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	

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


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int ans = min(b, d) - max(a, c);
	if(ans < 0){
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        var v = cin.ArrayInt(N);

        var odd_dic = new Dictionary<int, int>()
        {
            { int.MaxValue, 0 },
        };
        var even_dic = new Dictionary<int, int>()
        {
            { int.MaxValue, 0 },
        };
        for (int i = 0; i <= N - 2; i += 2) {
            if (even_dic.ContainsKey(v[i])) even_dic[v[i]]++;
            else even_dic[v[i]] = 1;
        }
        for (int i = 1; i <= N - 1; i += 2) {
            if (odd_dic.ContainsKey(v[i])) odd_dic[v[i]]++;
            else odd_dic[v[i]] = 1;
        }

        odd_dic = odd_dic.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        even_dic = even_dic.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        if (odd_dic.Keys.ElementAt(0) != even_dic.Keys.ElementAt(0)) Console.WriteLine(N - odd_dic.Values.ElementAt(0) - even_dic.Values.ElementAt(0));
        else {
            int a = N - odd_dic.Values.ElementAt(0) - even_dic.Values.ElementAt(1);
            int b = N - odd_dic.Values.ElementAt(1) - even_dic.Values.ElementAt(0);
            Console.WriteLine(Math.Min(a, b));
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 30048
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#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)
constexpr int MOD = 1000000007;
int main()
{
    lint N;
    cin >> N;
    lint min = 1e13;
    FOR(i, 1, 1000001) {
        if(N%i == 0) {
            lint tmp = (i-1) + (N/i-1);
            if(tmp < min) min = tmp;
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

struct UFT{    //O(loga(n))
    int n;
    vl d, r;
    UFT(int n) : n(n), d(n, -1), r(n, 0){};
    int root(int i){
        if(d[i] < 0) return i;
        return d[i] = root(d[i]);
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return false;

        if(r[x] < r[y]) swap(x, y);
        else if(r[x] == r[y]) r[x]++;
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    ll sum(int i){
        return -d[root(i)];
    }
};

const int MAX_N = 1e5+10;
const int MAX_M = 1e5+10;

struct Edge {
    int u, v;
    ll cost;
    bool operator < (const Edge& e) {
        return cost < e.cost;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    UFT uf(n);
    rep(i, n) {
        int x;
        cin >> x;
        uf.d[i] = -x;
    }
    vector<Edge> es(m);
    rep(i, m) {
        int u, v;
        ll cost;
        cin >> u >> v >> cost;
        --u;
        --v;
        es[i] = {u, v, cost};
    }
    sort(all(es));
    vector<int> crd(m);
    rep(i, m) {
        int u = es[i].u, v = es[i].v;
        ll cost = es[i].cost;
        uf.unite(u, v);
        // cout << u << " " << v << " " << cost << " " << uf.sum(u) << endl;
        if(uf.sum(u) >= cost) crd[i] = 1;
    }
    vector<vector<int>> ids(n);
    rep(i, m) {
        int u = es[i].u, v = es[i].v;
        ids[u].pb(i);
        ids[v].pb(i);
    }
    vector<int> used(m);
    repr(i, m) {
        if(crd[i] == 0 || used[i]) continue;
        int u = es[i].u, v = es[i].v;
        ll cost = es[i].cost;
        used[i] = 1;
        queue<int> q;
        q.push(u);
        q.push(v);
        while(!q.empty()) {
            auto p = q.front();
            q.pop();
            for(auto&& id : ids[p]) {
                if(used[id] || cost < es[id].cost) continue;
                used[id] = true;
                q.push(es[id].u);
                q.push(es[id].v);
            }
        }
    }
    int ans = 0;
    rep(i, m) if(!used[i]) ++ans;
    cout << ans << endl;
    // rep(i, m) cout << " " << used[i];
    // cout << endl;
    // rep(i, m) cout << " " << crd[i];
    // cout << endl;
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ignore ignore
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define YES printf("YES\n")
#define NO printf("NO\n")
#define yes printf("Yes\n")
#define no printf("No\n")
#define lin printf("\n")
// Iterator
#define rep(i,n) for(i=0;i<n;++i)
#define rrep(i,n) for(i=n-1;i>=0;--i)
#define lp(i,a,b) for(i=a;i<b;++i)
#define rlp(i,a,b) for(i=a;i>=b;--i)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// function
#define sz(x) x.size()
#define inrange(i,a,b) (i>=a && i<=b)
#define FLUSH fflush(stdout)
#define precision(x) cout << setprecision(x) << fixed
#define remax(a,b) a=max(a,b)
#define remin(a,b) a=min(a,b)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
// Constant
const double PI = acos(-1);
const double eps = (1e-9);
const ll INF = 2e15;
const int M = (1e9)+7;
const int N = (1e5);  // check the limit, man
int main()
{
    ll n,m;
    llin(n);
    m=1;
    ll sum=0;
    while(n>0)
    {
        sum+=m;
        n/=2;
        m*=2;
    }
    llout(sum);
}







Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<map>
#include<string>
#include<stdlib.h>
#define ran(x) (x).begin(),(x).end()
using namespace std;
int main() {
		string n;
		cin >> n;
		if(n == "0")
			return cout << "Yes" << endl, 0;
		int64_t sum = 0;
		for(auto i : n) {
			sum += (i)-48;
		}
		if(sum % 9 == 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;//*/
	
}

Measured memory_bytes: 3696
#include<stdio.h>
int main()
{	int a,b,x=0;
	scanf("%d %d",&a,&b);
	if(a>b){
	x+=a;
	a--;
	}else{
	x+=b;
	b--;
	}
		if(a>b){
		x+=a;
		a--;
		}else{
		x+=b;
		b--;
		}
	printf("%d",x);
return 0;
}

Measured memory_bytes: 128
#(34)フレームの描画
while True:
    H,W = [int(x) for x in input().split()]
    
    if (H,W)==(0,0): 
        break
    
    unit = "#."
    
    for i in range(H):
        print( unit*(W//2) + unit[0]*(W%2) )
        
        unit = unit[1] + unit[0]
    print("")


Measured memory_bytes: 5616
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 600016
#define MAXK 26
#define MAXX 15000006
#define ll long long
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define forit(it, A) for(set<ll>::iterator it = A.begin(); it != A.end(); it++)
#define bg(ms) *ms.begin()
#define ed(ms) *prev(ms.end(), 1)
#define addedge(a, b, c, v) v[a].pb(pi(b, c)); v[b].pb(pi(a, c))
#define ph push
#define all(x) x.begin(), x.end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll n, m;
map <ll, char> A;
string s1, s2;
ll gcd(ll a, ll b)
{
	if(b == 0)return a;
	return gcd(b, a%b);
}
int main()
{
	cin >> n >> m >> s1 >> s2;
	if(s1[0] != s2[0]){ cout << "-1\n"; return 0; }
	ll x = ((n*m)/gcd(max(n, m), min(n, m)));
	assert(x >= max(n, m));
	if(n < m){swap(n, m); swap(s1, s2); }
	for(ll i = 1; i < s2.length(); i++)
	{
		A[i*(x/m)] = s2[i];
	}
	for(ll i = 1; i < s1.length(); i++)
	{
		if(A.find(i*(x/n)) == A.end())A[i*(x/n)] = s1[i];
		else if(A[i*(x/n)] != s1[i]){ cout << "-1\n"; return 0; }
	}
	cout << x << "\n";
}


Measured memory_bytes: 10880
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long i, n, m, k;
    cin>>n>>m;
    long long sum = 0;
    for(i=0;i<m;++i)
    {
        cin>>k;
        sum += k;
    }
    if(sum > n) cout<<"-1";
    else    cout<<n-sum;
    return 0;
}

Measured memory_bytes: 3648
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e5 + 10, MOD = 1e9 + 7;
const ll INF = 1e18;

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n >= 3200)
		cout << s;
	else
		cout << "red";
}
int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

Measured memory_bytes: 256
import java.util.*;


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

        Scanner s = new Scanner(System.in);
        String n = s.next();

        int count = 0;
        for (String c : n.split("")) {
          if (c.equals("1")) {
            count++;
          }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC128-C, 
	int n, m; cin >> n >> m;
	vector<int> k(m), p(m);
	vector<vector<int>> s(m);
	rep(i, m) {
		cin >> k[i];
		s[i].resize(k[i]);
		rep(j, k[i]) cin >> s[i][j];
	}
	rep(i, m) cin >> p[i];
	
	int ans = 0;
	rep(i, 1 << n) {
		bool ok = true;
		rep(j, m) {
			int num = 0;
			rep(l, n) {
				if (i >> l & 1) {
					rep(o, k[j]) {
						if (s[j][o] == l + 1) num++;
					}
				}
			}
			if (num % 2 != p[j]) {
				ok = false;
				break;
			}
		}
		if (ok) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n,m;
int nu[100100];
llong sum[100100];
int main()
{
    scanf("%d%d",&n,&m);
    llong ans=0;
    for(int i=1;i<=n;++i)
        scanf("%d",&nu[i]);
    for(int i=2;i<=n;++i)
    {
        if(nu[i]>=nu[i-1])
        {
            ans+=nu[i]-nu[i-1];
            sum[nu[i-1]+2]++;
            sum[nu[i]+1]--;
        }
        else
        {
            ans+=nu[i]+m-nu[i-1];
            sum[nu[i-1]+2]++;
            sum[m+1]--;
            sum[0]+=m-nu[i-1]-1;
            sum[1]++;
            sum[nu[i]+1]--;
        }
    }
    for(int i=2;i<=m;++i)sum[i]+=sum[i-1];
    for(int i=2;i<=n;++i)
        if(nu[i]>=nu[i-1])
            sum[nu[i]+1]-=nu[i]-nu[i-1]-1;
        else sum[nu[i]+1]-=nu[i]+m-nu[i-1]-1;
    llong ma=0;
    for(int i=1;i<=m;++i)
    {
        sum[i]+=sum[i-1];
        ma=max(ma,sum[i]);
    }
    ans-=ma;
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

typedef long long int ll;

#define precision(x,d) cout<<fixed<<setprecision(d)<<x

bool check(string s)
{
    int p=0,q=s.length()-1;

    while(p<=q)
    {
        if(s[p]==s[q])
        {
            p++;
            q--;
        }
        else
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll n;
    cin >> n;

    long double ka = n*n*n;
    long double kh = 3*3*3;

    long double ans = ka/kh;

    precision(ans,13);
    return 0;
}


Measured memory_bytes: 256
import sys
def factoring(n):
    if n == 0:
        return {0: 1}
    if n == 1:
        return {1: 1}
    nOrigin = n
    n = n**0.5
    numlist = [0 for i in range(int(n) + 1)]
    numlist[0] = -1
    numlist[1] = -1

    t = 2
    while t < (n**0.5):
        if numlist[t] == 0:
            numlist[t] = t
            k = 2
            while t * k <= n:
                numlist[t * k] = -1
                k += 1
        t += 1
    while t <= n:
        if numlist[t] == 0:
            numlist[t] = t
        t += 1

    result = {}
    for i in numlist:
        if i == -1:
            continue
        j = 0
        while nOrigin % i == 0:
            j += 1
            nOrigin = nOrigin / i
        if j == 0:
            continue
        else:
            result[i] = j

    if int(nOrigin) != 1:
        result[int(nOrigin)] = 1
    return result

def help(e):
    i=0
    while i*(i+1)//2<=e:
        i+=1
    return i-1


N=int(input())
if N==1:
    print(0)
    sys.exit(0)
d=factoring(N)

retval=0
for key,value in d.items():
    retval+=help(value)


print(retval)


Measured memory_bytes: 19724
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	long long int a[100001];
	long long int asum = 0, sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += i + 1;
		asum += a[i];
	}
	if(asum % sum != 0){
		cout << "NO" << endl;
		return 0;
	}
	long long int k = asum / sum;
	long long int cnt = 0;
	for(int i = 0; i < n; i++){
		long long int tmp = k - (a[(i + 1) % n] - a[i]);
		// cout << tmp << endl;
		if(tmp % n != 0 || tmp < 0){
			cout << "NO" << endl;
			return 0;
		}
		cnt += tmp / n;
	}
	if(cnt == k){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
from math import factorial


def combination(n, r):
    if n < r:
        return 0
    else:
        return factorial(n) // (factorial(r) * factorial(n - r))


N, K = map(int, input().split())
MOD = 10 ** 9 + 7
for i in range(1, K + 1):
    ans = combination(N-K+1, i)*combination(K-1,i-1)
    print(ans % MOD)


Measured memory_bytes: 3316
#include <stdio.h>

int main(){
   int a,b,c,d;

   scanf("%d %d %d %d",&a,&b,&c,&d);
   while (a>0 && c>0) {
      c-=b;
      if (c<=0) break;
      a-=d;
   }
   if (a>0) puts("Yes");
   else     puts("No");
   return 0;
}


Measured memory_bytes: 1660
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			var b = cin.ArrayInt(n - 1);
			long ans = 0;
			for (int i = 0; i < n; i++)
			{
				if (i == 0) ans += b[i];
				else if (i == n - 1) ans += b[i - 1];
				else ans += Math.Min(b[i - 1], b[i]);
			}
			Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

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

using namespace std;

const int MAXN =200100;
typedef long long ll;
int n, m, a[MAXN];
ll p[MAXN];

int main()
{
    ll all = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; ++i) scanf("%d", a+i);
    for(int i=1; i<n; ++i)
    {
        int l = a[i-1], r = a[i];
        if(l>r) r += m;
        all += r-l;
        if(r-l>1)
        {
            p[l+2] += 1;
            p[r+1] -= (r-(l+2)+1) + 1;
            p[r+2] += (r-(l+2)+1);
        }
    }
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];

    ll ans = -1;
    for(int i=1; i<=m; ++i) ans = max(ans, p[i]+p[i+m]);
    cout << all - ans << endl;

    return 0;
}

Measured memory_bytes: 2176