akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main ()
{
    int n;//サイコロの個数
    int dice[100][7];
    int i,j,k,l;

    scanf("%d",&n);
    for(i=0;i<n;i++) {
        for(j=1;j<7;j++) {
            scanf("%d",&dice[i][j]);
        }
    }
    //処理
    for (l=1;l<n;l++) {
        for (i=0;i<6;i++) {
            if (dice[0][1]==dice[l][1])
                for (j=0;j<4;j++) {
                    
                    
                    for (k=1;k<7;k++)
                        if (dice[0][k]!=dice[l][k]) break;
                    if(k==7) {
                        printf("No\n");
                        return 0;
                    }
                    
                   dice[l][0] = dice[l][2];
                   dice[l][2] = dice[l][3];
                   dice[l][3] = dice[l][5];
                   dice[l][5] = dice[l][4];
                   dice[l][4] = dice[l][0];
                }
            dice[l][0] = dice[l][1];
                    
            switch(i) {
                        
                case 2:
                    dice[l][1] = dice[l][3];
                    dice[l][3] = dice[l][6];
                    dice[l][6] = dice[l][4];
                    dice[l][4] = dice[l][0];
                    break;
                    
                default:
                    dice[l][1] = dice[l][2];
                    dice[l][2] = dice[l][6];
                    dice[l][6] = dice[l][5];
                    dice[l][5] = dice[l][0];
                    break;
               
          }
//            printf("配列[%d][%d] %d ", l, I, dice[l][i]);
//
        }
//        printf("\n");
    }
    printf("Yes\n");
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }  
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;

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

Measured memory_bytes: 3604
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<vector<ll> > vv;
ll a1,b1;
ll mx;
ll d[110];

void dfs(ll a, ll p, ll h) {
	if (vv[a].sz == 1 && p != -1) {
		return;
	}
	ll c = 0;
	rep(i, 0, vv[a].sz) {
		if (vv[a][i] == p)continue;
		if(vv[a][i]==b1){
			dfs(b1, a, 0);
		}
		else{
			dfs(vv[a][i], a, h + 1);
			c++;
		}
	}
	mx = max(mx, h);
	d[h] = max(d[h], c);
	return;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> v1;
	vector<ll> v2;
	rep(i, 0, n - 1) {
		ll a, b;
		cin >> a >> b;
		v1.pb(a);
		v2.pb(b);
	}
	if (n == 2) {
		cout << 1 << " " << 2 << endl;
		return 0;
	}
	if (n == 3) {
		cout << 2 << " " << 2 << endl;
		return 0;
	}
	vector<vector<ll> > vv_(n + 1, vector<ll>());
	vv = vv_;
	rep(i, 0, v1.sz) {
		vv[v1[i]].pb(v2[i]);
		vv[v2[i]].pb(v1[i]);
	}
	ll ans_mn = 100000;
	ll ans_d = 1000000000000000000LL;
	rep(i, 1, n + 1) {
		mx = 0;
		clr(d, 0);
		b1 = 0;
		dfs(i, -1, 0);
		if (mx + 2 <= ans_mn) {
			if (mx + 2 < ans_mn) {
				ans_mn = mx + 2;
				ans_d = 1000000000000000000LL;
			}
			ll ddd = 1;
			rep(j, 0, n + 1) {
				if (d[j] != 0) {
					ddd *= d[j];
				}
			}
			ans_d = min(ans_d, ddd);
		}
	}
	rep(i, 0, v1.sz) {
		a1 = v1[i];
		b1 = v2[i];
		rep(k, 0, 2) {
			mx = 0;
			clr(d, 0);
			dfs(a1, -1, 0);
			if(mx>0){
				mx += 2;
			}
			else{
				mx = 2;
			}
			if (mx <= ans_mn) {
				if (mx < ans_mn) {
					ans_mn = mx;
					ans_d = 1000000000000000000LL;
				}
				ll ddd = 1;
				d[0] *= 2;
				rep(j, 0, n + 1) {
					if (d[j] != 0) {
						ddd *= d[j];
					}
				}
				ans_d = min(ans_d, ddd);
			}
			swap(a1,b1);
		}
	}
	cout << ans_mn << " " << ans_d << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

u_int64_t vsum[51][51];
u_int64_t cnt[51][51];
u_int64_t value[50];

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    for (int i = 0; i < N; i++)
    {
        cin >> value[i];
    }

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            if (i == 0 || j == 0)
            {
                vsum[i][j] = 0;
                cnt[i][j] = 1;
                continue;
            }
            u_int64_t lvsum = vsum[i - 1][j];
            u_int64_t rvsum = vsum[i - 1][j - 1] + value[i - 1];
            u_int64_t lcnt = cnt[i - 1][j];
            u_int64_t rcnt = cnt[i - 1][j - 1];

            if (lvsum == rvsum)
            {
                vsum[i][j] = lvsum;
                cnt[i][j] = lcnt + rcnt;
            }
            else if (lvsum > rvsum)
            {
                vsum[i][j] = lvsum;
                cnt[i][j] = lcnt;
            }
            else if (lvsum < rvsum)
            {
                vsum[i][j] = rvsum;
                cnt[i][j] = rcnt;
            }
        }
    }

    u_int64_t msum = 0;
    u_int64_t midx = 1;
    u_int64_t mcnt = 0;
    for (int i = A; i <= B; i++)
    {
        u_int64_t lexpr = i * msum;
        u_int64_t rexpr = midx * vsum[N][i];

        if (lexpr == rexpr)
        {
            msum = vsum[N][i];
            midx = i;
            mcnt += cnt[N][i];
        }
        else if (lexpr < rexpr)
        {
            msum = vsum[N][i];
            midx = i;
            mcnt = cnt[N][i];
        }
    }
    double ave = msum / (double)midx;

    cout << fixed << ave << endl
         << mcnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
	
