akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = []
for i in range(n):
  x = int(input())
  a.append(x)
zi = {}
b= sorted(a)
for i in range(n):
  zi[b[i]] = i
g = 0
k = 0
for i in range(n):
  if zi[a[i]] %2 == i%2:
    continue
  elif i%2 == 1:
    g += 1
  else:
    k += 1
print(g)

Measured memory_bytes: 62808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
 
int main() {
  int N, x, count=0;
  vector<int> diameter(111);
  cin >> N;
  rep(i,N){cin >> diameter.at(i);}
  sort(diameter.begin(),diameter.end(),greater<int>());
  rep(j,N)
  {
    if(diameter.at(j)!=diameter.at(j+1)&&diameter.at(j)!=0)
    {count++;}
  }
  cout << count << endl;
}

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

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

  int n,k;
  cin >> n >> k;

  vector<int> a(n + 1,0);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;

    for (int j = 0; j < d; j++) {
      int itr;
      cin >> itr;
      a[itr]++;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if(a[i] == 0) cnt++;
  }
  cout << cnt << endl;
}

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

#define printf_s printf
#define scanf_s scanf

struct Node {
	int v;
	int i, j;
	int l, r;
};

static const int MAX = 100000;
static const int INFTY = (1 << 31) - 1;
int np;

Node T[2*MAX];

int makeSegmentTree(int l, int r) {
	int v = np++;
	int mid = (l + r) / 2;
	T[v].v = INFTY;
	T[v].i = l; T[v].j = r;
	if (l == r)return v;
	T[v].l = makeSegmentTree(l, mid);
	T[v].r = makeSegmentTree(mid + 1, r);
	return v;
}

int update(int v, int i, int x) {
	Node& node = T[v];
	if (node.i == node.j) {
		node.v = x;
		return x;
	}
	int mid = (node.i + node.j) / 2;
	if (i <= mid) {
		node.v = min(T[node.r].v, update(node.l, i, x));
	}
	else {
		node.v = min(T[node.l].v, update(node.r, i, x));
	}
	return node.v;
}

int findMin(int v, int i, int j) {
	if (i <= T[v].i && T[v].j <= j)return T[v].v;
	int minv = INFTY;
	int mid = (T[v].i + T[v].j) / 2;
	if (!(mid < i))minv = min(minv, findMin(T[v].l, i, j));
	if (mid < j)minv = min(minv, findMin(T[v].r, i, j));
	return minv;
}

int main() {
	int n, q;
	np = 0;
	scanf_s("%d %d", &n, &q);
	int root = makeSegmentTree(0, n - 1);
	int com, x, y;
	for (int i = 0; i < q; i++) {
		scanf_s("%d %d %d", &com, &x, &y);
		if (com == 0)update(root, x, y);
		else {
			int m = findMin(root, x, y);
			printf_s("%d\n", m);
		}
	}
	return 0;
}


Measured memory_bytes: 7112
#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;


const int kN = 100 * 1000;
int a[kN];

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    ++a[x];
  }
  int best = 0;
  for (int x = 0; x < kN; ++x) {
    int curr = (x == 0 ? 0 : a[x - 1]) + a[x] + (x + 1 == kN ? 0 : a[x + 1]);
    best = max(best, curr);
  }
  cout << best << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main (void) {

    int ox[4] = {-1, 0, 1, 0};
    int oy[4] = {0, 1, 0, -1};

    do {
        unsigned int data_size;
        cin >> data_size;
        if (data_size == 0) { break; }

        int xs[data_size];
        int ys[data_size];

        xs[0] = 0;
        ys[0] = 0;

        int n, d;
        unsigned int i = 1;
        while (i < data_size) {
            cin >> n >> d;

            xs[i] = xs[n] + ox[d];
            ys[i] = ys[n] + oy[d];

            i++;
        }

        int xmin=0, xmax=0, ymin=0, ymax=0;

        for (int j=0; j<data_size; j++) {
            xmin = min(xmin, xs[j]);
            xmax = max(xmax, xs[j]);
            ymin = min(ymin, ys[j]);
            ymax = max(ymax, ys[j]);
        }

        cout << abs(xmin) + xmax + 1 << ' ' << abs(ymin) + ymax + 1<< endl;

    } while (true);

    return 0;
}

Measured memory_bytes: 1164
/*
	0161:Spoot Meet
*/
#include	<iostream>
#include	<vector>
#include	<algorithm>

using namespace std;

