akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;


int main() {
    string s;
    cin >> s;
    if (s == "SAT")cout << 1 << endl;
	if (s == "SUN")cout << 7 << endl;
	if (s == "MON")cout << 6 << endl;
	if (s == "TUE")cout << 5 << endl;
	if (s == "WED")cout << 4 << endl;
	if (s == "THU")cout << 3 << endl;
	if (s == "FRI")cout << 2 << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT

ll A,B,N;

ll f(ll x) {
  return (A*x) / B - A * (x/B);
}

signed main() {
  cin >> A >> B >> N;
  ll x = N;
  if (N >= B-1)
    x = B-1;
  cout << f(x) << endl;
  return 0;
}


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

#define F first
#define S second
#define int long long
#define inf 1000000000000000001
#define mod 1000000007


using namespace std;

signed main(){
    int n;
    cin >> n;
    vector<int> st(n), en(n);
    for (int i = 0; i < n; i++){
        cin >> st[i] >> en[i];
    }
    sort(st.begin(), st.end());
    sort(en.begin(), en.end());
    if (n % 2 == 1){
        int mn = st[n/2];
        int mx = en[n/2];
        cout << mx-mn+1 << endl;
    } else {
        double mn = ((double)st[n/2-1]+st[n/2])/2;
        double mx = ((double)en[n/2-1]+en[n/2])/2;
        if (mn == mx){
            cout << 1 << endl;
            return 0;
        } else if (mx-mn == 0.5){
            cout << 2 << endl;
            return 0;
        }
        //cout << mn << " " << mx << endl;
        int ans = (ceil(mn) != floor(mn)) + (ceil(mx) != floor(mx));
        //cout << ans << endl;
        mn = ceil(mn);
        mx = floor(mx);
        ans += mx-mn+1;
        ans += mx-mn;
        cout << ans << endl;
    }
    return 0;
}























Measured memory_bytes: 6380
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll H,W;
  cin>>H>>W;
  char a[200][200];
  for(int i=0;i <H+2; ++i){
    for(int j = 0; j<W+2; j++){
    a[i][j]='#';
    }
}
  for(int i=1; i<=H; ++i){
    for(int j = 1; j<=W; ++j){
    cin>>a[i][j];
    }
}
for(int i=0; i<=H+1; ++i){
  for(int j = 0; j<=W+1; ++j){
  cout<<a[i][j];
  }
  cout<<endl;
}
}

  


Measured memory_bytes: 256
n, m, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

lst = []
def generate(l):
    global lst, n, m
    if len(l) == n:
        lst.append(l)
        return 0
    if l == []:
        for i in range(1,m+1):
            generate([i])
        return 0
    for i in range(l[-1], m+1):
        t = l + [i]
        generate(t)

generate(lst)    

ans = 0
for A in lst:
    kari = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c:
            kari += d
    ans = max(ans, kari)
        
print(ans)
    

Measured memory_bytes: 22856
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL X,Y;
    R(X,Y);
    int an=0;
    while(X<=Y){
        an++;
        X*=2;
    }
    W(an);
    return 0;
}


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

int main() {
    int n, m;
    
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) cin >> blue.at(i);

    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) cin >> red.at(i);

    int max = 0;
    for (int i = 0; i < n; i++) {
        int mon = 0;
        for (int j = 0; j < n; j++) {
            if (blue.at(i) == blue.at(j)) mon++; 
        }
        for (int j = 0; j < m; j++) {
            if (blue.at(i) == red.at(j)) mon--;
        }
        if (max < mon) max = mon;
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,a[10000],min=1000000,max=-1000000,i;
	long s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		s+=a[i];
		min>a[i]?min=a[i]:0;
		max<a[i]?max=a[i]:0;
	}
	printf("%d %d %ld\n",min,max,s);
	return 0;
}


Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, p; cin >> a >> p;
	printf("%d", (3 * a + p) / 2);
	return 0;
}

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

const int maxn = 5010;

int n, m, a[3], b[3];
int ab[maxn];
long long ba[maxn*maxn];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < 3; ++i) scanf("%d", a+i);
	for (int i = 0; i < 3; ++i) scanf("%d", b+i);
	for (int i = 1; i <= n; ++i) {
		ab[i] = ab[i-1];
		for (int j = 0; j < 3; ++j) if (a[j] <= i) {
			ab[i] = max(ab[i], ab[i-a[j]]+(b[j]-a[j]));
		}
	}
	m = n+ab[n];
	for (int i = 1; i <= m; ++i) {
		ba[i] = ba[i-1];
		for (int j = 0; j < 3; ++j) if (b[j] <= i) {
			ba[i] = max(ba[i], ba[i-b[j]]+(a[j]-b[j]));
		}
	}
	printf("%lld\n", m+ba[m]);
}


