akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "7", "3 6", "1 2", "3 1", "7 4", "5 7", "1 4" ].parse.expand.solve == "Fennec" );
	assert( [ "4", "1 4", "4 2", "2 3" ].parse.expand.solve == "Snuke" );
	
	assert( [ "4", "1 2", "2 3", "3 4" ].parse.expand.solve == "Snuke" );		// 追加ケース
}



import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto abs = new long[ 2 ][ n - 1 ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	return tuple( n, abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	const F = 1L;
	const S = -1L;
	
	auto cs = new long[ n ];
	cs[ 0     ] = F;
	cs[ $ - 1 ] = S;
	
	auto nss = new long[][ n ];
	foreach( ab; abs )
	{
		nss[ ab[ 0 ] ] ~= ab[ 1 ];
		nss[ ab[ 1 ] ] ~= ab[ 0 ];
	}
	
	// お互い最善手で塗った結果を計算
	auto fq = make!DList( 0L,    -1L );
	auto sq = make!DList( n - 1, -1L );
	while( !fq.empty || !sq.empty )
	{
		// フェネックのターン
		solve2( cs, fq, nss, F );
		
		// すぬけくんのターン
		solve2( cs, sq, nss, S );
	}
	
	// 塗ったマス目 = 自分のターン数 なので、マス目の多いほうが勝ち（同数だったら後手の勝ち）
	auto fc = 0L;
	auto sc = 0L;
	foreach( c; cs )
	{
		fc += ( c == F );
		sc += ( c == S );
	}
	return ( fc <= sc ) ? "Snuke" : "Fennec";
}

void solve2( ref long[] cs, ref DList!( long ) queue, long[][] nss, long c )
{
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		if( f == -1 )
		{
			if( !queue.empty ) queue.insertBack( -1 );
			break;
		}
		
		foreach( t; nss[ f ] )
		{
			if( cs[ t ] != 0 ) continue;
			cs[ t ] = c;
			queue.insertBack( t );
		}
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
    int k; cin>>k;
     string s; cin>>s;

    if(s.size()<=k) cout<<s;
    else
    {
        for(int i=0;i<k;++i) cout<<s[i];
        cout<<"...";
    }
}

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


Never_give_up();


 return 0;
}




Measured memory_bytes: 3644
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		String[] arr = new String[N];
		int[] cnt = new int[N];
		cnt[0]=1;
		for (int i = 0; i < N; i++) {
			arr[i] = input.next();
		}
		Arrays.sort(arr);
		for (int i = 1; i < arr.length; i++) {
			cnt[i] = cnt[i-1]+1;
			for (int j = i-1; j >= 0; j--) {
				if (arr[i].equals(arr[j])) {
					cnt[i]--;
					break;
				}else break;
			} 
		}
		System.out.println(cnt[N-1]);
	}
}

Measured memory_bytes: 62660
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, ans = 0, h, w, cnt[2];
  scanf("%lld%lld", &w, &h);
  cnt[0] = w, cnt[1] = h;
  pair<ll, ll> p[w + h];
  for(i = 0; i < w; ++i) scanf("%lld", &p[i].first), p[i].second = 0, ans += p[i].first * (h + 1);
  for(i = w; i < w + h; ++i) scanf("%lld", &p[i].first), p[i].second = 1, ans += p[i].first * (w + 1);
  sort(p, p + w + h, greater< pair<ll, ll> >());
  for(i = 0; i < w + h; ++i) {
    ans -= cnt[(p[i].second + 1) % 2] * p[i].first;
    cnt[p[i].second]--;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 3328
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
// #define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double

/*-------------------------------------------------------------------------------------------------------------------------------------*/

int dp[6005][12005];
int n,MOD;
int rec(int ind,int balance)
{
	if(ind==0)
	{
		return (balance>=0 && balance%3==0);
	}
	int &ans=dp[ind][balance+3*n];
	if(ans>=0)return ans;
	ans=rec(ind-1,balance+1);
	if(ind>1)
		ans+=(ind-1)*rec(ind-2,balance-1);
	if(ind>2)
		ans+=(ind-1)*(ind-2)*rec(ind-3,balance);
	ans%=MOD;
	return ans;
}
int32_t main()
{
	fastio();
	cin>>n>>MOD;
	MEMS(dp,-1);
	cout<<rec(3*n,0)<<endl;
}


Measured memory_bytes: 563840
n = int(input())
a = list(map(int, input().split()))
o = 0
t = 0
f = 0
for i in range(n):
    if a[i]%4 == 0:
        f += 1
    elif a[i]%2 == 0:
        t += 1
    else:
        o += 1
if t == 0:
    if f+1 >= o:
        print("Yes")
    else:
        print("No")
else:
    if f >= o:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    double n,k;
    double ans=0;
    cin>>n>>k;
    rep(i,n){
        ll j=i+1;
        double x=1;
        while(j<k){
            j*=2;
            x/=2.0;
        }
        ans+=x/n;
        /*
        x=max(0,int((log(k/(i+1))/log(2)+1)));
        cout<<x<<' '<<pow(2,x)<<' '<<1/pow(2,x)/n<<endl;
        ans+=(float)(1.0/pow(2.0,x))/n;
        */
    }
    printf("%.12f\n",ans);
}






