akhauriyash/Code-Regression huggingface dataset:
n = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a = prime_factorize(n)
from collections import Counter
c = Counter(a)
x = set()
ans = 0
import itertools
r = list(itertools.accumulate(list(range(1,10**5))))
from bisect import bisect
for i in c:
    if c[i]==1:
        ans += 1
    else:
        ind = bisect(r,c[i])
        ans += ind


print(ans)

Measured memory_bytes: 18132
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,k,a[100],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=n-1,j=0;j<k;i--,j++){
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

int func(int x){
  if(x<10){
    return x;
  }else{
    return x%10+func(x/10);
  }
}

int main () {
  int n;
  cin >> n;
  int s=func(n);
  
  if(n%s==0){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>
using namespace std;

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

#define F first
#define S second

const int MAX = 1e5+9;
const ll MOD = 1e9+7;

map<int,int> mp;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i=0; i < n; i++) {
		int x;
		cin >> x;
		mp[-x]++;
	}
	ll mx = -1;
	for (auto x : mp) {
		ll s = -x.F;
		int t = x.S;
		if (t == 1) continue;
		if (t >= 4 && mx == -1)
			return cout << s * s << "\n",0;
		if (mx == -1)
			mx = s;
		else
			return cout << mx * s << "\n",0;
	}
	cout << 0 << "\n";

}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Y;
  cin >> N >> Y;
  int y = Y/1000;
  int a=-1, b=-1, c=-1;
  for (int i=0; i<=N; i++){
    for (int j=0; j<=N-i; j++){
      int k = N - i - j;
      int l = 10*i+5*j+k;
      if(l==y){
        a=i, b=j, c=k;
      }
    }
  }
  printf("%d %d %d\n", a, b, c);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	fmt.Println(favSound(a, b, c))
}

func favSound(a, b, c int) int {
	if b/a > c {
		return c
	}
	return b / a
}


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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int x;
	
	cin >> x;
	
	if(x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var i=cin();
			print("ABC"+i.ToString());
			read();
		}
	}
}

Measured memory_bytes: 13268
import java.util.Scanner;
 
 
public class Main {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a + b == 15){
			System.out.println("+");
		}
		else if(a * b == 15){
			System.out.println("*");
		}
		else {
			System.out.println("x");
		}
	}
 
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const ll INF = (ll)1 << 60;

