akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> nums(N);
  vector<int> balls(N);
  for (int i = 0; i < N; i++)
  {
    cin >> balls.at(i);
    nums.at(balls.at(i) - 1)++;
  }
  int64_t ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans += (int64_t)nums.at(i) * (nums.at(i) - 1) / 2;
  }
  for (int i = 0; i < N; i++)
  {
    int64_t a = ans - (nums.at(balls.at(i) - 1) - 1);
    cout << a << endl;
  }
}


Measured memory_bytes: 4096
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]
kosuu=0

for i in range(n):
	s=0
	for j in range(m):
		s+=a[i][j]*b[j]
	if s+c>0:
		kosuu+=1
print(kosuu)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let line = i.read_line();
    let mut s: Vec<isize> = Vec::new();
    for i in 0..line.len() {
        s.push((&line[i..i + 1]).parse().unwrap());
    }

    let result = (0..s.len() - 2)
        .map(|i| (s[i] * 100 + s[i + 1] * 10 + s[i + 2] - 753).abs())
        .min()
        .unwrap();

    writeln!(o, "{}", result).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

#define fi first
#define se second
#define pb push_back
#define ll long long

const int N = 5e4 + 7;

using namespace std;

int n , m;
ll used[N];
int cnt  , sum  , a , x , y , mn = 1e9;
int main(){
    ios_base::sync_with_stdio(false);
   cin >> n >> m;
   map<int , int>mp;
   vector<int>v;
   for( int i = 1;i <= m;i ++ )
    cin >> a , mp[a] ++;
   for( int i = 0;i <= 1000;i ++ )
    if( !mp[i] )
        v.pb(i);
    for( int i = 0;i < v.size();i ++ ){
        if( abs(n - v[i]) < mn )
            mn = abs(n - v[i]) , cnt = v[i];
    }
    cout << cnt;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    ll D;
    cin >> N >> D;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= D * D) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = acos(-1.0); //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

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

    ll t_sum = 1;
    ll a_sum = 1;

    rep(i, n) {
        long double ts = (long double) t_sum;
        long double as = (long double) a_sum;
        long double t, a;
        cin >> t >> a;
        ll k = (ll) max((ll) ceill(ts / t), (ll) ceill(as / a));
        t_sum = ((ll) t) * k;
        a_sum = ((ll) a) * k;
    }

    cout << t_sum + a_sum << endl;

    return 0;
}


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

int main()
{
  long long n,w;
  vector <pair <long long int,long long int> > v;
  cin>>n>>w;
  for(long long i=0;i<n;i++)
  {
      long long x,y;
      cin>>x>>y;
      v.push_back(make_pair(x,y));
  }
  sort(v.begin(),v.end());
  long long matrix[n+1][w+1];
  for(long long i=0;i<=w;i++)
    matrix[0][i]=0;
  for(long long i=0;i<=n;i++)
    matrix[i][0]=0;

  for(long long i=1;i<=n;i++)
  {
      for(long long j=1;j<=w;j++)
      {

          if(v[i-1].first>j)
            matrix[i][j]=max(matrix[i-1][j],matrix[i][j-1]);
        else
            matrix[i][j]=max(matrix[i-1][j],
                             max(v[i-1].second+matrix[i-1][(j-v[i-1].first)],
                                 matrix[i][j-1]));
      }
  }
 cout<<matrix[n][w]<<endl;
}


Measured memory_bytes: 82360
def up(c, i):
    i %= 26
    b = ord('z')-ord(c)+1
    if i >= b:
        i -= b
        c = 'a'
    c = chr(ord(c)+i)
    return c



s = input()
K = int(input())

a = ord('a')
ans = ''

for i in range(len(s)):
    b = ord('z')-ord(s[i])+1
    if i == len(s)-1:
        ans += up(s[i], K)
    elif b == 26:
        ans += 'a'
    elif K >= b:
        K -= b
        ans += 'a'
    else:
        ans += s[i]

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;

string s;

int go(int i,int j)
{
    i--; j--;
    while(i>=0)
    {
        if(s[i]!=s[j])return 0;
        i--; j--;
    }
    return 1;
}