int main(void) {
	while(1) {
		int n, m;
		
		cin >> n >> m;
		if(n == 0 && m == 0) { break; }
		
		vector<int> pointTotal(m);
		vector<int> Nums(m);
		
		for(int i = 0; i < m; i++) {
			pointTotal[i] = 0;
			Nums[i] = i+1;
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				int a;
				cin >> a;
				if(a == 1) { pointTotal[j]++; }
			}
		}
		
		for(int i = 0; i < m-1; i++) {
			for(int j = 0; j < m-1; j++) {
				if(pointTotal[j] < pointTotal[j+1]) {
					swap(pointTotal[j], pointTotal[j+1]);
					swap(Nums[j], Nums[j+1]);
				}
			}
		}
		
		for(int i = 0; i < m-1; i++) {
			cout << Nums[i] << ' ';
		}
		cout << Nums[m-1] << endl;
	}
	
	return 0;
}

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

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    long long s[A+2], t[B+2], x[Q];
    pair<long long, long long> p[Q];
    rep2(i, 1, A+1) cin >> s[i];
    rep2(i, 1, B+1) cin >> t[i];
    rep(i, Q){
        cin >> x[i];
        p[i].first = x[i];
        p[i].second = i+1;
    }
    sort(p, p + Q);
    int nums[Q+1], numt[Q+1];
    s[0] = -10000000000;
    t[0] = -10000000000;
    s[A+1] = 20000000000;
    t[B+1] = 20000000000;
    int j = 0;
    rep(i, Q){
        while(p[i].first >= s[j+1]) j++;
        nums[p[i].second] = j;
    }
    int k = 0;
    rep(i, Q){
        while(p[i].first >= t[k+1]) k++;
        numt[p[i].second] = k;
    }
    priority_queue<long long, vector<long long>, greater<long long> > que[Q+1];
    rep2(i, 1, Q+1){
        int a = nums[i];
        int b = numt[i];
        que[i].push(max(s[a+1], t[b+1]) - x[i-1]);
        que[i].push(x[i-1] - min(s[a], t[b]));
        que[i].push(s[a+1] - t[b] + min(s[a+1] - x[i-1], x[i-1] - t[b]));
        que[i].push(t[b+1] - s[a] + min(t[b+1] - x[i-1], x[i-1] - s[a]));
        cout << que[i].top() << endl;
    }
}

Measured memory_bytes: 13824
n = int(input())
a1 = list(int(i) for i in input().split())
a2 = list(int(i) for i in input().split())
ans = sum(a1)+a2[n-1]
for i in range(n):
  ans = max(ans,sum(a1[0:i+1])+sum(a2[i:n]))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, sums=0, m;