int main() {
    int a,b;
    cin >> a >> b;
    if (a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    tmp = input.split(" ");
    var a = parseInt(tmp[0], 10);
    var b = parseInt(tmp[1], 10);
    //計算
    c = a+b;
    d = a-b;
    e = a*b;
    f = Math.max(c,d,e);
    if (f === -0) {
        f = 0;
    }
    //結果
    console.log(f);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
# coding: utf-8
N = int(input())
li_T = list(map(int, input().split()))
M = int(input())

sum_T = sum(li_T)
for _ in range(M):
    p, x = map(int, input().split())
    i = p - 1
    print(sum_T - li_T[i] + x)


Measured memory_bytes: 2940
a = Array.new(4)
a.each_index do |i|
  a[i] = Array.new(51,0)
end
10.times do |i|
  a[0][i] = 1
end
3.times do |i|
  a[i+1][0] = 1
end

3.times do |i|
  50.times do |j|
    10.times do |k|
      if j+1-k >= 0
        a[i+1][j+1] = a[i+1][j+1] + a[i][j+1-k]
      end
    end
  end
end

while n = gets
  n = n.chomp.to_i
  print a[3][n], "\n"
end

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


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

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}


int solve(int N, vi& a) {
    set<int> p;
    rep(i,N) {
        int j = a[i]-1;
        if (a[j]-1 == i) p.insert(min(i,j));
    }
    return p.size();
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=1e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
char s[N]; 
int n,a[N],ans;
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	cin>>s+1;
	for(int i=1;i<=3;i++){
		if(s[i]=='R'){
			a[i]=1;
			a[i]+=a[i-1];
		}
		else a[i]=0;
		ans=max(ans,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll a,b;
  cin >> a >> b;
  if(a<10&&b<10){
    cout << a*b<<endl;
  }else{
    cout <<"-1\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007

using namespace std;
int a[200005];
int main()
{
    int n,T;
    cin >> n >> T;
    for(int i=0; i<n; i++)
        cin >> a[i];
    vector<ll> v;
    ll last = 0;
    ll res = 1LL * T*n;
    for(int i=0; i<n; i++)
    {
        v.push_back(a[i]);
    }
    int en = T;

    for(int i=1;i<v.size();i++)
    {
        if(v[i] <= en)
            res -= (en - v[i]);
        en = v[i]+T;
    }


    cout << res << endl;





    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N,T;
  cin>>N>>T; 
  vector<int>a(N);
  for(int i=0;i<N;++i){
    cin>>a.at(i);
  }
  long ans=0;

  for(int i=0;i<N-1;i++){
    if(a.at(i)+T<a.at(i+1)){
       ans+=T;
    }
    else{
      ans+=a.at(i+1)-a.at(i);
    }
  }
  
    cout<<ans+T<<endl; 
}



Measured memory_bytes: 1024
#include<bits/stdc++.h> 
#include <chrono> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono; 

template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less_equal<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
       'j','k','l','m','n','o','p','q','r','s','t','u','v',
       'w','x','y','z'};

// rectangle intersection
// x5 = max(x1, x3);
// y5 = max(y1, y3);
// x6 = min(x2, x4);
// y6 = min(y2, y4); 

const int mx = 200005;

// char get_next(char c) {
// 	for(int i=0; i<25; i++) if(c == alphabet[i]) return alphabet[i+1];
// 	return 'a';
// }


int32_t main() {
 	fastIO;
	int tc;
	// cin >> tc;
	tc = 1;
	while(tc--) {
		int n;
		cin >> n;
		int a[n];
		for(int i=0; i<n; i++) cin >> a[i];
		int cursum = 1000;
		for(int i=0; i<n-1; i++) {
			if(a[i] < a[i+1]) {
				int st = cursum / a[i];
				cursum += st * (a[i+1] - a[i]);
			}
		}
		cout << cursum << endl;
    }     
}


Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
int main(void) {
	int N;
	char s[100];

	int i;
	int a = 0;
	int b = 0;

	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i] == 'R')
			a++;
		else if (s[i] == 'B')
			b++;
	}
	if (a > b)
		cout << "Yes";
	else if (a <= b)
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
import sys
H,W=map(int,input().split())
m=[list(input()) for _ in range(H)]
off=[(-1,0),(0,-1),(1,0),(0,1)]
for y in range(H):
    for x in range(W):
        if m[y][x]=='.': continue
        f=False
        for dx,dy in off:
            x2=x+dx
            y2=y+dy
            if 0<=x2<W and 0<=y2<H:
                if m[y2][x2]=='#':
                    f=True
                    break
        if f==False:
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N=100010;

int n,k,cnt,ans,t,G[N];
struct edge{
  int t,nx;
}E[N<<1];

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

int dpt[N];

void dfs(int x,int f){
  for(int i=G[x];i;i=E[i].nx)
    if(E[i].t!=f){
      dfs(E[i].t,x);
      if(dpt[E[i].t]==k && x!=1) ans++;
      else dpt[x]=max(dpt[x],dpt[E[i].t]);
    }
  dpt[x]++;
}

int main(){
  scanf("%d%d",&n,&k); ans=0;
  int x; scanf("%d",&x);
  if(x!=1) ans++;
  for(int i=2;i<=n;i++)
    scanf("%d",&x),addedge(x,i);
  dfs(1,0);
  printf("%d\n",ans);
  return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


ll A,B,C,D;

void input() {
	cin>>A>>B>>C>>D;
}

void solve() {
	ll ans=-LLINF;
	chmax(ans,A*C);
	chmax(ans,A*D);
	chmax(ans,B*C);
	chmax(ans,B*D);
	cout<<ans<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main(){
	int out = 0;
	string s;
	cin>>s;
    for (int i = 0, size = s.size() ; i < size ; ++i ) {
        out *= 2;
        out += ((int)s[i] == 49) ? 1 : 0;
    }
    if(out ==0)
    	cout<<0<<endl;
    if(out == 1||out == 2||out== 4)
    	cout<<1<<endl;
    if(out == 3||out == 5||out ==6)
    	cout<<2<<endl;
    if(out == 7)
    	cout<<3<<endl;

    return 0;

}

Measured memory_bytes: 256
# ABC098_B
num = int(input())
str = input()
alphabets = [chr(ord('a') + i) for i in range(26)]

answer=0

for i in range(1, num):
    strLeft = str[0:i]
    strRight = str[i:num]
    common=0
    for j in alphabets:
        if ((j in strLeft) and (j in strRight)):
            common+=1
    if(answer < common):
        answer=common

print(answer)


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

s = set()
a = 1
while a <= 100000:
    s.add(a)
    a *= 6
a = 1
while a <= 100000:
    s.add(a)
    a *= 9
s = sorted(s)

INF = float('inf')
dp = [INF] * (N+1)
dp[0] = 0
for i in range(N):
    for a in s:
        if i+a > N: break
        dp[i+a] = min(dp[i+a], dp[i] + 1)
print(dp[N])

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll op[N] = {};
    ll ans = 0;
    while(true){
        bool ok = true;
        rep(i, N) if(A[i] >= N) ok = false;
        if(ok){
            cout << ans << endl;
            break;
        }

        rep(i, N) op[i] = 0;
        rep(i, N){
            if(A[i] >= N){
                //A[i]-kN <= N-1, kN >= A[i]-(N-1), k >= (A[i]-(N-1))/N
                op[i] = (A[i]-(N-1) + (N-1))/N;
            }
        }
        ll sum_op = 0; rep(i, N) sum_op += op[i];
        rep(i, N) A[i] += (sum_op - op[i]) - op[i]*N;
        ans += sum_op;
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func search(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] < x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	b := make([]int, 0)
	for i := 0; i < N; i++ {
		x := search(b, a[i])
		// out(x)
		if x == len(b) {
			b = append(b, a[i])
		} else {
			b[x] = a[i]
		}
		// out(b)
	}
	out(len(b))
}


Measured memory_bytes: 7120
#include<iostream>
#include<string.h>
using namespace std;
int main() 
{
   int i, j, flag=0;
  char str[150];
  cin >> str;
  for(i=0,j=(strlen(str)/2)-1;i<j;i++, j--)  
  if(str[i]!=str[j]) 
  {
  	flag=1;
  	break;
  } 
  if(flag==1)
  cout << "No" << endl;
  else
  {
  	flag=0;
  	for(i=0,j=strlen(str)-1;i<j;i++,j--) 
  	if(str[i]!=str[j]) 
  	{
  		flag=1;
  		break;
  	} 
  	
  	if(flag==1)
  	cout << "No" << endl;
  	else
  	cout << "Yes" << endl;
  } 
  return 0;
} 


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static boolean[] used;

	static class TaskX {
		@SuppressWarnings("unchecked")
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int V = in.nextInt(), E = in.nextInt();
			List<Edge>[] G = Stream.generate(ArrayList::new).limit(V).toArray(List[]::new);
			for (int i = 0; i < E; i++) {
				int u = in.nextInt();
				int v = in.nextInt();
				int c = in.nextInt();
				G[u].add(new Edge(v, c, G[v].size()));
				G[v].add(new Edge(u, 0, G[u].size() - 1));
			}

			int flow = 0;
			while (true) {
				used = new boolean[V];
				int f = dfs(0, V - 1, INF, G);
				if (f == 0) break;
				flow += f;
			}
			out.println(flow);

		}

		static int dfs(int u, int v, int f, List<Edge>[] G) {
			if (u == v) return f;
			used[u] = true;
			for (Edge e : G[u]) {
				if (!used[e.to] && e.cap > 0) {
					int d = dfs(e.to, v, Math.min(f, e.cap), G);
					if (d > 0) {
						e.cap -= d;
						G[e.to].get(e.rev).cap += d;
						return d;
					}
				}
			}
			return 0;
		}

	}
	static class Edge {
		int to, cap, rev;
		public Edge(int to, int cap, int rev) {
			this.to = to;
			this.cap = cap;
			this.rev = rev;
		}
	}


	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 49772
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		String t;double v,u,y;
		while((t=bf.readLine())!=null){
			v=Double.parseDouble(t);
			y=v*v/19.6;
			System.out.println((int)Math.ceil((y+5)/5));
		}
	}
}

Measured memory_bytes: 9164
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           double                      long double
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const double inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

double dp[608];
int n,m;
vector<int>adj[608];
double ses;
double solve(int pos)
{
    dp[n]=0;
    rf(i,n-1,1)
    {
        double sum=0;
        double mx=0;
        int sz=adj[i].size();
        for(int j=0;j<sz;j++)
        {
            int v=adj[i][j];
            sum+=dp[v];
            mx=max(mx,dp[v]);
        }
        if(i==pos && sz>=2)
        {
            sz--;
            sum-=mx;
        }
        dp[i]=(sum/(double)sz)+1;
    }
    ses=min(ses,dp[1]);
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
    }
    ses=inf;
    f(i,0,n-1)
    {
        solve(i);
    }
   cout<<fixed<<setprecision(10)<<ses<<endl;
    return 0;

}













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