int main()
{
    idfc;
  ///  string s;
    cin>>s;
    int n=s.length();
    int i;
    int ans=0;
    for(i=2;i<n;i+=2)
    {
        if(go(i/2,i))ans=i;
    }
    cout<<ans;


    return 0;
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error_old(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {it++;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); }

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){
    int n, k;
    cin >> n >> k;
    
    vi h(n);
    rep(i, n){
        cin >> h[i];
    }

    vi dp(n, INT_MAX);
    dp[0] = 0;
    repA(i, 1, n - 1){
        repA(jump, 1, k){
            if(i - jump < 0) break;
            dp[i] = min(dp[i], dp[i - jump] + abs(h[i - jump] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
const int mod = 1000000007;
int N, C, A[409], B[409], r[409][409], dp[409][409];
int binpow(int a, int b) {
	int ret = 1;
	while (b) {
		if (b & 1) ret = 1LL * ret * a % mod;
		a = 1LL * a * a % mod;
		b >>= 1;
	}
	return ret;
}
int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= C; j++) {
			for (int k = A[i]; k <= B[i]; k++) {
				r[i][j] += binpow(k, j);
				if (r[i][j] >= mod) r[i][j] -= mod;
			}
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= C; j++) {
			for (int k = 0; k <= j; k++) {
				dp[i + 1][j] = (dp[i + 1][j] + 1LL * dp[i][k] * r[i][j - k]) % mod;
			}
		}
	}
	cout << dp[N][C] << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<string>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    sort(a.at(i).begin(),a.at(i).end());
  }
  sort(a.begin(),a.end());
  long long cnt=0,count=0;
  string copy=a.at(0);
  for(int i=0;i<n;i++){
    if(a.at(i)==copy){
      count++;
    }
    else{
      cnt+=(count*(count-1))/2;
      count=1;
      copy=a.at(i);
    }
  }
  cnt+=(count*(count-1))/2;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>

using namespace std;
typedef unsigned long long ll;


int main()
{
	char s[5];
	scanf("%s", s);
	int ans = 700;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o')
			ans += 100;
	}
	cout << ans << endl;
}

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

int main() {
  int R;
  cin >> R;
  
  if (R < 1200) {
    cout << "ABC" << endl; 
  }
  else if (R < 2800) {
    cout << "ARC" << endl; 
  }
  else {
    cout << "AGC" << endl; 
  }
}


Measured memory_bytes: 256
def abs(n)
  if n > 0
    return n
  else
    return -n
  end
end
n = gets.to_i
datas = gets.split(" ").map{|nn|nn.to_i}
size = datas.size
for i in 0..(size-1) do
  datas[i] -= i + 1
end

datas.sort!

middle = 0
if datas.size % 2 == 0
  middle = datas[datas.size/2]
else
  middle = ((datas[(datas.size-1)/2] + datas[(datas.size-1)/2])/2).floor
end

sor = 0
datas.each do|da|
  sor += abs(da - middle)
end
puts sor.to_s

Measured memory_bytes: 17544
#include <iostream>
#include <vector>
using namespace std;
#define ll long long 
int main () {
  ll n;
  cin >> n;
  ll distance[n - 1], start[n - 1], frequency[n - 1];
  for (ll i = 0; i < n - 1; i++) {
    cin >> distance[i] >> start[i] >> frequency[i];  
  }
  vector<ll> ans;
  for (ll i = 0; i < n - 1; i++) {
    ll j = n - 2 - i;
    ll s = 0;
    for (ll l = 0; l < (i + 1); l++) {
      if (l == 0) {
        s = start[j] + distance[j];   
      }    
      else {
        if (s < start[j + l]) {
          s = start[j + l] + distance[j + l];    
        }  
        else {
          ll sub = s % frequency[j + l];
          if (sub == 0) {
            sub = 0;  
          }
          else {
            sub = frequency[j + l] - sub; 
          }
          s = s + sub + distance[j + l];   
        }
      }
    }    
    ans.push_back(s);
  }
  for (ll i = 0; i < n - 1; i++) {
    cout << ans[n - i - 2] << endl;  
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}
	sort.Sort(SortBy(A))
	//fmt.Println(A)

	maxA := A[len(A)-1]
	//trueで初期化
	//dp[i]=falseのとき、iより小さいiの約数が、Aに存在しない
	dp := make([]bool, maxA+1)
	ans := 0
	for i := 0; i < N-1; i++ {
		if dp[A[i]] == true {
			continue
		}
		for j := 1; j <= maxA/A[i]; j++ {
			dp[j*A[i]] = true
		}
		if A[i] != A[i+1] {
			ans++
		}

	}

	if dp[maxA] == false {
		ans++
	}

	fmt.Println(ans)

}

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 6148
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define db double
const db eps = 1e-8;

struct Point{
    db x, y;
    Point(db x=0, db y=0): x(x), y(y) {}    //必须有初始化
    bool operator < (const Point &p){
        return x < p.x || (x == p.x && y < p.y);
    }
};

typedef Point Vector;
Vector operator + (Vector a, Vector b){ return Point(a.x+b.x, a.y+b.y);}
Vector operator - (Point a, Point b){ return Vector(a.x-b.x, a.y-b.y);}
Vector operator * (Vector a, db k){ return Vector(a.x*k, a.y*k);}
Vector operator / (Vector a, db k){ return Vector(a.x/k, a.y/k);}

//inline将函数名为内联函数，不使用栈空间，直接运算，但不能有while,switch等复杂语句
inline db dot(Vector a, Vector b){
    return a.x*b.x + a.y*b.y;
}
inline db cross(Vector a, Vector b){
    return a.x*b.y - b.x*a.y;
}

int dcmp(db x){
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
bool operator == (Point a, Point b){
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}

struct Segment{
    Point p1, p2;
};
typedef Segment Line;
vector<Point> Polygon;
Point project(Line l, Point p){
    Point p1 = l.p1, p2 = l.p2;
    Vector a = p2 - p1, b = p - p1;
    db len_a = a.x*a.x + a.y*a.y;   //这里不加sqrt，是因为下面算投影长度时，要除以两次len_a
    Vector tmp = a * (dot(a, b) / len_a);
    return Point(tmp.x+p1.x, tmp.y+p1.y);
}
Point reflect(Line l, Point p){
    Point tmp = project(l, p);
    return p + (tmp - p)*2;
}
int main()
{
    Line l;
    Point p;
    int n;
    cin >> l.p1.x>> l.p1.y >>l.p2.x >>l.p2.y >>n;
    while(n --){
        cin >> p.x>> p.y;
        Point ans = reflect(l, p);
        printf("%.10f %.10f\n", ans.x, ans.y);
    }
    return 0;
}



Measured memory_bytes: 3292
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; // 998'244'353LL
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll A, B;
char c1, c2, c3;

signed main(){
    scanf("%lld %c.%c%c", &A, &c1, &c2, &c3);
    B = (c1-'0')*100 + (c2-'0')*10 + (c3-'0');
    cout << A * B / 100 << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<ll>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;
  string S,x;
  cin>>S>>x;


  vector<bool> vert;

  rep(i,N){
    if(i==N-1) {vert.emplace_back(true); break;}
    if(S[i]!=S[i+1]) {
      vert.emplace_back(true);
    }
    else {
      vert.emplace_back(false);
      i++;
    }
  }

  ll ans=1;

  if(vert[0]){
    ans=3;
  }
  else{
    ans=3*2;
  }

  reps(i,1,vert.size()){
    if(vert[i]){
      if(vert[i-1]){
        ans=ans*2%MOD;
      }
    }
    else{
      if(vert[i-1]){
        ans=ans*2%MOD;
      }
      else{
        ans=ans*3%MOD;
      }
    }
  }

  cout<< ans<<"\n";


}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans[52][52],h,w;
int main(){
	char m[52][52];
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
		cin>>m[i][j];
		if(m[i][j]=='#')for(int k=i-1;k<=i+1;k++)for(int l=j-1;l<=j+1;l++)ans[k][l]++;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(m[i][j]!='#')printf("%d",ans[i][j]);
			else printf("#");
		}
		printf("\n");
	}
}

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

