akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<tuple>
using namespace std;
int x[1005][1005], H, W; bool J[1005][1005];
int solve(int r, int s) {
	if (r <= 0 || s <= 0 || r > H || s > W)return 0; int B = 0;
	for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (x[r + i][s + j] == 0)B++; } }
	return B;
}
int main() {
	cin >> H >> W; queue<tuple<int, int, int>>Q;
	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) { char c; cin >> c; if (c == '.')x[i][j] = 0; else { x[i][j] = c - '0'; } } }
	vector<pair<int, int>>vec1;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (solve(i, j) >= x[i][j] && x[i][j] != 0) { vec1.push_back(make_pair(i, j)); J[i][j] = true; Q.push(make_tuple(i, j, 1)); }
		}
	}
	if (vec1.size() == 0) { cout << "0" << endl; return 0; }int Life = 1;
	for (int i = 0; i < vec1.size(); i++) { x[vec1[i].first][vec1[i].second] = 0; }vec1.clear();
	while (!Q.empty()) {
		int a1 = get<0>(Q.front()), a2 = get<1>(Q.front()), a3 = get<2>(Q.front()); Q.pop();
		if (a3 != Life) {
			for (int i = 0; i < vec1.size(); i++) { x[vec1[i].first][vec1[i].second] = 0; }
			vec1.clear(); Life++;
		}
		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				if (solve(a1 + i, a2 + j) >= x[a1 + i][a2 + j] && x[a1 + i][a2 + j] != 0 && J[a1 + i][a2 + j] == false) {
					vec1.push_back(make_pair(a1 + i, a2 + j)); J[a1 + i][a2 + j] = true;
					Q.push(make_tuple(a1 + i, a2 + j, a3 + 1));
				}
			}
		}
	}
	cout << Life << endl;
	return 0;
}

Measured memory_bytes: 8084
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in(), m = in();
	if (n >= m) {
		cout << 0 << endl;
	} else {
		vector<ll>inp(m); REP(i, m)scanf("%lld", &inp[i]); sort(ALL(inp));
		vector<ll>dis(m - 1); REP(i, m - 1)dis[i] = inp[i + 1] - inp[i]; sort(ALL(dis), greater<ll>());
		ll ans = inp.back() - inp.front();
		REP(i, n - 1)ans -= dis[i];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [item - 1 for item in a]

current_town = 0
if k < 200000:
    for i in range(k):
        current_town = a[current_town]
    print(current_town + 1)

else:
    passed = [-1] * n
    passed[0] = 0 
    for i in range(1, 1000000):
        current_town = a[current_town]
        if passed[current_town] > -1:
            start = passed[current_town]
            period = i - start
            break
        else:
            passed[current_town] = i

    m = (k - start) % period
    for i in range(m):
        current_town = a[current_town]

    print(current_town + 1)


Measured memory_bytes: 101048
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    cout<<t+s<<endl;
    return 0;

}


Measured memory_bytes: 256
n,m,R=[int(x) for x in input().split()]
r=[int(x) -1 for x in input().split()]
d=[[float("inf") for _ in [0]*n] for _ in [0]*n]
for i in range(n):
    d[i][i]=0
for i in [0]*m:
    a,b,c=[int(x) for x in input().split()]
    d[a-1][b-1]=d[b-1][a-1]=c
from itertools import product,permutations
for k,i,j in product(range(n),range(n),range(n)):
    if d[i][j] >d[i][k]+d[k][j]:
        d[i][j]=d[i][k]+d[k][j]
def Long(args):
    ans=0
    for i in range(len(args)-1):
        ans+=d[args[i+1]][args[i]]
    return ans
print(min(Long(i) for i in permutations(r)))

Measured memory_bytes: 53736
from sys import stdin, setrecursionlimit
from bisect import bisect_right


def factorization(n):
    arr = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if arr == []:
        arr[n] = 1

    return arr


def main():
    input = stdin.buffer.readline
    n = int(input())

    a1 = [0]
    for i in range(10 ** 4):
        a1.append(a1[i] + i + 1)

    ans = 0
    a2 = factorization(n)
    for k in a2:
        ans += bisect_right(a1, a2[k]) - 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 65176
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rept(i,s,n) for (int i = (s); i < (n); ++i)

#include <iostream>
#include <cmath>
#include <bitset>
using namespace std;