int main(){
	
	int i,n;
	
	for(i = 1; i < 10 ; i++){
		for(n = 1; n < 10 ; n++){
			printf("%dx%d=%d\n",i,n,i * n);
		}
	}
	return 0;
}

Measured memory_bytes: 524
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift

local n, k, q = io.read("*n", "*n", "*n")
local a = {}
local b = {}
local used = {}
for i = 1, n do
  a[i] = io.read("*n")
  b[i] = i
  used[i] = false
end
table.sort(b, function(x, y) return a[x] < a[y] end)

local ret = a[b[q]] - a[b[1]]
for i = 1, n do
  local topidx = b[i]
  used[topidx] = true
  local tmp = {}
  local cand = {}
  for j = 1, n do
    if used[j] then
      table.sort(tmp)
      for z = 1, #tmp - k + 1 do
        table.insert(cand, tmp[z])
      end
      tmp = {}
    else
      table.insert(tmp, a[j])
    end
  end
  table.sort(tmp)
  for z = 1, #tmp - k + 1 do
    table.insert(cand, tmp[z])
  end
  if #cand < q then break end
  table.sort(cand)
  ret = mmi(ret, cand[q] - cand[1])
end
print(ret)


Measured memory_bytes: 520
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    ll N, Q;
    string s;
    cin >> N >> Q >> s;

    vector<char> T(Q);
    vector<char> D(Q);

    for (ll i = 0; i < Q; i++)
        cin >> T[i] >> D[i];

    ll l, r;
    l = 0;
    r = N + 1;

    for (ll i = Q-1; i >= 0; i--){
        if (D[i] == 'L'){
            if (s[l] == T[i]){
                l++;
            } 
            if (r <= N){
                //cout << "here!\n";
                if (s[r - 1] == T[i])
                {
                    r++;
                }
            }
        } else {
            if (s[r - 2] == T[i]){
                r--;
            }
            if (l > 0) {
                if (s[l - 1] == T[i]) {
                    l--;
                }
            }
        }

        if (r - l - 1 == 0) {
            break;
        }
        //cout << "trial:i= " << i << ", l=" << l << ", r=" << r << endl;
    }
    cout << r - l - 1 << endl;

}

Measured memory_bytes: 900
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

ll n, m, sum1 = 1, sum2 = 1;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	cin >> n >> m;
	if(abs(n - m) > 1){
		printf("0\n");
		return 0;
	}
	for(int i = 1; i <= n; ++i){
		sum1 *= 1ll * i;
		sum1 %= 1ll * mod;
	}
	for(int i = 1; i <= m; ++i){
		sum2 *= 1ll * i;
		sum2 %= 1ll * mod;
	}
	ll ans = (sum1 * sum2) % (1ll * mod);
	if(n == m){
		ans *= 1ll * 2;
		ans %= 1ll * mod;
	}

	cout << ans;
	return 0;
}

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

L = [v for v in input().strip()]
c = len(L)

ans = [1] * c

for i in range(c - 1):
    if L[i] == "R" and L[i + 1] == "R":
        ans[i + 1] += ans[i]
        ans[i] = 0
        
for i in reversed(range(1, c)):
    if L[i] == "L" and L[i - 1] == "L":
        ans[i - 1] += ans[i]
        ans[i] = 0
        
for i in range(c - 1):
    if ans[i] != 0 and ans[i + 1] != 0 and L[i] == "R":
        a = ans[i] + ans[i + 1]
        if a % 2 == 0:
            ans[i] = a // 2
            ans[i + 1] = ans[i]
        else:
            t = max(ans[i], ans[i + 1])
            if ans[i] < ans[i + 1]:
                ans[i] = a // 2
                ans[i + 1] = ans[i] + 1
            else:
                ans[i] = a // 2 + 1
                ans[i + 1] = ans[i] - 1
                
            if t % 2 == 0:
                ans[i], ans[i + 1] = ans[i + 1], ans[i]

print(*ans)