int main(){
  long long a,b,r,tmp;
  cin>>a>>b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  long long ans=1;
  for (long long i=2;i*i<=b;i++){
    if (b%i==0){
      ans++;
      while (b%i==0){
        b/=i;
      }
    }
  }
  if (b!=1){
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static void solve(int n, int[] b) {
    long sum = 0;
    for (int i = n - 2; i >= 0; i--) {
      sum += Math.min(b[i], b[i + 1]);
    }
    sum += b[0];
    System.out.println(sum);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String[] bs = sc.nextLine().split(" ");
    int[] b = new int[n];
    for (int i = 0; i < n - 1; i++) b[i] = Integer.parseInt(bs[i]);
    b[n - 1] = Integer.MAX_VALUE;
    sc.close();
    solve(n, b);
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second


int main(){
    fast;
    int a,b; cin >> a >> b;
    if(b%a == 0)
        cout << (ll)a+b << endl;
    else 
        cout << (ll)(b-a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    bool s[n][n];
    memset(s, 0, sizeof(s));

    int num[n];
    rep(i, n) {
        string temp;
        cin >> temp;
        int count = 0;
        rep(j, n) {
            if (temp[j] == '1') {
                s[i][j] = true;
                count++;
            }
        }
        num[i] = count;
    }

    int count_min = mod;
    rep(i, n) { count_min = min(count_min, num[i]); }

    vector<int> start_point;
    rep(i, n) {
        if (num[i] == count_min) {
            start_point.push_back(i);
        }
    }

    int ans = 0;
    rep(j, n) {
        int start = j;
        queue<int> q;

        int color[n];
        memset(color, 0, sizeof(color));
        color[start] = 1;
        q.push(start);

        while (!q.empty()) {
            int now = q.front();
            q.pop();
            rep(i, n) {
                if (s[now][i]) {
                    if (color[i] == 0) {
                        q.push(i);
                        color[i] = color[now] + 1;
                    } else if (color[i] != color[now] - 1 &&
                               color[i] != color[now] + 1) {
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
        int ans_temp = 0;
        rep(i, n) { ans_temp = max(ans_temp, color[i]); }
        ans = max(ans_temp, ans);
    }

    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


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

using namespace std;

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

  vector<int> a(n);
  int A = 0, B = 0;
  int maxi = -1, mini = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > 0 && a[i] > A) A = a[i], maxi = i;
    if (a[i] < 0 && a[i] < B) B = a[i], mini = i;
  }

  vector<int> x, y;
  if (abs(A) >= abs(B)) {
    for (int i = 0; i < n; i++) {
      if (a[i] >= 0) continue;
      x.push_back(maxi + 1);
      y.push_back(i + 1);
      a[i] += A;
    }
    for (int i = 0; i + 1 < n; i++) {
      if (a[i] <= a[i + 1]) continue;
      x.push_back(i + 1);
      y.push_back(i + 2);
      a[i + 1] += a[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] <= 0) continue;
      x.push_back(mini + 1);
      y.push_back(i + 1);
      a[i] += B;
    }
    for (int i = n - 1; i > 0; i--) {
      if (a[i - 1] <= a[i]) continue;
      x.push_back(i + 1);
      y.push_back(i);
      a[i - 1] += a[i];
    }
  }

  cout << x.size() << endl;
  for (int i = 0; i < x.size(); i++) {
    cout << x[i] << " " << y[i] << endl;
  }

  return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
int A[1100];
signed main() {
    cin >> N >> K;
    rep(i, N) { cin >> A[i]; }
    sort(A, A + N);
    int ans = 0;
    rep(i, K) { ans += A[i]; }
    cout << ans << endl;
}


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

int main() {
    int N;
    vector<int> X(200000);
    vector<int> Y(200000);
    cin >> N;
    for (int i=0;i<N;i++){
        cin >> X.at(i);
        Y.at(i) = X.at(i);
    }
    
    
    sort(Y.begin(),Y.end());
    reverse(Y.begin(),Y.end());

    //cout << X[0] << X[1] << X[2] << X[3] <<  endl;
    //cout << Y[0] << Y[1] << Y[2] << Y[3] << endl;

    for (int i=0;i<N;i++){
        if (X.at(i)>=Y.at(N/2-1)){
            cout << Y.at(N/2) << endl;
        }else{
            cout << Y.at(N/2-1) << endl;
        }
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
ll dp[2005][2005];
int main()
{
	sync;
	ll n;
	cin>>n;
	vector<pair<ll,ll> >v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i].F;
		v[i].S=i+1;
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ll val=v[i-1].F,idx=v[i-1].S;
		for(ll j=1;j<=i;j++)
		{
			dp[j][i-j]=max(dp[j][i-j],dp[j-1][i-j]+abs(j-idx)*val);
			dp[i-j][j]=max(dp[i-j][j],dp[i-j][j-1]+abs(n+1-j-idx)*val);		
		}
	}
	
	for(ll i=0;i<=n;i++)
		ans=max(ans,dp[i][n-i]);
		
	cout<<ans;
}

Measured memory_bytes: 26344
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef double lf;
const int N=111111;
int n;
int main(){
	scanf("%d",&n);
	int ok=0;
	rep(i,1,3500)rep(j,1,3500){
		if(ok)break;
		ll x=1ll*n*i*j,y=4*i*j-n*i-n*j;
		if(y&&x%y==0&&x/y>0){
			printf("%d %d %lld\n",i,j,x/y);
			ok=1;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

#define NUM 10000

int main(void){
  int a[NUM];
  int i = 0;
  int j;

  while(1){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      break;

    i++;
  }

  for(j = 0; j < i; j++){
    printf("Case %d: %d\n", j+1, a[j]);
  }

  return 0;
}

Measured memory_bytes: 1768
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c,d,p;
	int sumx,sumy;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	sumx=a*p;
	if(p<=c)
	sumy=b;
	else{
		p-=c;
		sumy=b+(p*d);
	}
	if(sumx>sumy)
	printf("%d\n",sumy);
	else
	printf("%d\n",sumx);
}

Measured memory_bytes: 3228
#include <stdio.h>
#include <string.h>
 
int read_line(char* out, size_t limit) {
    char* lf;
    if (fgets(out, limit, stdin) == NULL) return 0;
    if ((lf = strchr(out, '\n')) != NULL) *lf = '\0';
    return 1;
}
 
int main(void) {
    char str[1024];
    char command[4096];
    int q, query_count;
    if (!read_line(str, sizeof(str))) return 1;
    if (!read_line(command, sizeof(command)) || sscanf(command, "%d", &q) != 1) return 1;
    for (query_count = 0; query_count < q; query_count++) {
        int a, b;
        char *command_kind, *p;
        int i;
        if (!read_line(command, sizeof(command))) return 1;
        if ((command_kind = strtok(command, " ")) == NULL) return 1;
        if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &a) != 1) return 1;
        if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &b) != 1) return 1;
        if (strcmp(command_kind, "replace") == 0) {
            /* there doesn't seem a grantee that p consists of lowercase letters */
            if ((p = strtok(NULL, "")) == NULL) return 1;
            if (b < a || (size_t)(b - a + 1) != strlen(p)) return 1;
            memcpy(&str[a], p, b - a + 1);
        } else if (strcmp(command_kind, "reverse") == 0) {
            for (i = 0; a + i < b - i; i++) {
                char temp = str[a + i];
                str[a + i] = str[b - i];
                str[b - i] = temp;
            }
        } else if (strcmp(command_kind, "print") == 0) {
            for (i = a; i <= b; i++) putchar((unsigned char)str[i]);
            putchar('\n');
        } else return 1;
    }
    return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>
#include<math.h>

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

  min = a[0];
  max = a[1]-a[0];

  for(int i=1; i<n; i++){
    if((a[i]-min)>max){
      max=a[i]-min;
    }
    if(min>a[i]){
      min = a[i];
    }
  }

  printf("%d\n", max);

  return 0;

}



Measured memory_bytes: 2548
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	string s; cin >> s;
	
	int ok = 1, i = s.size() - 1;
	
	while(true){		
		if(i == -1){
			break;
		}else if(i >= 5 && s.substr(i-5, 6) == "eraser"){
			i -= 6;
		}else if(i >= 6 && s.substr(i-6, 7) == "dreamer"){
			i -= 7;
		}else if(i >= 4 && (s.substr(i-4, 5) == "dream" || s.substr(i-4, 5) == "erase")){
			i -= 5;
		}else{
			ok = 0;
			break;
		}
	}
	
	cout << (ok==1?"YES":"NO") << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

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

    for(int i = 0; i < k; i++) {
        if(i % 2 == 0) {
            if(a % 2 == 0) {
                b += a/2;
                a = a/2;
            } else {
                a--;
                b += a/2;
                a = a/2;
            }
        } else {
            if(b % 2 == 0) {
                a += b/2;
                b = b/2;
            } else {
                b--;
                a += b/2;
                b = b/2;
            }
        }
    }

    cout << a << " " << b << endl;
        return 0;


}

Measured memory_bytes: 256
a = gets.chomp!.to_i
b = gets.chomp!.to_i
c = gets.chomp!.to_i
d = gets.chomp!.to_i
e = gets.chomp!.to_i
k = gets.chomp!.to_i

if e - a > k then
    puts ":("
else
    puts "Yay!"
end


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

int main(void){
  int A, B;
  cin >> A >> B;
  bool exist = false;
  for(int C = 1; C <= 3; C++){
    if((A * B * C) % 2 != 0)
      exist = true;
  }
  if(exist) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
  int n,a[110],max = -1,min = 1000000010;

  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(a[i] > max)
      max = a[i];
    if(a[i] < min)
      min = a[i];
  }

  cout << max - min << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int H, N; cin >> H >> N;
  pii AB[N];
  rep(i,N) cin >> AB[i].first >> AB[i].second;
  vector<vector<int>> dp(N+1, vector<int>(H+1,1000000000)); // dp[i][h]: i番目までの魔法でhダメージ与えるときの魔力の最小値
  dp[0][0] = 0;
  rep(i,N){
    rep(j,H+1){
      dp[i+1][j] =  min(dp[i+1][j],dp[i][j]);
      dp[i+1][min(j+AB[i].first,H)] = min(dp[i+1][min(j+AB[i].first,H)], dp[i+1][j] + AB[i].second);
    }
  }
  cout << dp[N][H] << endl;
  




  // cout << fixed << setprecision(10);
  
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int v, w; };

int main() {
	int N; ll x; cin >> N >> x;
	ll z = 1;
	while (N--) z = min(z * 2, z + x);
	cout << z << endl;
}


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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var x = input[0];
        var y = input[1];

        Console.WriteLine(x + y / 2);
    }
}