Measured memory_bytes: 384
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
lld p1=1e9 + 7,p2=998244353;

void judge(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
}

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

// lld fac[500005]; 

// void getfac(lld p)
// {
//     fac[0] = 1; 
//     for (lld i=1 ; i<=500005; i++) 
//         fac[i] = fac[i-1]*i%p; 
// }    

// long long int nCrmodp(lld n, lld r,lld p) 
// { 
//    // Base case 
//    if (r==0) 
//       return 1; 
     
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }


lld l,r,mid,ans=0;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;
lld ss=1;
void solve()
{  
    cin>>x>>y>>z;
    if(y*z>= x)
    {
        cout<<"Yes";
    }
    else cout<<"No";
}

int main()
{
    // judge();
    fastio();
    lld t=1;
    // cin>>t;
    // lld p1 = 1e9 + 7;
    // getfac(p1);
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
        // cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3644
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    let c = get!();
    
    if c > a + b {
    	let ans = a + b + 1 + b;
        println!("{}", ans);
        return;
    }
    if c == a + b {
    	let ans = a + b + b;
        println!("{}", ans);
        return;
    }
    
    let ans = c + b;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, a: "List[int]"):
    counter = 0
    current = 1
    for v in a:
        if v != current:
            counter += 1
        else:
            current += 1
    if counter == N:
        print(-1)
    else:
        print(counter)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26228
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		
		System.out.println(c / a * b);
		
		sc.close();
	}
	
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int INF=100000;

char str[100],*p,s[60][60];
int d[60][60];

int queue(int H,int W);

typedef struct{
  int xx;
  int yy;
} coordinate;

int main(void){
  int H,W,i,j,distance,count,ans;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  H=atoi(p);
  p=strtok(NULL," \n");
  W=atoi(p);
  
  for(i=0;i<H;i++){
    fgets(str,sizeof(str),stdin);
    p=strtok(str," \n");
    strcpy(s[i],p);
  }
  
  for(i=0,count=0;i<H;i++){
    for(j=0;j<W;j++){
      if(s[i][j]=='#'){
        count++;
      }
    }
  }
  distance=queue(H,W);
  if(distance==-1){
    printf("%d\n",distance);
    return 0;
  }
  ans=H*W-count-distance-1;
  printf("%d\n",ans);
  
  return 0; 
}

int queue(int H,int W){
  int top,bottom,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1},nx,ny,i,j,num=100000,x,y;
  coordinate q[100000];
  
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      d[i][j]=INF;
    }
  }
  
  d[0][0]=0;
  top=0;bottom=0;
  q[0].xx=0,q[0].yy=0;
  
  while(top!=bottom-1){
    x=q[bottom].xx, y=q[bottom].yy,bottom=(bottom+1)%num;
    if(x==W-1 && y==H-1){
      break;
    }
    for(i=0;i<4;i++){
      nx=x+dx[i],ny=y+dy[i];
      if(nx>=0 && nx<W && ny>=0 && ny<H && s[ny][nx]!='#' && d[ny][nx]==INF){
        top=(top+1)%num;
        q[top].xx=nx,q[top].yy=ny;
        d[ny][nx]=d[y][x]+1;
      }
    }
  }
  
  if(x!=W-1 && y!=H-1){;
    return -1;
    
  }
   
  return d[H-1][W-1];
  
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
s = sum(x * (x - 1) // 2 for x in counter.values())

# (n-1)(n-2)/2 - n(n-1)/2 = 1 - n
print('\n'.join(str(s + 1 - counter[x]) for x in A))



Measured memory_bytes: 31416
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	ll X;
	cin >> X;
	ll N = 100;
	ll ans = 0;
	while (X > N) {
		N = N + (N/100);
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


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

   if(n<500)
   {
       ll x = n/5;
       ll ans = x*5;
       cout<<ans<<endl;
   }
   else
   {
       ll a = n/500;
       ll ans=0;

       ans  = ans + (a*1000);
       ll p  = a*500;
       n-=p;
       a = n/5;
       ans = ans + (a*5);
       cout<<ans<<endl;
   }
}





Measured memory_bytes: 256
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int a, b;
    cin>>a>>b;
    cout<<a*b;

}