int main()
{    
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n;cin>>n;
    int a[n];
    long long ans=0;
    int neg=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<=0){
            neg++;
        }
        a[i]=abs(a[i]);
        ans+=a[i];

    }
    if(neg%2==0){
        cout<<ans;
        return 0;
    }
    sort(a,a+n);
    cout<<ans-2*a[0];

}

Measured memory_bytes: 640
package main

import "fmt"
import "math"

func main(){
	var D, N int
	var X[200][200] float64
	var tmp float64
	var sqrt float64
	var count int

	fmt.Scan(&N, &D)

	for i := 0 ; i < N ; i++ {
		for j := 0 ; j < D ; j++{
			fmt.Scan(&X[i][j])
		}
	}

	for i := 0 ; i < N ; i++ {
		for k := i+1 ; k < N ; k++{
			sqrt = 0
			for j := 0 ; j < D ; j++{
				sqrt += (X[i][j] - X[k][j])*(X[i][j] - X[k][j])
		//		fmt.Printf("(%f %f)", X[i][j], X[i+k][j])
			}
			sqrt = math.Sqrt(sqrt)
			tmp = math.Ceil(sqrt)
			if tmp == sqrt {
				count++
			}
		//	fmt.Println(sqrt)
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
n = gets.to_i

clue = []
n.times do
  clue << gets.split.map(&:to_i)
end

ans = nil
clue.sort_by!{|pt| pt[2]}
clue.reverse!

101.times do |i|
  101.times do |j|
    flag = true
    h = nil
    clue.each do |pt|
      if !h
        h = (i-pt[0]).abs + (j-pt[1]).abs + pt[2]
      else
        flag = false if pt[2] != [0, h - (i-pt[0]).abs - (j-pt[1]).abs].max
      end
    end
    ans = "#{i} #{j} #{h}" if flag
  end
end
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll A,B;
ll h[100000];

ll check(ll x){
  ll M=0;
  for(int i=0;i<N;i++){
    if(h[i]>x*B){
      ll hp=h[i]-x*B;
      ll C=A-B;
      M+= (hp+C-1)/C;
    }
  }
  return (M<=x);
}

int main(){
  cin>>N>>A>>B;
  for(int i=0;i<N;i++)cin>>h[i];

  ll left=1,right=1e9,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(mid))right=mid;
    else left=mid+1;
  }
  cout<<left<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		char[] s_chars = s.toCharArray();
        Arrays.sort(s_chars);

      if(s_chars[0]==s_chars[1]&&s_chars[2]==s_chars[3]&&s_chars[0]!=s_chars[2]){
        System.out.print("Yes");
      }else{System.out.print("No");}
      
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

double dp[310][310][310];

int n;
int a, b, c;

double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];

    if (i == 0 && j == 0 && k == 0) return 0.0;

    double ret = 0;

    if (i > 0) ret += rec(i - 1, j, k) * i;
    if (j > 0) ret += rec(i + 1, j - 1, k) * j;
    if (k > 0) ret += rec(i, j + 1, k - 1) * k;

    ret += n;

    ret /= i + j + k;

    return dp[i][j][k] = ret;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x == 1) a++;
        if(x == 2) b++;
        if(x == 3) c++;
    }
    memset(dp, -1, sizeof dp);
    cout << fixed << setprecision(10) << rec(a, b, c) << endl;
    return 0;
}


