akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
	ll a , b , c;
	cin>>a>>b>>c;
	ll ans = 0;
	map <pair <ll , pair <ll,ll> > , bool > ada ;
	while(1)
	{
		if(ada[make_pair(a , make_pair(b,c))] == 1)
		{
			ans = -1;
			break;
		}
		if(a%2 == 1 || b %2 == 1 || c%2 == 1)
		{
			break;
		}
		ada[make_pair(a , make_pair(b,c))] = 1;
		ll x = a/2 , y = b/2 , z = c/2;
		a =a/2;
		b = b/2;
		c = c/2;
		a = y + z;
		b = x + z;
		c = x + y;
//		cout<<a<<" "<<b<<" "<<c<<endl;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
R, G, B, N = map(int, input().split())

output = 0
# for g in range(N // G + 1):
#     for b in range(N // B + 1):
#         if (N - g*G - b*B) % R == 0:
#             if N >= g*G + b*B:
#                 output += 1
#             else:
#                 break

for r in range(N // R + 1):
    C = N - r*R
    for g in range(C // G + 1):
        if (C - g*G) % B == 0:
            if C >= g*G:
                output += 1
            else:
                break

print(output)


Measured memory_bytes: 2940
K = int(input())
i = list(map(int, input().split()))
A = i[0]
B = i[1]
C = A // K
D = B // K
E = A % K
F = B % K
if D - C > 0 or E == 0 or F == 0:
  print("OK")
else:
  print("NG")


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a1(n);
    vector<int> a2(n);
    rep(i, n){
        cin >> a1[i];
    }
    rep(i, n){
        cin >> a2[i];
    }
    int maxi = 0;
    for (int i=0; i<n; i++){
        int sum  = 0;
        for (int j=0; j<=i; j++){
            sum += a1[j];
        }
        for (int k=i; k<n; k++){
            sum += a2[k];
        }
        maxi = max(maxi, sum);
    }
    out(maxi);
}

Measured memory_bytes: 3608
n,m = [int(x) for x in input().split()]
a=[]
b=[]

for i in range(n): a.append([int(x) for x in input().split()])
for j in range(m): b.append(int(input()))
for a_row in a:
    print(sum([x*y for x,y in zip(a_row,b)]))


Measured memory_bytes: 5988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		execute();
	}

	private static void execute() {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if(a > 9 || b > 9) {
				System.out.println(-1);
			} else {
				System.out.println(a*b);
			}
			
			
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  int n; cin >> n;
  int x[n], minx = 100, maxx = 0;
  for(int i = 0; i < n; i++){
    cin >> x[i];
    minx = min(x[i], minx);
    maxx = max(x[i], maxx);
  }
  int summin = 100 * 100 * 100;
  for(int i = minx; i <= maxx; i++){
    int sum = 0;
    for(int j = 0; j < n; j++){
      sum += pow(x[j] - i, 2);
    }
    summin = min(sum, summin);
  }
  cout << summin << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,D;
    //string S;
    cin >> N >> D;
    ll x,y;
    ll ans = 0;
    rep(i,N){
        cin >> x >> y;
        if(x*x + y*y <= D*D)ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	char moji[7];
	int count = 0;

	cin >> moji;
	FOR(i, 0, 5) {
		if (moji[i] == '1') {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

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

int main(){
 int a,n,k,sum;
  cin>>n>>k;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
  vector<int> s(n);
  s[0]=p[0];
  for(int i=1;i<n;i++){
    s[i]=s[i-1]+p[i];
  }
  sum=s[k-1];
  for(int i=k;i<n;i++){
    sum=max(sum,s[i]-s[i-k]);
  }
  sum+=k;
  double ans=(double)sum/2;
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 1792
S = input()
N = len(S)
flag = True
for i in range(0,N//2):
    if S[i] != S[N//2 - i-1]:
        flag = False
    if S[i+N//2+1] != S[N-i-1]:
        flag = False
for i in range(N):
    if S[i] != S[N-1-i]:
        flag = False
print("Yes" if flag else "No")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
    int n, m;
    cin >> n>>m;
    int i;
    vector<int>h(n);
    vector<int>f(n);
    int cnt = 0;
    for (i = 0; i < n; i++)
    {
        cin >> h.at(i);
        f.at(i) = 1;
    }
    int a, b;
    for (i = 0; i < m; i++)
    {
        cin >> a >> b;
        if (h.at(a - 1) > h.at(b - 1))
            f.at(b - 1) = 0;
        else if(h.at(a - 1) < h.at(b - 1))
            f.at(a - 1) = 0;
        else
        {
            f.at(b - 1) = 0;
            f.at(a - 1) = 0;
        }   
    }
    for (i = 0; i < n; i++)
    {
       // cout << h.at(i) << endl;
        if (f.at(i) == 1)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4032
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  string s,t;
  cin>>s>>t;
  ll S=s.size(),T=t.size();
  vector<char> ss(S);
  vector<char> tt(T);
  for(ll i=0;i<S;i++){
    ss.at(i)=s.at(i);
  }
  for(ll i=0;i<T;i++){
    tt.at(i)=t.at(i);
  }
  sort(ss.begin(),ss.end());
  sort(tt.begin(),tt.end());
  for(ll i=0;i<S;i++){
    s.at(i)=ss.at(i);
  }
  for(ll i=0;i<T;i++){
    t.at(i)=tt.at(T-1-i);
  }
  if(s<t){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll X, Y, Z;
  cin >> X >> Y >> Z;

  cout << Z << ' ' << X << ' ' << Y << endl;
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  map<int,int> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  int count = 0;
  for (auto i : A) {
    if (i.first > i.second) count += i.second;
    else count += i.second - i.first;
  }
  
  cout << count << endl;
}


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

int main() {
    using namespace std;
    unsigned long N, T;
    cin >> N >> T;
    ++T;
    vector<pair<unsigned long, unsigned long>> c;
    vector<unsigned long> d;
    for(unsigned long i{0}, a, b; i < N; ++i){
        cin >> a >> b;
        ++a;
        ++b;
        if(a == 1) d.push_back(b);
        else if(b <= T) c.emplace_back(a, b);
    }
    d.push_back(0);
    sort(d.begin(), d.end());
    partial_sum(d.begin(), d.end(), d.begin());
    sort(c.begin(), c.end(), [](auto i, auto j){return i.second * (j.first - 1) < j.second * (i.first - 1);});
    vector<unsigned long> dp{1, numeric_limits<unsigned long>::max()};
    dp.reserve(c.size() + 2);
    for(const auto& i : c){
        unsigned long t = upper_bound(dp.begin(), dp.end(), (T - i.second) / i.first) - dp.begin();
        if(t + 1 == dp.size())dp.emplace_back(numeric_limits<unsigned long>::max());
        for(; t--; )dp[t + 1] = min(dp[t + 1], dp[t] * i.first + i.second);
    }
    unsigned long ans{0};
    for(unsigned long i{0}; i + 1 < dp.size(); ++i)ans = max(ans, i + max<unsigned long>(1UL, upper_bound(d.begin(), d.end(), T - min(T, dp[i])) - d.begin()) - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6384
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        long K = sc.nextLong();
        long[] dataA = new long[N];
        long[] dataB = new long[M];
        for (int i = 0; i < N; i++) {
            dataA[i] = sc.nextInt();
        }
        for (int i = 1; i < N; i++) {
            dataA[i] += dataA[i - 1];
        }

        for (int i = 0; i < M; i++) {
            dataB[i] = sc.nextInt();
        }

        for (int i = 1; i < M; i++) {
            dataB[i] += dataB[i - 1];
        }

        int result = 0;
        int nextB = 0;
        for (int i = N - 1; i >= 0; i--) {
            while (nextB < M && dataA[i] + dataB[nextB] <= K) {
                result = Math.max(result, i + 1 + nextB + 1);
                nextB++;
            }
        }
        for (int i = 0; i < N; i++) {
            if (dataA[i] <= K) {
                result = Math.max(result, i + 1);
            }
        }
        for (int i = 0; i < M; i++) {
            if (dataB[i] <= K) {
                result = Math.max(result, i + 1);
            }
        }

        pw.println(result);
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 63048
#include <iostream>

using namespace std;
long long dog;
char a[]={"zabcdefghijklmnopqrstuvwxy"};
int name[13];
int main() {
    cin>>dog;
    int i;
    for ( i=0; dog > 0; i++){
        if (dog%26 == 0) {
            name[i] = 0;
            dog/=26;
            dog--;
        }
        else {
            name[i] = (dog % 26);
            dog /= 26;
        }
    }
    i--;
    for (;i>=0; i--)
        cout<<a[name[i]];
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <stack>

int main() {
    int n; std::cin >> n;
    std::vector<std::vector<std::pair<int /* to */, int /* cols */>>> e(n);
    for (int i = 0; i < n-1; i++) {
        int u, v, w; std::cin >> u >> v >> w; u--; v--;
        e[u].push_back(std::make_pair(v, w));
        e[v].push_back(std::make_pair(u, w));
    }
    std::vector<int> c(n, -1);
    std::stack<int> s;
    s.push(0); c[0] = 0;
    while (!s.empty()) {
        int v = s.top(); s.pop();
        // std::cout << v << std::endl;
        for (const auto ee: e[v]) {
            if (c[ee.first] != -1) {
                continue;
            }
            // std::cout << "    " << ee.first << std::endl;
            if (ee.second % 2 == 0) {
                c[ee.first] = c[v];
            } else {
                c[ee.first] = 1 - c[v];
            }
            s.push(ee.first);
        }
    }
    for (int i = 0; i < n; i ++) {
        std::cout << c[i] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6784
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    vector<pair<int,int> >v;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        v.pb(mp(a[i],i+1));
    }
    sort(v.begin(),v.end());
    for(auto x:v)
        cout<<x.second<<" ";


}



Measured memory_bytes: 2164
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

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

int main()
{
    ll N;
    cin >> N;
    ll rootN = ll(sqrt(N));
    ll answer = N * 2;
    for (ll i = 1; i <= rootN; i++)
    {
        if (N % i == 0)
        {
            ll tmp = i + (N / i) - 2;
            if (tmp < answer) answer = tmp;
        }
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	sort(A.begin(), A.end());
	vector<int> B(M), C(M), perm(M);
	for (int i = 0; i < M; ++i) {
		cin >> B[i] >> C[i];
		perm[i] = i;
	}
	sort(perm.begin(), perm.end(), [&](int i, int j) { return C[i] > C[j]; });
	long long sum = 0;
	for (int i : perm) {
		for (long long j = sum; j < sum + B[i] && j < N; ++j) {
			A[j] = max(A[j], C[i]);
		}
		sum += B[i];
	}
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += A[i];
	}
	cout << ans << endl;
	return 0;
}

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

int factor(int x){

   int cnt =0;
   int lim = sqrt(x);

   for(int i=1;i<=lim;i++){

       if(x % i ==0){

         int f = x/i;
         int s = x / f;

         if(f == s){
                cnt++;
            //v.push_back({f,s});
         }else{
                cnt+=2;
           // v.push_back({f,s});
            //v.push_back({s,f});
         }
       }
   }

   return cnt;
}

int main()
{

  int n;
  cin>>n;
  int ans =0;
  for(int c=1;c<=n;c++){
    int n_s = n - c;
    ans += factor(n_s);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long dp1[100001][100];
long long a[100][2];
long long dp(int i,int n,int k){
	if(k==n)return 0;
	if(dp1[i][k]!=-1)return dp1[i][k];
	long long x=0;
	x=dp(i,n,k+1);
	if(a[k][0]<=i){x=max(x,a[k][1]+dp(i-a[k][0],n,k+1));}
	return dp1[i][k]=x;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,w;
	cin>>n>>w;
	memset(dp1,-1,sizeof(dp1));
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
	}
	cout<<dp(w,n,0);
    return 0;
}

Measured memory_bytes: 78464
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut resp = 0i64;
    let mut sum = 0;
    let mut plus = true;
    for i in 0..n {
        let sum2 = sum + a[i];
        if plus && sum2 <= 0 {
            resp += 1 - sum2;
            sum = 1;
        } else if !plus && sum2 >= 0 {
            resp += sum2 + 1;
            sum = -1;
        } else {
            sum = sum2;
        }
        plus = !plus;
    }

    let mut resm = 0i64;
    let mut sum = 0;
    let mut plus = false;
    for i in 0..n {
        let sum2 = sum + a[i];
        if plus && sum2 <= 0 {
            resm += 1 - sum2;
            sum = 1;
        } else if !plus && sum2 >= 0 {
            resm += sum2 + 1;
            sum = -1;
        } else {
            sum = sum2;
        }
        plus = !plus;
    }
    
    let ans = min(resp, resm);
    println!("{}", ans);
}


Measured memory_bytes: 3776
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        long cnt = 0;

        int N = sc.nextInt();
        long A = sc.nextInt();
        long B = sc.nextInt();

        long[] dp  = new long[N];
        
        for(int i=0;i<N;i++){
            dp[i] = sc.nextInt();
        }

        for (int i=0;i<N-1;i++){
          //   System.out.println(cnt);
            if( (dp[i+1]-dp[i]) * A < B ) cnt += (dp[i+1]-dp[i]) * A ; 
            else cnt += B;
          //  System.out.println(i);
        } 



        System.out.print(cnt);
        System.out.println();
    }

}

Measured memory_bytes: 34836
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function segTree(n){
  var l = n.length, u = l-1, x = 2, i, v;
  while(u)u >>= 1, x <<= 1;
  v = this.seg = Array(x-1).fill(0);
  this.l = x = (x >> 1) - 1;
  for(i = 0; i < l; i++)v[i+x] = n[i];
  for(i = x-1; i >= 0; i--)v[i] = segSolve(v[i+i+1],v[i+1<<1]);
}
function segSolve(a,b){
  return a|b;
}
segTree.prototype={
  get:function(l,r){//[l,r)
    if(l >= r)return 0;
    var v = this.seg;
    return q(l,r,0,this.l+1,0);
    function q(l,r,x,y,i){
      if(l === x && r === y)return v[i];
      var m = x+y >> 1;
      if(m < r)if(l < m)return segSolve(q(l,m,x,m,i+i+1),q(m,r,m,y,i+1<<1));
      else return q(l,r,m,y,i+1<<1);
      return q(l,r,x,m,i+i+1);
    }
  },
  update:function(x,i){
    var v = this.seg;
    i += this.l;
    v[i] = x;
    for(i = i-1>>1; i >= 0; i = i-1>>1){
      v[i] = segSolve(v[i+i+1],v[i+1<<1]);
    }
  },
}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var s = next(1);
  var q = next();
  var a = Array(n);
  for(var i = 0; i < n; i++){
    a[i] = 1 << (s[i].charCodeAt()-97);
  }
  var seg = new segTree(a);
  var ans = [];
  for(var i = 0; i < q; i++){
    var t = next();
    if(t === 1){
      var u = next()-1, v = next(1);
      seg.update(1 << v.charCodeAt()-97, u);
      continue;
    }
    var l = next()-1, r = next();
    ans.push(bitCount(seg.get(l,r)));
  }
  return ans.join("\n");
}

function bitCount(bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

Measured memory_bytes: 28732
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> a(N + 1);
  rep (i, N) cin >> a[i + 1];
  unordered_set<long> st;
  for (long i = N; i >= 1; i--) {
    long tmp = 0;
    for (long j = i; j <= N; j += i) if (st.count(j) > 0) tmp++;
    tmp %= 2;
    if (tmp != a[i]) st.insert(i);
  }
  cout << st.size() << endl;
  bool space = false;
  for (auto it: st) {
    if (space) cout << " ";
    space = true;
    cout << it;
  }
  if (st.size()) cout << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 8612
#include"bits/stdc++.h"
using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

bool equation(const string &s, int &i, const int set);
bool formula(const string &s, int &i, const int set);

int main() {
	string s;
	while (cin >> s, s[0] != '#') {
		s += '#';
		bool isok = true;
		for (int i = 0; i < (1 << ('k' - 'a' + 1)); i++) {
			int num=0;
			isok&=equation(s,num,i);
		}
		string res;
		if (isok) {
			res="YES";
		}
		else {
			res="NO";
		}
		cout << res << endl;
	}
	return 0;
}

bool equation(const string &s, int &i, int set) {
	bool lhs = formula(s, i, set);
	i++;
	bool rhs = formula(s, i, set);
	return (lhs == rhs);
}

bool formula(const string &s, int &i, int set) {
	if (s[i] == '-') {
		i++;
		return !formula(s, i, set);
	}
	if (s[i] == '(') {
		i++;
		bool lhs = formula(s, i, set);
		char op = s[i];
		i++;
		if (op == '-') {
			i++;
		}
		bool rhs = formula(s, i, set);
		i++;
		if (op == '*') {
			return lhs&rhs;
		}
		if (op == '+') {
			return lhs | rhs;
		}
		if (op == '-') {
			if (lhs && !(rhs)) {
				return false;
			}
			else {
				return true;
			}
		}
	}
	char val = s[i];
	i++;
	if (val == 'T') {
		return true;
	}
	if (val == 'F') {
		return false;
	}
	return (set & 1 << (val - 'a'));
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=51 ;
ll n,m,q ;
ll a[N],b[N],c[N],d[N] ;
ll ans ;
void fun(vector<ll>&v)
{
    if(v.size()==n){
        ll ct=0;
        for(ll j=0;j<q;j++){
            if(v[b[j]-1]-v[a[j]-1]==c[j]) ct+=d[j] ;
        }
        ans=max(ans,ct) ;
    }
    else if(v.size()==0){
        for(ll j=1;j<=m;j++){
            v.push_back(j) ;
            fun(v) ;
            v.pop_back() ;
        }
    }
    else{
        for(ll j=v.back();j<=m;j++){
            v.push_back(j) ;
            fun(v) ;
            v.pop_back() ;
        }
    }
}
int main()
{
   fast ;
   cin>>n>>m>>q ;
   for(ll i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i] ;

   ans=0 ;
   vector<ll>v ;
   fun(v) ;


   cout<<ans ;



}




Measured memory_bytes: 3620
def main():
    N = int(input())
    C = []
    S = []
    F = []
    for i in range(1, N):
        c, s, f = map(int, input().split())
        C.append(c)
        S.append(s)
        F.append(f)

    AC(N, C, S, F)


def AC(N, C, S, F):
    for i in range(N):
        t = 0
        for j in range(i, N - 1):
            t = t_func(t, C[j], S[j], F[j])

        print(t)


def t_func(t, c, s, f):
    if t < s:
        # 開通式終了前、終了待ってから次の駅(今までのtに依存しない)
        return s + c
    elif t % f == 0:
        # 開通式終了済み、ちょうど列車が発車しているか
        return t + c
    else:
        # 終了済みだが、列車待ち
        return t + (f - t % f) + c
        # t + (f - t  % f)
        # => (t // f + 1) * f
        # => t // f: 余りを気にせず商を求める
        ((t - t % f) // f + 1) * f
        (t - t % f) + f


def WA(N, C, S, F):
    # 逆順に計算して、結果の再利用
    res = [0] * N
    for i in range(1, N):
        res[i] = res[i - 1] + C[-i]
    # 後続の列車より早くない
    for i in range(1, N):
        res[i] = max(res[i - 1], res[i] + S[-i])

    for r in reversed(res):
        print(r)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	if(a.length() < b.length())	cout << "LESS" << endl;
	else if(a.length() > b.length()) cout << "GREATER" << endl;
	else{
		if(a > b)	cout << "GREATER" << endl;
		else if(a == b)	cout << "EQUAL" << endl;
		else if(a < b)	cout << "LESS" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    long double a,b;
    cin >> a >> b;
    cout << (ll)(a*b) << endl;
}

Measured memory_bytes: 3708
let inp = readLine()!.split(separator: " ").map { Int($0)! }
let N = inp[0]
let K = inp[1]
let h = readLine()!.split(separator: " ").map { Int($0)! }
var dp: [Int] = .init(repeating: Int.max, count: N)
dp[0] = 0
for i in 0..<N {
  for j in 1...K {
    if i + j >= N {
      break
    }
  	dp[i + j] = min(dp[i + j], dp[i] + abs(h[i+j] - h[i]))
  }
}
print(dp[N-1])

Measured memory_bytes: 13272
n = gets.to_i
A = gets.split.map(&:to_i)

ans = []
head = 0
last = A.size - 1

A.reverse.each_with_index do |a, i|
  if i % 2 == 0
    ans[head] = a
    head += 1
  else
    ans[last] = a
    last -= 1
  end
end

puts ans.join(' ')


Measured memory_bytes: 26884
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(3 * N + 1, vector<int>(N + 1, -1)));
    rep(i, N + 1) rep(j, 3 * N + 1) dp[i][j][0] = 0;
    rep(j, 3 * N + 1) rep(k, N + 1) dp[N][j][k] = 0;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j <= 3 * N; j++) {
            for (int k = 1; k <= N; k++) {
                if (j < w[i] - w[0]) {
                    dp[i][j][k] = dp[i + 1][j][k];
                } else {
                    dp[i][j][k] = max(dp[i + 1][j][k], dp[i + 1][j - w[i] + w[0]][k - 1] + v[i]);
                }
            }
        }
    }
    int ans = 0;
    rep(i, N) {
        if (W < w[0] * (i + 1)) break;
        int a = dp[0][min(3 * N, W - w[0] * (i + 1))][i + 1];
        //cout << a << endl;
        ans = max(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 13440
#include <iostream>

using namespace std;

const int N = 200005;
int n, pr[N], last[N], target[N], w[N], t, col[N];

void add(int a, int b, int wa)
{
	t++;
	w[t] = wa;
	pr[t] = last[a];
	target[t] = b;
	last[a] = t;
}

bool visit[N];
void dfs(int x)
{
	visit[x] = 1;
	int ptr = last[x];
	while (ptr != 0)
	{
		int xx = target[ptr];
		if (!visit[xx])
		{
			if(w[ptr] % 2 == 0)
			{
				col[xx] = col[x];
			}
			else
			{
				col[xx] = ((col[x] + 1) & 1);
			}
			dfs(xx);
		}
		ptr = pr[ptr];
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i ++)
	{
		int aa, bb, ww;
		cin >> aa >> bb >> ww;
		add(aa, bb, ww);
		add(bb, aa, ww);
	}
	col[1] = 0;
	dfs(1);
	for (int i =1; i <= n; i++) cout << col[i] << endl;
	return 0;
}


Measured memory_bytes: 5504
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int H, W, D, Q, a, b, val, x[90009], y[90009], s[90009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> val; val--;
			x[val] = i;
			y[val] = j;
		}
	}
	for (int i = 0; i < H * W; i++) {
		if (i >= D) s[i] = s[i - D] + abs(x[i] - x[i - D]) + abs(y[i] - y[i - D]);
	}
	cin >> Q;
	while (Q--) {
		cin >> a >> b; a--, b--;
		cout << s[b] - s[a] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , m ;
    cin >> n >> m ;
    vector<vector<int> > g(n) ;
    for(int i = 0; i < m; i++){
        int a , b ;
        cin >> a >> b ; 
        a--, b-- ;
        g[a].emplace_back(b) ;
        g[b].emplace_back(a) ;
    }
    vector<int> from(n, -1) ;
    vector<int> dist(n, INF) ;
    dist[0] = 0 ;
    queue<int> q; 
    q.push(0) ;
    while(not q.empty()) {
        int f = q.front() ; q.pop() ;
        for(int &c : g[f]){
            if ( dist[c] > dist[f] + 1 ){
                dist[c] = dist[f] + 1 ;
                from[c] = f ;
                q.push(c) ;
            }
        }
    }
    for(int i = 1; i < n; i++){
        if ( from[i] == -1 ) {
            cout << "No" << endl;
            return 0 ;
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < n; i++){
        cout << from[i] + 1 << endl;
    }
    return 0; 
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

int getCount(string s){
  int count = 0;
  std::string::size_type pos = 0;
  while((pos = s.find("D", pos)) != std::string::npos){
    count++;
    pos++;
  }
  pos = 0;
  while((pos = s.find("PD", pos)) != std::string::npos){
    count++;
    pos++;
  }
  return count;
}

signed main() {
  string str;
  cin >> str;
  
  string strR = str;
  string strD = str;
  replace(strR.begin(),strR.end(),'?','R');
  replace(strD.begin(),strD.end(),'?','D');
  
  cout << strD << endl;

//  if(getCount(strR)>getCount(strD))
//    cout << strR << endl;
//  else
  
  return 0;
}

Measured memory_bytes: 3872
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    int left = a + b;
    int right = c + d;
    
    if (left == right) {
      System.out.println("Balanced");
    } else if (left > right) {
      System.out.println("Left");
    } else if (left < right) {
      System.out.println("Right");
    }
  }
}

Measured memory_bytes: 23636
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long MOD = 1'000'000'007LL;
const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N, W; scanf("%lld %lld", &N, &W);
	ll mx = 10050;
	vector<ll> v(N), w(N); for (ll i = 0; i < N; i++) scanf("%lld %lld", &v[i], &w[i]);
	vector<vector<ll>> dp(N + 1, vector<ll>(mx, INF));
	dp[0][0] = 0;
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < mx; j++) {
			chmin(dp[i + 1][j], dp[i][j]);
			if (dp[i][j] == INF) continue;
			if (j + v[i] >= mx) continue;
			chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
		}
	}

	for (ll i = mx - 1; i >= 0; i--) {
		if (dp[N][i] <= W) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 10792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
const int X=1000000007;
signed main(){
    int n;
    cin>>n;
    vector<int> a(n);
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    int init;
    if(0==n%2){
        init =1;
    }else{
        init=0;
    }
    bool flag=true;
    vector<int> memo(n,0);
    for(int i=0;i<n;i++) memo[a[i]]++;
    for(int i=0;i<n;i++){
        if(0==n%2){
            if((1==i%2&2!=memo[i])||(0==i%2&0!=memo[i])){
                flag=false;
                break;
            }
        }else{
            if(0==i){
                if(1==memo[i]) continue;
                else{
                    flag=false;
                    break; 
                }
            }else{
                if((1==i%2&0!=memo[i])||(0==i%2&2!=memo[i])){
                    flag=false;
                    break;
                }
            }
        }
    }
    if(flag){
        int ret=1;
        for(int i=0;i<n/2;i++){
            ret*=2;
            ret%=X;
        }
        cout<<ret<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
num = 0
index = 0
a_lst = []
for _ in range(N):
  a_lst.append(int(input()))
past_index = [0] * N
while True:
  num += 1
  index = a_lst[index]-1
  if index == 1:
    break
  elif past_index[index] == 1:
    num = -1
    break
  else:
    past_index[index] = 1
print(num)

Measured memory_bytes: 13756
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
 vector<int> vec(5);
  int k;
  for(int i=0;i<5;i++){
    cin >> vec.at(i);
  }
  
  cin >>k;
  bool ans=true;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
    if(vec.at(j)-vec.at(i)>k){
      ans=false;
      break;
    }
  }
  }
  if(ans){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}
       
  

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

int main(){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++){
        if (ch == '\\'){
            S1.push(i);
        }else if (ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            int a = i - j;
            sum += a;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3212
from collections import Counter
N,K,Q = map(int,input().split())

A = [int(input()) for _ in range(Q)]
c = dict(Counter(A))
for i in range(1,N+1):
    if i in c:
        t = Q - c[i]
        print('Yes' if t < K else 'No')
    else:
        print('Yes' if Q < K else 'No')

Measured memory_bytes: 13432
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};


int main() {
    int n;
    cin >> n;
    vector<bool> visited(n);
    vector<int> dis(n);
    deque<edge<int>> dq;
    dis[1] = 1;
    if(10%n != 1) dq.emplace_front(1, 10%n, 0);
    dq.emplace_back(1, 2%n, 1);
    while(!dq.empty()){
        auto e = dq.front(); dq.pop_front();
        if(visited[e.to]) continue;
        visited[e.to] = true;
        dis[e.to] = dis[e.from]+e.cost;
        if(!visited[(e.to+1)%n]){
            dq.emplace_back(e.to, (e.to+1)%n, 1);
        }
        if(!visited[(e.to*10)%n]){
            dq.emplace_front(e.to, (e.to*10)%n, 0);
        }
    }
    cout << dis[0] << "\n";
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){int h,w,c[10][10],a;cin >>h>>w;rep(i,10)rep(j,10)cin>>c[i][j];rep(k,10){rep(i,10){rep(j,10){c[i][j]=min(c[i][j],c[i][k]+c[k][j]);}}}int ans=0;rep(i,h){rep(j,w){cin>>a;if(a!=-1)ans+=c[a][1];}}cout << ans << endl;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if(a <= k){
        cout << "0 " << max((ll)0,a+b-k) << endl;
    }else{ cout << a-k << " " << b << endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int a[1 << 17];
//100000
const int MAX_N = (1 << 17);
int nn, dat[2 * MAX_N - 1];
void init(int n_) {
	nn = 1;
	while (nn < n_)nn *= 2;
}
void update(int k, int a) {
	k += nn - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = dat[k * 2 + 1]+ dat[k * 2 + 2];
	}
}
int query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return 0;
	if (a <= l && r <= b)return dat[k];
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return vl+vr;
	}
}
vector<int> v[1 << 17];
int main() {
	int n; cin >> n; init(n);
	rep(i, n) {
		cin >> a[i];
		update(i, 1);
		v[a[i]].push_back(i);
	}
	ll out = 0;
	rep1(i, 100000) {
		rep(j, v[i].size()) {
			update(v[i][j], 0);
		}
		rep(j, v[i].size()) {
			out += min(query(0, v[i][j], 0, 0, nn), query(v[i][j], n, 0, 0, nn));
		}
	}
	cout << out << endl;
	return 0;
}



Measured memory_bytes: 10452
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		int min = scan.nextInt();
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < n - 1; i++) {
			int r = scan.nextInt();
			ans = Math.max(ans, r - min);
			min = Math.min(min, r);
		}
		System.out.println(ans);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 68764
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<int> h(n + 2);
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    vector<int> dist(n + 2, INT_MAX);
    dist[1] = 0;
    for (int i = 1; i < n; i++)
    {
        dist[i + 1] = min(dist[i + 1], dist[i] + abs(h[i + 1] - h[i]));
        dist[i + 2] = min(dist[i + 2], dist[i] + abs(h[i + 2] - h[i]));
    }
    cout << dist[n];
    return 0;
}


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

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

  // a : 97
  int i = 0;
  string s = "";
  while (n > 0) {
    s.insert(s.begin(), (char)((n - 1) % 26 + 97));
    n = (n - 1) / 26;
  }

  cout << s << endl;

  return 0;
}

/*
*/


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

long mod = 1000000007;
long calcComb(int, int);
long modpow(long,int);

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

    int mno = m;
    long ans = 1;
    for(int i=2;i*i<=mno;i++)
    {
        if(mno % i == 0)
        {
            int cnt = 0;
            while(mno % i == 0)
            {
                cnt++;
                mno /= i;
            }

            ans *= calcComb(n+cnt-1, n-1);
            ans %= mod;
        }
    } 
    if(mno != 1)
    {
        ans *= calcComb(n,n-1);
        ans %= mod;
    }
    cout << ans;
}

long calcComb(int a, int b){
    if(b>a-b) return calcComb(a,a-b);
    long ansMul=1;
    long ansDiv=1;
    for(int i=0;i<b;i++){
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul%=mod;
        ansDiv%=mod;
    }

    long ans = ansMul * modpow(ansDiv, mod-2)%mod;

    return ans;
}



long modpow(long a, int p)
{
    if(p==0) return 1;
    if(p%2==0)
    {
        int halfp = p/2;
        long half = modpow(a, halfp);
        return half*half%mod;
    }
    else
    {
        return a * modpow(a,p-1) % mod;
    }
}

Measured memory_bytes: 256
<?php
list($n, $x) = explode(" ", fgets(STDIN));
$jump_length= explode(" ", fgets(STDIN));
$ans = 1;
$length = 0;
foreach($jump_length as $jump){
	$length += $jump;
	if($length<=$x){
		$ans+=1;
	}else{
		break;
	}
}
echo $ans . "\n";
?>

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;

int main(){

  int n, m, h, a, b;
  cin >> n >> m;
  unordered_map<int, int> u;
  vector<bool> good(n + 1, true);
  for(int i = 0 ; i < n; i++){
    cin >> h;
    u[i + 1] = h;
  }

  for(int i = 0 ; i < m; i++){
    cin >> a >> b;
    if(u[a] > u[b]){
      good[b] = false;
    }
    else if(u[a] < u[b]){
      good[a] = false;
    }
    else{
      good[a] = false;
      good[b] = false;
    }
  }



  int res = 0;
  for(int i = 1; i <= n; i++){
    if(good[i])res++;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 6704
#include <iostream>
using namespace std;
int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    if( A == B ){
        cout << C << endl;
    }else if( B == C ){
        cout << A << endl;
    }else if( C == A ){
        cout << B << endl;
    }
    
    return 0;
}


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

using namespace std;

void dfs_max_path(int node, vector<bool>& visited, const vector<vector<int>>& adj, vector<int>& in_degree, vector<int>&distances)
{
	stack<int> s;
	s.push(node);
	while(!s.empty()) {
		int curr = s.top();
		s.pop();
		visited[curr] = true;
		for(int neighbour: adj[curr]) {
			distances[neighbour] = max(distances[neighbour], distances[curr] + 1);
			in_degree[neighbour]--;
			if(!in_degree[neighbour])
				s.push(neighbour);
		}
	}
}

int solution(int nodes, const vector<vector<int>>& adj, vector<int>& in_degree)
{
	vector<bool> visited(nodes + 1);
	vector<int> distances(nodes + 1, 0);
	for(int i = 1; i <= nodes; i++)
		if(!visited[i] && !in_degree[i])
			dfs_max_path(i, visited, adj, in_degree, distances);
	return *max_element(distances.begin(), distances.end());
}

int main()
{
	int nodes, edges;
	cin >> nodes >> edges;
	vector<vector<int>> adj(nodes + 1);
	vector<int> in_degree(nodes + 1);
	int from, to;
	for (int i = 1; i <= edges; i++) {
		cin >> from >> to;
		adj[from].push_back(to);
		++in_degree[to];
	}
	cout << solution(nodes, adj, in_degree);
}


Measured memory_bytes: 6528
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let s=read::<String>().as_bytes().iter().map(|c|*c as char).collect::<Vec<char>>();
    let t=read::<String>().as_bytes().iter().rev().map(|c|*c as char).collect::<Vec<char>>();
    println!("{}",if s[0]==t[0]&&s[1]==t[1]&&s[2]==t[2]{"YES"}else{"NO"})
}

Measured memory_bytes: 4352