akhauriyash/Code-Regression huggingface dataset:
Scanf.scanf "%d %d" (fun n m ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let b = Array.init m (fun _ -> Scanf.scanf " %d" (fun b -> b)) in
    Array.sort compare a;
    Array.sort compare b;

    let ( *@) a b = (a * b) mod 1_000_000_007 in

    let dup x =
        let n = Array.length x in
        let rec loop i =
            if i = n then false else
                if x.(i) = x.(i - 1) then true else loop (i + 1)
        in
        loop 1
    in

    let upper_bound arr v =
        let n = Array.length arr in
        let rec loop l r =
            if l = r then l else
                let m = (l + r) / 2 in
                if arr.(m) < v then loop (m + 1) r else loop l m
        in
        loop 0 n
    in

    let rec loop i acc =
        if i = 0 then acc else
            let r = upper_bound a i in
            let c = upper_bound b i in
            let mr = r < n && a.(r) = i in
            let mc = c < m && b.(c) = i in
            match mr, mc with
            | true,  true  -> loop (i - 1) acc
            | true,  false -> loop (i - 1) (acc *@ (m - c))
            | false, true  -> loop (i - 1) (acc *@ (n - r))
            | false, false -> loop (i - 1) (acc *@ ((m - c) * (n - r) - (n * m - i)))
    in
    Printf.printf "%d\n" @@ if dup a || dup b then 0 else loop (n * m) 1
)

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
int n,val[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

lint solve(const bool f){
	lint ans=0,s=0;
	for(int i=1; i<=n; ++i){
		s+=val[i];
		if((i&1)==f&&s<=0) ans+=-s+1,s=1;
		if((i&1)!=f&&s>=0) ans+=s+1,s=-1;
	}
	return ans;
}

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
	}
	printf("%lld\n",std::min(solve(0),solve(1)));
	return 0;
}


Measured memory_bytes: 640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 2e5 + 10;
int cnt[maxN];
int cnt2[maxN];
vector<int> ps[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    vector < int > a(n), b(n);
    for (int& v : a) {
        cin >> v;
        cnt[v]++;
    }
    for (int& v : b) {
        cin >> v;
        cnt2[v]++;
    }
    for (int i = 0; i < n; i++) {
        ps[a[i]].emplace_back(i);
    }
    for (int i = 1; i <= n; i++) {
        if (cnt[i] + cnt2[i] > n) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes\n";
    priority_queue < pair < int, int > > pq;
    priority_queue < pair < int, int > > aq;
    vector<int > ans(n);
    for (int i = 1; i <= n; i++) {
        if (cnt2[i]) pq.push(make_pair(cnt2[i] + cnt[i], i));
        if (cnt[i]) aq.push(make_pair(cnt[i] + cnt2[i], i));
    }
    while (!pq.empty()) {
        auto it = pq.top();
        pq.pop();
        auto pit = aq.top();
        aq.pop();
        if (pit.second == it.second) {
            auto tit = aq.top();
            aq.pop();
            aq.push(pit);
            pit = tit;
        }
        assert(pit.second != it.second);
        ans[ps[pit.second].back()] = it.second;
        ps[pit.second].pop_back();
        cnt2[it.second]--;
        if (cnt2[it.second]) pq.push(make_pair(cnt2[it.second] + cnt[it.second], it.second));
        cnt[pit.second]--;
        if (cnt[pit.second]) aq.push(make_pair(cnt[pit.second] + cnt2[it.second], pit.second));
    }
    for (int& v : ans) cout << v << " ";
    return 0;
}

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

using namespace std;

int main(){
	int N,W;
	cin >> N >> W;
	vector<long long> w(N),v(N);
	vector<vector<long long> > dp(N,vector<long long>(W+1));
	for(int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}
	
	if(w[0]<=W) dp[0][w[0]] = v[0];
	
	for(int i = 1; i < N; i++){
		
		for(int j = 1; j <= W; j++){
			if(j>=w[i])dp[i][j] = max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);		
			else 	   dp[i][j] = dp[i-1][j];		
		}
	}
	long long  ans = *max_element(dp[N-1].begin(),dp[N-1].end());
	cout << ans << "\n";
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, x, cnt = 0; cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        if((i & 1) && (x & 1)) cnt++;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3612
<?php
// 入力
fscanf(STDIN,"%d",$param_n);
$param_a = fgets(STDIN);
$arr_param_a = explode(' ',$param_a);

$ans = 1;
$max = 10**18;
$over_flow_flg = false;
foreach($arr_param_a as $val){
    $ans = $ans * $val;
    if($ans > $max){
        $over_flow_flg = true;
        $ans = 1;
    }else
    if($over_flow_flg && $val == 0){
        $ans = 0;
        $over_flow_flg = false;
    }

}

if($over_flow_flg){
    echo -1;
    exit();
}

echo $ans;


Measured memory_bytes: 25532
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();

        int cnt = 0;
        long sum1 = 0;
        for (int i = 0; i < S.length; i++) {
            char ch = S[i];
            if (ch == 'B') {
                cnt++;
                sum1+=i; // summation of initial position
            }
        }

        int i = S.length - 1;
        long sum2 = 0;
        while (cnt > 0) {
            sum2 += i;
            cnt--;
            i--;
        }

        System.out.println(sum2 - sum1);

        return;
    }

}

