akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <int32_t MOD>
struct mint {
    int64_t value;  // faster than int32_t a little
    mint() = default;  // value is not initialized
    mint(int64_t value_) : value(value_) {}  // assume value is in proper range
    inline mint<MOD> operator + (mint<MOD> other) const { int64_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> operator * (mint<MOD> other) const { int64_t c = this->value * int64_t(other.value) % MOD; return mint<MOD>(c < 0 ? c + MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
    inline mint<MOD> & operator *= (mint<MOD> other) { this->value = this->value * int64_t(other.value) % MOD; if (this->value < 0) this->value += MOD; return *this; }
};

constexpr int MOD = 998244353;
vector<mint<MOD> > solve(int k, int n) {
    auto dp0 = vectors(k + 1, n + 1, mint<MOD>());
    dp0[0][0] = 1;
    REP (i, k) {
        dp0[i + 1][0] = dp0[i][0];
        REP (j, n) {
            dp0[i + 1][j + 1] = dp0[i + 1][j] + dp0[i][j + 1];
        }
    }
    auto dp1 = vectors(k + 1, n + 1, mint<MOD>());
    dp1[0][0] = 1;
    REP (i, k) {
        REP (j, n) {
            dp1[i + 1][j + 1] = dp1[i + 1][j] + dp1[i][j] * 2;
        }
        REP (j, n + 1) {
            dp1[i + 1][j] += dp1[i][j];
        }
    }
    vector<mint<MOD> > answer(2 * k - 1);
    REP (x, k) {
        int a = k - x - 1;  // numbers which you can use freely
        int b = (x + 1) / 2;  // pairs which are mutual excluded
        bool c = 1 - x % 2;  // numbers which can be used at most once
        REP (l, n + 1) {
            int r = n - l;
            answer[x] += dp0[a][l] * dp1[b][r];
            if (c and r) answer[x] += dp0[a][l] * dp1[b][r - 1];
        }
    }
    REP3 (x, k, 2 * k - 1) {
        answer[x] = answer[(2 * k - 1) - x - 1];
    }
    return answer;
}

int main() {
    int k, n; cin >> k >> n;
    auto answer = solve(k, n);
    for (auto it : answer) {
        cout << it.value << endl;
    }
    return 0;
}


Measured memory_bytes: 62976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
#define MOD 1e9+7

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

struct edge {int to, cost;};
vector< vector<edge> > es;
const int MAX_N = 310;
ll d[MAX_N][MAX_N];
bool flags[MAX_N][MAX_N];
int n;

void warshallfloyd() {
    bool flag = true;
    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                if (d[i][j] > d[i][k]+d[k][j]) flag = false;
                else if (d[i][j] == d[i][k]+d[k][j] && i != k && j != k) {
                    flags[i][j] = false;
                }
            }
        }
    }
    if (!flag) cout << -1 << endl;
    else {
        ll ans = 0;
        REP(i, n) {
            REP(j, n) {
                if (flags[i][j]) ans += d[i][j];
            }
        }
        ans /= 2;
        cout << ans << endl;
    }
}

int main() {
    cin >> n;
    ll ans = 0;
    REP(i, n) {
        REP(j, n) {
            cin >> d[i][j];
            flags[i][j] = true;
        }
    }
    warshallfloyd();
    return 0;
}

Measured memory_bytes: 1024
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

// レベル l バーガーの下から x 層を食べる
fn dfs(mut x: i64, l: usize, p: &mut i64, xs: &[i64], ps: &[i64]) {
    // パン
    if x == 0 {
        return;
    }
    x -= 1;

    // l-1 バーガー
    if x < xs[l - 1] {
        return dfs(x, l - 1, p, xs, ps);
    }
    x -= xs[l - 1];
    *p += ps[l - 1];

    // パティ
    if x == 0 {
        return;
    }
    x -= 1;
    *p += 1;

    // l-1 バーガー
    if x == 0 {
        return;
    }
    if x < xs[l - 1] {
        return dfs(x, l - 1, p, xs, ps);
    }
    x -= xs[l - 1];
    *p += ps[l - 1];

    // パン
    if x == 0 {
        return;
    }
    x -= 1;
}

