akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int N = 52+1;
int n;
char s[2][N];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<2;++i)scanf("%s",s[i]+1);
	ll ans=1,flag=0;
	for(int i=1;i<=n;++i)
	{
		if(s[0][i]==s[1][i])
		{
			if(flag==0)(ans*=3ll)%=mod;
			if(flag==1)(ans*=2ll)%=mod;
			flag=1;
		}
		else
		{
			if(flag==0)(ans*=6ll)%=mod;
			if(flag==1)(ans*=2ll)%=mod;
			if(flag==2)(ans*=3ll)%=mod;
			flag=2;
			i++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B;
	cin >> A >> B;

	if (B == 1) co(0);
	else co(A - B);



	Would you please return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  vector<double> nums;
  double h;
  while(cin>>h){
    nums.push_back(h);
  }

  vector<double>::iterator min_it = min_element( nums.begin(), nums.end() );
  vector<double>::iterator max_it = max_element( nums.begin(), nums.end() );

  cout << *max_it - *min_it << endl;

  return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	ll ans = 0;
	ll d = min(A, K);
	ans += d;
	K -= d;
	d = min(B, K);
	K -= d;
	d = min(C, K);
	ans -= d;
	cout << ans << endl;
}


Measured memory_bytes: 3632
import math

def f_gcd(a, b):
    return math.gcd(a, b)

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += f_gcd(math.gcd(a, b), c)

print(ans)

Measured memory_bytes: 70712
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    string s1,s2; 
    cin>>s1>>s2; 
    int len=sz(s1),ans=0;
    for (int i=0;i<len;i++){
        if (s1[i] != s2[i]) ans++;
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int time,time_h,time_m,time_s;
    cin >> time;
    time_h = time/3600;
    time_m = time%3600/60;
    time_s = time%60;
    
    cout << time_h << ":" << time_m << ":" << time_s << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF = 0x3f3f3f3f ;
#define PII pair<lli,lli>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
lli a[305][305];

int main()
{
    int n;
    si(n);

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            sli(a[i][j]);
        }
    }

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(i!=k && k!=j && i!=j){
                    if(a[i][k]+a[k][j]<a[i][j]){
                        cout<<"-1"<<endl;
                        return 0;
                    }
                }
            }
        }
    }

    lli ans=0;
    for(int u=1;u<=n;u++){
        for(int v=u+1;v<=n;v++){
            int x=0;
            for(int k=1;k<=n;k++){
                if(u!=v && v!=k && u!=k){
                    if(a[u][k]+a[k][v]==a[u][v]){
                        x=1;
                        break;
                    }
                }
                if(x==1) break;
            }
            if(x==0) ans+=a[u][v];
        }
    }

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


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
const int N=1e5+5;
int a[N];
int main(){
	int n;
	scanf("%d",&n);
	int ai;
	while(n--){
		scanf("%d",&ai);
		a[ai]++;   
		a[ai-1]++;
		a[ai+1]++;
	}
	int max=0;
	for(int i=0;i<N-1;i++){
	if(max<a[i])
		max=a[i];
	}
	printf("%d\n",max);
 
	return 0;
 
}
 

Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);