Measured memory_bytes: 232960
N,K = list(map(int,input().split()))
line = list(map(int,input().split()))

temp_num = sum(line[0:K])
temp_max = temp_num

for i in range(N - K):
    temp_num = temp_num - line[i] + line[i + K]
    if temp_num > temp_max:
        temp_max = temp_num


print((temp_max + K) / 2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

struct Node {
    int key;
    Node *parent;
    Node *left;
    Node *right;
};

Node* newNode(int key) {
    Node *tmp = new Node;
    tmp->key = key;
    tmp->parent = NULL;
    tmp->left = NULL;
    tmp->right = NULL;
    return tmp;
}

Node* root(Node *node) {
    if (!node->parent) return node;
    else return root(node->parent);
}

void insert(Node *node, int key) {
    Node* now = root(node);
    Node* par = NULL;
    Node* z = newNode(key);

    // nodeの根から順に辿る
    while (now) {
        par = now;
        if (z->key < now->key) {
            now = now->left;  // 左の子へ移動
        } else {
            now = now->right; // 右の子へ移動
        }
    }
    z->parent = par;

    if (!par) {
        node = z;
    } else if (z->key < par->key) {
        par->left = z;
    } else {
        par->right = z;
    }
}

void preorder(Node* node) {
    if (!node) return;
    cout << ' ' << node->key;
    preorder(node->left);
    preorder(node->right);
}

void inorder(Node* node) {
    if (!node) return;
    inorder(node->left);
    cout << ' ' << node->key;
    inorder(node->right);
}


int main() {
    int n; cin >> n;
    Node* tree;
    rep(i, n) {
        string query;
        cin >> query;
        if (query == "insert") {
            int key; cin >> key;
            if (i == 0) tree = newNode(key);
            else {
                insert(tree, key);
            }
        }
        if (query == "print") {
            inorder(tree);
            cout << endl;
            preorder(tree);
            cout << endl;
        }
    }
}



Measured memory_bytes: 26536
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   char[] c = sc.next().toCharArray();
 
   char[] each1 = new char[c.length];
   char[] each2 = new char[c.length];
   for(int i = 0; i<c.length;i+=2)
   {
	 each1[i] = '0';
     each2[i] = '1';  
   }
   for(int i = 1; i<c.length;i+=2)
   {
	 each1[i] = '1';
     each2[i] = '0';  
   }
   
   int ans1 =0;
   int ans2 =0;
   for(int i=0;i<c.length;i++)
   {
     if(each1[i]!=c[i]) ans1++;
     if(each2[i]!=c[i]) ans2++;
   }
 
   if(ans1>ans2) System.out.println(ans2);
   else System.out.println(ans1);
 }
}

