akhauriyash/Code-Regression huggingface dataset:
// CODING BEAST
/*******************************************************************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define Precision(a) cout << fixed << setprecision(a)

using ll = long long;
ll inf = 1e18;
using vb = vector<bool>; using vc = vector<char>; using vd = vector<double>; using vi = vector<int>; using vvi = vector<vi>;
using vll = vector<ll>; using vvll = vector<vll>; using pi = pair<int, int>; using pll = pair<ll, ll>;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i = 0; i < n; i++)
#define repc(i,a,n) for(ll i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define Blazing_fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trav(a,v) for(auto &a:v)
int a[8] = { -1, -1, -1, 0, 0, 1, 1, 1};
int b[8] = { -1, 0, 1, -1, 1, -1, 0, 1};
inline ll power(ll x, ll y)
{
    ll temp;
    if ( y == 0)
        return 1;
    temp = power(x, y / 2) ;
    if (y % 2 == 0)
        return (temp * temp) ;
    else
        return (x * temp * temp) ;
}
bool sortbysec(pll & a, pll & b) {
    return (a.second < b.second);
}
/*
ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i) ;
    return res;
}

ll ncr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if ((n % 2 == 0) || (n % 3 == 0)) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if ((n % i == 0) || (n % (i + 2) == 0)) return false;

    return true;
}*/
/*********************************************************************************************************************************************************/

signed main() {
    ll n; cin >> n;
    unordered_map<string, ll>m;
    rep(i, n) {
        string s; cin >> s;
        m[s]++;
    }
    cout << "AC" << " " << "x" << " " << m["AC"] << endl;
    cout << "WA" << " " << "x" << " " << m["WA"] << endl;
    cout << "TLE" << " " << "x" << " " << m["TLE"] << endl;
    cout << "RE" << " " << "x" << " " << m["RE"] << endl;


}



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

int main() {
	int n, k;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h, h + n);
	int min = h[n - 1] - h[0];
	for (int i = 0; i + k - 1 < n; i++) {
		if (h[i + k - 1] - h[i] < min)
			min = h[i + k - 1] - h[i];
	}
	cout << min << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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;
}

