akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify

N, K = map(int, input().split())
V = list(map(int, input().split()))

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        takeR = take - takeL
        hand = []
        for i in range(takeL):
            heappush(hand, V[i])
        for i in range(takeR):
            if N - i - 1 < takeL:
                break
            heappush(hand, V[N- i - 1])
        S = max(sum(hand), S)
        for _ in range(K - take):
            if not hand or hand[0] >= 0:
                break
            heappop(hand)
            S = max(sum(hand), S)
print(S)



Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;//リストを使う
class Program
{

static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static long[] result = new long[n];//頂点0を１、隣接頂点を2と、交互に塗る。
static List<long>[] nextList = new List<long>[n];//隣接リスト
static bool twoGraph = true;//２部グラフならtrue

	 static void Main()
  {
    for(long i = 0; i < n; i++) nextList[i] = new List<long>();//リストの宣言
    for(long i = 0; i < m; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      nextList[nums[0]-1].Add(nums[1]-1);//隣接リストへ追加。
      nextList[nums[1]-1].Add(nums[0]-1);
    }
        
          result[0] = 1;
          Spread(0);//頂点0から色を広げる

         if(twoGraph) //２部グラフのとき
         {
            long whiteNum = 0;//頂点0と同じ色の頂点数
            for (long i = 0; i < n; i++)
            {
              if(result[i] == 1) whiteNum++;
            }
            Console.WriteLine(whiteNum*(n-whiteNum)-m);
         }
         else Console.WriteLine(n*(n-1)/2-m);//２部グラフでないとき
  }

   static void Spread(long vertex)//色を広げる
  {
    long color = result[vertex];//現在の頂点の色
    
  
    for(int i = 0; i < nextList[vertex].Count(); i++)
    {
      long a = (long)((List<long>)nextList[vertex])[i];
        if(result[a] == 0)
        {
          result[a] = 3 - color;//隣接頂点は別の色で塗る
          Spread(a);//色を広げる
        }
        else if(result[a] == color) twoGraph = false;//色の矛盾がある
    }
  }
}


Measured memory_bytes: 32928
s = input()
ans = []
for i in range(int(len(s))):
    if s[i] == "0":
        ans.append(0)
    elif s[i] == "1":
        ans.append(1)
    elif s[i] == "B":
        if not ans:
            continue
        del ans[int(len(ans))-1]
for i in ans:
    print(i,end="")
    


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long int
#define mi map<int,int>
#define mcr map<char,int>
using namespace std;

int main()
{
    int k, a, b, c;
    cin >> a >> b >> c >> k;
    if(k <= a){
        cout << k << endl;
    }else if(k <= a + b){
        cout << a << endl;
    }else{
        cout << a - (k - a - b) << endl;
    }
    return 0;
}


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

int main() {
    int n,k;
    cin>>n>>k;
    int p[n];
    rep(i,n)cin>>p[i];
    sort(p,p+n);
    int ans=0;
    rep(i,k)ans+=p[i];
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main() {
  int n, cnt[6] = {};
  double in; int temp;

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> in;
    in -= 165;
    if(in < 0) cnt[0]++;
    else {
      temp = in;
      cnt[temp/5+1]++;
    }
  }
  
  for(int i = 0; i < 6; i++) {
    cout << i+1 << ":";
    for(int j = 0; j < cnt[i]; j++) cout << "*";
    cout << endl;
  }
  return 0;
}

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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 1; i < N; ++i)
	{
		set<char> a,b;
		for (int j = 0; j < i; ++j)
		{
			a.insert(S[j]);
		}

		for (int j = i; j < N; ++j)
		{
			b.insert(S[j]);
		}

		int temp = 0;
		//cout << "a.size:" << a.size();
		auto it = a.begin();


		for (int j = 0; j < a.size(); ++j)
		{
			if (b.count(*it)) temp++;
			it++;
		}
		ans = max(ans,temp);
	}

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

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int &e : A) cin >> e;
  for (int i = 0; i < N-K; i++) {
    cout << (A[i] < A[i+K] ? "Yes" : "No") << endl;
  }
}

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

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    vector<int> h(n);
    int index = 1000000;
    int ans = -1;
    int dif = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h.at(i);
        dif = (t*1000 - h.at(i)*6) - a*1000;
        if (dif < 0 )
        {
            dif = -dif;
        }
        if (dif < index)
        {
            index = dif;
            ans = i + 1;
        }
    }
    cout << ans << endl;
} 

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