Measured memory_bytes: 25812
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
        double x1,y1,x2,y2,xq,yq;
        while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)){
            double p_a = (y2-y1) / (x2-x1);
            double q_a = -1 / p_a;
            double p_b = y1 - x1*p_a;
            double q_b = yq - xq*q_a;

            double xm = (q_b - p_b) / (p_a - q_a);
            double ym = (p_a*xm)+ p_b;

            double rx = xm-(xq-xm);
            double ry = ym-(yq-ym);
            if(x1 == x2){
                printf("%lf %lf\n",x1-(xq-x1),yq);
            }
            else if(y1 ==y2){
                printf("%lf %lf\n",xq,y1-(yq-y1));
            }
            else{
                printf("%lf %lf\n",rx,ry);
            }
        }
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d",&n);
  if (n % 4 == 0 || (n >= 7 && (n - 7) % 4 == 0) || (n >= 14 && (n - 14) % 4 == 0) || (n >= 21 && (n - 21) % 4 == 0)) {
      printf("Yes\n");
  } else {
      printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// #include <bits/stdtr1c++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
 
 
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
 
/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;
 
#define mt                  make_tuple
#define fbo                 find_by_order
#define ook                 order_of_key
#define UB                  upper_bound
#define LB                  lower_bound
#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define SQR(x)              ((x)*(x))
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)