int main()
{
  string S;
  cin >> S;
  int x,y;
  cin >> x >> y;
  int cnt = 0;
  int flag = 0;
  int flag2=0;
  vector<int> X;
  vector<int> Y;
  REP(i,sz(S)){
    if(S[i]=='F'){
      cnt++;
    }else{
      if(flag==0){
        if(flag2==0){
          x-=cnt;
          cnt=0;
          flag=1;
          flag2=1;
        }else{
          X.push_back(cnt);
          cnt=0;
          flag=1;
        }
      }else{
        Y.push_back(cnt);
        cnt=0;
        flag=0;
      }
    }
  }
  if(flag==0){
    if(flag2==0){
      x-=cnt;
    }else{
      X.push_back(cnt);
    }
  }else{
    Y.push_back(cnt);
  }
  sort(ALL(X));
  sort(ALL(Y));
  reverse(ALL(X));
  reverse(ALL(Y));
  int sumx=0;
  REP(i,sz(X)){
    if(sumx<x){
      sumx+=X[i];
    }else{
      sumx-=X[i];
    }
  }
  int sumy=0;
  REP(i,sz(Y)){
    if(sumy<y){
      sumy+=Y[i];
    }else{
      sumy-=Y[i];
    }
  }
  if(sumx==x&&sumy==y){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3668
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin –2147483648
#define llmax 9223372036854775807
#define llmin -9223372036854775808
using namespace std;

int n;
int a[26], mn[26];
string s;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	lp(26)
		mn[i] = intmax;
	cin >> n;
	lp(n) {
		lop(26, j)
			a[j] = 0;
		cin >> s;
		lop(s.size(), j)
			a[s[j] - 'a']++;
		lop(26, j)
			mn[j] = min(mn[j], a[j]);
	}
	s = "";
	lp(26) {
		lop(mn[i], j) {
			s += 'a' + i;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y;
	cin >> x>> y;
      cout << ((x*3+y)/2) << endl;
}

Measured memory_bytes: 256
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var h = o.a();
  var a = o.a();
  return Math.ceil(h/a);
}

Measured memory_bytes: 7372
def main():
    s = input()
    t = input()

    ind = [set() for _ in range(26)]
    outd = [set() for _ in range(26)]

    for se, te in zip(s, t):
        si = ord(se) - ord("a")
        ti = ord(te) - ord("a")
        outd[si].add(te)
        ind[ti].add(se)

    bl = True
    for e_ind, e_outd in zip(ind, outd):
        l_ind = len(e_ind)
        l_outd = len(e_outd)
        if l_ind >= 2 or l_outd >= 2:
            bl = False
            break

    print("Yes" if bl else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3632
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int status [][] = new int [4][2];
		int before [][] = new int [4][2];
		int N = in.nextInt();
		int K = in.nextInt();
		int pasta[] = new int [N + 1];
		for(int i = 1; i <= 3; i++){
			for(int k = 0; k <= 1; k++){
				status[i][k] = 0;
				before[i][k] = 0;
			}
		}
		for(int i = 0; i < K; i++){
			pasta[in.nextInt()] = in.nextInt();
		}
		for(int i = 1; i <= N; i++){
			if(pasta[i] != 0){//予約ありの時
				//System.out.println(i+"日目予約あり");
				if(i == 1){//初回に予約有りの時
					status[pasta[i]][0] = 1;
				}
				else{//初回以外に予約有りの時
					for(int k = 1; k <= 3; k++){
						for(int m = 0; m <= 1; m++){
							status[pasta[i]][0] += before[k][m];//予約パスタ（本日１日目状態）に前日の状態すべてを加算
						}
					}
					status[pasta[i]][1] += before[pasta[i]][0];//予約パスタ（本日の２日目状態）に（前日の１日目状態）を加算
					status[pasta[i]][0] -= before[pasta[i]][0];//予約パスタ（本日の１日目状態）から同種パスタの（前日の１日目状態）を減算
					status[pasta[i]][0] -= before[pasta[i]][1];//予約パスタ（本日の１日目状態）から同種パスタの（前日の２日目状態）を減算
					//System.out.println(i+"日 1日目状態の種類"+pasta[i]+"が"+status[pasta[i]][0]);
					//System.out.println(i+"日 2日目状態の種類"+pasta[i]+"が"+status[pasta[i]][1]);
				}
			}
			else{//予約無しの時
				if(i == 1){//初回予約なしの時
					for(int k = 1; k <= 3; k++){
						status[k][0] = 1;//すべての（本日の１日目状態）に１を代入
					}
				}
				else{//初回以外の予約なしの時
					//まずは（当日の１日目状態）に関して
					for(int k = 1; k <= 3; k++){//（当日のパスタ）のfor文
						for(int n = 1; n <= 3; n++){//（前日のパスタ）のfor文
							for(int m = 0; m <= 1; m++){//（何日目か）のfor文
								status[k][0] += before[n][m];//（本日の１日目状態）にすべての（前日の状態）を加算
							}
						}
						status[k][0] -= before[k][0] + before[k][1];//（本日の一日目状態）から同種パスタの（前日の１日目状態）と（前日の２日目状態）を減算
						//System.out.println("種類"+k+"の１日目状態　"+status[k][0]);
					}
					//（当日の１日目状態）終わり
					//次に（当日の２日目状態）に関して
					for(int k = 1; k <= 3; k++){
						status[k][1] = before[k][0];//（本日の２日目状態）に同種パスタの（前日の１日目状態）を代入
						//System.out.println("種類"+k+"の2日目状態　"+status[k][1]);
					}
					//（当日の２日目状態）終わり
				}
				//初回以外予約なし終わり
			}
			//予約なしもありも終わり
			//すべての（本日の状態）を（前日の状態）に変更
			for(int k = 1; k <= 3; k++){
				for(int m = 0; m <= 1; m++){
					before[k][m] = status[k][m] % 10000;
					status[k][m] = 0;
				}
			}
			//変更完了
		}
		//N回のループ完了
		int sum = 0;
		for(int k = 1; k <= 3; k++){
			for(int m = 0; m <= 1; m++){
				sum += before[k][m];
			}
		}
		System.out.println(sum % 10000);
	}

}

Measured memory_bytes: 19680
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L

long double a,b,h,m,c,d1,d2;
int main()
{
	cin>>a>>b>>h>>m;

	c=sqrt((a*a+b*b)-2*a*b*cos(2*PI*(h/12.0+m/720.0-m/60.0)));
	cout<<fixed<<setprecision(20)<<c;
}


Measured memory_bytes: 4096
#include <stdio.h>

int main(){
    int w,h;
    while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0){
            break;
        }
        
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i == 0 || i == h-1 || j == 0 || j == w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2068
/* Author : A110011 - 00:19 "Coding In Hard Way" */

#include<bits/stdc++.h>

typedef long long int ll;

using namespace std;


ll knap(vector<int> &val, vector<int> &wt, int w,int n,vector<vector<ll>> &res){

    if(n==0 || w==0){
         return 0;
    }

    if(res[n][w]!=-1){
        return res[n][w];
    }
    if(wt[n]<=w){
        res[n][w]=max(val[n]+knap(val,wt,w-wt[n],n-1,res),knap(val,wt,w,n-1,res));
        return res[n][w];
    }else{
        res[n][w]=knap(val,wt,w,n-1,res);
        return res[n][w];
    }

}

int main(){

	// For fast I/O.
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,w;

    cin>>n>>w;

    vector<int> wt(n+1);
    vector<int> val(n+1);

    vector<vector<ll>> res(n+1,vector<ll>(w+1,-1));

    for(int i=1;i<=n;i++){
        cin>>wt[i];
        cin>>val[i];
    }


    cout<<knap(val,wt,w,n,res)<<endl;

return 0;
}


Measured memory_bytes: 80256
a = input()
x,  y,  z,  b=int(a[0]),  int(a[1]),  int(a[2]),  int(a[3])
if x+y+z+b==7:
    print("{}+{}+{}+{}=7".format(x, y, z, b))
elif x-y-z-b==7:
    print("{}-{}-{}-{}=7".format(x, y, z, b))
elif x+y+z-b==7:
    print("{}+{}+{}-{}=7".format(x, y, z, b))
elif x+y-z+b==7:
    print("{}+{}-{}+{}=7".format(x, y, z, b))
elif x-y+z+b==7:
    print("{}-{}+{}+{}=7".format(x, y, z, b))
elif x+y-z-b==7:
    print("{}+{}-{}-{}=7".format(x, y, z, b))
elif x-y-z+b==7:
    print("{}-{}-{}+{}=7".format(x, y, z, b))
else:
    print("{}-{}+{}-{}=7".format(x, y, z, b))


Measured memory_bytes: 38384
names = Array.new(gets.chomp.to_i) { gets.chomp }

initials = Hash.new { |h, k| h[k] = 0 }.tap do |y|
  names.group_by { |x| x.downcase[0] }
       .map { |k, v| y[k] = v.size }
end

sum = 0
["m", "a", "r", "c", "h"].combination(3) do |c1, c2, c3|
  sum += initials[c1] * initials[c2] * initials[c3]
end
puts sum


Measured memory_bytes: 11004
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int r, c, i, j, all=0;
  cin >> r >> c;
  vector<vector<int> > data(r+1, vector<int>(c+1, 0));
  for (i=0; i<r; i++) {
    int sum=0;
    for (j=0; j<c; j++) {
      int num;
      cin >> num;
      data.at(i).at(j) = num; 
      sum+=num;
      data.at(r).at(j) += num; 
    }
    data.at(i).at(j) = sum; 
    all+=sum;
  }
  data.at(i).at(j) = all; 

  for (i=0; i<r+1; i++) {
    for (j=0; j<c+1; j++) {
      cout << data.at(i).at(j);
      if (j<c) cout << " ";
      else cout << endl; 
    }
  }
}


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


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n;
  cin >> n;
  int64_t i,ans=1,amari=1;
  for(i=0;i<9;i++){
    amari*=10;
  }
  amari+=7;
  for(i=1;i<=n;i++){
	ans=ans*i;
    ans=ans%amari;
  }
  cout << ans;
}

