akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

bool judge(string s, string p)//s???p????????????????????????
{	
	int size_s = s.size();
	int size_p = p.size();
	
	for(int i = 0; i < size_s; i++){
		for(int j = 0; j < size_p; j++){
			if(s[i + j] != p[j]){
				break;
			}
			if(j + 1 == size_p){
				return true;
			}
		}
	}
	return false;
}
void print_answer(bool judge)
{
	if(judge == true){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}
int main(void)
{
	string s;
	string p;
	
	getline(cin, s);//??????????????????
	getline(cin, p);
	
	s = s + s;
	
	print_answer(judge(s, p));
	
	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
  	cin.tie(0);
  	
  	//good luck, kittu
  	int n, m, q; cin>>n>>m;
  	ll adj[n][n], adjx[n][n];
  	for(int i = 0; i<n; i++){
      	for(int j = 0; j<n; j++) adj[i][j] = 1000000000000;
    }
  
  	ll l, a, b, c; cin>>l;
  	for(int i = 0; i<m; i++){
      	cin>>a>>b>>c;
      	a--; b--;
      	adj[a][b] = c;
      	adj[b][a] = c;
    }
    
  	for(int k = 0; k<n; k++){
      	for(int i = 0; i<n; i++){
          	for(int j = 0; j<n; j++) adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
        }
    }
  
  	for(int i = 0; i<n; i++){
     	for(int j = 0; j<n; j++) adjx[i][j] = (adj[i][j]<=l?(1):(1000000000000));
    }
  	
  	for(int k = 0; k<n; k++){
      	for(int i = 0; i<n; i++){
          	for(int j = 0; j<n; j++) adjx[i][j] = min(adjx[i][j], adjx[i][k]+adjx[k][j]);
        }
    }
  
  	cin>>q;
  	while(q--){
      	cin>>a>>b;
      	a--; b--;
      	if(adjx[a][b]==1000000000000) cout<<"-1\n";
      	else cout<<adjx[a][b]-1<<"\n";
    }
 	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cmath>

typedef long long ll;

using std::cin;
using std::cout;
using std::endl;

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

    ll ans = (ll)(1e18);
    for(int n = (int)(sqrt(num)); n >= 1; -- n) {
        if(num % n == 0)
            ans = std::min(ans, (n-1)+(num/n-1));
    }

    cout << ans << endl;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int o[20][10010];

void solve(int r, int c) {
    REP(i, r) {
        REP(j, c) { cin >> o[i][j]; }
    }

    int ans = 0;

    REP(ss, 1 << r) {
        int sum = 0;
        REP(i, c) {
            int tmp = 0;
            REP(j, r) {
                if ((ss >> j) & 1) {
                    if (o[j][i] == 0) {
                        tmp += 1;
                    }
                } else {
                    if (o[j][i] == 1) {
                        tmp += 1;
                    }
                }
            }
            sum += max(tmp, r - tmp);
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
}

int main() {
    int r, c;
    while (cin >> r >> c && r) {
        solve(r, c);
    }
    return 0;
}


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

public class Main {
    Long[] memo;
    final long MOD = (long) (1e9 +7); 
    
    long compute(int n) {
        if(n == 0) {
            return 1;
        }
        if(memo[n] != null) {
            return memo[n];
        }
        long ans = 0;
        for(int i = 3; i <= n; ++i) {
            ans += compute(n - i);
            ans %= MOD;
        }
        return memo[n] = ans;
    }
    
    void solve(Scanner in, PrintWriter out) {
        int s = in.nextInt();
        memo = new Long[s + 1];     
        out.println(compute(s));
    }

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


Measured memory_bytes: 36796
(defun digit-sum(x)
           (let ((x-str (format nil "~a" x)))
             (reduce #'+
                     (map 'vector (lambda (xxx)
                       (- (char-code xxx) (char-code #\0))) x-str))))
(format t "~a~%" (if (= (rem (digit-sum (read)) 9) 0) "Yes" "No"))

Measured memory_bytes: 113432
#include <bits/stdc++.h>
#define forn(x, n) for (int x = 0; x < n; x++)
#define forr(x, n) for (int x = n; x >= 0; x--)
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container) (container).begin(), (container).end()
#define rall(container) (container).rbegin(), (container).rend()
#define FILL(x, val) memset(x, val, sizeof(x))
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

using namespace std;

typedef long long i64; 
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

int main(void) {
  int n;
  scanf("%d", &n);
  printf("%d\n", (n*(n+1))/2);
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String inputStr = sc.nextLine();
		String[] inputStrArray = inputStr.split(" ");
		int A = Integer.parseInt(inputStrArray[0]);
		int B = Integer.parseInt(inputStrArray[1]);
		int sum = A + B;
		int dif = A - B;
		int multi = A * B;
		int ans;
		if(sum>dif){
			if(sum>multi){
				ans = sum;
			}else{
				ans = multi;
			}
		}else{
			if(dif>multi){
				ans = dif;
			}else{
				ans = multi;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			if(i*j==n)
			{
				printf("Yes");
				return 0;
			}
	printf("No");
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll x;
  cin >> x;

  ll l = x/105;
  ll r = x/100;
  FOR(i,l,r+1){
    if(i*100 <= x && x <= i*105){
      cout << 1 << endl;
      return 0;
    }
  }
  
  //cout << fixed << setprecision(10);
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define in cin >>
#define out cout <<
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()

 int main(){
     int n,l;
     cin >> n >> l;
    vector<string> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    sort(v);
    string ans;
    for(int i=0;i<n;i++){
        ans = ans + v[i];
    }
    cout << ans;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,a[101010],has;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			has++;
			a[i]=-1;
		}
	}
	cout<<has<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 500000
#define Keeper 1000000001

int count;

void MergeSort(int *,int,int);
void Merge(int *,int,int,int);

int main(){
  int loop;
  int i;
  int Retu[N];
  
  scanf(" %d",&loop);
  for(i=0;i<loop;i++){
    scanf(" %d",&Retu[i]);
  }

  MergeSort(Retu,0,loop);

  for(i=0;i<loop-1;i++){
    printf("%d ",Retu[i]);
  }
  
  printf("%d\n%d\n",Retu[loop-1],count);
  
  return 0;
}

void MergeSort(int *X,int lside,int rside){
  int center;
  
  if(lside+1<rside){
    center=(lside+rside)/2;
    MergeSort(X,lside,center);
    MergeSort(X,center,rside);
    Merge(X,lside,center,rside);
  }
}

void Merge(int *X,int lside,int center,int rside){
  int i,j,k;
  int Lreng,Rreng;
  int Left[N/2+3],Right[N/2+3];

  Lreng=center-lside;
  Rreng=rside-center;
  
  for(i=0;i<Lreng;i++){
    Left[i]=X[lside+i];
  }
  
  for(i=0;i<Rreng;i++){
    Right[i]=X[center+i];
  }

  Left[Lreng]=Keeper;
  Right[Rreng]=Keeper;

  i=0;
  j=0;

  for(k=lside;k<rside;k++){
    if(Left[i]<=Right[j]){
      X[k]=Left[i];
      i++;
      count++;
    }
    else{
      X[k]=Right[j];
      j++;
      count++;
    }
  }
 
}



Measured memory_bytes: 5628
#include <iostream>
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;

int main() {
  int n,x;
  char a[20];

  list<int> v;
  cin>>n;
  for (int i=0;i<n;i++){
    scanf("%s", a);
    if(a[0]=='i'){
      cin>>x;
      v.push_front(x);
    }else if(a[6]=='L'){
      v.pop_back();
    }else if(a[6]=='F'){
      v.pop_front();
    }else if(a[0]=='d'){
      cin>>x;
      for(list<int>::iterator it=v.begin();it!=v.end();it++) {
	if(*it==x){
	  v.erase(it);
	  break;
	}
      }
    }
  }
  int i=0;
  for(list<int>::iterator it=v.begin();it!=v.end();it++){
    if(i++) cout<<' ';
    cout<<*it;
  }
  cout<<'\n';

  return 0;

}



Measured memory_bytes: 34380
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split();
            int n = int.Parse(array[0]);
            long k = long.Parse(array[1]) - 1;

            var blocks = (from _ in Enumerable.Repeat(0, n)
                          let cols = Console.ReadLine().Split().Select(int.Parse).ToArray()
                          let block = new { Value = cols[0], Count = cols[1] }
                          orderby block.Value
                          select block).ToArray();

            long current = 0;
            foreach (var block in blocks)
            {
                if (current <= k && k < current + block.Count)
                {
                    Console.WriteLine(block.Value);
                    break;
                }

                current += block.Count;
            }
        }
    }
}

Measured memory_bytes: 34140
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main() {
    int n;
    VE x;
    VE y;
    cin >> n;
    int X;
    REP(i, n){
        cin >> X;
        x.push_back(X);
        y.push_back(X);
    }
    sort(x.begin(), x.end());
    int small, big;
    small = x[n / 2 - 1];
    big = x[n / 2];

//    print(small << " " << big);
    REP(i, n){
//        print(i << " " <<  y[i]);
        if(y[i] <= small){
            print(big);
        }else{
            print(small);
        }
    }
    return 0;
}

Measured memory_bytes: 3948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int a[] = new int[n];

		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		System.out.print(a[n-1]);
		for(n = n - 2; n >= 0; n--){
			System.out.print(" " + a[n]);
		}
		System.out.println();

	}

}



Measured memory_bytes: 26256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N = int(readline())
    abc = map(int, read().split())
    x, y, z = 0, 0, 0
    for a, b, c in zip(abc, abc, abc):
        x, y, z = max(y, z) + a, max(x, z) + b, max(x, y) + c

    print(max(x, y, z))


if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;

int main() {
  int d,n;
  cin>>d>>n;
  int ans;
  if (d == 0) {
    ans = n;
    if (n == 100) ans++;
  } else if (d == 1) {
    ans = 100 * n;
    if (n == 100) ans += 100; 
  } else {
    ans = 10000 * n;
    if (n == 100) ans += 10000;
  }                      
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
const int maxn = 210000;

int n,m;
int b[maxn],s[maxn],f[maxn];
vector<int>V[maxn];

int segf[maxn<<2],segd[maxn<<2];
void pushup(int seg[],const int x){ seg[x]=seg[x<<1]>seg[x<<1|1]?seg[x<<1]:seg[x<<1|1]; }
void build(const int x,const int l,const int r)
{
	if(l==r) { segd[x]=l>=0?-inf:0; return; }
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	build(lc,l,mid); build(rc,mid+1,r);
	pushup(segd,x);
}
int lx,rx,loc,c;
void upd(int seg[],const int x,const int l,const int r)
{
	if(l==r) { seg[x]=c; return; }
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	if(loc<=mid) upd(seg,lc,l,mid);
	else upd(seg,rc,mid+1,r);
	pushup(seg,x);
}
int query(int seg[],const int x,const int l,const int r)
{
	if(rx<l||r<lx) return -inf;
	if(lx<=l&&r<=rx) return seg[x];
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	return max(query(seg,lc,l,mid),query(seg,rc,mid+1,r));
}
int re;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]),re+=!b[i];
	for(int i=1;i<=n;i++) s[i]=s[i-1]+(b[i]?1:-1);
	build(1,0,n);
	for(int i=1;i<=n;i++) f[i]=-inf;
	
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		int l,r; scanf("%d%d",&l,&r);
		V[l].push_back(r);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<V[i].size();j++)
		{
			int r=V[i][j];
			lx=0,rx=i-1; int cc=query(segf,1,0,n);
			up(f[r],cc+s[r]-s[i-1]);
			
			lx=i-1,rx=r-1; cc=query(segd,1,0,n);
			up(f[r],cc+s[r]);
			
			loc=r,c=f[r];
			upd(segf,1,0,n);
			c=f[r]-s[r]; upd(segd,1,0,n);
		}
	}
	int ans=0;for(int i=1;i<=n;i++) up(ans,f[i]);
	printf("%d\n",n-(re+ans));
	
	return 0;
}


Measured memory_bytes: 18048
from sys import exit, stdin
S = list(stdin.readline().rstrip())
ci, cf = 0, 0
if 'C' in S and 'F' in S:
    for i, c in enumerate(S):
        if c == 'C':
            ci = i
        elif c == 'F':
            cf = i
    if ci < cf:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    
    println!("{}", a .iter().fold(0, |acc, &x| acc + x - 1));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    char s[3];
    int i=0,count=0;
   cin>>s;
   for(int i=0;i<3;i++)
   {
       if(s[i]=='R')
       count++;
   }
   if(s[0]=='R'&&s[1]=='S'&&s[2]=='R')
   cout<<"1"<<endl;
   else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S')
   cout<<"0"<<endl;
   else
   cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N,M,ans=0;
    cin>>N>>M;
    vector<int> A(M,0);
    for(int i=0;i<N;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int tmp;
            cin >> tmp;
            A[--tmp]++;
        }
    }
    sort(A.begin(),A.end());
    for(int i=0;i<M;i++){
        if(A[i]==N){
            ans++;           
        }
    }
    cout<<ans;
    return 0;

}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Thu Apr 02 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int A = in.nextInt();
        int P = in.nextInt();
        println((3*A + P)/2);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= N; i ++){
        int x = (i * 8) / 100;
        int y = (i * 10) / 100;
        if((x == a && y == b) || (x == b && y == a)){
            cout << i << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}


Measured memory_bytes: 256
//#include <algorithm>
//#include <cassert>
//#include <cfloat>
//#include <cmath>
//#include <cstdio>
//#include <cstdlib>
//#include <deque>
#include <iostream>
//#include <limits>
//#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>
//#include <vector>
using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int a[100000];

long getTotal(int n, int dir) {
  long total{0}, sum{0};
  for (int i{0}; i < n; ++i) {
    sum += a[i];
    if (dir > 0 && sum <= 0) {
      total += -sum + 1;
      sum = 1;
    } else if (dir < 0 && sum >= 0) {
      total += sum + 1;
      sum = -1;
    }
    dir *= -1;
  }
  return total;
}

int main() {
  int n; scanf("%d", &n);
  for (int i{0}; i < n; ++i) scanf("%d", &a[i]);

  long try1 = getTotal(n, 1);
  long try2 = getTotal(n, -1);

  printf("%ld\n", MIN(try1, try2));
  return 0;
}


Measured memory_bytes: 888
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        HashMap<Integer,Integer> num=new HashMap<>();
        Scanner sc=new Scanner(System.in);
        int loop=sc.nextInt();
        for(int i=1;i<loop;i++){
            int a=sc.nextInt();
            if(num.containsKey(a)){
                num.put(a,num.get(a)+1);
            }
            else{
                num.put(a,1);
            }
        }
        for (int i=1;i<=loop;i++){
            if(num.containsKey(i)){
                System.out.println(num.get(i));
            }
            else {
                System.out.println(0);
            }
        }
    }
}