int main() {

  int a, b, c, d;
  string str;

  str = "0290";
  cin >> str;

  a = str.at(0)-'0';
  b = str.at(1)-'0';
  c = str.at(2)-'0';
  d = str.at(3)-'0';
  int aa=a,bb=b,cc=c,dd=d;

  int nOp = str.length()-1;

  for(int bit=0; bit<(1<<nOp); ++bit){
    //cout << bitset<8>(bit)<< endl;
    a=aa,b=bb,c=cc,d=dd;

    if(bit & (1<<2))
      b *= -1;

    if(bit & (1<<1))
      c *= -1;

    if(bit & (1<<0))
      d *= -1;

    if(a+b+c+d==7){
      cout << a;
      cout <<showpos<<b<<c<<d<<"=7"<<endl;
      bit=(1<<nOp);
    }

  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, m;
    cin >> n >> m;
    ll l, r, lmax = -1, rmin = n + 1;
    REP(i, m){
        cin >> l >> r;
        lmax = max(lmax, l);
        rmin = min(rmin, r);
    }
    ll res = max(0LL, rmin - lmax + 1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
x = int(input())
ans = [i**5 for i in range(200)]
for i in ans:
    for j in ans:
        if i - j == x:
            print(ans.index(i), ans.index(j))
            exit()
        if i + j == x:
            print(ans.index(i), -ans.index(j))
            exit()

Measured memory_bytes: 9188
N, A, B = map(int, input().split())
if (B-A) % 2 == 0:
    print((B-A) // 2)
else:
    print(min(N-A, B-1, (B - A- 1) // 2 + N - B + 1, (B - A - 1) // 2 + A))

Measured memory_bytes: 38524
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
int main(){
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(N, vector<int>(3, 0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for (int i = 1; i < N; i++){
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + b[i];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
  }
  int M = 0;
  for (int i = 0; i < 3; i++){
    M = max(M, dp[N - 1][i]);
  }
  cout << M;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

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

ll d=s.size();


ll dp[n+1][n+1];

rrep(i, n+1){
	rrep(j, n+1){
dp[i][j]=0;
	}
}

dp[0][0]=1;

rep(i, n){
	for(int j=0;j<=n;j++){
if(j==0){
dp[i][j]=dp[i-1][j]+dp[i-1][j+1];
dp[i][j]%=MOD;
continue;
}
if(j==n){
	dp[i][j]=dp[i-1][j-1]*2;
dp[i][j]%=MOD;
continue;
}

dp[i][j]=dp[i-1][j-1]*2 + dp[i-1][j+1];
dp[i][j]%=MOD;
	}
}

ll ans=dp[n][d];
for(int i=1;i<=d;i++){
ans*=500000004;
ans%=MOD;
}
cout<<ans<<endl;


}

Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
///////////////////////////////////////////////////////////////////////////////////

ll n,k;
string s;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>k>>s;
    if(s[k-1]=='A'){
        s[k-1]='a';
    }else if(s[k-1]=='B'){
        s[k-1]='b';
    }else{
        s[k-1]='c';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int b = 0;
	int d = 10;
	for (int i = 0; i < 5; ++i) {
		int a;
		cin >> a;
		int c = a % 10;
		if (c == 0) c = 10;
		else a = (a / 10 + 1) * 10;
		b = b + a;
		d = min(d, c);
	}
	cout << b - (10 - d) << endl;
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    int n;
    while (cin >> n) {
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            ok &= x % 2 == 1 or x % 3 == 0 || x % 5 == 0;
        }
        cout << (ok? "APPROVED" : "DENIED") << endl;
    }
    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


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

using namespace std;


//ITP1_2_A:   Small, Large, or Equal
int main() {
    int a, b;
    cin >> a >> b;
    if (a < b)
        cout << "a < b" << endl;
    else if (a > b)
        cout << "a > b" << endl;
    else
        cout << "a == b" << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

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

    sort(a.begin(),a.end(),greater<int>());

    int Alice = 0; 
    int Bob = 0;
    for(int i = 0; i < N;i++){
        if(i % 2 == 0){
            Alice += a[i];
        }
        else if(i %2 == 1){
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	int A, B, Ans;

	cin >> A >> B;

	Ans = A + B;

	if (Ans >= 10)
		cout << "error";
	else
		cout << Ans;

	cin >> A;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define FOR_(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...) FOR_(__VA_ARGS__)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
#define TAIL(x) next (begin (x)), end (x)
using namespace std;

template <typename T = int64_t>
static constexpr auto inf = static_cast <T> (0x0de0b6b43b9aca00);

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t A, B, Q;
  cin >> A >> B >> Q;

  vector <int64_t> s (A);
  rep (i, A) cin >> s [i];

  vector <int64_t> t (B);
  rep (i, B) cin >> t [i];

  auto solve_impl_s = [&] (auto x) {
    auto ite = lower_bound (ALL (s), x);
    auto res = inf <>;
    if (ite != end (s)) res = min (res, abs (x - * ite));
    if (ite != begin (s)) res = min (res, abs (x - * prev (ite)));
    return res;
  };

  auto solve_impl_t = [&] (auto x) {
    auto ite = lower_bound (ALL (t), x);
    auto res = inf <>;
    if (ite != end (t)) res = min (res, abs (x - * ite));
    if (ite != begin (t)) res = min (res, abs (x - * prev (ite)));
    return res;
  };

  auto solve = [&] (int64_t x) {
    auto ite_s = lower_bound (ALL (s), x);
    auto res = inf <>;
    if (ite_s != end (s)) res = min (res, abs (x - * ite_s) + solve_impl_t (* ite_s));
    if (ite_s != begin (s)) res = min (res, abs (x - * prev (ite_s)) + solve_impl_t (* prev (ite_s)));
    auto ite_t = lower_bound (ALL (t), x);
    if (ite_t != end (t)) res = min (res, abs (x - * ite_t) + solve_impl_s (* ite_t));
    if (ite_t != begin (t)) res = min (res, abs (x - * prev (ite_t)) + solve_impl_s (* prev (ite_t)));
    return res;
  };

  vector <int64_t> q (Q);
  rep (i, Q)
  {
    int64_t x;
    cin >> x;
    cout << solve (x) << endl;
  }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int xa, ya, xb, yb;


signed main(){
	cin >> xa >> ya >> xb >> yb;

	int dx = xb-xa;
	int dy = yb-ya;
	cout << xb-dy;
	cout << ' ';
	cout << yb+dx;
	cout << ' ';
	cout << xa-dy;
	cout << ' ';
	cout << ya+dx << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, add, sub, mul;

    scanf("%d %d", &a, &b);

    add = a + b;
    sub = a - b;
    mul = a * b;

    if(sub <= add && mul <= add)
        printf("%d\n", add);
    else if(add <= mul && sub <= mul)
        printf("%d\n", mul);
    else
        printf("%d\n", sub);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    ll N;cin>>N;
    ll res =0;
    res+=2*(N/11);
    ll tmp=N%11;
    if(1<=tmp && tmp<=6)res++;
    else if(7<=tmp && 10>=tmp)res+=2;
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}

//小数点9桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,sum=0,o=LLONG_MAX,s=LLONG_MAX,b=LLONG_MIN;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        s=min(a[i],s);
        b=max(a[i],b);
    }

    for(ll i=s;i<=b;i++){
        for(ll j=0;j<n;j++){
            sum+=ism(a[j]-i,2);
        }
        o=min(sum,o);
        sum=0;
    }
    cout<<o<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "["; for (int i=0; i<(int)v.size(); i++) cout << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p>>=1;){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

ll N,M; int col[100010]; vi g[100010];
bool bip=1;

void dfs(int nod, int c){
    if (col[nod]!=0){
        if (col[nod]!=c) bip=0;
        return;
    }

    col[nod]=c;
    for (int nxt : g[nod])
        dfs(nxt,3-c);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;

    int i,x,y;
    for (i=1; i<=M; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    dfs(1,1);
    ll res=0;
    if (!bip) res=N*(N-1)/2-M;
    else {
        ll a=0;
        for (i=1; i<=N; i++)
            if (col[i]==1) a++;

        res=a*(N-a)-M;
    }

    cout << res << "\n";
	return 0;
}


Measured memory_bytes: 6656
#include<iostream>
using namespace std;
int main(){
	long long n;
	cin>>n;
	if(n==1){
		cout<<0<<endl;
	}else{
		long long sum=0;
		for(int i=1;i<n;i++){
			sum=sum+i;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    vector<vector<int>> a(n+1,vector<int>(n+1,0)),b(n+1,vector<int>(n+1,0));
    rep(i,m){
        int l,r;
        cin >> l >> r;
        a.at(l).at(r)++;
    }
    b.at(n).at(n)=a.at(n).at(n);
    for (int i=n-1;i>0;i--){
        int u=0;
        for (int j=i;j<n+1;j++){
            u+=a.at(i).at(j);
            b.at(i).at(j)=b.at(i+1).at(j)+u;
        }
    }
    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << b.at(l).at(r) << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    string T;
    int S[214][214];
    int D[214][214];
    cin >> N;
    REP(i,N){
        cin >> T;
        REP(j,N){
            S[i][j]=T[j]-'0';
        }
    }
    REP(i,N){
        REP(j,N){
            D[i][j]=INF;
        }
    }
    REP(i,N){
        D[i][i]=0;
    }
    REP(i,N){
        REP(j,N){
            if(S[i][j]==1){
                D[i][j]=1;
            }
        }
    }
    
    REP(k,N){
        REP(i,N){
            REP(j,N){
                D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
            }
        }
    }
    
    //REP(i,N){REP(j,N){cout << D[i][j] << " ";}cout << endl;}
    
    REP(k,N){
        REP(i,N){
            REP(j,N){
                if((D[i][j]+D[j][k]+D[k][i])%2!=0)GOODBYE;
            }
        }
    }
    
    int Ans=-INF;
    REP(i,N){
        REP(j,N){
            if(i==j)continue;
            Ans=max(Ans,D[i][j]+1);
        }
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 1024
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  import CountingSort.countingSort

  val n  = readInt()
  val xs = readLine().split(' ').map { _.toInt }

  val ys = countingSort(xs)
  println(ys.mkString(" "))
}

object CountingSort {
  val MaxValue = 10000

  def countingSort(xs: Array[Int]): Array[Int] = {
    val counts = {
      val counts = Array.fill(MaxValue + 1)(0)
      for (x <- xs) {
        counts(x) += 1
      }

      var i = 1
      while (i <= MaxValue) {
        counts(i) = counts(i) + counts(i - 1)
        i += 1
      }

      counts
    }

    val ys = new Array[Int](xs.length)
    for (x <- xs) {
      ys(counts(x) - 1) = x
      counts(x) -= 1
    }

    ys
  }
}



Measured memory_bytes: 471072
/*
 * ARC091_D.cpp
 *
 *  Created on: May 22, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



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

	lng N, K;
	cin >> N >> K;

	if(K == 0) {
		cout << N*N << endl;
		return 0;
	}
	lng ans = 0;
	FOR(b, K+1, N) {
		ans += (b-K)*(N/b);
		ans += max(0LL, N%b-K+1);
	}

	cout << ans << endl;
}






Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void solve() {
	int a, b, c; cin >> a >> b >> c;
	if (a < b&&b < c)cout << "Yes" << endl;
	else cout << "No" << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3172
order_list = [int(input()) for _ in range(5)]

min_remainder_num = 0
for i in range(1, 5):
    if order_list[min_remainder_num]%10 > order_list[i]%10 > 0:
        min_remainder_num = i

ans = 0

for j in range(5):
    if j == min_remainder_num:
        ans += order_list[j]
    else:
        ans += -((-1 * order_list[j])//10)*10

print(ans)

Measured memory_bytes: 3064
N,Q=map(int,input().split())
S=input()
t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2]=="AC" else 0)
for i in range(Q):
  start,end=map(int,input().split())
  print(t[end-1]-t[start-1])

Measured memory_bytes: 9284
#include "bits/stdc++.h"
using namespace std;


int main() {
	vector<int> vnumbers;
	int number;
	int maxdistance;
	int flag = 0;
	int distance;

	for (int i = 0; i < 5; i++) {
		cin >> number;
		vnumbers.push_back(number);
	}

	cin >> maxdistance;

	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			distance = vnumbers.at(i) - vnumbers.at(j);
			if (distance < maxdistance * (-1) || maxdistance < distance) flag = 1;
		}
	}

	if (flag == 1) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}



	
	return 0;

}


Measured memory_bytes: 256
//File Name: agc019_a.cpp
  //Created Time: 2017年10月15日 星期日 13时32分43秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;

LL solve(LL q,LL h,LL s,LL d,LL n){
	if(q + q < h) h = q + q;
	if(h + h < s) s = h + h;
	if(s + s < d) d = s + s;
	n *= 4;
	LL res = n / 8 * d;
	n %= 8;
	res += n / 4 * s;
	n %= 4;
	res += n / 2 * h;
	n %= 2;
	res += n / 1 * q;
	return res;
}
int main(){
	LL q,h,s,d,n;
	cin >> q >> h >> s >> d >> n;
	cout << solve(q,h,s,d,n) << endl;
	return 0;
}


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

int main(){
  int N,X;
  cin>>N>>X;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
    x[i] -= X;
    x[i] = abs(x[i]);
  }
  int ans = 0;
  for(int i=0;i<N;i++) ans = __gcd(ans,x[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int min(-1);
    for (int i = 0; i < s.size() - 2; ++i)
    {
        int tmp = abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0') - 753);
        if (min < 0 || tmp < min)
            min = tmp;
    }
    cout << min << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int t=s.nextInt();
		
		if(t>=30)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
		
	}
	
}

Measured memory_bytes: 35676
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=1,s=0; cin>>n;
    vector<ll> a(n+1,0),no(n+1,0);
    rep(i,n+1){
        cin>>a[i];
        s+=a[i];
    }
    s--;
    no[0]=1;
    rep(i,n){
        ll k=no[i]-a[i];
        if(k<1){
            ans=-1; break;
        }
        if(k<=s){
            no[i+1]=2*k;
            s-=k;
        }
        else{
            no[i+1]=k+s;
            s=0;
        }
        ans+=no[i+1];
    }
    cout<<(no[n]==a[n] ? ans : -1)<<endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,t;scanf("%d%d",&n,&t);
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].first,&a[i].second);
    sort(a.begin(),a.end());
    vector<vector<int>> dp(n+1,vector<int>(t));
    vector<int> m(n+1);
    for(int i=n-1;i>=0;i--)m[i]=max(m[i+1],a[i].second);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<t;j++){
            if(j<a[i].first)dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j],dp[i][j-a[i].first]+a[i].second);
        }
        ans=max(ans,dp[i+1][t-1]+m[i+1]);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 35584
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i32 = input();
    let p: i32 = input();
    println!("{}", (3 * a + p) / 2);
}


Measured memory_bytes: 4352
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double dis(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }

int main() {
	string s;
	cin >> s;
	char ans[110];
	int len = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0')
			ans[++len] = '0';
		else if (s[i] == '1')
			ans[++len] = '1';
		else if (s[i] == 'B'&&len >0) {
			len--;
		}
	}
	for (int i = 1; i <=len; i++)
		cout << ans[i];
	cout << endl;
	system("pause");
}

Measured memory_bytes: 504
#include<iostream>
#include<vector>
#include<map>
using namespace std;
vector<int>wt;
vector<int>pt;
int n;
const int inf=1000000001;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int W,i,j;
    cin>>n>>W;
    wt.resize(n);
    pt.resize(n);
    for(i=0;i<n;i++) cin>>wt[i]>>pt[i];
    vector<int>dp(100001,inf);
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=100000;j>=pt[i];j--)
        {
            dp[j]=min(dp[j],wt[i]+dp[j-pt[i]]);
        }
    }
    int ans;
    for(i=0;i<=100000;i++)
    {
        if(dp[i]<=W) ans=i;
    }
    cout<<ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;


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

	ll s;
	cin >> s;

	// Area:
	// |(x1 y2 - x2 y1) + (x2 y3 - x3 y2) + (x3 y1 - x1 y3)|
	// = |x1 y2 - x2 y1 + x2 y3 - x3 y2 + x3 y1 - x1 y3|
	// = |x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)|

	// y1 > y2 > y3, y1 - y2 = a, y2 - y3 = b:
	// = |b x1 + a x3 - (a + b) x2|

	ll h = 1e9;
	ll t = h - 1;
	ll v1 = s / t;

	ll x1 = min(v1, h);
	ll x3 = s - t * x1;
	ll x2 = 0;

	ll y1 = h;
	ll y2 = t;
	ll y3 = 0;

	cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << '\n';
}


Measured memory_bytes: 256
from collections import deque
import numpy as np

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

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

using namespace std;

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

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

int main()
{
	
	int mai = 0;
	bool maiiti = false;
	bool flag = false;
	int n;cin >> n;
	vector<ll> v(n);
	
	REP(i,n){
		cin >> v[i];
		if(v[i] == -1){
			maiiti = true;
		}
		else if(v[i] == -2){
			mai++;
		}
	}
	
	if(mai % 2 == 1){
		if(maiiti == true){
			flag = true;
		}
		else{
			mai--;
		}
	}
	
	vector<int> ret;
	
	REP(i,n){
		if(v[i] == -1){
			if(flag){
				flag = false;
				ret.PB(i);
			}
		}
		else if(v[i] == -2){
			if(mai > 0){
				mai--;
				ret.PB(i);
			}
		}
		else if(v[i] == 2){
			ret.PB(i);
		}
	}
	
	cout << ret.size() << endl;
	REP(i,ret.size()){
		cout << ret[i]+1 << endl;
	}
	
		
	
	return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  int a[100005], b[100005], c[100005];
  cin >> N;
  rep(i, N){
    cin >> a[i] >> b[i] >> c[i];
  }

  int dp[100005][3];
  rep(i, N){
    if (i == 0) {
      dp[0][0] = a[0];
      dp[0][1] = b[0];
      dp[0][2] = c[0];
    } else {
      dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
      dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
      dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
  }

  cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
}


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

public class Po
{
    public int x { get; set; }
    public int y { get; set; }
}
public class Po2
{
    public int x { get; set; }
    public int y { get; set; }
    public int n { get; set; }
}
public class Re
{
    public bool result { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var st = new Stack<Po2>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var py = int.Parse(line[0]);
            var px = int.Parse(line[1]);
            if (px == 0 && py == 0) break;
            var n = int.Parse(Console.ReadLine().Trim());
            var sc = new Po[n];
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var t = Array.ConvertAll(line2, int.Parse);
            for (int i = 0; i < n; i++)
                sc[i] = new Po { y = t[2 * i], x = t[2 * i + 1] };
            var map = new int[10, 10];
            var p = new Po2 { x = px, y = py, n = 0 };
            st.Push(p);
            var re = new Re();
            goDfs(map, sc, st,re);
            Console.WriteLine(re.result ? "OK" : "NA");
        }
    }
    public static void goDfs(int[,] map, Po[] sc, Stack<Po2> st,Re re)
    {
        var dxp = new int[] { -1, 0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2 };
        var dyp = new int[] { 2, 2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1 };
        var dxs = new int[] { -1, -1, -1, 0, 1, 1, 1, 0, 0 };
        var dys = new int[] { -1, 0, 1, 1, 1, 0, -1, -1, 0 };
        while (st.Count() > 0)
        {
            var p = st.Pop();
            if (p.n == sc.Length) { re.result = true; return; }
            writeMap(map, sc, p.n, dxs, dys);
            for (int i = 0; i < 12; i++)
            {
                var nx = p.x + dxp[i];
                var ny = p.y + dyp[i];
                if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && map[nx, ny] == 1)
                    st.Push(new Po2 { x = nx, y = ny, n = p.n + 1 });
            }
        }
    }
    public static void writeMap(int[,] map, Po[] sc, int n, int[] dxs, int[] dys)
    {
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++) map[i, j] = 0;
        for (int i = 0; i < 9; i++)
        {
            var nx = sc[n].x + dxs[i];
            var ny = sc[n].y + dys[i];
            if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10) map[nx, ny] = 1;
        }
    }
}

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

int main() {
  string S;
  cin >> S;
  string ans;
  /*int c = 0;
  
  for (int i = 0; i < 4; i++) {
    int result = S.compare(2i,2i+1,"hi"); // 0 (一致)
    if (result = 0) {
      
  }*/
  
  if (S == "hihihihihi") {
    ans = "Yes";
  }
  else if (S == "hihihihi") {
    ans = "Yes";
  }
  else if (S == "hihihi") {
    ans = "Yes";
  }
  else if (S == "hihi") {
    ans = "Yes";
  }
  else if (S == "hi") {
    ans = "Yes";
  }
  else {
    ans = "No";
  }
  
  cout << ans;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();

    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (s[i] != s[n - 1 - i])
            ok = false;
    }
    for (int i = 0; i < (n - 1) / 2; ++i) {
        if (s[i] != s[(n - 1) / 2 - 1 - i])
            ok = false;
    }
    for (int i = (n + 3) / 2 + 1; i < n; ++i) {
        if (s[i] != s[n - 1 - i])
            ok = false;
    }
    if (ok)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n;
  FOR(i, 1, 3501) FOR(j, 1, 3501) {
    if(4*i*j-n*i-n*j == 0) continue;
    int k = n*i*j/(4*i*j-n*i-n*j);
    if(1 <= k && 4LL*i*j*k == n*(i*j+j*k+k*i)) {
      cout << i << " " << j << " " << k << endl;
      return 0;
    }
  }
  assert(false);

  return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int V[300000], W[300000];

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


	int N;
	cin >> N;
	rep1(i, N) {
		cin >> V[i] >> W[i];
	}

	int Q;
	cin >> Q;

	rep(i, Q) {
		int P, L;
		cin >> P >> L;

		int k = 0;
		int v[20], w[20];
		while (P) {
			v[k] = V[P];
			w[k] = W[P];
			P /= 2;
			k++;

		}

		pair<int, int> A[1000] = {}, B[1000] = {};
		int a = 1, b = 1;
		rep(j, k / 2) {
			int tmp = a;
			pair<int, int> A2[1000];
			rep(q, tmp) {
				A[a++] = mp(A[q].first + w[j], A[q].second + v[j]);
			}
			int t1 = 0;
			int t2 = tmp;
			int t3 = 0;
			while (t1 < tmp || t2 < a) {
				if (t1 == tmp) A2[t3++] = A[t2++];
				else if (t2 == a) A2[t3++] = A[t1++];
				else if (A[t1] > A[t2]) A2[t3++] = A[t2++];
				else A2[t3++] = A[t1++];
			}
			rep(q, a) A[q] = A2[q];
		}

		for (int j = k / 2; j < k; j++) {
			int tmp = b;
			pair<int, int> A2[1000];
			rep(q, tmp) {
				B[b++] = mp(B[q].first + w[j], B[q].second + v[j]);
			}
			int t1 = 0;
			int t2 = tmp;
			int t3 = 0;
			while (t1 < tmp || t2 < b) {
				if (t1 == tmp) A2[t3++] = B[t2++];
				else if (t2 == b) A2[t3++] = B[t1++];
				else if (B[t1] > B[t2]) A2[t3++] = B[t2++];
				else A2[t3++] = B[t1++];
			}
			rep(q, b) B[q] = A2[q];
		}

		int saidai = 0;
		rep(j, a) {
			chmax(saidai, A[j].second);
			A[j].second = saidai;
		}
		saidai = 0;
		rep(j, b) {
			chmax(saidai, B[j].second);
			B[j].second = saidai;
		}
		reverse(B, B + b);

		int p2 = 0;
		int kotae = 0;
		rep(j, a) {
			while (p2 < b && A[j].first + B[p2].first > L) {

				p2++;
			}

			if (p2 < b) {
				chmax(kotae, A[j].second + B[p2].second);
			}
		}

		co(kotae);

	}






	Would you please return 0;
}

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

int main() {
  int n, cnt = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n / 2; ++i)
    if (s[i] == s[i + n / 2]) cnt++;
  if (n % 2 == 0)
    cout << ((cnt == n / 2) ? "Yes" : "No") << endl;
  else
    cout << "No" << endl;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




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

int ans = ((a + b) * h) / 2;

print(ans);

}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/25
// Problem:C - Bugged d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int INF = 1e9 + 1;
static const int MAX_N = 1;

int N;

int main()
{
  int _min = INF;
  scanf("%d", &N);
  vector< int > s(N);
  REP(i, N) {
    scanf("%d", &s[i]);
    if (s[i] % 10 != 0) _min = min(s[i], _min);
  }

  int ans = 0;
  REP(i, N) {
    ans += s[i];
  }
  if (ans % 10 == 0) ans = max(0, ans - _min);

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



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

int main(){
  int N;
  cin >> N;
  vector<int> vec1(N), vec2(N);
  for (int i = 0; i < N; i++) {
    cin >> vec1.at(i);
    vec2.at(i) = vec1.at(i);
  }
  
  sort(vec2.begin(), vec2.end()); 
  reverse(vec2.begin(), vec2.end()); 
  int max = vec2.at(0);
  int max2 = vec2.at(1);
  
  if (max == max2){
    for (int i = 0; i < N; i++) {
      cout << max << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (vec1.at(i) == max ){
        cout << max2 << endl;
      } else {
        cout << max << endl;
      }
    }
  } 
}


Measured memory_bytes: 3200