Measured memory_bytes: 195584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b;
  while(1){
    cin>>a>>b;
    if(a+b==0)break;
    if(a%2&&b%2)cout<<"no"<<endl;
    else cout<<"yes"<<endl;
  }
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N, K, S; cin >> N >> K >> S;
    int ts;
    if (S != 1e+9) {
        ts = S+1;
    } else {
        ts = 1;
    }
    // K個 Sを出力
    rep(i, K) {
        cout << S << " ";
    }
    repr(i, K, N) {
        cout << ts << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String n = stdIn.next();
        String t = stdIn.next();
        int answer = 0;
        for(int i = 0; i < 3; i++){
            if(n.charAt(i) == t.charAt(i)) answer++; 
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

template <class Abel>
struct UnionFind
{
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;

  UnionFind(int n = 1, Abel SUM_UNITY = 0)
  {
    init(n, SUM_UNITY);
  }

  void init(int n = 1, Abel SUM_UNITY = 0)
  {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }

  int root(int x)
  {
    if (par[x] == x)
    {
      return x;
    }
    else
    {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  Abel weight(int x)
  {
    root(x);
    return diff_weight[x];
  }

  bool issame(int x, int y)
  {
    return root(x) == root(y);
  }

  bool merge(int x, int y, Abel w)
  {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y), w = -w;
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }

  Abel diff(int x, int y)
  {
    return weight(y) - weight(x);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  UnionFind<int> uf(N);
  for (int i = 0; i< M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    if (uf.issame(l, r)) {
      int diff = uf.diff(l, r);
      if (diff != d) {
        cout << "No" << endl;
        return 0;
      }
    } else {
      uf.merge(l, r, d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}

// 重み付きUnion-Find木　ノード間の距離も管理することが出来る．diff(x, y): xとyとが同じグループにいるときweight(y) - weight(x)をリターンする．merge(x, y, w): weight(y) = weight(x) + wとなるようにxとyをマージする


Measured memory_bytes: 4472
S = list(input())
head = int(S[0] + S[1])
tail = int(S[2] + S[3])
minN = min(head, tail)
maxN = max(head, tail)
if 1 <= maxN and maxN <= 12 and 1 <= minN and minN <= 12:
    print("AMBIGUOUS")
    exit()
elif (maxN <= 0 or 13 <= maxN) and (minN <= 0 or 13 <= minN):
    print("NA")
    exit()
if (head == 0 or head >= 13) and 1 <= tail and tail <= 12:
    print("YYMM")
elif 1 <= head and head <= 12 and (tail >= 13 or tail == 0):
    print("MMYY")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=20100;
char s[MAXN],t[MAXN];
int n,a[MAXN],b[MAXN],sum;
inline int calc()
{
	int cnt1=0,cnt2=0,ans=n*n;
	for(int i=1;i<n;i++)
		if(s[i]=='0'&&s[i+1]=='1') a[++cnt1]=i;
	for(int i=1;i<=n;i++) b[++cnt2]=0;
	for(int i=1;i<n;i++)
		if(t[i]=='0'&&t[i+1]=='1') b[++cnt2]=i;
	for(int i=1;i<=n;i++) b[++cnt2]=n;
	for(int i=1;i<=cnt2-cnt1+1;i++)
	{
		int tmp=0;
		for(int j=1;j<i;j++) tmp+=b[j];
		for(int j=1;j<=cnt1;j++) tmp+=abs(a[j]-b[i+j-1]);
		for(int j=cnt1+i;j<=cnt2;j++) tmp+=n-b[j];
		ans=min(ans,tmp);
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>(s+1)>>(t+1);
	if(n<=2)
	{
		for(int i=1;i<=n;i++) sum+=(s[i]!=t[i]);
		cout<<sum<<endl;
		return 0;
	}
	sum=calc();
	for(int i=1;i<=n;i++) s[i]='0'+'1'-s[i],t[i]='0'+'1'-t[i];
	sum+=calc();
	cout<<sum<<endl;
	return 0;
}

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

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

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

// 最大公約数
ULL gcd(ULL x, ULL y) {
    return y ? gcd(y, x%y) : x;
}

ULL lcm(ULL m, ULL n) {
    return m/gcd(m, n)*n;
}

int main() {
    int n;cin >> n;
    vector<ULL> t(n);
    for(auto &tt : t) cin >> tt;
    ULL ans = t[0];
    for(int i=1;i<n;i++){
        ans = lcm(ans, t[i]);
    }
    printf("%llu\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
using namespace std;
namespace IO{/*{{{*/
	const int S=8005;
	char buf[S];
	int pos;
	void Load(){
		fread(buf,1,S,stdin);
		pos=0;
	}
	char getChar(){
		return buf[pos++];
	}
	int getInt(){
		int x=0,f=1;
		char c=getChar();
		while(c<'0'||c>'9'){if(c=='-')f=-1;c=getChar();}
		while('0'<=c&&c<='9'){x=x*10+c-'0';c=getChar();}
		return x*f;
	}
}/*}}}*/
using IO::getInt;
const int N=405;
namespace HASH{/*{{{*/
	const int N=2005;
	const int MOD=9875321;
	int sz,h[MOD],nex[N],val[N];
	ll key[N];
	inline int getHash(ll x){
		return x%MOD;
	}
	void add(ll x,int y){
		int pos=getHash(x),u;
		for(u=h[pos];u&&nex[u]&&key[u]!=x;u=nex[u]);
		if(key[u]==x)
			val[u]+=y;
		else{
			if(!h[pos])
				h[pos]=++sz;
			else nex[u]=++sz;
			key[sz]=x;
			val[sz]=y;
		}
	}
	int query(ll x){
		int pos=getHash(x),u;
		for(u=h[pos];u&&nex[u]&&key[u]!=x;u=nex[u]);
		return key[u]==x?val[u]:0;
	}
}/*}}}*/
int n;
int c[N][4];
inline ll getKey(int *c){
	return c[0]+c[1]*1000+1ll*c[2]*1000000+1ll*c[3]*1000000000;
}
inline void rotate(int *c){
	int c0=c[0];
	for(int i=0;i<3;i++)
		c[i]=c[i+1];
	c[3]=c0;
}
inline void pattern_add(int *c,int x){
	for(int i=0;i<4;i++){
		HASH::add(getKey(c),x);	
		rotate(c);
	}
}
void readData(){
	IO::Load();
	n=getInt();
	for(int i=1;i<=n;i++){
		for(int j=0;j<4;j++)
			c[i][j]=getInt();
		pattern_add(c[i],1);
	}
}
void solve(){
	ll ans=0;
	for(int i=1;i<n;i++){
		pattern_add(c[i],-1);
		for(int j=i+1;j<=n;j++){
			pattern_add(c[j],-1);
			for(int l=0;l<4;l++){// rotate up face
				static int s[4]; //state of side face (iterated)
				ll now=1;
				int k;
				bool flag=false;
				for(k=0;k<4&&now;k++){// count 4 side faces
					s[3]=c[i][k]; s[2]=c[i][(k+1)%4]; s[0]=c[j][3-k]; s[1]=c[j][3-(k+1)%4];
					now*=HASH::query(getKey(s));
					if(now)
						pattern_add(s,-1);
					else flag=true;
				}
				ans+=now;
				for(k--;k>=0;k--){// backspace 
					s[3]=c[i][k]; s[2]=c[i][(k+1)%4]; s[0]=c[j][3-k]; s[1]=c[j][3-(k+1)%4];
					if(!flag)
						pattern_add(s,1);
					flag=false;
				}
				rotate(c[j]);
			}
			pattern_add(c[j],1);	
		}
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
	long long a, b, x;

	std::cin >> a >> b >> x;

	long long c = a / x;
	long long d = b / x;

	long long ans = d - c;

	if (a % x == 0) ans++;

	std::cout << ans << std::endl;

	return 0;
}

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

using namespace std;

int main(){
    string X;
    int t=0,s=0,sub=0;
    cin >> X;
    for(int i=0;i<X.size();i++){
        if(X[i]=='S'){
            s++;
        }else{
            if(0<s){
                s--;
                sub += 2;
            }
        }
    }

    cout << X.size()-sub << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

struct segtree
{
	static const int DEPTH = 17;
	static const int N = 1 << DEPTH;
	int data[2 * N];

	void init()
	{
		for (int i = 0; i < 2 * N; ++i) data[i] = 0;
	}
	void incl(int p, int v)
	{
		p += N;
		while (p) {
			data[p] += v;
			p >>= 1;
		}
	}
	int query(int L, int R)
	{
		L += N; R += N;
		int ret = 0;
		while (L < R) {
			if (L & 1) ret += data[L++];
			if (R & 1) ret += data[--R];
			L >>= 1; R >>= 1;
		}
		return ret;
	}
};
int N;
int A[3][101010];
int V[101010];
segtree seg;

int invnum(vector<int> seq)
{
	seg.init();
	int ret = 0;
	for (int i = 0; i < seq.size(); ++i) {
		ret ^= seg.query(seq[i] + 1, segtree::N);
		seg.incl(seq[i], 1);
	}
	return ret & 1;
}

void flip(int a)
{
	swap(V[a - 1], V[a + 1]);
	V[a - 1] *= -1;
	V[a] *= -1;
	V[a + 1] *= -1;
}

bool isok()
{
	for (int i = 0; i < N; ++i) if (V[i] != i + 1) return false;
	return true;
}

void simple()
{
	if (N == 3) {
		if (isok()) {
			puts("Yes"); return;
		}
		flip(1);
		if (isok()) {
			puts("Yes"); return;
		}
	} else {
		for (int i = 0; i < 32; ++i) {
			if (isok()) {
				puts("Yes"); return;
			}
			flip((i % 2 == 0) ? 1 : 2);
		}
	}
	puts("No");
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < N; ++j) {
			scanf("%d", &(A[i][j]));
			--A[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		if (!(A[0][i] / 3 == A[1][i] / 3 && A[1][i] / 3 == A[2][i] / 3)) {
			puts("No"); return 0;
		}
		if (A[0][i] + A[2][i] != A[1][i] * 2) {
			puts("No"); return 0;
		}
		V[i] = A[0][i] / 3 + 1;
		if (A[0][i] > A[1][i]) V[i] = -V[i];
	}

	if (N <= 4) {
		simple();
		return 0;
	}

	vector<int> eve, od;
	int evi = 0, odi = 0;
	for (int i = 0; i < N; ++i) {
		if (i % 2 == abs(V[i]) % 2) {
			puts("No"); return 0;
		}
		if (i % 2 == 0) {
			eve.push_back(abs(V[i]));
			if (V[i] < 0) evi ^= 1;
		} else {
			od.push_back(abs(V[i]));
			if (V[i] < 0) odi ^= 1;
		}
	}
	odi ^= invnum(eve);
	evi ^= invnum(od);
	puts((odi == 0 && evi == 0) ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 3580
S = input()
x, y = map(int, input().split())

D = map(len, S.split("T"))
X, Y = {next(D)}, {0}
for i, d in enumerate(D, 1):
    if i % 2 == 0:
        X = {x + d for x in X} | {x - d for x in X}
    else:
        Y = {y + d for y in Y} | {y - d for y in Y}

if x in X and y in Y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4968
#include <iostream>

using namespace std;
int a[100];
int main ()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int sum=0;
    for(int i=1;i<n-1;i++)
        if((a[i+1]-a[i])*(a[i-1]-a[i])<0)
            sum++;

        cout<<sum;
    return 0;
}

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

int main() {
    int x, n; cin >> x;
    n = sqrt(x);
    
    int ans = 1;
    for (int i = 2; i <= n; i++) {
        int y = i;
        while (y <= x) y *= i;
        if (y > x) y /= i;
        ans = max(ans, y);
    }
    
    cout << ans << endl;
}


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

int main()
{
	int h1,h2,w1,w2;
	scanf("%d%d",&h1,&w1);
	scanf("%d%d",&h2,&w2);
	printf("%d\n",h1*w1-(h2*w1+h1*w2-h2*w2));
}

Measured memory_bytes: 256
n,m = map(int,input().split())
digit = ['-2']*n
for i in range(m):
    s,c = input().split()
    s = int(s)
    if digit[s-1] == '-2' or digit[s-1] == c:
        digit[s-1] = c
    else:
        digit[s-1] = '-1'
if ('-1' in digit) or (len(digit)!=1 and digit[0] == '0' and digit[1] == '-2'):
    print(-1)
else:
    if digit[0] != '-2' or (len(digit)==1 and digit[0] == '-2'):
        print("".join(digit).replace('-2','0'))
    else:
        digit[0] = '1'
        print("".join(digit).replace('-2','0'))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

ll dp[100010];

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M);
  for(int i=0;i<M;i++) cin>>A[i];

  vector<bool> ok(N+1,true);
  for(int i=0;i<M;i++){
    ok[A[i]]=false;
  }

  dp[0]=1;
  for(int i=0;i<N;i++){
    if(ok[i+1]) dp[i+1]=(dp[i+1]+dp[i])%MOD;
    if(ok[i+2]) dp[i+2]=(dp[i+2]+dp[i])%MOD;
  }

  cout<<(dp[N]+MOD)%MOD<<endl;

  return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string sound[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};

int n, m;
vector<int> t, s;

bool solve(int pos)
{
    for(int i=m-1; i>=0; --i){
        if(pos < 0 || pos >= n)
            return false;

        if(s[i] == t[pos])
            -- pos;
        else if(s[i] == (t[pos] + 1) % 12)
            pos -= 2;
        else if(s[i] == (t[pos] + 11) % 12)
            ++ pos;
        else
            return false;
    }

    return pos == -1;
}

int main()
{
    map<string, int> index;
    for(int i=0; i<12; ++i)
        index[sound[i]] = i;

    int d;
    cin >> d;

    while(--d >= 0){
        cin >> n >> m;

        t.resize(n);
        s.resize(m);
        for(int i=0; i<n; ++i){
            string a;
            cin >> a;
            t[i] = index[a];
        }
        for(int i=0; i<m; ++i){
            string a;
            cin >> a;
            s[i] = index[a];
        }

        if(solve(n-1) || solve(n-2))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    if((a+b) % 2 == 0)
    {
        cout << (a+b) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define preturn(X) cout<<X<<endl; return 0
typedef long long ll;



map<int,ll> h;

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    ll n,k; cin>>n>>k;
    int a,b;
    rep(i,0,n){
        cin>>a>>b;
        h[a]+=(b);
    }
    ll sum = 0;
    iter(it,h){
        if(k<=sum+(*it).S){
            cout<<(*it).F<<endl;
            return 0;
        }
        sum+=((*it).S);
    }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // Long long
typedef ll nt; // Number type

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1 i >= 0; --i)

int main(){
	int N;
	vector<int> a;
	cin >> N;
	a = vector<int>(N);
	rep(i, N){
		int in;
		cin >> in;
		a[i] = in;
	}

	int maxExp = 0;
	rep(i, N){
		int exp = 0;
		while((a[i]&1) == 0){
			++exp;
			a[i] = a[i]/2;
		}
		maxExp += exp;
	}

	cout << maxExp << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
#define N 60000
using namespace std;

int main() {
  int a[N];
  int n,d,x;
  int m = 0;
  cin >> n;
  cin >> d >> x;
  for(int i = 0;i < n;i++)
    cin >> a[i];

  for(int j = 0;j < n;j++){
    m += d / a[j];
    if(d % a[j] != 0)
      m++;
  }
  m += x;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
def draw(h,w):
	s = "#" * w
	k = "#" + "." * (w-2) + "#"
	print s
	for i in range(0,h-2):
		print k
	print s
	print

if __name__ == "__main__":
	while True:
		h,w = map(int, raw_input().split())
		if h==0 and w==0:
			break
		else:
			draw(h,w)

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    int cnt[2] = {0};
    rep(i, s.size()){
        ++ cnt[s[i] - '0'];
    }

    cout << s.size() - (max(cnt[0], cnt[1]) - min(cnt[0], cnt[1])) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int x;
    cin >> x;

    cout << 10 - x / 200 << "\n";

    return 0;
}



Measured memory_bytes: 3604
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long[] a1 = new long[n];
		long[] a2 = new long[n];
		for(i=0;i<n;i++) {
			a1[i] = parseLong(sc.next());
		}
		for(i=0;i<n;i++) {
			a2[i] = parseLong(sc.next());
		}
		sc.close();
		long[] b1 = new long[n];
		long[] b2 = new long[n];
		b1[0] = a1[0];
		b2[n-1] = a2[n-1];
		for(i=1;i<n;i++) {
			b1[i] = a1[i]+b1[i-1];
			b2[n-1-i] = a2[n-1-i]+b2[n-i];
		}
		long mx=0;
		long b12=0;
		for(i=0;i<n;i++) {
			b12 = b1[i] + b2[i];
			if(b12 > mx) mx = b12;
		}
		out.println(mx);
	}
}


Measured memory_bytes: 21844
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<climits>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int X;
    cin>>X;
    int n=100;
    int c=0;
    while(1){
        n=n+n/100;
        c++;
        if(n>=X) break;
        //cout<<n<<endl;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n;
	cin>>n;
	double sum=0,s=0;
	for(int i=1;i<=n;i+=2){
		s+=1;
	} 
	cout<<fixed<<setprecision(10)<<s/n;

}


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,h,w;
    cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	
	vector<vector<pair<int, pair<int, int>>>> dp(n + 1, vector<pair<int, pair<int, int>>>(m + 1, {0, {-1, -1}}));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i] == t[j] && dp[i + 1][j + 1].first < dp[i][j].first + 1) {
				dp[i + 1][j + 1] = {dp[i][j].first + 1, {i, j}};
			}
			if (dp[i + 1][j].first < dp[i][j].first) {
				dp[i + 1][j] = dp[i][j];
			}
			if (dp[i][j + 1].first < dp[i][j].first) {
				dp[i][j + 1] = dp[i][j];
			}
		}
	}
	
	int mxl{};
	pair<int, int> z;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (dp[i][j].first > mxl) {
				mxl = dp[i][j].first;
				z = dp[i][j].second;
			}
		}
	}
	
	char ans[mxl];
	for (int i = mxl - 1; i >= 0; i--) {
		ans[i] = s[z.first];
		z = dp[z.first][z.second].second;
	}
	for (int i = 0; i < mxl; i++) cout << ans[i];
}

Measured memory_bytes: 109028
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
c1 = Counter(v[0::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
  res = n // 2
else:
  if c1.most_common()[0][0] == c2.most_common()[0][0]:
    res = n - max(c1.most_common()[0][1]+c2.most_common()[1][1], c1.most_common()[1][1]+c2.most_common()[0][1])
  else:
    res = n - c1.most_common()[0][1] - c2.most_common()[0][1]
print(res)


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

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

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int total=0;

    for (int i=1;i<N+1;++i){
      int sum=sum_n(i);
      if (A<= sum && sum <=B) total+=i;
    }
    
    cout<<total<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int gu = 0;
        for(int i=0; i<N; i++){
            gu += i;
        }
        int ki = 0;
        for(int j=0; j<M; j++){
            ki += j;       
        }
        System.out.println(gu+ki);
	}
}


Measured memory_bytes: 22868
#include <iostream>
using namespace std;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC145();
}

void ABC145(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
}


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

long long n, cnt[3] = {};
string rgb = "RGB", s;

long long solve();

int main() {
  cin >> n >> s;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j)
      if (s[i] == rgb[j]) ++cnt[j];
  res = cnt[0] * cnt[1] * cnt[2];
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      int k = 2 * j - i;
      if (k >= n) continue;
      if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) --res;
    }
  return res;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll n,k;
    cin>>n>>k;
    ll a[n];
    map<int,int> d;
    rep(i,40){
        d[i]=0;
    }
    rep(i,n){
        cin>>a[i];
        bitset<40> s(a[i]);
        rep(i,40){
            if (s.test(i)){
                d[i]+=1;
            }
        }
    }
    ll num=1;
    rep(i,40){
        num*=2;
    }
    ll ans=0;
    ll now=0;
    for (int i=39;i>=0;i--){
        num/=2;
        if (d[i]>n/2){
            ans+=num*d[i];  
        }
        else{
            if (now+num>k){
                ans+=num*d[i];
            }
            else{
                now+=num;
                ans+=num*(n-d[i]);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<long long> H( N );
	for( int i = 0; i < N; i++ ) {
		cin >> H[i];
	}

	int ans = 0;
	int len = 0;
	for( int i = 0; i < N - 1; i++ ) {
		if( H[i] < H[i + 1] ) len = 0;
		else len++;
		ans = max( ans, len );
	}

	cout << ans << endl;
}


Measured memory_bytes: 4056
def counting_sort(A, B, k):
	C = [0 for i in range(k+1)]
	for a in A:
		C[a] += 1
	for i in range(1,k+1):
		C[i] += C[i-1]
	for a in A:
		B[C[a]-1] = a
		C[a] -= 1


if __name__ == '__main__':
	n = int(input())
	A = [int(s) for s in input().split()]
	B = A[:]
	counting_sort(A, B, max(A))
	print(*B)

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

using namespace std;
typedef long long ll;

const int N = 3007;

int a[N];
int n; 
ll memo[N][N];
ll solve(int l, int r) {
    if(l > r) return 0;
    ll & st = memo[l][r];
    if(st == -1) {
        int turn = (l - 0 + (n - 1 - r))%2;

        if(turn == 0) {
            st = max(solve(l+1, r) + a[l], solve(l, r-1) + a[r]);
        } else {
            st = min(solve(l+1, r) - a[l], solve(l, r-1) - a[r]);
        }
    }
    return st;
}

int main() {
    memset(memo, -1, sizeof memo);
    cin >> n;

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

    cout << solve(0, n-1) << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(char, b);
  if (b == 'A' || b == 'T') out((char)('A' + 'T' - b));
  if (b == 'C' || b == 'G') out((char)('C' + 'G' - b));
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> B(N-1);
    vector<ll> A(N,1000000);
    REP(i,N-1)cin >> B[i];
    REP(i,N-1){
        chmin(A[i],B[i]);
        chmin(A[i+1],B[i]);
    }
    ll sum = 0;
    REP(i,N)sum += A[i];
    cout << sum << "\n";
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N,K;
  scanf("%d%d", &N,&K);
  string s;
  cin >> s;

  vector<int> v;
  int now = -10;
  int now_mass = 1;

  if(s[0]=='L') now = -1;
  else now = 1;

  FOR(i,1,s.length()-1){
    if(s[i]!=s[i-1]) {
      v.PB(now_mass);
      now *= -1;
      now_mass = 1;
    }
    else{
      ++now_mass;
    }
  }

  v.PB(now_mass);

  int ans = s.length() - SZ(v);
  // cout << ans << endl;
  SORT(v);

  while(1){
    if(K>0){
      --K;
      ans += 2;
      if(ans>N-1) {
        ans = N-1;
        break;
      }
      // cout << ans << endl;
    }
    else{
      break;
    }
  }

  cout << ans << endl;



}



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

int main(){
  int N,T;
  cin>>N>>T;
  int C=1001;
  for(int i=0;i<N;i++){
    int c,t;
    cin>>c>>t;
    if(t<=T)
      C=min(C,c);
  }
  if(C==1001)
    cout<<"TLE"<<endl;
  else
    cout<<C<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll A,B,K;
    cin >> A >> B >> K;

    if(A <= K){
        K -= A;
        A = 0;
    }else if(A > K){
        A -= K;
        K = 0;
    }

    if(B <= K){
        B = 0;
    }else{
        B -= K;
    }

    cout << A << " " << B << endl;

}

Measured memory_bytes: 3632
n,m,x = map(int,input().split())
r_list = [0 for i in range(n+1)]
a_list = list(map(int,input().split()))

for i in a_list:
    r_list[i] = 1

zahyo = x
a = 0

while zahyo != 0:
    zahyo -= 1
    if r_list[zahyo] == 1:
        a += 1
zahyo = x
b = 0

while zahyo != n:
    zahyo += 1
    if r_list[zahyo] == 1:
        b += 1

print(min(a,b))


Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[200002][33];
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=1e9+7;
bool cmp(ii x, ii y) {
    return (x.first)*(y.second+1)>y.first*(x.second+1);
}
vector<int> zero;
vector<ii> notzero;
signed main() {
    int n,t,k;
    cin>>n>>t;
    for(int i=0 ; i<n ; i++) {
        int u,v;
        cin>>u>>v;
        if(u==0) zero.push_back(v);
        else notzero.push_back(ii(u,v));
    }
    sort(notzero.begin(),notzero.end(),cmp);
    sort(zero.begin(),zero.end());
    n=notzero.size();
    k=zero.size();
    for(int i=0 ; i<=n ; i++) {
        for(int j=0 ; j<=30 ; j++) {
            dp[i][j]=inf;
        }
    }
    for(int i=0 ; i<=n ; i++) dp[i][0]=0;
    for(int i=1 ; i<=n ; i++) {
        for(int j=1 ; j<=min(n,30ll) ; j++) {
            if(i==j) {
                dp[i][j]=min(inf,dp[i-1][j-1]+1+notzero[i-1].first*(dp[i-1][j-1]+1)+notzero[i-1].second);
            }
            else {
                dp[i][j]=min({inf,dp[i-1][j],dp[i-1][j-1]+1+notzero[i-1].first*(dp[i-1][j-1]+1)+notzero[i-1].second});
            }
        }
    }
    int ans=0;
    for(int i=0 ; i<=30 ; i++) {
        if(dp[n][i]<=t) {
            int cnt=i,cur=dp[n][i];
            for(int j=0 ; j<k ; j++) {
                if(cur+zero[j]<t) {
                    cur+=zero[j]+1;
                    cnt++;
                }
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 55916
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [a, b] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let c = a + b
    putStrLn $ if c >= 10 then "error" else show c


Measured memory_bytes: 380
#include<stdio.h>
#define MAX 44
int n;
int F[MAX];

int main(){
  int i,ans;

  scanf("%d", &n);
  F[0]=1;F[1]=1;
  for(i=2;i<n+1;i++){F[i]=F[i-2]+F[i-1];}
  
  ans = F[n];
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2108
<?php

$s = trim(fgets(STDIN));
$array = str_split($s, 1);

$cnt = 0;
for ($i = 0; $i < (count($array)/2); $i++) {
    $w1 = $array[$i];
    $w2 = $array[count($array) - 1 - $i];
    if ($w1 !== $w2) {
        $cnt++;
    }
}
print("${cnt}\n");

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    string S;
    std::cin >> S;

    auto ans = S;
    auto l_cnt = 0;
    REP(i, N) {
        if(S[i] == '(') {
            l_cnt++;
        }
        else {
            if(0 < l_cnt) l_cnt--;
            else ans = "(" + ans;
        }
    }

    ans = ans + string(l_cnt, ')');

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
using Int = int64_t;


void calc() {

	Int ans = 0;
	Int N, A, B; std::cin >> N >> A >> B;
	ans = (N / (A + B)) * A;
	Int total = (N / (A + B)) * (A + B);
	ans += std::min(A, N - total);

	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int ans[200005];
	for (i = 0; i < n; i++)
		ans[i] = 0;
	int m = 0;
	int count,j, k;
	for (i = n - 1; i >= 0; i--)
	{
		count = 0;
		for (k = 1;; k++)
		{
			if ((i + 1) * k > n)
				break;
			count += ans[k * (i + 1) - 1];
		}
		count %= 2;
		if (a[i] != count)
		{
			ans[i] = 1;
			m++;
		}
	}
	printf("%d\n", m);
	for (i = 0; i < n; i++)
	{
		if (ans[i] > 0)
		{
			if (m > 1)
			{
				printf("%d ", i + 1);
				m--;
			}
			else
				printf("%d\n", i + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 2432
def dfs(parent, connect, passed, N): #深さ優先探索
    cnt = 0
    passed.append(parent) #通った点をメモ
    if len(passed) == N: #全ての点を通過したかの判定
        cnt = 1
    for next_ in connect[parent]:
        if next_ in passed:
            continue
        cnt += dfs(next_, connect, passed, N) #全ての点を通るまで再帰. 戻り値の和で何通りかカウント
    passed.pop() #分岐点に戻る前にメモを1段だけ破棄
    return cnt    

N, M = map(int, input().split())
connect = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    connect[a-1].append(b-1)
    connect[b-1].append(a-1)
ans = dfs(0, connect, [], N) #点0からのdfs
print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define ll long long
const ll limit=1e18;
using namespace std;

int main()
{
   int t;t=1;
   while(t--)
   {
      ll a;long double b;
      cin>>a>>b;
      long double ans=a*b;
      cout<<(ll)ans;
      
      
   }
}

Measured memory_bytes: 3732
gender = {"Male":0,"Female":1}

N = int(input())

print(0)
left_str = input()
if left_str == "Vacant":
    exit()
print(N-1)
right_str = input()
if right_str == "Vacant":
    exit()

left = 0
right = N-1

for i in range(20):
    mid = (left+right)//2

    print(mid)
    mid_s = input()

    if mid_s == "Vacant":
        exit()

    if gender[mid_s] == (gender[left_str]+mid)%2:##正しい周期
        left = mid
    else:
        right = mid

Measured memory_bytes: 3660
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;


int main(){
  ll n;cin>>n;
  vll a(n);
  vector<set<ll> > vs(n);
  rep(i,0,n){
    cin>>a[i];
    rep(j,0,20){
      if(a[i]>>j&1){
        vs[i].insert(j);
      }
    }
  }
  
  ll ans=0;
  set<ll> tmp;ll now=0;
  rep(i,0,n){
    bool ok=false;
    while(now<n){
      for(auto u:vs[now]){
        if(tmp.count(u)){
          ok=true;
        }
      }
      if(ok)break;
      if(!ok){
        for(auto u:vs[now]){
          tmp.insert(u);
        }
      }

      now++;
    }
    
    ans+=now-i;
    
    for(auto u:vs[i]){
      tmp.erase(u);
    }
  }
  cout<<ans<<endl;

}




Measured memory_bytes: 107992