akhauriyash/Code-Regression huggingface dataset:
#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>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    mint sum = 0;
    for(int i=1; i<n; i++) sum += (mint)a[i];
    mint ans = 0;
    rep(i,n-1){
        ans += (mint)a[i] * sum;
        sum -= (mint)a[i+1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4824
import numpy as np

N = input().strip()
K = int(input().strip())
lenN = len(N)

dp = np.zeros((lenN+1, 2, 4))
dp[0][1][0] = 1
for keta in range(lenN):
    for flag in range(2):
        for k in range(K+1):
            for i in range(10):
                nk = k
                nflag = flag
                if flag:
                    if i > int(N[keta]):
                        continue
                    if i < int(N[keta]):
                        nflag = 0
                if i != 0:
                    nk = k + 1
                if nk > K:
                    continue
                dp[keta+1][nflag][nk]+=dp[keta][flag][k]

print(int(dp[lenN][0][K] + dp[lenN][1][K]))


Measured memory_bytes: 12500
#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>;
#define INF 100000000
const int MOD = 1000000007;


int main()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
const ll INF = (1ll << 60);

int main() {
  ll H,W,K; cin>>H>>W>>K;
  vector<string> A(H);
  REP(i,H) cin>>A[i];
  pii start;
  REP(i,H) REP(j,W) if(A[i][j]=='S') start={i,j};

  vpii deltas;
  deltas.PB({1,0});
  deltas.PB({0,1});
  deltas.PB({-1,0});
  deltas.PB({0,-1});


  vvi dist(H,vi(W,INF));
  queue<pii> q; q.push(start);
  dist[start.first][start.second]=0;
  while(q.size()) {
    pii from=q.front();
    q.pop();
    for(pii delta:deltas) {
      pii to={from.first+delta.first,from.second+delta.second};
      if(min(to.first,to.second)>=0&&to.first<H&&to.second<W&&dist[to.first][to.second]==INF&&A[to.first][to.second]!='#') {
        dist[to.first][to.second]=dist[from.first][from.second]+1;
        q.push(to);
      }
    }
  }
  ll ans=INF;
  REP(i,H) REP(j,W)if(dist[i][j]<=K) {
    ll d=min(min(i,H-i-1),min(j,W-j-1));
    if(d==0) ans=1;
    else ans=min(ans,(d-1)/K+2);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 6144
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	LL x;
	cin >> x;
	LL ans = 0;
	ans += (x / 11) * 2;
	x %= 11;
	if (x == 0) {}
	else if (1 <= x && x <= 6) {
		ans++;
	}
	else {
		ans += 2;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
let () =
  let game times =
    let rec loop a b = function
        0 -> a,b
      | i ->
        let x,y = Scanf.scanf "%s %s\n"
            (fun x y -> if x>y then 3,0 else if x<y then 0,3 else 1,1) in
        loop (a+x) (b+y) (i-1)
    in loop 0 0 times
  in
  let times = read_int () in
  let a,b = game times in
  Printf.printf "%d %d\n" a b

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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 main(){
    string s;
    cin >> s;
    for( char c='a';c<='z';c++){
        bool flg=true;
        for(int i=0;i<s.size();i++){
            if(c==s[i]) flg=false;
        }
        if(flg){
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll;
vector<int>v[200006];
int n,m,x,y,vis[200006];
bool flag;
void bfs(int x,int y,int k)
{
    if(x==y && k<=2)
    {
        printf("POSSIBLE\n");
        flag=true;
        return;
    }
    if(k>2) return;
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(!vis[v[x][i]])
        {
            vis[v[x][i]]=1;
            bfs(v[x][i],y,k+1);
            vis[v[x][i]]=0;
        }
    }
    vis[x]=0;
}
int main()
{
    scanf("%d%d",&n,&m);
    flag=false;
    memset(vis,0,sizeof(vis));
    while(m--)
    {
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    bfs(1,n,0);
    if(!flag) printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 12784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a;

		int five = 0;
		int seven = 0;

		for(int i = 0; i < 3; i++) {
			a = sc.nextInt();
			if(a == 5) {
				five++;
			}
			if(a == 7) {
				seven++;
			}
		}

		if(five == 2 && seven == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}

}


Measured memory_bytes: 21972
def counting_sort(arr_a, arr_b, k)
  arr_c = Array.new(k+1, 0)
  
  arr_a.each do |v|
    arr_c[v] += 1
  end

  for i in 1..k
    arr_c[i] = arr_c[i] + arr_c[i-1]
  end

  # n = arr_a.length
  # for j in (n-1).downto(0)
  #   arr_b[arr_c[arr_a[j]] - 1] = arr_a[j]
  #   arr_c[arr_a[j]] -= 1
  # end
  arr_a.reverse_each do |v|
    arr_b[arr_c[v] - 1] = v
    arr_c[v] -= 1
  end

end

n = gets.to_i
arr = gets.split.map(&:to_i)
arr_b = Array.new(n)
counting_sort(arr, arr_b, arr.max)
puts arr_b.join(' ')


Measured memory_bytes: 151396
#include<bits/stdc++.h>
using namespace std;
int a[200010],b[200010],n,k;
int main(){
	int i,j,k,l;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	while(k--){
		for(i=1;i<=n;i++)b[i]=0;
		for(i=1;i<=n;i++){
			j=max(i-a[i],1);
			l=min(i+a[i]+1,n+1);
			b[j]++,b[l]--;
		}
		for(i=1;i<=n;i++){
			a[i]=a[i-1]+b[i];
		}
		int cnt=0;
		for(i=1;i<=n;i++){
			if(i-a[i]-0.5<=1&&i+a[i]+0.5>=n)cnt++;
		}
		if(cnt==n&&k>=1){
			for(i=1;i<=n;i++)a[i]=n;
			break;
		} 
	}
	for(i=1;i<=n;i++){
		if(i!=1)printf(" ");
		printf("%d",a[i]);
	}
}

Measured memory_bytes: 5292
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1e+15;


void solve(istream &cin) {
    ll M, N;
    cin >> N >> M;
    if(!cin) return;

    ll ans = 1;
    for (int i = sqrt(M); i >= 1; --i) {
        if(M % i == 0){
            ll g = i;
            if(g * N <= M){
                ans = max(g, ans);
            }
            g = M / i;
            if(g * N <= M){
                ans = max(g, ans);
            }
        }
    } // end i
    cout << ans  << endl;
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	int n,k,x;
	cin>>n>>k;
	int nex[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>nex[i];
	}
	bool vis[n+1];
	memset(vis,0,sizeof vis);
	int st=-1;
	 x=1;
	while(1)
	{
		if(vis[x])
		{st=x;break;}
		vis[x]=1;
		x=nex[x];
	}
	//cout<<st<<" ";
	vector<int> cyc;
	memset(vis,0,sizeof vis);
	x=st;
	while(1)
	{
		if(vis[x])
		{break;}
		vis[x]=1;
		cyc.push_back(x);
		x=nex[x];
	}
	memset(vis,0,sizeof vis);
	 x=1;
	int hst=0;
	while(x!=st)
	{
		hst++;
		x=nex[x];
	}
	//cout<<hst;
	//cout<<cyc.size()<<" ";
	int chase;
	if(k>n)
	{
		int id=(k-hst)%cyc.size();
		cout<<cyc[id];
		return 0;
	}
	x=1;
	while(k--)
	{
		x=nex[x];
	}
	cout<<x;
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 6996
import abc
import itertools

def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for _ in range(N)]
    i = 0
    mps = []
    for assign in itertools.product([0, 1, 2, 3], repeat=N):
        if 1 not in assign or 2 not in assign or 3 not in assign:
            continue
        mp = 0
        abc_length = {1: 0, 2: 0, 3: 0}
        for i, abc in enumerate(assign):
            if abc == 0:
                continue
            elif abc_length[abc] == 0:
                abc_length[abc] = L[i]
            else:
                mp += 10
                abc_length[abc] += L[i]

        for key, goal in zip([1, 2, 3], [A, B, C]):
            mp += abs(goal - abc_length[key])
        mps.append(mp)
    print(min(mps))


if __name__ == '__main__':
    main()


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

int main() {
    long long N, A, B;
    cin >> A >> B >> N;
    
    if(B == 1) {
        cout << 0 << '\n';
    } else {
        cout << min(N, B - 1) * (A / B) + (A % B) * min(N, B - 1) / B << '\n';
        //cout << (B - 1) * (A / B) << '\n';
        //cout << (A % B) * min(N, B - 1) / B << '\n';
    }
}

Measured memory_bytes: 3632
s = input()
t = input()

s_arr = [0] * 26
t_arr = [0] * 26
for i in range(len(s)):
    temp = ord(s[i])- ord('a')
    s_arr[temp] += 1
    temp = ord(t[i])- ord('a')
    t_arr[temp] += 1

s_arr.sort()
t_arr.sort()

ans = 'Yes'
for i in range(26):
    if s_arr[i] != t_arr[i]:
        ans = 'No'

print(ans)


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(x, u) for (int x = 1; x <= u; x++)
typedef long long ll;
using namespace std;
void solve()
{     
    ll sum=0,k,a,b,c;
    cin>>k;
    FOR(a,k)
        FOR(b,k)
            FOR(c,k)
                sum+=__gcd(__gcd(a,b),c);

    cout<<sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
        cout << "\n";
    }
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 3804
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

#include <x86intrin.h>

using namespace std;

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

const ll mod = 1000000007;

ll a[200010];
ll dp[3][100010];

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

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

/*
  if (n % 2 == 0) {
    ll now = 0;
    for (int i = 0; i < n; i += 2) now += a[i];
    ll maximum = now;
    for (int i = n-2; i >= 0; i -= 2) {
      now += (a[i+1] - a[i]);
      if (now > maximum) maximum = now;
    }

    cout << maximum << endl;
  }
  else {
    vector<vector<ll> > dp(n+2, vector<ll>(3, (ll) -1e18));
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    dp[2][2] = a[2];
    for (int i = 0; i < n; i++) {
      if (i+2 < n) dp[i+2][0] = max(dp[i+2][0], dp[i][0] + a[i+2]);
      if (i+2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][1] + a[i+2]);
      if (i+2 < n) dp[i+2][2] = max(dp[i+2][2], dp[i][2] + a[i+2]);
      if (i+3 < n) dp[i+3][1] = max(dp[i+3][1], dp[i][0] + a[i+3]);
      if (i+3 < n) dp[i+3][2] = max(dp[i+3][2], dp[i][1] + a[i+3]);
      if (i+4 < n) dp[i+4][2] = max(dp[i+4][2], dp[i][0] + a[i+4]);
    }

    cout << max(max(dp[n-3][0], dp[n-2][1]), dp[n-1][2]) << endl;
  }
*/

  dp[0][0] = a[0];
  for (int i = 1; i < n/2; i++) {
    dp[0][i] = dp[0][i-1] + a[i*2];
  }
  dp[1][0] = a[1];
  for (int i = 1; i < n/2; i++) {
    dp[1][i] = max(dp[0][i-1], dp[1][i-1]) + a[i*2+1];
  }
  dp[2][0] = a[2];
  for (int i = 1; i < n/2; i++) {
    dp[2][i] = max(max(dp[0][i-1], dp[1][i-1]), dp[2][i-1]) + a[i*2+2];
  }

  ll ans = max(dp[0][n/2-1], dp[1][n/2-1]);
  if (n % 2 == 1) ans = max(ans, dp[2][n/2-1]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int md = 1e9+7;
 
 

 
 
long long cn, dp[2005];
 
ll  rec(ll s)
{
   
  if(dp[s]!=-1) return dp[s];
 
  if(s==0)      return 1;
  if(s<0)       return 0 ;
  
  
 
  
 
  ll ans=0;
 
  for(int i=3;i<=s;i++)
  
    ans = (ans%md +rec(s-i)%md)%md;
  
 
  dp[s] =ans;
 
  return dp[s];
 
 
}
 
 
 
int main()
{
 
  long long s;
  cin>>s;
 
  memset(dp,-1,sizeof(dp));  //dp array initialize all with minus -1
  
  //dp gives pair with sum =s and all element greater than or equal to 3
 
  cout<<rec(s)<<endl;
 
 
    
}

Measured memory_bytes: 3584
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

uint64_t get_gcd(uint64_t a, uint64_t b)
{
    if (b == 0)
        return a;
    else
        return get_gcd(b, a % b);
}

uint64_t get_lcm(uint64_t a, uint64_t b)
{
    uint64_t g = get_gcd(a, b);
    return a / g * b;
}

int main(void)
{
    intmax_t A, B;
    intmax_t ans = 0;

    scanf("%jd%jd", &A, &B);

    ans = get_lcm(A, B);

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
//神题
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
struct ww{ll a, b;}w[90][90];
int n, ans;
ll f[90], x, y, sum;
int main(){
	f[0]=f[1]=1; for(int i=2; i<=88; i++)f[i]=f[i-2]+f[i-1];
	w[1][1].a=1; w[1][1].b=2; w[1][2].a=1; w[1][2].b=3;
	for(int i=1; i<=86; i++){
		for(int j=1; j<=i+1; j++){w[i+1][j].a=w[i][j].b; w[i+1][j].b=w[i][j].a+w[i][j].b;}
		w[i+1][i+2].a=f[i+1]; w[i+1][i+2].b=f[i+3];
	}
	scanf("%d", &n);
	for(int owo=1; owo<=n; owo++){
		scanf("%lld%lld", &x, &y); if(x>y)swap(x, y);
		ans=1; for(int i=2; i<=86; i++)if(f[i]<=x&&f[i+1]<=y)ans=i;
		printf("%d ", ans);
		if(ans==1){printf("%d\n", (x%mod)*(y%mod)%mod); continue;}
		sum=0; ans--;
		for(int i=1; i<=ans+1; i++){
			sum=(sum+(x-w[ans][i].a)/w[ans][i].b)%mod;
			if(x>=w[ans][i].b)sum=(sum+(y-w[ans][i].a)/w[ans][i].b)%mod;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[5][5],B[200005],fix[5][5];
int main() {
    for(long long i=1;i<=3;i++) {
        for(long long j=1;j<=3;j++) {
            cin>>A[i][j];
        }
    }
    cin>>n;
    for(long long a=1;a<=n;a++) {
    cin>>B[a];
        for(long long i=1;i<=3;i++)
            for(long long j=1;j<=3;j++)
            if(B[a]==A[i][j]) fix[i][j]=1;
    }
	if(fix[1][1]==1 && fix[1][2]==1 && fix[1][3]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[2][1]==1 && fix[2][2]==1 && fix[2][3]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[3][1]==1 && fix[3][2]==1 && fix[3][3]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[1][1]==1 && fix[2][1]==1 && fix[3][1]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[1][2]==1 && fix[2][2]==1 && fix[3][2]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[1][3]==1 && fix[2][3]==1 && fix[3][3]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[1][1]==1 && fix[2][2]==1 && fix[3][3]==1) { cout<<"Yes"<<endl; return 0; }
	if(fix[1][3]==1 && fix[2][2]==1 && fix[3][1]==1) { cout<<"Yes"<<endl; return 0; }
	cout<<"No"<<endl;
}

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

using namespace std;

const int N = 1e6+10;
long long int a[N], b[N], c[N];

int main () {
    long long int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++ )
        cin >> a[i],a[i]--;
    for(int i = 0 ; i < n ; i++ )
        cin >> b[i];
    for(int i = 0 ; i < n-1 ; i++ )
        cin >> c[i];
    long long int g=a[0], ans=b[a[0]];
    for(int i = 1 ; i < n ; i++ ) {
        ans+=b[a[i]];
        if(g==a[i]-1)
            ans+=c[g];
        g=a[i];
    }
    cout << ans;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a), i_len = (b); i < b; ++i)

const int MAX_N = 1010;
ll factor[MAX_N];
const ll mod = 1e9 + 7;

void prime_factor(int N) {
    for(int i = 2; i * i <= N; ++i) {
        while(N%i == 0) {
            ++factor[i];
            N /= i;
        }
    }
    if(N != 1) ++factor[N];
}

int main()
{
    int N;
    cin >> N;
    for(int i = 1; i <= N; ++i) prime_factor(i);
    ll res = 1;
    for(int i = 1; i <= N; ++i) res *= (1LL + factor[i]), res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <tuple>
#define FOR0(var, max) for (ui (var) = 0; (var) < (max); ++(var))
#define FOR_INV(var, min, max) for (ui (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using sl = signed long long int;

const static ul NMAX = 100000;
const static ul HiMAX = 1000000000;

static ul N;
static sl Hi[NMAX + 1];

void solve(void) {
  Hi[N] = HiMAX + 1;
  ul maxidx = 0;
  ul res = 0;
  FOR0(_i, N) {
    ui i = _i + 1;
    if (Hi[i - 1] < Hi[i]) {
      // cout << maxidx << "(" << Hi[maxidx] << ") -> " << i << "(" << Hi[i] << ")" << endl;
      ul t = i - maxidx - 1;
      if (res < t) {
        res = t;
      }
      maxidx = i;
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Hi[i];
  }
  solve();
  return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        String[] s = br.readLine().split(" ");
        int[] a = new int[n];
        long sum = 0;
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(s[i]);
            sum += a[i];
        }

        long left = a[0], right = sum - a[0];
        long min = Math.abs(left - right);

        for(int i=1; i<n-1; i++){
            left += a[i];
            right -= a[i];
            if(Math.abs(left - right) < min) min = Math.abs(left - right);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 49500
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
int main(){
 
  int n;
  int i;
  int cnt = 0;
 
  scanf("%d", &n);
 
  for(i = 1;i <= n;i++){
    if(1 <= i && i <= 9) cnt++;
    if(100 <= i && i <= 999) cnt++;
    if(10000 <= i && i <= 99999)cnt++;
  }
 
  printf("%d\n", cnt);
 
  return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    ps: [f64; n]
  }
  let mut dp = vec![vec![0.0; n + 1]; n + 1];
  dp[0][0] = 1.0;
  for (i, p) in ps.iter().enumerate() {
    for k in 0..n+1 {
      dp[i+1][k] = dp[i][k] * (1.0 - p);
      if k >= 1 {
        dp[i+1][k] += dp[i][k-1] * p;
      }
    }
  }
  let ans: f64 = dp[n].iter().skip(n / 2 + 1).sum();
  println!("{:.15}", ans);
}


Measured memory_bytes: 90364
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 2333333
#define MIN(_A, _B) (((_A) < (_B)) ? (_A) : (_B))
 
int n, Q;
int B[233333];
 
struct Data{
	int l, r;
	bool operator <(const Data a)const{
		if(l == a.l) return r > a.r;
		return l < a.l;
	}
}d[233333];
 
 
//Seg_Tree
int ql, qr;
int t[999999];
int query(int now, int l, int r){
	if(l >= ql && r <= qr) return t[now];
	int mid = l + r >> 1, qa = INF, qb = INF;
	if(ql <= mid) qa = query(now << 1, l, mid);
	if(qr > mid) qb = query(now << 1 | 1, mid + 1, r);
	return MIN(qa, qb);
}
void modifm(int now, int l, int r, int q, int v){
	if(l == r) {t[now] = MIN(t[now], v); return;} 
	int mid = l + r >> 1;
	if(q <= mid) modifm(now << 1, l, mid, q, v);
	else modifm(now << 1 | 1, mid + 1, r, q, v);
	t[now] = MIN(t[now << 1], t[now << 1 | 1]);
}
 
int ans = 0;
void input(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &B[i]), (B[i] == 0) && (ans++);
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++)
		scanf("%d %d", &d[i].l, &d[i].r);
	std::sort(d + 1, d + Q + 1);
	memset(t, 63, sizeof(t));
}
 
void work(){
	int now = 1;
	for(int i = 1, tmp = 0; i <= n; i++){
		while(now <= Q && d[now].l == i){
			ql = i - 1, qr = d[now].r;
			tmp = query(1, 1, n);
			if(ql == 0) tmp = MIN(tmp, 0);
			modifm(1, 1, n, qr, tmp);
			now++;
		}
		ql = qr = i - 1;
		if(i == 1) tmp = 0;
		else tmp = query(1, 1, n);
		(B[i] == 0) ? (tmp--) : (tmp++);
		modifm(1, 1, n, i, tmp);
	}
	ql = qr = n;
	printf("%d\n", ans + query(1, 1, n));
}
 
int main(){
	input();
	work();
	return 0;
}

Measured memory_bytes: 6656
import math

def main(H,W):
    ans = float('inf')
    w = math.floor(W / 2)
    for i in range(H):
        Smin = min(i * W, w * (H - i), (W - w) * (H - i))
        Smax = max(i * W, w * (H - i), (W - w) * (H - i))
        ans = min(ans, Smax-Smin)
    return min(H,ans)

H, W = map(int, input().split())
    
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    print(min(main(H,W), main(W,H)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}



int main() {
ll N;
  ll D;
  cin >>N>>D;
  vl X(N);
  vl Y(N);
  rep(i,N) {
cin >>X.at(i)>>Y.at(i);
  }

  
  ll count=0;
  rep(i,N) {
ll a=X.at(i)*X.at(i)+Y.at(i)*Y.at(i);
    double b=sqrt(a);
    if(b<=D) {
      count++;
    }
  }
  
  
  
  cout<<count<<endl;
}


Measured memory_bytes: 6400
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N = +lines[0].split(" ")[0];
	const K = +lines[0].split(" ")[1];
	
	const ans = Array.from(Array(N),(e, i) => 
			Math.ceil(Math.max(Math.log2(K/(i+1)),0)))
		.map(n => Math.pow(1/2,n) / N)
		.reduce((a,b) => a+b);
	
	console.log(ans);
});

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

int main() {
   
	    int n;
	cin>>n;
	int a[n],dp[n];
	for(int i=0;i<n;i++)cin>>a[i];
	dp[0]=0,dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
	

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int n,m,q,from,to;
int rank[100000],parent[100000];

int find(int x){
	if(x == parent[x])return x;
	else{
		return parent[x] = find(parent[x]);
	}
}

bool isSame(int x,int y){
	return find(x) == find(y);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

	scanf("%d %d",&n,&m);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < m; i++){
		scanf("%d %d",&from,&to);

		if(isSame(from,to))continue;
		unite(from,to);
	}

	scanf("%d",&q);

	int left,right;

	for(int i = 0; i < q; i++){
		scanf("%d %d",&left,&right);

		if(isSame(left,right))printf("yes\n");
		else{
			printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.numeric, std.typecons;

bool[3001][3001] RESULT;

void main()
{
    auto it = readln.split.to!(int[]);
    auto A = it[0];
    auto B = it[1];
    auto C = it[2];
    auto D = it[3];
    auto E = it[4];
    auto F = it[5];

    void solve(int a, int b) {
        if (a + b > F || RESULT[a][b] || b * 100 > a * E) return;
        RESULT[a][b] = true;

        solve(a + 100 * A, b);
        solve(a + 100 * B, b);
        solve(a, b + C);
        solve(a, b + D);
    }

    solve(0, 0);

    size_t max_a, max_b;
    foreach (a, rs; RESULT) {
        foreach (b, r; rs) {
            if (r) {
                if (max_a == 0 && max_b == 0) {
                    max_a = a;
                    max_b = b;
                } else if ((b == 0 ? 0 : b * (max_a + max_b)) > (max_b == 0 ? 0 : max_b * (a + b))) {
                    max_a = a;
                    max_b = b;
                }
            }
        }
    }

    writefln("%s %s", max_a + max_b, max_b);
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

long long N, M, A[1 << 18];

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

	long long T = 0;
	for (int i = 0; i < N; i++) T += A[i];

	long long cnt = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] * 4LL * M >= T) cnt++;
	}
	if (cnt < M) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

int main() {
int n,k;
cin>>n>>k;
int a[n]={0};
for(int i=1;i<=n;i++)
{
    int co=0;
    int j=k;
    int kk=i;
    while(kk<j)
    {co++;
    kk*=2;
    }
    a[i-1]=co;
    co=0;
    
}

double ans=0;
for(int i=0;i<n;i++)
ans+=(double)(1/(pow(2,a[i])));

double don=(double)ans/n;
std::cout << std::fixed << std::setprecision(12) << don << std::endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << x << endl;
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;
//ll power_mod(ll a, ll k){ll ans = 1;a %= MOD;while(k){if(k % 2) ans *= a;a = (a * a) % MOD;k /= 2;ans %= MOD;}return ans;}
//ll power(ll a, ll k){ll ans = 1;while(k){if(k % 2)ans *= a;a = a * a;k /= 2;}return ans;}
//ll CalcAppNum(ll n){ll ans = 0;for(ll i=1,j; i<=n; i=j+1) {j = min(n, n / (n/i));ans += (j - i + 1) *(n/i);}return ans;}    //计算1-n约束个数和
template<class T>inline void read(T &res) {char c;T flag=1;while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;}
template<class T>inline void prin(T x) {if(x>9)prin(x/10);putchar(x%10+'0');}
const int MOD = 2333;
const int MAX = 1e7;
const int MAXN = 1e7+10;
const int inf = 2e5 + 100;
long double PI =3.14159265358979323846;
//INT_MAX

int main()
{
    int a, b;
    int tmp[3] = {1, 2, 3};
    cin >> a >> b;
    int c;
    for(int i=0; i<3; i++)
        if(tmp[i] != a && tmp[i] != b) c = tmp[i];
    cout << c << endl;
    return 0;
}

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

int calcMoney(string word, vector<string> s, vector<string> t)
{
  int money = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (s.at(i) == word)
    {
      money++;
    }
  }
  for (int i = 0; i < t.size(); i++)
  {
    if (t.at(i) == word)
    {
      money--;
    }
  }
  return money;
}

int main()
{
  int N, M;

  cin >> N;
  vector <string> s(N);
  for (int i = 0; i < N; i++)
  {
    cin >> s.at(i);
  }
  cin >> M;
  vector <string> t(M);
  for (int i = 0; i < M; i++)
  {
    cin >> t.at(i);
  }

  int result = 0;
  for (int i = 0; i < s.size(); i++)
  {
    result = max(calcMoney(s.at(i), s, t), result);
  }
  cout << result << endl;
}

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

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int count = 0;

        for (int i = 0; i < N; i++)
        {
            if (i%2==0 && list[i]%2!=0)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 19000
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 2e5 + 9;
int n; ll c, f[N], h[N];

struct Line {
    ll k, m;
    mutable ll p;
    bool operator<(const Line& o) const {
        return k < o.k;
    }
    bool operator<(const ll&x) const {
        return p < x;
    }
};

struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = numeric_limits<ll>::max();
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    // query max
    ll query(ll x) { 
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};




signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> c;
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    LineContainer lc;
    // lc.add(0, 0);
    f[1] = 0;
    lc.add(2 * h[1], -h[1] * h[1]);
    for(int i = 2; i <= n; i++) {
        f[i] = lc.query(h[i]) - h[i] * h[i] - c;
        lc.add(+2 * h[i], f[i] - h[i] * h[i]);
    }
    cout << -f[n] << "\n";


    
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(i, m, n) for(int i = m; i < n; i++)
    #define rep3(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    lint X;
    cin >> X;
    lint t[200];
    for(lint i=0;i<200;i++)t[i]=i*i*i*i*i;
    
    rep(i,200){
        rep(j,200){
            if(X == t[i]-t[j]){
                cout << i <<endl;
                cout << j;
                return 0;
            }
        }
    }
    rep(i,200){
        rep(j,200){
            if(X == t[i]+t[j]){
                cout << i <<endl;
                cout << -1*j;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3628
class Node
  def initialize(parent, key)
    @key = key
    @parent = parent
    @left = nil
    @right = nil
  end

  attr_accessor :left, :right, :parent
  attr_reader :key
end

class BinarySearchTree
  def initialize
    @first = nil
    @visited_node = []
  end

  def insert(node)
    unless @first.nil?
      current = @first
      until current.nil?
        node.parent = current
        if node.key < current.key
          current = current.left
        else
          current = current.right
        end
      end
    end
    if @first.nil?
      @first = node
    elsif node.key < node.parent.key
      node.parent.left = node
    else
      node.parent.right = node
    end
  end

  def preorder_tree_walk(node)
    @visited_node << node.key
    return if node.nil?
    preorder_tree_walk node.left unless node.left.nil?
    preorder_tree_walk node.right unless node.right.nil?
  end

  def inorder_tree_walk(node)
    return if node.nil?
    inorder_tree_walk node.left unless node.left.nil?
    @visited_node << node.key
    inorder_tree_walk node.right unless node.right.nil?
  end

  def print
    inorder_tree_walk @first
    puts " #{@visited_node.join ' '}"
    @visited_node = []
    preorder_tree_walk @first
    puts " #{@visited_node.join ' '}"
    @visited_node = []
  end
end

n = gets.to_i
tree = BinarySearchTree.new
n.times do
  input = gets.split ' '
  case input[0]
  when 'insert'
    tree.insert Node.new nil, input[1].to_i
  when 'print'
    tree.print
  end
end



Measured memory_bytes: 72340
N,M = map(int,input().split())
LR = [[i for i in map(int,input().split())] for j in range(M)]
start = 1
end = N
for i in range(M):
  if start < LR[i][0]: start = LR[i][0]
  if end > LR[i][1]: end = LR[i][1]
    
ans = end-start+1
if ans < 0: ans = 0
print(ans)

Measured memory_bytes: 22820
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var dic = new Dictionary<int,int>();
		for(int i=0;i<N;i++){
			if(dic.ContainsKey(D[i]) == false) dic.Add(D[i],0);
			dic[D[i]]++;
		}
		
		for(int i=0;i<M;i++){
			if(dic.ContainsKey(T[i]) == false){
				Console.WriteLine("NO");
				return;
			}
			dic[T[i]]--;
			if(dic[T[i]] < 0){
				Console.WriteLine("NO");
				return;
			}
		}
		
		Console.WriteLine("YES");
	}
	int N;
	int[] D;
	int M;
	int[] T;
	public Sol(){
		N = ri();
		D = ria();
		M = ri();
		T = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 47292
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int l = Integer.parseInt(sc.next());
      int[] taste = new int[n];
      int sum = 0;
      for(int i=0;i<n;i++){
        taste[i] = l+i;
        sum+=taste[i];
      }
      int idx = -1;
      int min = 10000000;
      for(int i=0;i<n;i++){
        if(min > Math.abs(taste[i])){
          idx = i;
          min = Math.abs(taste[i]);
        }
      }
      System.out.print(sum-taste[idx]);
      System.out.flush();
    }
}

Measured memory_bytes: 21716
'''
再帰を使う解き方
'''
def solve(A, B, C):
    # クッキーが奇数枚の場合処理を終了する
    if (A % 2 == 1 or B % 2 == 1 or C % 2 == 1): return 0
    # クッキーの枚数が同数の場合無限に操作が行われる
    elif (A == B == C): return -1
    # クッキーの枚数がいずれも偶数米の場合、操作を実施し次の操作に移る
    else: return solve((B/2 + C/2), (A/2 + C/2), (A/2 + B/2)) + 1

A, B, C = map(int, input().split())
ans = solve(A, B, C)
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
const int maxn = 2e5 + 5;
int main(){
	int n;
	long long T,t[maxn];
	scanf("%d%lld",&n,&T);
	for(int i = 1;i <= n;i++)
		scanf("%lld",&t[i]);
	long long sum = 0;
	for(int i = 2;i <= n;i++){
		if(t[i] - t[i - 1] < T)
			sum = sum + (t[i] - t[i - 1]);
			else sum += T;
	}
	printf("%lld\n",sum + T);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define M 100010
#define fi first
#define sc second
#define pb push_back
#define LL long long
#define MOD 998244353
#define pii pair<int, int>
#define For(i, x, y) for(int i = (x); i < (y); i ++)
#define rep(i, x, y) for(int i = (x); i <= (y); i ++)
#define drep(i, x, y) for(int i = (x); i >= (y); i --)
inline int read(){char ch=getchar();int x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline LL llread(){char ch=getchar();LL x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline int Power(int x,int y,int mod){int r=1;while(y){if(y&1)r=1ll*r*x%mod;x=1ll*x*x%mod;y>>=1;}return r;}
LL a[M], f[M];
LL res[M];
int tt;
inline int Get(int l, int r, LL C) {
	int ret = -1;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(a[mid] <= C) l = (ret = mid) + 1;
		else r = mid - 1;
	} return ret;
}
int main() {
	int n = read(), q = read();
	a[tt = 1] = n; rep(i, 1, q) {
		LL x = llread();
		while(tt && x <= a[tt]) tt --;
		a[++ tt] = x;
	} q = tt; f[q] = 1;
	//cout << tt << endl;
	drep(i, q, 1) {
		LL x = a[i]; int t = i - 1;
		while((t = Get(1, t, x)) > 0) {
			f[t] += (x / a[t]) * f[i];
			x %= a[t];
		} res[x] += f[i];
	} drep(i, n-1, 1) res[i] += res[i + 1];
	rep(i, 1, n) printf("%lld\n", res[i]);
	return 0;
}



Measured memory_bytes: 4096
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    ll N,a[100010];
    cin>>N;
    rep(i,0,N)cin>>a[i];
    sort(a,a+N);
    int ok=0;
    int jud=(a[0]^a[N/3])^a[2*N/3];
    if(a[0]==0&&a[N-1]==0)ok=1;
    else if(N%3==0&&a[0]==0&&a[2*N/3-1]==0&&a[2*N/3]==a[N-1])ok=1;
    else if(N%3==0&&a[0]==a[N/3-1]&&a[N/3]==a[2*N/3-1]&&a[2*N/3]==a[N-1]&&jud==0)ok=1;
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    

    
}






Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long  N, M;
  long long  ans = 0;
  string s;

  cin >> N;

  vector<long long > A(N);
  vector<long long > B(N);
  for(long long  i = 0; i < N; i++){
    cin >> A[i];
    B[i]= A[i];
  }
  sort(B.begin(), B.end());

  for(long long  i = 0; i < N; i++){
    if(B[N-1] == A[i]){
      cout << B[N-2] << endl;
    }else{
      cout << B[N-1] << endl;
    }
  }
}


Measured memory_bytes: 4736
#include <stdio.h>

int a, AC, WA, TLE, RE;
char b[1000000], A[]=("AC"), W[]=("WA"), T[]=("TLE"), R[]=("RE");

int main(){
	scanf("%d", &a);
	for(int i=0; i+1<=a; i++){
		scanf("%s", &b[i]);
	}
	for(int j=0; j+1<=a; j++){
		if(b[j]==A[0]) AC=AC+1;
		else if(b[j]==W[0]) WA=WA+1;
		else if(b[j]==T[0]) TLE=TLE+1;
		else if(b[j]==R[0]) RE=RE+1;
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", AC, WA, TLE, RE);
	return 0;
}

Measured memory_bytes: 1808
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int cnt = 0;
    for(int i=1; i<=n; ++i) {
        int tmp = 0;
        if (i%2==1) {
            for(int j=1; j<=i; ++j) {
                if (i%j==0) {
                    tmp++;
                }
            }
        }
        if (tmp==8) {
            cnt++;
        }
    }
    cout << cnt << "\n";
}



Measured memory_bytes: 256
N,Q = map(int,input().split())
S = str(input())
cumulative_sum = [0,0]
cont = 0
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        cont += 1
    cumulative_sum.append(cont)
for i in range(Q):
    l,r = map(int,input().split())
    print(cumulative_sum[r]-cumulative_sum[l])

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

int main()
{
  int N;
  cin >> N;
  
  vector<int> vec(N);

  for (int i = 0; i < N; i++) 
    cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N - 1; i++)
  {
    if (vec.at(i) == vec.at(i + 1))
    {
      cout << "NO" << endl;
      return 0;
    }
  }
  
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ab = sorted([[a[i], b[i]] for i in range(n)], key=lambda x: x[1])

    num=1
    while num < n:
        num *= 2
    num-=1
    inf=10**9+1

    m=num+n
    segtree=[inf]*m
    for i in range(num,m):
        segtree[i] = ab[i - num][0]
    for i in range(num-1,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=inf
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i] = min(segtree[j], segtree[j + 1])

    #探す
    def search(s):
        i=0
        while i < num:
            k = 2 * i + 1
            if k+2<=m:
                if segtree[k+1] <= s:
                    i = k + 1
                    continue
            if k+1<=m:
                if segtree[k] <= s:
                    i = k
                    continue
            return - 1
        return i - num
    
    #更新
    def update_good(i, s):
        if segtree[i] > s:
            segtree[i] = s
            update_good((i - 1) // 2, s)
    
    def update_bad(i):
        k=(i - 1) // 2
        if i % 2 == 1:
            if m > i + 1:
                temp=min(segtree[i+1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)
            else:
                segtree[k] = segtree[i]
                update_bad(k)
        else:
            if i != 0:
                temp=min(segtree[i-1],segtree[i])
                if segtree[k]<temp:
                    segtree[k] = temp
                    update_bad(k)

    cnt = 0
    for i in range(n):
        a,b=ab[i][0],ab[i][1]
        if a > b:
            t = search(b)
            if t <= i:
                print("No")
                return 0
            update_good(num + i, a)
            segtree[num + t] = a
            update_bad(num + t)
            ab[i][0], ab[t][0] = ab[t][0], a
            cnt+=1
    if cnt <= n - 2:
        print("Yes")
    else:
        print("No")
    
main()

Measured memory_bytes: 24920