Measured memory_bytes: 3588
n = int(input())
a = list(map(int, input().split()))
cnt_list = []

for i in range(n):
    cnt = 0
    while a[i] % 2 == 0:
        a[i] //= 2
        cnt += 1
    cnt_list.append(cnt)
    
print(min(cnt_list))

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

/**
 *
 * @author kaixi_000
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str=br.readLine();
        String[] t=str.split("\\ ");
        int a=Integer.parseInt(t[0]); int b=Integer.parseInt(t[1]);
        System.out.println(Math.max(a*b,Math.max(a-b,a+b)));
    }
    
}


Measured memory_bytes: 22484
//url:
//problem name:

#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>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

string S;

int main() {
    cin >> S;
    ll count_B = 0;
    int N = S.size();
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        if(S.at(i) == 'B') count_B++;
        else {
            ans += count_B;
        }
    }
    cout << ans << endl;
}


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

const int MX = 100005;

using namespace std;

template<typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template<typename T> void read(T &x)
{
	x = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n;
int fst[MX], nxt[MX*2], v[MX*2], lnum;

void addeg(int nu, int nv)
{
	nxt[++lnum] = fst[nu];
	fst[nu] = lnum;
	v[lnum] = nv;
}

void input()
{
	read(n);
	for(int i=1; i<n; i++)
	{
		int a, b;
		read(a), read(b);
		addeg(a, b);
		addeg(b, a);
	}
}

int fa[MX], mxd, pos;
vector<int> path;
bool on_path[MX];
int siz[MX];

void dfs(int x, int f, int d)
{
	fa[x] = f;
	if(d > mxd) pos = x, mxd = d;
	for(int i=fst[x]; i; i=nxt[i])
		if(v[i] != f)	
			dfs(v[i], x, d+1);
}

void work()
{
	dfs(1, 0, 1);
	int l = pos;
	mxd = 0;
	dfs(l, 0, 1);
	int r = pos;

	int x = r;
	while (x != l)
	{
		path.push_back(x);
		on_path[x] = 1;
		x = fa[x];
	}
	path.push_back(x);
	on_path[x] = 1;

	auto fuck = [](){puts("-1"), exit(0);};

	on_path[0] = 1;
	for(int i=1; i<=n; i++)
		if(!on_path[fa[i]]) fuck();
		else siz[fa[i]]++;
	siz[r]++;

	auto get_seq = [](vector<int> p)
	{
		vector<int> seq;
		int cnt = 1;
		for(auto v : path)
		{
			for(int i=1; i<siz[v]; i++) seq.push_back(cnt+i);
			seq.push_back(cnt);
			cnt += siz[v];
		}
		return seq;
	};

	vector<int> seq1 = get_seq(path), seq2;
	reverse(path.begin(), path.end());
	seq2 = get_seq(path);

	for(int i=0; i<seq1.size(); i++)
		if(seq1[i] != seq2[i])
			if(seq1[i] < seq2[i])
			{
				for(auto v : seq1) printf("%d ", v);
				putchar('\n');
				return;
			}
			else
			{
				for(auto v : seq2) printf("%d ", v);
				putchar('\n');
				return;
			}
	for(auto v : seq1) printf("%d ", v);
	putchar('\n');
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 9840
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll n;
    cin>>n;
    vector<ll> v;
    ll sum = 0;

    rep(i,n+1){
        ll a;
        cin>>a;
        v.push_back(a);
        sum+=a;
    }

    ll ans = 0;
    ll nr = 0;
    if(n==0){
        if(v[0]==1){
            cout<<1<<endl;
        }else {
            cout << -1 << endl;
        }
        return 0;
    }

    for(int i=0;i<n+1;i++){
      // cout<<i<<" "<<ans<<" "<<nr<<" "<<sum<<endl;

        if(i==0){
            if(v[i]>=2){
                cout<<-1<<endl;
                return 0;
            }else if(v[i]==0){
                ans+=1;
                nr=1;
            }else{
                nr=0;
                ans+=1;
                sum--;
            }
        }else{

            if(nr*2<v[i]||(nr*2==v[i]&&sum-v[i]!=0)||(nr==0&&sum>=0)||sum<0){
                cout<<-1<<endl;
                return 0;
            }


            if(nr<=sum&&sum<=nr*2){
                ans+=sum;
                sum-=v[i];
                for(int j=i+1;j<n+1;j++){
                    ans+=sum;
                    sum-=v[j];
                }
                if(sum!=0){
                    cout<<-1<<endl;
                    return 0;
                }
                cout<<ans<<endl;
                return 0;
            }else if(2*nr<sum){
                sum-=v[i];
                nr=2*nr;
                ans+=nr;
                nr-=v[i];
            }else{
                cout<<-1<<endl;
                return 0;
            }
        }
    }



    cout<<-1<<endl;



return 0;
}


Measured memory_bytes: 4320
line = gets.chop.split.map(&:to_i)
n = line[0]
k = line[1]


def minimal(n, k);
  tmp = Float::INFINITY
  tmp2 = 0
  if n > k
    tmp2 = n % k
  else
    tmp2 = n
  end
  while true do
    if tmp > tmp2
      tmp = tmp2
    else
      return tmp
    end
    tmp2 = (tmp2 - k).abs
  end
end
puts minimal(n, k)



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
char s[N];
int c;
int cnt[N], su, pw[N];
ll ans;
int main() {
	scanf("%s", &s);
	int n = strlen(s);
	pw[0] = 1;
	cnt[0]++;
	for (int i = 1; i <= n; i++)pw[i] = pw[i - 1] * 10 % 2019;
	for (int i = n - 1; i >= 0; i--) {
		c = s[i] - '0';
		su = (su + c * pw[n - i - 1]) % 2019;
		cnt[su]++;
	}
	for (int i = 0; i < 2019; i++)ans += 1ll * cnt[i] * (cnt[i] - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4652
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:[isize;5],
    }
    let mut z =110;
    let mut ans =0;
    for i in 0..5 {
        ans+=(a[i]+9)/10*10;
        if z>a[i]%10&&a[i]%10!=0 {z=a[i]%10;}
    }
    println!("{}",min(ans+z-10,ans))
}

Measured memory_bytes: 2092
N=int(input())
T=list(map(int,input().split()))
M=int(input())
drink=[]
for i in range(M):
    P,X=map(int,input().split())
    drink.append([P,X])
    
for j in range(len(drink)):
    P,X=drink[j]
    time=X+sum(T)-T[P-1]
    print(time)

Measured memory_bytes: 9112
N = int(input())
abc_l = []
for i in range(N):
    abc_l.append(list(map(int,input().split())))
DP = [[0,0,0] for i in range(N)]
for i in range(3):
    DP[0][i] = abc_l[0][i]
for i in range(1,N):
    for abc in range(3):
#        print(DP)
        copy = DP[i-1][:]
        copy.remove(DP[i-1][abc])
        DP[i][abc] = max(copy) + abc_l[i][abc]
print(max(DP[-1]))

Measured memory_bytes: 76632
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[4];
        int[] b = new int[4];
        int S;
        int T;
//        while(true){
            S=0;  T=0;
            for(int i=0;i<4;i++){
                a[i]=sc.nextInt();
                S += a[i];
            }
            for(int i=0;i<4;i++){
                b[i]=sc.nextInt();
                T += b[i];
            }
            if(S>=T){System.out.println(S);}
            else{System.out.println(T);} 
//        }
    }
}


Measured memory_bytes: 26272
#include <bits/stdc++.h>
#define inf (1ll << 62)
using namespace std;
const int maxn = 3005;
typedef long long ll;
int A[maxn];
ll memo[maxn][maxn][2];
ll solve(int i,int j,bool flag){
    if(i == j){
        if (flag)
            return -A[i];
        else
            return A[i];
    }
    ll &ans = memo[i][j][flag];
    if(ans != -inf)return ans;
    ll x = solve(i+1,j,!flag)+((flag)? -A[i] : A[i]);
    ll y = solve(i,j-1,!flag)+((flag)? -A[j] : A[j]);
    if (!flag)
        return (ans =max(x,y));
    else
        return (ans =min(x,y));

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    for (int i = 1; i <= N;i++){
        cin >> A[i];
    }
    for (int i = 1; i <= N;i++){
        for (int j = 1; j <= N;j++){
            memo[i][j][0] = memo[i][j][1] = -inf;
        }
    }
    cout << solve(1,N,0);
    return 0;
}


Measured memory_bytes: 141440
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,u,v;
  cin>>n>>m;
  int h[n];
  for (int i=0;i<n;i++)
    cin>>h[i];
  list <int> adj[n];
  while (m--)
  {
    cin>>u>>v;
    adj[u-1].push_back(v-1);
    adj[v-1].push_back(u-1);
  }
  int count=0;
  for (int i=0;i<n;i++)
  {   int tem=0;
    for (auto j: adj[i])
      if (h[j]>=h[i])
      {tem=1;
       break;}
    if (tem==0)
      count++;
  }
  cout<<count;
}

Measured memory_bytes: 12588
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    d = [ni()-1 for _ in range(n)]

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if last[di] != -1:
            if i - last[di] != 1:
                dp[i + 1] += dp[last[di] + 1]
                dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 92060
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var input = input.split("\n")
    var input = input[0]
	
  	if(input == "Rainy"){
    console.log("Sunny");
    }
  
	if(input == "Sunny"){
    console.log("Cloudy");
    }
  
  if(input == "Cloudy"){
    console.log("Rainy");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
a, b, c = map(int, input().split())

counter = 0

li_wk = sorted([a, b, c], reverse=True)

if (li_wk[0] - li_wk[1]) >= 2:
    add_1 = (li_wk[0] - li_wk[1]) // 2
    li_wk[1] += (add_1 * 2)
    counter += add_1

if (li_wk[0] - li_wk[2]) >= 2:
    add_2 = (li_wk[0] - li_wk[2]) // 2
    li_wk[2] += (add_2 * 2)
    counter += add_2

if li_wk.count(li_wk[0]) == 3:
    pass
elif li_wk.count(li_wk[0]) == 2:
    counter += 2
else:
    counter += 1

print(counter)





Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define MAXLEN 1001

char x[MAXLEN];
char y[MAXLEN];
int  b[MAXLEN][MAXLEN];                  //传递二维数组必须知道列数，所以使用MAXLEN这个确定的数


int max(int a,int c){
    if(a>c) return a;
    else return c;
}

int LCS()
{
    int i, j;
    int m = strlen(y);
    int n = strlen(x);
    memset(b,0,sizeof b);
    int maxx = 0;
    for(i=0;i<n;i++) {
        for(j=0;j<m;j++) {
            if(i!=0) b[i][j] = max(b[i][j],b[i-1][j]);
            if(j!=0) b[i][j] = max(b[i][j],b[i][j-1]);
            if(x[i] == y[j]) {
                b[i+1][j+1] = max(b[i+1][j+1],b[i][j]+1);
            maxx = max(maxx,b[i+1][j+1]);
            }
        }
    }
    return maxx;
}

int main()
{
    int N;
    int i = 0;
    int m;
    scanf("%d",&N);
    for(i=0; i<N; i++){
        scanf(" %s", &x[0]);
        scanf(" %s", &y[0]);
        m = LCS();
        printf("%d\n",m);
    }
    return 0;
}




Measured memory_bytes: 5736
#include <bits/stdc++.h>
using namespace std;
const int maxn=200050;
typedef long long ll;
const ll MOD=998244353;
int a[maxn];
ll sum[maxn];
int main() {
	int n,m,v,p;
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", a+i);
	}
	sort(a+1, a+1+n);
	for(int i = 1; i <= n; ++i) {
		sum[i] = sum[i-1]+a[i];
	}
	int ans=0;
	for(int i = 1; i <= n; ++i) {
		ll t=(ll)m*v - (ll)i*m;
		int pos = lower_bound(a+1, a+1+n, a[i]+m+1)-a;
		if(n-pos+1>=p) continue;
		if(t<0) {
			ans++;
			continue;
		}
		if((ll)(a[i]+m)*(pos-1-i) - sum[pos-1]+sum[i] >= (ll)t) {
			ans++;
		} else {
			int l=i+1, r=pos, A=r;
			while(l<=r) {
				int mid=(l+r)/2;
				ll d=(ll)(n-mid+1)*m;
				d = d + (ll)(min(mid-1, pos-1) - i)*(a[i]+m) - sum[min(mid-1, pos-1)] + sum[i];
				if(d>=t) A=mid, l=mid+1;
				else r=mid-1;
			}
			A=min(A, pos);
			if(n-A+1 <p) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
v[50],p,n,k,X;main(s){for(;n=atoi(gets(v));printf("%d\n",s)){for(p=s=0;p<n;v[++p]=strlen(gets(v+n)));for(;n;){n=0,p=++s;for(k=261096;k>>=3;n+=X)for(X=k&7;X>0;X-=v[p++]);}}}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<int> G[1000];
vector<double> dp(1000,-1);

double dfs(int u){
    if(dp[u]!=-1) return dp[u];
    if(G[u].size()==0) return dp[u] = 0;
    if(G[u].size()==1) return dp[u] = dfs(G[u][0]) + 1;
    double ret = 0;
    for (int i = 0; i < G[u].size(); i++) {
        ret += dfs(G[u][i])+1;
    }
    return dp[u] = ret/G[u].size();
}


int main(){
    int n,m;cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s,t;cin >> s >> t;
        s--,t--;
        G[s].pb(t);
    }
    double ans = dfs(0);
    for (int i = 0; i < n-1; i++) {
        if(G[i].size()==1) continue;
        vector<double> dp1 = dp;
        double mx = 0;
        double t = 0;
        for (int j = 0; j < G[i].size() ; j++) {
            mx = max(mx,dp1[G[i][j]]+1);
        }
        dp1[i] = (dp[i] * G[i].size() - mx) / (G[i].size() - 1);
        for (int j = i-1; j >= 0; j--) {
            double sum = 0;
            for (int k = 0; k < G[j].size(); k++) {
                sum += dp1[G[j][k]]+1;
            }
            dp1[j] = sum / G[j].size();
        }
        ans = min(ans,dp1[0]);
    }
    cout << setprecision(30) << fixed<<ans << endl;
    return 0;
}


Measured memory_bytes: 1408
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 3e5 + 10;
#define singleCase
// #define multipleCase
ll n,a[N];

void work() {
   in(n);
   for (ll i = 1 ; i <= n * 3 ; i++)
      in(a[i]);
   sort(a + 1 , a + n * 3 + 1);
   ll sol = 0;
   for (ll i = n * 3 - 1, t = 0 ; i >= 1 ; i -= 2, t++) {
      if (t == n) break;
      sol += a[i];
   }
   printf("%lld\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      ll nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(ll &x) {
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 6108
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main()
{
    int n;
    string str1, str2;
    map<string, int> dic;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> str1 >> str2;

        if( str1 == "insert" )
            dic[str2] = 1;
        else
        {
            if( dic[str2] == 1 )
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
    }
    return 0;
}


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

#define LL      long long
#define pb      push_back
#define inf     111111111111111
#define READ    freopen("in.txt", "r", stdin)
#define WRITE   freopen("out.txt", "w", stdout);

map <string, int> mp;

int main()
{
    string str;
    cin >> str;

    if(str[0] == str[1] or str[1] == str[2] or str[2] == str[3])
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  int Q,H,S,D;cin>>Q>>H>>S>>D;
  D=min({D,2*S,4*H,8*Q});
  S=min({S,2*H,4*Q});
  H=min(H,2*Q);
  int N;cin>>N;N*=100;
  int ans=0;
  ans+=D*(N/200);N%=200;
  ans+=S*(N/100);N%=100;
  ans+=D*(N/50);N%=50;
  ans+=Q*(N/25);
  print(ans);


}


Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	ios;
	int n;cin>>n;
	bitset<5000000> bit,tmp;
	bit.set(0);
	vector<int> v(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
	}
	for(int i=0;i<n;i++){
		bit|=(bit<<v[i]);
	}
	set<int> si;
	for(int i=0;i<sum+1;i++){
		if(bit[i]){
			si.insert(i);
		}
	}
	cout<< *si.lower_bound(sum/2+sum%2)<<endl;
}

Measured memory_bytes: 95872
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using gragh = vector<vector<int>>;

int main() {
    int N;
    cin>>N;
    double X;

    int x = 1;
    int y = 50000 * 1.08;

    while (y - x > 1){
        int temp = (x+y)/2;
        if ((int)(temp * 1.08) > N){
            y = temp;
            continue;
        }else if ((int)(temp * 1.08) < N){
            x = temp;
            continue;
        }else if ( (int)(temp * 1.08) ==N ){
            cout<<temp<<endl;

            return 0;
        }
    }

    if ((int)(x*1.08) == N){
        cout<<x<<endl;
        return 0;
    }else if ((int)(y*1.08) == N){
        cout<<y<<endl;
        return 0;
    }

    cout<<":("<<endl;

}


Measured memory_bytes: 256
n,m=map(int,input().split())
List=[]
kosu=[]
ans=0
for i in range(n):
   k,*a=map(int,input().split())
   List+=a
   kosu.append(k)
for i in range(kosu[0]):
    if List.count(List[i])==n:
        ans+=1
    else:
        ans+=0
print(ans)


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,c,d,ans=0;
    cin>>a>>b>>c>>d;
    ans=max(0,(min(b,d)-max(a,c)));
    cout <<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
K = 50
A, B = map(int, input().split())
grid = [[0]*(2*K) for i in range(2*K)]
for i in range(K):
  grid[i] = [1]*(2*K)

row = 0
while A>1:
  if row%2==0:
    if A>K:
      grid[row] = [1,0]*K
      A -= K
    else:
      grid[row] = [1,0]*(A-1)+[1,1]*(K-A+1)
      break
  row += 1

row = K+1
while B>1:
  if row%2==0:
    if B>K:
      grid[row] = [1,0]*K
      B -= K
    else:
      grid[row] = [1,0]*(B-1)+[0,0]*(K-B+1)
      break
  row += 1

ans = []
for i in range(2*K):
  s = ''
  for j in range(2*K):
    if grid[i][j] == 1:
      s += '#'
    else:
      s += '.'
  ans += [s]
print(2*K,2*K)
for i in range(2*K):
  print(ans[i])

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

int main(){
    ll k;
    string str;
    cin >> str >> k;
    rep(i, str.size()){
        if(str[i] == 'a') continue;
        int d = 'z' - str[i];
        if(d < k){
            str[i] = 'a';
            k -= d+1;
        }
    }
    k = k % ('z' - 'a' + 1);
    int rest = (k + str.back() - 'a') % ('z' - 'a' + 1);
    str[str.size()-1] = (char)(rest + 'a');
    cout << str << "\n";
}

Measured memory_bytes: 512
r, g, b, n = gets.split.map(&:to_i)
c3, c2, c1 = [r, g, b].sort # c1がrgbの中で一番大きい数字
count = 0
(0..n/c1).each do |nc1|
  rest1 = n - c1*nc1
  (0..rest1/c2).each do |nc2|
    count += 1 if (rest1 - c2*nc2) % c3 == 0
  end
end
puts count


Measured memory_bytes: 1788
N = int(input())
A = []
first = 0
second = 0
for i in range(N):
    Ai = int(input())
    A.append(Ai)
    if Ai > first:
        second = first
        first = Ai
    elif Ai > second:
        second = Ai

for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)

Measured memory_bytes: 12532
#include <stdio.h>

const int N = 2e5 + 10;
char a[N];
char t[N], dir[N];
int n, qq;

bool can_left(int x) {
  int cur = x;
  for (int i = 0; i < qq; i++) {
    if (t[i] == a[cur]) {
      if (dir[i] == 'L') {
        cur--;
      } else {
        cur++;
      }
      if (cur == -1) {
        return true;
      }
    }
  }
  return false;
}

bool can_right(int x) {
  int cur = x;
  for (int i = 0; i < qq; i++) {
    if (t[i] == a[cur]) {
      if (dir[i] == 'L') {
        cur--;
      } else {
        cur++;
      }
      if (cur == n) {
        return true;
      }
    }
  }
  return false;
}

int main() {
  scanf("%d %d", &n, &qq);
  scanf("%s", a);
  for (int i = 0; i < qq; i++) {
    scanf(" %c %c", &t[i], &dir[i]);
  }
  int lo = -1, hi = n;
  int ans = n;
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    if (can_left(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  ans -= lo + 1;
  lo = -1;
  hi = n;
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    if (can_right(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  ans -= n - hi;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 768
N = int(input())
H = list(map(int,input().split()))

ans = 0
MAX = max(H)
for h in range(MAX):
    kukan = False
    for i in range(N):
        if H[i] == 0:
            if kukan:
                ans += 1
                kukan = False
        else:
            H[i] -= 1
            kukan = True
    if kukan:ans+=1
    #print(H,ans)
            
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

void findDivisors(int n) 
{ 
  
    // Array to store the count 
    // of divisors 
    int div[n + 1]; 
    memset(div, 0, sizeof div); 
  
    // For every number from 1 to n 
    for (int i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (int j = 1; j * i <= n; j++) 
            div[i * j]++; 
    } 
  
    // Print the divisors 
    int sum=0;
    for (int i = 1; i <= n; i++) 
    {
        sum+=i*div[i];
    }
    cout<<sum;
} 

void solve()
{
    int t,n,m,i,k,r,l,u,v,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    // int x;
    cin>>n;
    findDivisors(n);
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // int n=(int)1e7+1;
    // findDivisors(n);
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 81764
#include <iostream>

using namespace std;

int main()
{
	int n, ans;
	cin >> n;
	for (int index = 0; index < n; index++) {
		ans = 0;
		for (int i = 1; i < 100; i++) {
			for (int j = i; j < 100; j++) {
				for (int k = j; k < 100; k++) {
					if (i * i + j * j + k * k + i * j + j * k + k * i == index + 1) {
						if (i != j && j != k) ans += 6;
						else if ((i == j || i == k || j == k) && !(i == j && i == k)) ans += 3;
						else if (i == j && i == k) ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
	}


	return 0;
}



Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



signed main(){

	int H, W, N, a[10000];
	int g[100][100];
	cin >> H >> W >> N;
	for (int i = 0; i<N; i++)
		cin >> a[i];

	int color = 0;

	for (int h = 0; h<H; h++){
		if (h % 2 == 0){
			for (int w = 0; w<W; w++){
				g[h][w] = color;
				a[color]--;
				if (a[color] == 0) color++;
			}
		}
		else{
			for (int w = W - 1; w >= 0; w--){
				g[h][w] = color;
				a[color]--;
				if (a[color] == 0) color++;
			}
		}
	}

	for (int h = 0; h<H; h++){
		for (int w = 0; w<W; w++)
			cout << g[h][w]+1 << " ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 384
import math

n, k = input().split()
n = int(n)
k = int(k)

ans = 0.0
for i in range(1, n+1):
    if i > k:
        ans += 1.0
    else:
        temp = math.log2(k / i)
        if abs(temp - int(temp)) > 0.0000000001:
            temp = int(temp) + 1
        ans += (0.5 ** temp)
ans = ans / n
print(ans)


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

int main(){
  int x;
  cin >> x;
  
  if(x >= 400 && x < 600){
    cout << 8 << endl;
  }else if(x >= 600 && x < 800){
    cout << 7 << endl;
  }else if(x >= 800 && x < 1000){
    cout << 6 << endl;
  }else if(x >= 1000 && x < 1200){
    cout << 5 << endl;
  }else if(x >= 1200 && x < 1400){
    cout << 4 << endl;
  }else if(x >= 1400 && x < 1600){
    cout << 3 << endl;
  }else if(x >= 1600 && x < 1800){
    cout << 2 << endl;
  }else if(x >= 1800 && x < 2000){
    cout << 1 << endl;
  }
    
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
vector<vector<int>> ki(200001);
long long point[220000];
void dfs(int now,int last,int add){
    point[now] += add;
    rep(i,ki[now].size()){
        if(ki[now][i] == last)continue;
        dfs(ki[now][i],now,point[now]);
    }
}
int main()
{   
    int n,q;
    cin >> n >> q;

    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        
        ki[a].push_back(b);
        ki[b].push_back(a);


    } 
    rep(i,n){
        point[i] = 0;
    }
    rep(i,q){

        int p,x;
        cin >> p >> x;
        p -=1;
        point[p] += x;

    }
    dfs(0,-1,0);
    rep(i,n){
        cout << point[i] << endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;

    vector<vector<int>> point(N, vector<int>(2));
    rep(i, N){
        cin >> point.at(i).at(0) >> point.at(i).at(1);
    }

    double sum = 0;
    vector<vector<double>> distance(N, vector<double>(N));
    rep(i, N - 1){
        rep2(j, i + 1, N){
            distance.at(i).at(j) = sqrt(pow(point.at(i).at(0) - point.at(j).at(0), 2.0) + pow(point.at(i).at(1) - point.at(j).at(1), 2.0));
            sum += distance.at(i).at(j);
            // cout << distance.at(i).at(j) << endl;
        }
    }

    /*
    int kaijo = 1;
    rep2(i, 1, N + 1){
        kaijo *= i;
    }
    */

    double average = 2.0 / (double)N * sum;

    // cout << sum << endl;
    // cout << kaijo << endl;
    cout << fixed << setprecision(10) << average << endl;
    // cout << average << endl;

}

