akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>

const int INF = 1001001001;
const int diri[] = {1, 0, -1, 0};
const int dirj[] = {0, 1, 0, -1};

int main(){
    int h, w;
    
    std::cin >> h >> w;
    //std::cout << h << w << std::endl;
    std::vector<std::string> s(h);
    int answer = 0;
   
    for(int i=0; i<h; i++){
        std::cin >> s[i];
    }
    
    for(int si=0; si<h; si++){
        for(int sj=0; sj<w; sj++){
            if(s[si][sj] == '#'){
                continue;
            }
            std::vector<std::vector<int>> dist(h, std::vector<int>(w, INF));
            std::queue<std::pair<int, int>> q;
            auto update = [&](int i, int j, int value){
                if(dist[i][j] != INF){
                    return;
                }
                dist[i][j] = value;
                q.push(std::pair<int, int>(i, j));
            };

            update(si, sj, 0);
            while(!q.empty()){
                int i = q.front().first;
                int j = q.front().second;
                q.pop();
                for(int dir=0; dir<4; dir++){
                    int ni = i + diri[dir];
                    int nj = j + dirj[dir];
                    if(ni<0 || nj<0 || ni>=h || nj>=w){
                        continue;
                    }
                    if(s[ni][nj]=='#'){
                        continue;
                    }
                    update(ni, nj, dist[i][j]+1);
                }
            }
            
            for(int i = 0; i<h; i++){
                for(int j=0; j<w; j++){
                    if(dist[i][j] == INF){
                        continue;
                    }
                    answer = std::max(answer, dist[i][j]);
                }
            }
            
            
        }
    }

    std::cout << answer << std::endl;
    
    

    return 0;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a.at(i);
    
    int ans=0;
    int now=-1;
    int cnt=0;
    rep(i,0,n){
        if(now==a.at(i)) cnt++;
        else{
            ans+=cnt/2;
            now=a.at(i);
            cnt=1;
        }
    }
    ans+=cnt/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
  int unused __attribute__((unused));
  int i, flag = 0;
  int cnt[26] = {0};
  char w[100];

  unused = scanf("%s", w);
  for(i=0; i<strlen(w); i++) cnt[w[i]-97]++;
  for(i=0; i<26; i++){
    if(cnt[i]%2==1) flag = 1;
  }
  if(flag==0) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(200000) #追加
S = [-1]*(101010)
def opt_S(h,n):
    if(n == 0):return 0
    elif(n == 1):return abs(h[1]-h[0])
    else :
        if(S[n] != -1):return S[n]
        s1 = opt_S(h,n-1) + abs(h[n-1]-h[n])
        s2 = opt_S(h,n-2) + abs(h[n-2]-h[n])
        S[n] = min(s1,s2)
        return S[n]



N = int(input())
h = list(map(int,input().split()))
print(opt_S(h,N-1))


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

int main(void)
{
	int n, rank;
	bool card[4][13];
	char suit;
	string suits="SHCD";

	for (int i=0; i<4; i++)
		for (int j=0; j<13; ++j) 
			card[i][j] = true;

	cin >> n;
	for (int i=0; i<n; i++){
		cin >> suit >> rank;
		card[suits.find(suit)][rank-1] = false;
	}

	for (int i=0; i<4; i++)
		for (int j=0; j<13; j++) 
			if (card[i][j] == true)
				cout << suits.at(i) << " " << j+1 << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;

int main(void)
{
    int a,b,c;
    cin >>a >>b >>c;

    printf("%d\n", max(c-(a-b), 0));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n;
     cin >>n;
     int a[n][3];
     for(int i=0;i<n;i++)
     {
         cin >>a[i][0]>>a[i][1]>>a[i][2];
     }
     int dp[n][3];

     memset(dp,0,sizeof(dp));
     dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
     for(int i=1;i<n;i++)
     {
         dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
         dp[i][1]=max(dp[i-1][2],dp[i-1][0])+a[i][1];
         dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
     }
     cout <<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
const int mod = (int)1e9 + 7;

int main()
{
    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    ll prod1 = a*c;
    ll prod2 = a*d;
    ll prod3 = b*c;
    ll prod4 = b*d;
    cout<<max(prod1, max(prod2, max(prod3, prod4)))<<endl;
}


Measured memory_bytes: 3632
<?php

list($problem_qty, $submit_num) = explode(' ', trim(fgets(STDIN)));

$correct_problem_list = [];
$penalty_counter_list = [];
$penalty_counter = 0;

for ($i = 0; $i < $submit_num; ++$i) {
    list($problem_num, $result) = explode(' ', trim(fgets(STDIN)));
    if (array_key_exists($problem_num, $correct_problem_list)) {
        continue;
    }

    if ($result === 'WA') {
        if (isset($penalty_counter_list[$problem_num])) {
            ++$penalty_counter_list[$problem_num];
        } else {
            $penalty_counter_list[$problem_num] = 1;
        }
    } elseif ($result === 'AC') {
        $correct_problem_list[$problem_num] = true;
        $penalty_counter += ($penalty_counter_list[$problem_num] ?? 0);
    }
}

echo count($correct_problem_list) . ' ' . $penalty_counter;


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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,w,h;

ll DP[100001][2] = {0};

vector<ll> X;
vector<ll> B;

ll dp(ll i, ll a){
    if(i == n)return 0;
    if(DP[i][a] != -1)return DP[i][a];
    ll a1 = min(X[i-1]-a*B[i-1],X[i]) + dp(i+1,1);
    ll a2 = min(X[i-1]-a*B[i-1],X[i]-B[i]) + dp(i+1,0);
    DP[i][a] = max(a1,a2);
    return DP[i][a];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;
    cin >> n;
    ll sx = 0;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        ll t = 1;
        b = 0;
        while(t < a){
            t *= 2;
            b++;
        }
        X.push_back(b);
        B.push_back(t != a);
        DP[c1][0] = -1;
        DP[c1][1] = -1;
        sx += X[c1];
    }
    ll ans = sx-max(dp(1,0),dp(1,1));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 8300
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:33554432")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
//typedef tuple <int, int, int> t3;

int IT_MAX = 1 << 18;
const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 1234567890123456789ll;
const db PI = acos(-1);
const db EPS = 1e-8;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)

class datax {
public:
	int n, v1, v2;
	datax() {
		n = v1 = v2 = 0;
	}
	datax(int n, int v1, int v2) : n(n), v1(v1), v2(v2) {}
	datax operator + (const datax &l) const {
		datax rv = datax();
		rv.n = n + l.n;
		rv.v1 = v1, rv.v2 = v2;
		if (n % 2 == 1) {
			rv.v1 = min(rv.v1, l.v2);
			rv.v2 = min(rv.v2, l.v1);
		}
		else {
			rv.v1 = min(rv.v1, l.v1);
			rv.v2 = min(rv.v2, l.v2);
		}
		return rv;
	}
};
datax indt[600000];
void update(int p, int v) {
	p += IT_MAX - 1;
	
	datax u = datax(1, v, INF);
	if (v == INF) u = datax(0, INF, INF);
	indt[p] = u;
	for (p /= 2; p; p /= 2) indt[p] = indt[2 * p] + indt[2 * p + 1];
}

set <int> Sx;
datax getv(int p1, int p2) {
	p1 += IT_MAX - 1;
	p2 += IT_MAX - 1;
	
	vector <datax> V1;
	vector <datax> V2;

	for (; p1 <= p2; p1 /= 2, p2 /= 2) {
		if (p1 % 2 == 1) V1.push_back(indt[p1++]);
		if (p2 % 2 == 0) V2.push_back(indt[p2--]);
	}
	reverse(all(V2));

	datax rv = datax(0, INF, INF);
	for (auto it : V1) rv = rv + it;
	for (auto it : V2) rv = rv + it;
	return rv;
}

int in[200050];
int pos[200050];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &in[i]);
		pos[in[i]] = i;
	}

	for (IT_MAX = 2; IT_MAX < N; IT_MAX *= 2);
	for (i = 1; i < 2 * IT_MAX; i++) indt[i] = datax(0, INF, INF);
	for (i = 1; i <= N; i++) update(i, in[i]);

	Sx.insert(N + 1);
	for (i = 1; i <= N / 2; i++) {
		datax u = indt[1];
		printf("%d ", u.v1);
		int p = pos[u.v1];
		update(p, INF);
		Sx.insert(p);

		auto it = Sx.lower_bound(p + 1);

		u = getv(p + 1, *it - 1);
		printf("%d ", u.v1);
		p = pos[u.v1];
		update(p, INF);
		Sx.insert(p);
	}
	return !printf("\n");
}

