akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    string b[n];  
	for (int i=0;i<n;i++) 
	{
    cin>>b[i];
    } 
	int m;
    cin >> m;
    string r[m]; 
	for (int i=0;i<m;i++) 
	{
    cin>>r[i];
    }
    int ans=0;
    for (int i=0;i<n;i++)
	{
		string word=b[i]; 
		int count=0;		
		for (int j=0;j<n;j++)
		{
		if(b[j]==word)
		count++;
		}		
		for(int j=0; j<m; j++)
		{
		if(r[j]==word) 
		count--;
		}		
		ans=max(ans,count);
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    N = int(readline())
    c = Counter(prime_factorize(N))

    ans = 0
    for power in c.values():
        tmp = power
        for j in range(1, power + 1):
            if j > tmp:
                break
            tmp -= j
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  for (i64 x = 1; x <= 3500; ++x) {
    for (i64 y = 1; y <= 3500; ++y) {
      i64 v1 = N * x * y;
      i64 v2 = 4 * x * y - N * y - N * x;
      if (v2 > 0 && v1 % v2 == 0 && v1 / v2 > 0) {
        i64 z = v1 / v2;
        cout << x << ' ' << y << ' ' << z << "\n";
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 998244353
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}

void solve()
{
	int a, b, c,sol=0;
	cin >> a >> b >> c;
	sol = max(sol, c - (a - b));
	cout << sol;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ran 2222
int row,col;
int a[ran][ran];
int R[ran][ran];
int C[ran][ran];
int sub(int a[ran][ran], int X1,int Y1,int X2,int Y2){
	if(X1 > X2 || Y1 > Y2)return 0;
	--X1;--Y1;
	return a[X1][Y1] + a[X2][Y2] - a[X1][Y2] - a[X2][Y1];
}
int main(){
	int q;
	char s[ran];
	scanf("%d%d%d",&row,&col,&q);
	for(int i=1; i<=row; i++){
		scanf("%s",s);
		for(int j=1; j<=col; j++)
			if(s[j-1] == '1')
				a[i][j] = 1;
	}
	for(int i=1; i<=row; i++)
		for(int j=1; j<=col; j++){
			if(i<row && a[i][j] == 1 && a[i+1][j] == 1)
				R[i][j] = 1;
			if(j<col && a[i][j] == 1 && a[i][j+1] == 1)
				C[i][j] = 1;
		}
	for(int i=1; i<=row; i++)
		for(int j=1; j<=col; j++){
			R[i][j] += R[i][j-1];
			C[i][j] += C[i][j-1];
			a[i][j] += a[i][j-1];
		}
	for(int i=1; i<=row; i++)
		for(int j=1; j<=col; j++){
			R[i][j] += R[i-1][j];
			C[i][j] += C[i-1][j];
			a[i][j] += a[i-1][j];
		}
	while(q--){
		int X1,Y1,X2,Y2;
		scanf("%d%d%d%d",&X1,&Y1,&X2,&Y2);
		printf("%d\n",sub(a, X1,Y1,X2,Y2) -
		sub(R, X1, Y1, X2-1, Y2) - sub(C, X1, Y1, X2, Y2-1));
	}
	return 0;
}


Measured memory_bytes: 59136
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    FOR(i, 0, n)
    {
        cin >> v[i];
        sum += v[i];
    }
    if (sum % n <= n / 2)
    {
        sum = sum / n;
    }
    else
    {
        sum = sum / n + 1;
    }
    int ans = 0;
    FOR(i, 0, n) { ans += (sum - v[i]) * (sum - v[i]); }
    cout << ans << '\n';
}


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

int n, q;
string s;
char t[200010], d[200010];
int num_g = { 1 };

int can_reach (int pos) {
  for (int i = 0; i < q; i++) {
    if (t[i] == s[pos]) {
      if (d[i] == 'L') {
        pos--;
        if (pos == -1) break;
      } else {
        pos++;
        if (pos == n) break;
      }
    }
  }
  return pos;
}

int main () {


  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < q; i++) {
    cin >> t[i] >> d[i];
  }

  int pos = (n - 1) / 2;
  int left = -1;
  int right = n;
  bool flag = true;

  while(right - left > 1) {
    if (can_reach(pos) == -1) {
      left = pos;
      pos = (left + right) / 2;
    } else {
      right = pos;
      pos = (left + right) / 2;
    }
  }
  int left2 = left;

  pos = (n - 1) / 2;
  left = -1;
  right = n;
  while(right - left > 1) {
    if (can_reach(pos) == n) {
      right = pos;
      pos = (left + right) / 2;
    } else {
      left = pos;
      pos = (left + right) / 2;
    }
  }
  int right2 = right;

  if (left2 < right2) {
    cout << right2 - left2 - 1 << endl;
  } else if (left2 >= right2) {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using ll = long long;
using pll = std::pair<ll, ll>;
using namespace std;
int n, m, x, y;
std::vector<pll> vec, vec2;
int pre_num = -1;
int num = -2;
std::map<pll, int> ma;

int main() {
    std::cin >> n >> m;
    for (int i = 0; i < m; i++) {
        std::cin >> x >> y;
        vec.push_back(std::make_pair(x, y));
        vec2.push_back(std::make_pair(x, y));
    }
    std::sort(vec2.begin(), vec2.end());
    for (auto &e: vec2) {
        if (e.first != pre_num) {
            num = 1;
            pre_num = e.first;
        }
        ma[e] = num;
        num++;
    }
    for (int i = 0; i < m; i++) {
        auto t = vec[i];
        printf("%06lld%06d\n", t.first, ma[t]);
    }
}

Measured memory_bytes: 11876
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
void print(LL i);
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

int main() {
    int a[4];
    REP(i, 4) {
        RI(a[i]);
    }
    sort(a, a+4);
    puts((a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	if A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 {
		fmt.Println("Possible")
		return
	}
	fmt.Println("Impossible")
}


Measured memory_bytes: 512
# include <iostream>
# include <string>
using namespace std;
const int INFTY = 1e+9;

int main() {
    string S;
    cin >> S;
    int len = S.length();

    int ans = INFTY;
    for(int i = 0; i <= len - 3; i++){
        int num = stoi(S.substr(i, 3));
        ans = min(ans, abs(num - 753));
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int k, n;
	cin >> k >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	a.push_back(a[0] + k);
	int l = 0;
	for (int i = 0; i < n; i++) {
		l = max(l, a[i + 1] - a[i]);
	}

	int ans = k - l;
	cout << ans << endl;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	string u,d; cin>>u>>d;
	int ans=3; const int mod=1e9+7;
	for(int i=1;i<n;++i){
		if(u.at(i)!=u.at(i-1)){
			if(u.at(i-1)!=d.at(i-1)&&u.at(i)==d.at(i))continue;
			else if(u.at(i-1)!=d.at(i-1)&&u.at(i)!=d.at(i))ans=(int64_t)ans*3%mod;
			else ans=(int64_t)ans*2%mod;
		}
	}
	if(n>=2&&u.at(0)!=d.at(0)&&u.at(0)==u.at(1))ans=(int64_t)ans*2%mod;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n; cin >> n;
    map<string, priority_queue<P>> mp;
    REP(i,n) {
        string s; ll p;
        cin >> s >> p;
        mp[s].push({p,i});
    }
    for (auto &&e: mp) {
        while (!e.second.empty()) {
            P x = e.second.top(); e.second.pop();
            cout << x.second+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [_ for _ in range(1,n+1)]

x = []
for i in range(1,n+1):
    a = 0
    b = i
    for j in range(int(n**0.5)):
        if b%2 == 0:
            a += 1
            b = b/2
    x.append(a)

c = x.index(max(x))

print(l[c])


Measured memory_bytes: 3060
n = int(input())
nums = [int(i) for i in input().split()]
rem = 2_000_000_000
for i in range(0, 101):
  distance_sum = 0
  for x in nums:
    distance_sum += (x - i)**2
  
  if distance_sum < rem: rem = distance_sum
    
print(rem)
  

Measured memory_bytes: 9164
#include <stdio.h>

#define M 2000000

int H,C[M+1];

void maxC(int i){
  int la,t,r,A;
  t=2*i;
  r=2*i+1;

  if(t<=H&&C[t]>C[i])
    la=t;
  else la=i;
  if(r<=H&&C[r]>C[la])
    la=r;
  if(la!=i){
    A=C[i];
    C[i]=C[la];
    C[la]=A;
    maxC(la);
  }
}

int main(){
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++)
    scanf("%d",&C[i]);
  for(i=H/2;i>=1;i--)
    maxC(i);
  for(i=1;i<=H;i++){
    printf(" %d",C[i]);
}
  printf("\n");
}



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

struct Sieve {
  vector<int> f, primes; // primesは素数集合，fは合成数に素因数を一つ示したもの
  Sieve(int N):f(N+1,0) {
    f[0] = f[1] = -1;
    for (int i = 2; i <= N; ++i) {
      if (!f[i]==0){
        continue;
      }
      primes.push_back(i);
      f[i] = i;
      if(i>sqrt(N)){
        continue;
      }
      for (int j = i*i; j <= N; j += i) {
        if (f[j]==0){
          f[j] = i;
        }
      }
    }
  }

  bool isPrime(int x) { //xが素数かどうかを判断するメンバ関数
    return f[x] == x;
  }

  vector<int> factorList(int x) { //xの素因数を小さい順ソートされた配列
    vector<int> res;
    if(x==0 || x==1){
      return { };
    }
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  vector<pair<int,int>> factor(int x) { //xのfactorListをランレングス圧縮したもの
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<int,int>> res(1, make_pair(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      }
      else {
        res.push_back(make_pair(p, 1));
      }
    }
    return res;
  }

  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0){
        x /= p, ++y;
      }
      if (y != 0){
        res.push_back(make_pair(p,y));
      }
    }
    if (x != 1){
      res.push_back(make_pair(x,1));
    }
    return res;
  }
};

int main(){
  ll N;
  cin >> N;
  Sieve S(1e6+5);
  vector<pair<ll,int>> fac=S.factor(N);
  ll ans=0;
  for(pair<ll,int>  p: fac){
    ans+=floor((-1+sqrt(1+8*p.second))/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 7892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s, t;
  ll a, b, c, d, e, f, x, y, z, n, m;

  cin >> a >> b >> m;
  vl aa(a);
  vl bb(b);
  rep(i, a) {
    cin >> aa[i];
  }
  rep(i, b) {
    cin >> bb[i];
  }

  ll ans = 1LL<<60;
  rep(i, m) {
    cin >> x >> y >> c;
    cmin(ans, aa[x-1]+bb[y-1]-c);
  }

  sort(all(aa));
  sort(all(bb));

  cmin(ans, aa[0]+bb[0]);
  cout << ans << endl;
}


Measured memory_bytes: 1792
#pragma region // {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion // }}}

void main() {
    vector<int> vs;
    LL n;
    cin >> n;
    for ( LL b=1; b<=3500; b++ ) {
        for ( LL c=1; c<=3500; c++ ) {
            LL x=b*c*n;
            LL y=4*b*c - b*n -c*n;
            if ( x<=0 || y<=0 ) continue;
            if ( x%y==0 ) {
                cout << x/y << ' ' << b << ' ' << c << '\n';
                exit(0);
            }
        }
    }
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int 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;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


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

}









Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 1;
        int cur = 1;
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        for(int i = 1; i < n; i++) {
            if(h[i] <= h[i - 1]) {
                ++cur;
                ans = Math.max(cur, ans);
            } else {
                cur = 1;
            }
        }
        System.out.println(ans - 1);

    }
}

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

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    vector<vector<int>> d(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }

    const int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
    const int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
            {
                for (int k = 0; k < 8; k++)
                {
                    int y = i + dy[k];
                    int x = j + dx[k];
                    if (y < 0 || y >= H || x < 0 || x >= W)
                        continue;
                    d[y][x]++;
                }
            }
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] != '#')
                cout << d[i][j];
            else
                cout << S[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	set<string> s;
	string word;
	for(int i=1;i<=n;i++){
		cin>>word;
		s.insert(word); 
	}
	cout<<s.size()<<'\n';
	return 0;
}

Measured memory_bytes: 19128
num=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(num[k-1])

Measured memory_bytes: 3060
n = int(input())

l_i = 0
l_i_1 = 1
l_i_2 = 2

if n == 1:
  print("1")
else:
  for i in range(n-1):
    l_i = 0
    l_i = l_i_1 + l_i_2
    l_i_2 = l_i_1
    l_i_1 = l_i
  print(l_i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    ll x,y;
    cin>>x>>y;
    ll m=log10(y)+1;
    x=x*powl(10,m);
    x+=y;
    if (sqrtl(x)==(int)sqrtl(x))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N;  string S;
    cin >> N >> S;
    
    int ans = 0;
    for(int n=1; n<N; n++){
        string candidate = S.substr(n-ans, ans+1);
        bool flag = false;
        for(int i=0; i+ans<n-ans; i++){
            if(S[i] != candidate[0])
                continue;
            string taken = S.substr(i, ans+1);
            if(taken == candidate)
                flag = true;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
int a[300000],b[300000];
int main(){
	int n;
	cin>>n;
	int maxx=0;
	map<int,int> num;
	for(int i=1;i<=n;i++){
		 cin>>a[i];
		 b[i]=a[i];
		 num[a[i]]++;
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++){
		if(a[i]!=b[n]) cout<<b[n]<<endl;
		else{
			if(num[b[n]]>1) cout<<b[n]<<endl;
			else cout<<b[n-1]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 8704
#include <iostream>

#define INF 1e9 + 7;

int main(){
    int a, b, c, x, y;
    std::cin >> a >> b >> c >> x >> y;

    int ans = (int)INF; 
    for(int i = 0; i <= std::max(x, y) * 2; i += 2){ // alter the number of mixed pizzas
        ans = std::min(ans, std::max(0, x - i / 2) * a + std::max(0, y - i / 2) * b + i * c);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T>inline void read(T &x){
	int p=1;x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')p=-1;
		c=getchar();
	}
	while(isdigit(c)){
		x=(x<<3)+(x<<1)+(c^'0');
		c=getchar();
	}
	x*=p;
}
int a,b,c,d;
int main(){
	read(a),read(b),read(c),read(d);
	cout<<min(a,b)+min(c,d)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
  string S;
  cin>>S;
  int ans = 1e4;
  for (int i = 0; i + 3 <= S.size(); i++) {
    int tmp,res;
    tmp = (S[i]-'0') * 100 + (S[i+1] - '0') * 10 + (S[i+2] - '0');
    res = abs(tmp - 753);
    ans = min(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N; cin >> N;
  ll ans = 0;
  
  //main
  for(int i=ceil(sqrt(N)); i>=1; i--){
    if(N%i == 0){ ans = N/i+i-2; break; }
    else{ continue; }
  }
  
  // output
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))    

Measured memory_bytes: 41180
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll i,j,n,m;
	string s, t;
	cin>>s>>t;
	n= s.size();
	m= t.size();
	
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if(s<t)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}























Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
os << P.first;
os << " ";
os << P.second;
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
/*struct DLL{
    struct node{
        int key;
        node* prev;
        node* next;
    }
    node* top_node;
    public:
        DLL(): top(new node){
            top->x = 0;
            top->prev = top_node;
            top->next = top_node;
        }
        ~DLL(){

        }
        void insert(int x){

        }
    };
}*/
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    deque<int> q;
    string s;
    int x;
    REP(i,N){
        cin >> s;
        if(s=="insert"){
            cin >> x;
            q.push_front(x);
        }else if(s=="delete"){
            cin >> x;
            auto it= q.begin();
            while( it!=q.end()){
                if(*it == x){
                    q.erase(it);
                    break;}
                it++;

            }
        }
        else if(s=="deleteFirst"){
            q.pop_front();
        }else{
            q.pop_back();
            
        }

    }
    for(auto it=q.begin();it<q.end();it++){
        if(it!=q.begin()) cout << " ";
        cout << *it;
    }
    cout << endl;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    using c = struct{int x; int y;};
    std::vector<c> A;
    REP(i, N) {
        int x, y;
        std::cin >> x >> y;
        A.push_back(c{x, y});
    }


    vector<int> v(N);
    iota(ALL(v), 0);

    double ans = 0;
    int    cnt = 0;
    auto dist = [](c& a, c& b) -> double {
                    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
                };
    do {
        cnt++;
        for(int i = 0; i < N - 1; i++) {
            ans += dist(A[v[i]], A[v[i + 1]]);
        }
    } while(std::next_permutation(v.begin(), v.end()));

    std::cout << setprecision(10) << ans / cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n;
int f()
{
	int a,b;scanf("%d:%d",&a,&b);return a*60+b;
}
main()
{
	while(cin>>n,n)
	{
		int a[1000]={};
		int t[1000]={};
		int ans=0;
		bool flag=false;
		for(;n--;)
		{
			string s;cin>>s;
			int X=f();
			string io;int id;cin>>io>>id;
			if(io=="I")
			{
				if(id)t[id]=X;
				else
				{
					for(int j=1;j<1000;j++)if(t[j])t[j]=X;
					flag=true;
				}
			}
			else
			{
				if(id)
				{
					if(flag)
					{
						a[id]+=X-t[id];
						ans=max(ans,a[id]);
					}
					t[id]=0;
				}
				else
				{
					for(int j=1;j<1000;j++)
					{
						if(t[j])
						{
							a[j]+=X-t[j];
							ans=max(ans,a[j]);
						}
					}
					flag=false;
				}
			}
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


int main(){
    int N,D;
    cin >> N >> D;

    vector<vector<int>> v(N,vector<int>(D));
    for (int i = 0; i < N; i++)
    {
        /* code */
        for (int j = 0; j < D; j++)
        {
            /* code */
            cin >> v[i][j];
        }
    }
    int ans = 0;
    int diff = 0;
    for (int i = 0; i < N; i++)
    {
        /* code */
        for (int j =i + 1 ; j < N; j++)
        {
            int dist = 0;
            bool flag = false;
            /* code */
            for (int k = 0; k < D; k++)
            {
                /* code */
                diff = abs(v[i][k] - v[j][k]);
                dist += diff * diff;
            }
            for(int k = 0; k <= dist;k++){
               if(k * k == dist){
                   flag = true;
               } 
            }
            if(flag){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
maxa = max(a)
max_index = [i for i, x in enumerate(a) if x == maxa]
if len(max_index) >= 2:
    for i in range(n):
        print(maxa)
else:
    for i in range(n):
        if i == max_index[0]:
            print(sorted(a)[-2])
        else:
            print(maxa)

Measured memory_bytes: 71128
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int query(int pos){
    printf("%d\n", pos);
    fflush(stdout);
    string s; cin >> s;
    return s[0] == 'M' ? 0 : s[0] == 'F' ? 1 : 2;
}

int main(){
    int N; cin >> N;
    vector<int> result(N+1, -1);
    int L = 0, R = N;
    result[0] = result[N] = query(0);
    if(result[0] == 2) return 0;
    while(true){
        int mid = (L+R)/2;
        result[mid] = query(mid);
        if(result[mid] == 2) break;
        if((mid-L)%2 == 0 ? result[L] == result[mid] : result[L] != result[mid]) L = mid;
        else R = mid;
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n;
string s;

int main(){
    cin >> s;
    ll ans = 0;
    int f1 = 0,f2 = 0;
    for(int i = s.length()-1; i >= 0; i--){
        if(s[i] == 'B')f1 = 1;
        else    f2 = 1;
    }

    int en = s.length()-1;
    if(f1 != 1 && f2 != 1){
        cout << 0 << endl;
        return 0;
    }
    bool flag = false;
    for(int i = s.length()-1; i >= 0; i--){
        if(s[i] == 'B'){
            ans += en-i;
            --en;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] h = in.nextIntArray(n);

        int current = 0;
        int max = 0;
        for (int i=0; i < n-1; i++) {
            if (h[i] >= h[i+1]) {
                current++;
            } else {
                max = Math.max(max, current);
                current = 0;
            }
        }

        out.println(Math.max(max, current));
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}


Measured memory_bytes: 41048
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>

using Gate = std::pair<int, int>;

int solve(int n, const std::vector<Gate>& gates)
{
  int first = 1;
  int last = n;
  for (const auto& g : gates) {
    first = std::max(first, g.first);
    last = std::min(last, g.second);
    if (last < first) break;
  }
  return first <= last ? last - first + 1 : 0;
}

int main()
{
  int n, m;
  std::cin >> n >> m;

  std::vector<Gate> gates(m);
  for (auto& g : gates) {
    std::cin >> g.first >> g.second;
  }

  std::cout << solve(n, gates) << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	ll n;
	cin>>n;
	int arr[n],col[9]={0},minV=0,maxV=0,flag=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]>3199)
			col[8]++;
		else
			col[arr[i]/400]++;
	}
	for(int i=0;i<8;i++)
		if(col[i])
			minV++;
	if(minV==0)
			cout<<minV+1<<" "<<minV+col[8];		
	else
			cout<<minV<<" "<<minV+col[8];

	return 0;
}



Measured memory_bytes: 3568
n,*a=map(int,open(0).read().split())
for i in range(n-1):
    a[i+1]+=a[i]
j,k=0,2
m=1e18
for i in range(1,n-1):
    while abs(a[j]*2-a[i])>abs(a[j+1]*2-a[i]):
        j+=1
    while abs(a[k]*2-a[i]-a[n-1])>abs(a[k+1]*2-a[i]-a[n-1]):
        k+=1
    t=a[j],a[i]-a[j],a[k]-a[i],a[n-1]-a[k]
    m=min(m,max(t)-min(t))
print(m)

Measured memory_bytes: 96636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    q = I()
    qi = 0

    while qi < q:
        qi += 1
        n = S()
        r = 0
        while len(n) > 1:
            r += 1
            t = 0
            for i in range(1,len(n)):
                u = int(n[:i]) * int(n[i:])
                if t < u:
                    t = u
            n = str(t)
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




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

struct UnionFind {
    vector<int> d;
    UnionFind(int n = 0) : d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n);
    UnionFind railway(n);
    for (int i = 0; i < k; ++i) {
        int p, q;
        cin >> p >> q;
        --p; --q;
        road.unite(p, q);
    }
    for (int j = 0; j < l; ++j) {
        int r, s;
        cin >> r >> s;
        --r; --s;
        railway.unite(r, s);
    }
    map<pair<int, int>, int> ma;
    for (int v = 0; v < n; ++v) {
        pair<int, int> p(road.find(v), railway.find(v));
        ma[p]++;
    }
    for (int v = 0; v < n; ++v) {
        pair<int, int> p(road.find(v), railway.find(v));
        cout << ma[p] << " ";
    }
    cout<< endl;
}


Measured memory_bytes: 13568
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
typedef long long ll;
using namespace std;
int n;
int main(int argc,char const* argv[])
{
  cin >> n;
  int ans=0;
  vector<int> a(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  for(int i=0;i<n;i++)
    {
      if(a[i]==i+1) 
	{
	  if(i==n-1)
	    {
	      swap(a[i-1],a[i]);
	      ans++;
	    }
	    
	  else
	    {
	      swap(a[i],a[i+1]);
	      ans++;
	    }
	}
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int maxN = 2 * (int)1e5 + 100;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int dp[maxN];
int a[maxN];
vector < int > all[maxN];
int b[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        all[a[i]].push_back(i);
    }
    int ans = 1;
    int cur = 0;
    for (int i = 1; i <= n; i++) {
        if (cur > 0 && a[i] == b[cur]) continue;
        cur++;
        b[cur] = a[i];
    }
    dp[0] = 1;
    for (int i = cur; i >= 1; i--) {
        dp[b[i]] = sum(dp[b[i]], dp[b[i + 1]]);
    }
    cout << dp[b[1]];
    return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
char s[3010],t[3010];
int m,n;
int dp[3010][3010];
int fr[3010][3010];
void dfs(int i,int j){
	if(i==0||j==0)return;
	if(fr[i][j]==1)dfs(i-1,j);
	if(fr[i][j]==2)dfs(i,j-1);
	if(fr[i][j]==3){
		dfs(i-1,j-1);
		cout<<s[i];
	}
}
int main(){
	scanf("%s%s",s+1,t+1);
	m=strlen(s+1);
	n=strlen(t+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++){
			if(dp[i-1][j]>dp[i][j-1]){
				fr[i][j]=1;
				dp[i][j]=dp[i-1][j];
			}
			else{
				fr[i][j]=2;
				dp[i][j]=dp[i][j-1];
			}
			if(s[i]==t[j]&&dp[i][j]<dp[i-1][j-1]+1){
				fr[i][j]=3;
				dp[i][j]=dp[i-1][j-1]+1;
			}
		}
	dfs(m,n);
	return 0;
}

Measured memory_bytes: 74456
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;


int mod[105];
int main(){
    //freopen("in.txt","r",stdin);
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    memset(mod,0,sizeof(mod));
    for(int i=1;;i++){
        int t=a*i%b;
        if(mod[t]){
            break;
        }
        mod[t]++;
    }
    if(mod[c]) printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {int f[N2], space, MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
  int sum = 0;
  for (int i = 0; i < N2; i++) {
    if (pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved() {
  for (int i = 0; i < N2; i++) if (state.f[i] != i + 1) return false;
  return true;
}

bool dfs(int depth, int prev) {
  if (state.MD == 0) return true;
  if (depth + state.MD > limit ) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for (int r = 0; r < 4; r++) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
    if ( max(prev, r) - min(prev, r) == 2 ) continue;
    tmp = state;

    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if ( dfs(depth + 1, r) ) {
      path[depth] = r;
      return true;
    }
    state = tmp;
  }

  return false;
}

string iterative_deepening(Puzzle in) {
  in.MD = getAllMD(in);

  for ( limit = in.MD; limit <= LIMIT; limit++) {
    state = in;
    if ( dfs(0, -100) ) {
      string ans = "";
      for (int i = 0; i < limit; i++) {
        ans += dir[path[i]];
      }
      return ans;
    }
  }

  return "unsolvable";
}

int main() {
  for (int i = 0; i < N2; i++) {
    for (int j = 0; j < N2; j++) {
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
    }
  }

  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }

  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 3184