fn main() {
    let (N, X) = read!(usize, i64);

    let mut ps = vec![0; N + 1];
    let mut xs = vec![0; N + 1];
    ps[0] = 1;
    xs[0] = 1;

    for l in 0..N {
        ps[1 + l] = ps[l] * 2 + 1;
        xs[1 + l] = xs[l] * 2 + 3;
    }

    let mut p = 0_i64;
    dfs(X, N, &mut p, &xs, &ps);

    println!("{}", p)
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int
main(int argc, char *argv[])
{
  int n, a[100];
  scanf("%d", &n);
  rep(i, n) scanf("%d", &a[i]);

  int cnt = 0, temp;

  for(int i = 0; i < n; i++){
    for(int j = n - 1; j > i; j--){
      if(a[j] < a[j - 1]){
	temp = a[j];
	a[j] = a[j - 1];
	a[j - 1] = temp;
	cnt++;
      }
    }
  }

  rep(i, n) {
    printf("%d", a[i]);
    if(i < n - 1) printf(" ");
  } endl;
  printf("%d", cnt); endl;

  return 0;
}



Measured memory_bytes: 2108
def solve(N, K):
    tmp = N % K

    if abs(tmp - K) < tmp:
        return abs(tmp - K)
    else:
        return tmp

def main():
    N, K = map(int, input().split())
    ans = solve(N, K)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		
		try(Scanner scan = new Scanner(System.in)){

			int n = scan.nextInt();
			int[] array = new int[n+1];
			for(int i=0; i<n; i++) {
				array[i] = scan.nextInt();
			}
			
			int dice = 0;
			int counter = 0; 
			
			for(int i=0; i<array.length; i++) {

				if(array[i] == 1) {
					counter++;
				}else {
					dice = Math.max(dice, counter);
					counter = 0;
				}
			}
			dice = Math.max(dice, counter);
			System.out.println(dice+1);
		}
	}
}


