akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) < TMPend; (i)++)
#define RFOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) >= TMPend; (i)--)
#define REP(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

#define NEUTRAL -1
#define OP max
class Seg {
  public:
    int t = 1;
    vector<long long> dp;

    Seg(int n) {
      while (t <= n) {
        t *= 2;
      }

      dp = vector<long long>(t * 2 - 1, NEUTRAL);
    }

    int up(int node) {
      return (node - 1) / 2;
    }

    int down(int node) {
      return (node * 2) + 1;
    }

    void update(int i, long long x) {
      i += t - 1;
      dp[i] = x;

      while (i != 0) {
        i = up(i);
        int c = down(i);
        dp[i] = max(dp[c], dp[c + 1]);
      }
    }

    long long find(int l, int r, int node=0, int sl=0, int sr=-1) {
      if (sr < 0) sr = t;

      if (sr <= l || r <= sl) {
        return NEUTRAL;
      }

      if (l <= sl && sr <= r) {
        return dp[node];
      }

      int sc = (sl + sr) / 2;
      int c = down(node);
      return max(find(l, r, c, sl, sc), find(l, r, c + 1, sc, sr));
    }
};

int main(){
  int input(n);
  int list_input(h, n);
  long long list_input(a, n);

  Seg seg(n);
  rrep(i, n - 1) {
    long long maxv = max(seg.find(h[i], seg.t), 0ll) + a[i];
    seg.update(h[i], maxv);
  }

  out(seg.dp[0]);
}


Measured memory_bytes: 6656
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn=200000+10;

typedef long long ll;

ll sum;int a[maxn];

int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;++i) {
		cin>>a[i];
		sum+=a[i];
	}
	
	ll cnt=0,ans=1ll<<60;
	for(int i=1;i<n;++i){
		cnt+=a[i];
		ans=min(ans,abs(sum-cnt-cnt));
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  unordered_map<int, pair<int, int>> m;
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    if (i + 1 + arr[i] < 200000)
      m[i + 1 + arr[i]].first++;
    if (i + 1 - arr[i] > 0)
      m[i + 1 - arr[i]].second++;
  }
  
  long long c(0);
  for (const auto& [k, v]: m) {
    c += (long long) v.first * v.second;
  }
  cout << c << endl;
  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL a, b, c;

int main() {
	cin >> a >> b >>c;
	
	LL n = a + b + c, ans = 0;
	while(a % 2 + b % 2 + c % 2 == 0) {
		a = (n - a) / 2;
		b = (n - b) / 2;
		c = (n - c) / 2;
		ans++;
		if(a == b && b == c) { ans = -1; break; }
	}
	
	cout << ans << endl;
	
	return 0;
}


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

'''
A, B, C, K = map(int, input().split()) 

for i in range(K):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

ans = A - B

if ans >= 10**8:
    ans = 'Unfair'
elif ans >*10**8:
    ans = 'Unfair'

print(ans)
'''



A, B, C, K= map(int, input().split())

if K%2==1: 
    ans = B - A
else:
    ans = A - B

if ans >= 10**18 or (-1)*ans >= 10**18:
    ans = 'Unfair'

print(ans)  



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