#define ll long long

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

}

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

constexpr int mod = 1e9 + 7;

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

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

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

    string s;
    int d;
    cin >> s >> d;
    int n = s.size();
    int dp[2][2][100] = {};

    dp[0][0][0] = 1;
    rep(i, n) rep(j, d) {
        rep(k, 10)(dp[i + 1 & 1][1][(j + k) % d] += dp[i & 1][1][j]) %= mod;
        rep(k, s[i] - '0')(dp[i + 1 & 1][1][(j + k) % d] += dp[i & 1][0][j]) %=
            mod;
        (dp[i + 1 & 1][0][(j + s[i] - '0') % d] += dp[i & 1][0][j]) %= mod;
        dp[i & 1][0][j] = dp[i & 1][1][j] = 0;
    }

    cout << (dp[n & 1][0][0] + dp[n & 1][1][0] - 1 + mod) % mod << endl;

    return 0;
}

Measured memory_bytes: 256
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
ll dp[2005][2005];
void solve()
{
  ll n;
  cin>>n;
  pii a[n];
  rep(i,0,n) cin>>a[i].F,a[i].S=i+1;
  sort(a,a+n);
  reverse(a,a+n); 
  ll k,idx;
  rep(i,0,n)
  {
    rep(j,0,n)
    {
      if(j>i) break;
      k=i-j;
      dp[j+1][k]=max(dp[j+1][k],abs(a[i].S-j-1)*a[i].F+dp[j][k]);
      idx=n-k;
      dp[j][k+1]=max(dp[j][k+1],abs(a[i].S-idx)*a[i].F+dp[j][k]);
    }
  }
  ll ans=0;
  rep(i,0,n+1) rep(j,0,n+1) ans=max(ans,dp[i][j]);
  cout<<ans;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 26436
n, m = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))

cd = []
for i in range(m):
    cd.append(list(map(int, input().split())))
# print(ab)
# print(cd)

for i in range(n):
    r = 999999999999999999
    cp = -1
    for j in range(m):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]) < r:
            r = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            cp = j
    print(cp+1)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll h,w,a,b;cin>>h>>w>>a>>b;
    for(ll i=0;i<h;i++){
        if(i<b){
            for(ll j=0;j<w;j++){
                if(j<a){
                    cout<<'1';
                }else{
                    cout<<'0';
                }
            }
        }else{
            for(ll j=0;j<w;j++){
                if(j<a){
                    cout<<'0';
                }else{
                    cout<<'1';
                }
            }
        }
        cout<<endl;
    }
    
    return 0;
}



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


# nを素因数分解したリストを返す
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(int(n))
    return table


from collections import defaultdict
dic = defaultdict(int)

for i in prime_decomposition(n):
    dic[i] += 1


ans = 0
for i in dic:
    k = dic[i]
    now = 1
    while k:
        k -= now
        if k == 0:
            ans += now
            break
        elif k < 0:
            ans += now - 1
            break
        now += 1

print(ans)


Measured memory_bytes: 66068
#include <cstdio>

char d[110][110];
int k[100][100];
int X, Y, r = 1;
void search(int x, int y ,int t){

    if(k[x][y] != -1 || d[x][y] != t)
        return;
    k[x][y] = r;
    if(x - 1 >= 0){
        search(x - 1, y, d[x][y]);
    }
    if(x + 1 < X){
        search(x + 1, y, d[x][y]);
    }
    if(y - 1 >= 0){
        search(x, y - 1, d[x][y]);
    }
    if(y + 1 < Y){
        search(x, y + 1, d[x][y]);
    }
}