Measured memory_bytes: 27916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

// (sum, {x,y,z})
using Data = pair<ll, vi>;

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

vl N(3);
rep(i,3) cin >> N[i];
int K;
cin >> K;

vvl v(3);
rep(i,3) {
    v[i].resize(N[i]);
    rep(j,N[i]) cin >> v[i][j];
    sort(v[i].begin(), v[i].end(), greater<ll>());
}

priority_queue<Data> que;
set<Data> st;
que.push(Data(v[0][0] + v[1][0] + v[2][0], vi({0, 0, 0})));
rep(k,K) {
    auto d = que.top(); que.pop();
    cout << d.first << endl;

    // (A[x],B[y],C[z])をみたときに
    // (A[x+1],B[y],C[z]), (A[x],B[y+1],C[z]),(A[x],B[y],C[z+1])を追加する
    rep(i,3) {
        // d.second[i] := i種類目(A,B,C)のケーキの現在のindex
        // N[i]より小さければインクリメントしたものを追加できる
        if(d.second[i] + 1 < N[i]) {
            ll sum = d.first - v[i][d.second[i]] + v[i][d.second[i] + 1];
            auto num = d.second;
            num[i]++;
            auto nd = Data(sum, num);
            //過去に追加したことあるものは除く
             if (!st.count(nd)) st.insert(nd), que.push(nd);
        }
    }
}

return 0;
}


