akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<int> A(5);
  for(auto& a : A){
    cin >> a;
  }
  int k;
  cin >> k;
  for(int ii=0; ii<5; ii++){
    for(int jj=ii+1; jj<5; jj++){
      if(A[jj] - A[ii] > k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n;
int main(){
	cin>>n;
	if ((n&(-n))==n)cout<<"No"<<endl;
	else {
		cout<<"Yes"<<endl;
		printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n",n+1,n+1,n+2,n+2,n+3);
		for (int i=4;i<n;i+=2){
			printf("%d %d\n%d %d\n",n+1,i,i,i+1+n);
			printf("%d %d\n%d %d\n",n+1,i+1,i+1,i+n);
		}
		if (~n&1){
			int k=n&(-n);
			printf("%d %d\n%d %d\n",k^1,n,n^k,n+n);
		}
	}
} 

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

int main() {
  char c;
  cin >> c;
  if(c=='a' || c=='i' || c== 'u' || c=='e' || c=='o'){
    cout << "vowel";
  }else{
    cout << "consonant";
  }
  cout << endl;
}


Measured memory_bytes: 256
coin500 = int(input())
coin100 = int(input())
coin050 = int(input())
target = int(input())
x = 0
 
for a in range(coin500+1):
  for b in range(coin100+1):
    for c in range (coin050+1):
     if target == a * 500 + b * 100 + c * 50:x += 1
print(x)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

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

  long long ans = 0;
  long long r=0,g=0,b=0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
    if(s[i] == 'B') b++;
  }
  ans = r*g*b;
  // cout << ans << endl;

  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      int k = 2*j - i;
      if(k < n && s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) ans --;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3512
import heapq
X, Y, A, B, C = map(int, input().split())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
CL = list(map(int, input().split()))
h = []
for a in AL:
  heapq.heappush(h, (-a, 0))
for b in BL:
  heapq.heappush(h, (-b, 1))
for c in CL:
  heapq.heappush(h, (-c, 2))
answer = 0
x_cnt = 0
y_cnt = 0
eat_cnt = 0
for _ in range(A+B+C):
  if eat_cnt >= X+Y:
    break
  d, t = heapq.heappop(h)
  if t == 0 and x_cnt+1 <= X:
    answer += -d
    x_cnt += 1
    eat_cnt += 1
  elif t == 1 and y_cnt+1 <= Y:
    answer += -d
    y_cnt += 1
    eat_cnt += 1
  elif t == 2:
    answer += -d
    eat_cnt += 1
print(answer)

Measured memory_bytes: 117536
n = int(input())
T,a = map(int,input().split())
li = list(map(int,input().split()))

m = 10**100
count = 0

for i in range(n):
    t = T - li[i] * 0.006
    if abs(t-a) < abs(m-a):
        m = t
        count = i+1

print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,p,a[N];
long long f[N][2];
int main() {
    n=gi(),p=gi();
    for(int i=1;i<=n;i++) a[i]=gi();
    f[0][0]=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++) {
            f[i+1][j]+=f[i][j];
            f[i+1][(j+a[i+1])&1]+=f[i][j];
        }
    printf("%lld\n",f[n][p]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 1e6 + 5;
int n = 0, m = 0;
int a[MAXN];
int b[MAXN];

bool check(ld n){
	ld sq = sqrt(n);
	return ((sq - floor(sq)) == 0);
}


int main() {
	string a;
	string b;
	cin >> a >> b;
	a+=b;
	ld k = stold(a);
	if(check(k)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	

    return 0;
} 

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  bool flag = true;
  int num = 0;

  int a, b, x; cin >> a >> b >> x;

  if (a + b < x) flag = false;
  if (x < a) flag = false;

  // cout << num << endl;
  cout << (flag ? "YES" : "NO") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<climits>
#include<cstring>
using namespace std;
#define ll long long

void solve(ll n,ll w,ll*weight,ll*value)
{
	ll maxVal=n*1000;
	ll dp[n+1][maxVal+1];

	for(int i=1;i<=maxVal;i++)
		dp[1][i]=1e9+1;

	dp[1][0]=0;
	dp[1][value[0]]=weight[0];
	
	for(ll i=2;i<=n;i++)
	{
		for(ll j=1;j<=maxVal;j++)
		{
			if(j-value[i-1]>=0)
				dp[i][j]=min(dp[i-1][j],weight[i-1]+dp[i-1][j-value[i-1]]);
		
			else
				dp[i][j]=dp[i-1][j];
		}
	}

	ll ans=0;
	for(ll i=0;i<=maxVal;i++)
	{
		if(dp[n][i]<=w)
			ans=i;
	}

	cout<<ans;
}

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

	ll*weight=new ll[n];
	ll*value=new ll[n];

	for(int i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;

		weight[i]=x;
		value[i]=y;
	}

	solve(n,w,weight,value);
	return 0;
}


Measured memory_bytes: 81744
figure = ''
height, width = [int(x) for x in input().split()]
while height or width:
    pattern = '#.' * (width//2 + 1)
    for h in range(height):
            figure += pattern[h%2 : h%2 + width] + '\n'
    figure += '\n'
    height, width = [int(x) for x in input().split()]
 
print(figure[:-1])

Measured memory_bytes: 7728
def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

N = intinput()
ans = 0
for i in range(N):
    a,b = splitintinput()
    ans += b-a+1

print(ans)



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<bitset>
using namespace std;
using ll = long long;
int main(){
  ll a, b;
  cin >> a >> b;
  ll e[100] = {};

  ll ans = 0;
  for(ll bit = 40; bit >= 0; bit--) {
    ll tmp = 0;
    if(bit == 0) {
      tmp = ((b - a) / (ll)pow(2, bit + 1) +
             max(min(b % (ll)pow(2, bit + 1), (ll)1),
                 min(a % (ll)pow(2, bit + 1), (ll)1))) % 2;
      //cout << tmp;
    } else {
      if(b >> bit & 1){
        tmp = 1 + b & 1;
      } else {
        tmp = 0;
      }
      if(a >> bit & 1){
        tmp += 1 + !(a & 1);
      }
      tmp %= 2;
    }
    if(tmp == 1) {
      //cout << 1;
      e[bit] = 1;
    } else {
      //cout << tmp;
      e[bit] = 0;
    }
  }
  ll sum = 0;
  
  for(ll bit = 40; bit >= 0; bit--) {
    sum += e[bit] << bit;
  }
  cout << sum << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sqr(k) ((k)*(k))
#define ll long long
using namespace std;

const int S = 115;
int n, x[S], v = 2e9;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	for (int i = 1; i <= 100; i++) {
		int p = 0;
		for (int j = 1; j <= n; j++) 
			p += sqr(abs(i - x[j]));
		if (p < v) v = p;
	}
	cout << v << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    char s[11];
    int i;

    for(i=0; i<=9; i++){
        scanf("%c",&s[i]);
    }

    s[3]='8';
    for(i=0; i<=8; i++){
        printf("%c",s[i]);
    }
    printf("%c\n",s[9]);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/union_find.hpp
#ifndef UNION_FIND_HPP
#define UNION_FIND_HPP


/*
usage:

tools::union_find<std::int_fast64_t> uf(10);
uf.unite(1, 3);
uf.is_same(1, 3);
*/

namespace tools {
  template <typename T>
  class union_find {
  private:
    std::vector<T> parents;
    std::vector<T> sizes;

    T root(const T x) {
      return this->parents[x] == x ? x : (this->parents[x] = this->root(this->parents[x]));
    }

  public:
    union_find(const T n) :
      parents(n),
      sizes(n, 1) {
      for (T i = 0; i < n; ++i) {
        parents[i] = i;
      }
    }

    bool is_same(const T x, const T y) {
      return this->root(x) == this->root(y);
    }

    void unite(T x, T y) {
      x = this->root(x);
      y = this->root(y);
      if (x == y) return;

      if (this->sizes[x] < this->sizes[y]) std::swap(x, y);
      this->parents[y] = x;
      this->sizes[x] += this->sizes[y];
    }

    T size(const T x) {
      return this->sizes[this->root(x)];
    }
  };
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  tools::union_find<i64> uf(N);
  i64 answer = N;
  for (i64 i = 0; i < M; ++i) {
    i64 X_i, Y_i, Z_i;
    std::cin >> X_i >> Y_i >> Z_i;
    --X_i;
    --Y_i;
    if (!uf.is_same(X_i, Y_i)) {
      uf.unite(X_i, Y_i);
      --answer;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1792
import numpy as np

def main():
    MOD = 10**9 + 7
    
    N = int(input())
    aff = np.array([map(int, input().split()) for i in range(N)])
    dpt = np.zeros((N+1, 1<<N), dtype='int64')
    dpt[0][0] = 1

    for i, row in enumerate(aff):
        for idx, v in enumerate(row):
            if v == 1:
                dpt[i+1][(1<<idx):] += dpt[i][:-(1<<idx)]
        dpt[i+1] %= MOD

    print(dpt[N][(1<<N)-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 370828
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto co = 0, c2 = 0, c4 = 0;
  auto rd = readln.splitter;
  foreach (_; 0..n) {
    auto a = rd.front.to!int; rd.popFront();
    if (a % 2 != 0) ++co;
    else if (a % 4 != 0) ++c2;
    else ++c4;
  }

  writeln(c2 > 0 && co <= c4 || c2 == 0 && co <= c4+1 ? "Yes" : "No");
}


Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  if(n == 1){
    cout << "Yes" <<endl;
    return 0;
  }

  bool ans = true;
  for(int i = 1; i < n; ++i){
    if(h[i] > h[i - 1]) h[i]--;
  }

  for(int i = 1; i < n; ++i){
    if(h[i - 1] > h[i]) ans = false;
  }

  if(ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using namespace std;

int main()
{
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, a;
    cin >> n >> a;
    cout << n * n - a;
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,m;
  cin>>n>>m;
  rep(i,m){
    ll a;
    cin>>a;
    n-=a;
  }
  cout<<(n>=0?n:-1)<<endl;

}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, l;
	cin >> n >> l;

	string s[100];
	rep(i, n) cin >> s[i];

	sort(s, s + n);

	string ans = "";
	rep(i, n) ans += s[i];

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<utility>
using namespace std;
 
typedef long long ll;

int main(){
	int n,m,k;
    cin >> n >> m >> k;
    for(int i =0;i<=n; i++){
    	for(int j=0;j <=m; j++){
        	if( (n-i)*j + i*(m-j) == k){
            	cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int r,x,d;
    int answer;
    scanf("%d%d%d",&r,&d,&x);
    answer = x;

    for(int i = 0;i < 10; i++){
        answer = answer*r-d;
        printf("%d\n",answer);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }

struct edge{
    int to;
    bool f;
};

vector<vector<edge>> G;

int main()
{
    int v, e;
    cin >> v >> e;
    G.resize(v);
    vector<int> iri(v, 0);

    rep(i, e){
        int from, to; cin >> from >> to;
        G[from].push_back({to, true});
        iri[to]++;
    }

    queue<int> que;
    rep(i, v) if(iri[i]==0) que.push(i);
    vector<int> res;

    while(!que.empty()){
        int a = que.front(); que.pop();
        res.push_back(a);

        for(auto ed: G[a]){
            iri[ed.to]--;
            if(iri[ed.to]==0) que.push(ed.to);
        }
    }

    rep(i, v){
        cout << res[i] << endl;
    }
    // prvec(res
    return 0;}


Measured memory_bytes: 3932
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll abcnt[27]={0};
int main(){
  string s;
  cin>>s;
  ll n=s.length();
  for(int i=0;i<n;i++){
    abcnt[(int)(s[i]-'a')]++;
  }
  ll ans=n*n-((n*(n+1))/2);
  for(int i=0;i<26;i++) ans-=(abcnt[i]*(abcnt[i]-1))/2;
  cout<<ans+1<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n, 0);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    //med-1 med
    int med = n / 2;
    cout << v[med] - v[med - 1] << endl;
    return 0;
}


Measured memory_bytes: 640
n = gets.to_i
as = gets.split.map(&:to_i)

c1 = as.max

as.delete(c1)

as = as.map{|a| 2 * a - c1}
c = as.min{|a, b| a.abs - b.abs}

print c1, ' ', (c + c1) / 2

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

int main() {
	int a[4],b[2],c=0,d=0;
	for(int i=0;i<4;i++){
		cin>>a[i];
	}
	for(int i=0;i<2;i++){
		cin>>b[i];
	}
	sort(a,a+4);
	reverse(a,a+4);
	if(b[0]<b[1]){
		b[0]=b[1];
	}
	for(int i=0;i<3;i++){
		c=c+a[i];
	}
	d=b[0];
	d=d+c;
	cout<<d<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3140
N = gets.to_i
arr = gets.split(" ").map{ |v|
	v.to_i
}


ans1 = 0
sum = 0
0.upto(N-1){ |i|
	sum = sum + arr[i]
	if i % 2 == 0 and sum <= 0 then
		ans1 += (1 - sum)
		sum = 1
	elsif i % 2 == 1 and sum >= 0 then
		ans1 += (sum - (-1))
		sum = -1
	end
}

arr2 = arr.map{ |v|
	-v
}

ans2 = 0
sum = 0
0.upto(N-1){ |i|
	sum = sum + arr2[i]
	if i % 2 == 0 and sum <= 0 then
		ans2 += (1 - sum)
		sum = 1
	elsif i % 2 == 1 and sum >= 0 then
		ans2 += (sum - (-1))
		sum = -1
	end
	
}

puts [ans1, ans2].min


Measured memory_bytes: 9356
from collections import deque

def bfs(i, c):
    q = deque()
    q.append(i)
    while q:
        p = q.popleft()
        for j in g[p]:
            if c[j] == 0 and i != j:
                q.append(j)
                c[j] = c[p] + 1
    return c

n = int(input())
g = [-1] * n
c1 = [0] * n
c2 = [0] * n
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if g[a] == -1:
        g[a] = [b]
    else:
        g[a].append(b)
    if g[b] == -1:
        g[b] = [a]
    else:
        g[b].append(a)

c1 = bfs(0, c1)
c2 = bfs(n - 1, c2)

F, S = 0, 0
for i in range(n):
    if c1[i] <= c2[i]:
        F += 1
    else:
        S += 1
print("Fennec" if F > S else "Snuke")

Measured memory_bytes: 29332
#include <iostream>
#include <algorithm>

using namespace std;
int X[50];
long long table[51][51][2501];
int N,A;

int main(){
  cin >> N >> A;
  for(int i=0;i<N;++i){
    cin >> X[i];
  }
  long long pat = 0;

  for(int i=0;i<=N;++i){
    for(int c=0;c<=N;++c){
      for(int s = 0;s<=N*50;++s){
        if( i == 0 && c == 0 && s == 0 ){
          table[i][c][s] = 1;
        }else if( i > 0 && s < X[i-1]) {
          table[i][c][s] = table[i-1][c][s];
        }else if( i > 0 && c>=1 && s >= X[i-1] ){
          table[i][c][s] = table[i-1][c-1][s-X[i-1]] + table[i-1][c][s];
        }else{
          table[i][c][s] = 0;
        }
      }
    }
  }
  for(int c=1;c<=N;++c){
    pat += table[N][c][c*A] ;
  }
  cout << pat << endl;
  return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;
    if(a=="H"&&b=="H"){
        cout << "H" << endl;
    }else if(a=="H"&&b=="D"){
        cout << "D" << endl;
    }else if(a=="D"&&b=="H"){
        cout << "D" << endl;
    }else if(a=="D"&&b=="D"){
        cout << "H" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N+1);
    rep(i,N){
        cin >> A[i+1];
    }
    if((A[0]*2+K-1)*K/2 > N){
        rep(i,N){
            A[i] = N;
        }
        PR(A,N);
        return 0;
    }
    rep(j,K){
        vector<ll> S(N*2);
        REP(i,1,N+1){
            if(i - A[i] >= 0){
                S[i - A[i]]++;
            }else{
                S[0]++;
            }
            if(i+1 + A[i] <= N){
                S[i+1 + A[i]]--;
            }else{
                S[N+1]--;
            }
        }
        rep(i,N){
            S[i+1] += S[i];
            A[i+1] = S[i+1];
        }
    }
    vector<ll> B(N);
    rep(i,N){
        B[i] = A[i+1];
    }
    PR(B,N);
}


Measured memory_bytes: 7968
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	if(s == "RRR") cout << "3\n";
	else if(s == "RRS" || s == "SRR") cout << "2\n";
	else if(s == "SSS") cout << "0\n";
	else cout << "1\n";
	return 0;
}

Measured memory_bytes: 3596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        x: i64,
    };

    let ans = if x == 0 {
        1
    } else {
        0
    };
    

    
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 10
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
P arr[M];

bool mswap(P a, P b){
	return a.second < b.second;
}
int main()
{ 
	int in, sum = 0;
	for(int i = 0; i < 5; i++) {
		cin >> in;
		arr[i] = make_pair(in, in % 10);
	}
	sort(arr, arr+5, mswap);
	bool first = true;
	for(int i = 0; i < 5; i++) {
		if(arr[i].second != 0 && first) {
			sum += arr[i].first;
			first = false;
		}
		else if(arr[i].second != 0) {
			sum += (arr[i].first - arr[i].second + 10);
		}
		else sum += arr[i].first;
	}
	cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});


int main() {
	char s;
	cin >> s;
	int n = 1;
	printf("%c\n", s + n);
	return 0;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())
for i, num in enumerate(range(A, B + 1)):
    if i + 1 > K:
        break
    print(num)
x = []
for i, num in enumerate(range(B, A-1, -1)):
    if i + 1 > K:
        break
    x.append(num)
x.sort()
k = B - A +1

for i in x:
    if k < 2 * K:
        k += 1
    else:
        print(i)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nkxy = Enumerable.Repeat(0, 4).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        Console.WriteLine(Min(nkxy[0], nkxy[1]) * nkxy[2] + Max(0, nkxy[0] - nkxy[1]) * nkxy[3]);
    }
}

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

#define MAX 4001

string str1, str2;

void lcs(){
    int T[MAX], NT[MAX];
    int h = str1.size();
    int w = str2.size();

    for ( int j = 0; j <= w; j++ ) T[j] = 0;

    int ans = 0;
    for ( int i = 1; i < h; i++ ){
	for ( int j = 1; j < w; j++ ){
	    if ( str1[i] == str2[j] ){
		NT[j] = T[j-1] + 1;
		ans = max(ans, NT[j]);
	    } else {
		NT[j] = 0;
	    }
	}
	for ( int j = 1; j < w; j++ ) T[j] = NT[j];
    }
    cout << ans << endl;
}

main(){
    while( cin >> str1 ){
	cin >> str2;
	str1 = ' ' + str1;
	str2 = ' ' + str2;
	lcs();
    }
}

Measured memory_bytes: 972
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll n,m;
	cin>>n>>m;
	string s[n];
	for (int i = 0; i < n; ++i){
		cin>>s[i];
	}
	ll dp[n][m];	
	dp[0][0]=1;
	for (int i = 1; i < n; ++i){
		dp[i][0]=dp[i-1][0];
		if(s[i][0]=='#')
			dp[i][0]=0;
	}
	for (int i = 1; i < m; ++i){
		dp[0][i]=dp[0][i-1];
		if(s[0][i]=='#')
			dp[0][i]=0;
	}
	for (int i = 1; i < n; ++i){
		for (int j = 1; j < m; ++j){
			if(s[i][j]=='#'){
				dp[i][j]=0;
				continue;
			}
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%modulo;
		}
	}
	cout<<dp[n-1][m-1]<<"\n";
	return 0;
}

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

int main()
{
  int n;
  cin>>n;
  int a[n],cnt=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      if(a[i]%2!=0 && (i+1)%2!=0)
        cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B)  cout << C << endl;
  else if(A==C)  cout << B << endl;
  else if(C==B)  cout << A << endl;

  return 0;
}


Measured memory_bytes: 256
import calendar
flag=False
while 1:
    a,b=map(int,input().split(" "))
    if a==b==0:break
    if flag:print()
    leaps=list(filter(calendar.isleap,range(a,b+1)))
    if not leaps:
        print("NA")
    else:
        for i in leaps:
            print(i)
    flag=True


Measured memory_bytes: 7416
package main

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

func threeNums(s string) []int {

	var ret []int

	for i := 0; i < len(s)-2; i++ {
		t, err := strconv.Atoi(s[i : i+3])

		if err != nil {
			print("Error to parse")
		}

		ret = append(ret, t)
	}

	return ret
}

func nearest(ts []int) int {

	answer := 1000

	for _, t := range ts {

		d := 753 - t

		if d < 0 {
			d = -d
		}

		if d < answer {
			answer = d
		}
	}

	return answer
}
func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanLines)

	ok := stdin.Scan()
	if !ok {
		print("Error to scan")
	}

	if err := stdin.Err(); err != nil {
		print("Error to scan")
	}

	line := stdin.Text()
	answer := nearest(threeNums(line))

	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int N;
int nextNum[114514];
int* nexts[114514];
int* henIndice[114514];

int answer[114514];

void asumikana(int idx, int pidx, int pcolor) {
	int i;
	int nextColor = 1;
	for (i = 0; i < nextNum[idx]; i++) {
		if (nexts[idx][i] != pidx) {
			int color;
			if (nextColor == pcolor) nextColor++;
			color = nextColor++;
			answer[henIndice[idx][i]] = color;
			asumikana(nexts[idx][i], idx, color);
		}
	}
}

int main(void) {
	int i;
	int K;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i < N; i++) {
		int a, b;
		if (scanf("%d%d", &a, &b) != 2) return 1;

		nexts[a] = realloc(nexts[a], sizeof(int) * (nextNum[a] + 1));
		nexts[a][nextNum[a]] = b;
		henIndice[a] = realloc(henIndice[a], sizeof(int) * (nextNum[a] + 1));
		henIndice[a][nextNum[a]] = i;
		nextNum[a]++;

		nexts[b] = realloc(nexts[b], sizeof(int) * (nextNum[b] + 1));
		nexts[b][nextNum[b]] = a;
		henIndice[b] = realloc(henIndice[b], sizeof(int) * (nextNum[b] + 1));
		henIndice[b][nextNum[b]] = i;
		nextNum[b]++;

	}

	K = 0;
	for (i = 1; i <= N; i++) {
		if (nextNum[i] > K) K = nextNum[i];
	}
	asumikana(1, 0, 0);

	printf("%d\n", K);
	for (i = 1; i < N; i++) {
		printf("%d\n", answer[i]);
	}

	for (i = 1; i <= N; i++) {
		free(nexts[i]);
		free(henIndice[i]);
	}
	return 0;
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  int a = max(h,w);
  (n % a) ? cout << n / a + 1 : cout << n / a;
  cout << "\n";
return 0;
}

Measured memory_bytes: 256
import sys

n, m = map(int, input().split())
sc = {}
for _ in range(m):
    s, c = map(int, input().split())
    if s in sc:
        if sc[s] != c:
            print(-1)
            sys.exit()
    else:
        sc[s] = c

ans = [0] * n
ans[0] = 1

for s, c in sc.items():
    ans[s-1] = c

# ansチェック
if n != 1 and ans[0] == 0:
    print(-1)
elif n==1 and m==0:
    print(0)
else:
    print(int("".join(map(str, ans))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 510;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}

int A[N][N];
vector<pii> v1,v2;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j;
    int m;
    cin>>n>>m;
    rep(i,1,n)rep(j,1,m)cin>>A[i][j];
    rep(i,1,n)
    {
        if(i%2==1)
        {
            rep(j,1,m-1){
                if(A[i][j]%2==0)continue;
                int st =i,en=j+1;
                v1.pb(mp(i,j));
                v2.pb(mp(st,en));
                A[st][en]++;
            }
            if(i==n)break;
            if(A[i][m]%2==0)continue;
                int st =i+1,en=j;
                v1.pb(mp(i,j));
                v2.pb(mp(st,en));
                A[st][en]++;
        }
        else
        {
            repv(j,m,2){
                if(A[i][j]%2==0)continue;
                int st =i,en=j-1;
                v1.pb(mp(i,j));
                v2.pb(mp(st,en));
                A[st][en]++;
            }
            if(i==n)break;
            if(A[i][1]%2==0)continue;
                int st =i+1,en=1;
                v1.pb(mp(i,j));
                v2.pb(mp(st,en));
                A[st][en]++;
        }
    }
    cout<<v1.size()<<"\n";
    fr(i,v1.size()){
        cout<<v1[i].f<<" "<<v1[i].s<<" "<<v2[i].f<<" "<<v2[i].s<<"\n";
    }






    
    return 0;
}


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

int main(){
  int front = 0;
  string S;cin >> S;
  int Q;cin >> Q;
  vector<char> F;
  vector<char> B;
  for(int q=0;q<Q;q++){
    int T;cin >> T;
    if(T==1){
      front = (front+1)%2;
    }else{
      int x;cin >> x;
      char c;cin >> c;
      if((front==0&&x==1)||(front==1&&x==2)){
        F.push_back(c);
      }else{
        B.push_back(c);
      }
    }
  }
  if(front==0){
    int N=F.size();
    for(int i=N-1;i>=0;i--){
      cout << F[i];
    }
    N = S.size();
    for(int i=0;i<N;i++){
      cout << S[i];
    }
    N = B.size();
    for(int i=0;i<N;i++){
      cout << B[i];
    }
  }else{
    int N=B.size();
    for(int i=N-1;i>=0;i--){
      cout << B[i];
    }
    N = S.size();
    for(int i=N-1;i>=0;i--){
      cout << S[i];
    }
    N = F.size();
    for(int i=0;i<N;i++){
      cout << F[i];
    }
  }
  cout << endl;
}

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


int main()
{
	string s;
	cin >> s;
	int max_ = 0;
	int i = 0;
	int idx=0;
	while (i < s.size())
	{
		if (s[i] == 'R')
		{
			idx++;
			i++;
		}
		else
		{
			if (max_ < idx) max_ = idx;
			idx = 0;
			i++;
		}
	}
	if (max_ < idx) max_ = idx;
	cout << max_;
	return 0;
}

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

int N;
vector<ll> A;

void solve(){
    vector<ll> minus, plus;
    for(int i = 0; i < N; i++){
        if( A[i] >= 0) plus.push_back(A[i]);
        else minus.push_back(A[i]);
    }
    sort(plus.begin(), plus.end(), greater<ll>());
    sort(minus.begin(), minus.end());
    if(plus.empty()) plus.push_back(minus.back()),minus.pop_back();
    if(minus.empty()) minus.push_back(plus.back()), plus.pop_back();

    vector<pair<ll, ll> > res;
    ll cur = minus[0];
    for(int i = 0; i < plus.size() - 1; i++){
        res.push_back({cur,plus[i]});
        cur -= plus[i];
    }
    res.push_back({plus.back(),cur});
    cur = plus.back() - cur;
    for(int i = 1; i < minus.size(); i++){
        res.push_back({cur,minus[i]});
        cur -= minus[i];
    }
    cout << cur << endl;
    for(auto p: res) cout << p.first << " " << p.second << endl;
}

int main(){
    cin >> N; 
    A.resize(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    solve();
}

Measured memory_bytes: 5872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k, n;
  cin >> k >> n;
  vector<int> house(n);
  for(int i = 0; i < n; ++i) cin >> house[i];
  sort(house.begin(), house.end());
  int diff = -1;
  for(int i = 0; i < n - 1; ++i) diff = max(diff, house[i + 1] - house[i]);
  diff = max(diff, k - house[n - 1] + house[0]);
  cout << k - diff << endl;
}

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

using namespace std;

int main(){
    int a,b;
    bool first=true;
    while(true){
        cin>>a>>b;
        if(a==0&&b==0)break;
        else if(first)first=false;
        else cout<<endl;
        bool f=true;
        for (int i = a; i <= b; ++i) {
            if(i%4==0){
                if(i%100==0){
                    if(i%400==0){
                        cout<<i<<endl;
                        f=false;
                    }
                }
                else {
                    cout<<i<<endl;
                    f=false;
                }
            }
        }
        if(f)cout<<"NA"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3056
#include <stdio.h>

char s[11], e[11];

int main(void)
{
	int i, j = 0;

	scanf("%s", s);
	for (i = 0; s[i]; ++i)
	{
		if (s[i] == 'B')
		{
			if (j) --j;
		}
		else
		{
			e[j++] = s[i];
		}
	}
	e[j] = 0;
	printf("%s\n", e);

	return 0;
}

Measured memory_bytes: 1660
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		HashSet<String> dic = new HashSet<String>();
		for (int i = 0; i < n; i++) {
			String inst = scan.next();
			String str = scan.next();
			switch (inst) {
			case "insert":
				dic.add(str);
				break;
			case "find":
				System.out.println(dic.contains(str) ? "yes" : "no");
				break;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



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

int main(){
  ll a, b;
  cin >> a >> b;
  if(a <= 0 && b >= 0) cout << "Zero" << endl;
  else if(a > 0 && b > 0) cout << "Positive" << endl;
  else cout << ((b - a + 1) % 2 ? "Negative" : "Positive") << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
ch = [[],[]]
for i in S:
    if not i in ch[0]:
        ch[0].append(i)
        ch[1].append(1)
    else:
        idx = ch[0].index(i)
        ch[1][idx] += 1
ans = 1
for i in ch[1]:
    ans *= i + 1
ans -= 1
print(ans % (10**9 + 7))

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,sum=0;
	cin >> n;
	vll a(n+1),b(n);
	rep(i,n+1) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n){
		ll left=min(a[i],b[i]);
		sum+=left;
		a[i]-=left;
		b[i]-=left;
		ll right=min(a[i+1],b[i]);
		sum+=right;
		a[i+1]-=right;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
/*Infor {{{
 ******************************************************
 * > File Name: a.cpp
 * > Author: samcompu
 * > Mail: admin@samcompu.com
 * > Created Time: 2018/7/21 12:00:58
 ******************************************************
}}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ull unsigned long long int
/*}}}*/

/*Constant {{{*/
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
int ans[10];
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
  int a, b, c;
  cini(a), cini(b), cini(c);
  ans[1] = abs(a - b) + abs(b - c);
  ans[2] = abs(a - c) + abs(c - b);
  ans[3] = abs(b - a) + abs(a - c);
  ans[4] = abs(b - c) + abs(c - a);
  ans[5] = abs(c - a) + abs(a - b);
  ans[6] = abs(c - b) + abs(b - a);
  int minCost = 0x7fffffff;
  FOR(i, 1, 6) minCost = min(minCost, ans[i]);
  coui(minCost), LIN;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/


Measured memory_bytes: 256
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	int  n;
	double a;
	cin >> n;
	double bunbo = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		bunbo += 1 / a;
	}
	double ans = 1 / bunbo;
	cout << round(ans*1000000)/1000000 << endl;
}

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

int main()
{
  string a,b; cin >> a >> b;
  int num = atoi((a+b).c_str());
  rep(i,500) {
    if(i*i == num){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iostream>
using namespace std;
typedef long long LL;
const LL INF = 1LL << 60;
const int MaxN = 1e5;

int n, q, k;
int all;
int pre[2 * MaxN + 5], last[2 * MaxN + 5], other[2 * MaxN + 5];
LL cost[2 * MaxN + 5];
LL dis[MaxN + 5];
bool vis[MaxN + 5];

void build(int x, int y, LL w)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

void spfa(int s)
{
	for(int i = 1; i <= n; i++)
		dis[i] = INF;
	dis[s] = 0;
	vis[s] = 1;
	queue <int> q;
	q.push(s);
	int now, ed, dr;
	while(!q.empty()) {
		now = q.front();
		q.pop();
		ed = last[now];
		while(ed != -1) {
			dr = other[ed];
			if(dis[now] + cost[ed] < dis[dr]) {
				dis[dr] = dis[now] + cost[ed];
				if(!vis[dr]) {
					q.push(dr);
				}
			}
			ed = pre[ed];
		}
		vis[now] = 0;
	}
}

int main()
{
	cin >> n;
	all = -1; memset(last, -1, sizeof(last));
	for(int i = 1; i < n; i++) {
		int u, v;
		LL w;
		cin >> u >> v >> w;
		build(u, v, w);
		build(v, u, w);
	}
	scanf("%d %d", &q, &k);
	spfa(k);
	for(int i = 1; i <= q; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		cout << dis[u] + dis[v] << endl;
	}
}


Measured memory_bytes: 6656
#include <iostream>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

int main(){
    int N, M, S, dp[60][3010];
    while(std::cin >> N >> M >> S, N){
        REP(i, 60){
            REP(j, 3010){
                dp[i][j] = 0;
            }
        }
        dp[0][0] = 1;
    
        for(int i=1;i<=M;i++){// 1つずつ入れてるdp
            for(int j=N*N;j>=1;j--){
                for(int s=i;s<=S;s++){
                    dp[j][s] = (dp[j][s] + dp[j-1][s-i]) % 100000;
                }
            }
        }

        std::cout << dp[N*N][S] << std::endl;
    }
}

Measured memory_bytes: 1864
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const str = next()
    if(str == "ABC") console.log("ARC")
    if(str == "ARC") console.log("ABC")

}
Main()


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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }

	friend modnum pow() {}
};

using num = modnum<998244353>;

num pow(num a, ll b){
	assert(b >= 0);
	if(b & 1) return a * pow(a, b-1);
	if(!b) return 1;
	return pow(a * a, b / 2);
}

vector<num> fact;
vector<num> ifact;

void init(){
	fact = {1};
	for(int i = 1; i < 11000000; i++) fact.push_back(i * fact[i-1]);
	ifact.resize(fact.size());
	ifact.back() = 1 / fact.back();
	for(int i = (int)ifact.size() - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	init();
	num ans = 1;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) ans *= 3;
	vector<num> p2(n+1, 0);
	p2[0] = 1;
	for(int i = 1; i <= n; i++){
		p2[i] = 2 * p2[i-1];
	}
	for(int i = 0; i < n/2; i++){
		ans -= 2 * p2[i] * ncr(n, i);
	}
	cout << (int)ans << '\n';
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A.at(i);
    }

    int ans = 0;
    while (true) {
        bool hasOdd = false;
        rep(i, N) {
            if (A.at(i) % 2 == 1) {
                hasOdd = true;
            }
        }

        if (hasOdd) break;
        
        rep(i, N) {
            A.at(i) /= 2;
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256