int main(void)
{

    while(1){
        r = 0;
        scanf("%d %d", &X, &Y);
        if(X == 0 && Y == 0)
            break;
        gets(d[0]);
        for(int x = 0; x < X; x++){
            gets(d[x]);
            for(int y = 0; y < Y; y++){
                k[x][y] = -1;
            }
        }
        for(int x = 0; x < X; x++){
            for(int y = 0; y < Y; y++){
                if(k[x][y] != -1)
                    continue;
                search(x, y, d[x][y]);
                r++;
            }
        }
        printf("%d\n", r);
    }
    return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>s(n);
    int sum=0;
    rep(i,n){
        cin>>s[i];
        sum+=s[i];
    }
    sort(s.begin(),s.end());
    rep(i,n){
        if(sum%10!=0){
            cout<<sum<<endl;
            return 0;
        }
        else{
            if(s[i]%10!=0)sum-=s[i];
        }
    }
    cout<<0<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
ll n;
cin>>n;
while(n){
    if(n%10==7){
        cout<<"Yes"<<"\n";
        return 0;
    }
    n/=10;
}
cout<<"No"<<"\n";
}

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

int main() {

    string S;
    cin >> S;

    bool flag = false;
    if (S.substr(0, 1) == "A") {
        int i_num = 0;
        int count = 0;
        for(int i = 2; i < S.size() - 1; i++) {

            if(S.substr(i, 1) == "C") {
                i_num = i;
                count += 1;
            }
        }

        if(count == 1) {

            count = 0;

            for(int i = 0; i < S.size(); i++) {
                if( S.substr(i, 1) >= "A" && S.substr(i, 1) <= "Z") {
                    count++;
                }
            }

            if (count == 2) {
                flag = true;
            }
        }
    }

    if(flag == true) {
        cout << "AC" << endl;
    }
    else {
        cout << "WA" << endl;
    }
    
}


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

const int mod = 1e9 + 7;
const int ma = 201010;

ll fact[ma], rfact[ma];

ll mod_pow(ll x, ll n, ll mod) {
    ll a = 1LL;
    while (n) {
        if (n%2) a = ((a%mod)*(x%mod))%mod;
        x = ((x%mod)*(x%mod))%mod;
        n /= 2LL;
    }
    return a;
}

ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m-2, m);
}

ll ncr(int n, int r) {
    if (n < r) return 0;
    return fact[n] * (rfact[r] * rfact[n-r] % mod) % mod;
}

void init() {
    fact[0] = rfact[0] = 1;
    for (int i=1; i<ma; ++i) {
        fact[i] = (fact[i-1] * i) % mod;
        rfact[i] = mod_inverse(fact[i], mod);
    }
}