Measured memory_bytes: 1536
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=3005;
ll ksm(ll a,ll b,ll mod)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	}
	return res;
}
ll S[N][N],C[N][N];
int main()
{
	int n,mod;
	read(n,mod);
	S[0][0]=C[0][0]=1;
	for(int i=1;i<=n+1;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j) S[i][j]=(S[i-1][j-1]+S[i-1][j]*j)%mod,C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	ll ans=0;
	for(int i=0;i<=n;++i)
	{
		ll res=0;
		for(int k=0;k<=i;++k) res+=ksm(ksm(2,n-i,mod),k,mod)*S[i+1][k+1]%mod;
		res%=mod;
		ans+=((i&1)?-res:res)*C[n][i]%mod*ksm(2,ksm(2,n-i,mod-1),mod)%mod;
	}
	((ans%=mod)+=mod)%=mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 95952
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

bool cmp(pint a, pint b) { return a.second > b.second; }
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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  vector<pint> p(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>p[i].first>>p[i].second;
  ll sum=0;
  rep(i,m) sum+=p[i].first;
  ll tmp=0;
  sort(ALL(p),cmp);
  ll i=0;
  while(tmp<=min(sum,n)){
    if(m<=i) break;
    rep(j,p[i].first){
      a.push_back(p[i].second);
      tmp++;
      if(tmp>min(sum,n)) break;
    }
    i++;
  }
  sort(ALL(a),greater<ll>());
  ll ans=0;
  rep(i,n){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6512
from typing import List
from collections import defaultdict

def management(N: int, A_i: List[int]):
    sub_dict = defaultdict(set)

    for i in range(2, N+1):
        sub_dict[A_i[i]].add(i)

    def get_sub_num(i):
        # if len(sub_dict[i]):
        #     return len(sub_dict[i]) + sum([get_sub_num(j) for j in sub_dict[i]])
        return len(sub_dict[i])

    for i in range(1, N+1):
        print(get_sub_num(i))

if __name__ == '__main__':
    N = int(input())
    A_i = [0, 0] + list(map(int, input().split()))
    management(N, A_i)


Measured memory_bytes: 92232
# abc131_b.py
N, L = map(int,input().split())
apple = []
for i in range(N):
    apple.append(L+i)
taste = sum(apple)
diff = 10**9
ans = 0
for i,v in enumerate(apple):
    if diff > abs(taste-(taste-v)):
        diff = abs(taste-(taste-v))
        ans = taste-v
print(ans)


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

int main() {
	int n, a, b, max, min;
	cin >> n >> a >> b;
	max = b - a;
	min = a;
	if (a > b)min = b;
	for (int i = 1; i < n - 1; i++) {
		cin >> a;
		if (max < a - min)max = a - min;
		if (min > a)min = a;
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 3096
/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

/*
 N 500
 */
int main(){
  
  // read problem
  long long int N, K, tmp, sum;
  std::vector<long long int> A;

  scanf("%lld%lld", &N, &K);
  
  sum = 0;
  for(int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp);
    sum += tmp;
  }
  
  std::cerr << "reading problem ended" << std::endl;
  std::cerr << "N: "  << N << " K: " << K << std::endl << "A: ";
  for(int i = 0; i < N; i++){
    std::cerr << A[i] << " ";
  }std::cerr << std::endl << "sum: " << sum << std::endl;
 
  long long int n_divisers;
  std::vector<long long int> divisers;
  
  n_divisers = 0;
  for(long long int i = 1; i*i <= sum; i++){
    if(sum%i == 0){
      divisers.push_back(i);
      divisers.push_back(sum/i);
      if(i*i < sum){
        n_divisers += 2;
      }
      else{
        n_divisers++;
      }
    }
  }
  
  std::sort(divisers.begin(), divisers.end(), std::greater<long long int> ());
  
  std::cerr << "divisers: ";
  for(int i = 0; i < n_divisers; i++){
    std::cerr << divisers[i] << " ";
  }std::cerr << std::endl << std::endl;
  
  // solve problem
  std::vector<long long int> residues;
  for(int i = 0; i < N; i++)residues.push_back(0);
  long long int sum_residues, check;
  
  long long int d;
  
  // solve loop
  for(long long int i = 0; i < n_divisers; i++){
    d = divisers[i];
    std::cerr << "d: " << d << std::endl;
    // calculate residues
    sum_residues = 0;
    std::cerr << "residues: ";
    for(long long int j = 0; j < N; j++){
      residues[j] = A[j]%d;
      sum_residues += A[j]%d;
      std::cerr << A[j]%d << " ";
    }std::cerr << std::endl << "sum of residues" << sum_residues << std::endl;
    
    std::sort(residues.begin(), residues.end(), std::less<long long int>());
    // check problem
    check = 0;
    for(int j = 0; j < N; j++){
      check += residues[j];

      if(check >= d*(N-j-1) - (sum_residues-check)){
        std::cerr << "check: " << check << std::endl;
        if(check <= K || d == 1){
          i = n_divisers;
        }
      }
    }
  }
  
  std::cerr << std::endl << "Answer: ";
  std::cout << d << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;



	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		int SIZE = 55;

		Set<String> SET = new HashSet<String>();
		StringBuilder ans = new StringBuilder();

		int LENGTH[] = new int[SIZE];
		char words[][] = new char[SIZE][SIZE];
		char array[] = {'a','i','u','e','o'};

		while(true){

			int N = scanner.nextInt();
			if(N == 0)break;

			int maximum = 0;

			int ans_K = BIG_NUM;

			//文字列の入力
			for(int i = 0; i < N; i++){

				String input_str = scanner.next();
				LENGTH[i] = input_str.length();
				maximum = Math.max(maximum, LENGTH[i]);

				char work[] = input_str.toCharArray();
				for(int k = 0; k < LENGTH[i]; k++){

					words[i][k] = work[k];
				}
			}

			for(int k = 1; k <= maximum; k++){

				SET.clear();
				boolean FLG = true;

				for(int i = 0; i < N; i++){

					//文字列iのコードを作る
					StringBuilder sb = new StringBuilder();
					sb.append(words[i][0]); //先頭の1文字

					int tmp_len = 1;

					//母音に続く文字
					for(int a = 1; a < LENGTH[i] && tmp_len < k; a++){

						boolean tmp_FLG = false;
						for(int b = 0; b < array.length; b++){

							if(words[i][a-1] == array[b]){

								tmp_FLG = true;
								break;
							}
						}

						if(tmp_FLG){
							sb.append(words[i][a]);
							tmp_len += 1;
						}
					}

					String add_str = sb.toString();
					if(SET.contains(add_str)){

						FLG = false;
						break;

					}else{

						SET.add(add_str);
					}
				}

				if(FLG){

					ans_K = k;
					break;
				}
			}
			if(ans_K == BIG_NUM){

				ans.append("-1\n");

			}else{

				ans.append(Integer.toString(ans_K)).append("\n");
			}
		}
		System.out.print(ans.toString());
	}
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 39388
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int X;
  cin >> X;

  int ans = 1;
  int mi = INT_MAX;

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

  for (int i = 2; i <= X; i++) {
    int p = 2;
    while ((int)pow(i, p) <= X) p++;
    p--;
    if (p < 2) continue;

    int a = (int)pow(i, p);
    if (X - a < mi) {
      ans = a, mi = X - a;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,w,h,i,j,k,l,m,n,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> s;
	j = 0;
	for(i=0;i<3;i++) {
		if (s[i]=='R') {
			ans = max(ans , ++j);
		} else {
			j = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    rep1(i, 50001){
        // cout << i*1.08 << endl;
        if(floor(i*1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int n;
    cin >> n;
    string s;
    cin >> s;

    long long int ans = 0;
    long long int cnt[3] = {};
    for ( long long int i = 0; i < s.size(); i++ ) {
        if ( s[i] == 'R' ) {
            cnt[0]++;
        } else if ( s[i] == 'G' ) {
            cnt[1]++;
        } else {
            cnt[2]++;
        }
    }
    ans = cnt[0] * cnt[1] * cnt[2];

    for ( long long int i = 1; i < s.size() / 2 + 2; i++ ) {
        for ( long long int x = 0;; x++ ) {
            long long int y = x + i;
            long long int z = y + i;
            if ( z >= s.size() ) break;
            if ( s[x] != s[y] && s[x] != s[z] && s[y] != s[z] ) ans--;
        }
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3636
n, cost = map(int, input().split())

judge = False
result = []
for i in range(n+1):
  if judge:
    break
  for j in range(n+1-i):
    if 10000*i + 5000*j + 1000*(n-i-j) == cost:
      judge = True
      result = [i, j, n-i-j]
      break

if not judge:
  result = [-1, -1, -1]
  

print(result[0], result[1], result[2])

      

      
    

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#define MAXN 35
#define NN 15
using namespace std;
char in[MAXN][MAXN];
int malt[MAXN][MAXN], tmp[MAXN][MAXN];
int tt[MAXN][MAXN], vis[15];
int n, m, key;
void work()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            tt[i][j] = tmp[i][j];
            tmp[i][j] = 0;
        }
    }
    for(int j = 1; j <= m; j++)
    {
        int now = n;
        for(int i = n; i >= 1; i--)
        {
            if(!tt[i][j]) continue;
            tmp[now--][j] = tt[i][j];
        }
    }
}
void cop(int x, int y)
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            tmp[i][j] = malt[i][j];
        }
    }
    tmp[x][y] = 0;
    work();
}
void print()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            printf("%d ", tmp[i][j]);
        }
        puts("");
    }
}
int solve()
{
    int mul = 1, res = 0, sum;
    while(true)
    {
        sum = 0;
        for(int i = 1; i <= 9; i++) vis[i] = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int k, j = 1; j <= m; j = k)
            {
                k = j;
                while(k <= m && tmp[i][j] == tmp[i][k]) k++;
                if(k - j >= key)
                {
                    sum += tmp[i][j] * (k - j);
                    for(int h = j; h < k; h++) tmp[i][h] = 0;
                }
            }
        }
        if(!sum) break;
        work();
        res += (mul * sum);
        mul *= 2;
        //print();
        //printf("----------------%d %d\n", mul, sum);
    }
    return res;
}
int main()
{
    scanf("%d%d%d", &n, &m, &key);
    for(int i = 0; i < n; i++) scanf("%s", in[i]);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            malt[i + 1][j + 1] = in[i][j] - '0';
        }
    }
    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cop(i, j);
            res = max(res, solve());
        }
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int n, m;

