akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
int x,n,mn=1e7,ans=1e7,c[205]={0};
cin>>x>>n;
while(n--)
{
	int y;
	cin>>y;
	c[y]++;
	
}
rep(y,0,204)
{
	if(c[y])continue;
	if(abs(y-x)<mn)
	{
		mn=abs(y-x);
		ans=y;
	}
	else if(abs(y-x)==mn)
	{
		ans=min(ans,y);
	}
}
ol(ans);
return 0;
}



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

int main()
{
    int r, g, b, n, ans = 0;
    scanf("%d%d%d%d", &r, &g, &b, &n);
    for (int i = 0; i * r <= n; i++)
        for(int j = 0; j * g <= n; j++)
        {
            if ((n - i * r - j * g) < 0) continue;
            if ((n - i * r - j * g) % b) continue;
            ans++;
        }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
import sys
n, q = map(int, input().split())

S = [[] for _ in range(n)]
ans =[]

for _ in range(q):
    query = list(map(int, sys.stdin.readline().split()))
    if query[0] == 0:
        S[query[1]].append(query[2])
    elif query[0] == 1:
        if S[query[1]]:
            ans.append(S[query[1]][-1])
            # print(S[query[1]][-1])
    else:
        if S[query[1]]:
            S[query[1]].pop()

for i in ans:
    print(i)


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

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> ans(n+1);
    rep(i, n){
        ans[a[i]] = i+1;
    }

    for(int i=1; i<=n; i++){
        cout << ans[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pii> X;
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;

        X.push_back(make_pair(x+y, x-y));
    }
    SORT(X);
    int ans = 0;
    int cur = -1000000000;
    for (int i = 0; i < N; ++i) {
        if (cur <= X[i].second) {
            ans++;
            cur = X[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

set<PII> se;
void move(string c, int num, PII &p) {
    if (c == "N") {
        REP(i, num) {
            p.second++;
            if(FIND(se, p)) se.erase(p);
        }
    }
    if (c == "S") {
        REP(i, num) {
            p.second--;
            if(FIND(se, p)) se.erase(p);
        }
    }
    if (c == "W") {
        REP(i, num) {
            p.first--;
            if(FIND(se, p)) se.erase(p);
        }
    }
    if (c == "E") {
        REP(i, num) {
            p.first++;
            if(FIND(se, p)) se.erase(p);
        }
    }
}

void solve(int N) {
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        se.insert(MP(x, y));
    }
    int M; cin >> M;
    PII robo = MP(10, 10);
    REP(i, M) {
        string c;
        int num;
        cin >> c >> num;
        move(c, num, robo);
    }
    if (se.size() == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" <<endl;
    }
}

int main(void) {
    int n, p, m;
    string s;
    int a, b, c;
    while (cin >> n) {
        if (n == 0) return 0;
        solve(n);
        se.clear();
        //return 0;
    }
}

Measured memory_bytes: 3124
#include <deque>
#include <vector>
#include <iostream>
#include <cassert>

using namespace std;

template<typename T>
class matrix2d {
public:
	matrix2d(size_t width, size_t height) : width_(width), height_(height), data_(width*height, T()) {}

	T&       at(size_t x, size_t y)       { return data_[width_ * y + x]; }
	const T& at(size_t x, size_t y) const { return data_[width_ * y + x]; }

	size_t width()  const { return width_; }
	size_t height() const { return height_; }

private:
	size_t width_;
	size_t height_;
	deque<T> data_;
};

class block {
public:
	block(size_t width, size_t height, const char *blocks) : data_(width, height) {
		for (size_t y = 0; y < height; y++) {
			for (size_t x = 0; x < width; x++) {
				data_.at(x, y) = (blocks[width * y + x] == '1') ? 1 : 0;
			}
		}
		assert(blocks[width*height] == 0);
	}

	int&       at(size_t x, size_t y)       { return data_.at(x, y); }
	const int& at(size_t x, size_t y) const { return data_.at(x, y); }

	size_t width() const { return data_.width(); }
	size_t height() const { return data_.height(); }

private:
	matrix2d<int> data_;
};

class field {
public:
	field(size_t width, size_t height) : data_(width, height) {}

	int& at(size_t x, size_t y) { return data_.at(x, y); }

	bool contains(const block& b) const {
		for (int y = 0; y < data_.height(); y++) {
			for (int x = 0; x < data_.width(); x++) {
				if (x + b.width() > data_.width()) {
					break;
				}
				if (match(b, x, y)) {
					return true;
				}
			}
			if (y + b.height() > data_.height()) {
				break;
			}
		}
		return false;
	}

private:
	bool match(const block& b, int left, int top) const {
		for (int dy = 0; dy < b.height(); dy++) {
			for (int dx = 0; dx < b.width(); dx++) {
				if (data_.at(left + dx, top + dy) != b.at(dx, dy)) {
					return false;
				}
			}
		}
		return true;
	}

	matrix2d<int> data_;
};

typedef pair<block, char> block2name;

block2name make_block(const char* data, size_t width, size_t height, char name) {
	return make_pair(block(width, height, data), name);
}

int main(void) {
	vector<block2name> blocks;

	blocks.push_back(make_block(
		"11"
		"11", 2, 2, 'A'));

	blocks.push_back(make_block(
		"1"
		"1"
		"1"
		"1", 1, 4, 'B'));

	blocks.push_back(make_block(
		"1111", 4, 1, 'C'));

	blocks.push_back(make_block(
		" 1"
		"11"
		"1 ", 2, 3, 'D'));

	blocks.push_back(make_block(
		"11 "
		" 11", 3, 2, 'E'));

	blocks.push_back(make_block(
		"1 "
		"11"
		" 1", 2, 3, 'F'));

	blocks.push_back(make_block(
		" 11"
		"11 ", 3, 2, 'G'));

	while (!cin.eof()) {
		field f(8, 8);
		char c;	
		for (int y = 0; y < 8; y++) {
			for (int x = 0; x < 8; x++) {
				cin >> c;
				f.at(x, y) = (c == '1') ? 1 : 0;
			}
		}

		for (int i = 0; i < blocks.size(); i++) {
			if (f.contains(blocks[i].first)) {
				cout << blocks[i].second << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1176
def run():
    N = int(input())
    for _ in range(N):
        x = int(input())
        y = int(input())
        if 80 < len(str(x)) or 80 < len(str(y)) or 80 < len(str(x+y)):
            print('overflow')
        else:
            print(x+y)

if __name__ == '__main__':
    run()




Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  string s;
  cin >> s;
  i64 c1 = 0, c2 = 0;
  for (i64 i = 0; i < s.size(); ++i) {
    if (s[i] == '0') ++c1; else ++c2;
    swap(c1, c2);
  }
  cout << min(c1, c2) << '\n';
  return 0;
}


Measured memory_bytes: 512
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        _n: usize,
        s: String,
    }
    let mut x = 0i32;
    let mut y = 0i32;
    for c in s.chars() {
        if 'A' <= c && c <= 'M' {
            x += 1;
        } else if 'N' <= c && c <= 'Z' {
            x -= 1;
        } else if 'a' <= c && c <= 'm' {
            y += 1;
        } else {
            y -= 1;
        }
    }
    let mut ans = String::new();
    while x > 0 {
        x -= 1;
        ans.push('A');
    }
    while x < 0 {
        x += 1;
        ans.push('Z');
    }
    while y > 0 {
        y -= 1;
        ans.push('a');
    }
    while y < 0 {
        y += 1;
        ans.push('z');
    }
    println!("{}\n{}", ans.len(), ans);
}

fn main() {
    run();
}



Measured memory_bytes: 5036
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

s = []
for x in range(X) :
    for y in range(Y) :
        s.append(A[x]+B[y])
s.sort(reverse=True)

t = []
for k in range(min(K, len(s))) :
    for z in range(Z) :
        t.append(s[k]+C[z])
        
t.sort(reverse=True)

print("\n".join(map(str, t[:K])))

Measured memory_bytes: 149612
#include <cstdio>
#include <cstring>

using namespace std;

char ans[2][205];
char q[4];

void set_value(int pos, int val){
    if(val == 0 || val == 1){
        ans[0][pos] = '.';
    }else{
        ans[0][pos] = '#';
    }
    if(val == 0 || val == 3){
        ans[1][pos] = '.';
    }else{
        ans[1][pos] = '#';
    }
}

int main(){
    int N;

    scanf("%d",&N);

    int start = N,end = N;
    memset(ans,0,sizeof ans);

    for(int i = 0;i < 4;++i){
        set_value(end,i);
        printf("%s\n%s\n",ans[0] + start,ans[1] + start);
        fflush(stdout);
        scanf("%s",q);
        if(q[0] == 'T' || q[0] == 'e'){
            ++end;
            break;
        }
    }

    if(q[0] == 'e'){
        return 0;
    }

    bool found = true;
    while(found){
        found = false;
        for(int i = 0;i < 4;++i){
            set_value(end,i);
            printf("%s\n%s\n",ans[0] + start,ans[1] + start);
            fflush(stdout);
            scanf("%s",q);
            if(q[0] == 'T' || q[0] == 'e'){
                found = true;
                ++end;
                break;
            }
        }

        if(q[0] == 'e'){
            return 0;
        }
    }

    ans[0][end] = ans[1][end] = 0;

    found = true;
    while(found){
        found = false;
        --start;
        for(int i = 0;i < 4;++i){
            set_value(start,i);
            printf("%s\n%s\n",ans[0] + start,ans[1] + start);
            fflush(stdout);
            scanf("%s",q);
            if(q[0] == 'T' || q[0] == 'e'){
                found = true;
                break;
            }
        }

        if(q[0] == 'e'){
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 596
n,m=map(int,input().split())
mod=10**9+7
def c(a,b):
	r=fac[b]*fac[a-b]%mod
	return fac[a]*pow(r,mod-2,mod)%mod
def p(a,b):
	return c(a,b)*fac[b]%mod
fac=[1]
for i in range(m+2):
	fac.append(fac[-1]*(i+1)%mod)
ans=p(m,n)
for i in range(1,n+1):
	r=c(n,i)*p(m-i,n-i)%mod
	if i%2==1:
		ans-=r
	else:
		ans+=r
	ans%=mod
print(ans*p(m,n)%mod)

Measured memory_bytes: 104524
import sys
N = int(input())
word = input()
if word.count('W') == N:
  print(0)
  sys.exit()
num_R = word.count('R')
num_W,min_count= 0,float('inf')
for i in range(N):
  if word[i] == 'W':
    num_W += 1
  else:
    num_R -= 1
  min_count = min(min_count,max(num_W,num_R))
print(min_count)

Measured memory_bytes: 9436
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sqr(x) (x) * (x)
#define cube(x) (z) * (z) * (x)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}

signed main() {
  int N, K;
  cin >> N >> K;
  vector<char> D(K);
  rep(i, K) {
    cin >> D[i];
  }
  rep(i, 500000) {
    if (i >= N) {
      string temp = to_string(i);
      rep(j, temp.size()) {
        rep(k, D.size()) {
          if (temp[j] == D[k]) {
            goto out;
          } else if (j == temp.size() - 1 && k == D.size() - 1) {
            cout << i << endl;
            return 0;
          }
        }
      }
    }
  out:;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    int N,D,X,R = 0;
    vector<int> A;
    cin >> N >> D >> X;
    for(size_t i = 0;i < N;i++){
        int Ai;
        int ic = 0;
        cin >> Ai;
        for(size_t j = 0;j < D;j += Ai){
            ic ++;
        }
        R += ic;
    }
    cout << R + X;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define long long long long
using namespace std;
long long n,i,j,rt,cnt,l[200005],r[200005],sz[200005],rnd[200005];
long long ans,m,a[200005],val[200005];
long long nwnd(long long x)
{
	cnt++;
	l[cnt]=r[cnt]=0;
	sz[cnt]=1;val[cnt]=x;rnd[cnt]=rand()*32768+rand();
	return cnt;
}
void pushup(long long x)
{
	sz[x]=1+sz[l[x]]+sz[r[x]];
}
void split(long long x,long long y,long long &sl,long long &sr)
{
	if (!x)
	{
		sl=sr=0;
		return;
	}
	if (val[x]<=y)
	{
		split(r[x],y,r[x],sr);
		sl=x;
		pushup(x);
		return;
	}
	else
	{
		split(l[x],y,sl,l[x]);
		sr=x;
		pushup(x);
		return;
	}
}
long long merge(long long x,long long y)
{
	if (!x||!y) return x+y;
	if (rnd[x]>rnd[y])
	{
		r[x]=merge(r[x],y);
		pushup(x);
		return x;
	}
	else
	{
		l[y]=merge(x,l[y]);
		pushup(y);
		return y;
	}
}
int main()
{
	cin>>n>>m;
	fz1(i,n)
	{
		cin>>a[i];
		a[i]-=m;
		a[i]+=a[i-1];
	}
	rt=nwnd(0);
	fz1(i,n)
	{
		long long t1,t2;
		split(rt,a[i],t1,t2);
		ans+=sz[t1];
		rt=merge(merge(t1,nwnd(a[i])),t2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    X = int(input())
    l = [7,5,3]
    if X in l:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 5092
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string N, ABC;
    cin >> N;
    ABC = "ABC";
    cout << ABC << N << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N;
	cin >> N;
	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	ll M = 1000000;
	vector<ll> c(M+1, 0);
	repn(i, N) c[A[i]]++;

	vector<vector<ll>> div(M+1);
	repn(i, M) {
		for (ll j = i * 2; j <= M; j += i)div[j].push_back(i);
	}

	ll ans = 0;

	repn(i, N) {
		//cout << i << endl;
		if (c[A[i]] > 1) { continue; }
		ll b = 1;
		for (ll j : div[A[i]]) {
			if (c[j] > 0) { b = 0; }
			//cout << j <<" "<< c[j] << endl;
		}

		ans += b;
		
	}

	cout << ans << endl;

}

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

int main(void){
    string s;
    char c[4] = {'A','C','T','G'};
    cin >> s;
    int max = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] != c[0] && s[i] != c[1] && s[i] != c[2] && s[i] != c[3])continue;
        int a = 1;
        for(int j = i+1;j < s.size();j++){
            if(s[j] != c[0] && s[j] != c[1] && s[j] != c[2] && s[j] != c[3])break;
            a++;
        }
        if(max < a)max = a;
    }
    cout << max;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest 095 - Problem A: Something on It (https://atcoder.jp/contests/abc095/tasks/abc095_a)
#include <bits/stdc++.h>

using namespace std;

int solve(const string S)
{
    int ans = 700;

    for (auto c : S)
        ans += (c == 'o' ? 100 : 0);

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    auto ans = solve(S);

    cout << ans << '\n';

    return 0;
}


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

int main(){
  long long int N, norma = 0, ans = 0, ans2 = 0;
  cin >> N;
  vector<int> A(N), B(N), sabun(N);
  
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  for (int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  
  for (int i = 0; i < N; i++){
    sabun.at(i) = B.at(i) - A.at(i);
    if (B.at(i) - A.at(i) > 0){
      norma += B.at(i) - A.at(i);
      ans++;
    }
  }
  
  sort(sabun.begin(), sabun.end());
  
  while (norma > 0 && ans2 < N){
    norma += sabun.at(ans2);
    ans2++;
  }
  
  if (norma > 0){
    cout << "-1" << endl;
  }
  else{
	cout << ans + ans2 << endl;
  }
}

Measured memory_bytes: 4516
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	int k , n , m;
	cin >> k >> n >> m;
	bool ok = 0;
	int cnt = k;
	while(1){
		if(k >= n && k <= m){
			ok = 1;break;
		}
		k += cnt;
		if(k > m)break;
	}
	puts(ok?"OK":"NG");
	return 0;
}

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

typedef long long LL;
typedef pair<LL,LL> PII;

int main() {
	LL N;
	cin >> N;
	/*
	LL left = 0, right = N;
	
	while(true) {
		
		
	}*/
	vector<int> ans;
	
	for(int i=0; i<=N; i++) {
		if(i * (i + 1) / 2  >= N) {
			int cur = i;
			ans.push_back(cur);
			
			int remain = N - cur;
			for(int j=cur-1; j>=1; j--) {
				if(remain>=j) {
					ans.push_back(j);
					remain -= j;
				}
			}
			
			break;
		}
		
	}
	/*
	if(N==1) {
		ans.push_back(1);
	}*/
	for(int i=0; i<ans.size(); i++) {
		cout << ans[i] << endl;
//		if(i < ans.size()-1) cout << " ";
//		else cout << endl;
	}
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get() {}template<class H, class...T>void get(H&h, T&...t) { cin >> h; get(t...); }
template<class T>void geti(T&a) { for (auto&_ : a)cin >> _; }
template<class T>void getii(T&a) { for (auto&_ : a)geti(_); }
void put(string d) {}template<class H, class...T>void put(string d, H&h, T&...t) { cout << h; if (sizeof...(t))cout << d; put(d, t...); }
template<class T>void puti(T&a, string d = " ") { bool f = 1; for (auto&_ : a)cout << (exchange(f, 0) ? "" : d) << _; cout << endl; }
template<class T>void putii(T&a, string d = " ") { for (auto&_ : a)puti(_, d); }
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

int main() {
    int a, b,c;
    cin >> a >> b >> c;
    cout << (((a + b - c) < 0) ? "No" : "Yes");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,r,k,t1,t2;
  cin >> n;
  int graph[n+1][n+1];
  for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      graph[i][j] = 1000000;
    }
  }

  for(int i=0;i<n;i++){
    cin >> r >> k;
    int t;
    for(int j=0;j<k;j++){
      cin >> t;
      graph[r][t] = 1;
    }
  }


  //ワーシャルフロイド
  for(int k=1;k<n+1;k++){
    for(int i=1;i<n+1;i++){
      for(int j=1;j<n+1;j++){
	graph[i][j] = min( graph[i][j] , graph[i][k] + graph[k][j]);
      }
    }
  }


  int p;
  cin >> p;
  for(int i=0;i<p;i++){
    int s,d,v;
    cin >> s >> d >> v;
    if(v-graph[s][d] <= 0) cout << "NA" << endl;
    else cout << graph[s][d]+1 << endl;
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b,n;
	cin>>a>>b>>n;
		if(n>=b-1){
			n=b-1;
		}
		cout << (a*n)/b-a*(n/b);
	// your code goes here
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bits/stdc++.h>
#include <set>
#include <vector>
#include <queue>
#include <bitset>
#define NL << endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define fill(x, y) memset(x, y, sizeof(y))
#define debug(x)                          \
    {                                     \
        cerr << #x << " = " << x << endl; \
    }
#define inarr(arr, n)                            \
    {                                       \
        for(int i =0;i<n;i++){              \
            cin >> arr[i];                  \
        }                                   \
    }
#define out(a) cout << a << endl;
typedef long long ll;
const int MOD = 1e9 + 7;
using namespace std;

void solve()
{
    string s; cin >> s;
    if(s=="RRR"){
        out(3);
    }
    else if(s=="RRS" || s == "SRR"){
        out(2);
    }
    else if(s=="SSS"){
        out(0);
    }
    else{
        out(1);
    }
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; t = 1; 
    // int t; cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3532
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  a1 <- getIntList
  a2 <- getIntList
  a3 <- getIntList
  n <- getInt
  bs <- replicateM n getInt

  let a4 = [a1 !! 0, a2 !! 0, a3 !!0]
      a5 = [a1 !! 1, a2 !! 1, a3 !!1]
      a6 = [a1 !! 2, a2 !! 2, a3 !!2]
      a7 = [a1 !! 0, a2 !! 1, a3 !!2]
      a8 = [a1 !! 2, a2 !! 1, a3 !!0]

  putStrLn $ check [a1, a2, a3, a4, a5, a6, a7, a8] bs

  where
    check [] _ = "No"
    check (a:as) bs = let c0 = (a!!0) `elem` bs
                          c1 = (a!!1) `elem` bs
                          c2 = (a!!2) `elem` bs
                      in
                        if c0 && c1 && c2
                        then "Yes"
                        else check as bs

Measured memory_bytes: 380
#include <iostream>

using namespace std;

int opss[8] = {0, 1, 2, 3, 4, 5, 6, 7};
int a[4];

int main() {
    // Input
    string line; cin >> line;
    for(int i = 0; i < 4; ++i) a[i] = line[i] - '0';

    for(int i = 0; i < 8; ++i) {
        int ops = opss[i];
        int sum = a[0];

        for(int j = 1; j < 4; ++j) {
            // 1の場合+, 0の場合-
            if(ops & 1) sum += a[j];
            else sum -= a[j];

            ops >>= 1;
        }

        ops = opss[i];

        if(sum == 7) {
            cout << a[0];
            for(int j = 0; j < 3; ++j) {
                if(ops & 1) cout << '+';
                else cout << '-';
                cout << a[j+1];
                ops >>= 1;
            }
            cout << "=7" << endl;
            break;
        }
    }
}


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

void solve(istream& cin, ostream& cout) {
  int a, b, k;
  cin >> a >> b >> k;

  int i = 0;
  int j = min(a, b) + 1;
  while (i < k) {
    j--;
    if (a % j == 0 && b % j == 0) {
      i++;
    }
  }
  cout << j << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
// ****  All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define fl(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define fi(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> dmap;
typedef set<int> dset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
/********** solver function **********/
// vector<string> ans;
// void solve(string &a, string &b, int i, int j, string s){
//     if( i==a.size() && j==b.size()){ ans.push_back(s); return;}
//     if( i>=a.size() || j>=b.size()) return;
//     if( a[i]==b[j]){
//             s.push_back(a[i]);
//             solve( a, b, i+1, j+1, s);
//             s.pop_back();
//     }
//     else{
//         solve( a, b, i+1, j, s);
//         solve( a,b,i, j+1,s);
//     }
// }
/********** Main()  function **********/
int main()
{std::ios::sync_with_stdio(false);
	string a;
    string b;
    cin>>a>>b;
    vector<vector<int>>dp(a.size()+1, vector<int>(b.size()+1, -1));
    for( int i=0; i<dp.size(); i++){
        dp[i][0]=0;
        // dp[i][0]=0;
    }
    for( int i=0;i<dp[0].size();i++){
        dp[0][i]=0;
    }
    for( int i=1;i<dp.size();i++){
        for( int j=1;j<dp[0].size();j++){
            if( a[i-1]==b[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else{ dp[i][j]= max( dp[i-1][j], dp[i][j-1]); }
        }
    }
    string ans;
    int i=dp.size()-1, j=dp[0].size()-1;
    while( i>0 && j>0){
            if( b[j-1]==a[i-1]){ ans.push_back(a[i-1]); i--; j--;}
            else{
                int x=dp[i-1][j]; int y=dp[i][j-1];
                if( x>y) {i--;}
                else{
                    j--;
                }
            }

        }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
    // solve( a, b, 0,0,"");
    // sort(ans.begin(), ans.end());
    // cout<<"ans-"<< ans[ans.size()-1]<<" | ";
    // for( int i=0;i<ans.size();i++){
    //     cout<<ans[i]<<" ";
    // }
	// return 0;
}

Measured memory_bytes: 38112
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 1e5 + 10;

ll k;
const int n = 50;
ll a[n + 1];

void simulate(ll a[], int n, int times) {
	while (times--) {
		int maxi = max_element(a + 1, a + n + 1) - a;
		for (int i = 1; i <= n; i++) {
			if (i == maxi) a[i] -= n;
			else a[i]++;
		}
	}
}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> k;

	ll init = (n - 1) + (k + n - 1) / n;
	fill(a + 1, a + n + 1, init);

	ll need = (init - (n - 1)) * n;
	simulate(a, n, need - k);

	cout << n << endl;
	for (int i = 1; i <= n; i++)
		cout << a[i] << " ";
 
	return 0;
}

Measured memory_bytes: 256
/**
    A	Darker and Darker    	C++14 (GCC 5.4.1)
    Accept
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int r ;
    cin >> r ;
    cout << 3 * r * r << endl;
    return 0;
}

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



int main(){
  string a,b;
  cin>>a>>b;
  int c[10000]={};
  c[0]=1;
  for(int i=0;i<a.size();i++){
    for(int t=b.size()-1;t>=0;t--){
      if(a[i]==b[t]){
	c[t+1]+=c[t];
	c[t+1]=c[t+1]%1000000007;
      }
    }
  }

  /*
  for(int i=0;i<b.size()+10;i++){
    cout<<c[i]<<endl;
  }
  */
  
  cout<<c[b.size()]<<endl;
  return 0;
}



Measured memory_bytes: 3240
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int n = sc.nextInt();
        int kosuu = 0;
        for(int i = 1; i <= n; i++){
          int a = sc.nextInt();
        	if(i%2 != 0 && a%2 != 0){
                	kosuu += 1;
            }        
        }

			System.out.println(kosuu);
		
	}
}

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

vector<P>E[200000];
int s[4];
ll d[4][200000];
ll dp[200000];
int n,m;

ll solve(){
	ll Min=LLONG_MAX;
	memset(dp,0x3f,sizeof(dp));
	dp[s[0]]=d[2][s[0]];
	vector<int>v;
	rep(i,n)v.push_back(i);
	sort(v.begin(),v.end(),[&](int a,int b){return d[0][a]<d[0][b];});
	for(int i:v){
		if(d[0][i]+d[1][i]!=d[0][s[1]])continue;
		dp[i]=min(dp[i],d[2][i]);
		Min=min(Min,dp[i]+d[3][i]);
		for(auto u:E[i]){
			if(d[0][u.second]==d[0][i]+u.first){
				dp[u.second]=min(dp[u.second],dp[i]);
			}
		}
	}
	return Min;
}
int main(){
	cin>>n>>m;
	rep(i,4)cin>>s[i],s[i]--;
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		E[a].push_back(P(c,b));
		E[b].push_back(P(c,a));
	}
	memset(d,0x3f,sizeof(d));
	rep(i,4){
		priority_queue<P,vector<P>,greater<P>>que;
		d[i][s[i]]=0;que.push(P(0,s[i]));
		while(!que.empty()){
			P p=que.top();que.pop();
			if(d[i][p.second]!=p.first)continue;
			for(auto u:E[p.second]){
				if(d[i][u.second]>p.first+u.first){
					d[i][u.second]=p.first+u.first;
					que.push(P(d[i][u.second],u.second));
				}
			}
		}
	}
	ll ans=min(d[2][s[3]],solve());
	swap(s[2],s[3]);
	rep(i,n)swap(d[2][i],d[3][i]);
	ans=min(ans,solve());
	cout<<ans<<endl;
}


Measured memory_bytes: 27312
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, Y;
  cin >> N >> Y;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (i + j > N) continue;

      int k = N - (i + j);
      if (i * 10000 + j * 5000 + k * 1000 == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


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

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

using namespace std;

int main() {
  int n;  
  cin>>n;
 vector<int> a(n);

  rep(i,n) {cin>>a[i];}
  int ans=0;
   ////////////
  bool hueru=false,heru=false;
  rep(i,n-1){
        
   	if(!heru&&a[i]<a[i+1]){
     	hueru=true;
     continue;
   	}
   	if( hueru&&a[i]>a[i+1]){
  		
       	   ans++;
    	 hueru=false;
     	continue;
     	   }
   
   	if(a[i]>a[i+1]){
    	 heru=true;
      continue;
  	}
  	if( heru&&a[i]<a[i+1]){
  		
    	      ans++;
    	 heru=false;
    	 continue;
     	   }
    
  }  
  
  
  
  ans++;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  1000LL
#define tmod            998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
t= q;
while(q--)
{
    ll n,m,k,i,j,l,r,c=0,g,counter=0,u,v,d,e,w,p,x,y,flag=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n ;
    vector<ll> A(n),B(n);
    B[0] = 1e15;
    CIN(B,0,n-1);
    A[0] = B[0];
    B[n-1] = 1e15;
    for(i=1;i<n;i++)
    {
        A[i] = min(B[i],B[i-1]);
    }
    ll sum=0;
    for(i=0;i<n;i++) sum += A[i];

    cout << sum << endl;
}
    return 0;
}

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

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}


Measured memory_bytes: 256
n = int(input())
deg = [0]*n
child, parent = {}, {}
sib = [None]*n
for i in range(n):
    a = list(map(int, input().split()))
    if a[1] != -1:
        if a[2] == -1:
            child[a[0]] = [a[1]]
            sib[a[1]] = a[2]
            deg[a[0]] = 1
        else:
            child[a[0]] = a[1:]
            sib[a[1]] = a[2]
            sib[a[2]] = a[1]
            deg[a[0]] = 2
        for j in child[a[0]]:
            parent[j] = a[0]
    elif a[2] != -1:
        child[a[0]] = [a[2]]
        sib[a[2]] = a[1]
        deg[a[0]] = 1
        for j in child[a[0]]:
            parent[j] = a[0]
    else:
        child[a[0]] = []

root = (set(child)-set(parent)).pop()
depth = [None]*n
depth[root] = 0
hei = [None]*n
parent[root] = -1
sib[root] = -1

def dfs(s):
    if len(child[s]) == 0:
        hei[s] = 0
        return
    for i in child[s]:
        depth[i] = depth[s] + 1
        dfs(i)
    hei[s] = max(hei[i] for i in child[s]) + 1
    
    
dfs(root)

for i in range(n):
    node_type = 'root' if parent[i] == -1 else 'leaf' if len(child[i]) == 0 else 'internal node'
    print(f'node {i}: parent = {parent[i]}, sibling = {sib[i]}, degree = {deg[i]}, depth = {depth[i]}, height = {hei[i]}, {node_type}')   
    


Measured memory_bytes: 5640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int a,b;
  cin>>a>>b;
  cout<<(b-1+a-1-1)/(a-1)<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r,a;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r<0)
		a=0;
	else if(y-r<0)
		a=0;
	else if(x+r>W)
		a=0;
	else if(y+r>H)
		a=0;
	else
		a=1;
	if(a==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 584
import java.util.*;

class Main{
    int h, w;
    int[] dx = {1, -1, 0, 0};
    int[] dy = {0, 0, 1, -1};
    char[][] map;

    void solve(){
        Scanner sc = new Scanner(System.in);

        h = sc.nextInt(); w = sc.nextInt(); int n = sc.nextInt();
        map = new char[h][w];
        int[][] zahyo = new int[n+1][2];
        int sx = 0, sy = 0;
        for(int i=0; i<h; i++){
            char[] line = sc.next().toCharArray();
            for(int j=0; j<w; j++){
                map[i][j] = line[j];
                if(map[i][j]=='S') {sx = j; sy = i;}
                if(Character.isDigit(map[i][j])) zahyo[map[i][j]-'0'] = new int[]{j, i};
            }
        }

        int sum = 0;
        for(int i=1; i<=n; i++){
            if(i==1) sum += bfs(sx, sy, zahyo[i][0], zahyo[i][1]);
            else sum += bfs(zahyo[i-1][0], zahyo[i-1][1], zahyo[i][0], zahyo[i][1]);
        }
        System.out.println(sum);
    }

    int bfs(int sx, int sy, int gx, int gy){
        LinkedList<int[]> q = new LinkedList<int[]>();
        boolean[][] v = new boolean[h][w];
        q.add(new int[]{sx, sy, 0});

        while(q.size()>0){
            int[] qq = q.poll();
            int x = qq[0], y = qq[1], cnt = qq[2];

            if(x==gx && y==gy) return cnt;
            if(v[y][x]) continue;
            v[y][x] = true;

            for(int i=0; i<4; i++){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h || map[ny][nx]=='X') continue;
                q.add(new int[]{nx, ny, cnt+1});
            }
        }
        return -1;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 127292
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    cout << (x ^ 1) << "\n";
}

Measured memory_bytes: 3640