Measured memory_bytes: 256
S = input()

count = 0

for i in range(1, len(S)):
    if S[i - 1] == '0' and S[i] != '1':
        S = S[: i] + '1' + S[i + 1:]
        count += 1
    elif S[i - 1] == '1' and S[i] != '0':
        S = S[: i] + '0' + S[i + 1:]
        count += 1
print(count)

Measured memory_bytes: 3436
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// x^n(mod M)
void solve(ll n, ll p, const string &s) {
    vector<ll> ten(n+1), x(n+1);
    ten[0] = 1;
    rep(i,n) {
        ten[i+1] = (ten[i]*10)%p;
        ten[i+1] %= p;
    }

    rep(i,n) {
        ll d = s[i]-'0';
        x[i+1] = (x[i]%p+(d*ten[i])%p)%p;
    }

    ll ans = 0;
    map<ll, ll> mp;
    rep(i,n+1) {
        if (!mp.count(x[i])) {
            mp[x[i]]++;
        }
        else {
            ans += mp[x[i]];
            mp[x[i]]++;
        }
    }

    cout << ans << '\n';
}

void solve2(ll n, ll p, const string &s) {
    ll ans = 0;
    rep(i,n) {
        ll d = s[i]-'0';
        if (d%p==0) ans += (n-i);
    }
    cout << ans << '\n';
}