bool ok(int t) {
	int k = m / t;
	
	return k >= n;
}

int main(){
	cin >> n >> m; i64 ma = 0;
	for(i64 i = 1; i * i <= m; i++) {
		if(m % i) continue;
		if(ok(i)) ma = std::max(ma, i);
		if(ok(m / i)) ma = std::max(ma, m / i);
	}
	
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();

        if (A >= K) {
            A = A - K;
        } else {
            if (B >= (K - A)) {
                B = B - (K - A);
            } else {
                B = 0;
            }
            A = 0;
        }
        System.out.println(A + " " + B);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001
int dp[40][401][401];

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    int a[40], b[40], c[40];
    for(int i=0; i<N; ++i) cin >> a[i] >> b[i] >> c[i];

    for(int i=0; i<40; ++i) {
        for(int j=0; j<=400; ++j) {
            for(int k=0; k<=400; ++k) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    dp[0][a[0]][b[0]] = c[0];
    for(int i=1; i<N; ++i) {
        for(int j=0; j<=400; ++j) {
            for(int k=0; k<=400; ++k) {
                if(j-a[i] >= 0 && k-b[i] >= 0) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a[i]][k-b[i]] + c[i]);
                dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
            }
        }
    }
    int ans = INF;
    for(int k=1; Ma*k <=400 && Mb*k <= 400; ++k) {
        ans = min(ans, dp[N-1][Ma*k][Mb*k]);
    }
    if(ans != INF) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 25344
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> v;
	rep(i,n) {
		int a;
		cin >> a;
		a--;
		if (i == a) v.push_back(a);
	}
	ll ans = 0;
	rep(i,v.size()) {
		ans++;
		if (i < v.size() - 1 && v[i] + 1 == v[i+1]) {
			i++;
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3908
let line = readLine()!.split(separator: " ").map({Int($0)!})
let (N, K) = (line[0], line[1])
let A = readLine()!.split(separator: " ").map({Int($0)! - 1})

var visit = Array(repeating: -1, count: N)

var cities: [Int] = []
var city = 0
while visit[city] < 0 {
    visit[city] = cities.count
    cities.append(city)
    city = A[city]
}

if K < cities.count {
    print(cities[K] + 1)
} else {
    let start = visit[city]
    print(cities[start + (K - start) % (cities.count - start)] + 1)
}


Measured memory_bytes: 19308
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;

void solve(){
    int n;
    cin >> n;
    string x;
    set <string> s;
    for(int i = 1; i <= n; ++i) {
        cin >> x;
        s.ins(x);
    }
    cout << s.size();
}

 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 19244
from collections import Counter
 
mod = 998244353
 
def solve():
    N = int(input())
    Ds = list(map(int, input().split()))
    # 頂点1から頂点1は必ず深さ0
    if Ds[0] != 0:
        print(0)
        return
    
    counter = Counter(Ds)
    ret = 1
 
    if counter[0] > 1:
        print(0)
        return
    max_key = max(counter.keys())
    for i in range(1, max_key+1):
        if i not in counter:
            print(0)
            return
        
        ret = (ret*(counter[i-1]**counter[i]))%mod
        
    print(ret)
    
solve()


Measured memory_bytes: 24304
#include<stdio.h>
#include<math.h>
 
int main(void)
{
    int n;
    int i;
    int x[100];
    int y[100];
    int z[100];
    double L_1 = 0, L_2 = 0, L_3 = 0, L_inf;
     
    scanf("%d\n", &n);
    for(i = 0; i<n; i++)
        scanf("%d", &x[i]);
    for(i = 0; i<n; i++)
        scanf("%d", &y[i]);
    for(i = 0; i<n; i++) {
        z[i] = (x[i] - y[i]>0)? x[i] - y[i]: y[i] - x[i];
        if(i == 0) L_inf = z[0];
        else {
            if(z[i] > L_inf) L_inf = z[i];
        }
    }
     
    for(i=0; i<n; i++) {
        L_1 += z[i];
        L_2 += z[i] * z[i];
        L_3 += z[i] * z[i] * z[i];
    }
     
    L_2=pow(L_2, 1.0/2);
    L_3=pow(L_3, 1.0/3);
     
    printf("%f\n%f\n%f\n%f\n", L_1, L_2, L_3, L_inf);
     
    return 0;
}


Measured memory_bytes: 2144
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut ratios = vec![];
    for i in 0..n {
        let v = read_vec::<i128>();
        let (t, a) = (v[0], v[1]);
        ratios.push((t, a));
    }
    let mut cur_t = ratios[0].0;
    let mut cur_a = ratios[0].1;

    for (t, a) in ratios.into_iter().skip(1) {
        debug!(cur_t, cur_a);
        let criterion = |mid| cur_t > t * mid || cur_a > a * mid;
        let (ok, ng) = binary_search(0, 200000_00000_00000_000 / max(t, a), criterion);
        cur_t = ng * t;
        cur_a = ng * a;
        debug!(ng);
    }
    println!("{}", cur_a + cur_t);
}

fn binary_search<F>(lb: i128, ub: i128, criterion: F) -> (i128, i128)
where
    F: Fn(i128) -> bool,
{
    assert_eq!(criterion(lb), true);
    assert_eq!(criterion(ub), false);
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    vector a(n, 0L);
    for (auto&& aa : a) {
        cin >> aa;
    }

    int64_t mx = 0;
    int64_t ans = 0;
    for (auto aa : a) {
        ans += max(mx - aa, 0L);
        mx = max(mx, aa);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4836
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int[] T = new int[N];
        int[] count = new int[100001];
        st = new StringTokenizer(br.readLine());
        for(int i=0; i<N; i++){
            T[i]=Integer.parseInt(st.nextToken());
            count[T[i]]++;
        }

        System.out.println(solve(T, count, N));
    }
    public static int solve(int[] T, int[] count, int N){
        if(N%2!=0 && count[0]!=1)
            return 0;
        if(N%2==0){
            for(int i=1 ; i<N; i+=2){
                if(count[i]!=2)
                    return 0;
            }
        }
        else{
            for(int i=2 ; i<N; i+=2){
                if(count[i]!=2)
                    return 0;
            }
        }
        int ans=1;
        int i=0;
        while(i<N/2){
            ans*=2;
            ans=ans%1000000007;
            i++;
        }
        return ans;
    }
}


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

int main(){
	ll n;cin>>n;
	priority_queue<ll> a;

	ll MIN=INF;
	for(ll i=0;i<n;i++){
		ll num;
		cin>>num;
		a.push(num);
		MIN=min(MIN,num);
	}

	while(a.size()!=1){
		ll now=a.top();
		a.pop();
		if(now%MIN!=0){
			a.push(now%MIN);
			MIN=min(MIN,now%MIN);
		}
	}

	ll ans;
	ans=a.top();

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

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,nc,sum=0;cin>>n;
    nc=n;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    if(nc%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
int main(void){
 
    int H, W, i, j;
 
    while(1){
      
    scanf("%d %d",&H ,&W);
  
    if(H == 0 && W == 0)break;
 
    for(i = 0; i < H; i++){

    for(j = 0; j < W; j++){
        
    if(i == 0 || j == 0 || j == (W - 1) || i == (H - 1) ){
            printf("#");
        
    }else{
            printf(".");
    }
  
    }
    
    printf("\n");
  
    }
    
    printf("\n");
    
    }
    
  
 
    return 0;
      
    }



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[1010][1010],com[4333][4333];
long long l[4011],re[4010];
long long j[4111][4111];

long long x,y,z,mod=1000000007;
//string r;
char r[3];

P u[1];
queue<P> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v[3];


bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y>b.y;
  
}

long long rr(long long x,long long y)
{
  long long p=1;
  for(;y;y/=2,x*=x,x%=mod)
  if(y%2) p*=x,p%=mod;
  return p;
}

long long g(int n,int m)
{
  if(n==m||n==0) return 1;
  if(com[n][m]>=0) return com[n][m];
  return com[n][m]=(g(n-1,m-1)+g(n,m-1))%mod;
}

long long f1(int n,int m)
{
  if(m==0) return 1;
  if(j[n][m]>0) return j[n][m];
  return j[n][m]=re[n]*f1(n,m-1)%mod;
}

long long f(int n,int m,int c)
{
  return g(n*m,c)*re[m]%mod*l[n*m]%mod*f1(n,m)%mod;
}

int main()
{
  memset(com,-1,sizeof(com));
  l[0]=re[0]=1;
  for(int t=1;t<=4000;t++)
   l[t]=l[t-1]*t%mod,re[t]=rr(l[t],mod-2);
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  o[b-1][a]=1;
  for(int t=b;t<=c;t++)
  for(int w=0;w<=a;w++)
  {
    o[t][w]+=o[t-1][w];
    for(int i=d;w+i*t<=a&&i<=e;i++)
    {
      o[t][w]+=o[t-1][w+i*t]*f(t,i,w+i*t)%mod,o[t][w]%=mod;
      //printf("%d %d %d %lld\n",t,i,w+i*t,f(t,i,w+i*t));
    }
    //printf("%lld ",o[t][w]);
  }
  printf("%lld",o[c][0]);
}
//0
//15




Measured memory_bytes: 186880
while True:
    a, b = map(int, input().split())
    if a == b and a == 0:
        break

    for i in range(a):
        for j in range(b):
            if i == 0 or i == a - 1 or j == 0 or j == b - 1:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

signed main()
{
   int N, C; cin >> N >> C;
   V<int> x(N+1), v(N+1);
   FORE(i, 1, N) {
      cin >> x[i] >> v[i];
   }

   V<int> rightS(N+1), leftS(N+1);
   FORE(i, 1, N) {
      rightS[i] = rightS[i-1] + v[i];
      leftS[i] = leftS[i-1] + v[N+1-i];
   }

   V<V<int>> MAX_R(N+1, V<int>(2, 0)), MAX_L(N+1, V<int>(2, 0));
   FORE(i, 1, N) {
      MAX_R[i][0] = max(MAX_R[i-1][0], rightS[i] - x[i]);
      MAX_R[i][1] = max(MAX_R[i-1][1], rightS[i] - 2*x[i]);
      MAX_L[i][0] = max(MAX_L[i-1][0], leftS[i] - (C-x[N+1-i]));
      MAX_L[i][1] = max(MAX_L[i-1][1], leftS[i] - 2*(C-x[N+1-i]));
   }

   int ans = 0;
   FORE(i, 0, N) {
      ans = max(ans, MAX_R[i][0] + MAX_L[N-i][1]);
      ans = max(ans, MAX_R[i][1] + MAX_L[N-i][0]);
   }
   cout << ans << endl;

   return 0;
}


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

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N;
  cin >> N;
  string ans = N ? "" : "0";
  while (N) {
    if (N % 2) {
      N--;
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }
    N /= -2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define M 1000000007

int main() {
    long long int n;
    cin >> n;
    vector<long long int> k(n+1, 0);

    long long int m;
    cin >> m;

    for (long long int i = 0; i < m; i++) {
        long long int a;
        cin >> a;
        k[a] = -1;
    }

    k[0] = 1;

    if (k[1] != -1) {
        k[1] += k[0];
    }
    for (long long int i = 2; i <= n; i++) {
        if (k[i] != -1) {
            if (k[i-1] != -1) {
                k[i] += k[i-1];
                k[i] %= M;
            }
            if (k[i-2] != -1) {
                k[i] += k[i-2];
                k[i] %= M;
            }
        }
    }

    cout << k[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int Arr[100005];
void seive(){
		Arr[0]=Arr[1]=1;
		for(int i=2;i<100005;++i){
			if(Arr[i]==0)
			for(int j=2*i;j<100005;j+=i)
			Arr[j]=1;
		}
}


bool isprime(int a){
	if(a<2)
	return false;
	if(a==2)
	return true;
	if(a%2==0)
	return false;
	for(int i=3;i*i<=a;i+=2)
	if(a%i==0)
	return false;
	return true;
}




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


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



void q1(){
	int k,x;
	cin>>k>>x;
	int pp=500*k;
	if(pp>=x)
	cout<<"Yes";
	else
	cout<<"No";	
}
// -----------------------------------------------------------------------


void q2(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<=n-3;++i){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
		ans++;
	}
	cout<<ans;
}

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

void q3(){
	int n;
	cin>>n;
	vector<int> v,v1,v2;
	for(int i=1;i<=n;++i)
	v.push_back(i);
	int a,b;
	for(int i=0;i<n;++i){
		int t;
		cin>>t;
		v1.push_back(t);
	}
	for(int i=0;i<n;++i){
		int t;
		cin>>t;
		v2.push_back(t);
	}
	int cp=0;
	do { 
        bool ft=true;
        for(int i=0;i<n;++i)
        if(v1[i]!=v[i])
        ft=false;
        if(ft)
        a=cp;
        ft=true;
        for(int i=0;i<n;++i)
        if(v2[i]!=v[i])
        ft=false;
        if(ft)
        b=cp;
        cp++;
    } while (next_permutation(v.begin(), v.end())); 
    cout<<abs(a-b);
}


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

void q4(){
	seive();
	//cout<<Arr[23]<<endl;
	int ans[100005];
	ans[0]=0;ans[1]=0;ans[2]=0;
	for(int i=3;i<=100005;i+=2)
	{
		int num=i+1;
		num/=2;
		if(Arr[i]==0 && Arr[num]==0)
		ans[i]=1;
		else
		ans[i]=0;
	}
	//cout<<ans[3]<<endl;
	
	for(int i=1;i<100005;++i)
	ans[i]+=ans[i-1];
	//cout<<ans[7]<<endl;

	int q;cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<ans[r+1]-ans[l]<<endl;
		/*int cp=0;
		for(int i=l;i<=r;++i){
			int num=i+1;
			num/=2;
			if(i%2==1)
			if(isprime(i) && isprime(num))
			cp++;
		}
		cout<<cp<<endl;*/
	}
}

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


int32_t main()
{
	mod=1e+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	q3();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
typedef long long llong;
using namespace std;

int gcd(int x,int y){
	if(x>y) std::swap(x,y);
	return y%x==0?x:gcd(y%x,x);
}

llong lcm(int x,int y){
	llong n=(llong)gcd(x,y);
	return ((llong)x*y)/n;
}

int main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	
	llong l=lcm(n,m);
	vector<pair<llong,char> > ss,tt;
	for(int i=1;i<=n;++i){
		pair<llong,char> tmp=make_pair((i-1)*(l/n)+1,s[i-1]);
		ss.push_back(tmp);
	}
	for(int i=1;i<=m;++i){
		pair<llong,char> tmp=make_pair((i-1)*(l/m)+1,t[i-1]);
		tt.push_back(tmp);
	}

	ss.insert(ss.end(),ALL(tt));//Point.
	sort(ALL(ss));
	bool jud=true;
	REP(i,ss.size()-1){
		if(ss[i].first==ss[i+1].first){
			if(ss[i].second!=ss[i+1].second){
				jud=false;
				break;
			}
		}
	}
	
	if(jud) cout<<l<<endl;
	else cout<<-1<<endl;
	return 0;
}//解説参考.

Measured memory_bytes: 5876
#include <bits/stdc++.h>
typedef long long ll;

int main(int argc, char const *argv[]) {
    ll H, W;
    std::cin >> H >> W;
    std::string S;
    for (size_t i = 0; i < H; i++) {
        std::cin >> S;
        std::cout << S << '\n' << S << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	ll ans1 = 0LL;
	ll ans2 = 0LL;
	cin >> n;
	V a(n);
	cin >> a;
	rep(i, n) {
		if (ans1 < a[i]) {
			ans2 = ans1;
			ans1 = a[i];
		}else{
			chmax(ans2, a[i]);
		}
	
	}
	rep(i, n) { 
		if(a[i]==ans1){
			cout << ans2 << endl;
		}else{
			cout << ans1 << endl;
		}
		
	
		 }
}

Measured memory_bytes: 4844
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
float f = 0;
float s=0;
Float a[]=new Float[N];
for(int i=0;i<N;i++){
f=sc.nextInt();
a[i]=1/f;
}
for(int i=0;i<N;i++){
s=s+a[i];
}
float T = 1/s;
System.out.println(T);
}
}

Measured memory_bytes: 22740
import Data.List
import Control.Monad

getList :: IO [Int]
getList = do
    _ <- readLn :: IO Int
    ak <- map read <$> (words <$> getLine) :: IO [Int]
    return ak


main = do
    [n,k] <- map read <$> (words <$> getLine) :: IO [Int]
    giveList <- replicateM k getList
    let ls = nub $ concat $ giveList
    print $ length $ filter (not . flip elem ls) [1..n] 


Measured memory_bytes: 5956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  int M1, M2, D1, D2;

  cin >> M1;
  cin >> D1;
  cin >> M2;
  cin >> D2;

  int ans;
  if ( M1 == M2 )
    ans = 0;
  else
    ans = 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256