Measured memory_bytes: 7132
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,i,m1=0,m2=0;
    cin >> n;
    vector <int>a(n);
    for(i=0;i<n;i++){
        cin >> a[i];
        if(m1<a[i]){
            m2=m1;
            m1=a[i];
        }
        else if(m2<a[i]) m2=a[i];
    }
    for(i=0;i<n;i++){
        if(a[i]==m1) cout << m2 << endl;
        else cout << m1 << endl;
    }
}

Measured memory_bytes: 2432
A,B = map(int, input().split())
a=input()
b="Yes"
for i in range(A):
  if not a[i] in "1234567890":
    b="No"
if a[A]!="-":
  b="No"
for j in range(A+1,A+B+1):
  if not a[j] in "1234567890":
    b="No"
print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef unsigned long long int ulli;

const ulli MOD = 1e+9 + 7;

bool validate(unsigned N, const std::vector<unsigned> &A)
{
  std::vector<unsigned> c(N, 0);
  for(unsigned n = 0; n < N; ++n)
  {
    ++c[A[n]];
  }
  
  if(N % 2 == 1 && c[0] != 1)
  {
    return false;
  }
  
  unsigned s = (N % 2 == 0) ? 2 : 1;
  unsigned K = (N % 2 == 0) ? 1 : 0;
  for(unsigned i = s; i < N; ++i)
  {
    if(c[i] != ((i % 2 == K) ? 2 : 0)) return false;
  }
  
  return true;
}

ulli mod_pow(ulli b, ulli x, ulli mod)
{
  if(x == 0) return 1;
  else if(x == 1) return b;
  
  ulli w = mod_pow(b, x >> 1, mod);
  ulli y = (w * w) % mod;
  
  if(x % 2 == 1) y = (y * b) % MOD;
  
  return y;
}

