akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int n, q;
vector<vector<int>> g;
vector<ll> v;
void dfs(int now, int pre) {
    for (int nxt : g[now]) {
        if (nxt == pre) continue;
        v[nxt] += v[now];
        dfs(nxt, now);
    }
}
int main() {
    cin >> n >> q;
    g.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    v.resize(n);
    rep(i, q) {
        int p;
        ll x;
        cin >> p >> x;
        p--;
        v[p] += x;
    }
    dfs(0, -1);
    rep(i, n) cout << v[i] << " \n"[i == n - 1];
}

Measured memory_bytes: 24320
h, w = [int(x) for x in input().split()]
matrix = [list(input()) for _ in range(h)]
surrounding_distances = (-1, 0, 1)


def count_bombs(i, j):
    for da in surrounding_distances:
        for db in surrounding_distances:
            if da == db == 0:
                # Not surrounidings.
                continue
            si = i + da
            sj = j + db
            if si < 0 or si >= h or sj < 0 or sj >= w:
                continue
            if matrix[si][sj] == '#':
                yield 1


for i in range(h):
    for j in range(w):
        if matrix[i][j] == '.':
            matrix[i][j] = str(sum(count_bombs(i, j)))

[print(''.join(row)) for row in matrix]


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

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

using boost::multiprecision::cpp_int;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  for (auto it : a) {
    if (it == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  cpp_int ans = 1;
  for (auto it : a) {
    ans *= it;
    if (ans > (ll)1e18) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4000
import java.io.*;
public class Main {
	public static void main(String[] args){
		try{
			int j,k;
			BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
			int i=Integer.parseInt(b.readLine());
			StringBuffer[] str=new StringBuffer[i];
			String[] s;
			for(j=0;j<i;j++){
				str[j]=new StringBuffer();
				s=b.readLine().split(" ");
				for(k=0;k<s.length;k++){
					s[k]=s[k].replaceAll("Hoshino", "Hoshina");
					str[j].append(s[k]+" ");
				}
				str[j].deleteCharAt(str[j].length()-1);
			}
			for(j=0;j<i;j++)System.out.println(str[j].toString());
		}catch(IOException e){}
	}
}

Measured memory_bytes: 9796
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    int ans=100100100;
    for(int i=0;i<n;i++){
        int s1=0,s2=0;
        for(int j=0;j<=i;j++){
            s1+=w[j];
        }
        for(int k=i+1;k<n;k++){
            s2+=w[k];
        }
        ans=min(ans,abs(s1-s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input().split('T')
x, y = map(int, input().split())
s = [len(_) for _ in s]
dx = s[::2]
dy = s[1::2]

x = abs(x-dx[0])
y = abs(y)
dx = dx[1:]
px = 0
py = 0
for d in reversed(sorted(dx)) :
    if px > x :
        px -= d
    else :
        px += d

for d in reversed(sorted(dy)) :
    if py > y :
        py -= d
    else :
        py += d

if px == x and py == y :
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3188
#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(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi;
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; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int A, B, K;
string s;

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

    int k = 0;
    for (int n = min(A, B); n >= 1; --n) {
        if (A % n == 0 && B % n == 0) {
            k++;
        }
        if (k == K) {
            write(n);
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, K;
    cin >> n >> K;

    vector<int> p(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    ll r = -(1LL << 60);

    for (int x = 0; x < n; x++) {
        vector<int> b(n, -1);
        vector<ll> a(n);
        ll s = 0;
        int k = K, l = 0;

        for (int i = x, j = 0;; j++) {
            if (k == 0) break;
            s += c[i];
            k--;

            if (b[i] >= 0 && l == 0) {
                if (s <= a[i]) {
                    break;
                }
                int f = j - b[i];
                int t = k / f;
                s += (s - a[i]) * t;
                k -= f * t;
                l = 1;
            }

            b[i] = j;
            r = max(r, a[i] = s);

            i = p[i];
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, X; std::cin >> n >> X;
  std::vector< int > a(n); std::cin >> a;
  int r = 0, min = 2*n, sum = 0;
  rep(l, 0, n) {
    while (r<n && sum<X) {
      sum+=a[r];
      r++;
    }
    if (r==n && sum<X) break;
    cmn(min, r-l);
    sum-=a[l];
  }
  if(min==2*n)min=0;
  std::cout << min << std::endl;
  return 0;
}



Measured memory_bytes: 3428
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int k[4];
    rep(i, 4) k[i] = S[i] - '0';
    if (k[0] + k[1] + k[2] + k[3] == 7) cout << k[0] << "+" << k[1] << "+" << k[2] << "+" << k[3] << "=7" << endl;
    else if (k[0] + k[1] + k[2] - k[3] == 7) cout << k[0] << "+" << k[1] << "+" << k[2] << "-" << k[3] << "=7" << endl;
    else if (k[0] + k[1] - k[2] + k[3] == 7) cout << k[0] << "+" << k[1] << "-" << k[2] << "+" << k[3] << "=7" << endl;
    else if (k[0] + k[1] - k[2] - k[3] == 7) cout << k[0] << "+" << k[1] << "-" << k[2] << "-" << k[3] << "=7" << endl;
    else if (k[0] - k[1] + k[2] + k[3] == 7) cout << k[0] << "-" << k[1] << "+" << k[2] << "+" << k[3] << "=7" << endl;
    else if (k[0] - k[1] + k[2] - k[3] == 7) cout << k[0] << "-" << k[1] << "+" << k[2] << "-" << k[3] << "=7" << endl;
    else if (k[0] - k[1] - k[2] + k[3] == 7) cout << k[0] << "-" << k[1] << "-" << k[2] << "+" << k[3] << "=7" << endl;
    else if (k[0] - k[1] - k[2] - k[3] == 7) cout << k[0] << "-" << k[1] << "-" << k[2] << "-" << k[3] << "=7" << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int n,Min = INF,Max = -2000000000;
    cin >> n;
    vector<int> v(n);

    rep(i, n){
        cin >> v.at(i);
    }

    Min = v.at(0);

    rep1(i, n - 1){
        Max = max(Max, v.at(i) - Min);
        Min = min(Min, v.at(i));
    }

    cout << Max << endl;

    return 0;
}


Measured memory_bytes: 3528
/*input
abcdefghijklmnopqrstuvwxyz
atcoderregularcontest
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 200005

string s;
int last[N][26];
int dp[N][26];
pair<int, int> par[N][26];

int cal(int pos, int dig) {
	if (pos > s.size()) return 0;
	int &ret = dp[pos][dig];
	if (ret != -1) return ret;
	ret = 1e18;
	if (pos == s.size()) {
		par[pos][dig] = mp(pos + 1, 0);
		ret = 1;
	}
	else {
		int nxt = last[pos][dig];
		for (int i = 0; i <= 25; i++) {
			if (cal(nxt + 1, i) + 1 < ret) {
				par[pos][dig] = mp(nxt + 1, i);
				ret = cal(nxt + 1, i) + 1;
			}
		}
	}
	return ret;
}

void trace(int pos, int dig) {
	if (pos >= s.size()) return;
	cout << char(dig + 'a');
	trace(par[pos][dig].fi, par[pos][dig].se);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	memset(last, 127, sizeof(last)); memset(dp, -1, sizeof(dp));
	for (int i = s.size() - 1; i >= 0; i--) {
		for (int j = 0; j <= 25; j++) last[i][j] = last[i + 1][j];
		last[i][s[i] - 'a'] = i;
	}
	pair<int, int> mn = mp(1e9, 0);
	for (int i = 0; i <= 25; i++) {
		if (cal(0, i) < mn.fi) mn = mp(cal(0, i), i);
	}
	trace(0, mn.se);
}

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

typedef long long ll;
const int mod=1000000007;

int n,k,ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=k;i<=n+1;i++){
        ans=(ans+(ll)((n+n-i+1)-(i-1))*i/2+1)%mod;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
n = int(input())
lis = [i for i in range(n + 1)]
cnt = [0 for i in range(n + 1)]
for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        while lis[j] % i == 0:
            cnt[i] += 1
            lis[j] //= i
ans = 1
for i in cnt:
    ans = ans * (i + 1) % 1000000007
print(ans)


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

using namespace std;

int main() {
	int N, A, B; cin >> N >> A >> B;
	string S; cin >> S;

	int foreign = 1;
	int pass = 0;
	for(int i = 0; i < N; i++) {
		switch(S[i]) {
			case 'a':
				if(A+B > pass) {
					cout << "Yes" << endl;
					pass++;
				}
				else {
					cout << "No" << endl;
				}
				break;
			case 'b':
				if(A+B > pass && B >= foreign) {
					cout << "Yes" << endl;
					pass++; foreign++;
				}
				else {
					cout << "No" << endl;
				}
				break;
			case 'c':
				cout << "No" << endl;
				break;
		}
	}

	return 0;
}


Measured memory_bytes: 896
n=input()
ans=0
def dfs(i,flag):
  global ans
  if i!=len(n)-1:
    dfs(i+1,flag)
    dfs(i+1,flag|2**i)
  else:
    num=[]
    start=0
    for i in range(len(n)):
      if flag&2**i>0:
        num.append(int(n[start:i+1]))
        start=i+1
    if start!=n:
      num.append(int(n[start:]))
    ans+=sum(num)
dfs(0,0)
print(ans)

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

using lli = long long int;

using namespace std;

//struct S {
//    int l = 0;
//};

int main() {
    std::string s, t;
    cin >> s >> t;

    std::vector<std::vector<lli>> dp(s.size() + 1, std::vector<lli>(t.size() + 1, 0));

    for (lli dps = 0; dps < s.size(); ++dps) {
        for (lli dpt = 0; dpt < t.size(); ++dpt) {
            if (s[dps] == t[dpt]) {
                dp[dps + 1][dpt + 1] = dp[dps][dpt] + 1;
            }

            if (dp[dps + 1][dpt + 1] < dp[dps + 1][dpt]) {
                dp[dps + 1][dpt + 1] = dp[dps + 1][dpt];
            }

            if (dp[dps + 1][dpt + 1] < dp[dps][dpt + 1]) {
                dp[dps + 1][dpt + 1] = dp[dps][dpt + 1];
            }
        }
    }

    std::string ans;

    auto si = s.size();
    auto ti = t.size();
    while (si > 0 && ti > 0) {
        if (dp[si][ti] == dp[si - 1][ti]) {
            --si;
        } else if (dp[si][ti] == dp[si][ti - 1]) {
            --ti;
        } else {
            ans.insert(0, std::string{s[si - 1]});
            --si;
            --ti;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include<iostream>
#include<string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <map>
using namespace std;
int a[105];
bool cmp(int a,int b){
    return a<b;
}
int main() {
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            for(int k=j+1;k<=n;k++)
                if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
//noob
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
typedef vector<int> vi;
typedef pair<int,int> PI;
const int N = (int)1e6 + 7;

void solve()
{
	int d,t,s;cin>>d>>t>>s;
	float a=(float)d/s;
	if(a<=(float)t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	
solve();
	return 0;
}

Measured memory_bytes: 3624
//
//  B - Ice Rink Game.cpp
//  atcoder grand contest 020
//
//  Created by Huang,Zhiqiang on 2018/2/21.
//  Copyright © 2018年 Huang,Zhiqiang. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

ll aks[100005] = { 0 };
int k;

int main() {
    cin >> k;
    for (int i = 1; i <= k; i++) cin >> aks[i];
    ll ans_max = 2, ans_min = 2;
    for (int i = k; i >= 1; i--) {
        ans_max = ans_max / aks[i] * aks[i] + aks[i] - 1;
        ans_min = (ans_min + aks[i] - 1) / aks[i] * aks[i];
        if (ans_min > ans_max) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans_min << " " << ans_max << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

bool check_zorome(int a){
  int ketasu = log10(a);
  int k = a/pow(10,ketasu);
  bool f = false;
  for(int i = ketasu; i >= 0; i--){
    int t = a / (int)pow(10,i);
    if(t != k) f = true;
    a = a % (int)pow(10,i);
  }
  if(f) return false;
  else return true;
}

int main(){
  int N;
  cin >> N;
  int ans;
  for(int i = N; i < 1000; i++){
    if(check_zorome(i)){
      ans = i;
      break;
    }
  }
cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 文字列の入力
    string s;
    cin >> s;
  
    // 出力
  	if(s == "Sunny"){
      cout << "Cloudy" << endl;
    }
  	if(s == "Cloudy"){
      cout << "Rainy" << endl;
    }
  	if(s == "Rainy"){
      cout << "Sunny" << endl;
    }

    return 0;
}

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

int main() {
  
  int N, K, Q; cin >> N >> K >> Q;
  
  vector<int> vec(N, K - Q);
  
  for (int i = 0; i < Q; i++) {
    
    int A; cin >> A; vec[A - 1]++;
    
  }
  
  for (int x : vec) {
    
    if (0 < x) cout << "Yes" << endl;
    
    else cout << "No" << endl;
    
  }
  
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{  
    int A, B, i, flag=0;

    scanf("%d %d",&A, &B);

    for(i=1; i<=1250; i++) {
        if((int)(i*0.08) == A && (int)(i*0.1) == B) {
            flag = 1;
            break;
        }
    }

    if(flag == 1) {
        printf("%d\n", i);
    } else {
        printf("-1\n");
    }
    

    return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int price = 700;

  for(int i=0;i<3;++i)
  {
    if (s[i] == *"o") price += 100;
  }
  cout << price << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int main(){
	int x,y,b,p,n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y>>b>>p;
		int ans=x*b+y*p;
		ans=min(ans,(max(5,b)*x+max(2,p)*y)*4/5);
		cout<<ans<<endl;
	}
}

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

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

    int K, S;
    cin >> K >> S;

    int ans = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            int f = S - i - j;
            if(0 <= f and f <= K){
                ans++;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//Problem B
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,m,a[N],aa[N],b[N],f[N],g[N],s;
map<int,int> mp;
vector<int>e[N];
int dfs(int v){
	g[v]=1;int res=b[v];
	for(int i=0;i<(int)e[v].size();i++){
		int u=e[v][i];
		if(!g[u]){
			int get=min(res,dfs(u));
			s+=get,res-=get;
		}
	}
	if(f[v])s+=res>>1;
	return res;
}
int main(){
	scanf("%d",&m);for(int i=1;i<=m;i++)scanf("%d",&aa[i]);
	sort(aa+1,aa+m+1);
	for(int i=1,j=1;i<=m;i=j){
		while(j<=m&&aa[i]==aa[j])++j;
		a[++n]=aa[i],b[n]=j-i;
	}
	//for(int i=1;i<=n;i++)printf("v %d %d\n",a[i],b[i]);
	for(int i=1;i<=n;i++)mp[a[i]]=i;
	for(int i=1;i<=n;i++)
		for(int j=1;j;j<<=1)if(a[i]<=j){
			int v=mp[j-a[i]];
			if(v){
				if(v==i)f[i]=1;//printf("f %d\n",i);
				else e[i].push_back(v);//printf("e %d %d\n",i,v);
			}
		}
	for(int i=1;i<=n;i++)if(!g[i])dfs(i);
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 46720
var main = standardInput => {
  var ary = standardInput.split(" ");
  ary = ary.map(v => {
    return parseInt(v, 10);
  });

  var inputLines = standardInput.split("\n").map(function(v) {
    return v;
  });
  var line0 = inputLines[0].split(" ");
  var road = inputLines[1];
  road = "X" + road;

  var N = parseInt(line0[0], 10);
  var A = parseInt(line0[1], 10);
  var B = parseInt(line0[2], 10);
  var C = parseInt(line0[3], 10);
  var D = parseInt(line0[4], 10);

  function checkPlace(i) {
    var target = i;
    if (target > N) return false;
    var bool = road[target] === "." && target !== A && target !== B;
    return bool;
  }

  function check1(AorB) {
    var target = AorB + 1;
    if (target > N) return false;
    var bool = road[target] === "." && target !== A && target !== B;
    return bool;
  }

  function check2(AorB) {
    var target = AorB + 2;
    if (target > N) return false;
    var bool = road[target] === "." && target !== A && target !== B;
    return bool;
  }

  if (C < D) {
    while (B !== D) {
      if (check2(B)) {
        B += 2;
      } else if (check1(B)) {
        B += 1;
      } else {
        console.log("No");
        process.exit(0);
      }
    }

    while (A !== C) {
      if (check2(A)) {
        A += 2;
      } else if (check1(A)) {
        A += 1;
      } else {
        console.log("No");
        process.exit(0);
      }
    }

    console.log("Yes");

  } else if (D < C) {
    while (B !== D) {
      if (checkPlace(B - 1) && checkPlace(B + 1)) {
        break;
      } else if (check1(B)) {
        B += 1;
      } else if (check2(B)) {
        B += 2;
      } else {
        console.log("No");
        process.exit(0);
      }
    }

    while (A !== C) {
      if (check2(A)) {
        A += 2;
      } else if (check1(A)) {
        A += 1;
      } else {
        console.log("No");
        process.exit(0);
      }
    }

    while (B !== D) {
      if (check2(B)) {
        B += 2;
      } else if (check1(B)) {
        B += 1;
      } else {
        console.log("No");
        process.exit(0);
      }
    }
    console.log("Yes");
  }
};

main(require("fs").readFileSync("/dev/stdin", "UTF-8"));


Measured memory_bytes: 21064
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    string s;
    cin>>s;
    int a=0,m=0;
    for(char c:s){
        if(c=='T') a++;
        else a--;
        m=max(a,m);
    }
    cout<<m*2<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int A[300], N, K, d, a;

int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);

  cin>>N>>K;
  rep(i,K) {
    cin>>d;
    rep(j,d) {
      cin>>a;
      A[a]++;
    }
  }
  int ans=0;
  rep(i,N) if(A[i+1] == 0) ans++;
  cout<<ans;

  return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()

{
	int p,j,i;
	cin>>p;
	string a=to_string(p);
	int s=a.size();
	for(int j=0; j<s; j++)
	{
		if(a[j]=='7')
		{
			cout<<"Yes";
			break;
		}
		i=j;
	}
		if(i+1 ==s)
		cout<<"No";
		
}


Measured memory_bytes: 3672
fun main() {
    val mod = 1e9.toInt() + 7
    val (h, w, k) = readLine()!!.split(' ').map { it.toInt() }
    val dp = Array(h + 1) { IntArray(w) }
    dp[0][0] = 1

    val bitsSequence = sequence {
        for (bits in 0 until (1 shl w - 1)) {
            var invalid = false
            for (i in 0 until w - 2) {
                val l = (bits shr i) and 1
                val r = (bits shr i + 1) and 1
                if (l and r == 1) {
                    invalid = true
                }
            }
            if (invalid) continue
            yield(bits)
        }
    }

    for (i in 0 until h) {
        for (j in 0 until w) {
            for (bits in bitsSequence) {
                var nj = j
                if (bits shr j and 1 == 1) nj = j + 1
                else if (j > 0 && bits shr j - 1 and 1 == 1) nj = j - 1
                dp[i + 1][nj] += dp[i][j]
                dp[i + 1][nj] %= mod
            }
        }
    }

    println(dp[h][k - 1])
}


Measured memory_bytes: 38340
N = int(input())
prob = list(map(int, input().split()))
ans = []
for i in reversed(range(N)):
  boo = False
  for j in reversed(range(i + 1)):
    if prob[j] == j + 1:
      boo = True
      ans.append(j + 1)
      del prob[j]
      break
  if not boo:
    break
if len(ans) == N:
  for x in reversed(ans):
    print(x)
else:
  print(-1)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=2222222;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}

int ei(int h,int w){
    return nCk(h+w,w);
}

pint a,b;

int solve(pint s,pint t){
    t.fi++;
    int ret=0;

    int sum=0;
    for(int x=a.se;x<=b.se;x++){
        add(sum,ei(a.fi-s.fi,x-s.se)*ei(t.fi-a.fi-1,t.se-x)%mod);
    }

    add(ret,sum);

    for(int y=a.fi+1;y<b.fi;y++){
        int tmp=ei(y-s.fi,b.se-s.se)-ei(y-s.fi,a.se-1-s.se)+mod;
        tmp%=mod;
        tmp=tmp*ei(t.fi-y,t.se-b.se-1)%mod;

        add(sum,mod-tmp);

        tmp=ei(t.fi-y,t.se-a.se)-ei(t.fi-y,t.se-b.se-1)+mod;
        tmp%=mod;
        tmp=tmp*ei(y-s.fi,a.se-1-s.se)%mod;
        add(sum,tmp);

        add(ret,sum);
    }

    return ret;
}

signed main(){
    int x[6],y[6];
    rep(i,6)cin>>x[i];
    rep(i,6)cin>>y[i];
    x[0]--;y[0]--;x[5]++;y[5]++;

    a={y[2],x[2]};
    b={y[3]+1,x[3]};

    int ans=0;
    rep(i,2)rep(j,2)rep(k,2)rep(l,2){
        int w;
        if((i+j+k+l)%2==0){
            w=1;
        }
        else{
            w=-1;
        }

        add(ans,(w*solve({y[i],x[j]},{y[4+k],x[4+l]})+mod)%mod);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 34944
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef pair<xy_t, int> pci;

int main(){
    double r, c;
    int n;
    scanf("%lf%lf%d", &r, &c, &n);
    vector<pci> p;
    rep(i, n){
        double x1, y1, x2, y2;
        scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
        if((x1==0||y1==0||x1==r||y1==c) && (x2==0||y2==0||x2==r||y2==c)){
            p.push_back(pci(xy_t(x1, y1), i));
            p.push_back(pci(xy_t(x2, y2), i));
        }
    }
    xy_t z = xy_t(r/2, c/2);
    sort(p.begin(), p.end(), [&z](const pci &a, const pci &b){return arg(a.fi-z) < arg(b.fi-z);});
    stack<int> s;
    for(pci t: p){
        if(s.empty() || s.top() != t.se) s.push(t.se);
        else s.pop();
    }
    printf((s.empty() ? "YES\n": "NO\n"));
}

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

int seq[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main() {
	int k;
	cin >> k;

	cout << seq[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N,M;

    private void solve() {
        N = nextInt();
        M = nextInt();

        int div = 1;
        for(int i = 0;i < M;i++) {
            div <<= 1;
        }

        out.println((div * M * 1900 + div * (N - M) * 100));


    }

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

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21076
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N, W = imn()
weight = []
value = []
for _ in range(N):
    w,v = imn()
    weight.append(w)
    value.append(v)

max_v = 100*1000

dp = [[INF for _ in range(max_v+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(max_v+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j - value[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-value[i]]+weight[i])
ans = 0
for i in range(max_v+1):
    if dp[N][i] <= W: ans = i
print(ans)



Measured memory_bytes: 335744
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 4.0*atan(1.0)
#define epsilon 0.000000001
#define INF 1000000000000000000
#define MOD 1000000007

int K, visited [100010];
deque<int> dq;

int main(){
    //freopen("fortmoo.in", "r", stdin); freopen("fortmoo.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18);
    cin >> K; fill(visited, visited+K, 1000000);
    visited[1] = 1; dq.push_back(1);
    while(dq.size() > 0){
        int now = dq.front(); dq.pop_front();
        if(visited[(now*10)%K] > visited[now]){
            visited[(now*10)%K] = visited[now];
            dq.push_front((now*10)%K);
        }
        if(visited[(now+1)%K] > visited[now]+1){
            visited[(now+1)%K] = visited[now]+1;
            dq.push_back((now+1)%K);
        }
    }
    cout << visited[0] << '\n';
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll  long long
#define int long long
#define ld  long double
#define pb push_back
#define mod 1000000007
#define M_PI 3.141592653589
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int x=0;x<n;x++)cin>>a[x];
    sort(a,a+n);
    ll s=0;
    for(int x=0;x<k;x++)s+=a[x];
    cout<<s;

}


Measured memory_bytes: 3636
#include<iostream>
#include <limits>
using namespace std;

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  int max_x{numeric_limits<int>::min()}, min_y{numeric_limits<int>::max()};
  for (int i{}; i < N; ++i) {
    cin >> x[i];
    if (max_x < x[i]) {
      max_x = x[i];
    }
  }
  for (int i{}; i < M; ++i) {
    cin >> y[i];
    if (min_y > y[i]) {
      min_y = y[i];
    }
  }

  bool ans = max_x < min_y && X < max_x && min_y <= Y;

  cout << (ans ? "No War" : "War") << endl;
  return 0;
}


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

int main(void){
  int n;
  
  scanf("%d",&n);
  
  n=n%10;
  
  if(n==3){
    printf("bon");
  }else if(n==0||n==1||n==6||n==8){
    printf("pon");
  }else{
    printf("hon");
  }
  return 0;
}
    
  
  

Measured memory_bytes: 1728
p = 10**9+7
N,M = map(int,input().split())
A = {i:0 for i in range(N+1)}
for _ in range(M):
    A[int(input())] = 1
dp = [0 for _ in range(N+1)]
dp[N] = 1
for i in range(N-1,-1,-1):
    if A[i]==1:continue
    if A[i+1]==0:
        dp[i] = dp[i+1]
    if i+2<=N and A[i+2]==0:
        dp[i] = (dp[i]+dp[i+2])%p
print(dp[0])

Measured memory_bytes: 87692
// B - ATCoder
#include <bits/stdc++.h>
using namespace std;

int main(){
	string T="ACGT", S; cin>>S;
	int maxi, pre, now;
	maxi = pre = T.find(S[0])<T.size()? 1: 0;
	for(int i=1; i<S.size(); ++i){
		now = T.find(S[i])<T.size()? pre+1: 0;
		maxi = max(maxi, now);
		pre = now;
	}
	cout<< maxi <<endl;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {


    int N, A, B;

    cin >> N >> A >> B;
    int ans = min(B, N*A);
    cout << ans<<endl;
}

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

typedef long long LL;
const int MAXN = 100000 + 10;
int n, a[MAXN];
bool vis[MAXN];
LL ans;

int main()
{
	cin >> n;	
	for(int i = 1; i <= n; i++) 
	{
		cin >> a[i];
		if(a[i]) vis[i] = true;
		ans += a[i] / 2; 
		a[i] %= 2;
	}
	
	for(int i = 2; i <= n; i++)
	{
		if(a[i] && a[i-1]) 
		{
			ans++;
			a[i-1] = a[i] = 0;
		}
		else if(a[i] == 0 && a[i-1])
		{
			if(vis[i]) a[i-1]--, a[i]++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

bool dp[100000+10];
int main(){
  ll N,K;
  cin >> N >> K;
  VLL a(N);
  rep(i,N) cin >> a[i];

  FOR(i,1,K+1){
	   rep(j,N)
      if(i -a[j] >=0 && dp[i-a[j]] == 0) dp[i]=1;
  }
  cout << (dp[K]?"First":"Second") << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

constexpr int mod = 1000000007;

// modをとった積を返す
inline
int modMultiple(int a, int b){return (static_cast<long long>(a) * b) % mod;}

int main()
{
    scanInt(N);
    string s1;
    cin >> s1;
    vector<char> T; // true : v, false : h
    loop(i, N){
        if (i < N - 1 && s1[i] == s1[i + 1]){
            T.emplace_back(false);
            ++i;
        }else{
            T.emplace_back(true);
        }
    }
    int result;
    if (T[0]){
        result = 3;
    }else{
        result = 6;
    }
    for (int i = 1; i < T.size(); ++i){
        if (T[i - 1]){
            result = modMultiple(result, 2);
        }else if (!T[i]){
            result = modMultiple(result, 3);
        }
    }
    printf("%d\n", result);
}


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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

vi a;
int n;

int main()
{
    cin >> n;
    REP(i, n)
    {
        int c;
        cin >> c;
        a.push_back(c);
    }

    int ans = 0;
    sort(ALL(a));
    reverse(ALL(a));
    for (auto k : a)
    {
        ans += k - 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    ll n = s.size();
    vector<ll> a(n+1, 0);
    RANGE(i, 0, n-1) {
        if (s[i] == '<') {
            chmax(a[i+1], a[i]+1);
        }
    }
    DSRNG(i, n-1, 0) {
        if (s[i] == '>') {
            chmax(a[i], a[i+1]+1);
        }
    }
    DUMPALL(a);
    cout << accumulate(ALL_OF(a), 0LL) << endl;
    
}

Measured memory_bytes: 4764
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;

int main(void) {
	int X,cnt = 0,i,j,k;
	int ABC[3], tmp;

	rep(i, 3) {
		scanf("%d", &tmp);
		ABC[i] = tmp + 1;
	}
	scanf("%d", &X);

	rep(i, ABC[0]) {
		rep(j, ABC[1]) {
			rep(k, ABC[2]) {
				tmp = 500 * i + 100 * j + 50 * k;
				if (tmp == X) {
					cnt++;
				}
			}
		}
	}
	printf("%d\n", cnt);

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int n,m,q,a[52],b[52],c[52],d[52];
vector<int> v;
int tot=0;
int ans=0;
void solve(int cur,int p)
{
	if(cur==n)
	{
		int res=0;
		for(int i=1;i<=q;i++)
		{
			if(v[b[i]-1]-v[a[i]-1]==c[i])
				res+=d[i];
		}
		ans=max(ans,res);
		return;
	}
	for(int j=p;j<=m;j++)
	{
		v.pb(j);
		solve(cur+1,j);
		v.pop_back();
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	solve(0,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660