Measured memory_bytes: 19712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}


struct Fenwick {
	vector<ll> fenv;

	Fenwick() : fenv() {}
	Fenwick(int n) : fenv(vector<ll>(n, 0)) {}

	void fadd(int p, ll x) {
		for(; p < (int)fenv.size(); p |= p + 1)
			fenv[p] = add(fenv[p], x);
	}
	int get(int r) {
		int res = 0;
		for(; r >= 0; r = (r & (r + 1)) - 1)
			res = add(res, fenv[r]);
		return res;
	}
	int getSum(int l, int r) {
		if (l >= r) return 0;
		return sub(get(r - 1), get(l - 1));
	}
};

const int N = 200200;
int n, k;
ll pw[N], rpw[N];
pii ord[N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &k);
	pw[0] = 1;
	pw[1] = sub(1, rev(k));
	for (int i = 2; i < N; i++)
		pw[i] = mult(pw[i - 1], pw[1]);
	rpw[1] = rev(pw[1]);
	for (int i = 2; i < N; i++)
		rpw[i] = mult(rpw[i - 1], rpw[1]);

	Fenwick F1 = Fenwick(n), F2 = Fenwick(n), F3 = Fenwick(n);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		ord[i] = mp(x, i);
	}
	sort(ord, ord + n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x = ord[i].second;
		ll sumL = F1.getSum(0, x), sumR = F1.getSum(x + 1, n);
		ll sumRevL = F2.getSum(0, x), sumRevR = F2.getSum(x + 1, n);
		ll cntL = F3.getSum(0, x), cntR = F3.getSum(x + 1, n);
		ans = add(ans, mult(rev(2), mult(sumRevL, pw[max(k - 1, x)])));
		ans = add(ans, cntR);
		ans = sub(ans, mult(rev(2), mult(sumR, rpw[max(k - 1, x)])));
		F1.fadd(x, pw[max(k - 1, x)]);
		F2.fadd(x, rpw[max(k - 1, x)]);
		F3.fadd(x, 1);
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 12408
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    if(S.equals("Sunny")){
      System.out.println("Cloudy");
    }
    else if(S.equals("Cloudy")){
      System.out.println("Rainy");
    }
    else{
      System.out.println("Sunny");
    }
  }
}


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

