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

int main(){
	ll l, r;
	cin >> l >> r;
	
	if(r-l >= 2019){
		cout << 0 << endl;
	}
	else{
		ll ans = 2020;
		for(ll i= l; i<=r; i++){
			for(ll j=i+1; j<=r; j++){
				ans = min(ans, (i*j)%2019);
			}
		}
		
		cout << ans << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<char,int> MIN_of;
    for(char c='a'; c<='z'; c++)
        MIN_of[c]=1e9;
    REP(i,n){
        map<char,int> A;
        for(char c='a'; c<='z'; c++)
            A[c]=0;
        string si;
        cin >> si;
        for(auto c : si)
            A[c]++;
        for(auto c : A){
            MIN_of[c.first] = min(MIN_of[c.first], c.second);
        }
    }
    string ans="";
    for(char c='a';c<='z'; c++)
        REP(i,MIN_of[c]) ans.push_back(c);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, K;
  cin>>N>>K;

  vector<Int> A(N);
  cin>>A;

  for(Int i=K;i<N;i++){
    if(A[i - K] < A[i]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 4772
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    string s;
    cin >> s;

    vector<int> sv(2, 0);
    for (int i = 0, prev = '0'; i < n; i++) {
        if (prev == s[i]) {
            sv[sv.size() - 1]++;
        } else {
            prev = s[i];
            sv.push_back(sv[sv.size() - 1] + 1);
        }
    }

    int max = 0;
    for (int i = (s[0] == '0' ? 1 : 2); i < static_cast<int>(sv.size()); i++) {
        int l = (i % 2 == 0 ? (i - 2 * k - 1) : (i - 2 * k));
        if (l < 0) {
            l = 0;
        }

        if (max < sv[i] - sv[l]) {
            max = sv[i] - sv[l];
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 1020
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(S: str):
    N = len(S)
    # 0:文字列の総数 1:Aの数  2:ABの数 3:ABCの数
    ## dp[i][j] = i文字目まで見たときに状態jの数
    ## answer: dp[N][3]

    dp = [[0]*4 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in (0,1,2,3):
            if S[i] == "?":
                dp[i+1][j] += dp[i][j]*3
            else:
                dp[i+1][j] += dp[i][j]

            dp[i+1][j]%=MOD
            
        ## カウント進める場合
        if S[i] == "A" or S[i] == "?":
            dp[i+1][1] += dp[i][0]
            # dp[i+1][1] %= MOD
        
        if S[i] == "B" or S[i] == "?":
            dp[i+1][2] += dp[i][1]
            # dp[i+1][2] %= MOD

        if S[i] == "C" or S[i] == "?":
            dp[i+1][3] += dp[i][2]
            # dp[i+1][3] %= MOD

    print(dp[N][3]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28672
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long cnt = 0;
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            mergeSort(Ai, 0, (int)N);
            WriteLine(String.Join(" ", Ai));
            WriteLine(cnt);
        }
        static public void merge(long[] A, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;
            var L = new long[n1 + 1];
            var R = new long[n2 + 1];
            for (var i = 0; i < n1; ++i)
            { L[i] = A[left + i]; }
            for (var i = 0; i < n2; ++i)
            { R[i] = A[mid + i]; }
            L[n1] = long.MaxValue;
            R[n2] = long.MaxValue;
            var im = 0;
            var jm = 0;
            for (var k = left; k < right; ++k)
            {
                if (L[im] <= R[jm])
                {
                    A[k] = L[im];
                    ++im;
                }
                else
                {
                    A[k] = R[jm];
                    ++jm;
                }
                ++cnt;
            }
        }
        public static void mergeSort(long[] A, int left, int right)
        {
            if(left+1<right)
            {
                var mid = (left + right) / 2;
                mergeSort(A, left, mid);
                mergeSort(A, mid, right);
                merge(A, left, mid, right);
            }
        }
    }
}



Measured memory_bytes: 70148
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n, ans = 0;
	int result;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 1,j=0; i < n; ++i)
	{
		if (s[i] == t[j])
		{
			ans++;
			j++;
		}
			
	}
	if (s == t)
		result = n ;
	else
	{
		result = n *2- ans;
	}
	cout <<result<< endl;
	return 0;

}


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

int main() {
  // N個の変数を配列に格納
  int N;
  cin >> N;

  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }

  int cnt = 0;
  int min = INT_MAX;
  for (size_t i = 0; i < N; i++) {
    if (a.at(i) <= min) {
      min = a.at(i);
      cnt++;
    }
  }

  cout << cnt;
}

Measured memory_bytes: 1024
N = int(input())
S = str(input())
sets = [(set(S[:i+1]),set(S[i+1:])) for i in range(len(S)-1)]
size_of_intersection = [len(s1.intersection(s2)) for s1, s2 in sets]
if size_of_intersection:
    print(max(size_of_intersection))
else:
    print(0)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s;
signed main() {
	while (cin >> s && s != "0") {
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			sum += (int)(s[i] - '0');
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3172
N = int(input())

X = N / 1.08
X1 = int(X)
X2 = X1 + 1

if N <= X1 * 1.08 < N + 1:
    print(X1)
elif N <= X2 * 1.08 < N + 1:
    print(X2)
else:
    print(':(')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n; cin>>n;
    vector<ll> a(3*n);
    rep(i,3*n) cin>>a[i];
    sort(a.begin(), a.end(), greater<ll>());
    ll res=0;
    rep(i,n) res+=a[2*i+1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
const int N=2e5+1;
int n,a[N],q[N],t,L[N],R[N];
long long A;
void D(int k,int l,int r)
{
	A+=(long long)a[k]*(k-l+1)*(r-k+1);
	if(L[k])
		D(L[k],l,k-1);
	if(R[k])
		D(R[k],k+1,r);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		while(t&&a[q[t]]>a[i])
			L[i]=q[t--];
		R[q[t]]=i,q[++t]=i;
	}
	D(q[1],1,n);
	cout<<A;
	return 0;
}

Measured memory_bytes: 8064
from scipy.optimize import*
from numpy import*
n=int(input())
x=array([list(map(int,input().split()))for _ in range(n)])
def r(a):return sqrt(square(x-a).sum(1).max())
print(minimize(r,[0,0],method="Nelder-Mead",tol=1e-8).fun)

Measured memory_bytes: 17464
import java.util.*;

class Main {
        private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    public static void main (String[] args){
        Scanner stdIn = new Scanner(System.in);
        long A = stdIn.nextInt();
        long B = stdIn.nextInt();

        long C=0;

        C = A*B / gcd(A,B);
        System.out.print(C);



    }
}

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

int main() {
	ll c=0,a[3],i,c1=0;
	for(i=0;i<3;i++){
		cin>>a[i];
		if(a[i]==5)
		c++;
		else if(a[i]==7)
		c1++;
	}
	if(c==2 && c1==1)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int xx, yy;
int sz[100010];
int u[100010];
int v[100010];
int p[100010];
int visited[100010];
int dap = 0;
vector<vector<int>> vt;
void dfs(int here, int par) {
	visited[here] = 1;
	for (int i = 0; i < vt[here].size(); i++) {
		int next = vt[here][i];
		if (next == par)continue;
		if (!visited[next] && sz[next] == 2)
			dfs(next, here);
		if (next == yy)
			dap++;
	}
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	vt.resize(n + 1);
	int cnt = 0, cnt1 = 0;
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &u[i], &v[i]);
		vt[u[i]].push_back(v[i]);
		vt[v[i]].push_back(u[i]);
		sz[u[i]]++; sz[v[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		p[i] = i;
		if (sz[i] % 2) {
			puts("No");
			return 0;
		}
		if (sz[i] >= 6)cnt++;
		if (sz[i] == 4)cnt1++;
	}
	if (cnt || cnt1 >= 3) {
		puts("Yes");
		return 0;
	}
	if (cnt1 == 2) {
		for (int i = 1; i <= n; i++) {
			if (sz[i] == 4) {
				if (!xx)
					xx = i;
				else
					yy = i;
			}
		}
		dfs(xx, 0);
		if (dap == 2)
			puts("Yes");
		else
			puts("No");
		return 0;
	}
	puts("No");

}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;
bool isPowerOfTwo(int n)
{
    if(n==0)
        return false;

    return (ceil(log2(n)) == floor(log2(n)));
}
void solve() {
  int n;
  cin>>n;
  vector<int> v(n);
  for(auto &i:v) {
      cin >> i;
  }
  int xx=v[0];
  for(auto i=1;i<n;++i) xx^=v[i];
  for(int i=0;i<n;++i)
  {
      cout<<(xx^v[i])<<" ";
  }

}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //int t;cin>>t;while(t--)
        solve();
}

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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int a , b , t;
   cin >> a >> b >> t;
   cout << (t / a * b) << '\n';
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<ll,ll> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res=(a*res)%10;
        }
        a=(a*a);
        b/=2;
    }
    return res;
} 
void solve(){
    ll n;
    cin>>n;
    string ans="";
    while(n){
        ll x=n/26;
        ll y=n%26;
        if(y==0){ 
            x--;
            ans=(char)'z'+ans;
        }
        else ans=(char)(y+'a'-1)+ans;
        n=x;
    }
    cout<<ans;
}
int main() {
	// your code goes here
	//isprime();
	//prime(); 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//int t;
	//cin>>t;
	//while(t--) 
	    solve();
	return 0; 
	
}


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

using namespace std;

int main() {
    int n, a[100009];
    bool visited[100009];    
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        visited[i] = false;
    }

    int r = 0;
    int p = 1;
    while(true) {
        if(p==2) {
            cout << r << endl;
            return 0;
        }
        if(visited[p]) {
            cout << -1 << endl;
            return 0;
        }
        visited[p] = true;
        p = a[p];
        r++;
    }

}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
 
  for (int i = 0; i < N; i ++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  double x = vec.at(0);
  
  for (int i = 0; i < N-1; i++){
    x = (x+vec.at(i+1))/2;
  }
  cout << x << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<typename T, typename U>
inline auto cmn (T& a, U b) {if (a > b) {a = b; return true;} return false;}
template<typename T, typename U>
inline auto cmx (T& a, U b) {if (a < b) {a = b; return true;} return false;}
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<long long>a(n);
  std::for_each(a.begin(), a.end(), [](auto& x){std::cin >> x;});
  using value_t = std::pair<long long, long long>;
  using vec1    = std::vector<value_t>;
  using vec2    = std::vector<vec1>;
  using vec3    = std::vector<vec2>;
  auto dp = vec3(n, vec2(n));
  auto insert = [&] (vec1& v, long long x, long long y) {
    auto lb = std::lower_bound(v.begin(), v.end(), value_t{x, 0LL});
    if (lb != v.begin()) {
      auto it = std::prev(lb);
      if (it->second <= y) return;
    }
    auto it = lb;
    while (it != v.end() && y <= it->second) it = v.erase(it);
    v.insert(it, {x, y});
  };
  auto renew = [&] (int l, int r) {
    for (int c = l + 1; c < r; c++) {
      for (auto p : dp.at(l).at(c)) {
        for (auto q : dp.at(c).at(r)) {
          insert(dp.at(l).at(r),
            p.first + p.second + a.at(c) + q.first,
            p.second + a.at(c) + q.first + q.second
          );
        }
      }
    }
  };
  for (int i = 0; i < n - 1; i++) {
    dp.at(i).at(i + 1).emplace_back(0, 0);
  }
  for (int d = 2; d < n; d++) {
    for (int l = 0, r = d; r < n; l++, r++) {
      renew(l, r);
    }
  }
  constexpr long long inf = 1LL << 60;
  long long ret = inf;
  for (auto p : dp.at(0).at(n - 1)) {
    cmn(ret,
      a.at(0) + p.first + p.second + a.at(n - 1)
    );
  }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  string s;
  cin>>s;
  int n=s.size();

  int ans=(n+1)/2;
  char m=s[n/2];

  if(n%2==0){
    rep(i,n/2){
      if(s[n/2-1-i]==m && s[n/2+i]==m) ans++;
      else break;
    }
  }

  if(n%2==1){
    rep(i,n/2){
      if(s[n/2-1-i]==m && s[n/2+1+i]==m) ans++;
      else break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3784
// フェルマーの小定理
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	p = 1000000007
)

var (
	fac []int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func mpow(x int, n int) int {
	result := 1
	for n != 0 {
		if n&1 == 1 {
			result = result * x % p
		}
		x = x * x % p
		n >>= 1
	}
	return result
}

func mcomb(n int, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	result := fac[n]
	result *= mpow(fac[n-k], p-2)
	result %= p
	result *= mpow(fac[k], p-2)
	result %= p
	return result
}

func main() {
	X := readInt()
	Y := readInt()

	if (X+Y)%3 != 0 {
		fmt.Println(0)
		return
	}

	a := (2*Y - X) / 3
	b := (2*X - Y) / 3

	if a < 0 || b < 0 {
		fmt.Println(0)
		return
	}

	n := a + b
	k := min(a, b)

	fac = make([]int, n+1)
	fac[0] = 1
	for i := 0; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % p
	}

	fmt.Println(mcomb(n, k))
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 6016
<?php
class ExceptionHandling {
    var $N, $A, $answer;
    
    function __construct() {
        $this->N = trim(fgets(STDIN));
        while($line = trim(fgets(STDIN))) {
            $this->A[] = $line;
        }
    }

    function __invoke() {
        $tmp = $this->A;
        rsort($tmp);
        foreach ($this->A as $v) {
            $this->answer[] = $v === $tmp[0] ? $tmp[1] : $tmp[0];
        }
        return $this->answer;
    }
}

$ExceptionHandling = new ExceptionHandling;
echo implode("\n", $ExceptionHandling());


Measured memory_bytes: 37356
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  vector<int> a(10, 0);
  vector<int> b(100, 0);
  vector<int> c(1000, 0);
  for(int i = 0; i < n - 2; ++i){
    int x = s[i] - '0';
    if(!a[x]){
      a[x] = 1;
      for(int j = i + 1; j < n - 1; ++j){
	int y = x * 10 + (int)(s[j] - '0');
	if(!b[y]){
	  b[y] = 1;
	  for(int k = j + 1; k < n; ++k){
	    int z = y * 10 + (int)(s[k] - '0');
	    c[z] = 1;
	  }
	}
      }
    }
  }
  int res = 0;
  for(int i =0; i < 1000; ++i)if(c[i])res++;
  cout<<res<<endl;  
  return 0;
}


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

vector<int> seq;
int N,K;
int val(int i){
    int ans=0;
    if(i==0){
        for(int j=0;j<2*K;j++) ans+=seq[j];
    }else if(i==seq.size()-(K-1)*2-1){
        for(int j=i-1;j<i+2*K-1;j++) ans+=seq[j];
    }else{
        for(int j=i-1;j<i+2*K;j++) ans+=seq[j];
    }
    return ans;
}

int main(){
    
    string S;
    cin>>N>>K>>S;

    
    int firstbit=((S[0]=='0')?0:1);
    int renzoku=1;
    for(int i=1;i<N;i++){
        if(S[i]==S[i-1]) renzoku++;
        else{
            seq.push_back(renzoku);
            
            renzoku=1;
        }
    }
    seq.push_back(renzoku);
    
    if(seq.size()/2<K){
        cout<<N<<endl; return 0;
    }
    int saidai=0;
    for(int i=firstbit;i<=seq.size()-(K-1)*2-1;i+=2){
        saidai=max(saidai,val(i));
    }

    cout<<saidai<<endl;
    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;
ll ans = 0;

void go(vector<ll> visited,map<ll,set<ll>> &branch,ll N,ll &ans){
    /* for(auto x:visited){
        cout << x << " ";
    }
    cout << endl;*/
    if (visited.size() == N)
    {
        ans++;
        return;
    }
    for (auto x:branch[visited[visited.size()-1]]){
        bool flag = true;
        for (auto bef:visited){
            if (bef==x){
                flag = false;
            }
        }
        if(flag){
            vector<ll> visitedd = visited;
            visitedd.push_back(x);
            go(visitedd, branch, N,ans);
        }
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    map<ll, set<ll>> branch;
    ll a, b;
    rep(i,M){
        cin >> a >> b;
        a--;
        b--;
        branch[a].insert(b);
        branch[b].insert(a);
    }
    ll ans = 0;
    vector<ll> visited = {0};
    go(visited, branch, N, ans);
    cout << ans << endl;
}

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

for n in range(N+1):
  i = 0
  while n >= 6**i:
    if n == 6**i:
      dp[n] = 1
    else:
      dp[n] = min(dp[n], dp[n-6**i]+1)
    i += 1
                
  i = 1
  while n >= 9**i:
    if n == 9**i:
      dp[n] = 1
    else:
      dp[n] = min(dp[n], dp[n-9**i]+1)
    i += 1

print(dp[N])

Measured memory_bytes: 3828
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>

int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	int N, *A, *B, *C, i, j, max_i = 0, T, F, flag = 0, Q, kind=0;
	long long int count=0, ans;
	//	int A[200000];




	scanf("%d", &N);

	A = (int *)malloc(sizeof(int)*N);
	B = (int *)malloc(sizeof(int)*N);
	C = (int *)malloc(sizeof(int)*N);

	for (i = 0; i < N; i++){
		scanf("%d", &A[i]);
		B[i] = A[i];
		C[i] = 0;
	}
qsort(B, N, sizeof(int), compare_int);

C[B[0]]++;

	for (i = 1; i < N; i++){
		C[B[i]]++;
		if (B[i] == B[i - 1]){
			flag++;
			count += flag;

		}
		else{
			flag = 0;

		}
	}

	for (i = 0; i < N; i++){
		ans = count - (C[A[i]] - 1);
		printf("%lld\n", ans);
	}
	return 0;

}

Measured memory_bytes: 4972
//Name: Anipero 2012
//Level: 2
//Category: 動的計画法,DP
//Note:

/*
 * [i曲目][残り本数][レベル2を振る本数] = 累計満足度でDP。
 * 更新は、レベル1をl本振るとして、dp[i][j][k] = max(∀l,k'. dp[i-1][j+max(l-k',0)+k][k'] + f(i,l,k))
 * （レベル1を増やしたいとき、過去に遡って折っていたことにする；初日はレベル1を振れないことに注意）。
 * サイリウムを折っても、必ずしも振る必要はないことに注意。
 *
 * オーダーは O(NML^3)。
 * ただし、Lは同時に使えるサイリウムの最大本数で、L=8。
 */
#include <iostream>
#include <array>

using namespace std;

template <typename T>
struct Maybe {
    T val;
    bool valid;

    Maybe() : valid(false) {}
    Maybe(T &t) : val(t), valid(true) {}

    T& operator =(const T &rv) {
        val = rv;
        valid = true;
        return val;
    }
};

bool solve() {
    int N, M;
    if(!(cin >> N >> M)) return false;

    array<array<array<Maybe<int>,9>,51>,51> dp;
    dp[0][M][0] = 0;
    for(int i = 1; i <= N; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        for(int j = 0; j <= M; ++j) {
            for(int k = 0; k <= 8; ++k) {
                for(int l = 0; l <= 8-k; ++l) {
                    if(i == 1 && l > 0) break;
                    const int add = (k+l == 0) ? c : l*b + k*a;
                    for(int pk = 0; pk <= 8; ++pk) {
                        const int pj = j + max(0, l-pk) + k;
                        if(pj < 0 || pj > M) continue;
                        if(!dp[i-1][pj][pk].valid) continue;
                        const int ns = dp[i-1][pj][pk].val + add;
                        if(!dp[i][j][k].valid || dp[i][j][k].val < ns) dp[i][j][k] = ns;
                    }
                }
            }
        }
    }
    Maybe<int> ans;
    for(int j = 0; j <= M; ++j) {
        for(int k = 0; k <= 8; ++k) {
            if(dp[N][j][k].valid) {
                const int v = dp[N][j][k].val;
                if(!ans.valid || ans.val < v) ans = v;
            }
        }
    }
    cout << ans.val << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1376
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int dp[5050][5050],n;
string s;

int Rec(int i , int j , int k){

    if(i == s.size() || j == s.size())  return 0;

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

    int Res = 0;

    return dp[i][j] = (k > 0 && s[i] == s[j] ? 1 + Rec(i + 1 , j + 1 , k - 1) : Res);
}

int main()
{
    memset(dp , -1 , sizeof(dp));
    int Ans = 0;  cin >> n >> s;
    for(int i = 0;i<n;i++){
        for(int j = i;j<n;j++){
            Ans = max(Ans , Rec(i , j , j - i));
        }
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 99968
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int  INF=10e7;

typedef  pair<int,int> P;


int main(){
     int n,m;
     cin>>n>>m;
     if(m==1)cout<<"0"<<endl;
     else{
     vector<long> x(m);
     for(int i=0;i<m;++i){
          cin>>x[i];
     }
     sort(x.begin(),x.end());
 
     array<long,100100>dis={0};
  
     
     for(int i=0;i<m-1;++i){
          dis[i]=abs(x[i+1]-x[i]);
     }
     sort(dis.begin(),dis.begin()+m-1);
     long ans=0;
     for(int i=0;i<m-n;++i){
          ans+=dis[i];
     }
 
     cout<<ans<<endl;
     }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N,M;
  cin>>N>>M;
  vector<pair<ll,ll>>C(N);
  
  rep(i,N){
    cin>>C[i].first>>C[i].second;
  }
  
  sort(all(C));
  
  priority_queue<ll>que;
  
  ll x=0;
  ll ans=0;
  
  
  for(ll i=M-1;i>=0;i--){
    while(x<N){
      if(i+C[x].first<=M){
        que.push(C[x].second);//push_backではないことに注意
        x++;
      }
      else{
break;
      }
    }

    if(!que.empty()){
      ans+=que.top();//一番上を表示
      que.pop();//一番上だけを消す
    }
  }
cout<<ans<<endl;
  
}


Measured memory_bytes: 2936
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long calc(long long a){
	if(a<=0)return 0;
	long long ret=0;
	for(int i=1;i<40;i++){
		long long tmp=0;
		long long at=a%(1LL<<(i+1));
		tmp=max(0LL,at-(1LL<<i)+1);
		if(tmp%2)ret+=(1LL<<i);
	}
	if(a%4==1||a%4==2)ret++;
	return ret;
}
int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	long long ret=calc(a-1)^calc(b);
	printf("%lld\n",ret);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	static Scanner sc = new Scanner(System.in);
	static int n = sc.nextInt();
	
	public static void main(String[] args){
		int[] A = new int[n+1];
		for(int i=1; i<n+1; i++){
			A[i] = sc.nextInt();
		}
		
		buildMaxHeap(A);
		
		for(int i=1; i<n+1; i++){
			System.out.print(" " + A[i]);
		}
		System.out.println();
	}
	
	static void maxHeapify(int[] A, int i){
		int l = 2*i;
		int r = 2*i+1;
		int lar=0;
		int tmp=0;
		if (l <= n && A[l] > A[i]){
			lar = l;
		} else {
			lar = i;
		}
		if (r <= n && A[r] > A[lar]){
			lar = r;
		}
		
		if (lar != i){
			tmp = A[lar];
			A[lar] = A[i];
			A[i] = tmp;
			maxHeapify(A, lar);
		}
	}
	
	static void buildMaxHeap(int[] A){
		for (int i=n/2; i>0; i--){
			maxHeapify(A, i);
		}
	}
}



Measured memory_bytes: 167624
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int N;cin >> N;
    vector<int> a(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum+=a[i];
    }
    int ans=0,t=INF;
    for(int i=0;i<N;i++){
        if(t>abs(sum-a[i]*N)){
            ans=i;
            t=abs(sum-a[i]*N);
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

using ll = long long;

const int kMod = 1000 * 1000 * 1000 + 7;

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

  int N;
  cin >> N;

  ll total = 1;
  ll a = 1;
  ll b = 1;
  rep(i, N) {
    total = (10 * total) % kMod;
    a = (9 * a) % kMod;
    b = (8 * b) % kMod;
  }

  ll result = ((total - a - a + b) % kMod + kMod) % kMod;
  cout << result << '\n';

  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define N 100000
#define M 50000
#define NOT_FOUND -1

int BinarySearch( int, int [], int );

int main(){
    int n, q;
    int S[N], T[M];
    int i, cnt = 0;

    //input 
    scanf("%d", &n);
    for (i = 0; i<n; i++)
	scanf("%d", &S[i]);
    scanf("%d", &q);
    for (i = 0; i<q; i++)
	scanf("%d", &T[i]);

    //sort
    for (i = 0; i<q; i++)
	if (BinarySearch(n, S, T[i]) != NOT_FOUND)
	    cnt++;

    //dispaly 
    printf("%d\n", cnt);

    return 0;
}

int BinarySearch( int n, int S[], int key){
    int i, right = 0, left = 0, mid;

    right = n;
    while (left < right){
	mid = (right + left)/2;
	if (key == S[mid])
	    return mid;
	else if (key < S[mid])
	    right = mid;
	else if (key > S[mid])
	    left = mid + 1;
    }
    return NOT_FOUND;
}



Measured memory_bytes: 2280
#include<stdio.h>

int main()
{
	while (1)
	{
		int n, x;
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0){ 
			break;
		}
		int i, j, k, total, sum=0;
		for (i = 1; i <= n - 2; i++)
		{
			for (j = i + 1; j <= n - 1; j++)
			{
				for (k = j + 1; k <= n; k++)
				{
					total = i + j + k;
					if (total == x){
						sum += 1;
					}
				}
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    deque<char> deq;
    rep(i, s.size()) deq.push_back(s[i]);
    int q;
    cin >> q;
    int flag = 0;
    rep(i, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            flag++;
            flag %= 2;
        }
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1)
            {
                if (flag == 0)
                    deq.push_front(c);
                else
                    deq.push_back(c);
            }
            else
            {
                if (flag == 0)
                    deq.push_back(c);
                else
                    deq.push_front(c);
            }
        }
    }
    if (flag == 0)
        rep(i, deq.size()) cout << deq[i];
    else
        repr(i, deq.size() - 1) cout << deq[i];

    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main() {
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    
    if (a > b && a > c)
    {
        if (b > c)
        {
            cout << c << " " << b << " " << a << endl;
        }
        else
        {
            cout << b << " " << c << " " << a << endl;
        };
    }
    else if (b > a && b > c)
    {
        if (a > c)
        {
            cout << c << " " << a << " " << b << endl;
        }
        else
        {
            cout << a << " " << c << " " << b << endl;
        };
    }
    else if (c > a && c > b)
    {
        if (a > b)
        {
            cout << b << " " << a << " " << c << endl;
        }
        else
        {
            cout << a << " " << b << " " << c << endl;
        };
    }
    else
    {
        cout << " " << endl;
    };
}


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


int N, M, Q;
vector<int> a, b, c, d, A;

int score(){
    int ans = 0;
    for(int i=0;i<Q;i++){
        if(A[b[i]]-A[a[i]] == c[i]) ans += d[i];
    }
    return ans;
}

int dfs(int i, int v){
    if(i == N){
        return score();
    }

    int ans = 0;
    for(int x=v;x<=M;x++){
        A[i] = x;
        ans = max(ans, dfs(i+1, x));
    }
    return ans;
}

int main(void){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    A.resize(N);
    for(int i=0;i<Q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;b[i]--;
    }
    cout << dfs(0, 1) << endl;
    return 0;
}

Measured memory_bytes: 3600
N=int(input())
B=list(map(int,input().split()))
A=[]
A.append(B[0])
for i in range(0,N-2):
  A.append(min(B[i],B[i+1]))
A.append(B[N-2])
sum=0
for i in range(N):
  sum+=A[i]
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;

//n番目のリュカ数を返す
ll luca(ll n) {
    ll L0 = 2, L1 = 1;

    if (n == 0) return 2;
    if (n == 1) return 1;

    ll Ln = 0;
    ll pp = 2, p = 1;

    for (int i = 2; i <= n; i++) {
        Ln = pp + p;
        pp = p;
        p = Ln;
    }

    return Ln;
}

int main() {
    ll N;
    cin >> N;

    cout << luca(N) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num[5000];
int  serch(int line,int now,int maxe)
{
    if(maxe==now)return line;
    line=max(line,serch(line+num[now],now+1,maxe));
    return line;
}
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>num[i];
        int ans=num[0];
        for(int i=0;i<n;i++)ans=max(serch(num[i],i+1,n),ans);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
//import java.util.ArrayDeque;                                                      

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        boolean[] dict = new boolean[(int) Math.pow(5, 12)];
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            String[] in = br.readLine().split(" ");
            if(in[0].equals("insert")){
                //dict.add(in[1]);                                                  
                dict[hash(in[1].toCharArray())] = true;
            }else{
                if(dict[hash(in[1].toCharArray())] == true) sb.append("yes\n");
                else sb.append("no\n");
            }
        }
        System.out.print(sb);
    }

    public static int hash(char[] c){
        int a;
        int hash = 0;
        for(int i = 0; i < c.length; i++){
            switch(c[i]){
            case 'A':
                a = 1;
                break;
            case 'C':
                a = 2;
                break;
            case 'G':
                a = 3;
                break;
            default:
                a = 4;
                break;
            }
            hash = hash * 5 + a;
        }
        return hash;
    }

}

Measured memory_bytes: 391648
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
  ll dp[100000]={0};
ll vis[100000]={0};
vector<vector<ll>>v(100000);
  void dfs(ll x)
{
  vis[x]=1;
  for(ll j=0;j<v[x].size();j++)
  {
    int nei=v[x][j];
    if(!vis[nei])
    {
      dfs(v[x][j]);
    }
     dp[x]=max(dp[x],dp[nei]+1);
  }
 
}
  int main()
{
  ll n,m,i,maxi=-1,x,y;
  cin>>n>>m;
  for(i=0;i<m;i++)
  {
    cin>>x>>y;
    v[x].push_back(y);
    //v[y].push_back(x);
    
  }
  for(i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      dfs(i);
    }
  }
    for(i=1;i<=n;i++)
    {
      if(dp[i]>maxi)
        maxi=dp[i];
    }
    cout<<maxi;
    
  
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(0);

	int n;
	cin>>n;

	int ans =1;
	unordered_map<int,int> m;
	for(int i=0;i<n;i++)
	{
		int val;
		cin>>val;
		if(m.count(val) == 0) m[val] = 1;
		else ans =0;
	}

	if(ans) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	
	
	
	



}

Measured memory_bytes: 8520
(function main() {
  const n = Number(require('fs').readFileSync('/dev/stdin', 'utf8')) + 1;
  root5 = Math.sqrt(5);
  console.log(Math.round(1/root5 * (Math.pow((1 + root5) / 2, n) - Math.pow((1 - root5) / 2, n))));
})();



Measured memory_bytes: 15124
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    int N,n,k,D;
    vector<bool> d(10,true);
    cin >> N >> k;
    rep0(i, k){
        cin >> D;
        d[D] = false;
    }
    while (1) {
        n = N;
        while (n) {
            if (!d[n % 10]) {
                ++N;
                break;
            }
            n = n / 10;
        }
        if (n == 0) {
            break;
        }
    }
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(int a,int b)
        {
            return a>b;
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int X,A;
            cin>>X>>A;
            if(X<A)
            cout<<0;
            else
            cout<<10;
            return 0;
        }


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

int main(void)
{
  int n, p[102], m[101][101], i, j, k, l, tmp;

  scanf("%d", &n);
  scanf("%d", &p[0]);

  for (i = 1; i < n; i++)  {
    scanf("%d", &p[i]);
    scanf("%d", &p[i]);
  }
  scanf("%d", &p[n]);

  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }

  for (l = 2; l <= n; l++) {
    for (i = 1; i <= n - l + 1; i++) {
      j = i + l - 1;
      m[i][j] = 1000000000;
      for (k = i; k < j; k++) {
        tmp = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        if (m[i][j] > tmp)
        m[i][j] = tmp;
      }
    }
  }
  printf("%d\n", m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
H = array[1].split(" ").map(&:to_i)
Item = Struct.new(:a, :b, :c)

items = [Item.new(0,0,0)]
array[1..N].each do |s|
  item = Item.new
  item.a, item.b, item.c = s.split(" ").map(&:to_i)
  items << item
end

dp = Array.new(N+1).map{Array.new(3, 0)}

for i in 1...N+1
  for j in 0...3
    dp[i][j] = [
      dp[i-1][1] + items[i].a, dp[i-1][2] + items[i].a
    ].max if j==0
    dp[i][j] = [
      dp[i-1][0] + items[i].b, dp[i-1][2] + items[i].b
    ].max if j==1
    dp[i][j] = [
      dp[i-1][0] + items[i].c, dp[i-1][1] + items[i].c
    ].max if j==2
  end
end

#dp.each{|l| p l}
puts dp.max.max

Measured memory_bytes: 30844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    ll H,W,k;
    cin>>H>>W>>k;
    ll ans=0;
    char c[10][10];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>c[i][j];
        }
    }
    for(int Hbit=0;Hbit<(1<<H);Hbit++){
        for(int Wbit=0;Wbit<(1<<W);Wbit++){
            char z[10][10];
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    z[i][j]=c[i][j];
                }
            }
            for(int i=0;i<H;i++){
                if(Hbit&(1<<i)){
                    for(int j=0;j<W;j++){
                        z[i][j]='A';
                    }
                }
            }
            for(int j=0;j<W;j++){
                if(Wbit&(1<<j)){
                    for(int i=0;i<H;i++){
                        z[i][j]='A';
                    }
                }
            }
            ll kosuu=0;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(z[i][j]=='#') kosuu++;
                }
            }
            if(kosuu==k) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int w,a,b;
    cin>>w>>a>>b;
    int ans;
    if(a<=b){
        ans=(b-(a+w));
        if(ans<0){
            ans=0;
        }
    }else{
        ans=(a-(b+w));
        if(ans<0){
            ans=0;
        }
    }
    cout<<ans<<endl;
            
    return 0;
}

Measured memory_bytes: 256