int main(){
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<long long int> vc(2), vd(2), vcd(2);
    a--;
    vc[0] = a / c;
    vd[0] = a / d;
    if(a < (c*d) /gcd(c, d)) vcd[0] = 0;
    else vcd[0] = a / ((c*d) /gcd(c, d));
    vc[1] = b / c;
    vd[1] = b / d;
    if(b < (c*d) /gcd(c, d)) vcd[1] = 0;
    else vcd[1] = b / ((c*d) /gcd(c, d));
    cout << (b - (vc[1] + vd[1] - vcd[1])) - (a - (vc[0] + vd[0] - vcd[0])) << endl;
    return 0;
}
long long int gcd(long long int a, long long int b){
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
int n;long long d=0,v[10000000],ju[10000000];
void readdata()
{
    cin>>n;
    for (int i=0;i<=n;i++)
    {
        cin>>v[i];
    }
}

int gcd(int u,int v)
{
    while (v != 0) {
        int r = u % v;
        u = v;
        v = r;
    }
    return u;
}

void solve()
{
    long long max1=0;
    for (int i=1;i<=n-1;i++)
    {
        int a;
        int k=0;
        long long sum=0;
        while (1)
        {
            a=n-1-k*i;
            if (a<=i) break;
            sum+=v[i*k]+v[n-1-k*i];
            if (!((a%i==0)&&((a/i-1)*i+a<n-1)))
                max1=max(max1,sum);
            k++;
        }
    }
    cout<<max1;
}

void vet()
{
    int max1=0;
    for (int a=1;a<=n-1;a++)
    {
        for (int b=1;b<a;b++)
        {
            int step=0;
            d++;
            int sum=0;
            while (step<=n-1)
            {
                step+=a;
                sum+=v[step];
                ju[step]=d;
                if (step>n-1)
                {
                    sum=0;
                    break;
                }
                else
                {
                    if (step==n-1) break;
                }
                step-=b;
                if (ju[step]==d)
                {
                    sum=0;
                    break;
                }
                sum+=v[step];
            }
            max1=max(max1,sum);
        }
    }
    cout<<max1;
}

int main()
{
   // freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    readdata();
    //vet();
    solve();
    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
int a,b,c;
int cnt=0;
main(){
   
   scanf("%d%d%d",&a,&b,&c);
  
   
   while(a<=b){
   
   if(c%a==0){
   cnt++;}
   
   a++;
   
   }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 596
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    v = get_li()
    c = get_li()
    print(sum(max(vi-ci, 0) for vi, ci in zip(v, c)))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    int tmp = 0, ans = 0;
    for (int i = 0; i < S.size(); ++i){
        int j = i;
        int tmp=0;
        while (j < S.size()){
            if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
                tmp++;
            }
            else{
                ans = max(ans, tmp);
                tmp = 0;
                break;
            }
            ++j;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1000000007;
using namespace std;

int main()
{
    string S;
    cin >> S;
    int s = S.size();
    if (S[s - 1] == 's')
    {
        cout << S;
        cout << "es";
    }
    else
    {
        cout << S;
        cout << 's';
    }
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    int mod = 1e9 + 7;
    vector<int> dp(1 << N);
    dp[0] = 1;

    for (int s = 0; s < 1 << N; s++) {
        for (int j = 0; j < N; j++) {
            if (s >> j & 1) continue;
            int i = __builtin_popcount(s);
            if (A[i][j] == 0) continue;
            dp[s | (1 << j)] += dp[s];
            dp[s | (1 << j)] %= mod;
        }
    }
    
    cout << dp[(1 << 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: 8448
#include <bits/stdc++.h>
using namespace std;

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

  int N;
  cin >> N;
  vector<int> X(N);
  for(int i = 0; i < N; ++i) cin >> X.at(i);
  int Left = *min_element(X.begin(), X.end());
  int Right = *max_element(X.begin(), X.end());

  int min_HP = 10000000;
  for (int P = Left; P <= Right; ++P) {
    int HP = 0;
    for(int i = 0; i < N; ++i) {
      HP += (X.at(i) - P) * (X.at(i) - P);
    }
    min_HP = min(min_HP, HP);
  }
  cout << min_HP << endl;
  return 0;
}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;


int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int cnt = 0;
    vector<vector<int>> m(h, vector<int>(w, -1));
    vector<int> hh(w, 0), ww(h, 0);
    rep(i, 0, h){
        rep(j, 0, w){
            if(j < a && i < b){
                m[i][j] = 0;
            }else if((j < a && i >= b) || (j >= a && i < b)){
                m[i][j] = 1;
                hh[j]++; ww[i]++;
            }else{
                m[i][j] = 0;
            }
        }
    }
    rep(i, 0, h){
        if(min(ww[i], w - ww[i]) > a){
            cout << "No" << endl;
            return 0;
        }
    }
    rep(j, 0, w){
        if(min(hh[j], h - hh[j]) > b){
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            cout << m[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 5120
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int getDigit(int num)
{
    if(num<=9)
    {
        return 1;
    }
    else if(num<=99)
    {
        return 2;
    }
    else if(num<=999)
    {
        return 3;
    }
    else if(num<=9999)
    {
        return 4;
    }
    else if(num<=99999)
    {
        return 5;
    }
    else if(num <= 999999)
    {
        return 6;
    }
}
int main()
{
    int N;
    cin>>N;
    int Sum = 0;

    for(int i = 1;i <= N;i++)
    {
        if(getDigit(i)%2==1)
        {
            Sum++;
        }
    }
    cout << Sum <<endl;
}

Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-28 15:35:36
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}

void No()
{
  cout << "No" << endl;
  exit(0);
}

int N, M;
vector<int> V[100010];
int parent[100010];
int start = -1;
int goal = -1;

bool dfs(int s)
{
  for (auto x : V[s])
  {
    if (x != parent[s])
    {
      if (x == start)
      {
        return false;
      }
      else if (x == goal)
      {
        return true;
      }
      parent[x] = s;
      if (!dfs(x))
      {
        return false;
      }
    }
  }
  return true;
}

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  for (auto i = 0; i < N; i++)
  {
    int s = V[i].size();
    if (s % 2 == 1)
    {
      No();
    }
  }
  for (auto i = 0; i < N; i++)
  {
    int s = V[i].size();
    if (s >= 6)
    {
      Yes();
    }
  }
  int four = 0;
  for (auto i = 0; i < N; i++)
  {
    int s = V[i].size();
    if (s == 4)
    {
      four++;
    }
  }
  if (four >= 3)
  {
    Yes();
  }
  if (four <= 1)
  {
    No();
  }
  for (auto i = 0; i < N; i++)
  {
    if ((int)V[i].size() == 4)
    {
      if (start == -1)
      {
        start = i;
      }
      else
      {
        goal = i;
        break;
      }
    }
  }
  fill(parent, parent + N, -1);
  if (!dfs(start))
  {
    Yes();
  }
  else
  {
    No();
  }
}

Measured memory_bytes: 7296
n, x = map(int, input().split())
a = list(sorted(map(int, input().split())))
if x == sum(a):
    print(n)
else:
    acc = 0
    for i in range(n):
        acc += a[i]
        if acc > x:
            break
    if i == n:
        print(n - 1)
    else:
        print(i)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define pb push_back

using namespace std;

typedef long long ll;

const int N = 1e6 + 10;
const ll INF = 1e15 + 10;
const ll MOD = 1e9 + 7;

ll dists[N], distt[N];
ll cnts[N], cntt[N];
vector <pair <int, int> > g[N];

void dijkstra(ll* d, ll* cnt, int s, int n) {
    fill(d, d + n, INF);
    vector <bool> used(n, 0);
    d[s] = 0;
    cnt[s] = 1;
    set <pair <ll, int> > st;
    for (int i = 0; i < n; i++)
        if (i != s)
            st.insert(make_pair(INF, i));
    st.insert(make_pair(0, s));
    for (int i = 0; i < n; i++) {
        auto tmp = *st.begin();
        int v = tmp.second;
        for (auto t: g[v])
            if (d[t.second] < INF && d[t.second] + t.first == d[v]) {
                cnt[v] = (cnt[v] + cnt[t.second]);
                if (cnt[v] >= MOD) cnt[v] -= MOD;
            }
        ll w = tmp.first;
        used[v] = true;
        st.erase(st.begin());
        for (auto t: g[v]) {
            if (used[t.second]) continue;
            //assert(st.count(make_pair(d[t.first], t.first)));
            st.erase(make_pair(d[t.second], t.second));
            d[t.second] = min(d[t.second], d[v] + t.first);
            st.insert(make_pair(d[t.second], t.second));
        }
    }
}

int main() {
    //freopen("a.in", "r", stdin);
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    int v, u, w;
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &v, &u, &w);
        g[--v].pb({w, --u});
        g[u].pb({w, v});
    }
    //for (int i = 0; i <n; i++)for (auto u: g[i]) cout << i << " " << u.second << endl;
    dijkstra(dists, cnts, s, n);
    dijkstra(distt, cntt, t, n);
    ll T = dists[t];
    //cout << T << endl;
//    for (int i = 0; i < n; i++)
//        cout << dists[i] << " ";cout << endl;

    vector <int> verts;
    for (int v = 0; v < n; v++)
        if (dists[v] == distt[v] && 2 * dists[v] == T) {
            verts.pb(v);
            //cout << "v " << v << endl;
        }


    ll ans = cnts[t] * cnts[t] % MOD;
    for (int v = 0; v < n; v++)
        for (auto j: g[v]) {
            int u = j.second;
            if (dists[v] + distt[u] + j.first == T &&
                2 * dists[v] < T && 2 * dists[u] > T)
                ans = (ans - cnts[v] * cntt[u] % MOD * cnts[v] % MOD * cntt[u]) % MOD;
        }

    for (auto v: verts)
        ans = (ans - cnts[v] * cntt[v] % MOD * cnts[v] % MOD * cntt[v]) % MOD;

    cout << (ans + MOD) % MOD << endl;
}


Measured memory_bytes: 45312
N,A=gets.split.map(&:to_i)
X=gets.split.map{|i|i.to_i-A}.sort!

H=Hash.new(0)
H[0]=1

N.times do |i|
  HH=H.dup
  H.each do |k,v|
    HH[X[i]+k]+=v
  end
  H=HH.dup
end

puts H[0]-1

Measured memory_bytes: 5756
//
// Created by kuroneko on 2019-09-28.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;

#define INF 1000000000000009LL
#define MOD 1000000007LL

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight):src(src), dst(dst), weight(weight) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
    std::cout << std::fixed;
    std::cout << std::setprecision(7);
    int N; cin >> N;

    if (N % 2 == 0) cout << 1.0 / 2 << endl;
    else cout << 1.0 * (N + 1) / 2 / N << endl;

    return 0;

}


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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
		
	int T;
	cin >> T;
	map<string, int> m;
	while(T--) {
		string s;
		cin >> s;
		m[s]++;	
	}

	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;

}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define elif else if
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define For(i, a) for (int i = 0; i < (a); i++)
#define Ford(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define Fd(i, a) for (int i = (a)-1; i >= 0; i--)


int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

int main()
{
    ffast;
    //freopen("0in.txt","r",stdin);
    //freopen("0out.txt","w",stdout);


    int t;
    cin>>t;
    ll ans = 0;
    for(int i=1; i<=t; i++)
    {
        for(int j=1; j<=t;j++)
        {
            for(int k=1; k<=t; k++)
            {
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans<<"\n";

    return 0;
}






Measured memory_bytes: 3648
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main()
{
	int n;

	scanf("%d", &n);

	map<string, int> list;

	int lmax = 0;

	for (int i = 0; i < n; i++)
	{
		char input[20];

		scanf("%s", input);

		string str;

		str = input;

		map<string, int>::iterator ret;
		
		ret = list.find(str);

		int val;

		if (ret == list.end())
		{
			val = 1;

			list[str] = 1;
		}

		else
		{
			val = ++ret->second;
		}

		if (val > lmax)
		{
			lmax = val;
		}
	}

	for (map<string, int>::iterator it = list.begin(); it != list.end(); it++)
	{
		if (it->second == lmax)
		{
			printf("%s\n", it->first.c_str());
		}
	}

	return 0;
}

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

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	int max = (a > b ? a : b) > c ? (a > b ? a : b) : c;
	
	int ans = max * 10;
	if(max == a) {
		ans += b + c;
	}
	else if(max == b) {
		ans += a + c;
	}
	else {
		ans += a + b;
	}
	
	cout << ans << endl;
	
    return 0;
}

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


int main(){
    int N,M,C;
    cin >> N >> M >> C;
    
    vector<int> B(M);
    rep(i,M){
        cin >> B[i];
    }
    
    int ans=0;
    rep(z,N){
        int sum=0;
        rep(i,M){
            int x;
            cin >> x;
            sum += x * B[i];
        }
        if(sum + C >0){
            ans++;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean b = false;
		if(n < 82) {
			for(int i = 1;i <= 9;i++) {
				for(int k = 1; k <= 9;k++) {
					if(n == i * k) {
						b = true;
						break;
					}
				}
			}
		}
		if(b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23892
import copy


def q3():
    H, W, K = [int(i) for i in input().split(" ")]
    C = []
    for _ in range(H):
        C.append([i for i in input()])

    def helper(li):
        count = 0
        for i in range(len(li)):
            for j in range(len(li[i])):
                if li[i][j] == "#":
                    count += 1
        return count

    def get_all_selection(num):
        li = []
        if num == 0:
            return []
        if num == 1:
            return [[False], [True]]
        for l in get_all_selection(num - 1):
            li.append([False] + l)
            li.append([True] + l)
        return li

    answer = 0

    for sh in get_all_selection(H):
        for sw in get_all_selection(W):
            c = copy.deepcopy(C)
            for i in range(H):
                if not sh[i]:
                    c[i] = ["-"] * W
            for i in range(W):
                if not sw[i]:
                    for l in c:
                        l[i] = "-"

            black_count = helper(c)
            if black_count == K:
                answer += 1
                # print(sh, sw, c)

    print(answer)


q3()


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

using namespace std;

#define intt long long
const int MAXN = 100005;

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    stack <char> st;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i ++) {
        if (s[i] == '0' || s[i] == '1') st.push(s[i]);
        else {
            if (st.size() != 0) {
                st.pop();
            }
        }
    }
    string ans = "";
    while (!st.empty()) {
        char x = st.top();
        ans += x;
        st.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i=0,c1=0,c0=0;
  char s[100000];
  
  scanf("%s",s);
  
  while(s[i]!='\0')
  {
	if(s[i]=='0') c0++; 
    else if(s[i]=='1') c1++;
    i++;
  }
	
  if(c0>=c1) printf("%d",2*c1);
  else printf("%d",2*c0);
  
  return 0; 
}

Measured memory_bytes: 256
N = int(input())
A, B = map(int, input().split())
P = map(int, input().split())

easy = 0
normal = 0
hard = 0

for i in P:
    if i <= A:
        easy += 1
    elif A < i <= B:
        normal += 1
    else:
        hard += 1

print(min(easy, normal, hard))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

int n, q;
string s;
vector<set<int>> st(26);

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

    cin >> n;
    rep(i, n) {
        char c;
        cin >> c;
        s.push_back(c);
        st[c - 'a'].insert(i);
    }
    cin >> q;
    while(q--) {
        int query;
        cin >> query;
        if(query == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            st[s[i] - 'a'].erase(i);
            st[c - 'a'].insert(i);
            s[i] = c;
        } else {
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            rep(i, 26) if(st[i].lower_bound(l - 1) != st[i].lower_bound(r))
                cnt++;
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 24192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int count = 0;
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0)
				break;

			for (int i = 1; i <= n - 2; i++) {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}

}



Measured memory_bytes: 26696
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
//#define all(c) c.begin(), c.end()
//#define rall(c) c.rbegin(), c.rend()
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

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

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

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

void solve() {
	ll n, m;
	cin >> n >> m;
	vector<ll> cnt(m, 0);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		for (ll j = 0; j < k; j++) {
			ll c;
			cin >> c;
			cnt[c - 1]++;
		}
	}
	ll cnt0 = 0;
	forEach(cnt) cnt0 += ll(it == n);
	cout << cnt0 << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


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

using namespace std;

int main()
{
    char a[20],b[20],c[20];
    int x,y;
    cin>>a>>b>>c;
    x=strlen(a);
    y=strlen(b);
    if(a[x-1]==b[0])
    {
        if(b[y-1]==c[0])
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if(a==5&&b==5&&c==7 || a==5&&b==7&&c==5 || a==7&&b==5&&c==5){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 19796
//
// Created on 2020/05/10.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }
};

const int MAX = 510000;//nCkのn,kの取りうるMAX

long long fac[MAX],finv[MAX],inv[MAX];

//階乗のテーブルを作る
void COM_initialize(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2 ; i < MAX ; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod -inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

//二項係数計算,nCkのn,kを引数として渡す
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod)% mod;
}

int main() {
    mint ans = 0;
    int n,m,k;
    cin>>n>>m>>k;
    COM_initialize();
    mint paint = m ;
    for (int i = n-1 ; i >= 0; --i) {
        if(i <= k ){
            mint group = COM(n-1,i);
            ans += group * paint;
        }
        paint *= (m-1);
    }

    cout<<ans.x<<endl;

    return 0;
}


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

using namespace std;

int cnt = 0;
int MOD = 1000000007;

int x[10],y[10];

double dist(int i,int j){
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(pow(dx,2)+pow(dy,2));
}

int main(){
    int N;
    cin >> N;
    
    for(int i=1;i<=N;i++){
        cin >> x[i] >> y[i];
    }
    
    double sum = 0.0;
    vector<int> v(N);
    
    for(int i=0;i<N;i++){
        v[i] = i+1;
    }
    
    do{
        for(int i=0;i<N-1;i++){
            sum += dist(v[i],v[i+1]);
        }
    }while(next_permutation(v.begin(), v.end()));
    
    int tmp = 1;
    for(int i=2;i<=N;i++){
        tmp *= i;
    }
    
    cout << fixed << setprecision(10) << sum / tmp << endl;
    
    return 0;
}


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


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int compare_string(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
}
//  qsort(names, 3, sizeof *names, compare_string);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
//  int  a, b, c, d, e, X, Y ,r;
  unsigned long long a, b, c, d, e, X, Y;
  //  double  c;
// long long  A[200003]={};
  int  A[200003]={};
  int  B[100003]={};
//  int  C[100003][100001]={};
  int  C[100003]={};

  int  flg=0;

//  char s[101][101]={};
  char s[10000001][11]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
  int sosuu[46] ={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199};
  int min =100000001;
  int len=0;
  int l=0;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long  ans=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  b=100;
  //  a=0;
  scanf("%llu", &a);
//  printf("%llu\n",);
  for(i=1;i<3800;i++){
    b=(b+b*0.01);
//         if(i>3700) printf("%llu\n",b);
    if(a<=b){
      printf("%d\n",i);
      return 0;
    }  
  }
  printf("NG\n");
return 0;
}


Measured memory_bytes: 1736
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }

int h, w;
int f[55][55] = { 0 }, dp[55][55] = { 0 };

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			f[i][j] = s[j] - '0';
		}
	}
	dp[0][0] = f[0][0];
	for (int i = 1; i < w; i++) {
		dp[0][i] = dp[0][i - 1] + f[0][i];
	}
	for (int i = 1; i < h; i++) {
		dp[i][0] = dp[i - 1][0] + f[i][0];
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			dp[i][j] = min(dp[i - 1][j], dp[i][j-1]) + f[i][j];
			//cout << dp[i][j] << " ";
		}
		//cout << "\n";
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 3208
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  n <- readLn
  s <- B.getLine
  putStrLn $ if solve n s then "Yes" else "No"

solve :: Int -> B.ByteString -> Bool
solve n s
  | q == 1    = False
  | otherwise = t == u
    where (p, q) = divMod n 2
          (t, u) = B.splitAt p s


Measured memory_bytes: 3840
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Static Sushi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

ll xs[MAX_N], vs[MAX_N];
ll sum0[MAX_N + 1], sum1[MAX_N + 1];
ll dp0[MAX_N + 1], dp1[MAX_N + 1];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  ll c;
  scanf("%d%lld", &n, &c);

  for (int i = 0; i < n; i++) scanf("%lld%lld", &xs[i], &vs[i]);

  sum0[0] = sum1[0] = dp0[0] = dp1[0] = 0;

  for (int i = 0, j = n - 1; i < n; i++, j--) {
    sum0[i + 1] = sum0[i] + vs[i];
    sum1[i + 1] = sum1[i] + vs[j];
    dp0[i + 1] = max(dp0[i], sum0[i + 1] - xs[i]);
    dp1[i + 1] = max(dp1[i], sum1[i + 1] - (c - xs[j]));
  }

  ll maxd = 0;
  setmax(maxd, dp0[n]);
  setmax(maxd, dp1[n]);

  for (int i = 0, j = n - 1; i < n; i++, j--) {
    ll d0 = sum0[i + 1] - xs[i] * 2 + dp1[j];
    ll d1 = sum1[i + 1] - (c - xs[j]) * 2 + dp0[j];
    setmax(maxd, d0);
    setmax(maxd, d1);
  }

  printf("%lld\n", maxd);
  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int Q = in.nextInt();
		int H = in.nextInt();
		int S = in.nextInt();
		int D = in.nextInt();
		int N = in.nextInt();
		
		long l1 = Math.min(Q*4, Math.min(H*2, S));
		long l2 = D;
		
		if(l1*2<=l2){
			System.out.println(l1*N);
		}else{
			System.out.println(l2*(N/2)+l1*(N%2));
		}
	}

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

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


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


	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (1) {
		C -= B;
		if (C <= 0) {
			co("Yes");
			return 0;
		}
		A -= D;
		if (A <= 0) {
			co("No");
			return 0;
		}

	}





	Would you please return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int a, b;
	cin >> a >> b;
	for(int i=1; i<=8e4; ++i) {
		int a2=i*0.08, b2=i*0.1;
		if(a2==a&&b2==b) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}

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

int main() {
  int N ,K;
  cin >> N >> K;
  
  vector<int> height(N);
    for(int i = 0; i < N; i++){
      cin >> height.at(i);
    }
  
  int count = 0;
  
  for(int i = 0; i < N; i++){
    if(height.at(i) >= K){
      count++;
    }
  }
  
  cout << count << endl;
  

}


Measured memory_bytes: 640
import math

q, h, s, d = map(int, input().split())
n = int(input())

if 2*q < h:
    h = 2*q

if 2*h < s:
    s = 2*h

if 2*s < d:
    d = 2*s

print(math.floor(n/2)*d + n%2*s)

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

int main() {
	int n, k, b;
	cin >> n >> k;

	vector<int> t(k);
	for (int i = 0; i < k; i++)  cin >> t[i];
	sort(t.begin(), t.end());

	for (int i = 0; i < 1 << k; i++) {
		int d = 0;
		vector<int> temp;
		for (int j = 0; j < k; j++) {
			if (i & 1 << j) {
				d |= 1 << t[j];
				temp.push_back(t[j]);
			}
		}
		cout << d << ":";
		for (int j : temp)    cout << " " << j;
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3144
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
    char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
    in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
    in int read()
    {
        int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
        x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
    }
    in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
    in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
    in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
    in void flush() {if(C>1<<22) ot();}
    template <typename T>
    in void write(T x,char t)
    {
        int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
        if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
    }
    in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=1.5e3+5;
int n,s[N][N],p[N][N],mn[2][N][N],mx[2][N][N];ll ans;
char ch[N][N];
int main()
{
	n=read();for(int i=1;i<=n;i++) gs(ch[i]+1);
	for(int i=n,t=1;i;t^=1,i--) for(int j=n;j;j--) if(ch[i][j]^'#')
	{
		s[i][j]=s[i][j+1]+s[i+1][j]+ch[i][j]-'0';
		p[i][j]=max(max(p[i][j+1],p[i+1][j]),i);
		mn[t][j][i]=j;
		for(int k=i+1;k<=p[i+1][j];k++) mn[t][j][k]=mn[t^1][j][k];
		for(int k=max(p[i+1][j],i)+1;k<=p[i][j+1];k++) mn[t][j][k]=mn[t][j+1][k];
		mx[t][j][i]=j;
		for(int k=i;k<=p[i][j+1];k++) mx[t][j][k]=mx[t][j+1][k];
		for(int k=max(p[i][j+1],i)+1;k<=p[i+1][j];k++) mx[t][j][k]=mx[t^1][j][k];
		int l=i+1,r=min(p[i][j+1],p[i+1][j]);
		while(l<=r)
		{
			if(mx[t^1][j][l]>=mn[t][j+1][l]) s[i][j]-=s[l][mn[t][j+1][l]],l=p[l][mn[t][j+1][l]];
			l++;
		}
		ans+=1ll*(ch[i][j]-'0')*(s[i][j]-(ch[i][j]-'0'));
	}
	write(ans,'\n');
	return ot(),0;
}
//Author: disangan233

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

vector<char> hands = {'r', 's', 'p'};

bool isWin(char h1, char h2){
  if(h1 == 'r' && h2 == 's') return true;
  else if(h1 == 's' && h2 == 'p') return true;
  else if(h1 == 'p' && h2 == 'r') return true;
  else return false;
}

void showTable( vector<vector<int>> table ){
  int n = table.size();
  int m = table.front().size();
  rep(i,n){
    rep(j,m){
      cout << setw(4) << left << table[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}

int main(){
  int n,k; cin >> n >> k;
  vector<int> point(3); rep(i,3) cin >> point[i];
  string t; cin >> t;

  vector<vector<int>> dp(n, vector<int>(3, 0));

  int ans = 0;
  rep(i,k){
    int p = i;
    while(p < n){
      if(i == p){
        rep(j,3) if(isWin(hands[j], t[p])) dp[p][j] = point[j];
      }
      else{
        rep(j,3){
          rep(hand,3){
            if(j == hand) continue;
            else if(isWin(hands[j], t[p])) dp[p][j] = max(dp[p-k][hand]+point[j], dp[p][j]);
            else dp[p][j] = max(dp[p-k][hand], dp[p][j]);
          }
        }
      }
      p += k;
      //showTable(dp);
    }
    ans += max(dp[p-k][0], max(dp[p-k][1], dp[p-k][2]));
  }

  cout << ans << endl;
}

Measured memory_bytes: 5760