/// Constants
#define MAX                 200005 
#define MOD                 1000000007
#define base                1000000007
#define eps                 1e-9
#define INF                 1<<20    // 2,305,843,009,213,693,952
#define inf                 2000000000       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f
///string reverse example

    map<string,int> use;
int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\input.txt", "r", stdin);
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\output.txt", "w", stdout);
    #endif
    int n,mx=0;
    si(n);
    string str;
    FOR(i,0,n){
        cin>>str;
        use[str]++;
    }
    for(auto x:use){
        // cout<<x.ff<<" "<<x.ss<<endl;
        mx = max(mx,x.ss);
    }
    for(auto x:use){
        if(x.ss==mx)cout<<x.ff<<endl;
    }
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 25216
a = gets.split.map(&:to_i)
if a[0] % 2 == 1 || a[1] % 2 == 1 || a[2] % 2 == 1
    p 0
    exit
end
if a.uniq.size == 1
    p -1
    exit
end
ans = 0
loop {
    if a[0] % 2 == 1 || a[1] % 2 == 1 || a[2] % 2 == 1
        break
    end
    tmp = Array.new(a)
    a[0] = (tmp[1] + tmp[2]) / 2
    a[1] = (tmp[2] + tmp[0]) / 2
    a[2] = (tmp[0] + tmp[1]) / 2
    ans += 1
    }
p ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

void solve() {
  ll d,s,t;
  cin >> d >> s >> t;
  // d/s <= t
  if (d <= s*t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


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

int xy[4][2]={{0,1},{-1,0},{1,0},{0,-1}},sum,h,w,gi,gj,map[20][20];

void move(int hh,int ww,int k,int num)
{
  int a,b;
  if(num==10)return;
  if(map[hh+xy[k][0]][ww+xy[k][1]]==1)return;
  num++;
  while(1){
    a=hh+xy[k][0],b=ww+xy[k][1];
    if(hh==gi && ww==gj){
      sum=min(sum,num);
      return;
    }
    if(a==-1 || a==h || b==-1 || b==w)return;
    if(map[a][b]==1){
      map[a][b]=0;
      break;
    }
    hh+=xy[k][0];ww+=xy[k][1];
  }
  for(int i=0;i<4;i++){
    move(hh,ww,i,num);
  }
  map[a][b]=1;
}

int main()
{
  int si,sj;
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>map[i][j];
	if(map[i][j]==2){
	  si=i;sj=j;
	  map[i][j]=0;
	}
	if(map[i][j]==3){
	  gi=i;gj=j;
	  map[i][j]=0;
	}
      }
    }
    sum=100;
    for(int i=0;i<4;i++){
      move(si,sj,i,0);
    }
    if(sum>10)cout<<-1<<endl;
    else cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i, n) cin >> a[i];
    double ans = 0.0;
    rep(i, n){
        ans += 1.0 / a[i];
    }
    cout << fixed << setprecision(6) <<  1 / ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double
#define il inline