int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i,n) cin >> t[i];
    int sum = accumulate(t.begin(), t.end(), 0);

    int m;
    cin >> m;
    rep(i,m){
        int p, x, diff;
        cin >> p >> x;
        diff = t[p-1] - x;
        cout << sum - diff << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int howmany[27][51];

int main(){
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> vec(N);
    rep(i, N){
        cin >> vec[i];
    }
    rep(i, N){
        rep(j, vec[i].size()){
            howmany[(int)vec[i].at(j) - 97][i]++;
        }
    }
    int mini[27];
    int m;
    rep(i, 26){
        m = 51;
        rep(j, N){
            if(m > howmany[i][j]){
                m = howmany[i][j];
            }
        }
        mini[i] = m;
    }
    char c;
    rep(i, 26){
        rep(j, mini[i]){
            c = i + 97;
            cout << c;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

if a == 1 and b == 1:
  print('Draw')
elif a == 1 and b != 1:
  print('Alice')
elif a != 1 and b == 1:
  print('Bob')
elif a != 1 and b != 1:
  if a > b:
    print('Alice')
  elif a < b:
    print('Bob')
  elif a == b:
    print('Draw')

Measured memory_bytes: 9096
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
string en="\n";
string t="hello";
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1;
    while(cin>>n>>m)
    {
        s=0;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=n;j++)
            {
                k=m-i-j;
                    if(k>=0 && k<=n) s++;
            }
        }
        cout<<s<<en;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;
  if(S==U){
    A -= 1;
  }
  else{
    B -= 1;
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
nk = list(map(int, input().split()))
lis = list(map(int, input().split()))

lis.sort()
lis.append(241543903)
num = []
score = 1
kind = 1
ans = 0

for j in range(nk[0]):
    if lis[j] == lis[j+1]:
        score += 1
    else:
        num.append(score)
        score = 1
        kind += 1

kind -= 1
num.sort()

if nk[1] >= kind:
    print(0)
else:
    for k in range(kind - nk[1]):
        ans += num[k]
    print(ans)


Measured memory_bytes: 25716
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        long n = Long.parseLong( in.nextLine() );

        long count = 0;
        for( long i = 1 ; i < n ; i++ ){
            count += i;
        }

        System.out.println(count);

    }

}

Measured memory_bytes: 23892
program main
  implicit none
  integer(8) :: n, i, m, dpless, dpsame
  character(100001) :: l
  m = 10 ** 9 + 7
  read *, l
  n = len_trim(l)
  dpsame = 1
  dpless = 0
  do i = 1, n
    dpless = dpless * 3
    dpless = modulo(dpless, m)
    if (l(i:i) == "1") then
      dpless = dpless + dpsame
      dpless = modulo(dpless, m)
      dpsame = dpsame * 2
      dpsame = modulo(dpsame, m)
    end if
  end do
  print "(i0)", modulo(dpless + dpsame, m)
end program main


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int N_MAX = 100000;
int N;
vector<int> A(N_MAX);
vector<int> dp(N_MAX, INF);

int main() {
    cin >> N;
    REP(i,N) {
        cin >> A[i];
        auto itr = lower_bound(ALL(dp), A[i]);
        *itr = A[i];
    }

    auto len = lower_bound(ALL(dp), INF);
    int ans = len - dp.begin();

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


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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

int main() {
    vll nums(4);
    for (int i = 0; i < 4; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    if (nums[0] == 1 && nums[1] == 4 && nums[2] == 7 && nums[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int a[85][85], b[85][85];
int dp[85][85][10000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> a[i][j];
	rep(i, h) rep(j, w) cin >> b[i][j];
	dp[0][0][abs(a[0][0] - b[0][0])] = 1;
	rep(i, h) rep(j, w){
		if(!i && !j) continue;
		rep(k, 10000){
			if(i) dp[i][j][abs(k - abs(a[i][j] - b[i][j]))] |= dp[i - 1][j][k];
			if(j) dp[i][j][abs(k - abs(a[i][j] - b[i][j]))] |= dp[i][j - 1][k];
			if(i) dp[i][j][abs(k + abs(a[i][j] - b[i][j]))] |= dp[i - 1][j][k];
			if(j) dp[i][j][abs(k + abs(a[i][j] - b[i][j]))] |= dp[i][j - 1][k];
		}
	}
	rep(i, 1000) if(dp[h - 1][w - 1][i]){
		cout << i << endl;
		return 0;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

int main(void) {
    int prev,current;
    int magic = 0;
    int N;
    cin>>N;

    cin>>prev;

    for(int i = 1;i < N;i++) {
        cin>>current;
        if(prev == current) {
            magic++;
            prev = -1;
        } else {
            prev = current;
        }
    }

    cout<<magic<<endl;

    return 0;
}


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

int main(){
  string S,T;
  cin >> S >> T;
  bool flag = true;
  for(int i=0;i<S.size();i++){
    if(S.at(i) != T.at(i)) flag = false;
  }
  if(S.size()+1 != T.size()) flag = false;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	_, M := nextInt(), nextInt()
	maxL, minR := 0, 100000
	for i := 0; i < M; i++ {
		maxL = max(maxL, nextInt())
		minR = min(minR, nextInt())
	}

	fmt.Println(max(minR-maxL+1, 0))
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
	int n;
    cin>>n;
    string c;
    cin>>c;
    int sw = 0;
    for(int i= 0;i<n;i++){
    	if(c[i] =='W'){
          sw++;
        }
    }
    int k = 0;
    for(int i = n-1;i>n-1-sw;i--){
    	if(c[i] =='R'){
          k++;
        }
    }
    cout<<k;
    return 0;
}

Measured memory_bytes: 3456
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = (1..N).map { readLine()!! }
    println("AC x ${S.count { it == "AC" }}")
    println("WA x ${S.count { it == "WA" }}")
    println("TLE x ${S.count { it == "TLE" }}")
    println("RE x ${S.count { it == "RE" }}")
}

Measured memory_bytes: 61552
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  ll is = 0;
  if ((x * 2 == W) && (y * 2 == H)) {
    is = 1;
  }
  double ans = W * H;
  ans /= 2.0;
  cout << setprecision(15) << ans;
  cout << ' ' << is << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {

	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			int max_occur = 0;
			TreeMap<String, Integer> counter = new TreeMap<String, Integer>();
			for(int i = 0; i < N; i++) {
				final String s = sc.next();
				
				if(!counter.containsKey(s)) {
					counter.put(s, 0);
				}
				
				final int occur = counter.get(s) + 1;
				counter.put(s, occur);
				
				max_occur = Math.max(max_occur, occur);
			}
			
			for(final Entry<String, Integer> entry : counter.entrySet()) {
				if(entry.getValue() == max_occur) {
					System.out.println(entry.getKey());
				}
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 62668
class Heap
  attr_reader :size

  def initialize(order: :asc)
    @size = 0
    @heap = []
  end

  def empty?
    @size.zero?
  end

  def push(val)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if @heap[parent] <= val

      @heap[index] = @heap[parent]
      index = parent
    end

    @heap[index] = val
  end

  alias_method :<<, :push

  def pop
    val = @heap.first
    root = @heap[size - 1]
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && @heap[right] < @heap[left]
        left = right
      end

      break if @heap[left] >= root

      @heap[index] = @heap[left]
      index = left
    end

    @heap[index] = root
    val
  end

  def top
    @heap.first
  end
end

N = gets.to_i
A = gets.split.map(&:to_i)

front = Heap.new
front_sum = 0

back = Heap.new
back_sum = 0

N.times do
  v = A.shift
  front.push(v)
  front_sum += v

  w = A.pop
  back.push(-w)
  back_sum += w
end

f_sums = [front_sum]
b_sums = [back_sum]

A.each do |a|
  if front.top < a
    front_sum -= front.pop
    front.push(a)
    front_sum += a
  end

  f_sums << front_sum
end

A.reverse_each do |a|
  if -back.top > a
    back_sum += back.pop
    back.push(-a)
    back_sum += a
  end

  b_sums << back_sum
end

puts f_sums.zip(b_sums.reverse).map { |a, b| a - b }.max



Measured memory_bytes: 32312
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  def genStr(s:String) = {
    val a = new ArrayBuffer[String]
    var i = 0

    while(i<s.length) {
      var c = s(i)
      var j = i
      var cnt = 0
      while(j<s.length && s(i)==s(j)) { j+=1;cnt+=1 }
      a += cnt.toString+s(i)
      i = j
    }
    a.mkString
  }
  Iterator.continually(readInt).takeWhile(_!=0).foreach { n =>
    var s = readLine
    (0 until n).foreach { _ => s = genStr(s) }
    println(s)
  }
}

Measured memory_bytes: 69608
#include <stdio.h>
int main(){
  int H , W;
  while(1){
    scanf("%d %d",&H,&W);
    if(H == 0&& W == 0)break;
    for(int i = 0; i < H; i++){
      if(i % 2 == 0){
        for(int k = 0; k < W; k++){
          if(k % 2 == 0)printf("#");
          else printf(".");
        }
      }
      else{
        for(int k = 0; k < W; k++){
          if(k % 2 == 0)printf(".");
          else printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1820
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LL long long
#define uLL unsigned long long
LL map[1000][1000];
int cmp(LL a,LL b,LL c,LL d)
{
	if (a==c)
	{
		return c-d;
	}
	else
	{
		return a-c;
	}
}
int islegal(char ch)
{
	if (ch=='.') {return 1;}
	if (ch=='#') {return 2;}
	return 0;
}
int solve(LL a,LL b)
{
	if (map[a][b]==2)
	{
		if (map[a-1][b]==2) {return 1;}
		if (map[a+1][b]==2) {return 1;}
		if (map[a][b+1]==2) {return 1;}
		if (map[a][b-1]==2) {return 1;}
		return 0;
	}
	else
	{
		return 1;
	}
}
int main()
{
	//freopen("in.in","r",stdin);
	LL i,j,k,a,b,c,ans,n,m;
	char ch;
	scanf("%lld%lld",&n,&m);
	ans=0;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			while (1)
			{
				scanf("%c",&ch);
				if (islegal(ch)!=0) {break;}
			}
			map[i][j]=islegal(ch);
		}
	}
	for (i=0;i<=n+1;i++) {map[i][0]=1;map[i][m+1]=1;}
	for (i=0;i<=m+1;i++) {map[0][i]=1;map[n+1][i]=1;}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (solve(i,j)==0)
			{
				goto FAIL;
			}
		}
	}
	printf("Yes\n");
	return 0;
	FAIL:
	printf("No\n");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=16,M=1e9+7;
int n,m,a[N],fac[1<<N],inv[1<<N],dp[N+1][1<<N][2];
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[x-y]%M*inv[y]%M;
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=0;i<m;i++)scanf("%lld",&a[i]);
	reverse(a,a+m);
	fac[0]=inv[0]=1;
	for (int i=1;i<1<<n;i++)fac[i]=fac[i-1]*i%M;
	for (int i=1;i<1<<n;i++)inv[i]=ksm(fac[i],M-2);
	dp[0][0][0]=1;
	for (int i=1;i<=m;i++)
		for (int j=0;j<1<<n;j++)
			for (int flag=0;flag<=1;flag++){
				dp[i][j][flag]=dp[i-1][j][flag];
				for (int k=0;k<n;k++)
					if ((1<<k)&j)
						(dp[i][j][flag]+=dp[i-1][j^(1<<k)][flag^1]*C((1<<n)-a[i-1]-(j^(1<<k)),(1<<k)-1)%M*fac[1<<k])%=M;
			}
	int ans=0;
	for (int i=0;i<1<<n;i++)
		(ans+=(dp[m][i][0]-dp[m][i][1]+M)*fac[(1<<n)-i-1])%=M;
	printf("%lld\n",ans*(1<<n)%M);
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll w, h;
    cin >> w >> h;
    vector<pair<ll, ll>> v;
    for (ll i = 0; i < w; i++)
    {
        ll tmp;
        cin >> tmp;
        v.push_back(make_pair(tmp, 0));
    }
    for (ll i = 0; i < h; i++)
    {
        ll tmp;
        cin >> tmp;
        v.push_back(make_pair(tmp, 1));
    }
    sort(ALL(v));
    ll ans = 0;
    w++;
    h++;
    for (auto now : v)
    {
        if (now.second == 1)
        {
            ans += w * now.first;
            h--;
        }
        else
        {
            ans += h * now.first;
            w--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main() {
	int a, b, c,d,e,f,g,i,j,s,t;
	scanf("%d", &a);//500の枚数
	scanf("%d", &b);//100の枚数
	scanf("%d", &c);//50の枚数
	scanf("%d", &d);//金額
	e = d / 50;//50円玉換算
	f = d/500;//500の最大数(理想
	for (i = 0; i <= f && i<=a; i++) {
		g = (d-500*i) / 100 ;//100の最大数(理想
		for (j = 0; j <= g && j<=b; j++) {
			t = (d - 500 * i - 100 * j) / 50;
			if (t <= c) {
				s++;
			}
			else {

			};
		};
	};
	printf("%d\n", s);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> pr(55556);
    rep(i,55556) pr.at(i)=i;
    vector<bool> isP(55556,true); isP.at(0)=isP.at(1)=false;
    for(int i=2; i<=55555; i++){
        if(isP.at(i)){
            for(int j=i*2; j<=55555; j+=i){
                isP.at(j)=false;
            }
        }
    }
    vector<int> prime;
    rep(i,55556){
        if(isP.at(i) and i%5==1) prime.push_back(i);
    }
    rep(i,n-1){
        cout<<prime.at(i)<<' ';
    }
    cout<<prime.at(n-1)<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e6 + 5;
int arr[MAX_N];

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int res = 0;
    for (int i = 0; i < k; i++)
    {
        res += arr[i];
    }
    cout << res << "\n";
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,a,b,c;
  cin>>n>>a>>b>>c;

  if(a+b+c==0) drop("No");

  vector<string> ss(n);
  for(int i=0;i<n;i++) cin>>ss[i];

  string ans;
  for(int i=0;i<n;i++){
    string s=ss[i];
    if(s=="AB"){
      if(a+b==0) drop("No");
      if(i+1<n and a==b){
        if(ss[i+1]=="AC"){
          ans+='A';
          a++;
          b--;
        }else{
          ans+='B';
          a--;
          b++;
        }
      }else if(a<=b){
        ans+='A';
        a++;
        b--;
      }else{
        ans+='B';
        a--;
        b++;
      }
    }
    if(s=="AC"){
      if(a+c==0) drop("No");
      if(i+1<n and a==c){
        if(ss[i+1]=="AB"){
          ans+='A';
          a++;
          c--;
        }else{
          ans+='C';
          a--;
          c++;
        }
      }else if(a<=c){
        ans+='A';
        a++;
        c--;
      }else{
        ans+='C';
        a--;
        c++;
      }
    }
    if(s=="BC"){
      if(b+c==0) drop("No");
      if(i+1<n and b==c){
        if(ss[i+1]=="AB"){
          ans+='B';
          b++;
          c--;
        }else{
          ans+='C';
          b--;
          c++;
        }
      }else if(b<=c){
        ans+='B';
        b++;
        c--;
      }else{
        ans+='C';
        b--;
        c++;
      }
    }
  }

  cout<<"Yes"<<newl;
  for(char c:ans) cout<<c<<newl;
  return 0;
}


Measured memory_bytes: 6704
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int X, Y;
    cin >> X >> Y;

    vector<int> xc(N), yc(M);

    for (int i = 0; i < N; ++i) {
        cin >> xc[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> yc[i];
    }

    for (int z = X+1; z <= Y; ++z) {
        bool f = true;
        for (int x: xc) {
            if (!(x < z)) {
                f = false;
                break;
            }
        }
        for (int y: yc) {
            if (!(y >= z)) {
                f = false;
                break;
            }
        }

        if (f) {
            cout << "No War" << endl;
            return 0;
        }
    }

    cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000000
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pi 3.14159
ll power(ll a,int n){
  if(n==0)
    return 1;
  if((n%2)==0)
    return power(a*a,n/2);
  else
    return a*power(a*a,n/2);    
}
vector<bool> mark;
void seive(ll N){
    mark.resize(N+1);
  for(ll i=2;i*i<=N;i++){
    if(!mark[i]){
       for(ll j=i*i;j<=N;j+=i){
         mark[j]=1;
       }
      }
  }
}
//vector<int> a1(150002),a2(150002);
int main(){
FASTIO
ll n,k;
cin>>n>>k;
vector<ll> a(n);
for(int i=0;i<n;i++){
  cin>>a[i];
}
vector<int> v(1);
v[0]=1;
vector<bool> v1(n);
v1[0]=true;
int p=a[0];
while(!(v1[p-1])){
  v.pb(p);
  v1[p-1]=true;
  p=a[p-1];
}
int i;
int ans=-1;
for(i=0;i<v.size();i++){
  if(v[i]==p){
    if(k==0){
        ans=v[i];
        break;
    }
    break;
  }
  else{
     if(k==0){
        ans=v[i];
        break;
     }
     k--;
  }
}
k=k%(v.size()-i);
if(ans==-1){
  ans=v[i+k];
}
cout<<ans;
return 0;
}


Measured memory_bytes: 5848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		char[] arr = sc.nextLine().toCharArray();
		sc.close();

		int totalWest=0;
		int[] wCounts = new int[arr.length];
		for(int i=0; i<wCounts.length; i++) {
			wCounts[i]=(i == 0 ? 0 : wCounts[i-1]);
			if (arr[i]=='W') {
				totalWest++;
				wCounts[i]++;
			}
		}

//		System.out.println("totalW: "+totalWest);
//		for(int i=0; i<wCounts.length; i++)
//			System.out.print(wCounts[i]+", ");
//		System.out.println();

		int min = arr.length;
		for(int i=0; i<arr.length; i++) {
			int tmpWest = totalWest-wCounts[i];
			int wHenkou = wCounts[i];
			if (arr[i]=='W')
				wHenkou--;
			int eHenkou = arr.length - (i+1) - tmpWest;
			int tmp = wHenkou + eHenkou;
//			System.out.println("\t"+i+": "+wHenkou+" + "+eHenkou+" = "+tmp+", tmpwest="+tmpWest);

			if (min > tmp)
				min = tmp;
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 30744
import collections as c

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

A=c.Counter(A)
A=list(A.items())
A.sort(key=lambda x: -x[1])
#print(A)
#print([A[i][1] for i in range(K)])

if len(A)<=K:
  print(0)
else:
  print(N-sum([A[i][1] for i in range(K)]))

Measured memory_bytes: 36236
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N,K,M;
	cin >> N>>K>>M;

	cout << min(K,M)<<" "<<max(ll(0),(K+M)-N) << endl;


}

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

int main() {
    string s;
    cin >> s;
    bool ans = true;
    if (s[0] != 'A') ans = false;
    string t = s.substr(2, s.size() - 3);
    int cnt = 0;
    for (char c : t) if (c == 'C') cnt++;
    if (cnt != 1) ans = false;
    int large = 0;
    for (char c : s) if ('A' <= c && c <= 'Z') large++;
    if (large != 2) ans = false;
    cout << (ans ? "AC" : "WA") << endl;
}


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

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

bool primo(int x) {
  if (x == 3) return 1;
  for (int i = 2; i < x; i++) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

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

  int x;
  cin >> x;
  if (x == 2) cout << 2 << ende;
  else {
    if (!(x & 1)) x++;
    while (!primo(x)) x+=2;
    cout << x << ende;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var r = n
    for (i in 0..n) {
        var count = 0

        var t = i
        while (t > 0) {
            count += t % 9
            t /= 9
        }

        t = n - i
        while (t > 0) {
            count += t % 6
            t /= 6
        }

        r = Math.min(r, count)
    }
    println(r)
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	char c;
	cin >> c;
	if(isupper(c)) {
		cout << "A";
	}
	else {
		cout << "a";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3648
def insert(string, hash_list):
    hali = hash_list
    if string not in hali:
        hali[string] = 1
    return hali


def find(string, hash_list):
    hali = hash_list
    return string in hali



n = int(input())
words = {}
operate = [list(input().split()) for i in range(n)]

for i in operate:
    if i[0] == "insert":
        insert(i[1], words)
    elif i[0] == "find":
        if find(i[1], words):
            print("yes")
        else:
            print("no")

Measured memory_bytes: 260496
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var k =int.Parse(Console.ReadLine());
	var g = 0;
    for(var a = 1;a<=k;a++){
      for(var b =1;b<=k;b++){
        for(var c =1;c<=k;c++){
          var max =1;
          var array = new[] { a,b,c};
　　　　　　var min = array.Min();
            for(var i=2;i<=min;i++){            
              if(a%i == 0&&b%i==0&&c%i==0){
                max = i;
              }
            }
          g += max;
        }
      }
    }
    Console.WriteLine(g);
  }
}

Measured memory_bytes: 22676
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc  = new Scanner(System.in);
      	int n = sc.nextInt();
      	Integer[] a = new Integer[n];
      	for(int i = 0; i < n; i++){
        	a[i] = sc.nextInt();
        }
      
      	Arrays.sort(a, Collections.reverseOrder());
      	int Alice = 0;
      	int Bob = 0;
      	for(int i = 0; i < n; i++){
        	if(i%2==0) Alice += a[i];
          	else Bob += a[i];
        }
      
      	System.out.println(Alice - Bob);
    }
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int a,b,t;
int main() {
    cin >> a >> b >> t;
    int c = t/a;
    int ans = c*b;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

}


Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main(){
    long long t,n;
    for(int i=0;i<4;i++){
        cin>>t>>n;
        if(t==1){
            cout<<6000*n<<endl;
        }
        else if(t==2){
            cout<<4000*n<<endl;
        }
        else if(t==3){
            cout<<3000*n<<endl;
        }
        else if(t==4){
            cout<<2000*n<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3088
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    S=input()
    a=ord("a")

    for i in range(26):
        temp=a+i
        for s in S:
            if s==chr(temp):break
        else:print(chr(temp));return
    print("None")
                

            
        
#%%submit!    
resolve()

Measured memory_bytes: 39280
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int a = arr[0];
			int b = arr[1];

			int num;
			int cnt;

			if (a < b)
			{
				num = a;
				cnt = b;
			}
			else
			{
				num = b;
				cnt = a;
			}

			for (int i = 0; i < cnt; i++)
			{
				Console.Write(num);
			}

		}


	}


}


Measured memory_bytes: 11220
#!/usr/bin/ruby
#encoding: utf-8

$n,k = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)

$likenum = [0,1,2,3,4,5,6,7,8,9]
(0..k-1).each do |i|
  $likenum.delete(d[i])
end

$ans = 100100100

def dfs(x)
  #puts "x = #{x}"
  if x.to_i >= $n 
    if $ans >= x.to_i
      $ans = x.to_i
    end
    return
  end
 
  a = $likenum.size
  (0..a-1).each do |i|
    dfs(x + $likenum[i].to_s)
  end
end

#puts dfs($likenum.min.to_s)
if $likenum.min != 0
  dfs("")
else 
  dfs($likenum[1].to_s)
end

puts $ans


Measured memory_bytes: 1788
#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() {
    ll a, b;
    cin >> a >> b;
    ll c = abs(a+b);
    if (c%2 == 1) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << c/2 << endl;  
    }

    return 0;
}

Measured memory_bytes: 3616
y, m, _d = gets.split("/").map(&:to_i)

if y >= 2019 && m >= 5
  # 2019/05以降はTBD
  puts "TBD"
elsif y == 2019 && m <= 4
  # 2019/01~04はHeisei
  puts "Heisei"
elsif y <= 2018
  # 2018以前はHeisei
  puts "Heisei"
end


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

int main() {
  
  //入力処理
  int H, W;
  string X;
  cin >> H >> W;
  W += 2;
  
  //上#
  for (int i = 0; i < W; i++) {
	cout << "#";
  }
  cout << endl;
  
  //文字列
  for (int i = 0; i < H; i++) {
    cin >> X;
    cout << "#";
    cout << X;
    cout << "#" << endl;
  }
  
  //下#
  for (int i = 0; i < W; i++) {
    cout << "#";
  }
  cout << endl;
  
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e5+5;
int n;
int a[maxn],nxt[maxn];
ll suf[maxn],pre[maxn];
char opt[maxn][2];
int main(){
	read(n);
	opt[1][0]='+';
	rep(i,1,n){
		scanf("%d",&a[i]);
		if(i<n)scanf("%s",opt[i+1]);
	}
	rep(i,1,n)
		if(opt[i][0]=='+')pre[i]=pre[i-1]+a[i];
		else pre[i]=pre[i-1]-a[i];
	per(i,n,1)suf[i]=suf[i+1]+a[i];
	int lst=n+1;
	ll ans=pre[n];
	per(i,n,1)if(opt[i][0]=='-'){
		if(lst!=n+1)ans=max(ans,pre[i-1]-suf[i]+2*suf[lst]);
		lst=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N,M;
    Scd2(N,M);

    char a[66][66] = {{}};
    char b[66][66] = {{}};

    Rep(i,N){
        Scs(a[i]);
    }
    Rep(i,M){
        Scs(b[i]);
    }

    int di = 0, dj = 0;
    bool ok = true;
    bool ans = false;
    Rep(i,N-M+1){
        Rep(j,N-M+1){
            ok = true;
            Rep(di,M){
                Rep(dj,M){
                    if( a[i+di][j+dj] != b[di][dj] ) ok = false;
                    if( !ok ) break;
                    if( di == dj && dj == M-1 ) ans = true;
                }
                if( !ok ) break;
            }
        }
    }
    YesNo(ans);

    return 0;
}



Measured memory_bytes: 256
h,w=map(int,input().split())
S=[]
S.append(['0']*(w+2))
for i in range(h):
    X=['0']
    X.extend(list(input()))
    X.extend(['0'])
    S.append(X)
S.append(['0']*(w+2))    
    
for i in range(1,h+1):
    for j in range(1,w+1):
        cnt=0
        if S[i][j]=='.':
            for a in range(-1,2):
                for b in range(-1,2):
                    if a==0 and b==0: 
                        continue
                    if S[i+a][j+b]=='#':
                        cnt+=1
            S[i][j]=str(cnt)
    Y=''.join(S[i][1:w+1])
    print(Y)


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

int main(){
    int N;
    string S;

    cin >> N >> S;

    int r=0, g=0, b=0;

    rep(i,N){
        if(S[i]=='R') r++;
        else if(S[i]=='G') g++;
        else if(S[i]=='B') b++;
    }

    ll ans = (ll)r*(ll)g*(ll)b;
    rep(i,N) rep(j,N){
        if(j<=i) continue;
        if(2*j-i<N){
            if(S[i] != S[j] && S[i] != S[2*j-i] && S[j] != S[2*j-i]) ans--;
        }   
    }
    if(ans<0) ans=0;
    print(ans);
    return 0;
}

Measured memory_bytes: 3628
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
ll wasum(double n, double m) {
	return (n + m)*(m - n + 1) / 2;
}
int main()
{
	double n, m, d;
	double sum;
	cin >> n >> m >> d;
	if (d == 0) {
		cout << (m - 1) / n;
		return 0;
	}
	sum = (m - 1) / n;
	sum *= (n - d);
	sum /= wasum(1, n-1);
	sum *= (n-1);
	std::cout << std::fixed;
	cout << std::setprecision(10) << sum;
}


Measured memory_bytes: 384