akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
v=list(map(int,input().split()))
ma=0
for i in range(k//2+1):
     pick=min(k-i,n)
     for j in range(pick+1):
          if j==0:
               l=v[:pick]
               al=l
          elif j==pick:
               r=v[-pick:]
               al=r
          else:
               l=v[:pick-j]
               r=v[-j:]
               al=l+r
          for rem in range(i):
               if len(al)>0:
                    mi=min(al)
                    if mi<0:
                         al.remove(mi)
                    else:
                         break
               else:
                    break
          if len(al)>0:
               ma=max(ma,sum(al))
print(ma)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n, m;
  cin >> n >> m;
  vector<pair<bool, ll>> vec(n+1);
  rep(i,n+1) vec.push_back(make_pair(false, 0));
  rep(i, m) {
    int x;
    string y;
    cin >> x >> y;
    if (y == "WA" && !vec[x].first) {
      vec[x].second++;
    }
    if (y == "AC" && !vec[x].first) {
      vec[x].first = true;
    }
  }
  ll ac = 0;
  ll wa = 0;
  rep(i, n+1) {
    if (vec[i].first) {
      ac++;
      wa += vec[i].second;
    }
  }
  cout << ac << " " << wa << endl;
  return 0;
}

Measured memory_bytes: 6404
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	ll h;
	cin >> h;
	ll sum = 0;
	ll tm = floor(log2(h));
	ll base = 1LL;
	for (int i = 0; i <= tm; i++)
	{
		sum += base;
		base *= 2LL;
	}

	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 640
import fractions
n = int(input())
a = list(map(int, input().split()))
lcm = a[0]
ans = 0
for i in range(1, n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
for i in range(0, n):
    ans += lcm//a[i]
print(ans%(10**9+7))

Measured memory_bytes: 6112
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    
    
	public static void main (String[] args) throws java.lang.Exception
	{
			Scanner s = new Scanner(System.in);
			int n = s.nextInt();
			if(n==1) {
				System.out.printf("%.9f", 1.0);
			}
			else if(n%2==0) {
				System.out.printf("%.9f", 0.5);
			}
			else {
				System.out.printf("%.9f", (n/2+1.0)/n);
			}
	}
}


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

const int INF = INT_MAX/2;