using namespace std;
const int N=3e5+10;
il LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
#define mid ((l+r)>>1)
struct sgmttr
{
	LL s[N<<2],tg[N<<2];
	void psup(int o){s[o]=min(s[o<<1],s[o<<1|1]);}
	void ad(int o,LL x){s[o]+=x,tg[o]+=x;}
	void psdn(int o){if(tg[o]) ad(o<<1,tg[o]),ad(o<<1|1,tg[o]),tg[o]=0;}
	void bui(int o,int l,int r)
	{
		s[o]=1ll<<50;
		if(l==r) return;
		bui(o<<1,l,mid),bui(o<<1|1,mid+1,r);
	}
	/*void modifa(int o,int l,int r,int ll,int rr,int x)
	{
		if(ll<=l&&r<=rr){ad(o,x);return;}
		psdn(o);
		if(ll<=mid) modifa(o<<1,l,mid,ll,rr,x);
		if(rr>mid) modifa(o<<1|1,mid+1,r,ll,rr,x);
		psup(o);
	}*/
	void modifc(int o,int l,int r,int lx,LL x)
	{
		if(l==r){s[o]=x;return;}
		psdn(o);
		if(lx<=mid) modifc(o<<1,l,mid,lx,x);
		else modifc(o<<1|1,mid+1,r,lx,x);
		psup(o);
	}
	LL quer(int o,int l,int r,int ll,int rr)
	{
		if(ll>rr) return 1ll<<50;
		if(ll<=l&&r<=rr) return s[o];
		psdn(o);
		LL an=1ll<<50;
		if(ll<=mid) an=min(an,quer(o<<1,l,mid,ll,rr));
		if(rr>mid) an=min(an,quer(o<<1|1,mid+1,r,ll,rr));
		psup(o);
		return an;
	}
}tr1,tr2;
int n,q,a[N];

int main()
{
    //asdfdsgds
	n=rd(),q=rd()+2,a[1]=rd(),a[2]=rd();
	for(int i=3;i<=q;++i) a[i]=rd();
	tr1.bui(1,1,n),tr2.bui(1,1,n);
	tr1.modifc(1,1,n,a[1],abs(a[3]-a[2])-a[1]),tr2.modifc(1,1,n,a[1],abs(a[3]-a[2])+a[1]);
	tr1.modifc(1,1,n,a[2],abs(a[3]-a[1])-a[2]),tr2.modifc(1,1,n,a[2],abs(a[3]-a[1])+a[2]);
	LL ans;
	for(int i=4;i<=q;++i)
	{
		ans=min(tr1.quer(1,1,n,1,a[i])+a[i],tr2.quer(1,1,n,a[i]+1,n)-a[i]);
		tr1.ad(1,abs(a[i]-a[i-1])),tr2.ad(1,abs(a[i]-a[i-1]));
		tr1.modifc(1,1,n,a[i-1],ans-a[i-1]),tr2.modifc(1,1,n,a[i-1],ans+a[i-1]);
	}
	ans=1ll<<50;
	for(int i=1;i<=n;++i) ans=min(ans,min(tr1.quer(1,1,n,i,i)+i,tr2.quer(1,1,n,i,i)-i));
	printf("%lld\n",ans);
    return 0; 
}


Measured memory_bytes: 24448
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	string s; cin >> s;
	int left = 0,right = s.size()-1;
	int ans = 0;
	while ((right-left)>0)
	{
		//cout<<s[right]<<':'<<s[left]<<endl;
		if(s[right]==s[left])
		{
			left++;
			right--;
		}
		else if(s[right]=='x')
		{
			right--;
			ans++;
		}
		else if(s[left]=='x')
		{
			left++;
			ans++;
		}
		else
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  pb push_back
#define mp make_pair
double dp[310][310][310];
int n;
double cal(int x,int y,int z){
   // cout<<x<<' '<<y<<' '<<z;
    if(dp[x][y][z]!=-1)return dp[x][y][z];
    if(x==0&&y==0&&z==0)
        return 0;
        double res=1;
    if(x)res+=cal(x-1,y,z)*((1.0*x)/n);
    if(y)res+=cal(x+1,y-1,z)*((1.0*y)/n);
    if(z)res+=cal(x,y+1,z-1)*((1.0*z)/n);
    res/=(1.0*(x+y+z))/n;
    return dp[x][y][z]=res;
}
int main(){
    cin>>n;
    int x=0,y=0,z=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a==1)x++;
        if(a==2)y++;
        if(a==3)z++;
    }
    for(int i=0;i<310;i++)for(int j=0;j<310;j++)for(int z=0;z<310;z++)dp[i][j][z]=-1;
    cout<<setprecision(10)<<fixed<<cal(x,y,z)<<'\n';
    return 0;
}


Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a,b);
    ll ab = (a*b);
    ll ans = ab / g;
    cout << ans << endl;   
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;