Measured memory_bytes: 11348
class Cumsum2d(object):
    def __init__(self, a):
        self.a = a
        self.h = len(a)
        self.w = len(a[0])
        self._cumsum = [[0 for _ in range(self.w + 1)] for _ in range(self.h + 1)]
        self._preprocess()

    def _preprocess(self):
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                self._cumsum[i][j] = (
                    self.a[i - 1][j - 1]
                    + self._cumsum[i][j - 1]
                    + self._cumsum[i - 1][j]
                    - self._cumsum[i - 1][j - 1]
                )

    def query(self, h1, h2, w1, w2):
        return (
            self._cumsum[h2][w2]
            - self._cumsum[h1][w2]
            - self._cumsum[h2][w1]
            + self._cumsum[h1][w1]
        )


if __name__ == "__main__":
    N, M, Q = [int(x) for x in input().split(" ")]
    # L = [0 for _ in range(N + 2)]
    count = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
    for _ in range(M):
        l, r = [int(x) for x in input().split(" ")]
        count[l][r] += 1

    cumsum = Cumsum2d(count)
    for _ in range(Q):
        p, q = [int(x) for x in input().split(" ")]
        print(cumsum.query(p, q + 1, p, q + 1))


Measured memory_bytes: 20840
#include<iostream>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    while(n != 0 ||x != 0){
        int i,j,k,y=0;
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i + j + k == x) y++;
                }
            }
        }
        cout << y << endl;
        cin >> n >> x;
    }