int main() {
    init();

    int n; cin >> n;
    vector<int> a(n+1);
    
    int po[ma];
    fill(po, po+ma, -1);
    
    int l,r;
    rep(i, n+1) {
        cin >> a[i];
        if (po[a[i]] == -1) { po[a[i]] = i+1; }
        else {
            l = po[a[i]];
            r = i+1;
        }
    }

    int pos = r - l + 1;
    for (int k=1; k<=n+1; ++k) {
        ll t =  ncr(n+1, k) - ncr(n+1-pos, k-1);
        if (t < 0) {
            t += mod;
        }
        cout << t << endl;
        
    }
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define PI 3.1415926535897932384626433832795
using namespace std;

int main(){
    double l;
    cin>>l;
    double ans;
    cout<<setprecision(20)<< (l/3) *(l/3) *(l/3);
   


    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int zero = 0;
    int one = 0;
    char[] ch = new char[str.length()];
    for(int i = 0; i < str.length(); i++) {
      ch[i] = str.charAt(i);
      if(ch[i] == '0') zero++;
      else if(ch[i] == '1') one++;
    }
    int ans = 2 * Math.min(zero, one);
    System.out.println(ans);
  }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

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

using namespace std;
using ll=long long;

const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int w,h,n;
int p[110];

int main(void){
	cin >> w >> h >> n;
	rep(i,n) cin >> p[i];
	int cx[2]={0,0},cy[2]={0,1},mode[2]={1,1};
	
	int ans=0;
	rep(i,n){
		switch(mode[p[i]]){
			case 1:
				cx[p[i]]+=1;
				break;
			case 2:
				cy[p[i]]+=1;	
				break;
			case 3:
				cx[p[i]]-=1;
				break;
		}
		if(cx[p[i]]==w-1-p[i] && mode[p[i]]==1) mode[p[i]]++;
		if(cy[p[i]]==h-1-p[i] && mode[p[i]]==2) mode[p[i]]++;
		if(abs(cx[1]-cx[0])+abs(cy[1]-cy[0])==1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

class Point{
	int x;
	int y;
	int z;
	Point(int a,int b,int c){
		this.x = a;
		this.y = b;
		this.z = c;
	}
}
public class Main {

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

		int[][] C = new int[3][3];
		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				C[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int[][] V = new int[3][3];
		V[0][0] = 0;
		V[1][0] = 0;
		V[2][0] = 0;

		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				if(j>0){
					V[i][j] = C[i][j]-C[i][j-1];
				}
			}
		}
/*
		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 3 ; j++){
			System.out.print(V[i][j] + " ");
			}
			System.out.println("");
		}
*/

		if(V[0][0] == V[1][0] && V[1][0] == V[2][0]){
			if(V[0][1] == V[1][1] && V[1][1] == V[2][1]){
				if(V[0][2] == V[1][2] && V[1][2] == V[2][2]){
					System.out.println("Yes");
				}
				else{
					System.out.println("No");
				}
			}
			else{
				System.out.println("No");
			}
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
int main()
{
    int x,y;
    while(scanf("%d %d",&x,&y)!=EOF)
    {
        if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
            printf("Yes\n");
        else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
            printf("Yes\n");
        else if(x==2&&y==2)
            printf("Yes\n");
        else
            printf("No\n");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

int main(){
    
    ll mod=INF;
    ull ans=1;
    ll n,m;
    cin >> n>>m;
    
    if(n<m)swap(m,n);
    
    if(n>m+1){
        ans=0;
    }else{
        for(ll i=1;i<=m;i++){
            ans = ans * i * i %mod;
        }
        if(m==n)ans=ans*2%mod;
        else ans = ans*n%mod;
    }
    
    cout << ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
def main():
    N = input()
    if int(N) % 2 == 1:
        print(0)
        exit()
    cnt5 = 0
    for i in range(1,100):
        tmp =  int(N) // (5 ** i)
        cnt5 += tmp // 2
    print(cnt5)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
//============================================================================
// Name        : aaaa.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>

using namespace std;

int main(){
	int A, B;
	cin >> A >> B;
	cout << (A - 1) * (B - 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,c,k,ans=1,cnt=0,s=0;
int t[200000];
signed main(){
    cin>>n>>c>>k;
    rep(i,n)cin>>t[i];
    sort(t,t+n);
    rep(i,n){
        if(cnt==0){
            s=t[i];
            cnt++;
        }
        else if(cnt==c||t[i]>s+k){
            ans++;
            cnt=1;
            s=t[i];
        }
        else cnt++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
C = []
S = []
F = []
for i in range(n-1):
    c,s,f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(n):
    t = 0
    for j in range(i, n-1):
        t = max(S[j], (t+F[j]-1)//F[j]*F[j]) + C[j]
    print(t)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(void){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int d;
  if(a < b){
    d = a;
    a = b;
    b = d;
  }
    if(b < c){
      d = b;
      b = c;
      c = d;
    }

  if(a < b){
    d = a;
    a = b;
    b = d;
  }
  printf("%d\n", a*10+b+c);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,count=0;
	string s;
	cin >> n >> s;
	string str = "ABC";
	for (int i = 0; i < s.size()-2; i++) {
		if (s[i] == str[0]) {
			if (s[i + 1] == str[1]) {
				if (s[i + 2] == str[2]) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
}


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

vector<int> par;
vector<int> RA;

void Re(int a){
  par.resize(a);
  RA.resize(a);
  for(int i=0;i<a;i++){
    par[i]=i;
  }
}
int root(int a){
  if(a==par[a]){
    return a;
  }
  else{
    return par[a]=root(par[a]);
  }
}
void UN(int a,int b){
  a=root(a);
  b=root(b);
  if(a==b){
    return;
  }
  else if(RA[a]<RA[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
  }
  if(RA[a]==RA[b]){
    RA[a]++;
  }
}
bool same(int a,int b){
  if(root(a)==root(b)){
    return true;
  }
  else{
    return false;
  }
}

int main() {
  int N,Q;
  cin>>N>>Q;
  Re(N);
  for(int i=0;i<Q;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(a){
      if(same(b,c)){
        cout<<"1"<<endl;
      }
      else{
        cout<<"0"<<endl;
      }
    }
    else{
      UN(b,c);
    }
  }
}

Measured memory_bytes: 4700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
using namespace std;

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef pair<int,int> pint;
typedef vector<pint> vping;

#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

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


int N,M;
bool tree[8][8];


int count(int x, int res){
  if(!res) return 1;
  int cnt = 0;

  rep(i, N){
    if((res>>i & 1) && tree[x][i]){
      cnt += count(i, res-(1<<i));
    }
  }

  return cnt;
}



int main() {
  cin >> N >> M;
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;b--;
    tree[a][b] = true;
    tree[b][a] = true;
  }

  int ans = 0;
  int res = (1<<N) - 2;
  // set<int> s;
  // rep(i,N-1) s.insert(i+1);

  ans = count(0,res);

  cout << ans << endl;



}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };


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

	vector<vector<int>>D(c,vector<int>(c,0));
	rep(i, 0, c)rep(j, 0, c)cin >> D[i][j];

	vector<vector<int>>modcol(3, vector<int>(c, 0));
	rep(i, 0, n)rep(j, 0, n) {
		int col;
		cin >> col;
		col--;
		modcol[(i+1+j+1)%3][col]++;
	}

	vector<int>per(c);
	rep(i, 0, c)per[i] = i;


	int ans = INF;
	rep(i, 0, c)rep(j, 0, c)rep(k, 0, c) {
		if (i != j && j != k && k != i) {
			int temp = 0;
			rep(x, 0, c)temp += modcol[0][x] * D[x][i];
			rep(y, 0, c)temp += modcol[1][y] * D[y][j];
			rep(z, 0, c)temp += modcol[2][z] * D[z][k];
			ans = min(ans, temp);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
  int N;

  while(cin >> N, N) {
    int count = 0;
    for (int i = 1; i < N; i++) {
      int sum = 0;
    
      for (int j = i; j < N; j++) {
	sum += j;
	if (N<sum) break;
	else if (N==sum) {
	  count++;
	  break;
	} 
      }
      //cout << count << endl;
    }
    cout << count << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  ll x,y;
  cin >> x >> y;
  if(x%y==0){
    cout << -1 << endl;
  }else{
    cout << x << endl;
  }
  
}


Measured memory_bytes: 256
n = int(input())
d = [int(input())for i in range(n)]
ok1 = True
nowmx = 0
for i in range(n-1):
    if i > nowmx:
        ok1 = False
        break
    x = i+d[i]//10#いける右端のトランポリ
    if x >= nowmx:
        nowmx = x
   
if nowmx < n-1:ok1 = False
d = d[::-1]
ok2 = True
nowmx = 0
for i in range(n-1):
    if i > nowmx:        
        ok2 = False
        break
    x = i+d[i]//10#いける右端のトランポリン
    if x >= nowmx:
        nowmx = x
  
if nowmx < n-1:ok2 = False
if ok1 and ok2:print('yes')
else:print('no')



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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

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

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}

const int MAX_N = 300000;
const int MAX_J = 61;
lli n;
lli A[MAX_N][MAX_J];
lli K[MAX_J];
lli tmp;

int main(void){
    //int ti = clock();
    cin >> n;
    rep(i, n){
        cin >> tmp;
        rep(j, 60){
            A[i][j] = tmp%2;
            tmp = tmp/2;
        }
    }
    rep(i, n){
        rep(j, 60){
            K[j] = max(A[i][j], K[j]+A[i][j]);
        }
    }
    lli res = 0;
    rep(j, 60){
        lli x = K[j]*(n-K[j]);
        rep(i, j) (x*=2)%=MOD;
        (res+=x)%=MOD;
    }
    cout << res << endl;
    //cout << fixed << setprecision(10) << 1.0*(clock()-ti)/CLOCKS_PER_SEC << endl;
    return 0;
}


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

int main(){
    char S[3];
    char T[3];
    int i;
    for(i=0; i<3; i++){
        cin >> S[i];
    }
    for(i=0; i<3; i++){
        cin >> T[i];
    }
    int ans=0;
    for(i=0; i<3; i++){
        if(S[i]==T[i]){
            ans=ans+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,K;
double A[200005];
signed main(){
	cin>>N>>K;
	rep(i,N)cin>>A[i];
	double ok=1e9,ng=0;
	rep(_,200){
		double mid=(ok+ng)/2;
		int sum=0;
		rep(i,N){
			sum+=ceil(A[i]/mid)-1;
		}
		if(sum<=K)ok=mid;
		else ng=mid;
	}
	cout<<(int)ceil(ok)<<endl;
}

Measured memory_bytes: 5396
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
string s; 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>s;
	if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
		cout<<"Yes";
	}
	else
	cout<<"No";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a) //追加//
#define pp() pop_back() //削除//
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())

signed main(){
  int n,m;
  cin>>n>>m;
  int ans=0;
  V<int> b(m,0);
  for(int i=0; i<n; i++){
    int k;
    cin>>k;
    V<int> a(k);
    fo(j,k){
      cin>>a[j];
    }
    fo(j,k){
      b[a[j]-1]++;
    }

  }
  fo(i,m){
    if(b[i]==n)
      ans++;
  }
  cout<<ans<<endl;
}


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

const int maxn = 1e3+7;

char maze[maxn][maxn];

vector<pair<int,int> >vec;

int dis[maxn][maxn];

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

int main(){
    int n,m;cin>>n>>m;
    for(int i=0;i<n;i++) cin>>maze[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(maze[i][j]=='#') vec.push_back({i,j}),dis[i][j]=0;
            else dis[i][j]=1000000;
        }
    }
    int ans;
    for(int i=0;i<vec.size();i++){
        ans=dis[vec[i].first][vec[i].second];
        for(int j=0;j<4;j++){
                int ex=vec[i].first+dx[j];
                int ey=vec[i].second+dy[j];
                if(ex>=0&&ex<n&&ey>=0&&ey<m&&dis[ex][ey]>100000){
                    dis[ex][ey]=dis[vec[i].first][vec[i].second]+1;
                    vec.push_back({ex,ey});
                }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15340
#include<bits/stdc++.h>
using namespace std;
#define int long long
int f(int n,int x){
    if(n==-1)return 0;
    return n/x+1;
}
signed main(){
    int a,b,x;
    cin>>a>>b>>x;
    cout<<f(b,x)-f(a-1,x)<<endl;
    return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
h = [1]
p = [1]
for i in range(N):
    h.append(h[i]*2+3)
    p.append(p[i]*2+1)
def f(N,X):
    if X == 1:
        if N == 0:
            return 1
        return 0
    elif 1 < X and X <= 1 + h[N-1]:
        return f(N-1,X-1)
    elif X == 2 + h[N-1]:
        return p[N-1] + 1
    elif 2 + h[N-1] < X and X <= 2 + 2 * h[N-1]:
        return p[N-1] + 1 + f(N-1,X-2-h[N-1])
    elif X == 3 + 2 * h[N-1]:
        return p[N]
print(f(N,X))

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    vector<ll> c(N);
    c[0] = A[0];
    for ( int i = 1; i < N; i++ ) {
        c[i] = c[i-1] + A[i];
    }
    for ( int i = N-2; i >= 0; i-- ) {
        if ( c[i] * 2 < A[i+1] ) return N-1-i;
    }
    return N;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

//#define max(x, y) ((x)>(y)?(x):(y))
//#define min(x, y) ((x)<(y)?(x):(y))

Int n, h[216000], a[216000];
Int seg[1 << 20];

Int cnt = 0;
void setval(Int pos, Int val){
  pos += (1 << 19);
  seg[pos] = val;
  while(pos /= 2){
    seg[pos] = max(seg[pos*2], seg[pos*2+1]);
  }
}

Int getval(Int l, Int r, Int bottom = 0, Int top = (1<<19), Int pos = 1){
  if(r <= bottom || top <= l)return 0;
  if(l <= bottom && top <= r)return seg[pos];
  Int mid = (bottom + top) / 2;
  return max(getval(l, r, bottom, mid, pos * 2),
	     getval(l, r, mid, top, pos * 2 + 1));
}

int main(){
  cin >> n;
  for(int i = 0;i < n;i++)cin >> h[i];
  for(int i = 0;i < n;i++)cin >> a[i];
  for(int i = 0;i < n;i++){
    setval(h[i], max(getval(h[i], h[i]+1), getval(1, h[i]) + a[i]));
  }
  cout << getval(1, 216000) << endl;
  return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define ll long long

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef  pair<int,int> pii;
typedef vector<pii> vp;
typedef pair<ll, ll> pll;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}

int n;
vi v;

int main() {
	scanf("%d", &n);
	v.resize(n+1, 0);
	for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
	v[1] = v[1] == 1? 1: 0;
	for(int i = 2; i <= n; i++) {
		v[i] = (v[i] == i && !v[i-1]);
	}

	printf("%d\n", accumulate(++v.begin(), v.end(), 0));
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
	string str;
	cin >> str;
    int len  = (int)(str.length());
    int flag = 0;
	for(int i = 0; i < len/2; i++){
        if (str[i] != str[len-1-i]) {
            flag++;
        }
	}
    cout << flag << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    A = []
    for i in range(H):
        a = list(input())
        A.extend(a)

    D = Counter(A)
    B = [["" for _ in range(W)] for _ in range(H)]
    if H > 1 and W > 1:
        for h in range(H // 2):
            for w in range(W // 2):
                for k, v in D.items():
                    if v >= 4:
                        B[h][w] = k
                        B[h][-(w + 1)] = k
                        B[-(h + 1)][w] = k
                        B[-(h + 1)][-(w + 1)] = k
                        D[k] -= 4
                        break

        if H % 2 != 0:
            for w in range(W // 2):
                for k, v in D.items():
                    if v >= 2:
                        B[H // 2][w] = k
                        B[H // 2][-(w + 1)] = k
                        D[k] -= 2
                        break
        if W % 2 != 0:
            for h in range(H // 2):
                for k, v in D.items():
                    if v >= 2:
                        B[h][W // 2] = k
                        B[-(h + 1)][W // 2] = k
                        D[k] -= 2
                        break
        if H % 2 != 0 and W % 2 != 0:
            for k, v in D.items():
                if v >= 1:
                    B[H // 2][W // 2] = k
                    D[k] -= 1
                    break
    elif W == 1 and H > 1:
        for h in range(H // 2):
            for k, v in D.items():
                if v >= 2:
                    B[h][0] = k
                    B[-(h + 1)][0] = k
                    D[k] -= 2
                    break
        if H % 2 != 0:
            for k, v in D.items():
                if v >= 1:
                    B[H // 2][0] = k
                    D[k] -= 1
                    break
    elif H == 1 and W > 1:
        for w in range(W // 2):
            for k, v in D.items():
                if v >= 2:
                    B[0][w] = k
                    B[0][-(w + 1)] = k
                    D[k] -= 2
                    break
        if W % 2 != 0:
            for k, v in D.items():
                if v >= 1:
                    B[0][W // 2] = k
                    D[k] -= 1
                    break
    else:
        print("Yes")
        exit()

    for i in B:
        if "" in set(i):
            print("No")
            break
    else:
        print("Yes")


if __name__ == '__main__':
    resolve()


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

int main()
{
	string a;
	cin >> a;
	string b;
	cin >> b;
	int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		if(a[i] == b[i])
		{
			ans += 1;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi std::vector<int>
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
#define YES std::cout << "YES" << std::endl
#define NO std::cout << "NO" << std::endl
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T> void debug(const T& t);
constexpr ll mod10_9p7 = 1000000000 + 7;

/**************************************************************/
int main()
{
    stat();
    int n;cin>>n;
    int co=0;int c=0;
    rep(i,n){
int a,b;cin>>a>>b;
if(a==b){
++c;
}else{
co=max(co,c);
c=0;
}

co=max(co,c);
    }
if(co>=3){
	Yes;
}else{
	No;
}

    return 0;
}
/**************************************************************/
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}

unsigned long long modpow(int x__, int n__, long long mod__)
{
    long long ret__ = 1;
    for (long long i__ = 0; i__ < n__; ++i__) {
        ret__ = ret__ * x__ % mod__;
    }
    return ret__;
}

template <typename T> void debug(const T& t)
{
#ifdef local
    dbg(t);
#endif
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 1e17
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int N;
    cin >> N;
    vector<ll> sums(N+1,0);
    FOR(i,1,N+1) {
        int a;
        cin >> a;
        sums[i] = a + sums[i-1];
    }

    ll mini = INF;
    REP(i,N-1) {
        ll x = sums[i+1];
        ll y = sums[N] - x;
        chmin(mini, abs(x - y));
    }

    cout << mini << endl;

}

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


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    REP(i,1,N+1) {
        if (i%3==0&&i%5==0);
        else if (i % 3 == 0);
        else if (i % 5 == 0);
        else {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define multis          multiset <int, greater <int> > gquiz1;
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void ayushmehta651()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
}

int32_t main()
{
	ayushmehta651();
	int n, k; cin >> n >> k;
	int a[n];

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

	sort(a, a + n);

	int i = 0;
	int sum = 0;
	while (k--)
	{
		sum += a[i];
		++i;
	}
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/

#define double long double

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

    int n; cin >> n;
    vector <double> A(n);
    for (double &i: A) cin >> i;

    vector <double> dp(n+1, 0);
    dp[0] = 1;
    for (int coins = 0; coins < n; ++coins) {
        for (int i = coins+1; i >= 0; --i) {
            dp[i] = (i ? dp[i-1]*A[coins] : 0) + dp[i]*(1 - A[coins]);
        }
    }

    double ans = 0;
    for (int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if (heads > tails) ans += dp[heads];
    }

    cout << fixed << setprecision(10);
    cout << ans;



    return 0;
}


Measured memory_bytes: 3920