int main(int argc, char const *argv[]) {
    int n,p; cin>>n>>p;
    string s; cin>>s;
    reverse(s.begin(), s.end());

    if (p==2 || p==5) {
        solve2(n,p,s);
    }
    else {
        solve(n,p,s);
    }

    return 0;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> pii;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const int MAXN = 500;
const int INF = 1e9;
vector<int> res;
//#define DEBUG

int main(){
  FastIO;
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif
  ll m;
  cin >> m;
  ll a, b;
  ll ans = 0;
  vector<ll> add(10, 0);
  for (int i = 1; i < 10; ++i)
  {
    int last = 0;
    for (int j = 0; j < 10; ++j)
    {
      last += i;
      if (last > 10){
        last %= 10;
        ++add[i];
      }
      ++add[i];
    }
  }
  forn(i, m)
  {
    cin >> a >> b;
    if (a == 0)
    {
      ans += b - 1;
      res.pb(0);
      continue;
    }
    while(b >= 10)
    {
      ans += b / 10 * add[a];
      b = b % 10 + b / 10;
    }
    forn(j, b)
    {
      res.pb(a);
    }
  }
  int last = res[0];
  for (int i = 1; i < res.size(); ++i)
  {
    if (res[i] + last >= 10)
    {
      ans += 2;
      last = (res[i] + last) % 10 + 1;
    }
    else
    {
      ++ans;
      last = res[i] + last;
    }
  }
  cout << max((ll)1, ans);
  return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) {
        sum += a[i];
        if (sum >= h) {
            println("Yes")
            return 0;
        }
    }
    
    println("No")
    return 0;
}

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