return 0;
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000

typedef long long ll;
typedef pair<ll,ll> P;

int main()
{
	ll a,b;cin >> a >> b;
	
	ll ans = a*b;
	
	if(a == 1 && b == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	
	if(a == 1 || b == 1)
	{
		cout << max(a-2,b-2) << endl;
		return 0;
	}
	
	cout << max(0LL,(a-2)*(b-2)) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double> >q

#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    int n,cnt=0;
    string s;

    cin>>n>>s;
    int i=0;
int    j=s.size()-1;
    for(int i=0; i<j; i++)
    {
        if(s[i]=='W')
        {
            while(s[j]=='W'&&j>i)
                j--;
                if(s[j]=='R')
                {
                     cnt++;
                     swap(s[i],s[j]);
                }

        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3704
#include <stdio.h>

int main(void){
int n,k;
int p[1005];
int max=0;

scanf("%d %d",&n,&k);
for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
}
    for(int i=0;i<k;i++){
        int min=9999999;
        int minnum=0;
        for(int j=0;j<n;j++){
            if(p[j]<=min){
                min=p[j];
                minnum=j;
            }
        }
        max=max+min;
        p[minnum]=999999999;
    }
    printf("%d",max);

}


Measured memory_bytes: 1696
n = int(input())
l = []

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    l.append({'cost': a, 'deadline': b})

def solve(list):
    list_sorted = sorted(list, key=lambda x:x['deadline'])

    t = 0
    for i in list_sorted:
        t = t + i['cost']
        if t > i['deadline']:
            return False

    return True


print('Yes' if solve(l) else 'No')


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

int main()
{
  int N;

  cin >> N;

  vector<pair<int,int>> D(N);

  for(int i=0; i<N; ++i){
    cin >> D[i].first >> D[i].second;
  }

  for(int i=0; i<N-2; ++i){
    if(D[i].first == D[i].second && D[i+1].first == D[i+1].second && D[i+2].first == D[i+2].second){
      cout << "Yes" << endl;

      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int a, b, h; cin >> a >> b >> h;
    cout << (a + b) * h / 2;
    return 0;
}


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

char c[80][80];
struct str {
	string s;
	str(string s = "") :s(s) {}
}d[80][80];
bool operator<(str a, str b) {
	if (a.s.size() == b.s.size())return a.s < b.s;
	return a.s.size() < b.s.size();
}
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		rep(i, h)scanf("%s", c[i]);
		str Max = (string)"0";
		rep(i, h)rep(j, w) {
			if ('0' <= c[i][j] && c[i][j] <= '9') {
				d[i][j] = to_string(c[i][j] - '0');
				if (i)d[i][j] = max(d[i][j], str(d[i - 1][j].s + c[i][j]));
				if (j)d[i][j] = max(d[i][j], str(d[i][j - 1].s + c[i][j]));
				while (!d[i][j].s.empty() && d[i][j].s.front() == '0')d[i][j] = d[i][j].s.substr(1);
				Max = max(Max, d[i][j]);
			}
			else d[i][j] = (string)"";
		}
		cout << Max.s << endl;
	}
}

Measured memory_bytes: 3416
unittest
{
	assert( [ "4 4 2", "3413", "4121", "1424", "2312" ].parse.expand.solve == 23 );
	assert( [ "4 4 2", "1212", "2121", "1212", "2121" ].parse.expand.solve == 54 );
	assert( [ "7 7 2", "8989898", "9898989", "8989898", "9898989", "8989898", "9898989", "8989898" ].parse.expand.solve == 2520 );
	assert( [ "17 17 2", "12345678912345678", "23456789123456789", "34567891234567891", "45678912345678912", "56789123456789123", "67891234567891234", "78912345678912345", "89123456789123456", "91234567891234567", "12345678912345678", "23456789123456789", "34567891234567891", "45678912345678912", "56789123456789123", "67891234567891234", "78912345678912345", "89123456789123456" ].parse.expand.solve == 2354638 );
}



import std.algorithm;
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 hwk = input.front.split.to!( long[] );
	auto css = new long[][]( hwk[ 1 ], hwk[ 0 ] );		// css[0][0]を左下、css[w][h]を右上にする
	foreach_reverse( y; 0L .. hwk[ 0 ] )
	{
		input.popFront;
		foreach( x, c; input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).enumerate( 0L ) )
		{
			css[ x ][ y ] = c;
		}
	}
	return tuple( hwk[ 0 ], hwk[ 1 ], hwk[ 2 ], css );
}

auto solve( long h, long w, long k, long[][] css )
{
	auto ans = 0L;
	foreach( y; 0L .. h )
	{
		foreach( x; 0L .. w )
		{
			ans = max( ans, solve2( h, w, k, css.dup, x, y ) );
		}
	}
	return ans;
}

auto solve2( long h, long w, long k, long[][] css, long sx, long sy )
{
	css[ sx ] = css[ sx ][ 0 .. sy ] ~ css[ sx ][ sy + 1 .. $ ];
	
	auto st = 0L;
	for( auto i = 0L;; i++ )
	{
		auto s = 0L;
		foreach_reverse( y; 0L .. h )
		{
			for( auto lx = 0L, rx = 1L; lx < w; lx = rx, rx++ )
			{
				if( css[ lx ].length <= y ) continue;
				
				while( rx < w && y < css[ rx ].length && css[ lx ][ y ] == css[ rx ][ y ] ) rx++;
				
				auto n = rx - lx;
				if( k <= n )
				{
					s += css[ lx ][ y ] * n;
					foreach( cx; lx .. rx )
					{
						css[ cx ] = css[ cx ][ 0 .. y ] ~ css[ cx ][ y + 1 .. $ ];
					}
				}
			}
		}
		if( s == 0 ) break;
		st += s * 2 ^^ i;
	}
	return st;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b - 1);
  }
  sort(v.begin(), v.end(), [](auto a, auto b){return a.second < b.second;});
  int ans = 0, now = 0;
  for(int i = 0; i < m; i++){
    if(now < v[i].first){
      ans++;
      now = v[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    string s;
    cin >> s;
    bool consec = true;
    int counter = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R' && consec == true) {
            counter++;
        }
        else if (s[i] == 'S') {
            consec = false;
        }
        else {
            counter = 1;
            consec = true;
        }
    }
    cout << counter;
}