int main(){
	IOS
	cin >> n;
	int arr[n+5];
	for(int i=1;i<=n;i++){
		cin >> arr[i];
		sums+=arr[i];
	}
	cin >> m;
	while(m--){
		int a, b;
		ll temp=sums;
		cin >> a >> b;
		ll jarak=b-arr[a];
		temp+=jarak;
		cout << temp << '\n';
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
ll nc(ll x){
  return x*(x-1)/2;
}
int main()	{
  int n;
  cin>>n;
  vector<int>a(n),cnt(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  rep(i,n){
    cnt[a[i]]++;
  }
  ll sum=0;
  rep(i,n){
    sum+=nc(cnt[i]);
  }
  rep(i,n){
    ll ans=sum;
    ans-=nc(cnt[a[i]]);
    ans+=nc(cnt[a[i]]-1);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
ll xy[200005];
bool used[200005];
vector <p> g[200005];
ll xmin=LONG_MAX,ymin=LONG_MAX,n,R,C;

void dfs(ll v,ll c){
  used[v]=1;
  xy[v] = c;
  for(ll i=0;i<(ll)g[v].size();i++){
    ll nv =g[v][i].first;
    ll cc =g[v][i].second;
    if(used[nv]){
      if(xy[v]+xy[nv] != cc){
        cout<<"No"<<endl;
        exit(0);
      }
    }
    else dfs(nv,cc-c);
    }
  if(v>R) xmin = min(c,xmin);
  else ymin = min(c,ymin);
}


int main(){
  cin>>R>>C>>n;
  for(ll i=0;i<n;i++){
    ll a,r,c;
    cin>>r>>c>>a;
    g[r].push_back(p(c+R,a));
    g[c+R].push_back(p(r,a));
  }
  for(ll i=1;i<=R;i++){
    if(used[i])continue;
    xmin=1e10;ymin=1e10;
    dfs(i,0);
    if(xmin+ymin<0) {cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  return 0;
}
  


Measured memory_bytes: 16640
// fahadmd16(IIEST Shibpur)

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define ll                                      long long
#define pb                                      push_back
#define pf                                      push_front
#define eb                                      emplace_back
#define mp                                      make_pair
#define ff                                      first
#define ss                                      second
#define db                                      long double
#define pll                                     pair<ll, ll>
#define ALL(a)                                  (a).begin(),(a).end()
#define endl                                    "\n"

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define ford1(i, n) for (int i = int(n) - 1; i >= 1; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabd(i, a, b) for(int i = int(a); i >= int(b); i--)

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0)

/// ---------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
/// --------------------------------------------------------------------


const ll sz = 1e5 + 5;
const ll mod = 1e9 + 7;
const db PI = acos(-1);
const db eps = 1e-10;
const ll INF = 1e18 + 5;


typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;
typedef vector<vector<vector<ll> > > VVVL;


ll power(ll n, ll k, ll m) {
	ll ans = 1;
	while (k) {
		if (k & 1){
			ans = (ans * n) % m;
			k--;
		}
		else{
			n = (n * n) % m;
			k /= 2;
		}
	}
	return ans;
}

void solver() {
	ll n,w;cin>>n>>w;
	ll max_val=0;
	vector<array<ll,2>> a(n);forn(i,n){cin>>a[i][0]>>a[i][1];max_val+=a[i][1];}
	
	
	VL dp(max_val+1,INF);
	dp[0]=0;
	forn(j,n){
		ford1(i,max_val+1){
			if(i>=a[j][1])
				dp[i]=min(dp[i],dp[i-a[j][1]]+a[j][0]);
		}
	}
	ford1(i,max_val+1){
		if(dp[i] && dp[i]<=w){cout<<i<<endl;return;}
	}
	
	cout<<"0\n";
	
}

int main() {
	IOS;
	ll T = 1; //cin >> T;
	forn1(i, T + 1) {
		solver();
	}
	return 0;
}


Measured memory_bytes: 3996
A=input()
B=input()
A=list(A)
B=list(B)

V=""
if len(A)-len(B)==0:
    for i in range(len(A)):
        V +=A[i]+B[i]
    print(V)
else:
    for i in range(len(B)):
        V +=A[i]+B[i]
    print(V+A[len(A)-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int h,w;
    cin >> h >>w;
    vector<vector<char>> hai_a(h*2,vector<char>(w*2,'.'));
    vector<int> hai_h(h,0);
    vector<int> hai_w(w,0);
    int cnt_h =0 , cnt_w =0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> hai_a.at(i).at(j);
            if(hai_a.at(i).at(j)=='#'){
                hai_h.at(i)++;
                hai_w.at(j)++;
            }
        }   
    }
    for(int i=0;i<h;i++){
        if(hai_h.at(i)==0){
            cnt_h++;
        }
    }
    for(int j=0;j<w;j++){
        if(hai_w.at(j)==0){
            cnt_w++;
        }
    }
    for(int l=0;l<h;l++){ 
        for(int i=0;i<h;i++){
            bool k=true;
            for(int j=0;j<w;j++){
                if(hai_a.at(i).at(j)!= '.'){
                    k =false;
                }
            }
            if(k == true){
                for(int j=0;j<w;j++){
                    hai_a.at(i).at(j)=hai_a.at(i+1).at(j);
                    hai_a.at(i+1).at(j) = '.';
                }
            }
        }
    }
    for(int l=0;l<w;l++){
        for(int i=0;i<w;i++){
            bool k=true;
            for(int j=0;j<h;j++){
                if(hai_a.at(j).at(i)!= '.'){
                    k =false;
                }
            }
            if(k == true){
                for(int j=0;j<h;j++){
                    hai_a.at(j).at(i)=hai_a.at(j).at(i+1);
                    hai_a.at(j).at(i+1) = '.';
                }
            }
        }
    }
    vector<vector<char>> hai_ans(h-cnt_h,vector<char>(w-cnt_w,'.'));
    for(int i=0;i<h-cnt_h;i++){
        for(int j=0;j<w-cnt_w;j++){
            hai_ans.at(i).at(j) = hai_a.at(i).at(j);
            if(j!=w-cnt_w-1){
                cout << hai_ans.at(i).at(j);
            }else{
                cout << hai_ans.at(i).at(j) <<endl;
            }
        }
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  ll a, b;
  cin >> n >> a >> b;
  VL h(n);
  REP(i, 0, n) {
    cin >> h[i];
  }
  ll lo = 0;
  ll hi = 2e9 / b;
  while (hi - lo > 1) {
    ll mid = (hi + lo) / 2;
    // check
    VL u(n);
    REP(i, 0, n) {
      u[i] = h[i] - b * mid;
    }
    ll nc = 0;
    REP(i, 0, n) {
      if (u[i] >= 0) {
	nc += (u[i] + (a - b - 1)) / (a - b);
      }
    }
    if (nc <= mid) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << endl;
}


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

bool isPallindrome(string s)
{
	int n = s.length();
	int i = 0,j=n-1;
	while(i<j)
	{
		if(s[i]==s[j])i++,j--;
		else return false;
	}
	return true;
}

int main()
{
	string s;
	cin>>s;
	int n = s.length();
	if(isPallindrome(s)&&isPallindrome(s.substr(0,n/2))&&isPallindrome(s.substr((n+2)/2,n/2)))
	{
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>
#include <queue>
#include <functional>
#include <unordered_map>
#include <random>
#include <iomanip>

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

vector<int> dRow = { 1,0,-1, 0 };
vector<int> dCol = { 0,1, 0, -1 };
int main()
{
    int height, width;
    cin >> height >> width;
    vector<string> field(height);
    for (int row = 0; row < height; row++) cin >> field[row];
    queue<tuple<int, int, int, int>> q;
    q.push(make_tuple(0, 0, -1 ,-1));
    while (!q.empty())
    {
        bool isNext = false;
        int curRow, curCol, prevRow, prevCol;
        tie(curRow, curCol, prevRow, prevCol) = q.front(); q.pop();
        for (int dir = 0; dir < 4; dir++)
        {
            int nextRow = curRow + dRow[dir];
            int nextCol = curCol + dCol[dir];
            if (nextRow < 0 || nextRow >= height || nextCol < 0 || nextCol >= width || (nextRow == prevRow && nextCol == prevCol)) continue;
            if (dir < 2)
            {
                if (field[nextRow][nextCol] == '#')
                {
                    isNext = true;
                    q.push(make_tuple(nextRow, nextCol,curRow,curCol));
                }
            }
            else if (field[nextRow][nextCol] == '#')
            {
                cout << "Impossible" << endl;
                return 0;
            }
        }
        if (!isNext && (curRow != height - 1 || curCol != width - 1))
        {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t i,N,sum=1,sun=1,s=1,t;
  cin>>N;
  for(i=0;i<N;i++){
    sum*=10;
    sum%=1000000000+7;
  }
  for(i=0;i<N;i++){
    sun*=8;
    sun%=1000000000+7;
  } 
  for(i=0;i<N;i++){
    s*=9;
    s%=1000000000+7;
  }
  t=(sum+sun-s-s)%(1000000000+7);
  t+=1000000000+7;
  cout<<t%(1000000000+7)<<endl;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        sc.close();

        // 主処理
        char[] array = s.toCharArray();
        boolean[] isUsed = new boolean[100];
        int[] count = new int[10000];
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                int num = ((int) array[i] - 48) * 10 + ((int) array[j] - 48);
                if (isUsed[num]) {
                    continue;
                }
                isUsed[num] = true;

                int index = j + 1;
                StringBuilder sb = new StringBuilder(s);
                int[] countArray = calcCountArray(sb.substring(index).toString());

                for (int k = 0; k < 10; k++) {
                    if (countArray[k] == 1) {
                        count[num * 10 + k] = 1;
                    }
                }
            }
        }
        int sum = Arrays.stream(count).sum();
        int result = sum;

        // 出力
        System.out.println(result);
    }

    public static int[] calcCountArray(String s) {
        int[] count = new int[10];
        if (s.contains("0")) {
            count[0]++;
        }
        if (s.contains("1")) {
            count[1]++;
        }
        if (s.contains("2")) {
            count[2]++;
        }
        if (s.contains("3")) {
            count[3]++;
        }
        if (s.contains("4")) {
            count[4]++;
        }
        if (s.contains("5")) {
            count[5]++;
        }
        if (s.contains("6")) {
            count[6]++;
        }
        if (s.contains("7")) {
            count[7]++;
        }
        if (s.contains("8")) {
            count[8]++;
        }
        if (s.contains("9")) {
            count[9]++;
        }
        return count;
    }
}


Measured memory_bytes: 43536
#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>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

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) {
	if (v.size()) {
		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() {
	ll N, K; cin >> N >> K;
	vll A(N); cin >> A;
	
	ll X = 0;
	ll ans = 0;
	for (int b = 59; b >= 0; b--) {
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			cnt += (A[i]>>b)&1;
		}
		if (cnt < N-cnt && X + (1ll<<b) <= K) {
			X |= (1ll<<b);
			ans += (1ll<<b) * (N-cnt);
		} else {
			ans += (1ll<<b) * cnt;
		}
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 3956
x = gets.to_i
pows = Array.new(1000){|i| i ** 5}
pows.each_index{|b|
	u = x + pows[b]
	a = pows.find_index{|a5| a5.abs == u}
	if a != nil
		puts "#{u > 0 ? a : -a} #{b}"
		break
	end
	u = x - pows[b]
	a = pows.find_index{|a5| a5.abs == u}
	if a != nil
		puts "#{u > 0 ? a : -a} #{-b}"
		break
	end
}

Measured memory_bytes: 14376
while True:
    n,m=map(int,input().split())
    if n==m==0:
        break
    ta=[int(input()) for i in range(n)]
    ha=[int(input()) for i in range(m)]
    taro=sorted(ta)
    hana=sorted(ha)
    taha=(sum(ta)-sum(ha))/2
    kai=0
    if taha<0:
        for i in range(len(taro)):
            if taro[i]+abs(taha) in hana:
                kai=1
                print(taro[i],int(taro[i]+abs(taha)))
                break
    else:
        for i in range(len(taro)):
            if taro[i]-abs(taha) in hana:
                kai=1
                print(taro[i],int(taro[i]-abs(taha)))
                break
    if kai!=1:
        print('-1')


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

#define int long long int

const int N=104;


int32_t main()
{
     
     int n,x,a[N];
     
     cin>>n>>x;
     
     for(int i=1;i<=n;i++)
          cin>>a[i];
     
     sort(a+1,a+1+n);
     
     int ans=0;
     
     int i;
     
     for(i=1;i<=n;i++)
     {
          if(x<a[i])
               break;
          x-=a[i];
          ans++;
     }
     
     if(x>0 && i>n)
          ans--;
          
     cout<<ans;     
     
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
 
signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++)
            if(s[i]=='7')
            {
                cout<<"Yes";
                return 0;
            }
        cout<<"No";
    }
    //cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}

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

using namespace std;

int main() {

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

	vector<int> h(999, 0);
	h[0] = 1;
	for (int i = 1; i < 999; i++) {
		h[i] = h[i - 1] + i+1;
	}
	cout << h[b-a - 2] - a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main()
{
  int i, j, n, v, ct;
  int array[N];

  scanf("%d", &n);

  for( ct=0; ct<n; ct++){
    scanf("%d", &array[ct]);
  }   

  for( ct=0; ct<n-1; ct++){
    printf("%d ", array[ct]);
  }
  printf("%d\n", array[n-1]);

  for( i=1; i<=n-1; i++){
    v = array[i];

    j = i - 1;

    while( j >= 0 && array[j] > v ){
      array[j+1] = array[j];

      j--;
    }

    array[j+1] = v;

    for( ct=0; ct<n-1; ct++){
      printf("%d ", array[ct]);
    }
    printf("%d\n", array[n-1]);

  }

  return 0;
}

Measured memory_bytes: 600
import sys

def knappack(N, W, vs, ws):
    dp = [0] * (W + 1)
    for i in range(N):
        for j in range(ws[i], W + 1):
            dp[j] = max(dp[j], dp[j - ws[i]] + vs[i])
            
    return dp[-1]
    
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    Nstr, Wstr = line.split()
    N, W = int(Nstr), int(Wstr)
    vs, ws = [], []
    for i in range(N):
        line = sys.stdin.readline()
        v, w = line.split()
        v, w = int(v), int(w)
        vs.append(v)
        ws.append(w)
    sys.stdout.write(str(knappack(N, W, vs, ws)))
    sys.stdout.write('\n')
    

Measured memory_bytes: 4748
def solve():
    N = int(input())
    S = [input() for _ in range(N)]
    AB_count = 0
    # 元から含まれているABの計算
    head_B_count = 0
    tail_A_count = 0
    B_and_A_count = 0
    for si in S:
        # print(si.count('AB'))
        AB_count += si.count('AB')
        # print(list(si)[0], list(si)[-1])
        list_si = list(si)
        if list_si[0] == 'B' and list_si[-1] == 'A':
            B_and_A_count += 1
            pass
        elif list_si[0] == 'B':
            head_B_count += 1
        elif list_si[-1] == 'A':
            tail_A_count += 1
    if B_and_A_count > 0:
        AB_count += B_and_A_count - 1
        if head_B_count > 0:
            AB_count += 1
            head_B_count -= 1
        if tail_A_count > 0:
            AB_count += 1
            tail_A_count -= 1
    AB_count += min(head_B_count, tail_A_count)
    print(AB_count)


if __name__ == '__main__':
    solve()


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

int main() {
  long long n,k;
  cin>>n>>k;
  vector<long long >a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=1;i<n-k+1;i++){
    if(a[i+k-1]>a[i-1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

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

int main() {
  int n,s=1000000;
  cin>>n;
  for(int i=0; i<n; i++){
    int a,b=0;
    cin>>a;
    while(a%2==0){
      a/=2;
      b+=1;
    }
    if(s>b){
      s = b;
    }
  }
  cout<<s;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>

using namespace std;

void FLCS(std::istream& in, std::ostream& out) {
    string s, t;
    in >> s >> t;
    int n = (int) s.size();
    int m = (int) t.size();
    vector<vector<int>> dp(n + 1, vector<int> (m + 1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    string ans;
    int i = n - 1, j = m - 1;
    while (i >= 0 && j >= 0) {
        if (s[i] == t[j]) {
            ans += s[i--];
            j--;
        } else {
            if (dp[i + 1][j + 1] == dp[i + 1][j]) {
                j--;
            } else {
                i--;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    out << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    FLCS(in, out);
    return 0;
}

Measured memory_bytes: 38516
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


class CombMod:

    def __init__(self, N, MOD=10**9 + 7):

        N = N + 1
        inv = [0] * N
        fact = [0] * N
        fact_inv = [0] * N

        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD

        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD

        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD

        self.fact = fact
        self.fact_inv = fact_inv
        self.inv = inv

    def comb(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[r] % mod * self.fact_inv[n - r] % mod

    def perm(self, n, r, mod=10**9 + 7):
        return self.fact[n] * self.fact_inv[n - r] % mod


def main():

    N, M = in_nn()
    mod = 10**9 + 7
    c = CombMod(M)

    ans = 0
    for i in range(N + 1):
        t = c.comb(N, i)

        t *= (-1)**(i % 2)
        t %= mod

        t *= c.perm(M, i)
        t %= mod

        t *= c.perm(M - i, N - i)
        t %= mod

        t *= c.perm(M - i, N - i)
        t %= mod

        ans += t
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85692
import java.io.InputStream;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int max = Integer.MIN_VALUE;
    NumberQueue scanQueue = new NumberQueue(k);
    for (int i = 0; i < n; i++) {
      scanQueue.add(Integer.valueOf(sc.next()));
      if (max < scanQueue.sum()) {
        max = scanQueue.sum();
      }
    }
    pw.println(
      ((double) k * 0.5) + ((double) max * 0.5)
    );
  }

  static class NumberQueue {

    private int k;
    int sum;
    private Queue<Integer> queue;

    public NumberQueue(int k) {
      this.k = k;
      this.queue = new LinkedList<>();
    }

    private void add(Integer i) {
      if (queue.size() < k) {
        queue.add(i);
        sum += i;
        return;
      }
      sum -= queue.poll();
      sum += i;
      queue.add(i);
    }

    private int sum() {
      return sum;
    }

    double sumOfMeanValue() {
      return queue.stream()
        .mapToDouble(this::mean)
        .sum();
    }

    double mean(int i) {
      return (double) i * (1 + i) / 2 / i;
    }
  }
}


Measured memory_bytes: 68304
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

signed main()
{
    showoff;
    int a;
    string s;
    cin >> a >> s;
    if(a < 3200)cout << "red";
    else cout << s;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  pair<int,int> p[100000];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  for(int i=0;i<n;i++)
    cout<<p[i].first<<" "<<p[i].second<<endl;
  return 0;
}



Measured memory_bytes: 3884
#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 k, n, ans;
    vector<int> a(300000), dist(300000);

    cin >> k >> n;
    rep(i, n) cin >> a.at(i);
    ans = k;
    rep(i, n)
    {
        if (i == n - 1)
            dist.at(i) = k - a.at(i) + a.at(0);
        else
            dist.at(i) = a.at(i + 1) - a.at(i);
    }

    rep(i, n)
    {
        if (k - dist.at(i) < ans)
            ans = k - dist.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5432
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, a[300000];
int b[300001];//最初からここまでの和
int c[300001];//n～2nまでの最小の和
int d[300001];//n～3nまでの和
int e[300001];//n～2nまでの最大の和
signed main() {
	cin >> n;
	for (int i = 0; i < 3 * n; i++)
		cin >> a[i];
	//ここから前の部分
	b[0] = a[0];
	for (int i = 1; i < 3 * n; i++)
		b[i] = b[i - 1] + a[i];
	priority_queue<int, vector<int>, greater<int>>p;
	for (int i = 0; i < n; i++)
		p.push(a[i]);
	for (int i = n; i < 3 * n; i++) {
		p.push(a[i]);
		if (i != n)
			c[i] = c[i - 1] + p.top();
		else
			c[i] = p.top();
		p.pop();
	}
	//ここまでが前の部分
	d[3 * n - 1] = a[3 * n - 1];
	for (int i = 3 * n - 2; i >= 0; i--)
		d[i] = d[i + 1] + a[i];
	priority_queue<int>q;
	for (int i = 3 * n - 1; i >= 2 * n; i--)
		q.push(a[i]);
	for (int i = 2 * n - 1; i >= 0; i--) {
		q.push(a[i]);
		if (i != 2 * n - 1)
			e[i] = e[i + 1] + q.top();
		else
			e[i] = q.top();
		q.pop();
	}
	////////////////////////////////
	int ans = max(b[n - 1] - (d[n] - e[n]), (b[2 * n - 1] - c[2 * n - 1]) - d[2 * n]);
	for (int i = n; i < n * 2 - 1; i++) {
		ans = max(ans, (b[i] - c[i]) - (d[i + 1] - e[i + 1]));
	}
	cout << ans << endl;
	getchar(); getchar();
}

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

using namespace std;

int N, A, B;
typedef long long ll;
ll v[51];
ll com[53][53];

void init(int N) {
  for(int i = 0; i <= N; i++) {
    com[i][i] = com[i][0] = 1;
  }

  for(int i = 2; i <= N; i++) {
    for(int j = 1; j < i; j++) {
      com[i][j] = com[i-1][j-1] + com[i-1][j];
    }
  }
}

ll nCr(int n, int r) {
  return com[n][r];
}
  
int main() {
  cin >> N >> A >> B;

  init(N);

  for(int i = 0; i < N; i++)  cin >> v[i];
  
  sort(v,v+N,greater<ll>());

  int c = 0;

  
  
  ll ans = 0;
  
  for(int i = 0; i < A; i++) ans += v[i];
  
  cout <<fixed<< ans /(double)A<<endl;

 
  int k = 0; int t = 0;
  ll ans2 = 0;

  for(int i = 0; i < N; i++) {
    if(v[i] == v[A-1]) {
      k++;
      if(i < A) t++;
    }
  }

  if(t == A) {
    for(int i = A; i <= B; i++) {
      ans2 += nCr(k,i);
    }
  }
  else {
    ans2 += nCr(k,t);
  }

  cout << ans2 << endl;
}
    
  


Measured memory_bytes: 256
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = 2
x, y = map(int, input().split())
if x in g1 and y in g1:
  print("Yes")
elif x in g2 and y in g2:
  print("Yes")
elif x == g3 and y == g3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <utility>
#include <vector>
#include <array>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
	_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

template<typename T>
using V = vector<T>;
using A = array<int, 3>;

int main() {
	int M {in}, N {in}, K {in};
	V<V<array<int, 3>>> dp(M + 1, V<array<int, 3>>(N + 1));
	for (int i: range(1, M + 1)) {
		A a {};
		for (int j: range(1, N + 1)) {
			char c = gcu();
			a[c == 'J' ? 0: c == 'O' ? 1 : 2]++;
			for (int k: range(3))
				dp[i][j][k] = a[k] + dp[i - 1][j][k];
		}
		gcu();
	}
	times(i, K) {
		int a {(int)in - 1}, b {(int)in - 1}, c {in}, d {in};
		for (int j: range(3))
			out(j ? " " : "", dp[a][b][j] - dp[a][d][j] - dp[c][b][j] + dp[c][d][j]);
		outl();
	}
}


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

int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		int ans=0;
		queue<int> que;
		for(int i=0,num;i<m;i++){
			cin>>num;
			que.push(num);
			ans+=num;
		}
		for(int i=m,num,sum=ans-que.front();i<n;i++){
			que.pop();
			cin>>num;
			ans=max(ans,sum+=num);
			sum-=que.front();
			que.push(num);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1348
# -*- coding: utf-8 -*-

def small_dp(N,A,B):
    *X, = filter(lambda c: int.__sub__(*c)<0, zip(A,B))
    k = len(X)
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        if (N//X[1][0]+1)*(N//X[0][0]+1) <= 10**6 :
            return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        else:
            dp = [0]*(N+1)
            for w in range(1,N+1):
                dp[w] = max(dp[w-X[i][0]]+X[i][1] if w>=X[i][0] else w for i in range(k))
            N = dp[-1]
            return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    res = small_dp(small_dp(N, A, B), B, A)

    return str(res)

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
typedef pair<int, int> pii;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 200200;
vector<pii> g[maxn];

bool used[maxn];
int n, m, k;

ll cx[maxn];
ll val, xmin, ymin;
void dfs(int u, ll cur) {
    if (used[u]) {
        if (cur != cx[u]) {
            cout << "No\n";
            exit(0);
        }
        return;
    }
    //cerr << u << ' ' << cur << '\n';
    cx[u] = cur;
    if (u < n)
        xmin = min(xmin, cur);
    else
        ymin = min(ymin, cur);
    used[u] = true;
    for (auto p: g[u]) {
        int v = p.first;
        ll delta = p.second;
        dfs(v, delta - cur + val);
    }
}

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    cin >> n >> m >> k;
    forn (i, k) {
        int x, y, a;
        cin >> x >> y >> a;
        --x, --y;
        g[x].emplace_back(y + n, a);
        g[y + n].emplace_back(x, a);
    }
    forn (i, n) {
        if (used[i])
            continue;
        if (sz(g[i]) == 0)
            continue;
        xmin = infl, ymin = infl;
        val = g[i][0].second;
        dfs(i, val);
        if (xmin + ymin - val < 0) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
  long long n, w;
  cin >> n >> w;
  vector <long long> v(n), dp(w + 1, 0), weight(n);
  ffor(n) {
	cin >> weight[i] >> v[i];
  }
  
  ffor(n) {
    for(int j = w; j >= 0; j--) {
      if (j - weight[i] < 0) continue;
      dp[j] = max(dp[j], dp[j - weight[i]] + v[i]);
    }
  }
  long long ans = 0;
  for (auto e: dp) ans = max(ans, e);
  cout << ans << '\n';
}

Measured memory_bytes: 4060
#include<set>  
#include<map>  
#include<stack>  
#include<cstdio>  
#include<queue>  
#include<cmath>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std;
#define INF 0x3f3f3f3f
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 100
char a[4][MAXN+5];
int main(){
	scanf("%s",a[0]);
	scanf("%s",a[1]);
	scanf("%s",a[2]);
	int la[5];
	la[0]=strlen(a[0]),la[1]=strlen(a[1]),la[2]=strlen(a[2]);
	int ta[5]={0},t=0,f=0;
	while(ta[0]<=la[0]&&ta[1]<=la[1]&&ta[2]<=la[2]){
		if(ta[t]==la[t]){f=t;break;}
		t=a[t][ta[t]++]-'a';
	}
	if(f==0) printf("A\n");
	else if(f==1) printf("B\n");
	else printf("C\n");
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, x[40009], y[40009], z[40009], pp[40009], bit[40009]; long double a[40009], b[40009], aa[40009], bb[40009], p[40009];
void add(int p) {
	for (int i = p + 1; i <= N; i += i & (-i)) bit[i]++;
}
int sum(int p) {
	int ret = 0;
	for (int i = p; i >= 1; i -= i & (-i)) ret += bit[i];
	return ret;
}
int calc() {
	fill(bit, bit + N, 0);
	for (int i = 0; i < N; i++) pp[i] = i;
	sort(pp, pp + N, [](int i, int j) { return p[i] < p[j]; });
	int ret = 0;
	for (int i = 0; i < N; i++) {
		ret += sum(pp[i]);
		add(pp[i]);
	}
	return ret;
}
double solve() {
	for (int i = 0; i < N; i++) pp[i] = i, aa[i] = a[i], bb[i] = b[i];
	sort(pp, pp + N, [](int i, int j) { return a[i] < a[j]; });
	for (int i = 0; i < N; i++) a[i] = aa[pp[i]], b[i] = bb[pp[i]];
	long double l = -1.0e+12L, r = 1.0e+12L;
	for (int i = 0; i < 150; i++) {
		long double m = (l + r) * 0.5L;
		for (int j = 0; j < N; j++) p[j] = a[j] * m + b[j];
		if (calc() * 2 < N * (N - 1) / 2) l = m;
		else r = m;
	}
	return l;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> z[i];
	for (int i = 0; i < N; i++) {
		a[i] = -1.0 * x[i] / y[i];
		b[i] = 1.0 * z[i] / y[i];
	}
	long double ret1 = solve();
	for (int i = 0; i < N; i++) {
		a[i] = -1.0 * y[i] / x[i];
		b[i] = 1.0 * z[i] / x[i];
	}
	long double ret2 = solve();
	printf("%.15Lf %.15Lf\n", ret1, ret2);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll mod = 1000000007;
ll ka[5000010];

ll c(ll x, ll y, ll m) {
	if (y > x)return 0;
	return ka[x] * mod_pow(ka[x - y], mod - 2, mod) % mod*mod_pow(ka[y], mod - 2, mod) % mod;
}

ll n, m;
ll ans = 1;

signed main() {
	cin >> n >> m;
	ka[0] = 1;
	for (int i = 1; i <= m; i++)ka[i] = ka[i - 1] * i%mod;
	for (int i = m; i >= m - n + 1; i--)ans = ans * i%mod;
	ll cnt = ans;
	for (int i = 1; i <= n; i++) {
		if (i % 2)cnt = (cnt - c(n, i, mod)*ka[m - i] % mod*mod_pow(ka[m - n], mod - 2, mod) % mod + mod) % mod;
		else cnt = (cnt + c(n, i, mod)*ka[m - i] % mod*mod_pow(ka[m - n], mod - 2, mod) % mod) % mod;
	}
	cout << ans * cnt%mod << endl;
}

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

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return false;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans = n;
    for(int i=1;i<n-1;i++){
        int t = a[i];
        for(int j=1;j<=3;j++){
            if(a[i-1]!=j && a[i+1]!=j) continue;
            a[i] = j;
            for(int l=i,r=i,cnt=1;l>=0&&r<n;cnt=2,l--,r++){
                if(a[l] != a[r]) break;
                while(l>0 && a[l-1]==a[l]){
                    cnt++;
                    l--;
                }
                while(r<n-1 && a[r]==a[r+1]){
                    cnt++;
                    r++;
                }
                if(cnt>=4){
                    ans = min(ans, n-(r-l+1));
                }else{
                    break;
                }
            }
        }
        a[i] = t;
    }
    cout << ans << endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}



Measured memory_bytes: 3144