int main(){
    int N; cin >> N;
    vector<int> dp(N+1, INF);
    vector<int> height;
    for(int i=0; i<N; i++){
        int h; cin >> h;
        height.push_back(h);
    }

    dp[0] = 0;
    dp[1] = dp[0] + abs(height[1] - height[0]);
    for(int i=0; i<N-2; i++){
        dp[i+2] = min(dp[i+1] + abs(height[i+2] - height[i+1]), dp[i] + abs(height[i+2] - height[i]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1404
N,M,Q = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]
PQ = [list(map(int,input().split())) for _ in range(Q)]

Sumtable = [[0 for _ in range(N+1)] for _ in range(N+1)]
for l,r in LR:
  Sumtable[l][r] += 1
#print(Sumtable)
for i in range(1,N+1):
  for j in range(1,N+1):
    Sumtable[i][j] += Sumtable[i-1][j] + Sumtable[i][j-1] - Sumtable[i-1][j-1]
#print(Sumtable)

for p,q in PQ:
  print(Sumtable[q][q] - Sumtable[p-1][q] - Sumtable[q][p-1] + Sumtable[p-1][p-1])


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

int main()
{
	char *formats[4] = {
		"YYMM",
		"MMYY",
		"AMBIGUOUS",
		"NA"
	};
	string s;
	cin >> s;
	int n1, n2;
	n1 = 10 * (s[0] - '0') + s[1] - '0';
	n2 = 10 * (s[2] - '0') + s[3] - '0';
	if (n1 > 0 && n1 <= 12 && n2 > 0 && n2 <= 12)
		cout << formats[2] << endl;
	else if (n1 > 0 && n1 <= 12)
		cout << formats[1] << endl;
	else if (n2 > 0 && n2 <= 12)
		cout << formats[0] << endl;
	else
		cout << formats[3] << endl;
	//system("pause");
	return 0;
}

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

int main(){

  int A, B, C, D, big, small, ans;
  cin >> A >> B >> C >> D;

  big = max(C, A);
  small = min(B, D);

  ans = small - big > 0 ? small - big : 0 ;
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s;

	cin >> s;

	ll ans = 0;

	REP(i, s.size()) {
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	cout << ans << endl;
}

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

using namespace std;

struct Restaurant
{
	int id;
	string name;
	int point;
};

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

	vector<Restaurant> restaurants(N);
	for (int i = 0; i < N; ++i)
	{
		restaurants[i].id = i + 1;
		cin >> restaurants[i].name;
		cin >> restaurants[i].point;
	}

	sort(restaurants.begin(), restaurants.end(), [](const Restaurant& lhs, const Restaurant& rhs) {
		if (lhs.name == rhs.name)
		{
			return lhs.point > rhs.point;
		}
		return lhs.name < rhs.name;
	});

	for (const auto& r : restaurants)
	{
		cout << r.id << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
 
#define rep(i,n) for(int i = 0;i < n;i++)
 
using namespace std;
using ll = long long;
 
const int INF = 1001001001;
const int MOD = 1000000007;
 
 
 
int main(){
	int n; cin >> n;
	int a = n/100;
	int b = n%100 / 10;
	int c = n%10;
 
	if(a == 7 || b == 7 || c == 7){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

ll solve(ll h, ll w) {
    ll mn = w*h, a[3] = {};
    for (ll i = 1; i < w; ++i) {
        a[0] = i * h;
        a[1] = (w-i)/2 * h;
        a[2] = w*h - a[0] - a[1];
        sort(a, a+3);
        mn = min(mn, a[2]-a[0]);

        a[0] = i * h;
        a[1] = h/2 * (w-i);
        a[2] = h*w - a[0] - a[1];
        sort(a, a+3);
        mn = min(mn, a[2]-a[0]);
    }
    return mn;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    ll h, w;
    cin >> h >> w;
    ll a = solve(h, w);
    ll b = solve(w, h);
    cout << min(a, b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=998244353;
struct Node{
    int x,d;
}e[maxm];
int d[maxm];
int n;
bool cmp(Node a,Node b){
    return a.x<b.x;
}
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>e[i].x>>e[i].d;
    }
    sort(e+1,e+1+n,cmp);
    d[n]=2;
    stack<int>s;
    s.push(n);
    for(int i=n-1;i>=1;i--){
        while(!s.empty()&&e[i].x+e[i].d>e[s.top()].x)s.pop();
        d[i]=d[i+1];
        if(!s.empty())d[i]=(d[i]+d[s.top()])%mod;
        else d[i]=(d[i]+1)%mod;
        s.push(i);
    }
    cout<<d[1]<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> T(N);
  rep(i, N) { cin >> T[i]; }
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int Tpeak;
  int prev = 0;
  vector<bool> Lower(N, true);
  rep(i, N) {
    if (prev < T[i]) Tpeak = i;
    if (prev != T[i]) Lower[i] = false;
    prev = T[i];
  }
  int Apeak;
  prev = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (prev < A[i]) Apeak = i;
    if (prev != A[i]) Lower[i] = false;
    prev = A[i];
  }

  if (T[Tpeak] != A[Apeak] || Apeak < Tpeak) {
    cout << 0 << endl;
    return 0;
  }

  int64_t answer = 1;
  int64_t mod = 1e9 + 7;
  rep(i, N) {
    if (!Lower[i]) continue;
    answer *= (int64_t)min(T[i], A[i]);
    answer %= mod;
  }
  cout << endl;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = false;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1) {}

  //functions
  void init_tree() {
    for (int i = 0; i < d.size(); i++) {
      d[i] = -1;
    }
  }
  
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return -d[find(x)];
  }
};

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

  int n, m;
  cin >> n >> m;
  //int inc = (n * (n-1)) / 2;
  vector<ll> incs(m+1);
  incs[0] = ((ll)n * (n-1)) / 2;
  UnionFind uf(n);
  vector<pii> bridges(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    bridges[i] = pii(a, b);
  }

  for (int i = 0; i < m; i++) {
    pii br = bridges[m-1-i];
    if (!uf.same(br.first, br.second)) {
      incs[i+1] = incs[i] - uf.size(br.first) * uf.size(br.second);
      uf.unite(br.first, br.second);
    }
    else {
      incs[i+1] = incs[i];
    }
  }
  
  for (int i = m; i > 0; i--) {
    cout << incs[i-1] << endl;
  }
}


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

int32_t main()
{
     int n;
     cin >> n;
     if(n==5 || n == 7 || n==3){
          cout << "YES";
     }
     else{
          cout <<"NO";
     }
     return 0;
}


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

int main(){
    ll N;cin>>N;
    map<ll,ll> p;
    for(ll i=2;i<=N;i++){
        ll t=i;
        for(ll j=2;j<=i;j++){
            if(t%j!=0)continue;
            else{
                if(p.find(j)==p.end())p[j]=0LL;
                while(t%j==0){
                    p[j]++;
                    t/=j;
                }
            }
        }
    }
    ll res=1;
    for(auto i:p){
        res=(res*(i.second+1))%MOD;
    }
    cout<<res<<endl;
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,K;
    vector<ll> H;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        ll h;
        cin >> h;
        H.pb(h);
    }
    dsort(H,ll);
    ll cnt = 0;
    for (int i = K; i < N; i++) {
        cnt += H[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 5316
import math

def check_kai(arr):
    len_a = len(arr)
    check_len = int(math.ceil(len_a/2))
    lef = arr[0:check_len]
    arr.reverse()
    rig = arr[0:check_len]
    if lef == rig:
        return True
    else:
        return False


input = list(input())
N = len(input)

if check_kai(input) and check_kai(input[0:(int((N-1)/2))]) and check_kai(input[int((N+1)/2):]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1
#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;

    ll N,A[100010],sum;
    ll ans,ns;
    bool fir=true;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
    }
    REP(K,2){
        sum=0;
        if(K==1){
            fir=false;
        }
        REP(i,N){
            sum+=A[i];
            DEB(sum)
            if(fir){
                if(i%2==0){
                    if(sum<1){
                        ans+=abs(1-sum);
                        sum-=A[i];
                        sum=1;
                    }
                }else{
                    if(sum>-1){
                        ans+=abs(-1-sum);
                        sum-=A[i];
                        sum=-1;
                    }
                }
            }else{
                if(i%2!=0){
                    if(sum<1){
                        ns+=abs(1-sum);
                        sum-=A[i];
                        sum=1;
                    }
                }else{
                    if(sum>-1){
                        ns+=abs(-1-sum);
                        sum-=A[i];
                        sum=-1;
                    }
                }
                if(i==N-1&&sum==0){ns++;}
            }
        DEB(i)DEB(sum)END;
        }
    }
    ans=min(ans,ns);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;

int main()
{
    abdelrahman010
    long double l;
    cin >> l;
    cout << fixed << setprecision(9) << l * l * l / 27;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
double dp[3009][3009],a[3009];
double best(ll d,ll sum)
{
    if(d==n){
        if(sum>n/2)
        return 1;
        return 0;
    }
    double &r=dp[d][sum];
    if(r!=10) return r;
    return r=(best(d+1,sum)*(double(1)-a[d]))+(best(d+1,sum+1)*a[d]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(ll i=0;i<n;i++)
    cin>>a[i];
for(ll i=0;i<3005;i++)
    for(ll j=0;j<3005;j++)
    dp[i][j]=10;
printf("%0.10f",best(0,0));
return 0;
}


Measured memory_bytes: 74572
instr = input()
cnum = int(input())
for i in range(cnum):
    lineSp = input().split()
    cmd = lineSp[0]
    a, b = int(lineSp[1]), int(lineSp[2])
    if cmd == "replace":
        repstr = lineSp[3]
        instr = instr[0:a] + repstr + instr[b + 1:]
    elif cmd == "reverse":
        repstr = instr[a:b + 1][::-1]
        instr = instr[0:a] + repstr + instr[b + 1:]
    else:
        print(instr[a:b + 1])



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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s.at(i);
  
  vector<vector<int>> ans(h, vector<int> (w));
  vector<int> line(h);
  for(int i = 0; i < h; i++){
    bool ok = false;
    for(int j = 0; j < w; j++){
      if(s.at(i).at(j) == '#') ok = 1;
    }
    if(ok) line.at(i) = 1;
  }
  int num = 0;
  bool ok = false;
  for(int i = 0; i < h; i++){
    if(line.at(i)) num++, ok = false;
    for(int j = 0; j < w; j++){
      if(ok){
        if(s.at(i).at(j) == '#') num++;
      }
      if(line.at(i)) ans.at(i).at(j) = num;
      if(!line.at(i)){
        if(i > 0) ans.at(i).at(j) = ans.at(i-1).at(j);
      }
      if(s.at(i).at(j) == '#') ok = true;
    }
  }
  if(ans.at(0).at(0) == 0){
    int k;
    for(int i = 1; i < h; i++){
      if(line.at(i)){
        k = i;
        break;
      }
    }
    for(int i = 0; i < k; i++){
      for(int j = 0; j < w; j++){
        ans.at(i).at(j) = ans.at(k).at(j);
      }
    }
  }
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++) cout << ans.at(i).at(j) << " ";
    cout << endl;
  }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

vector<li> lights[11];
li p[22];

int main() {
    li n, m;
    cin >> n >> m;
    rep(i, m) {
        li k;
        cin >> k;
        rep(j, k) {
            li x;
            cin >> x;
            lights[i].pb(x - 1);
        }
    }
    rep(i, m) {
        cin >> p[i];
    }

    li res = 0;
    rep(i, bit(n)) {
        bitset<11> bs(i);
        bool ok = true;
        rep(j, m) {
            li cnt = 0;
            for (auto && sw : lights[j]) {
                if (bs[sw]) {
                    cnt++;
                }
            }
            if (cnt % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok)res++;
    }
    cout << res << endl;


    return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if(b <= a) {
    cout << "delicious" << endl;
  } else if(b <= a + x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};


int main(){
    int n0, m0, k0;
    cin >> n0>> m0 >> k0;
    mint n = n0, m = m0, k = k0;
    mint ans=0;
    vector<mint> c(n0+1);
    c[0] = 1;
    for(ll i = 1; i<k0 + 1; i++){
        c[i] = c[i-1];
        c[i] /= i;
        c[i] *= n0 - i;
    }
    rep(i, k0+1){
        mint memo = m;
        memo *= (m-1).pow(n0-1-i);
        memo *= c[i];
        ans += memo;
    }
    cout << ans.x << endl;
    return 0;
}

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

int main(){
	int n, W; cin >> n >> W;
	int v[n], w[n];
	for(int i=0; i<n; i++){
		cin >> v[i] >> w[i];
	}
	vector<vector<int>> dp = vector<vector<int>>(n+1, vector<int>(W+1, -1));
	dp[0][0] = 0;
	for(int i=0; i<n; i++)for(int j=0; j<=W; j++)if(dp[i][j] >= 0){
		dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		if(j + w[i] <= W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
	}
	int ans = 0;
	for(int j=0; j<=W; j++){
		ans = max(ans, dp[n][j]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6848
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        h: usize,
        w: usize,
        c: (Usize1, Usize1),
        d: (Usize1, Usize1),
        s: [Chars; h],
    }

    use std::cmp::Reverse;
    let mut heap = BinaryHeap::new();
    const INF: usize = 1_000_000_000_000_000;
    let mut dist = vec![vec![INF; w]; h];
    heap.push((Reverse(0), c));
    dist[c.0][c.1] = 0;

    while let Some((Reverse(cost), (x, y))) = heap.pop() {
        if (x, y) == d {
            println!("{}", cost);
            return;
        }
        for dx in 0..5 {
            for dy in 0..5 {
                if dx == 2 && dy == 2 {
                    continue;
                }
                if x + dx < 2 || y + dy < 2 {
                    continue;
                }

                let nx = x + dx - 2;
                let ny = y + dy - 2;
                if nx > h - 1 || ny > w - 1 {
                    continue;
                }
                if s[nx][ny] == '#' {
                    continue;
                }
                let d = (dx, dy);
                let c = if d == (2, 1) || d == (2, 3) || d == (1, 2) || d == (3, 2) {
                    0
                } else {
                    1
                };
                let nc = cost + c;
                if dist[nx][ny] <= nc {
                    continue;
                }
                dist[nx][ny] = nc;
                heap.push((Reverse(nc), (nx, ny)));
            }
        }
    }
    println!("-1");
}


Measured memory_bytes: 15132
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a*b>a+b&&a*b>a-b){
		printf("%d\n",a*b);
	}
	else if(a+b>a*b&&a+b>a-b){
		printf("%d\n",a+b);
	}
	else{
		printf("%d\n",a-b);
	}
	return 0;
}


Measured memory_bytes: 128
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

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

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


#line 2 "tmp.cpp"

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

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  FOR(b, k + 1, n + 1) { ans += (n / b) * (b - k) + max(0, n % b - k + 1); }
  if (k == 0)
    ans -= n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
d  ={}
for i in range(n):
    s = str(input())
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x : x[0])
d = sorted(d, key=lambda x : x[1],reverse=1)

flag = d[0][1]
for i in d:
    if i[1] == d[0][1]:
        print(i[0])
    else:
        exit()

Measured memory_bytes: 44764
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> num(3);
    cin >> num[0] >> num[1] >> num[2];
    sort(num.begin(), num.end());
    cout << num[0] << " " << num[1] << " " << num[2] << endl;
 //   system("pause");
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;

int n, m;
map <string, int> mp;
int32_t main() {
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string x; cin >> x;
		++mp[x];
	}
	cin >> m;
	for(int i = 0; i < m; ++i) {
		string x; cin >> x;
		--mp[x];
	}
	int ans = 0ll;
	for(auto it:mp) {
		ans = max(ans, it.second);
	}
	cout << ans;
	time
}

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

int main() {
    const ll MOD = 1e9 + 7;
    int n, m;
    cin >> n >> m;
    vector<bool> oks(n + 1, true);
    rep(i, m) {
        int a;
        cin >> a;
        oks[a] = false;
    }

    vector<ll> dp(n + 1);
    dp[0] = 1;
    rep(i, n) {
        for (int j = i + 1; j <= min(n, i + 2); j++) {
            if (oks[j]) {
                dp[j] += dp[i];
                dp[j] %= MOD;
            }
        }
    }

    cout << dp[n] << endl;
    return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    string s , t;
    cin >> s >> t;

    t.pop_back();

    printf("%s\n" , s == t ? "Yes" : "No");



}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<random>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for(int i=0; i<m; i++) cin >> c[i];

  vector<int> cn(n+1, inf);
  for(int i=0; i<m; i++) cn[ c[i] ] = 1;

  for(int i=1; i<=n; i++){
    for(int j=0; j<m; j++){
      if( i - c[j] < 0 ) continue;
      cn[i] = min(cn[i], cn[ i - c[j] ] + 1);
    }
  }
  cout << cn[n] << endl;


  return 0;
}





// EOF

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

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

	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp % 2 == 0 && tmp % 3 != 0 && tmp % 5 != 0) {
			printf("DENIED");
			return 0;
		}
	}

	printf("APPROVED");

	
	return 0;
}

Measured memory_bytes: 256
/**
 * Problem:	B. 
 * Author:	hkxadpall. 
 * Date:	2018-09-01. 
 * Upload:	AtCoder. 
 */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>
using namespace std;

namespace AuthorName { 
    template <typename _TpInt> inline _TpInt read();
    template <typename _TpRealnumber> inline double readr();
    template <typename _TpInt> inline void write(_TpInt x);
//	template <typename _TpSwap> inline void swap(_TpSwap &x, _TpSwap &y);
	
#	define Max_N 1007
	
	int x1, y1, x2, y2;
	int x3, y3, x4, y4;
	
	int main() 
	{
		x1 = read<int>();
		y1 = read<int>();
		x2 = read<int>();
		y2 = read<int>();
		x3 = x2 - (y2 - y1);
		y3 = y2 + (x2 - x1);
		x4 = x3 - (y3 - y2);
		y4 = y3 + (x3 - x2);
		write(x3); putchar(32);
		write(y3); putchar(32);
		write(x4); putchar(32);
		write(y4); putchar(32);
	    return 0;
	}

#	define Getchar() getchar()

    template <typename _TpInt>
    inline _TpInt read()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpInt init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = (init << 3) + (init << 1) + (c & 15);
        return init * flag;
    }

    template <typename _TpRealnumber>
    inline double readr()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpRealnumber init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init * 10 + (c & 15);
        if (c != '.') return init * flag;
        register _TpRealnumber l = 0.1;
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init + (c & 15) * l, l *= 0.1;
        return init * flag;
    }

    template <typename _TpInt>
    inline void write(_TpInt x)
    {
        if (x < 0) {
            putchar('-');
            write<_TpInt>(~x + 1);
        }
        else {
            if (x > 9) write<_TpInt>(x / 10);   
            putchar(x % 10 + '0');
        }
    }