Measured memory_bytes: 3580
N, K, C = map(int, input().split())
S = input()

wd_e = []
wd_l = []

pre = -(C+1)
for i in range(N):
    if S[i] == 'o' and i-pre > C:
        wd_e.append(i)
        pre = i
    if len(wd_e) == K:
        break

pre = -(C+1)
S = S[::-1]
for i in range(N):
    if S[i] == 'o' and i-pre > C:
        wd_l.append(N-1-i)
        pre = i
    if len(wd_l) == K:
        break

for a, b in zip(wd_e, wd_l[::-1]):
    if a == b:
        print(a+1)

Measured memory_bytes: 22080
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  int a[Q];
  int p[N];
  for(int i = 0;i<Q;i++){
    cin>>a[i];
  }
  for(int i = 0;i<N;i++){
    p[i] = K;
  }
  for(int i = 0;i<Q;i++){
    p[a[i]-1]++;
  }

  for(int i = 0;i<N;i++){
    if((p[i]-Q)>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	int N, T, c, t, c_best = 1001;
	cin >> N >> T;
	for (int i = 0; i < N; i++)
	{
		int c, t;
		cin >> c >> t;
		if (t > T)
		{
			continue;
		}
		else if (c_best > c)
		{
			c_best = c;
		}
		else;
	}
	if (c_best == 1001)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << c_best << endl;
	}

	return 0;
}

Measured memory_bytes: 256