int main() {
    int t,n,m;
    double opt = 0.0;

    cin>>t;
    while(t--) {
        cin>>n>>m;
        double p = 0.0,e = 0.0,v,r;
        for(int i=0; i<m; ++i) {
            cin>>v>>r;
            e += v*r;
            p += r;
        }

        double np = 1.0-p;
        e = e*(1/(1-np));
        opt = max(opt, e);
    }

    cin>>n>>m;
    double p=0.0,e=0.0,v,r;
    for(int i=0; i<m; ++i) {
        cin>>v>>r;
        e += v*r;
        p += r;
    }

    e = e*(1/p);
    if(opt > e+0.0000001) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << ": " << var << "\n"
#define all(n) begin(n), end(n)
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;
using namespace std;

int main(){

 map<char, int> chars;//charはint番目の文字
 rep(i, 26){
   chars.insert(make_pair((char)('A' + i), i));
 }

 int N; cin >> N; string S; cin >> S;
 rep(i, S.size()){
   S[i] = (char)('A' + (chars[S[i]] + N) % 26);
 }

 cout << S;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	string s;
	cin >> s;

	int res = 0;
	for (ll i = s.length() - 2; i >= 0; i--)
	{
		ll j = i / 2;
		if (i % 2 == 0 && s.substr(0, j) == s.substr(j, i - j))
		{
			res = i;
			break;
		}
	}

	println(res);
}

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

using namespace std;


typedef pair<int, int> P;

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

    vector<int> a, b;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (i % 2 == 0) a.emplace_back(x);
        else b.emplace_back(x);
    }

    map<int, int> mp_a, mp_b;
    for (int i = 0; i < n / 2; ++i) {
        mp_a[a[i]]++;
        mp_b[b[i]]++;
    }

    vector<P> cnt_a, cnt_b;
    for (auto m : mp_a) cnt_a.emplace_back(P(m.second, m.first));
    for (auto m : mp_b) cnt_b.emplace_back(P(m.second, m.first));
    sort(cnt_a.begin(), cnt_a.end());
    reverse(cnt_a.begin(), cnt_a.end());
    sort(cnt_b.begin(), cnt_b.end());
    reverse(cnt_b.begin(), cnt_b.end());

    if (cnt_a[0].second != cnt_b[0].second) cout << n - cnt_a[0].first - cnt_b[0].first << endl;
    else {
        int ret1 = cnt_a[0].first;
        if (cnt_b.size() > 1) ret1 += cnt_b[1].first;

        int ret2 = cnt_b[0].first;
        if (cnt_a.size() > 1) ret2 += cnt_a[1].first;
        cout << n - max(ret1, ret2) << endl;
    }

}