int main()
{
  unsigned N;
  std::cin >> N;
  
  std::vector<unsigned> A(N);
  for(unsigned n = 0; n < N; ++n)
  {
    std::cin >> A[n];
  }
  
  if(!validate(N, A))
  {
    std::cout << 0 << std::endl;
  }
  else
  {
    std::cout << mod_pow(2, N >> 1, MOD) << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1152
def main():
    from fractions import gcd

    n, *a = map(int, open(0).read().split())
    a = [0] + a + [0]
    l = [0 for _ in range(n + 1)]
    r = [0 for _ in range(n + 1)]
    tmpl = 0
    tmpr = 0
    for i in range(1,n+1):
        tmpl = gcd(tmpl, a[i-1])
        tmpr = gcd(tmpr, a[-i])
        l[i] = tmpl
        r[-i] = tmpr

    ans = 0
    for i, j in zip(l, r):
        g = gcd(i, j)
        ans = max(ans, g)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 96952
n_k_q_str = input()
n_k_q = n_k_q_str.split(" ")
N = int(n_k_q[0])
K = int(n_k_q[1])
Q = int(n_k_q[2])
answers = [0] * N
for i in range(Q):
    answer = int(input()) - 1
    answers[answer] += 1

for i in range(N):
    if K - (Q - answers[i]) > 0:
        print("Yes")
    else:
        print("No")

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll x; cin >> x;
    ll ans = 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    cout << ans;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#define ll long long
using namespace std;
int main()
{
    int d;
    int a[55];
    scanf("%d",&d);
    int sum=0;
    for(int i=0;i<d;i++)
    {
       scanf("%d",&a[i]);
       sum+=a[i];
    }
    int sum1=0;
    for(int i=0;i<d-1;i++)
    {
       sum=sum-a[i];
       sum1+=a[i]*sum;
    }
    printf("%d\n",sum1);
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a%3 == 0){cout << "Possible" << endl;}
    else if(b%3 == 0){cout << "Possible" << endl;}
    else if((a+b)%3 == 0){cout << "Possible" << endl;}

    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using Pr = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, K;
ll R, S, P;
std::string T;
std::string vs[100010];

// 0: r, 1: s, 2: p
ll win( char ch, ll l ) {
  if( ch == 'r' ) {
    return l == 2 ? P : 0;
  } else if( ch == 's' ) {
    return l == 0 ? R : 0;
  } else {
    return l == 1 ? S : 0;
  }
}

int main() {
  std::cin >> N >> K >> R >> S >> P >> T;

  rep( i, N ) {
    vs[i%K] += T[i];
  }

  ll ans = 0;

  rep( i, K ) {
    std::vector<std::vector<ll>> dp( vs[i].size()+10, std::vector<ll>( 3, 0 ) );

    rep( j, vs[i].size() ) rep( k, 3 ) rep( l, 3 ) {
      if( l == k )
        continue;
      
      chmax( dp[j+1][l], dp[j][k]+(win(vs[i][j], l) ? win(vs[i][j], l) : 0) );
    }

    ll ma = 0;

    rep( k, 3 )
      chmax( ma, dp[vs[i].size()][k] );
    
    ans += ma;
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11908
h, w = map(int, input().split(" "))
s = []
for row in range(h):
    line = input()
    tmp = []
    for column in range(w):
        tmp.append(line[column])
    s.append(tmp)

sx = [-1, 0, 0, 1]
sy = [0, 1, -1, 0]

res = True
for row in range(h):
    for column in range(w):
        if s[row][column] == "#":
            count = 0
            for i in range(len(sx)):
                row_target = row + sx[i]
                column_target = column + sy[i]
                if row_target < 0 or len(s) <= row_target:
                    continue
                if column_target < 0 or len(s[row]) <= column_target:
                    continue
                if s[row_target][column_target] == "#":
                    count += 1
            if count == 0:
                res = False

print("Yes" if res == True else "No")



Measured memory_bytes: 3064
#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) ; 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 All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int a,b;cin >> a >> b;
   if(a*b == 15){
      cout << "*";
   }else if(a+b == 15){
      cout << "+";
   }else{
      cout << "x";
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=2E5;
typedef pair<int,int> Pair;

int main(){
    int N,Y;
    cin >> N >> Y;
    int gosen=0,man=0;
    int sen=Y/1000;
    if(sen>N){
        if((sen/5)+sen%5>=N){
            gosen=sen/5;
            sen%=5;
        }
        else{
            gosen=(sen-N)/4;
            sen-=5*gosen;
        }
    }   
    if(sen+gosen>N){
        if((gosen/2)+gosen%2+sen>=N){
            man=gosen/2;
            gosen%=2;
        }
        else{
            man=(gosen+sen-N);
            gosen-=2*man;
        }
    }
    if(sen+gosen*5+man*10==Y/1000 && man+sen+gosen==N && sen>=0 && gosen >=0 && man >=0){
        cout << man << " " << gosen <<" "<< sen << endl;
    }else {
        cout << -1 << " " << -1 <<" "<< -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    # N = int(input())
    # N, M = map(int, input().split())
    # A = list(map(int, input().split()))
    S = input()
    # if 'hi' in S:
    #     print('Yes')
    # else:
    #     print('No')

    for i in range(len(S)):
        if i % 2 == 0 and S[i] != 'h':
            print('No')
            break
        if i % 2 != 0 and S[i] != 'i':
            print('No')
            break
    else:
        if S[-1] == 'i':
            print('Yes')
        else:
            print('No')





if __name__ == '__main__':
    solve()

Measured memory_bytes: 38492
l,r=map(int,input().split())
if (l//2019) == (r//2019):
    l,r=l%2019,r%2019
    ans=2018
    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp=(i*j)%2019
            if tmp<ans:
                ans=tmp
    print(ans)
else:
    print(0)


Measured memory_bytes: 3060
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
      	
      	if (s.equals("Sunny")) {
          System.out.print("Cloudy");
        } else if (s.equals("Cloudy")) {
          System.out.print("Rainy");
        } else {
          System.out.print("Sunny");
        }       
    }
}

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

using namespace std;

int main() {
    long n;
    cin >> n;
    vector<long> b(n-1);
    for (long i = 0; i < n-1; ++i) {
        cin >> b[i];
    }

    long ans = b[0]+b[n-2];
    for (long i = 0; i < n-2; ++i) {
        ans += min(b[i], b[i+1]);
    }

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

int main(void){
	int h,w,i,j;
	string c[123];
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> c[i];
		cout << c[i] << endl;
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace _056_Goldbach_sConjecture
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (10000 * 3);

			while ((inputStr = Console.ReadLine ()) != "0")
			{
				int inputNum = int.Parse (inputStr);
				int count = 0;

				bool result = Conjecture.IsConjecture (2, inputNum - 2);
				if (result)
					count++;

				for (int lp = 3; lp <= inputNum / 2; lp += 2)
				{
					bool result2 = Conjecture.IsConjecture (lp, inputNum - lp);
					if (result2)
						count++;
				}

				output.AppendLine (count.ToString ());
			}

			Console.Write (output);
		}
	}

	class Conjecture
	{
		static Conjecture ()
		{
			PrimeNumberArray = new int[50000 + 1];

			//2????????°????????????????????????
			PrimeNumberArray[2] = PrimeNumber;
			for (int lp = 2 * 2; lp < PrimeNumberArray.Length; lp += 2)
			{
				PrimeNumberArray[lp] = NotPrimeNumber;
			}

			int limit = (int) Math.Sqrt (50000);
			for (int lp = 3; lp <= limit; lp += 2)
			{
				if (PrimeNumberArray[lp] != NotPrimeNumber)
				{
					//?????????????????????
					for (int lp2 = lp * 2; lp2 < PrimeNumberArray.Length; lp2 += lp)
					{
						PrimeNumberArray[lp2] = NotPrimeNumber;
					}
				}
			}
		}

		private static int[] PrimeNumberArray;
		private const int PrimeNumber = 0;
		private const int NotPrimeNumber = int.MinValue;
		
		public static bool IsConjecture ( int num, int num2 )
		{
			return
				(PrimeNumberArray[num2] == PrimeNumber) &&
				(PrimeNumberArray[num] == PrimeNumber);
		}
	}
}

Measured memory_bytes: 9708
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder {

    class MainClass {

        public static void Main(string[] args) {

            var array = Console.ReadLine().Split(' ');
            var h = int.Parse(array[0]);
            var n = int.Parse(array[1]);

            var array2 = Console.ReadLine().Split(' ');

            foreach(var a in array2) {

                h -= int.Parse(a);

            }

            if(h <= 0) {

                Console.WriteLine("Yes");

            } else {

                Console.WriteLine("No");

            }


        }

        

    }
}

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

int main() {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	if (k * 2 >= n) {
		cout << n << endl;
		return 0;
	}
	int num[100000];
	int pointer = 0;
	for (int i = 0; i < 100000; i++) {
		num[i] = 0;
	}
	if (s.find('1') == -1 && k == 0) {
		cout << 0 << endl;
		return 0;
	}
	bool is0 = false;
	for (int i = 0; i < s.length(); i++) {
		if ((is0 && s[i] == '0') || (!is0 && s[i] == '1')) {
			num[pointer]++;
		} else {
			is0 = !is0;
			pointer++;
			num[pointer]++;
		}
	}
	int ans = 0;
	k = k * 2 + 1;
	for (int i = 0; i < 100000 - k; i+=2) {
		int sum = 0;
		for (int j = 0; j < k; j++) {
			sum += num[i + j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

ll ans;

ll fun(ll h,ll w){
	ll ta = (w+1) / 2;
	ll tb = h*(w-ta);
	ta = (h+1) / 2;
	tb = max(tb,w*(h-ta));
	return tb;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll h,w; cin >> h >> w;
	ans = 1e16;
	ll ta = (w+2) / 3;
	ll tb = fun(h,w-ta);
	ans = min(ans,ta*h-tb);
	ta = (w) / 3;
	tb = fun(h,w-ta);
	ans = min(ans,abs(ta*h+tb-h*(w-ta)));
	ta = (h+2) / 3;
	tb = fun(h-ta,w);
	ans = min(ans,ta*w-tb);
	ta = (h) / 3;
	tb = fun(h-ta,w);
	ans = min(ans,abs(ta*w+tb-w*(h-ta)));
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  string s[H];
  char sharp[W+2];

  for (int i =  0; i < W+2 ; i++){
    sharp[i] ='#';
  }

  for (int i =  0; i < H ; i++){
    cin >> s[i];
  }

  for (int i =  0; i < W+2 ; i++){
    cout << sharp[i];
  }

  cout << endl;

  for (int i =  0; i < H ; i++){
    cout << '#' << s[i] << '#' << endl;
  }

  for (int i =  0; i < W+2 ; i++){
    cout << sharp[i];
  }

  cout << endl;  
}


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

typedef long long ll;


void solve(long long N){
  ll tmp = N % 10;
  switch (tmp){
    case 3:
    cout <<"bon" << endl;
    break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout <<"pon" << endl;
      break;
    default:
    cout << "hon"<<endl;
    break;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  char c;
  cin >> c;
  cout << ++c << endl;
  return 0;
}

Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }
    else{
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
 
int main()
{
    long long int n;cin >> n;
    long long int sum;

    long long int ans1=0,ans2=0;

    vector<long long int> a;
    for(int i=1;i<=n;i++){
        long long int tmp;cin >> tmp;
        a.push_back(tmp);
    }


    sum=0;
    for(int i=1;i<=n;i++){
        sum += a[i-1];
        if(i%2==0 && sum <= 0){
            ans1 += abs(sum) + 1;
            sum = 1;
        } else if (i%2==1 && sum >= 0){
            ans1 += abs(sum) + 1;
            sum = -1;
        }
    }

    sum=0;    
    for(int i=1;i<=n;i++){
        sum += a[i-1];
        if(i%2==0 && sum >= 0){
            ans2 += abs(sum) + 1;
            sum = -1;
        } else if (i%2==1 && sum <= 0){
            ans2 += abs(sum) + 1;
            sum = 1;
        }
    }
    p(min(ans1,ans2))
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  map<string,vector<int>> mp;
  string s;
  int d;
  rep(i,n){
    cin >> s >> d;
    mp[s].push_back(d);
  }
  for(auto &p:mp) sort(all(p.second));
  int m;
  cin >> m;
  d=0;
  rep(i,m){
    cin >> s;
    vector<int> &v=mp[s];
    auto itr=upper_bound(all(v),d);
    if(itr!=v.end()){
      d=(*itr);
    }else{
      CNO;
      return 0;
    }
  }
  CYES;
  return 0;
}



Measured memory_bytes: 21888
#include <stdio.h>
int main(){
    int n,l,r,tot;
    bool f;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        tot=0;
        f=false;
        for(int i=0;i<12;i++){
            scanf("%d%d",&l,&r);
            tot+=l-r;
            if(tot>=n&&!f){
                f=true;
                printf("%d\n",i+1);
            }
        }
        if(!f)printf("NA\n");
        
    }
}

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

ll memo[101][100001];
ll knapsack(int W, int n, int *wt, ll *val)
{
    ll &ans = memo[n][W];
    if (ans != -1)
        return ans;
    if (n == 0 || W == 0)
        return ans = 0;
    ans = knapsack(W, n - 1, wt, val);
    if (W >= wt[n - 1])
        ans = max(ans, val[n - 1] + knapsack(W - wt[n - 1], n - 1, wt, val));
    return ans;
}

ll knapsackdp(int W, int n, int *wt, ll *val)
{
    ll dp[n + 1][W + 1];
    for (int i = 0; i <= n; i++)
        dp[i][0] = 0;
    for (int w = 0; w <= W; w++)
        dp[0][w] = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int w = 1; w <= W; w++)
        {
            dp[i][w] = dp[i - 1][w];
            if (w >= wt[i - 1])
                dp[i][w] = max(dp[i][w], val[i - 1] + dp[i - 1][w - wt[i - 1]]);
        }
    }

    return dp[n][W];
}

int main()
{
    memset(memo, -1, sizeof memo);
    int n, w;
    cin >> n >> w;
    int wt[n];
    ll val[n];
    for (int i = 0; i < n; i++)
        cin >> wt[i] >> val[i];
    cout << knapsackdp(w, n, wt, val) << "\n";
    return 0;
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;

  cout << 48 - n << endl;
  
  return (0);
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=55;
lli n,m,q,store[N][4],ans;
vector<lli> v;

void solve(lli ind, lli end)
{
    if(ind==n)
    {
        lli ans1=0;
        
        for(int i=0;i<q;i++)
        {
            if(v[store[i][1]-1] - v[store[i][0]-1] == store[i][2])
                ans1+=store[i][3];
        }
        ans=max(ans,ans1);
        
        return;
    }
    
    for(int j=end;j<=m;j++)
    {
        v.push_back(j);
        solve(ind+1,j);
        v.pop_back();
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m>>q;
    for(int i=0;i<q;i++) for(int j=0;j<4;j++) cin>>store[i][j];
    
    solve(0,1);
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3616
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/* eslint-env es6, mocha, node */
/* eslint-extends: eslint:recommended */
'use strict';



// Import modules
import fs = require("fs");


// Read stdin
const data = fs.readFileSync("/dev/stdin", "utf-8").split("\n");
const values = data[0].split(" ").map((v) => Number(v));


// Main
const result = values.every((value) => {
    return (value < 9);
});


// Output
console.log(result ? "Yay!" : ":(");



/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */

Measured memory_bytes: 7372
import hashlib
from sys import stdin

def insert(v, B):
    key = hashlib.md5(v.encode("utf-8")).hexdigest()
    B[key] = v

def search(v, B):
    key = hashlib.md5(v.encode("utf-8")).hexdigest()
    if key in B:
        return key
    else:
        return 0

def read_and_print_word_dict(n):
    B = {}
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            insert(cmd[1], B)
        elif cmd[0] == 'find':
            res = search(cmd[1], B)
            if res == 0:
                print("no")
            else:
                print("yes")

n = int(input())
read_and_print_word_dict(n)


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

using namespace std;

typedef long long ll;

int main()
{
    int n , i , j , k , mn = 10000 , mx = -10000 , sum  = 0;
    int l;

    scanf("%d %d",&n,&l);

    for(i = 1 ; i <= n ; i++)
    {
        k = l+i-1;

        sum += k;
        if(k  < 0) k = -k;
        if(k < mn) mn = k;
    }




    if(sum >= 0) sum -= mn;
    if(sum < 0) sum += mn;

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


    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
bool bit[600000];
int lb, lim;

int main(void)
{
	cin >> n;
	
	for(int i = 0; i < 600000; i++) bit[i] = false;
	lb = 0, lim = -1;
	
	int x;
	for(int in = 0; in < n; in++){
		cin >> x;
		
		if(bit[0]){
			cout << "No" << endl;
			continue;
		}
		if(x <= lb && x < lim){
			cout << "No" << endl;
			continue;
		}
		
		if(x >= 600000){
			lim = x;
			cout << "Yes" << endl;
			continue;
		}
		
		if(x == lb+1){
			bit[x] = true;
			lim = max(lim, x);
			for(int i = x; i < 600000; i++){
				if(bit[i]) lb = i;
				else break;
			}
		}
		else{
			for(int i = x; i >= 0; i--){
				if(!bit[i]){
					bit[i] = true;
					if(i == lb+1) lb++;
					lim = max(lim, i);
					break;
				}
				bit[i] = false;
				if(i == lim) lim--;
			}
		}
		cout << "Yes" << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    cout << 0 << endl;
  }
  else if (A < 13) {
    cout << B / 2 << endl;
  }
  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, C, x, v;
lint X[100001], V[100001];
lint points[2][100002];

lint solve() {
	lint maxv = 0;
	REP(i, N) {
		points[0][i + 1] = V[i];
		points[1][N - i] = V[i];
	}
	REP(i, N) {
		points[0][i + 1] += points[0][i];
		points[1][i + 1] += points[1][i];
	}
	REP(i, N) {
		points[0][i + 1] -= 2 * X[i];
		points[1][N - i] -= (C - X[i]);
	}
	lint index = 0, curr = 0;
	REP(i, N + 1) {
		if (curr < points[0][i]) {
			curr = points[0][i];
			index = i;
		}
		if (maxv < points[1][N - i] + points[0][index]) {
			maxv = points[1][N - i] + points[0][index];
		}
	}
	return maxv;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> C;
	REP(i, N) {
		cin >> X[i] >> V[i];
	}
	lint ans = 0;
	chmax(ans, solve());
	reverse(V, V + N);
	REP(i, N) X[i] = C - X[i];
	reverse(X, X + N);
	chmax(ans, solve());
	cout << ans << endl;
}


Measured memory_bytes: 6760
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int res;
int n,a;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		mp[a]++;
	}
	for(__typeof(mp.begin()) it=mp.begin();it!=mp.end();it++){
		int id=it->first;
		int cand=mp[id];
		if(mp.count(id-1)){
			cand+=mp[id-1];
		}
		if(mp.count(id+1)){
			cand+=mp[id+1];
		}
		res=max(res,cand);
	}
	cout<<res<<endl;
	return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MOD 1000000007
using namespace std;

pii sec(vi & v){
	vi used(sz(v) + 1 , 0);
	rep(i , sz(v)){
		int e = v[i];
		if(used[e])
			return {used[e] - 1 , i};
		used[e] = i + 1;
	}
}

int fac[200002], ifac[200002];

inline int fpow(int a, int st) {
	int ans = 1;
	while (st) {
		if (st % 2) ans = (ll)ans * a % MOD;
		a = (ll)a * a % MOD;
		st /= 2;
	}
	return ans;
}

inline int cnk(int n, int k) {
	if (n < 0 || k < 0 || k > n) return 0;
	return (ll)fac[n] * ifac[n - k] % MOD * ifac[k] % MOD;
}

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

	fac[0] = ifac[0] = 1;
	repi(i, 200000 - 1) {
		fac[i] = (ll)fac[i - 1] * i % MOD;
		ifac[i] = fpow(fac[i], MOD - 2);
	}
	

	int n;
	cin >> n;
	
	vi v(n + 1);
	rep(i , n + 1){
		cin >> v[i];
	}
	
	auto m = sec(v);
	
	ll ans = 0;
	
	vector<vector<ll>> dp(n + 1 , vector<ll>(3));
	int k = 0;
	repi(i , n + 1){
		ans = 0;
		if(i == 1){
			ans = n;
		}else if(i == n + 1){
			ans = 1;
		}else{
			ans = cnk(n + 1 , i) % MOD;

			ans -= cnk(n - m.se + m.fi , i - 1);

			ans %= MOD;
			while(ans < 0)ans += MOD;
		}
		cout << ans << nl;
	}

	return 0;
}

Measured memory_bytes: 8696
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int x, a;
    cin >> x >> a;
    int res;
    if(x < a)res = 0;
    else res = 10;
    cout << res << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ((A + B) % 2 == 0){
    cout << (A + B) / 2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

const static array<int, 10> digit_to_match = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

class Solution {
public:
    void dfs_num_digits(int d, int matches_left, const vector<int>& avail, int& depth) {
        if (matches_left < 0) {
            return;
        }
        if (matches_left == 0) {
            depth = max(depth, d);
            return;
        }
        if (matches_left / avail[0] + d <= depth) { // prune
            return;
        }
        for (int m : avail) {
            dfs_num_digits(d + 1, matches_left - m, avail, depth);
        }
    }

    void dfs_gen_result(int d, int num_digits, int matches_left, const vector<int>& digits,
                        const vector<int>& avail, string& buf, string& result, bool& found) {
//        LOG("{}\n", buf);
        if (found || d > num_digits) {
            return;
        }
        if (matches_left == 0 && d == num_digits) {
            found = true;
            result = buf;
            LOG("Setting result to {}\n", result);
            return;
        }
        if (matches_left <= 0) {
            return;
        }
        if (d + matches_left / avail[0] < num_digits) { // no enough matches to gen enough digits
            return;
        }
        for (int i = digits.size() - 1; i >= 0; --i) {
            int dig = digits[i];
            buf += char('0' + dig);
            dfs_gen_result(d + 1, num_digits, matches_left - digit_to_match[dig], digits, avail,
                    buf, result, found);
            buf.pop_back();
        }
    }

    string match_matching(int N, vector<int>& digits) {
        sort(digits.begin(), digits.end());
        vector<int> avail_matches;
        for (int d : digits) {
            avail_matches.emplace_back(digit_to_match[d]);
        }
        sort(avail_matches.begin(), avail_matches.end());
        auto new_end = unique(avail_matches.begin(), avail_matches.end());
        avail_matches.resize(new_end - avail_matches.begin());

        int num_digits = 0;
        dfs_num_digits(0, N, avail_matches, num_digits);
        LOG("{}\n", num_digits);

        bool found = false;
        string buf;
        string result;
        dfs_gen_result(0, num_digits, N, digits, avail_matches, buf, result, found);
        return result;
    }

private:

};

int solve() {
    Solution solution;
    // handle IO here
    int N, M;
    cin >> N >> M;
    vector<int> digits(M);
    for (int i = 0; i < M; ++i) {
        cin >> digits[i];
    }
    cout << solution.match_matching(N, digits) << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 512
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
A=[0]*N
for i in range(len(V)):
    for j in range(len(C)):
        A[i]=V[i]-C[i]
n=0
for i in range(len(A)):
    if A[i]>=0:
        n+=A[i]
print(n)



Measured memory_bytes: 3064
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:10th May 2020
  Category:DP
  ToDo:
 */
#include<bits/stdc++.h>
#define dbg(x) cerr <<__LINE__<<" where "<< #x << " = " << x << endl
#define all(x) (x).begin(),(x).end()

using namespace std;
template <class T> inline void read(T &res)
{
    res = 0; bool bo = 0; char c;
    while (((c = getchar()) < '0' || c > '9') && c != '-');
    if (c == '-') bo = 1; else res = c - 48;
    while ((c = getchar()) >= '0' && c <= '9')
        res = (res << 3) + (res << 1) + (c - 48);
    if (bo) res = ~res + 1;
}
const int N=20;
typedef long long ll;
int len,_,n,d,k,m,l,c,cs=1;
string s,t;
int score[N][N],book[12],cst[N];
bool Ok()
{
  for(int i=0;i<m;++i)
  {
    if(book[i]<k)return false;
  }
  return true;
}
void HalfDead() 
{
  read(n); read(m); read(k);
  for(int i=0;i<n;++i)
  {
    read(cst[i]);
    for(int j=0;j<m;++j)read(score[i][j]);
  }
 // int x=(1<<n);
//  dbg(x);
  int ans=1e9;
  for(int mask=1;mask<(1<<n);++mask)
  {
    int cost=0;
    memset(book,0,sizeof book);
    for(int i=0,mk=mask;mk>0;++i,mk>>=1)
    {
      if(mk&1)
      {
       // dbg("hi");
        cost+=cst[i];
        for(int j=0;j<m;++j)book[j]+=score[i][j];
      }
    }
   // dbg(cost);
    if(Ok())
    {
     ans=min(ans,cost);
    }

  } // end 

  ans>=1e9?cout<<"-1"<<endl:cout<<ans<<endl;
}
int main()
{
  HalfDead();
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class BIT {
public:
  int N;
  vi arr;
  BIT(int n) {
    N = n;
    arr = vi(N+1,0);
  }
  int sum(int x) {
    int s = 0;
    for(int i = x+1;i > 0;i -=i&(-i)) {
      s += arr[i];
    }
    return s;
  }
  void add(int x,int k) {
    for(int i = x+1;i <= N;i +=i&(-i)) {
      arr[i] += k;
    }
  }
};
  
int main() {
  ll N,K;
  cin >> N >> K;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vl acc(N+1,0);
  rep(i,N) {
    acc[i+1] = acc[i]+A[i];
  }
  vl B(N+1,0);
  rep(i,N+1) {
    B[i] = acc[i]-K*i;
  }
  map<ll,int> mp;
  typedef pair<ll,int> PL;
  v(PL) BI(N+1);
  rep(i,N+1) {
    BI[i] = PL(B[i],i);
  }
  sort(rng(BI));
  rep(i,N+1) {
    mp[BI[i].first]=i;
  }
  BIT bit(N+1);
  ll ans = 0;
  rep(i,N+1) {
    ans += bit.sum(mp[B[i]]);
    bit.add(mp[B[i]],1);
  }
  cout << ans << endl;
  return 0;
}

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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(Console.ReadLine());
            List<string> result = new List<string>();
            for (int i = 0; i < n; i++)
            {
                string[] cmd = Console.ReadLine().Split(' ');
                int a = int.Parse(cmd[1]);
                int b = int.Parse(cmd[2]);

                string word = str.Substring(a, b - a + 1);
                string word_b = str.Substring(0, a);
                string word_e = str.Substring(b + 1);

                if (cmd[0] == "print")
                {
                    result.Add(word);
                }
                else if (cmd[0] == "replace")
                {
                    str = word_b + cmd[3] + word_e;
                }
                else
                {
                    str = word_b + string.Join("", word.Reverse()) + word_e;
                }
            }
            foreach (string item in result)
                Console.WriteLine(item);
        }
    }
}


Measured memory_bytes: 20328