Measured memory_bytes: 73572
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define eb emplace_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
#define inf 1000000000000000000
#define MOD 1000000007
using namespace std;
void solve(){
	ll n;
	cin>>n;
	double prob[n+1],dp[n+1][n+1]={0};
	dp[0][0]=1;
	for (int i = 1; i <=n; ++i)
	{
		cin>>prob[i];
	}
	dp[0][0]=1;
	for (int i = 1; i <=n; ++i)
	{
		for (int j = 0; j<=i; ++j)
		{
			if(j!=0)
				dp[i][j]=prob[i]*dp[i-1][j-1];
			else dp[i][j]=0;
			dp[i][j]+=(1.0-prob[i])*dp[i-1][j];
		}
	}
	double ans=0;
	for (int i = n/2+1; i <=n; ++i)
	{
	//	cout<<i<<" "<<dp[n][i]<<endl;
		ans+=dp[n][i];
	}
	printf("%.10f",ans);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 70528
/*author ADITYA BANSAL
         MNNIT ALLAHABAD     */
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long
ll power(ll,ll);
ll mul(ll a,ll b);
#define watch(x) cerr<<(#x)<<"is"<<x<<nl;
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi(a,b) for(ll i=a; i<b; i++)
#define fk(a,b) for(ll k=a; k<b; k++)
#define fri(a,b) for(ll i=a; i>b; i--)
#define fj(a,b) for(ll j=a; j<b; j++)
#define ffi(a,b) for(ll i=a;i*i<=b;i++)
#define mp make_pair
#define ff first 
#define  tc ll t; cin>>t; while(t--)
#define all(v) (v).begin(),(v).end()
#define ss second
#define pb push_back
#define mem(v) memset((v),0,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define pob pop_back
#define nl endl
const ll  N=1000002LL;

signed main(){ fast
  //tc
 { ll n;
 cin>>n;
 ll a[n];
 fi(0,n) cin>>a[i];
 
 //~ mem(b)
 ll b=0; 
 fi(0,n) if(a[i]!=(i+1)) b++;
 if(b>2 || b%2) cout<<"NO\n";
else cout<<"YES";  
 }
    return 0;
}


/******************************************************************************/

ll mul(ll a,ll b){
    return ((a)*1LL*(b))%mod;
}

/*--------------------<<BINARY EXPONENTIATION>>--------------------*/
ll power(ll a,ll n){
  ll res=1;
  while(n){
      if(n&1) res= mul(res,a);
     n>>=1; 
     a= mul(a,a);
  }
    return res;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n),b(n);
  for (int i=0; i<n; i++) cin>>a[i];
  b=a;
  sort(b.begin(), b.end());
  int max_a=b[n-1];
  int next_a=b[n-2];
  for (int j=0; j<n; j++){
    if (a[j]!=max_a) cout<<max_a<<endl;
    else cout<<next_a<<endl;
  }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define eps (1e-10)
#define xx first
#define yy second
#define ln 17
#define off 2

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

#define log 20
#define mod 998244353LL
#define maxn 200005
#define INF 1000000000

int en[maxn] ;
int a[maxn] , b[maxn] ;

void Do( int n )
{
    memset(en,0,sizeof(en)) ;
    memset(b,0,sizeof(b)) ;

    int cur = 0 ;

    for(int i=1 ; i<=n ; i++)
    {
        b[i] += cur ;
        cur += 1 ;
        if( i+a[i] <= n ) en[ i+a[i] ]++ ;
        cur -= en[i] ;
    }
    memset(en,0,sizeof(en)) ;

    cur = 0 ;
    for(int i=n ; i>=1 ; i--)
    {
        b[i] += cur ;
        cur += 1 ;
        if( i-a[i] >=1  ) en[ i-a[i] ]++ ;
        cur -= en[i] ;
    }
    for(int i=1 ; i<=n ; i++) a[i] = b[i] + 1 ;
}

int main()
{
    int n , k ;

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

    for(int i=1  ; i<=n ; i++) scanf("%d",&a[i] ) ;

    for(int i=1; i<=min(k,200) ; i++) Do(n) ;

    for(int i=1 ; i<=n ; i++) printf("%d ",a[i]) ;
    printf("\n") ;

    return 0 ;
}


Measured memory_bytes: 6204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 100002;
string s;
string ans[16];

int main(){
	string s;
	cin>>s;
	ans[0]="KIHBR";
	ans[1]="AKIHBR";
	ans[2]="KIHABR";
	ans[3]="KIHBAR";
	ans[4]="KIHBRA";
	ans[5]="AKIHABR";
	ans[6]="AKIHBAR";
	ans[7]="AKIHBRA";
	ans[8]="KIHABAR";
	ans[9]="KIHABRA";
	ans[10]="KIHBARA";
	ans[11]="AKIHABAR";
	ans[12]="AKIHABRA";
	ans[13]="AKIHBARA";
	ans[14]="KIHABARA";
	ans[15]="AKIHABARA";
	bool ok=false;
	FOR(i,0,16){
		if(s==ans[i])ok=true;
	}
	if(ok){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2, ceil

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    a, b = intin()
    bits = {}

    if not b:
        print(0)
        return 0

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 1e6 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-5 ;

ll n, ans;

ll p[maxn], a[maxn];

ll fa[maxn], c[maxn][2];

struct vertex
{
	ll pos, c[2];
	vertex(){pos = c[0] = c[1] = 0;}
	friend bool operator < (vertex a, vertex b)
	{
		if(a.pos == 1) return 0;
		if(b.pos == 1) return 1;
		return a.c[0] * b.c[1] == b.c[0] * a.c[1] ? a.pos < b.pos : a.c[0] * b.c[1] > b.c[0] * a.c[1];
	}
};

set <vertex> s;

void init()
{
	rep(i, 1, n)
	{
		fa[i] = i, c[i][a[i]] ++;
		vertex tmp;
		tmp.pos = i, tmp.c[a[i]] ++;
		s.insert(tmp);
	}
}

ll getfa(ll a)
{
	return a == fa[a] ? a : fa[a] = getfa(fa[a]);
}

signed main()
{
	scanf("%lld", &n);
	rep(i, 2, n) scanf("%lld", &p[i]);
	rep(i, 1, n) scanf("%lld", &a[i]);
	init();
	while(s.size() != 1)
	{
		vertex now = *(s.begin());
		vertex pnow;
		pnow.pos = getfa(p[now.pos]);
		fa[now.pos] = pnow.pos;
		pnow.c[0] = c[pnow.pos][0], pnow.c[1] = c[pnow.pos][1];
		s.erase(s.find(now)), s.erase(s.find(pnow));
		ans += c[pnow.pos][1] * c[now.pos][0];
		c[pnow.pos][1] += c[now.pos][1], c[pnow.pos][0] += c[now.pos][0];
		pnow.c[0] = c[pnow.pos][0], pnow.c[1] = c[pnow.pos][1];
		s.insert(pnow);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 29184
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int a, b;
	std::cin >> a >> b;
	if (a > b)
		std::swap(a, b);
	for (int i = 0; i < b; ++i)
		std::cout << a;
	std::cout << "\n";
}


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

int main()
{
	int64_t n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	sort(as.begin(), as.end());

	int64_t ok = n - p, ng = -1;

	while (1 < abs(ok - ng))
	{
		int64_t mid = (ok + ng) / 2;

		int64_t u = v - min(v, mid + p);
		int64_t sz = n - (mid + 1) - (p - 1);
		int64_t l = mid + 1, r = l + sz;

		bool f = true;

		int64_t e = 0;
		for (int64_t i = l; i < r; i++)
		{
			if ((as[mid] + m) < as[i])
			{
				f = false;
				break;
			}
			e += min(m, (as[mid] + m) - as[i]);
		}

		((f && 0 <= e - u * m) ? ok : ng) = mid;
	}

	cout << n - ok << endl;

	return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    string st;

    cin >> st;

    stack<char>s;


    for(int i=0; i<st.length();i++)
    {
        if(st[i]=='0' || st[i]=='1')
        {
            s.push(st[i]);
        }
        else if(st[i]=='B')
        {
            if(s.empty())
            {
                continue;
            }
            else
            {
                s.pop();
            }
        }
    }


    vector<char>v;



    while(!s.empty())
    {
        char a = s.top();
        v.pb(a);

        s.pop();
    }

    for(int i=v.size()-1; i>=0; i--)
    {
        cout << v[i];
    }





    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();

	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long a = sc.nextLong();
			long b = sc.nextLong();
			System.out.println(getLCM(a, b) + " " + getGCD(a, b));
		}
//		System.out.println(getGCD(8, 6));;
//		System.out.println(getGCD(50000000, 30000000));;
//		System.out.println(getGCD(3, 1));;
	}
	
	//a >= b
	public static long getGCD(long a, long b){
		long ta = a, tb = b;
		while(true){
			if(ta == tb){
				break;
			}
			while(ta > tb){
				tb += b;
			}
			while(tb > ta){
				ta += a;
			}
			//System.out.println("ta = " + ta + ", tb = " + tb);
			
		}
		
		return ta;
	}
	
	//a >= b
	public static long getLCM(long a, long b){
		long p, q, r;
		p = a;
		q = b;
		r = b;
		long tmp;
		do{
			tmp = r;
			r = p % q;
			p = q;
			q = r;
			
		}while(r != 0);
		
		return tmp;
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(void){
  map<int,int> point2rank;
  map<int,int> team2point;
  vector<int> points;
  int p,s;
  while(1){
    scanf("%d,%d",&p,&s);
    if(p==0 && s==0)break;
    points.push_back(s);
    team2point[p]=s;
  }
  sort(points.begin(),points.end());
  points.erase(unique(points.begin(),points.end()),points.end());
  for(int i=0;i<points.size();i++){
    point2rank[points[i]]=points.size()-i;
  }
  int q;
  while(cin>>q){
    cout<<point2rank[team2point[q]]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3248
N = int(input())
S = input()


if len(S) % 2 != 0:
    print('No')
    exit()

right = S[:len(S)//2]
left = S[(len(S)//2):]

ans = 'Yes'
for i, rc in enumerate(right):
    if left[i] != rc:
        ans = 'No'

print(ans)


Measured memory_bytes: 38384
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def is_palindrome(s):
  n=len(s);b=True
  for i in range(int(0.5*n)):
    if s[i]!=s[n-i-1]:b=False
  return b

def main():
  s,t=input().split()
  print(t+s)

if __name__ == '__main__':
    main()

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

int n,d,T,a[505000],b[505000],c[505000];

int main(){
  ios::sync_with_stdio(0);
  cin>>n>>b[0];
  for (int i=1;i<=n;++i) cin>>a[i], b[i]=min(abs(b[i-1]-a[i]),b[i-1]);
  c[n+1]=0;
  for (int i=n;i;--i){
    c[i]= c[i+1]>=a[i]/2? min(c[i+1]+a[i],b[0]): c[i+1];
  }
  for (cin>>T;T--;){
    cin>>d;
    puts(c[d+1]>=b[d-1]? "NO": "YES");
  }
}


Measured memory_bytes: 7808
S = int(input())
mod = int(1e9) + 7 # <-- input modulo
maxf = 2010           # <-- input factional limitation

def make_fact(n, k):
    tmp = n
    perm = [i for i in range(k)]
    L = [0 for _ in range(k)]
    for i in range(k):
        L[i] = tmp % (i + 1)
        tmp //= i + 1
    LL = [0 for _ in range(k)]
    for i in range(k):
        LL[i] = perm[L[-i-1]]
        for j in range(L[-i-1]+1, k):
            perm[j-1] = perm[j]
    return LL

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
X = 0
for i in range(1, S//3+1):
  X += fact[S-2*i-1] * invf[i-1] * invf[S-3*i] % mod
  X %= mod
print(X)

Measured memory_bytes: 9292
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) (a>0?a:(-(a)))
#define maxn 100050
using namespace std;
int a[maxn],lg[maxn];
int l[maxn][20],r[maxn][20];
int main(){
	int n;
	scanf("%d",&n);
	lg[0]=-1;
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]),lg[i]=lg[i>>1]+1;
	a[0]=a[n+1]=n+1;
	for (int i=0;i<=n+1;i++)
	l[i][0]=r[i][0]=a[i];
	for (int j=1;j<=lg[n];j++){
		for (int i=0;i<=n+1;i++)
		if (i+(1ll<<(j-1))<=n+1) r[i][j]=max(r[i][j-1],r[i+(1ll<<(j-1))][j-1]);else
			r[i][j]=r[i][j-1];
		for (int i=n+1;i>=0;i--)
		if (i-(1ll<<(j-1))>=0) l[i][j]=max(l[i][j-1],l[i-(1ll<<(j-1))][j-1]);else
			l[i][j]=l[i][j-1];
	}
	ll ans=0;
	for (int i=1;i<=n;i++){
		int L=i-1,R=i+1;
		for (int j=lg[n];j>=0;j--){
			if (L-(1ll<<j)>=0&&l[L][j]<a[i]) L=L-(1ll<<j);
			if (R+(1ll<<j)<=n+1&&r[R][j]<a[i]) R=R+(1ll<<j);
		}
		int mxl=L,mxr=R;
		L--,R++;
		for (int j=lg[n];j>=0;j--){
			if (L-(1ll<<j)>=0&&l[L][j]<a[i]) L=L-(1ll<<j);
			if (R+(1ll<<j)<=n+1&&r[R][j]<a[i]) R=R+(1ll<<j);
		}
		//printf("%d %d %d %d\n",mxl,mxr,L,R);
		if (mxr<=n) ans+=1ll*a[i]*(i-mxl)*(R-mxr);
		if (mxl>0) ans+=1ll*a[i]*(mxr-i)*(mxl-L);
		//printf("i=%d %lld\n",i,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16512
fn main() {
    let h = read();
    let ans = solve(h);
    write(ans);
}
 
fn read() -> u64 {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let h = l1.trim().parse::<u64>().unwrap();

    h
}
 
fn write(ans: u64) {
    println!("{}", ans);
}
 
fn solve(h: u64) -> u64 {
    if h <= 0 {return 0;};

    let mut c = 0u64;
    let mut k = 1;
    let mut h = h;
    while h > 0 {
        h /= 2;
        c += k;
        k *= 2
    }    

    c

}

Measured memory_bytes: 2080
#!python3

from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(26)]
    S = [[next(it) for i in range(26)] for i in range(D)]
    L = [[-1]] * 26
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    score = 0
    for i in range(D):
        score += S[i][0]
    L[0] = [i for i in range(-1, D)]

    x = (1+D)*D//2
    for i in range(1, 26):
        score -= C[i] * x

    for di in range(D):
        for qi in range(26):
            diff, swap = update(di, qi)
            if diff > 0:
                score += diff
                q0, T[di] = T[di], qi
                L[q0], L[qi] = swap

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, 26)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()


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

int main() {
    // 入力
    int N, W;
    cin >> N >> W;
    vector<ll>w(N);
    vector<ll>v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    ll INF = 10000000000000;
    // i+1番目以降で価値j以上の時の重さの最小値がdp[i][j]
    // 価値の総和の最大値はN*10^3
    vector<vector<ll>> dp(N+1, vector<ll>(N*1000 + 1, INF));

    for (int i = N-1; i >= 0; --i) {
        dp[i][0] = 0;
        for (int j = 1; j <= N*1000; ++j){
            if(j <= v[i]){
                // DP[][j-v[i]]が0になるので
                dp[i][j] = min(dp[i+1][j], w[i]);
            }else{
                dp[i][j] = min(dp[i+1][j], dp[i+1][j - v[i]] + w[i]);
            }
        }
    }

    // 二部探索、容量Wで価値vが可能ならば(dp[0][v] <= W) == true、vの最大値lbを求める
    // lb == 0の時は価値0なのでそのままでいい
    int lb=0, ub = N*1000 + 1;
    while( ub-lb > 1 ){
        int mid = (lb + ub) / 2;
        if (dp[0][mid] <= W) {
            lb = mid;
        } else {
            ub = mid;
        }
    }

    cout << lb;
    return 0;
}

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

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

int main(){
  int x,a; cin >> x >> a;
  if(x<a){
    cout << 0 << endl;
  }else{
	cout << 10 << endl;
  }
  return 0;
}

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

int main()
{
    int x,a,b;
    while (scanf("%d%d%d",&x,&a,&b)!=EOF)
    {
        if (b-a>x)
            printf("dangerous\n");
        else if (b-a<=0)
            printf("delicious\n");
        else
            printf("safe\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
 
int main ()
{
  long long int a,b,c,t;
  cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0){
  cout<<'0'<<endl;
  }
  else{
  t = min(min(a*b,b*c),c*a);
    cout<<t<<endl;
  }
  
    
	return 0;
 
}

Measured memory_bytes: 256
n = int(input())
blist = list(map(int, input().split()))

total = 0
for i in range(n):
    if i == 0:
        total += blist[i]
    elif i == n-1:
        total += blist[i-1]
    else:
        total += min(blist[i], blist[i-1])
print(total)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> jewel(n);
    rep(i,n)cin >> jewel[i];
    rep(i,n){
        ll temp;cin >> temp;
        jewel[i] -= temp;
    }
    ll res = 0;
    rep(i,n)if(jewel[i] > 0)res += jewel[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
DP= [[0 for j in range(W+1)] for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)
for i in range(1,N+1):
  v[i],w[i]=map(int,input().split())

for i in range(1,N+1):
  for j in range(1,W+1):
    if j-w[i]<0:
      DP[i][j]=DP[i-1][j]
    else:
      if v[i]+DP[i-1][j-w[i]]>DP[i-1][j]:
        DP[i][j]=v[i]+DP[i-1][j-w[i]]
      else:
        DP[i][j]=DP[i-1][j]
print(DP[N][W])


Measured memory_bytes: 25940
// B - Count Balls
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = 0, r;
    ans = n/(a+b)*a;
    r = n%(a+b);
    ans += min(r, a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int a[3];
    rep(i, 3){
      cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[2]-a[0]<<endl;

    return 0;
}


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

int main() {

	int A=0, W=0, T=0, R=0;
	long N;
	cin >> N;

	vector<string> S(N);

	for (int i = 0; i < N; i++) {
				cin >> S[i];
	}

	for (int i = 0; i < N; i++) {
		if (S[i] == "AC") {
			A += 1;
		}
		if (S[i] == "WA") {
			W += 1;
		}
		if (S[i] == "TLE") {
			T += 1;
		}
		if (S[i] == "RE") {
			R += 1;
		}
	}
	

	cout << "AC x "<< A << endl;
	cout << "WA x " << W << endl;
	cout << "TLE x " << T << endl;
	cout << "RE x " << R << endl;

}

Measured memory_bytes: 6432