int main() {
  int n;
  bool b = false;
  cin >> n;
  while (n) {
    if (n % 10 == 7) {
      b = true;
    }
    n /= 10;
  }

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

Measured memory_bytes: 3592
from itertools import accumulate

N, K = map(int, input().split())
S = input()
S = [int(s) for s in S]

# 0, 1 が連続して何回出現するかカウント
# はじめを必ず 1 はじめにしてしまう？
# 端は全て 0 の個数でまとめてしまう
nums = list()
now = 1
count_tmp = 0
for i in range(N):
    if S[i] == now:
        count_tmp += 1
    else:
        nums.append(count_tmp)
        now = 1 - now
        count_tmp = 1
if count_tmp > 0:
    nums.append(count_tmp)
# 何がなんでも 1 0 1 0 1 で終わらせたい
# 始まりは 1 始まりになってるので、0 終わりの場合は len(nums) が偶数となる
if len(nums) % 2 == 0:
    nums.append(0)

# nums の累積和
# nums 内の i から j までの和を sums[j] - sums[i] で表したいので [0] を先頭に足す
sums = list(accumulate([0] + nums))

# 1 0 1 0 .... 1 で終わっているので、 0 の個数を表す部分のみ見ればよい
max_add = 2 * K  # 最大で追加して取れる区間
ans = 0
for i in range(0, len(nums), 2):
    left = i
    right = min(i + max_add, len(nums) - 1)
    # nums の left から right までの和
    tmp = sums[right + 1] - sums[left]
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 9472
import java.util.Scanner;
import java.util.Vector;

public class Main {
	static int a[];
	static long dp[][];
	static int g[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		dp = new long [n][n];
		g = new int[n][n];
		a = new int[n];
		for (int i=0;i<n;i++) 
			a[i]=sc.nextInt();
			f(0,n-1);
		System.out.println(dp[0][n-1]);
	}
	private static long f(int l, int r) {
		if (l==r) {
			g[l][r] = 1;
			dp[l][r] = a[l];
			return a[l];
		}
		if (g[l][r]>0) return dp[l][r];
		long ans = a[r] - f(l,r-1);
		long ans1 = a[l] - f(l+1,r);
		if (ans<ans1) ans = ans1;
		
		g[l][r] = 1;
		dp[l][r] = ans;
		return ans;
	}
}


Measured memory_bytes: 167856
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int mod = 1e9+7;
int F[1000009];
int pw(int a,int n) {
	int y = 1;
	for (;n;n/=2) {
		if (n & 1) y = 1ll*y*a%mod;
		a = 1ll*a*a%mod;
	}
	return y;
}
int C(int n,int m) {
	if (n < m) return 0;
	return 1ll*F[n]*pw(F[m],mod-2)%mod*pw(F[n-m],mod-2)%mod;
}
main() {
	ios::sync_with_stdio(false);
	cin.tie(0);   // asdfs asdfgd
	 			 // sum (a = 0,x) C(x,a)*C(y,k-a) = x!y!/ (a!*(k-a)!)   / (x-a)!*(y + a - k)!
	int n,k;
	cin >> n ;
	F[0] = 1;
	for (int i = 1; i <= 1000000; i++)
		F[i] = 1ll*F[i-1]*i%mod;
	
	vector<vector<int> > cnt(n+2);
	for (int i = 0,a; i <= n; i++) {
		cin >> a;
		cnt[a].push_back(i);
	}
	int a,b;
	for (int i =  0; i <= n; i++) {
		if (cnt[i].size() == 2)
			a = cnt[i][0],
			b = cnt[i].back();
	}
	
	for (int k = 1;k <= n+1; k++) {
		int ans = C(n+1,k);
		int y = (a) + (n  - b);
		ans -= C(y,k-1);
		if (ans < 0) ans+=mod;
		cout << ans<<'\n';
		
	}
	
	
	
}

Measured memory_bytes: 16348
n = int(input())
h = [int(i) for i in input().split()]

movable = [0] * n
result = 0
prev = 10000000000
cnt = 0

for hi in h[::-1]:
    if hi < prev:
        result = max(result, cnt)
        cnt = 0
    else:
        cnt += 1
    prev = hi

if cnt == n - 1:
    print(cnt)
else:
    print(result)


Measured memory_bytes: 14252
#include<stdio.h>
int main(void)
{
    int t1,n1,t2,n2,t3,n3,t4,n4,z1,z2,z3,z4,a[5]={1,2,3,4};
	scanf("%d %d",&t1,&n1);
	scanf("%d %d",&t2,&n2);
	scanf("%d %d",&t3,&n3);
	scanf("%d %d",&t4,&n4);
	a[1]=6000;
	a[2]=4000;
	a[3]=3000;
	a[4]=2000;
	z1=a[t1]*n1;
	z2=a[t2]*n2;
	z3=a[t3]*n3;
	z4=a[t4]*n4;
	printf("%d\n",z1);
	printf("%d\n",z2);
	printf("%d\n",z3);
	printf("%d\n",z4);
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;


    ll N,M,K,Q;
    ll ans;
    ll A[100010];
struct UnionFind {
    vector< int > data;
    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) std::swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int k){
        return(-data[find(k)]);
    }
};
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M;
    UnionFind U(N+10);
    REP(i,N){cin>>A[i];}
    REP(i,M){
        int a,b;
        cin>>a>>b;
        U.unite(A[a-1],A[b-1]);
    }
    REP(i,N){
        ans+=U.same(i+1,A[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

const long long MOD=1000000007;

long long modmypower(long long a, long long b){
  if(b==1){
    return a;
  }else if(b%2==0){
    long long c=modmypower(a,b/2);
    return (c*c)%MOD;
  }else{
    long long c=modmypower(a,(b-1)/2);
    return (((c*c)%MOD)*a)%MOD;
  }
}   

long long modfac(long long x){
  if(x<=1) x=1;
  else for(int i=x-1; i>0; i--) x=(x*i)%MOD;
  return x;
}

long long modfp(long long n, long long k){
  long long nn=n;
  if(n<=1||k==0) n=1;
  else if(k>1) for(int i=nn-1; i>nn-k; i--) n=(n*i)%MOD;
  return n;
}

long long modinv(long long x){
  return modmypower(x,MOD-2);
}

long long modnck(long long n, long long k){
  if(k>n/2) k=n-k;
  return (modfp(n,k)*modinv(modfac(k)))%MOD;
}

int main(){
  int N,K; cin >> N >> K;
  
  for(int i=1; i<=K; i++){
    if(i==1) cout << N-K+1 << endl;
    else if(i-1>N-K) cout << 0 << endl;
    else{
      long long result=modnck(K-1,i-1);
      long long g=0;
      for(int j=i-1; j<=N-K; j++){
        g+=(N-K-j+1)*modnck(j-1,i-2);
        g%=MOD;
      }
      cout << (result*g)%MOD << endl;
    }
  }
}

Measured memory_bytes: 256
# Kadane
module Kadane
  def self.max_subarray(a)
    max_so_far = max_ending_here = -1.0 / 0
    a.each do |i|
      max_ending_here = [i, max_ending_here + i].max
      max_so_far = [max_so_far, max_ending_here].max
    end
    max_so_far
  end
end

answers = []

while n = gets.to_i
  break if n == 0
  a = []
  n.times { a << gets.to_i }
  answers << Kadane.max_subarray(a)
end

answers.each { |answer| puts answer }

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

int tax(int,int);

int main()
{
    int X,Y,S;
    int maximum;
    while(cin >> X >> Y >> S && X>0 && Y>0 && S>0)
    {
        maximum=0;
        for(int i=1;i<S;i++)
           for(int j=i;j<S;j++)
              if(tax(X,i)+tax(X,j)==S)
                maximum=max(maximum,tax(Y,i)+tax(Y,j));
        cout << maximum << endl;
    }
}

int tax(int x,int price)
{
    return(price*(100+x)/100);
}


Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

bool func(const string &s, bool left) {
  REP(i, s.size()) {
    if (i&&s[i]==s[i-1]) return 0;
    if (left && s[i] == 'R' || !left && s[i] == 'L') {
      return 0;
    }
    left ^= 1;
  }
  return 1;
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    string s;
    cin >> s;
    if (func(s, 0) || func(s, 1)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1036
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,x;
  cin >> n >> x;
  int a[n];
  rep(i,n)cin >> a[i];
  ll ans = 0;
  rep(i,n-1){
    if(a[i]+a[i+1]>x){
      ans += a[i]+a[i+1]-x;
      a[i+1]=max(0,a[i+1]-(a[i]+a[i+1]-x));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3952
#include <iostream>

using namespace std;

int main(void){

  double xa,xb,xc,xd;
  double ya,yb,yc,yd;

  while( cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd ){

    if( yb < yc || xb < xc || xd < xa || yd < ya ){
      cout << "NO" << endl;
      continue;
    }
    else cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	string S;
	cin >> N >> S;
	int white = 0; 
	for(char& c : S)
	{
		if(c == '.') white++;
	}
	int rightWhite = white;
	int leftBlack = 0;
	int ans = white;
	for(int inx = 0; inx < N; inx++)
	{
		if(S[inx] == '.')
		{
			rightWhite--;
		}
		else
		{
			leftBlack++;
		}
		ans = min(ans, leftBlack + rightWhite);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  type Per = List[Int]
  type Rot = Dice => Dice

  object DiceRoll extends Monoid[Rot]{

    def op(rot1: Rot, rot2: Rot): Rot = (dice: Dice) => rot2(rot1(dice))
    def zero: Rot = (dice: Dice)=>dice

    val north = List(2,6,3,4,1,5).map(_ - 1)
    val east = List(4,2,1,6,5,3).map(_ - 1)
    val ccw = List(1,4,2,5,3,6).map(_ - 1)

    def rot(perm: Per): Rot = (dice: Dice) => Dice(perm.map(dice.pip))

    def axial(f: Rot): List[Rot] = List(zero,f,op(f,f),op(op(f,f),f))

    def enumerateTop(f: Rot = zero, n: Int = 6): List[Rot] = {
      if(n<=0)List[Rot]()
      else if(n%2==0) f :: enumerateTop(op(f,rot(north)),n-1)
      else f :: enumerateTop(op(f,rot(east)),n-1)
    }

    def enumerate: List[Rot] = enumerateTop().flatMap( e => axial(rot(ccw)).map(op(e,_)))
  }

  case class Dice(pip: List[Int])

  def main(args: Array[String]): Unit = {
    val pip1 = readLine.split(" ").map(_.toInt).toList
    val pip2 = readLine.split(" ").map(_.toInt).toList
    val all1: List[Dice] = DiceRoll.enumerate.map(_(Dice(pip1)))
    println(if(all1.exists(_.pip.corresponds(pip2)(_ == _))) "Yes" else "No")
  }
}

Measured memory_bytes: 41492
a, b  = map(int, input().split())
diva = int(a / 0.08)
divb = int(b / 0.1)
start = min(diva,divb)
flag = 0
for i in range(start,start+100):
    if int(i * 0.08) == a and int(i*0.1) == b:
        print(i)
        flag = 1
        break
if flag == 0:
    print(-1)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    n *= 2;
    int num[n];
    rep(i,n){
        cin >> num[i];
    }
    sort(num,num+n);
    reverse(num,num+n);
    ll ans = 0;
    rep(i,n){
        if(i % 2 == 1) ans += num[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


int32_t main(){
	IOS
	vector<int>degree(4+1);
	for(int i=1;i<4;i++){
		int u,v;cin>>u>>v;
		degree[u]++;
		degree[v]++;
	}
	int ok = 1;
	for(int i=1;i<=4;i++){
		ok &= degree[i] <= 2;
	}
	cout << (ok?"YES":"NO");
		
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

int main() {

    int L , R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for(int i = L; i <= R; i++){
        if(i%d==0){
            ans++;
        }
    }
    cout << ans<< endl;


    return 0;
}

Measured memory_bytes: 3632
//RE
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 100;

vector<int> makeDx(string str){
    reverse(str.begin(), str.end());
    vector<int> ret(N, 0);
    REP(i, str.size()) ret[i] = str[i] - '0';
    return ret;
}

bool isOver80(vector<int> dx){
    FOR(i, 80, dx.size()) if(dx[i] != 0) return true;
    return false;
}

int main(){
    int n; cin >>n;
    REP(z, n){
        string str[2]; cin >>str[0] >>str[1];
        if(str[0].size() > 80 || str[1].size() > 80){
            cout <<"overflow" <<endl;
            continue;
        }

        vector<int> dx[2] = {makeDx(str[0]), makeDx(str[1])};
        vector<int> ans(N, 0);

        REP(i, max(dx[0].size(), dx[1].size())){
            ans[i] += (dx[0][i] + dx[1][i]);
            ans[i + 1] += (ans[i] / 10);
            ans[i] %= 10;
        }

        if(isOver80(ans)){
            cout <<"overflow" <<endl;
            continue;
        }

        reverse(ans.begin(), ans.end());
        int s = 0;
        while(ans[s] == 0 && s < ans.size() - 1) s++;
        //debug
        //cout <<"size = " <<ans.size() - s <<endl;
        FOR(i, s, ans.size()) cout <<ans[i];
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 1232
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        long[][] dp = new long[n][n];
        for (int i=0; i<n; i++) {
            dp[i][i] = a[i];
        }

        long[] g0;
        long[] g1;
        long L;
        long R;

        for (int i=n-2; i>-1; i--) {
            g0 = dp[i];
            g1 = dp[i+1];
            for (int j=i+1; j<n; j++) {
                L = a[i] - g1[j];
                R = a[j] - g0[j - 1];
                dp[i][j] = Math.max(L, R);
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}


Measured memory_bytes: 128600
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;
	long ans;
	if (S == "SUN")
		ans = 7;
	else if (S == "MON")
		ans = 6;
	else if (S == "TUE")
		ans = 5;
	else if (S == "WED")
		ans = 4;
	else if (S == "THU")
		ans = 3;
	else if (S == "FRI")
		ans = 2;
	else
		ans = 1;

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int xCnt = scan.nextInt();
		int yCnt = scan.nextInt();
		int xPoint = scan.nextInt();
		int yPoint = scan.nextInt();

		int[] xArray = new int[xCnt];
		for (int i = 0; i < xCnt; i++) {
			xArray[i] = scan.nextInt();
		}

		int[] yArray = new int[yCnt];
		for (int i = 0; i < yCnt; i++) {
			yArray[i] = scan.nextInt();
		}

		Arrays.sort(xArray);
		Arrays.sort(yArray);

		String result = null;
		if (xArray[xCnt-1] >= yArray[0]) {
			result = "War";
		} else {
			if (xArray[xCnt-1] > xPoint && yArray[0] <= yPoint) {
				result = "No War";
			} else {
				result = "War";
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23636
void main()
{
    long h, w;
    rdVals(h, w);
    string[] s = h.rdCol!string;

    bool[][] seen = new bool[][](h, w);
    long[] dely = [-1, 0, 1, 0], delx = [0, 1, 0, -1];
    long result;
    void bfs(long y, long x)
    {
        Grid[] que;
        que ~= Grid(y, x);
        seen[y][x] = true;
        long black, white;
        if (s[y][x] == '#') ++black;
        else ++white;
        while (!que.empty)
        {
            Grid now = que.front;
            que.popFront;
            foreach (dy, dx; zip(dely, delx))
            {
                Grid nxt = now;
                nxt.y += dy, nxt.x += dx;
                if (nxt.y < 0 || h <= nxt.y || nxt.x < 0 || w <= nxt.x) continue;
                if (seen[nxt.y][nxt.x]) continue;
                if (s[nxt.y][nxt.x] == s[now.y][now.x]) continue;

                que ~= nxt;
                seen[nxt.y][nxt.x] = true;
                if (s[nxt.y][nxt.x] == '#') ++black;
                else ++white;
            }
        }
        result += black * white;
    }

    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            if (!seen[i][j]) bfs(i, j);
        }
    }

    result.writeln;
}

struct Grid
{
    long y, x;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 5372
fn main() {
    let n: u32 = read();
    let k: u32 = read();
    let x: u32 = read();
    let y: u32 = read();
    let mut ans = 0;
    for i in 0..n {
        if i < k {
            ans += x;
        } else {
            ans += y;
        }
    }
    println!("{}", ans);
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1;
    }
    let mut r = n;
    for i in 0..n - 1 {
        r *= n - i - 1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n - m)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[100009];
int dp[100009];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        int mn=10000000009;
        int x;
        for(int j=i-k;j<i;j++){
            if(j<0) continue;
            x=abs(a[i]-a[j])+dp[j];
            mn=min(mn,x);
        }
        dp[i]=mn;
    }
    cout<<dp[n-1]<<endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    if (A % 2 == 0 && A == B && B == C) {
        cout << -1 << endl;
        return 0;
    }
    while (!(A % 2 || B % 2 || C % 2)) {
        int a, b, c;
        a = B / 2 + C / 2;
        b = A / 2 + C / 2;
        c = A / 2 + B / 2;
        A = a, B = b, C = c;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	/*int tests;
	cin >> tests;
	while (tests--) {*/
		int a, ans;
		for (int i = 1; i <= 5; i++) {
			cin >> a;
			if (a == 0)
				ans = i;
		}
		cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3160
using System;


namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] num = str.Split(' ');
            int a = int.Parse(num[0]);
            int b = int.Parse(num[1]);

            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if(a < b)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }

        }
    }
}

Measured memory_bytes: 8808
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, a, b) for(int i=(a); i<(int)(b); i++)

typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}

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

Measured memory_bytes: 256
from itertools import combinations
def triangle(l_tuple):
  if len(set(l_tuple)) == 3:
    if l_tuple[0] + l_tuple[1] > l_tuple[2] and l_tuple[1] + l_tuple[2] > l_tuple[0] and l_tuple[2] + l_tuple[0] > l_tuple[1]:
      return True
  return False
n = int(input())
l = list(map(int, input().split()))
l_comb = list(combinations(l, 3))
cnt = 0
for i in l_comb:
  if triangle(i):
    cnt += 1
print(cnt)

Measured memory_bytes: 20620
#include <bits/stdc++.h>
#define int long long
using namespace std;
int cnt[100007];
signed main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int sum = 0;
	for(int i = 0; i < k; i++) sum += a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3604
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
bool check(string s) {
	if (s == "dream" || s == "dreamer" || s == "erase" || s == "eraser")return true;
	else false;
}
signed main() {
	string s; cin >> s;
	vector<int>v(s.size(), 0);
	rep(i, 0, s.size()) {
		dump(i);
		if (s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase") {
			rep(j, i, 5 + i) v[j] = 1;
		}
		if (s.substr(i, 6) == "eraser") {
			rep(j, i, 6 + i) v[j] = 1;
		}
		if (s.substr(i, 7) == "dreamer") {
			rep(j, i, 7 + i)v[j] = 1;
		}
	}
	if (accumulate(all(v), 0) == s.size())cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1024