Measured memory_bytes: 6520
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);


int main()
{
    string s;
    cin >> s;

    vector<string> days = { "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" };

    int i = 0;
    for (;; ++i)
    {
        if (days[i] == s) break;
    }
    cout << (i + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque

S = input()
N = len(S) // 2
S = S[:N]
s1 = deque(S); s2 = deque(S)
ans = 2*N
for i in range(N-1):
  ans -= 2
  s = s1.pop()
  s2.appendleft(s)
  s2.pop(); s2.pop()
  if s1 == s2:
    print(ans)
    quit()

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
 
 
int main(void){
 
  int n;
  double x[4], y[4];
  double ab[2], cd[2];
 
   
  scanf("%d", &n);
  while(n>0){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]);
 
    ab[0]=x[1]-x[0];
    ab[1]=y[1]-y[0];
 
    cd[0]=x[3]-x[2];
    cd[1]=y[3]-y[2];
 
 
    if(fabs(ab[0]*cd[1]-ab[1]*cd[0])<1e-10){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
     
 
    n--;
  }
 
  return(0);
}


Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int main()
{
    int m,n,i;
    cin>>m>>n;
    if(m>n){
    for(i=0;i<m;i++){
       cout<<n;
    }}
    else{
        for(i=0;i<n;i++){
       cout<<m;
    }}
    return 0;
}


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

using namespace std;
#define ll long long

bool compare(const pair<ll, bool> &i, const pair<ll, bool> &j) {
    return i.first > j.first;
}

void solve() {
    ll n, B, a, b, count = 0, sum = 0;
    cin >> n >> B;
    vector<pair<ll, bool> > vc;
    for (ll i = 1; i <= n; i++) {
        cin >> a >> b;
        vc.push_back({b, true});
        vc.push_back({a, false});
    }
    sort(vc.begin(), vc.end(), compare);
    for (ll i = 0; i < vc.size(); i++) {
        if (sum >= B)break;
        if (vc[i].second == true) {
            sum += vc[i].first;
            count++;
        }
        else {
            ll left = B - sum;// 276=46
            if (left % vc[i].first == 0)count += ((left / vc[i].first));
            else count += (left / vc[i].first) + 1;
            break;
        }
    }
    cout << count << endl;
}

int32_t main() {
    ll t = 1;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
  ll n,k,i,a[200010];
  map<int,vector<int>> m;
  cin >> n >> k;
  for (i=1;i<=n;i++){
    cin >> a[i];
    a[i]=(a[i]+k-1)%k;
  }
  for (i=2;i<=n;i++) a[i]=(a[i]+a[i-1])%k;
  for (i=0;i<=n;i++) m[a[i]].push_back(i);
  
  ll ans=0;
  map<int,vector<int>>::iterator ite;
  for (ite=m.begin();ite!=m.end();ite++){
    int l,r=0;
    vector<int> v=ite->second;
    for (l=0;l<v.size();l++){
      while (r<v.size() && v[r]-v[l]<k) r++;
      ans+=max(0,r-l-1);
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

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

  ll n, p;

  while (cin >> n >> p) {
    map<ll, ll> cnt;
    for (ll i = 2; i * i <= p; i++) {
      while (p % i == 0) {
        p /= i;
        cnt[i]++;
      }
    }
    if (p > 1) {
      cnt[p]++;
    }

    ll ans = 1;

    foreach(itr, cnt) {
      ll x = itr->first;
      ll y = itr->second;
      ll div = y / n;
      while (div-- > 0) {
        ans *= x;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int p[100],m[100][100];
void M(int n){
  int i,j,k,l,a;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l - 1;
      m[i][j] = 100000;
      for(k=i;k<j;k++){
        a = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
        if(m[i][j]>a) m[i][j]=a;
      }
    }
  }
}

int main(){
  int n,i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  M(n);
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main()
{
    string S;
    cin >> S;
    if(S.at(0)==S.at(1) && S.at(2)==S.at(3) && S.at(0)!=S.at(2)) cout << "Yes" <<endl;
    else if(S.at(0)==S.at(2) && S.at(1)==S.at(3) && S.at(0)!=S.at(1)) cout << "Yes" <<endl;
    else if(S.at(0)==S.at(3) && S.at(1)==S.at(2)&& S.at(0)!=S.at(1)) cout << "Yes" << endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String O = sc.next();
    String E = sc.next();
    if(O.length() == E.length()) {
      for(int i = 0; i < O.length(); i++ ){
        System.out.print(O.charAt(i));
        System.out.print(E.charAt(i));
      }
    }else {
      for(int i = 0; i < E.length(); i++ ){
        System.out.print(O.charAt(i));
        System.out.print(E.charAt(i));
      }
      System.out.print(O.charAt(E.length()));
    }
    System.out.println();
  }
}


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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, a, b, c;
   cin >> n >> a >> b >> c;
   vector<int> d(n);
   for (int i = 0; i < n; i++) {
      cin >> d[i];
   }
   sort(d.begin(), d.end(), greater<int>());
   int calo = c, cost = a; // 総カロリー、総コスト
   int Max = 0;
   for (int i = 0; i < n; i++) {
      Max = max(Max, calo / cost);
      calo += d[i];
      cost += b;
   }
   printf("%d\n", Max);

   return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int h_cnt = 0;
    int w_cnt = 0;
    int n = s.size();
    bool flg[4] = {false, false, false, false};
    rep(i, n) {
        if (s[i] == 'N') flg[0] = true;
        if (s[i] == 'E') flg[1] = true;
        if (s[i] == 'W') flg[2] = true; 
        if (s[i] == 'S') flg[3] = true;
    }
    if (!(flg[0] ^ flg[3]) && !(flg[1] ^ flg[2])) cout << "Yes" << endl;
    else                                          cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3620
n, m = map(int,input().split())
l = list(map(int,input().split()))

dp = [0 for i in range(n)]

for i in range(1,n):
    if i <= m-1:
        dp[i] = abs(l[0]-l[i])
    
    else:
        mini = 10**9
        for j in range(1,m+1):
            mini = min(mini, abs(l[i]-l[i-j])+dp[i-j])
        
        dp[i] = mini

print(dp[-1])

Measured memory_bytes: 56544
N = int(input())
dp = [[0] * 3 for _ in range(N+1)]
A = [list(map(int,input().split())) for _ in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + A[i][k])
print(max(dp[N]))


Measured memory_bytes: 50336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int INF=55;
ll dp [INF] [INF * INF]; // int prevent explosion
int main()
{
    int n,a;
    cin>>n>>a;
    int x;
    dp[0][0]=1;
    for(int i=1; i<=n; i++){
        cin>>x;
        for(int j=i-1; j>=0; j--){
            for(int k=0; k<=INF*j; k++){   
                dp[j+1][k+x]+=dp[j][k];
            }
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        ans+=dp[i][i*a];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout <<endl;
  
  for (int i = 0; i < H; i++) {
    vector<char> a(W); 
    for (int j = 0; j < W; j++) {
      cin >> a.at(j);
    }
    cout << '#';
    for (int k = 0; k < W; k++) {
      cout << a.at(k);
    }
    cout << '#' << endl;
  }
  
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
        t: chars,
        q: usize,
        v: [[usize; 4]; q]
    }
    let mut sc: Vec<usize> = s.iter().map(|c| if *c == 'A' {1} else {2}).scan(0,|ac,x| {*ac += x; Some(*ac)}).collect();
    sc.insert(0,0);
    let mut tc: Vec<usize> = t.iter().map(|c| if *c == 'A' {1} else {2}).scan(0,|ac,x| {*ac += x; Some(*ac)}).collect();
    tc.insert(0,0);
    for i in 0..q {
        if (sc[v[i][1]] - sc[v[i][0]-1]) % 3 == (tc[v[i][3]] - tc[v[i][2]-1]) % 3 {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Measured memory_bytes: 14844
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    string S;
    cin >> S;
    vector<string> T = {"dream", "dreamer", "erase", "eraser"};
    reverse(S.begin(), S.end());
    bool s_is_t=true;
    for (int i = 0; i < S.size();)
    {
        bool dividable = false;
        for (string t : T)
        {
            reverse(t.begin(),t.end());
            if (S.substr(i, t.size()) == t)
            {
                i += t.size();
                dividable = true;
            }
        }
        if (!dividable)
        {
            s_is_t=false;
            break;
        }
    }
    if(s_is_t)
    cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3740
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int sum=0;
		int [] w=new int [n];
		for(int i=0;i<n;i++)
		{
			w[i]=in.nextInt();
			sum=sum+w[i];
		}
		int min=10000000;
		int leftsum=0;
		for(int i=n-1;i>=0;i--)
		{
			sum=sum-w[i];
			leftsum=leftsum+w[i];
			int diff=Math.abs(sum-leftsum);
			if(min>diff)
				min=diff;
		}
		System.out.println(min);
	}
}
	

Measured memory_bytes: 23764
#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;
 
int main() {
	cin.sync_with_stdio(false);
	string s;
	ll K;
	cin >> s >> K;
	int l = s.size();
	rep(i, s.size()) {
		if ((s[i] - 'a') + K > 'z' - 'a' &&s[i]!='a') {
			K -= ('z' - s[i]) + 1;
			s[i] = 'a';
		}
	}
	K %= 26;
	while (K > 0) {
		s[l - 1]++;
		if (s[l - 1]-'a' > 'z'-'a')s[l - 1] = 'a';
		K--;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 592
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;


int main() {
	scanf("%lld", &N);
	ll sum = 0;
	for(int i = 1; i <= N; i++) {
		if(i % 3 == 0 || i % 5 == 0);
		else {
			sum += i; 
		}
	}		
	printf("%lld\n", sum);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3824
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())
MOD = 1000000007

next = [0,0,0]
ans = 1

for ai in a:
    cnt = next.count(ai)
    if cnt == 0:
        ans = 0
        break
    else:
        idx = next.index(ai)
        next[idx] += 1
        ans *= cnt
        ans %= MOD

print(ans)

Measured memory_bytes: 14396
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;
void solve(void)
{
    string s, t;
    cin >> s >> t;
    int len = s.length();
    string ans = "No";
    rep(i, len)
    {
        int cta = 0;
        rep(j, len)
        {
            if (s[j] == t[(j + i) % len])
                cta++;
        }
        if (cta == len)
            ans = "Yes";
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;

	vector<char> v;
	rep(i, s.size()){
		if(s[i] == 'B'){
			if(!v.empty()) v.pop_back();
		} else {
			v.emplace_back(s[i]);
		}
	}

	rep(i, v.size()){
		cout << v[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    if (A > B) swap(A, B);
    int K = (B - A) / 2 + A;
    if (K - A == B - K) cout << K << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  cout<<n*m-(x*m+y*n-x*y)<<endl;
  return 0;
}

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

using namespace std;

int n;
string s;

bool check(int x)
{
	if(s[x] != '.') return false;
	
	bool flag = false;
	for(int i = x+1; i < n; i++){
		if(s[i] == '.') return true;
		if(s[i] == 'B'){
			flag = true;
			break;
		}
	}
	bool flag2 = false;
	for(int i = x-1; i >= 0; i--){
		if(s[i] == '.') return true;
		if(s[i] == 'B'){
			flag2 = true;
			break;
		}
	}
	if(flag && flag2) return false;
	return true;
}

int calc(int x)
{
	s[x] = 'W';
	int ret = 0, cnt = 0; bool flag = false;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'W'){
			if(flag){
				ret = max(ret, cnt);
			}
			flag = true;
			cnt = 0;
		}
		if(s[i] == '.') flag = false;
		if(s[i] == 'B'){
			if(flag) cnt++;
		}
	}
	s[x] = '.';
	return ret;
}

int main(void)
{
	cin >> n >> s;
	
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(check(i)) ans = max(ans, calc(i));
	}
	cout << ans << endl;
	
	return 0;
}


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

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<int> y(n);
    rep(i, n) y[i]=abs(v[i]-x);

    int g=y[0];

    rep(i, n-1){
        int a=g;
        int b=y[i+1];
        if(y[i+1]>g){
            int t=a;
            a=b;
            b=t;
        }

        int r=a%b;
        while(r!=0){
            a=b;
            b=r;
            r=a%b;
        }
        g=b;
    }

    cout<<g<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long m,n,a,b,c;
	cin>>m>>n;
	if(n%1000!=0) cout<<"-1 -1 -1"<<endl;
	else
	{
		for(int i=0;10000*i<=n;i++)
		{
			for(int j=0;10000*i+5000*j<=n;j++)
			{
				if((m-i-j)*1000+i*10000+j*5000==n)
				{
					cout<<i<<" "<<j<<" "<<m-i-j<<endl;
					return 0;
				}
			}
		}
		cout<<"-1 -1 -1"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int N, X;

long long int PAL(long long int a, long long int b) {

	//cout << a << " " <<b << endl;
	if (a < b) { return PAL(b, a); }

	if (a%b == 0) {
		return b*(2 * (a / b) - 1);
	}
	
	return 	b * 2 * (a / b) + PAL(b, a%b);

}

int main(void) {

	cin >> N >> X;


	cout << N+PAL(X, N-X) << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
long long M;
vector<int> A;
vector<long long> S;

bool C(int x) {
    long long cnt = 0;
    for(int i=0; i<N; ++i) {
        cnt += end(A) - lower_bound(begin(A), end(A), x - A[i]);
    }
    return cnt >= M;
}

int main() {
    cin >> N >> M;
    A.resize(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    sort(begin(A), end(A));

    S.resize(N + 1, 0);
    for(int i=0; i<N; ++i) S[i + 1] = S[i] + A[i];

    int l = 0, r = 210000;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(C(m)) l = m;
        else r = m;
    }
    long long X = l;

    long long res = 0;
    long long cnt = 0;
    for(int i=0; i<N; ++i) {
        int k = upper_bound(begin(A), end(A), X - A[i]) - begin(A);
        cnt += N - k;
        res += S[N] - S[k] + 1LL * (N - k) * A[i];
    }
    res += X * (M - cnt);
    cout << res << endl;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
	int a[5],j=0;
	for(int i=0;i<5;i++){
		cin>>a[i];
		if(a[i]==0){
			j=i;
			break;
		}
	}
	cout<<j+1<<endl;
	return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		long sum = 0;
		int K = Integer.valueOf(s);
		
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(gcd(i, j), k);
				}
			}
		}
		System.out.println(sum);
	}

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

}


Measured memory_bytes: 35784
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

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

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

    int temp = k;
    int ans = 1;
    while(temp < n){
        temp += (k-1);
        ans++;
    }

    cout << ans;


    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int c = 1;
    while(b/c > 0){
        c *= 10;
    }
    int x = a*c + b;
    int r = 1;
    bool frag = true;
    while (r*r <= x) {
        if (x == r*r){
            cout << "Yes" << endl;
            frag = false;
        }
        r++;
    }
    if (frag) {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.List

main = C.interact $ C.pack . show . sol . get

get = map (unfoldr (C.readInt . C.dropWhile (<'0'))) . C.lines

sol ([n]:is) = (+1) $ (-) <$> (f . sort . map last) <*> (f . sort . map head) $ is
  where
  f | odd n     = (!!h)
    | otherwise = (+) <$> (!!h) <*> (!!(h-1))
  h = n `div` 2

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

int main(){
    int n;
    cin >> n;
    int a = n / 111;
    if(n%111 != 0){
        cout << a+1 << a+1 << a+1 << endl;
    }
    else if(n%111 == 0){
        cout << a << a << a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;
  std::cin >> n >> k;
  std::vector<ll> a(n), f(n);
  vvl p = vv(n, 2, 0, ll);
  ll o = 0;
  for(int i=0;i<n;i++) {
    std::cin >> a[i];
    o+=a[i];
  }
  if(o<=k){
    std::cout << 0 << '\n';
    return 0;
  }
  for(int i=0;i<n;i++) std::cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.begin(), f.end());
  ll l = 0, r = 1000000000000000;
  while(r-l>1){
    ll mid = (r+l)/2, c = 0;
    for(int i=0;i<n;i++){
      ll t = mid/f[n-1-i];
      if(a[i] - t>0) c += a[i] - t;
    }
    if(c>k) l = mid;
    else r = mid;
  }
  std::cout << r << '\n';
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int l,r,d;
  cin >> l >> r >> d;
  int cnt = 0;
  FOR(i,l,r+1) if(i%d==0) cnt++;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3636
using System;
class Program
{

    static void Main()
    {
        string[] In1 = Console.ReadLine().Split(' ');
        int n = int.Parse(In1[0]);
        int m = int.Parse(In1[1]);
        int[] H = new int[n];//height
        int[] M = new int[n];//max of near here//自身以外
        string[] In2 = Console.ReadLine().Split(' ');
        for (int i=0; i<n; i++)
        {
            H[i] = int.Parse(In2[i]);
            M[i] = 0;
        }
        string[] In3;
        int a, b;
        for(int i=0; i<m; i++)
        {
            In3 = Console.ReadLine().Split(' ');
            a = int.Parse(In3[0])-1;
            b = int.Parse(In3[1])-1;
            if (M[a] <= H[b]) M[a] = H[b];
            if (M[b] <= H[a]) M[b] = H[a];
        }
        int cnt = 0;
        for(int i=0; i<n; i++)
        {
            if (H[i] > M[i])
            {
                //Console.WriteLine("top=" + H[i]);
                cnt++;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 46400
import sys
input = sys.stdin.readline
from collections import defaultdict

"""
(駅、会社)を頂点にグラフを持つ。頂点数O(M)。
そのまま辺を貼ると辺が多くなりすぎる。
(駅、会社) -> (駅、無属性) -> (駅、会社)
"""

L = 32
mask = (1 << L) - 1
N,M = map(int,input().split())
graph = defaultdict(list)
for _ in range(M):
    p,q,c = map(int,input().split())
    p <<= L
    q <<= L
    graph[p].append(p+c)
    graph[p+c].append(p)
    graph[q].append(q+c)
    graph[q+c].append(q)
    graph[p+c].append(q+c)
    graph[q+c].append(p+c)

INF = 10 ** 9
dist = defaultdict(lambda: INF)

start = 1 << L
goal = N << L

q = [start] # 0 が会社に属していない状態
dist[start] = 0
d = 0
while q:
    qq = []
    while q:
        x = q.pop()
        if x & mask == 0:
            for y in graph[x]:
                if dist[y] <= d + 1:
                    continue
                dist[y] = d + 1
                qq.append(y)
        else:
            for y in graph[x]:
                if dist[y] <= d:
                    continue
                dist[y] = d
                q.append(y)
    d += 1
    q = qq

answer = dist[goal]
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 166516
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, s;
  cin >> k >> s;
  int cnt=0;
  for (int x = 0; x <= k; ++x) {
    for (int y = x; y <= k; ++y) {
      if (x+y>s) break;
      int z = s-x-y;
      if (z>k) continue;
      if (x==y) cnt+=1;
      else cnt+=2;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    H-=h; W-=w;
    int ans= H*W;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {

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

    // freopen("data.in","r",stdin);

    string s; cin >> s;

    for(int i = s.size()-1; i >= 0; i--) {
        if(s[i] == ',') {
            s[i] = ' ';
        }
    }

    cout << s << '\n';

    return 0;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n; cin >> n;

  if (n % 2) {
    cout << 0 << endl;
    return 0;
  }

  int cnt = 0;
  ll tmp = n;

  while (tmp) {
    ++cnt;
    tmp /= 5;
  }

  ll c[30] = {};
  ll ans = 0;

  rep3(i, cnt, 1) {
    ll v = 2;
    rep(j, i) v *= 5LL;

    c[i+1] += c[i+2];
    c[i] = (n / v) - c[i+1];
    ans += i * c[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 3632
N,Q = map(int,input().split())
S = input()

lr = [list(map(int,input().split())) for _ in range(Q)]

#print(N,Q,S)
#print(lr)

#print(S[0:5])

CC=[0]
for _ in range(1,N):
    if (S[_-1:_+1] == 'AC'):
        CC.append(CC[_-1]+1)
    else:
        CC.append(CC[_-1])

    #CC.append(S[0:_].count('AC'))

#print(CC)

for _ in range(Q):
    l = lr[_][0]
    r = lr[_][1]

    print(CC[r-1]-CC[l-1])

#for _ in range(Q):
#    l = lr[_][0]
#    r = lr[_][1]
    #print(_,S[0:r],S[0:(l-1)])
    #print(S[0:r].count('AC')-S[0:l].count('AC'))
    #print(_,S[l-1:r])
#    print(S[l-1:r].count('AC'))


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

int main() {
  int N;
  cin >> N;
  
  int size = 0;
  for (int i = 0; i < N; i++) {
    char s, g;
    cin >> s;
    
    if (g != s || i == 0) {
      g = s;
      size++;
    }
  }
  
  cout << size << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        Map<String, Integer> s = new HashMap<>();
        for(int i=0; i<n; i++) {
            String str = sc.nextLine();
            if(s.containsKey(str)) {
                s.put(str, s.get(str)+1);
            } else {
                s.put(str, 1);
            }
        }

        int m = sc.nextInt();
        sc.nextLine();
        Map<String, Integer> t = new HashMap<>();
        for(int i=0; i<m; i++) {
            String str = sc.nextLine();
            if(t.containsKey(str)) {
                t.put(str, t.get(str)+1);
            } else {
                t.put(str, 1);
            }
        }
        sc.close();

        int count = 0;
        int currentCount = 0;
        for(String str: s.keySet()) {
            if(t.containsKey(str)) {
                count = s.get(str) - t.get(str);
            } else {
                count = s.get(str);
            }
            if(currentCount < count) {
                currentCount = count;
            }
        }
        System.out.println(currentCount);
    }
}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n,k,s;cin>>n>>k>>s;
	rep(i,k) cout<<s<<" ";
	if(s!=pow(10,9)) rep(i,n-k) cout<<s+1<<" ";
	else rep(i,n-k) cout<<1<<" ";
	cout<<"\n";
}

Measured memory_bytes: 1280