//	template <typename _TpSwap>
//	inline void swap(_TpSwap &x, _TpSwap &y)
//	{
//	    _TpSwap t = x;
//	    x = y;
//	    y = t;
//	}
}

int main()
{
    AuthorName::main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int K, N; cin >> K >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    vector<int> diff(N);
    REP(i, 1, N) diff[i] = A[i] - A[i - 1];
    diff[0] = A[0] + (K - A.back());

    int d = 0;
    REP(i, 0, N) d = max(d, diff[i]);

    cout << K - d << endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int R = cin.nextInt();
        int D = cin.nextInt();
        int X2000 = cin.nextInt();

        int ans = X2000;

        for (int i = 1; i <= 10; ++i)
        {
            ans = R * ans - D;

            WriteLine(ans);
        }
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int a,b;
int main(){
	scanf("%d",&a);
	rep(i,0,a/100+10){
		int s=a-i*100;
		if(0<=s&&s<=5*i){
			puts("1");
			return 0;
		}
	}
	puts("0");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
} comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> graph[N]; // 0-indexed
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    mint ans = 1;
    int root = 0;
    vector<int> parent(N, -1);
    vector<int> order;
    stack<int> stk; // llかどうかに注意
    stk.push(root);
    while (!stk.empty()) {
        int cur = stk.top(); stk.pop();
        order.push_back(cur);
        if (cur == root) {
            if (sz(graph[root]) + 1 > K) {
                cout << 0 << '\n';
                return 0;
            }
            ans *= comb.p(K, sz(graph[root]) + 1);
        } else {
            if (sz(graph[cur]) - 1 > K - 2) {
                cout << 0 << '\n';
                return 0;
            }
            ans *= comb.p(K-2, sz(graph[cur]) - 1);
        }
        for (int next : graph[cur]) {
            if (next == parent[cur]) continue;
            parent[next] = cur;
            stk.push(next);
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 166812
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    long h, w;
    scan(h, w);
    if (h == 1 || w == 1) {
        writeln(1);
        return;
    }
    auto ans = (h*w + 1) / 2;
    writeln(ans);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	auto ip2 = readAs!(int[]), h = ip2[0], w = ip2[1];
	writeln((H-h) * (W-w));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    cin >> N;

    vector<vector<i64>> abc(N,vector<i64>(3));
    rep(i,0,N) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

    vector<vector<i64>> dp(N,vector<i64>(3,-inf64));
    rep(i,0,3) dp[0][i]=abc[0][i];
    rep(i,1,N){
        rep(j,0,3){
            rep(k,0,3){
                if(j==k) continue;
                chmax(dp[i][j],dp[i-1][k]+abc[i][j]);
            }
        }
    }

    cout << *max_element(begin(dp[N-1]),end(dp[N-1])) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(){
  ll k,s;
  cin>>k>>s;
  ll ans=0;
  for(ll i=0;i<=k;i++){
    for(ll j=0;j<=k;j++){
      ll z=s-i-j;
      if(z<0||z>k)continue;
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll sum = 0, mi_n = - 1;
    while(n >= 10){
        sum += n % 10;
        mi_n += 9;
        n /= 10;
    }
    sum += n;
    mi_n += n;
    cout << max(sum, mi_n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int n,m;
  cin >>n;
  cin >>m;

  vector<int> dd(0);

  for(int i=1;i*i<=m;i++){
    if(m%i == 0){
      dd.push_back(i);
      dd.push_back(m/i);
    }

  }
  sort(dd.begin(),dd.end());

  int d=1;

  for(int x:dd){
    int res = m - n*x;
    if(res < 0){
      //cout << endl;
      break;
    }
    else if(res == 0){
      d=x;
      //break;
    }
    else{
      //cout << x << ":";
      //cout << res << endl;
      if(res % x == 0) d=x;
    }

  }

  cout << d << endl;

  return 0;
}


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

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

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

  map<int, int> p;
  int m = 0;

  for (int i = 0; i < n; i++) {
    if (a[i] >= 1 && a[i] <= 399) p[0]++;
    if (a[i] >= 400 && a[i] <= 799) p[1]++;
    if (a[i] >= 800 && a[i] <= 1199) p[2]++;
    if (a[i] >= 1200 && a[i] <= 1599) p[3]++;
    if (a[i] >= 1600 && a[i] <= 1999) p[4]++;
    if (a[i] >= 2000 && a[i] <= 2399) p[5]++;
    if (a[i] >= 2400 && a[i] <= 2799) p[6]++;
    if (a[i] >= 2800 && a[i] <= 3199) p[7]++;
    if (a[i] >= 3200) m++;
  }

  if (p.size() == 0)
    cout << "1 " << m << endl;
  else
    cout << p.size() << " " << p.size() + m << endl;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a_lst(N);

    int sum = 0;
    for(int &x: a_lst)
    {
        cin >> x;
        sum += x;
    }
    int counter = M;
    for(int &x: a_lst)
    {
        if(((float)x/sum) >= ((float)1/(4*M)))
        {
            counter--;
            if(counter==0)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

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

int main(void){
  string s,t;
  cin>>s>>t;
  int min=t.size();
  for (int i = 0; i <= (s.size()-t.size()); i++)
  {
    int n=0;
    for(int j=0; j<t.size();j++){
      if(s[i+j]!=t[j])n++;
    }
    if(n<min)min=n;
  }

  cout<<min<<endl;
  return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
typedef long long int ll;
#define MOD 1000000007
int main() {
    char s[1001],t[1001];
    scanf("%s",s);
    scanf("%s",t);
    int t_size=0;
    int s_size=0;
    while(t[t_size]!='\0') t_size++;
    while(s[s_size]!='\0') s_size++;
  	int max=0;
	for (int i=0;i<s_size-t_size+1;i++) {
        int count=0;
        for (int j=0;j<t_size;j++) {
          if (s[i+j]==t[j]) count++;
        }
        if (max<count) max=count;
    }
  	printf("%d",t_size-max);
    return 0;
}

Measured memory_bytes: 1732