double n,k;

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

  double ans = 0;
  for(double i=1; i<n+1; i++){
    double tmp = 1.0/n;
    double count = i;
    while(count<k){
      tmp /= 2.0;
      count *= 2.0;
    }
    // cout << tmp << endl;
    ans += tmp;
  }
  cout.precision(12);
  cout << ans << endl;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

int main() {
	int n; cin >> n;
	int S = 0;
	int m = 0;
	for (int i = 1; i <= n; i ++) {
		S += i;
		if (S >= n) {
			m = i;
			break;
		}
	}
	for (int i = m; i >= 1; i--) {
		if (n >= i) {
			cout << i << endl;
			n -= i;
		}
	}
	return 0;
}

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

int N, Q;
string s;
vector<char> t, d;

bool vanish(int n, int m){
    // 初期位置 n のゴーレムが消えるか否かを判定。
    //  m=0：左で消えるとき true, それ以外のときfalse
    //  m=1：右で消えるとき true, それ以外のときfalse

    int x = n-1;  // 文字列 s は 0-indexed なので調整する
    int L = s.length();
    for(int i=0; i<Q; i++){
        if(t[i]==s[x]){
            x += (d[i]=='R' ? 1:-1);
            // ゴーレムが左か右にはみ出たらループを抜ける
            if(x==-1 || x==L) break;
        }
    }

    if(x==-1 && m==0){
        return true;
    }else if(x==L && m==1){
        return true;
    }else{
        return false;
    }
}

int main(){    
    cin >> N >> Q >> s;
    t = vector<char>(Q);
    d = vector<char>(Q);
    for(int i=0; i<Q; i++) cin >> t[i] >> d[i];

    // 左で消えるゴーレムの境界を求める
    int l1 = 0, r1 = N+1;    
    while(r1 - l1 > 1){
        int mid = l1 + (r1 - l1)/2;
        if(vanish(mid, 0)){
            l1 = mid;
        }else{
            r1 = mid;
        }
    }

    // 右で消えるゴーレムの境界を求める
    int l2 = 0, r2 = N+1;
    while(r2 - l2 > 1){
        int mid = l2 + (r2 - l2)/2;
        if(vanish(mid, 1)){
            r2 = mid;
        }else{
            l2 = mid;
        }
    }
    
    if(l2 >= r1){
        cout << l2 - r1 + 1 << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (ab);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
 
template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}
 
const long long INF = 1LL << 60;
 
 
int main(void){
	ll ab;cin >> ab;
	if(ab%2==1){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	while(ab>0){
		ans += ab/10;
		ab /= 5;
	}
	cout << ans << endl;
	return 0;
}
 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();

		String t = br.readLine();

		char[] sArray = s.toCharArray();
		char[] tArray = t.toCharArray();

		//1000個ごとに分割する感じ
		final int DIVID = 2000;
		boolean[][] charExists = new boolean[26][200000/DIVID];

		for(int i = 0; i < sArray.length; i++){
//			System.out.println(sArray[i]);
			charExists[sArray[i] - 'a'][i/DIVID] = true;
		}

		int i = 0;
		long result = 0;
		while(i < t.length()){
			boolean hit = false;

			for(int k = 0; k < charExists[0].length ; k++){
//				System.out.println("k = "+k);
//				System.out.println("t "+tArray[i]);
				if((k + 2)*DIVID < sArray.length &&  !charExists[tArray[i] - 'a'][k]){
//					result += Math.min(DIVID, Math.max(0, tArray.length - k*DIVID)) ;
//					System.out.println("result"+result);

					result += DIVID;
					continue;
				}
				for(int j = k * DIVID; j < s.length() && j < (k + 1) * DIVID ; j++){
//					System.out.println("j = "+j);
					result++;

					if(sArray[j] == tArray[i]){
						hit = true;
						i++;
						if(i == t.length()){
							break;
						}
					}
				}

				if(i == t.length()){
					break;
				}
			}
			if(!hit){
				System.out.println(-1);
				return;
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 26216