Measured memory_bytes: 26364
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll n, k;
    cin >> n >> k;
    vel d(k);
    ll ans = 0;
    vector<bool> p(n, false);
    rep(i, k) {
        cin >> d[i];
        vel a(d[i]);
        rep(j, d[i]) {
            cin >> a[j];
            rep(l, n) {
                if(l+1 == a[j]) {
                    p[l] = true;
                }
            }
        }
    }
    rep(i, n) {
        if(p[i]);
        else {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
long sort(const void *a, const void*b){
  return *(long*)b - *(long*)a;
}

int main(){
  long n;
  scanf("%ld",&n);
  long a[n+1];
  for(long i=0;i<n;i++)scanf("%ld",&a[i]);
  
  qsort(a,n,sizeof(long),sort);
  
  long ans=a[0];
  long k=n-2;
  long p;
  for(long i=1;i>0;i++){
    if(k<2){
      p=i;
      break;
    }
    
    ans+=2*a[i];
    k-=2;
  }
  
  if(k==1){
    ans+=a[p];
  }
  
  printf("%ld",ans);
  return 0;
}

Measured memory_bytes: 5048
INF = 10**8
N, M = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
# p arr
dp = Array.new(M+1){Array.new(N+1, INF)}
dp.each do |d|
  d[0] = 0
end
1.upto(M) do |i|
  1.upto(N) do |j|
    if j - arr[i-1] < 0
      dp[i][j] = dp[i-1][j]
    else
      dp[i][j] = [dp[i-1][j], dp[i][j - arr[i-1]] + 1].min
    end
  end
end
# p dp
p dp[M][N]


Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

const int none=0;

int p[15][6];
int n;

void debug_print(){
  cout<<endl;
  rep(i,n){
    rep(j,5)cout<<p[i][j]<<" ";
    cout<<endl;
  }
}

void init(){
  rep(i,n)rep(j,5)p[i][j]=none;
}

void fall(){
  for(int j=0;j<5;j++){
    for(int i=n-1;i>=1;i--){
      for(int k=n-1;k>=1;k--)if(p[k][j]==none)swap(p[k][j],p[k-1][j]);
    }
  }
}

void vanishment(pi vanish,int i){
  bool ok=false;
  rep(j,5){
    if(vanish.first==p[i][j]&&vanish.first==p[i][j+1])ok=true;
    if(vanish.second!=0&&p[i][j]==vanish.first&&ok){
      p[i][j]=none;
      vanish.second--;
    }
  }
}

void solve(){
  pi vanish;
  int score=0;
  bool ok=true;
  while(ok){
    ok=false;
    rep(i,n){
      vanish.first=p[i][0];vanish.second=1;
      REP(j,1,5){
	if(p[i][j]==vanish.first&&p[i][j]!=none)vanish.second++;
	else if(vanish.second<=2){vanish.first=p[i][j];vanish.second=1;}
	else if(p[i][j]!=vanish.first&&vanish.second>=3)break;
      }
      if(vanish.second>=3){
	ok=true;
	score+=vanish.first*vanish.second;
	vanishment(vanish,i);
	if(debug)cout<<"score: "<<score<<endl;
      }
    }
    if(debug)cout<<"before";
    if(debug)debug_print();
    fall();
    if(debug)cout<<"after";
    if(debug)debug_print();
  }
  cout<<score<<endl;
}

int main(){
  while(cin>>n){
    if(n==0)break;
    init();
    rep(i,n)rep(j,5)cin>>p[i][j];
    solve();
  }
}

Measured memory_bytes: 3068
#include<iostream>

using namespace std;


int main(void) {
  int n;
  cin >> n;
  int h[n];
  int max = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    if (h[i] >= max) {
      max = h[i];
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
import heapq

N = int(input())
graph = {i:[] for i in range(1, N+1)}
route = [10**20 for i in range(N+1)]
visited = [False for i in range(N+1)]

for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    graph[u].append((v, w))
    graph[v].append((u, w))

for key, value in graph.items():
    if len(value):
        start = key
        route[start] = 0
        visited[start] = True
        q = []
        for v, w in value:
            route[v] = min(route[v], w)
            heapq.heappush(q, (w, v))
        break

while len(q):
    w, v = heapq.heappop(q)
    if not visited[v]:
        visited[v] = True
        for u, c in graph[v]:
            if route[u] > route[v] + c:
                route[u] = route[v] + c
                heapq.heappush(q, (c, u))

for n in route[1:]:
    if n % 2:
        print('1')
    else:
        print('0')

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

int main(){
    int N,W;
    cin >> N >> W;
    int v[N],w[N];
    for(int i=1; i<=N; ++i){
        cin >> v[i] >> w[i];
    }

    int DP[N+1][W+1] = {};

    for(int i=1; i<=N; ++i){
        for(int c=1; c<=W; ++c){
            if(c-w[i]<0){
              DP[i][c] = DP[i-1][c];
            } else {
              DP[i][c] = max(DP[i][c-w[i]]+v[i], DP[i-1][c]);
            }
        }
    }

    cout << DP[N][W] << endl;
}

Measured memory_bytes: 6988
#include<stdio.h>
int main(void)
{
	int n,s[101],g=0,t,min,i;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d", &s[i]);
		g+=s[i];
	}
	while(g%10==0)
	{
		min=101;
		for(i=0; i<n; i++)
		{
			if(s[i]%10!=0&&min>s[i])
			{
				min=s[i];
				t=i;
			}
		}
		if(min==101)
		{
			g=0;
			break;
		}
		g-=s[t];
		s[t]=101;
	}
	printf("%d\n", g);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  string ans = "aeiou";
  if(ans.find(c) == std::string::npos){
    cout << "consonant" << endl;
  }else{
    cout << "vowel" << endl;
  }
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a>k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,X,M;
    cin >> N >> X >> M;
    ll Z=X;
    set<ll> st;
    vl A;
    ll kaburi0=-1,kaburi1=-1;
    rep(i,N){
        if(st.count(X)){
            rep(j,A.size()){
                if(A[j]==X){
                    kaburi0=j;
                    kaburi1=i;
                }
            }
            break;
        }
        else{
            A.pb(X);
            st.insert(X);
            X*=X;
            X%=M;
        }
    }
    if(kaburi0==-1&&kaburi1==-1){
        ll ans=0;
        rep(i,N){
            ans+=Z;
            Z*=Z;
            Z%=M;
            //cout << Z << endl;
        }
        cout << ans << endl;
        return 0;
    }
    ll ans=0;
    rep(i,kaburi0){
        ans+=A[i];
    }
    ll loop=0;
    FOR(i,kaburi0,kaburi1){
        loop+=A[i];
    }
    N-=kaburi0;
    ans+=N/(kaburi1-kaburi0)*loop;
    N%=(kaburi1-kaburi0);
    rep(i,N){
        ans+=A[kaburi0+i];
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 5944
from itertools import combinations
n=int(input())
A=list(map(int,input().split()))
q=int(input())
M=list(map(int,input().split()))

l=set()
for a in range(1,len(A)):
    for com in combinations(A,a):
        l.add(sum(com))
            
for m in M:
    if m in l:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5696
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
 int n;
 cin>>n;

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

 int ans=0;
 for(int i=1;i<n-1;++i)
 {
  if(v[i]>min({v[i-1],v[i],v[i+1]}) && v[i]<max({v[i-1],v[i],v[i+1]}))
  ++ans;
 }

 cout<<ans;
}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}



Measured memory_bytes: 256
class SchoolRoad
  def initialize(x, y)
    @x = x
    @y = y
    @grid = Array.new(y+1).map{Array.new(x+1, 0)}
    @grid[1][1] = 1
  end

  def set_under_constraction(x, y)
    @grid[y][x] = nil
  end

  def solve
    (1..@y).each do |i|
      (1..@x).each do |j|
        next if @grid[i][j].nil?
        @grid[i][j] += get_grid_num(i-1, j) + get_grid_num(i, j-1)
      end
    end
    @grid[@y][@x]
  end

  def get_grid_num(i, j)
    (@grid[i][j].nil? ? 0 : @grid[i][j])
  end
end

def make_school_road(x, y)
  school_road = SchoolRoad.new(x, y)
  n = gets.chomp.to_i
  n.times do
    xi, yi = gets.chomp.split.map(&:to_i)
    school_road.set_under_constraction(xi, yi)
  end
  school_road
end

def main
  loop do
    x, y = gets.chomp.split.map(&:to_i)
    break if (x|y) == 0
    puts make_school_road(x, y).solve
  end
end

main

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

namespace CSharpSample01
{


    class Program
    {

        

        static void Main(string[] args)
        {

            int[] data = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int K = int.Parse(Console.ReadLine());

            int max = -1;
            int u = 0;
            for(int i = 0; i < 3; i++)
            {
                if (max < data[i])
                {
                    max = data[i];
                    u = i;
                }
            }

            data[u] *= (int)Math.Pow(2, K);

            Console.WriteLine(data[0] + data[1] + data[2]);

        }
    }
}

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

int Test( const int A, const int B )
{
int x;
int y;

	x = A;
	y = B;

	while( true )
	{
		x %= y;
		if( x == 0 ) return y;

		y %= x;
		if( y == 0 ) return x;
	}

	return 0;
}

int main( int argc, char *argv[] )
{
int A;
int B;
int C;

	cin >> A;
	cin >> B;
	cin >> C;

	if( C % Test( A, B ) == 0 )
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}






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

for a in range(1,3501):
    for b in range(1,3501):
        x = a*b*N
        y = 4*a*b - b*N - a*N
        if y != 0 and x/y > 0:
            c = x//y
            if 4*a*b*c == b*c*N + a*c*N + a*b*N:
                print(a,b,c)
                exit()

Measured memory_bytes: 68820
#include <stdio.h>

int main()
{
  int a,b,c,d; scanf ("%d %d %d %d",&a,&b,&c,&d);
  while (1){
    c -= b;
    if (c <= 0){puts("Yes");break;}
    a -= d;
    if (a <= 0){puts("No");break;}
  }
return 0;
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int H, W;
  cin >> H >> W;
  long long int ans = 0;
  if(H == 1 || W == 1){
    cout << "1" << endl;
    return 0;
  }
  if((H*W)%2 == 0) ans = (H*W)/2;
  else ans = (H*W+1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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



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

    if(a % 3 == 0 ||
       b % 3 == 0 ||
       (a+b) % 3 == 0)
        cout << "Possible" << "\n";
    else
        cout << "Impossible" << "\n";

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
  cout << -1 << endl;
  exit(0);
}

int main(){
  ll n, a, b, p, ans=infll;
  cin >> n >> a >> b;
  ll cnt[3] = {};
  for(ll i=0; i < n; i++){
    cin >> p;
    if(p <= a){
      cnt[0] += 1;
    }else if(a < p && p <= b){
      cnt[1] += 1;
    }else{
      cnt[2] += 1;
    }
  }
  for(ll j=0; j < 3; j++){
    chmin(ans, cnt[j]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int main() {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2-(y2-y1);
    int y3 = y2+(x2-x1);
    int x4 = x3-(y3-y2);
    int y4 = y3+(x3-x2);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun w h ->
  let ps = Array.init w (fun _ -> Scanf.scanf "%d\n" (fun p -> (p, 2))) in
  let qs = Array.init h (fun _ -> Scanf.scanf "%d\n" (fun q -> (q, 1))) in
  List.sort (fun (p, _) (q, _) -> compare p q) (Array.to_list qs @ Array.to_list ps)
  |> List.fold_left (fun (cost, (w, h)) -> function
    | (p, 2) ->
        (* p_i は，∀j. (i, j)と(i + 1, j)を結ぶコスト *)
        (cost + p * h, (w - 1, h))
    | (q, 1) ->
        (* q_j は，∀i. (i, j)と(i, j + 1)を結ぶコスト *)
        (cost + q * w, (w, h - 1))) (0, (w + 1, h + 1))
  |> fst
  |> Printf.printf "%d\n"

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

int main(){
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
    } else if(s.size() == 26){
        int num = 0;
        for(int i = 25; i >= 0; i--){
            if(s[i-1] < s[i]){
                num = i-1;
                break;
            }
        }
        string g = s.substr(0,num);
        cout << g;
        for(char x = s[num] + 1; x <= 'z'; x++){
            int found = 0;
            for(int j = 0; j < g.size(); j++){
                if(g[j] == x) found = 1;
            }
            if(!found){
                cout << x << endl;
                break;
            }
        }
    } else {
        cout << s;
        for(char x = 'a'; x <= 'z'; x++){
            int found = 0;
            for(int j = 0; j < s.size(); j++){
                if(s[j] == x) found = 1;
            }
            if(!found){
                cout << x << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


int dig(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	int res = INF;
	FOR(i,1, N) {
		int a = i;
		int b = N - i;
		int c = dig(a) + dig(b);
		res = min(res, c);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

const int maxn = 1e5 + 5;

int a[maxn][4];
int n;

int dp[maxn][4];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= 3;j++){
            scanf("%d", &a[i][j]);
        }
    }
    memset(dp, -1, sizeof(dp));
    for(int j = 1;j <= 3;j++){
        dp[1][j] = a[1][j];
    }
    for(int i = 2;i <= n;i++){
        for(int j = 1;j <= 3;j++){
            for(int k = 1;k <= 3;k++){
                if(k == j)
                    continue;
                if(dp[i - 1][k] == -1)
                    continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= 3;i++){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
n = int(input())
fizz = 0
buzz = 0
fizzbuzz = 0
num_sum = 0
for num in range(1,n+1):
    if(num%3 == 0):
        fizz += num
    if(num%5 == 0):
        buzz += num
    if(num%3 == 0 and num%5==0):
        fizzbuzz += num
    num_sum += num
ans = num_sum - fizz - buzz + fizzbuzz
print(ans)

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

#include <bits/stdc++.h>
using namespace std;

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for(long long a = 2; a * a <= N; ++a) {
        if(N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while(N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if(N != 1)
        res.push_back({N, 1});
    return res;
}

int main() {
    ll maxi = 1000001;
    ll N;
    int ans = 0;
    cin >> N;
    for(int c = 1; c < N; c++) {
        // cout << "c:" << c << endl;
        ll num = N - c;
        int tmp = 1;
        const auto &res = prime_factorize(num);
        for(auto p : res) {
            tmp *= (p.second + 1);
            // cout << "a:" << p.first << " ex" << p.second << ", ";
        }
        // cout << "res.size():" << res.size();
        // cout << endl;
        if(res.size() == 0) {
            ans += 1;
        } else {
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	for i := 0; i < n; i++ {
		seg.maximize(i, getNextInt(scanner))
	}
	for i := 0; i < m; i++ {
		seg.maximize(seg.top(), seg.bucket[seg.h-1][0]>>1)
	}

	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(seg.bucket[0][i])
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index, value int) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		s := index - index%seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		parent := index / seg.chunk
		max := 0
		for i := s; i < t; i++ {
			if max < seg.bucket[seg.i][i] {
				max = seg.bucket[seg.i][i]
			}
		}
		seg.bucket[seg.i+1][parent] = max
		index /= seg.chunk
	}
}

func (seg *Segment) top() int {
	index := 0
	for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
		s := index * seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		for i := s; i < t; i++ {
			if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
				index = i
				break
			}
		}
	}

	return index
}


Measured memory_bytes: 3712
from bisect import *

n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    index_A = bisect_left(A, b)
    index_C = bisect_right(C, b)
    ans += index_A * (n - index_C)
print(ans)

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

		Scanner s = new Scanner((System.in));
		int n = s.nextInt();
		int fh = n / 100;
		int sh = n % 100;

		System.out.println(isMonth(fh) ? (isMonth(sh) ? "AMBIGUOUS " : "MMYY") : (isMonth(sh) ? "YYMM" : "NA"));

    }

    public static Boolean isMonth(int i){
    	return (1 <= i) && (i <= 12);
	}


}


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

int main(){
    int N, K;

    cin >> N >> K;
    if(K * 2 < N + 2)
        cout << "YES" << endl;
    else if(K == 1 && N == 1)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <math.h> 

using namespace std;

int main()
{
    double N;
    cin >> N;
    double result = ceil(N/1.08);

    if(floor(result*1.08)==N){
        cout << ceil(result) << endl;
    }
    else { cout << ":(" << endl;}
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    string s; cin >> s;
    if(s=="SSS") cout << 0 << endl;
    else if(s=="SRR" or s == "RRS") cout << 2 << endl;
    else if(s=="RRR") cout << 3 << endl;
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3612
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n,*a=map(int,read().split())
	
	aa=max(a)
	
	li=[[] for _ in range(aa+1)]
	
	for i in range(n):
		li[a[i]].append(i)
	
	if len(li[0])>3 or len(li[0])==0:
		print(0)
		exit(0)
	else:
		ans=3 if len(li[0])==1 else 6
	for i in range(1,aa+1):
		if len(li[i])>3 or len(li[i])==0 or len(li[i])>len(li[i-1]):
			print(0)
			exit(0)
		else:
			k=bisect.bisect_right(li[i-1],li[i][0])
			ans*=k
			ans%=MOD
			
			if len(li[i])>1:
				k=bisect.bisect_right(li[i-1],li[i][1])-1
				ans *= k
				ans %= MOD
		
	print(ans)
	
	
if __name__ == "__main__":
		main()


Measured memory_bytes: 21844
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

ans = -1
for n in range(10**(N-1), 10**N):
    sn = str(n)
    ok = True
    for s, c in SC:
        if sn[s-1] != str(c):
            ok = False
    if ok:
        ans = n
        break

if N == 1:
    ok = True
    for s, c in SC:
        if c != 0:
            ok = False
    if ok:
        ans = 0
print(ans)

Measured memory_bytes: 40304
n, m = map( int, input().split() )
edge_list = []
for _ in range( m ):
    a_i, b_i, c_i = map( int, input().split() )
    edge_list.append( ( a_i - 1, b_i - 1, - c_i ) )

INF = 10 ** 13
cost = [ INF ] * n
cost[ 0 ] = 0

NegativeLoopExist = False
for i in range( n ):
    for j in range( m ):
        a, b, c = edge_list[ j ]
        if cost[ a ] != INF and cost[ b ] > cost[ a ] + c:
            cost[ b ] = cost[ a ] + c
            if i == n - 1 and b == n - 1:
                NegativeLoopExist = True

if NegativeLoopExist:
    print( "inf" )
else:
    print( - cost[ n - 1 ] )

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

#define MAX 100

int isempty(void);
int isfull(void);
void push(int);
int pop(void);

int top = 0;
int stack[MAX];

int main()
{
  int x, a, b;
  char s[100];
  while(scanf("%s", s) != EOF) {
    if(s[0] == '+') {
      push(pop()+pop());
    }
    else if(s[0] == '-') {
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(s[0] == '*') {
      push(pop()*pop());
    }
    else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n", pop());
  return 0;
}
  
int isempty(void)
{
  if(top == 0)
    return 1;
  else
    return 0;
}
  
int isfull(void)
{
  if(top > MAX-1)
    return 1;
  else
    return 0;
}

void push(int x)
{
  if(isfull()) {
    fprintf(stderr, "エラー（オーバーフロー）\n");
    exit(1);
  }
  top++;
  stack[top] = x;
}

int pop(void)
{
  if(isempty()) {
    fprintf(stderr, "エラー（アンダーフロー）\n");
    exit(2);
  }
  top--;
  return stack[top+1];
}

Measured memory_bytes: 548
#1_9_C
n = int(input())
t = 0
h = 0
l = 0
for i in range(n):
    word1 , word2 = map(str,input().split())
    if word1 >= word2:
        l = len(word2)
    else:
        l  = len(word1)
    if word1 == word2:
        t += 1
        h += 1
    elif word1[:l] == word2[:l]:
        if len(word1) > len(word2):
            t += 3
        else:
            h += 3
    else:
        for j in range(l):
            if ord(word1[j]) > ord(word2[j]):
                t += 3
                break
            elif ord(word1[j]) < ord(word2[j]):
                h += 3
                break
print(t,h)


Measured memory_bytes: 5600
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()
cnt = 0
list=[0]
for i in range(0,len(s)-1):
    if s[i: i + 2] == 'AC':
        cnt += 1
    list.append(cnt)

for _ in range(q):
    l,r=map(int, input().split())
    print(list[r-1]-list[l-1])

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, M;
    cin >> N >> M;
    vector<long long> As(N);
    for (auto & a : As) cin >> a;

    vector<long long> cum(N + 1, 0);
    long long c = 0;
    for (int i = 0; i < N; ++i){
        c = (c + As[i]) % M;
        cum[i + 1] = c;
    }

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

    long long ans = 0;
    long long cnt = 0;
    long long val = -1;

    for (auto & c : cum){
        if (c == val){
            ++cnt;
        }else{
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
            val = c;
        }
    }
    ans += cnt * (cnt - 1) / 2;

    cout << ans << endl;

    return 0;
}

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


int compute(int* arr,int i,int n,int* dp)
{
    if(i==n-1)
        return 0;
    int ans=0;
    if(i==n-2)
    {
        ans=ans+abs(arr[i+1]-arr[i])+compute(arr,i+1,n,dp);
        dp[i]=ans;
        return ans;
    }
    if(dp[i]!=-1)
        return dp[i];
    int ans1=0;
    ans1=abs(arr[i]-arr[i+1])+compute(arr,i+1,n,dp);
    int ans2=abs(arr[i]-arr[i+2])+compute(arr,i+2,n,dp);
    ans=min(ans1,ans2);
    dp[i]=ans;
    return ans;

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

    int* arr=new int[n];
    int* dp=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
        dp[i]=-1;
    cout<<compute(arr,0,n,dp);
    return 0;
}


Measured memory_bytes: 13692
import heapq

N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

comfort = A[0]
edges = [-A[1], -A[1]]

for ai in A[2:]:
    m = heapq.heappop(edges) * -1
    comfort += m
    heapq.heappush(edges, -ai)
    heapq.heappush(edges, -ai)
print(comfort)


Measured memory_bytes: 103288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define sll set<ll>
#define str string
#define rev reverse
#define mp make_pair
#define pb push_back
#define acc accumulate
#define vll vector<ll>
#define eb emplace_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define dq deque<ll>
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back

void lcs(str a,str b)
{
    ll n=a.size();
    ll m=b.size();
    //cout << n << m;
    ll l[n+1][m+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                l[i][j]=0;
            else if(a[i-1]==b[j-1])
                l[i][j]=l[i-1][j-1]+1;
            else
                l[i][j]=max(l[i-1][j],l[i][j-1]);
        }
    }
    ll i=n,j=m;
    vector<char> ans;
    while(i>0 and j>0)
    {
        if(a[i-1]==b[j-1])
        {
            ans.pb(a[i-1]);
            i--;
            j--;
        }
        else
        {
            if(l[i-1][j]>l[i][j-1])
                i--;
            else
                j--;
            
        }            
    }
    for(i=ans.size()-1;i>=0;i--)
    {
        cout << ans[i];
    }
    cout << endl;
}

void solve()
{
    str a,b;
    cin >> a >> b;
    lcs(a,b);
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll cases;
    //cin >> cases;
    cases=1;
    for(ll i=0;i<cases;i++)
        solve();

    return 0;
}

Measured memory_bytes: 70656
N = int(input())
B = list(map(int,input().split()))

if N == 2:
    print(B[0]*2)
else:
    res = 0
    for i in range(N-2):
        res += min(B[i],B[i+1])
    res += B[0] + B[-1]
    print(res)

Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		double p0 = 0.0;
		for(int i = 1; i <= n; i++) {
			int x = i;
			int pow = 0;
			while(x < k) {
				x *= 2;
				pow++;
			}
			p0 += (1.0/Math.pow(2.0, pow))/n;
		}
		System.out.println(p0);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    int n = S.length();
    ll dp[n+1][13] = {}; dp[n][0] = 1;

    int mul = 1;
    for (int i=n-1; i>=0; --i)
    {
        int c = S[i] == '?' ? -1 : S[i]-'0';
        REP(j, 10)
        {
            if (c != -1 && c != j) continue;

            REP(k, 13)
            {
                dp[i][(j*mul + k)%13] += dp[i+1][k];
            }
        }

        REP(k, 13) dp[i][k] %= (ll)1e9+7;

        mul *= 10;
        mul %= 13;
    }

    cout << dp[0][5] << endl;
    return 0;
}

Measured memory_bytes: 10624
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main()
{
    while(true){
        string s;
        cin >> s;
        if(s == "0") break;
        int n = s.size();
        int ans = 0;
        for(int i = 0; i < n; i++){
            ans += s[i] - '0';
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll t1,t2,temp,temp1;
    t1=n/1.08;
    t2=t1+1;
    temp=t1*1.08;
    temp1=t2*1.08;
    if(temp==n||temp1==n){
        if(t1*1.08==n)
            cout<<t1<<"\n";
        else
            cout<<t2<<"\n";
    }
    else
        cout<<":("<<"\n";
	return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL ans[100];
    ans[0] = 2;
    ans[1] = 1;
    int n;cin >> n;
    for(int i=2;i<=n;i++){
        ans[i] = ans[i-1] + ans[i-2];
    }
    cout << ans[n] << endl;
    return 0;
}


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

using ll = long long;
const ll MAX = 1e18;
int main()
{
    int n;
    cin >> n;
    ll a[n];
    ll val = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << "0";
            return 0;
        }
    }
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        //if((MAX/val < x) || ((MAX/val == x) && (MAX%val != 0))) {
        if(x <= MAX/val) {
            val *= x;
        }
        else {
            cout << "-1" << endl;
            return 0;
        }

    }
    cout << val;
}


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

int main()
{
    int h, w, a, b;
    h = w = 100;
    char d[100][100];
    cin >> a >> b;
    int count = 1;
    for(int i = 0; i<50; i++){
        for(int j = 0; j<100; j++){
            if(i%2==0 && j%2==0 && count<a){
                d[i][j] = '.';
                count++;
            }else{
                d[i][j] = '#';
            }
        }
    }
    count = 1;
    for(int i = 50; i<100; i++){
        for(int j = 0; j<100; j++){
            if(i%2==1 && j%2==0 && count<b){
                d[i][j] = '#';
                count++;
            }else{
                d[i][j] = '.';
            }
        }
    }
    
    cout << h << " " << w << endl;
     for(int i = 0; i<100; i++){
        for(int j = 0; j<100; j++){
            cout << d[i][j];
        }
        cout << endl;
     }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(llong (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a) ((a)>0?(a):(-(a)))

using namespace std;

int main(){
	llong a,b,c,d;
	cin >> a >> b >> c >> d;
	llong ans=-1001001001001001001;
	ans = _max( ans,a*c );
	ans = _max( ans,a*d );
	ans = _max( ans,b*c );
	ans = _max( ans,b*d );
	cout << ans;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
	int n,a=0;
	double x[2],y[2],r[2],d;
	scanf("%d",&n);
	rep(i,n){
		rep(j,2)scanf("%lf%lf%lf",x+j,y+j,r+j);
		d=(x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]);
		if(d<(r[0]-r[1])*(r[0]-r[1])){
			if(r[0]>r[1])a=2;
			else a=-2;
		}else if(d>(r[0]+r[1])*(r[0]+r[1]))a=0;
		else a=1;
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a+b > c+d) cout << "Left" << endl;
    else if(a+b < c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,a[200007],res=0;
map<ll,ll> m;
int main(){
  cin >> n;
  for(ll i = 1; i<=n; i++) cin >> a[i];
  for(ll i = 1; i<=n; i++){
    a[i]+=a[i-1];
    res+=(a[i]==0);
  }
  for(ll i = 1; i<=n; i++){
    res+=m[a[i]];
    m[a[i]]++;
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 14336
#include <stdio.h>

int main(){
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  for(int i=a; i<=b; i++){
    if(i%n == 0){
      printf("OK\n");
      return 0;
    }
  }
  printf("NG\n");
  return 0;
}

Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 1e9+7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
	char in;bool IsN=false;
	in=getchar();
	if(in==EOF) return false;
	while(in!='-'&&(in<'0'||in>'9')) in=getchar();
	if(in=='-'){ IsN=true;num=0;}
	else num=in-'0';
	while(in=getchar(),in>='0'&&in<='9'){
			num*=10,num+=in-'0';
	} 
	if(IsN) num=-num;
	return true;
}
int main(){
	//freopen("1.in", "r", stdin);
	string s;
	cin>>s;
	int ans=0;
	string now="";
	string prev="";
	for(char c:s){
		now+=c;
		if(now!=prev){
			prev=now;
			now="";
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640