Measured memory_bytes: 256
n,m,s=map(int,input().split())
s=min(s,2500)
edge=[[] for i in range(n*50*51)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    for j in range(a,2501):
        edge[u-1+j*n].append((v-1+(j-a)*n,b))
        edge[v-1+j*n].append((u-1+(j-a)*n,b))
for i in range(n):
    c,d=map(int,input().split())
    for j in range(2501-c):
        edge[i+j*n].append((i+(j+c)*n,d))
    for j in range(2500):
        edge[i+(j+1)*n].append((i+j*n,0))

def dijkstra(s,n):
    from heapq import heappush,heappop
    d = [float('inf') for i in range(n+1)]
    pq = []
    d[s]=0
    heappush(pq,(0,s))
    while pq:
        dist,u = heappop(pq)
        for v,cost in edge[u]:
            if d[v]<=dist+cost:
                continue
            d[v]=dist+cost
            heappush(pq,(d[v],v))
    return d
d=dijkstra(s*n,n*50*51)
for i in range(1,n):
    print(d[i])

Measured memory_bytes: 127768
N,M=map(int,input().split())
xy = [map(int,input().split())for _ in range(M)]
x,y=[list(i) for i in zip(*xy)]
city=[0]*N
for i in range(M):
    for n in range(1,N+1):
        if x[i]==n:
            city[n-1]=city[n-1]+1
        if y[i]==n:
            city[n-1]=city[n-1]+1
for i in range(N):
    print(city[i])
        
        


Measured memory_bytes: 3064