akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

inline int comb(int n, int k) {
    if (k > n) return 0;
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k == 2) return (n * (n - 1)) / 2;
    return (n * (n - 1) * (n - 2)) / 6;
}

inline int pot(int x, int k) {
    int result = 1;
    fori (i, 0, k) result *= x;
    return result;
}

void solve() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int size = s.size();
    ll ans = 0;
    fori (i, k, size) {
        ans += 1LL * pot(9, k) * comb(i - 1, k - 1);
    }
    int rem_k = k;
    for (int i = 0; i < size && rem_k > 0; i++) {
        int d = s[i] - '0';
        int rem_size = size - i - 1;
        fori (j, 1, d) {
            ans += 1LL * pot(9, rem_k - 1) * comb(rem_size, rem_k - 1);
        }
        if (d > 0 && i > 0) {
            ans += 1LL * pot(9, rem_k) * comb(rem_size, rem_k);
        }
        if (d > 0) {
            rem_k--;
        }
    }
    if (rem_k == 0) ans++;
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    string s; cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i + 1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define int long long
# define mo 1000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define fi first
# define se second
signed main()
{
   gok
  int n,k;
  cin>>n>>k;
  double a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  double su=0,ma=0;
  for(int i=0;i<n;i++)
  {
      if(i<k-1)
      {
          double ss = (a[i]*(a[i]+1))/2;
          ss = (ss/a[i])*1.000;
          su += ss;
      }
      else
      {
          double ss = (a[i]*(a[i]+1))/2;
          ss = (ss/a[i])*1.000;
          su += ss;
          ma = max(ma,su);
          ss = (a[i-k+1]*(a[i-k+1]+1))/2;
          ss = (ss/a[i-k+1])*1.000;
          su -= ss;
      }
  }
  cout<<fixed<<setprecision(6)<<ma;
   return 0;
}


Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(){

  int n, win, p;
  while(cin >> n >> win >> p){
    if(n == 0 && win == 0 && p == 0) break;
    double money = 0;
    int data[n];

    for(int i = 0; i < n; i++){
      cin >> data[i];
      money += data[i];
    }
    money *= (100-p);

    if(data[win-1] == 0){
      cout << "0" << endl;
    }else{
      cout <<  (int)money/ data[win-1]<< endl;
    }
  }

  return 0;
}

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

int lcs(string str1, string str2)
{
  int m = str1.size(), n = str2.size();
  int c[1001][1001];
  str1 = ' ' + str1;
  str2 = ' ' + str2;
  for (int i = 1; i <= m; i++) c[i][0] = 0;
  for (int i = 1; i <= n; i++) c[0][i] = 0;

  for (int i = 1; i <= m; i++){
    for (int j = 1; j <= n; j++){
      if (str1[i] == str2[j]) c[i][j] = c[i - 1][j - 1] + 1;
      else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
    }
  }
  return (c[m][n]);
}
int main()
{
  int q;
  cin >> q;
  while (q--){
    string str1, str2;
    cin >> str1 >> str2;
    cout << lcs(str1, str2) << endl;
  }
}

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

const long long MAX = 10000001;

long long factor[MAX] = { 0 };

void generatePrimeFactors()
{
    factor[1] = 1;

    for (long long i = 2; i < MAX; i++)
        factor[i] = i;

    for (long long i = 4; i < MAX; i += 2)
        factor[i] = 2;
    for (long long i = 3; i * i < MAX; i++) {
        if (factor[i] == i) {
            for (long long j = i * i; j < MAX; j += i) {
                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

long long calculateNoOFactors(long long n)
{
    if (n == 1)
        return 1;

    long long ans = 1;
    long long dup = factor[n];
    long long c = 1;
    long long j = n / factor[n];
    while (j != 1) {
        if (factor[j] == dup)
            c += 1;
        else {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }
        j = j / factor[j];
    }
    ans = ans * (c + 1);

    return ans;
}

int main() {
  long long n; cin >> n;
  long long ans = 0;

  generatePrimeFactors();

  for(long long i = 1; i <= n; i++) {
    ans += i * calculateNoOFactors(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 81744
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	ll n; cin >> n;
	vector<ll> x(n);
	cin >> x[0];
	ll min_R = x[0];
	ll max_profit = -1000000000;
	for (ll i=1; i<n; ++i) {
		cin >> x[i];
		min_R = min(min_R,x[i-1]); 
		max_profit = max(max_profit, x[i] - min_R);
	}
	cout << max_profit << endl;
	return 0;
}



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

int main()
{
	int n, m, l, a[100][100], b[100][100];
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
	for (int i = 0; i < m; i++) for (int j = 0; j < l; j++) cin >> b[i][j];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			long long c = 0;
			for (int k = 0; k < m; k++)
				c += a[i][k] * b[k][j];
			cout << c << (j == l - 1 ? '\n' : ' ');
		}
	}
}


Measured memory_bytes: 3132
function main(input){
  var k = parseInt(input[0].split(' ')[1]);
  var line1 = input[1].split(' ');
  var arr = Array(line1.length);
  arr[0] = 0;
  for (var i=1; i<line1.length; i++){
    var min = null;
    for (var j=0; j<k; j++){
      if (i-j-1 >= 0) {
        var newMin = Math.abs(parseInt(line1[i-j-1]) - parseInt(line1[i])) + arr[i-j-1];
        if (min == null || newMin < min) min = newMin;
      }
    }
    arr[i] = min;
  }

  console.log(arr[line1.length-1]);
}


var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


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

int main(){
    int N;
    cin >> N;
    int A[110];
    for(int i = 0; i<N; i++){
        cin >> A[i];
    }
    int min = A[0];
    int max = A[0];
    for (int i = 0; i<N; i++){
        if(A[i] > max) max = A[i];
        if(A[i] < min) min = A[i];
    }
    cout<<max-min<<endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll D, A; cin >> D >> A;
    ll X[N], H[N]; rep(i, N) cin >> X[i] >> H[i];
    pair<ll, ll> XH[N]; rep(i, N) XH[i] = make_pair(X[i], H[i]);
    sort(XH, XH+N);
    ll ans = 0;
    if(D == 0){
        rep(i, N){
            ans += H[i]/A;
            if(H[i] % A) ans++;
        }
        cout << ans << endl;
        return 0;
    }

    int dam[N];
    dam[0] = 0;
    int idx = 0;
    int pos = XH[0].first + 2*D;
    for(int i = 1; i < N; i++){
        while(XH[idx].first + 2*D < XH[i].first) idx++;
        dam[i] = idx;
    }


    ll S[N];
    if(XH[0].second % A == 0) S[0] = XH[0].second / A;
    else S[0] = XH[0].second / A + 1;
    ans = S[0];

    for(int i = 1; i < N; i++){
        ll Xi = XH[i].first;
        ll Hi = XH[i].second;

        //どれほどのダメージを食らったか
        if(dam[i] == 0) Hi -= S[i-1]*A;
        else Hi -= (S[i-1] - S[dam[i]-1])*A;

        if(Hi <= 0){
            S[i] = S[i-1];
            continue;
        }
        else{
            ll temp;
            if(Hi % A == 0) temp = Hi / A;
            else temp = Hi / A + 1;
            S[i] = S[i-1] + temp;
            ans += temp;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8832
num = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(num):
    if b[i] >= a[i]:
        cp=a[i]
        count += a[i]
        a[i]=0
        b[i] -=cp
        if b[i] >= a[i+1]:
            cp = a[i+1]
            count += cp
            a[i+1] = 0
        else:
            a[i+1] -=b[i]
            count += b[i]
    else:
        a[i] -=b[i]
        count += b[i]
print(count)

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

int main(void){
    int H,W;
    cin>>H>>W;
    int cnt[H+2][W+2];
    char boad[H][W];

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>boad[i][j];
        }
    }
    for(int i=0;i<H+2;i++){
        for(int j=0;j<W+2;j++){
            cnt[i][j]=0;
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(boad[i][j]=='#'){
                cnt[i][j]++;
                cnt[i][j+1]++;
                cnt[i][j+2]++;
                cnt[i+1][j]++;
                cnt[i+1][j+2]++;
                cnt[i+2][j]++;
                cnt[i+2][j+1]++;
                cnt[i+2][j+2]++;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(boad[i][j]=='#')
                cout<<'#';
            else
                cout<<cnt[i+1][j+1];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	string s;
	cin >> s;
	int a[11];
	REP(i, s.length())
	{
		a[i] = s[i] - '0';
	}

	int mi = INT_MAX;
	for (int i = 0; i < s.length() - 2; i++)
	{
		int  n = a[i] * 100 + a[i + 1] * 10 + a[i + 2];
		int sub = abs(753 - n);
		mi = min(mi, sub);
	}
	cout << mi << endl;
}



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

int main() {
 int N, x;
 cin >> N >> x;
 vector<int> a(N);
  
  for(int i = 0; i < N; i++) cin >> a.at(i);
   sort( a.begin(), a.end() );
  
   int ans = 0;
  

  for(int i = 0; i < N; i++){
    if( x >= a.at(i)){
     ans ++;
     x -= a.at(i);
    }
       else{
         break;
    }
  }
  
  if ( x > 0 && ans == N ) cout << ans - 1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

ps = list(map(int,input().split()))

a = 0
m = n + 1
qs = []
for i in range(n):
    if m >= ps[i]:
        a += 1
    qs.append(ps[i])
    m = min(m,ps[i])
    if ps[i] == 1:
        break

print(a)


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

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

int main()
{
	string s;
	cin >> s;
	int index = s.size() - 1;
	bool ans = true;
	while(index >= 0){
		if(index >= 4 && s.substr(index - 4, 5) == "dream"){
			index -= 5;
		}else if(index >= 4 && s.substr(index - 4, 5) == "erase"){
			index -= 5;
		}else if(index >= 6 && s.substr(index - 6, 7) == "dreamer"){
			index -= 7;
		}else if(index >= 5 && s.substr(index - 5, 6) == "eraser"){
			index -=6;
		}else{
			ans = false;
			break;
		}
	}
	YES(ans);
	return 0;
}


Measured memory_bytes: 512
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x, y = na()

g1 = {1, 3, 5, 7, 8, 10, 12}
g2 = {4, 6, 9, 11}
g3 = {2}

if (x in g1 and y in g1) or (x in g2 and y in g2) or (x in g3 and y in g3):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N;
  cin >> N;
  vector<ll> C;
  ll prev = -1;
  rep (i, N) {
    ll c;
    cin >> c;
    if (c != prev) C.push_back(c);
    prev = c;
  }
  N = C.size();

  unordered_map<ll, ll> locked_count;
  ll free = 1;
  rep (i, N) {
    ll tmp = free;
    free += locked_count[C[i]];
    free %= MOD;
    locked_count[C[i]] += tmp;
    locked_count[C[i]] %= MOD;
  }
  cout << free << "\n";
}

Measured memory_bytes: 10096
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!int;
    string[] wordList;
    bool result = true;
    foreach (i; 0..N) {
        auto W = readln.chomp;
        scope(exit) wordList ~= W;
        if (wordList is null) continue;
        if (wordList.canFind(W)) result = false;
        if (wordList.back.back != W.front) result = false;
    }
    writeln(result ? "Yes" : "No");
}



Measured memory_bytes: 256
s = list(str(input()))
a = [int(i) for i in s]
count1 = 0
count2 = 0
for t in range(0, len(a), 2):
	if a[t] == 0:
		count1 += 1
	else:
		count2 += 1
for u in range(1, len(a), 2):
	if a[u] == 1:
		count1 += 1
	else:
		count2 += 1
print(min(count1, count2))

Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <numeric>
//#include <bits/stdc++.h>

using namespace std;

typedef long long li;


struct MaxFlow {
    static const long long inf = 1LL << 60;
    struct edge {int to; long long cap; int rev;};
    int V;
    vector<vector<edge> > G;
    vector<int> used;

    MaxFlow (unsigned int _V = 1e6): V(_V), G(_V), used(_V) {}

    void add_edge(int from, int to, long long cap) {
        G[from].push_back((edge){to, cap, (int) G[to].size()});
        G[to].push_back((edge){from, 0, (int) G[from].size() - 1});
    }

    long long dfs(int v, int t, long long f) {
        if (v == t) return f;
        used[v] = 1;
        for (int i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                long long d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -=d ;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    long long max_flow(int s, int t) {
        long long flow = 0;
        for (;;) {
            fill(used.begin(), used.end(), 0);
            long long f = dfs(s, t, inf);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main() {
    li n;
    cin >> n;
    vector<li> a(n);
    li best_performance = 0;
    for (int k = 0; k < n; ++k) {
        cin >> a[k];
        if (a[k] > 0) {
            best_performance += a[k];
        }
    }

    MaxFlow mf(n + 2);
    const int source = n;
    const int sink = source + 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] > 0) {
            mf.add_edge(i, sink, a[i]);
        } else if (a[i] < 0) {
            mf.add_edge(source, i, -a[i]);
        }
        for (int j = i + 1; j < n; ++j) {
            if ((j + 1) % (i + 1) == 0) {
                mf.add_edge(i, j, 1LL << 55);
            }
        }
    }
    cout << best_performance - mf.max_flow(source, sink) << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int &i:a) cin >> i;
	reverse(a, a + n);
	for(int i = 0; i < n; i++){
		if(i) cout << ' ';
		cout << a[i];
	}
	cout << endl;
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

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

	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll sum = 0;
	rep(i, n) sum += a[i];
	sum %= mod;
	ll ans = sum * sum % mod;
	rep(i, n) ans -= a[i] * a[i] % mod;
	ans %= mod; if (ans < 0) ans += mod;
	if (ans & 1) ans += mod;
	cout << ans / 2 << '\n';
}

Measured memory_bytes: 4764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var m = cin.nextInt();
            var X = cin.nextInt();
            var Y = cin.nextInt();
            var x = cin.ArrayInt(n);
            var y = cin.ArrayInt(m);

            var xm = x.Max();
            var ym = y.Min();
            for (int z = -100; z <= 100; z++)
            {
                if((X < z && z <= Y) && (xm < z && z <= ym))
                {
                    Console.WriteLine("No War");
                    return;
                }
            }

            Console.WriteLine("War");
        }
    }

    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 int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            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 long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            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;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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

    priority_queue<ll, vector<ll>, greater<ll>> pq;


    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        pq.push(a);
    }

    int cnt = 0;

    while(!pq.empty()){
        if(pq.size() == 1){
            cnt++;
            break;
        }
        ll a, b;
        a = pq.top();
        pq.pop();
        b = pq.top();
        pq.pop();
        // cout << a << " " << b << endl;
        if(a * 2 >= b){
            cnt++;
        } else {
            cnt = 0;
        }
        pq.push(a + b);
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1400
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
total = 0
ans = 0

for i in range(n):
    for j in range(m):
        total += a[i][j]*b[j]
    total += c
    if total > 0:
        ans += 1
    total = 0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
int main(){
  int N;
  scanf("%d", &N);
  //std::map<int, int > mp;
  std::vector<int > A(N+4, 0);
  int a;
  for (int i=0; i<N-1; i++){
    scanf("%d", &a);
    a--;
    A[a]++;
  }
  for (int i=0; i<N; i++){
    printf("%d\n", A[i]);
  }
  return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
using namespace std;
int a, b;
string s;
int main() {
	int i;
	cin>>a>>b>>s;
	if(s.size()!=a+b+1) {cout<<"No"; return 0;}
	for(i=0; i<a; i++) if(s[i]<'0' || s[i]>'9') {cout<<"No"; return 0;}
	if(s[a]!='-') {cout<<"No"; return 0;}
	for(i=a+1; i<a+b+1; i++) if(s[i]<'0' || s[i]>'9') {cout<<"No"; return 0;}
	cout<<"Yes";
	return 0;
}

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

void	ft_swap(int **ab, int i, int j)
{
	int		*temp;
	temp = ab[i];
	ab[i] = ab[j];
	ab[j] = temp;
}

void	ft_qsort(int **ab, int left, int right)
{
	int		pivot = ab[(left+right)/2][0];
	int		i = left;
	int		j = right;
	while (1)
	{
		while (ab[i][0] < pivot)
			i++;
		while (pivot < ab[j][0])
			j--;
		if (i >= j) 
			break;
		ft_swap(ab, i, j);
		i++;
		j--;
	}
	if (left < i-1)
		ft_qsort(ab, left, i-1);
	if (j+1 < right)
		ft_qsort(ab, j+1, right);
}

int		main(void)
{
	int		n,m;
	scanf("%d %d", &n, &m);
	int		**ab = (int **)malloc(sizeof(int *) * n);
	for (int i = 0; i < n; i++)
		ab[i] = (int *)malloc(sizeof(int) * 2);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &ab[i][0], &ab[i][1]);
	int		left = 0;
	int		right = n - 1;
	ft_qsort(ab, left, right);
	int		count = 0;
	long	sum = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; count < m && j < ab[i][1]; j++)
		{
			sum += ab[i][0];
			count++;
		}
	}
	printf("%ld\n", sum);

}

Measured memory_bytes: 4096
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
    long long int N, K, res=0;
	vector<long long int> p;

	cin >> N >> K;

	rep(i, N){
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}

	sort(p.begin(), p.end());

	rep(i, K){
		res+=p[i];
	}

	cout << res;

 
	return 0;
}

Measured memory_bytes: 3636
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

const int MAX_V = 110;
int d[MAX_V][MAX_V];

void setCost(int d[MAX_V][MAX_V], int s, int e, int cost){
    d[s][e] = d[e][s] = cost;
}

int
main(void){  
  int n, m;  
  cin >> n >> m;
  const int V = n;
  
  FOR(i, 1, V+1){
    FOR(j, 1, V+1){
      if (i == j) d[i][j] = 0;
      else d[i][j] = MOD;
    }
  }
  
  ll a[m+1], b[m+1], c[m+1];
  FOR(i, 1, m+1){
    cin >> a[i] >> b[i] >> c[i];
    setCost(d, a[i], b[i], c[i]);
  }
  
  // Warshall Floyd
  FOR(k, 1, 1+V){
    FOR(i, 1, 1+V){
      FOR(j, 1, 1+V){
	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans=0;
  FOR(i, 1, 1+m){
    if(d[a[i]][b[i]] < c[i]) ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	double A, B, H, M; cin >> A >> B >> H >> M;	
	double h = (H / 12 + M / 720) * 2 * M_PI;
	double m = M / 60 * 2 * M_PI;

	//cout << h << " " << m << endl;
	double y1 = A * cos(h);
	double x1 = A * sin(h);
	double y2 = B * cos(m);
	double x2 = B * sin(m);
	//cout << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	cout << sqrt((y1-y2)*(y1-y2) + (x1-x2)*(x1-x2)) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,i,j,k,l,m,o,p,q,r,s,t;
    cin>>n>>i>>j;
    k=(i+j);
    if(k==0)
    {
        cout<<0<<endl;
        return 0;
    }
    m=(n/k);
    o=(m)*i;
    if(n%k!=0)
    {
        p=min(i,n%k);
        o+=p;
    }
    cout<<o<<endl;
    return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;

int main(void) {
    ll p, q; cin >> p >> q;
    ll g = __gcd(p, q); p /= g, q /= g;
    ll ret = 1;
    set<ll> primes;
    repi(i, 2, 40000) { 
        for (auto p : primes) 
            if (i % p == 0)
                goto SKIP;
        if (q % i == 0) ret *= i;
        primes.insert(i);
        while (!(q % i)) 
            q /= i; 
        SKIP:;
    }
    if (q > 1)
        ret *= q;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3280
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string N;

  std::cin >> N;

  int s = 0;

  for (const auto& c : N)
    (s += (c - '0')) %= 9;

  std::cout << (s == 0 ? "Yes" : "No") << std::endl;

  return 0;
}


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

using namespace std;

int main(){
	long long Q,H,S,D,N; cin>>Q>>H>>S>>D>>N;
	H=min(2*Q,H);
  	S=min(2*H,S);//1L
  long long d;
  if(2*S>D) d=N/2;
  long long ans=d*D+(N-d*2)*S;
  printf("%lld",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
  #define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


  int main () {
    FASTIO
    long long int n, x, y;
    cin >> n;
    if (n == 2) {
      cout << 1 << endl;
      return 0;
    }
    map<long long int, int>mp;
    for (long long int i = 2; i < sqrt(n  - 1) + 1; i++) {
      if ((n - 1) % i == 0) {
        mp[i]++;
        mp[(n - 1) / i]++;
      }
    }
    mp[n - 1]++;
    mp[n]++;
    // cout << (int)mp.size() << endl;
    for (long long int i = 2; i < sqrt(n) + 1; i++) {
      if (n % i == 0) {
        y = n / i;
        while(y % i == 0) {
          y = y / i;
        }
        if (y > 1 && (y - 1) % i == 0) {
          mp[i]++;
        }
        if (y == 1) {
          mp[i]++;
        }
      }
    }
    cout << (int)mp.size() << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 1000000007
#define ll long long
#define endl "\n"
using namespace std;

int n, m;

ll dp[1001][1001];

char mat[1001][1001];



int32_t main()
{


	cin >> n >> m;


	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
			cin >> mat[i][j];
	}



	memset(dp, 0, sizeof(dp));



	for (int i = 0; i < n; ++i) {

		if (mat[0][i] == '#')
			break;

		dp[0][i] = 1;
	}



	for (int i = 0; i < m; ++i) {

		if (mat[i][0] == '#')
			break;

		dp[i][0] = 1;
	}


	dp[0][0] = 1;


	for (int i = 1; i < n; ++i)
	{

		for (int j = 1; j < m; ++j)
		{
			if (mat[i][j] == '.')
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
		}

	}




	cout << dp[n - 1][m - 1] % M << endl;


}

Measured memory_bytes: 12408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int x[5];
    rep(i,5) cin >> x[i];
    rep(i,5){
        if(x[i] == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;

int main(void) {
  int n;
  scanf("%d", &n);
  int d = 0;
  for(int nn = n; nn != 0; nn /= 10) {
    d += nn % 10;
  }
  puts(n % d == 0 ? "Yes" : "No");
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int a, b, c;
    cin >> a >> b >> c;

    if (a==b && b==c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    string S; cin>>S;
    int ans = 0;
    int temp = 0;
    REP(i,S.size()){
        if(S[i]=='W'){
            ans += i-temp;
            temp ++;
        }
    }
    Out(ans);
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

struct Cake {
    ll beauty, delicious, popular;

    ll sum() {
        return beauty + delicious + popular;
    }
};

vector<Cake> rev(vector<Cake> ary, int n, int i) {
    if (i & 1) {
        rep(j, n) ary[j].beauty *= -1;
    }
    if ((i >> 1) & 1) {
        rep(j, n) ary[j].delicious *= -1;
    }
    if ((i >> 2) & 1) {
        rep(j, n) ary[j].popular *= -1;
    }
    return ary;
}

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

    vector<Cake> cakes(n);
    rep(i, n) cin >> cakes[i].beauty >> cakes[i].delicious >> cakes[i].popular;

    vector<ll> candidate;

    for (int i = 0; i < (1 << 3); i++) {
        vector<Cake> tmp_cakes = rev(cakes, n, i);
        sort(tmp_cakes.rbegin(), tmp_cakes.rend(), [&](Cake &c, Cake &d) {
            return c.sum() < d.sum();
        });
        ll now = accumulate(tmp_cakes.begin(), tmp_cakes.begin() + m, 0ll, [&](ll prev, Cake &c) {
            return prev + c.sum();
        });
        candidate.push_back(now);
    }
    cout << *max_element(candidate.begin(), candidate.end()) << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int maxn = 1e5 + 10;
const int INF = 1e9 + 10;
const int mod = 1e9 + 7;
using namespace std;

int n, m, T, kase = 1;
int a[maxn << 2], b[maxn];

int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i]; a[i] -= (i + 1);
    }
    sort(a, a + n);
    ll ans = 0; ll k = a[n / 2];
    for(int i = 0; i < n; i++) ans += abs(a[i] - k);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;

        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
ll dp2[404][404];
ll dp[404][404];
void solve(){
    ll n;
    cin>>n;ll c;cin>>c;
    ll a[n+1],b[n+1];
    for(int i = 1;i<=n;i++){
        cin>>a[i];
    }
    for(int i= 1;i<=n;i++){
        cin>>b[i];
    }

    for(int i =0;i<404;i++){
        for(int j = 0;j<404;j++){
            //dp2[i][j] =1;
            //dp[i][j] = 1;
        }
    }

    dp2[1][0] = 1;
    for(int i =2;i<=400;i++){
        dp2[i][0] = (dp2[i-1][0] + 1)%MOD;
    }

    for(ll pw = 1;pw<=400;pw++){
        dp2[0][pw] = 0;
        for(ll i = 1;i<=400;i++){
            ll gg = binpow(i,pw);gg%=MOD;
            if(gg<0)gg+=MOD;
            gg%=MOD;
            dp2[i][pw] = (dp2[i-1][pw] + gg)%MOD;    
        }
    }

    dp[0][0] = 1;
    for(int i= 1;i<=n;i++){
        for(ll j = 0;j<=c;j++){
            for(ll k = 0;k<=j;k++){
                ll gg = (dp2[b[i]][k]-dp2[a[i]-1][k])%MOD;
                gg%=MOD;
                if(gg<0)gg+=MOD;
                gg%=MOD;
               // cout<<i<<" "<<gg<<endl;
                ll gg2 = (dp[i-1][j-k]*gg)%MOD;
                dp[i][j] = (dp[i][j] + gg2)%MOD;
                if(dp[i][j]<0)dp[i][j]+=MOD;

            }
        }
     }

     cout<<dp[n][c]<<endl;
}






int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

Measured memory_bytes: 2816
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a * (len(C)-c)
print (ans)

Measured memory_bytes: 105572
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int n;
    std::cin >> n;
    int res = n / 2;
    if (n % 2 == 1) {
        ++res;
    }
    std::cout << res << '\n';
    return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  ll n;
  vector<ll> pt;

  cin >> n;
  REP(i, 5){
      ll t;
      cin >> t;
      pt.pb(t);
    }
    sort(pt.begin(), pt.end());

    ll ans = n / pt[0] + 4;
    if(n %pt[0] != 0)  ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair

const ll N = 100005;

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

bool check(ll x,ll y, ll n, ll m){
    return x>=0 && y>=0 && x<n && y<m;
}
int main(){
    ll n;
    cin >> n;
    ll p = n * n;
    ll P[p];
    for(int i=0;i<p;i++){
		cin >> P[i];	
	}
    ll D[n][n];
    ll vis[n][n];
    for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
	    	ll a = min(i,n-i-1);
	    	ll b = min(j,n-j-1);
	    	D[i][j]=min(a,b);
	    	vis[i][j]=1;
    	}
    }
    ll ans=0;
    for(int i=0;i<p;i++){
    	ll r = P[i];
    	ll x = (r-1)/n;
    	ll y = (r-1)%n;
    	queue<pair<ll,ll> > q;
    	q.push({x,y});
    	ans += D[x][y];
    	vis[x][y] = 0;
    	while(!q.empty()){
    		pair<ll,ll> r = q.front();
    		q.pop();
    		for(int j=0;j<4;j++){
    			ll nx = r.first+dx[j];
    			ll ny = r.second+dy[j];
    			if(check(nx,ny,n,n) && D[nx][ny] > D[r.first][r.second] + vis[r.first][r.second]){
    				q.push({nx, ny});
    				D[nx][ny] = D[r.first][r.second] + vis[r.first][r.second];
    			}
    		}	
    	}
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9344