akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  string s, t;
  cin >> s >> t;
  int ans = t.size();
  int n = s.size();
  int k = t.size();
  rep(i, n-k+1){
    int num = 0;
    rep(j, k){
      if(s[i+j] == t[j])num++;
    }
    ans = min(ans, k - num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	ll a,b,x;
	cin>>a>>b>>x;
	if(a==b){
		if(a%x==0){
			ce('1')
		}else{
			ce('0')
		}
	}else{
	ll ans=-((a-1)/x)+b/x;
if(a==0&&x!=1){ans++;}
	ce(ans)
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>

int isPrime( int );

int main( void ) {
	int a, d, n, fig;

	for ( ; scanf( "%d %d %d", &a, &d, &n ), a; printf( "%d\n", fig - d ) )
		for ( fig = a; n; fig += d )
			if ( isPrime( fig ) )
				n--;

	return 0;
}

int isPrime( int n ) {
	int i;

	for ( i = 2; i * i <= n; i++ )
		if ( n % i == 0 )
			return 0;

	return n != 1;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e15;
typedef pair<int,int> ii;
typedef vector<int> vi;

const int max_item_cnt=100;
const int max_knapsack_size=1e5;
ll W[max_item_cnt],V[max_item_cnt];
ll dp[2][max_knapsack_size];
//dp[i][j] - max sum of values with j space from 1-th to i-th (only i's parity matters)
 
int main(){
	ll n,w;
	cin>>n>>w;
	for(int i=1;i<=n;i++){
		cin>>W[i]>>V[i];
	}
	
	for(int i=1;i<=n;i++){
		int t=i%2;
		for(int j=0;j<=w;j++){
			if(j>=W[i]){
				dp[t][j]=max(dp[!t][j],dp[!t][j-W[i]]+V[i]);
			}else{
				dp[t][j]=dp[!t][j];
			}
		}
	}
	ll ans=dp[n%2][w];
	cout<<ans;
 
	return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VEC;

int main() {
  string S,T;cin>>S>>T;
  int N = S.size();
  vector<bool> s_checked(N,false);

  // 順番にSの文字を見ていく
  // 文字を取得したら、それと同じ文字が以降にないかチェックして、全てのidxを取得
  // Tの文字の該当IDXが全て同じ文字かを判定
  // 最後まで行けたらYes
  // 途中で引っかかったらNo
  REP(i,N){
    if (s_checked[i]) continue;

    s_checked[i] = true;
    VEC idxs{i};
    FOR(j,i+1,N) if (S[j] == S[i]) {
      idxs.push_back(j);
      s_checked[j] = true;
    }
    char tchar = T[i];
    for (auto idx:idxs) {
      if (T[idx] != tchar) {
        OUT("No");
        return 0;
      }
    }
  }

  vector<bool> t_checked(N,false);
  REP(i,N){
    if (t_checked[i]) continue;

    t_checked[i] = true;
    VEC idxs{i};
    FOR(j,i+1,N) if (T[j] == T[i]) {
      idxs.push_back(j);
      t_checked[j] = true;
    }
    char schar = S[i];
    for (auto idx:idxs) {
      if (S[idx] != schar) {
        OUT("No");
        return 0;
      }
    }
  }
  OUT("Yes");

  return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> s;

    for (int i = 0; i < n; i++) {
        char st[11];
        cin >> st;
        s.insert(st);
    }
    cout << s.size() << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	cout << ((s<="2019/04/30")? "Heisei" : "TBD") << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	string X, Y;
	bool rev = false;
	for(int i=0; i<Q; i++){
		int t;
		cin >> t;
		if(t==1){
			rev = !rev;
			continue;
		}
		int f;
		string c;
		cin >> f >> c;
		if(f==1 && rev || f==2 && !rev){
			Y.append(c);
		} else {
			X.append(c);
		}
	}

	if(!rev){
		reverse(X.begin(), X.end());
		cout << X << S << Y << endl;
	} else {
		reverse(S.begin(), S.end());
		reverse(Y.begin(), Y.end());
		cout << Y << S << X << endl;
	}

	return 0;
}


Measured memory_bytes: 1088
#include <iostream>
using namespace std;
 
int main(){
    long long h,w;
    long long ans = 0;
    cin >> h >> w;
    if(h == 1 or w == 1){
        ans = 1;
    }
    else{
        ans = (w * h + 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import collections

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
cnt=collections.Counter(arr)
for key in cnt.keys():
  if cnt[key]==2:
    K=key
pos1=-1
pos2=-1
for i in range(n+1):
  if arr[i]==K:
    if pos1==-1:
      pos1=i
    else:
      pos2=i
A=pos1
B=pos2-pos1-1
C=n-pos2
facts=[1]
for i in range(1,n+1):
  facts.append((facts[-1]*i)%mod)
revfacts=[1]
for i in range(1,n+1):
  revfacts.append(pow(facts[i],mod-2,mod))
ans=[]
for i in range(1,n+2):
  ways1=0
  if i<=A+B+C:
    ways1=(facts[A+B+C]*revfacts[i]*revfacts[A+B+C-i])%mod
  ways2=0
  if i>=2 and i-2<=A+B+C:
  	ways2=(facts[A+B+C]*revfacts[i-2]*revfacts[A+B+C-(i-2)])%mod
  ways3=0
  if i>=1 and i-1<=A+C:
    ways3=(facts[A+C]*revfacts[i-1]*revfacts[A+C-(i-1)])%mod
  ways4=0
  if i>=1 and i-1<=A+B+C:
    ways4=(2*facts[A+B+C]*revfacts[i-1]*revfacts[A+B+C-(i-1)]-2*ways3)%mod
  ans.append((ways1+ways2+ways3+ways4)%mod)
for val in ans:
  print(val)

Measured memory_bytes: 77160
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	W, a, b := nextInt(), nextInt(), nextInt()
	if a > b {
		a, b = b, a
	}
	fmt.Println(MaxOf(0, b-(a+W)))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

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

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

   int N,X;
   cin>>N>>X;
   vector<int>m(N);
   for(int i=0;i<N;i++)cin>>m[i];
   int ans = 0;
   for(int i=0;i<N;i++){
      ans++;
      X-=m[i];
   }
   int MIN = *min_element(m.begin(),m.end());
   ans += X/MIN;
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
vector<int>row[3*maxn];
vector<int>col[3*maxn];


int32_t main(){
	fastio();
	int n,m,w;
	cin >> n >> m >> w;
	map<int,int>r,c;
	set<pair<int,int>>s;
		for(int i = 0; i < w; i++){
		int a,b;
		cin >> a >> b;
		r[a]++;
		c[b]++;
		s.insert({a,b});
		row[a].push_back(b);
		col[b].push_back(a);
	}
	int ans = 0;
	set<pair<int,int>>cnt;
	for(int i = 1; i <= m; i++){
		cnt.insert({col[i].size(), i});
	}
	for(int i = 1; i <= n; i++){
		for(auto j:row[i]){
			ans = max(ans,(int)row[i].size() + (int)col[j].size() - 1);
		}
	}
	for(int i = 1; i <= n; i++){
		for(auto j:row[i]){
			cnt.erase({col[j].size(),j});
		}
		if(cnt.size() > 0){
			pair<int,int>p = *cnt.rbegin();
			ans = max(ans,(int)row[i].size() + p.ff);
		}
		for(auto j:row[i]){
			cnt.insert({col[j].size(),j});
		}
	}
	cout << ans;
}

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

#include <atcoder/all>
using namespace atcoder;

using namespace std;
using ll = long long;

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

    dsu d(N + 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        d.merge(a, b);
    }
    vector<vector<int>> g = d.groups();
    cout << g.size() - 2 << endl;

    return 0;
}


Measured memory_bytes: 9036
n, m = map(int, input().split())

graph1 = [[] for _ in range(n * 3)]

for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph1[u * 3 + 0].append(v * 3 + 1)
    graph1[u * 3 + 1].append(v * 3 + 2)
    graph1[u * 3 + 2].append(v * 3 + 0)

s, t = map(int, input().split())
s -= 1
t -= 1
s = s * 3
t = t * 3

from heapq import heappush, heappop


def dijkstra(graph: list, n: int, start: int, INF: int = float('inf')) -> list:
    # graph[node] = [(cost, to)]
    dist = [INF] * n
    num = [0] * n

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        _, v_from = heappop(heap)
        for v_to in graph[v_from]:
            dist_cand = dist[v_from] + 1
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist
    # dist = [costs to nodes]


inf = float('inf')
dist = dijkstra(graph1, n * 3, s)
if dist[t] == inf:
    print(-1)
else:
    print(dist[t] // 3)


Measured memory_bytes: 105328
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> a;
    for (int i  = 0; i < N; i++) {
        int _a;
        cin >> _a;
        a.push_back(_a);
    }

    int min_cost = 1000000000;
    for (int y = -100; y <= 100; y++) {
        int cost = 0;
        for (int i = 0; i < N; i++) {
            cost += (a[i] - y) * (a[i] - y);
        }
        min_cost = min(cost, min_cost);
    }
    cout << min_cost << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
ma = []
ma.append(b[0])
for i in range(len(b)-1):
    if b[i] <= b[i+1]:
        ma.append(b[i])
    else:
        ma.append(b[i+1])
"""
if b[-2] <= b[-1]:
    ma.append(b[-2])
else:
    ma.append(b[-1])
"""
ma.append(b[-1])
print(sum(ma))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define _  << ' ' <<
#define squ(x)  ((x) * (x))
#define VAR_NAME(var)  cout << #var << " : ";
#define debug(var)  VAR_NAME(var); view(var);
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T>
using VVV = vector<vector<vector<T>>>;
//// view vector functions
template<typename T>
void view(T e){
  cout << e << endl;
}
template<typename T>
void view(vector<T>& v){
  for(const auto& e : v){
    cout << setw(5)<< e << " ";
  }
  cout << endl;
}
template<typename T>
void view(const vector<vector<T>>& vv){
  for(const auto& v : vv){
    for(const auto& e : v)
      cout << setw(5) << e << " ";
    cout << endl;
  }
}

int main(){
  int i, j;
  int N, M;
  cin >> N >> M;
  V<int> l(M);
  V<int> r(M);
  for(i=0; i<l.size(); ++i) cin >> l[i] >> r[i];
  int lmax = *max_element(l.begin(), l.end());
  int rmin = *min_element(r.begin(), r.end());
  int dif = rmin - lmax;
  cout << (dif>=0? dif+1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<math.h>
#include<stack>
#include<map>
#include<queue>
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define eps 1e-9
using namespace std;
long long n,m;
long long a[100005];
long long b[100005],c[100005];
int main()
{
	scanf("%lld%lld",&n,&m);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	long long ans=0;
	for(long long i=1;i<n;i++)
	{
		if(a[i+1]>a[i])
		{
			ans+=a[i+1]-a[i];
			b[a[i]+2]++;
			b[a[i+1]+1]--;
			c[a[i+1]+1]-=(a[i+1]-a[i]-1);
		}
		else
		{
			ans+=m-a[i]+a[i+1];
			b[a[i]+2]++;
			b[2]++;
			b[a[i+1]+1]--;
			c[1]+=m-a[i];
			c[a[i+1]+1]-=a[i+1]+m-a[i]-1;
		}
	}
	//cout<<ans<<endl;
	for(long long i=1;i<=m;i++)
	{
		b[i]+=b[i-1];
		//cout<<i<<' '<<b[i]<<endl;
	}
	long long mx=0;
	for(long long i=1;i<=m;i++)
	{
		c[i]+=c[i-1]+b[i];
		//cout<<i<<' '<<c[i]<<endl;
		mx=max(mx,c[i]);
	}
	printf("%lld\n",ans-mx);
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a[200000],i,cnt;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	cnt=0;
	for(i=1;i<=n;i++){
		if(a[i]!=i-cnt)	cnt++;
	}
	if(cnt==n){
		printf("-1\n");
	}
	else	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2472
N = int(input())
A = list(map(int,input().split()))
m = 10 ** 18
ans = 1
if 0 in A:
    print(0)
else:
    for i in range(N):
        if A[i] >= m:
            print(-1)
            exit()
    A = sorted(A)
    A = reversed(A)
    for i in A:
        ans *= i
        if ans > m:
            ans = -1
            break
    print(ans) 

Measured memory_bytes: 21576
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int K = 5555;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<bitset<K>> dp_front(n + 2);
  vector<bitset<K>> dp_back(n + 2);
  dp_front[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp_front[i] = dp_front[i - 1] | (dp_front[i - 1] << a[i]);
  }
  dp_back[n + 1][0] = 1;
  for (int i = n; i >= 1; i--) {
    dp_back[i] = dp_back[i + 1] | (dp_back[i + 1] << a[i]);
  }
  int ans = 0;
  auto eval = [] (const vector<int>& v, int left, int right) {
    if (left <= 0) return v[right] > 0;
    return (v[right] - v[left - 1]) > 0;
  };
  for (int i = 1; i <= n; i++) {
    vector<int> f(K);
    vector<int> b(K);
    for (int j = 0; j < K; j++) {
      f[j] = dp_front[i - 1][j];
      if (j > 0) f[j] += f[j - 1];
    }
    for (int j = 0; j < K; j++) {
      b[j] = dp_back[i + 1][j];
      if (j > 0) b[j] += b[j - 1];
    }
    bool need = false;
    for (int j = 0; j < k; j++) {
      if ((dp_front[i - 1][j] || dp_back[i + 1][j]) && (j >= max(0, k - a[i]))) need = true;
      if (dp_front[i - 1][j] && eval(b, k - j - a[i], k - 1 - j)) need = true;
      if (dp_back[i + 1][j] && eval(f, k - j - a[i], k - 1 - j)) need = true;
    }
    if (!need) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7168
using namespace std;
#define ll long long
#include <iostream>
#include <bits/stdc++.h>

int main(){
    string s;
    cin >> s;
    char a[s.size()];
    for ( int i = 0; i < s.size(); i ++ ){
        a[i] = s[i];
    }
    int res = 0;
    for ( int i = 0; i < s.size() / 2; i ++ ){
        if ( a[i] != a[s.size() - 1 - i ] ) res ++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;

int main(){
  int n, temp = 1;
  int now = 0;
  int count = 0;
  cin >> n;
  string s;
  if(n == 0) cout << 0 <<endl;
  for(int i = 0 ; n != 0; ++i){
    if(n % 2 == 0){
      s = '0' + s;
    } else {
      n -= 1;
      s = '1' + s;
    }
    n /= -2;

  }
      cout << s << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair <ll,ll> pll;

const ll Inf = 1e18;

int main()
{
    ll n, D, A;    cin >> n >> D >> A;

    vector <pll> a(n);

    for(pll& p : a) scanf("%lld%lld", &p.first, &p.second);

    sort(a.begin(), a.end());

    vector <vector <ll>> In(n);
    vector <vector <ll>> Out(n);

    ll Ans = 0;
    ll Sum = 0;

    for(ll i = 0; i < n; i++)
    {
        ll x = a[i].first;
        ll H = a[i].second;

        H -= Sum;

        if(H > 0)
        {
            ll j = upper_bound(a.begin(), a.end(), pll(x + 2 * D, Inf)) - a.begin() - 1;

            ll Need = (H + A - 1) / A;

            Ans += Need;
            In[i].push_back(Need * A);
            Out[j].push_back(Need * A);
        }

        for(ll y : In[i])   Sum += y;

        H -= Sum;

        for(ll y : Out[i])  Sum -= y;
    }

    cout << Ans << endl;
}


Measured memory_bytes: 25216
#include<stdio.h>

int main()
{
  int a,b,c,k;
  scanf("%d%d%d%d",&a, &b, &c, &k);
  if(a>=k){
    printf("%d\n",k);
  } else if(a<k && a+b>=k){
    printf("%d\n",a);
  } else if(a+b<k){
    printf("%d\n",2*a+b-k);
  }
  return 0;
 }


Measured memory_bytes: 1692
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }

    int ans = 0;
    rep(i, n - 1){
        if(h[i] >= h[i + 1]){
            int j = i;
            while(j < n - 1 && h[j] >= h[j + 1]){
                ++j;
            }
            chmax(ans, j - i);
            i = j - 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

#define pi 3.141592653589

int main() {

  double r=0;
  cin >> r;

  double S = r*r*pi;
  double L = 2*r*pi;

  cout << fixed << setprecision(10) << S << " ";
  cout << fixed << setprecision(10) << L << endl;
  
}


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

int main() {
    std::string s;

    while (std::cin >> s, s != "-") {

        int m;
        std::cin >> m;

        for (int i = 0; i < m; ++i) {
            int h;
            std::cin >> h;

            std::string t = s;
            s = t.substr(h, t.size() - h) + t.substr(0, h);
        }

        std::cout << s << std::endl;
    }
}
    


Measured memory_bytes: 3156
function main(input){
  const args=input.split(' ');
  const num1=parseInt(args[0]);
  const num2=parseInt(args[1]);
  
  if(num1*num2 % 2 ===0){
    console.log('Even');
  }else{
    console.log('Odd');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}



int main() {
    int N,P;
    cin >> N >> P;


    int odd_num = 0,even_num = 0;
    REP(i,N){
        int a;cin >> a;
        if(a % 2 == 0) even_num++;
        else odd_num++;
    }

    if(odd_num==0){
        if(P==1){
            pl(0)
        } else {
            pl((ll)pow(2,even_num))
        }
    } else {
        pl((ll)pow(2,N-1))
    }

    return 0;
}


Measured memory_bytes: 256
/* -> Written by <-
   -----------
  |K_A_Z_A_M_A|
  |___________|
  |    _    |
  |   (^_^)   |
  |  /( | )\  |
  |____|_|____|
    H O A N G
*/

#define Task ""
#define F first
#define S second
#define push_back pb
#define bit(x, i) (x >> i) & 1
#define inf 1e9
#define INF 1e18
#define fr(i, a, b) for (int i = (a); i <= (b); i ++)
#define FR(i, a, b) for (int i = (a); i < (b); i ++)


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int maxn = 2005;

int s;
ll dp[maxn];

void Solve(int test_case)
{
    cin >> s;
    dp[0] = 1;
    for (int i = 1; i <= s; i ++)
        for (int j = i; j >= 3; j --) dp[i] = (dp[i] + dp[i-j]) % MOD;
    cout << dp[s];
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    if(fopen(Task".inp", "r"))
    {
        freopen(Task".inp","r",stdin);
        freopen(Task".out","w",stdout);
    }
    int test_case = 1;
//    cin >> test_case;
    for (int i = 1; i <= test_case; i ++)
        Solve(i);
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll calc(vector<PL> a){
    int n = a.size();
    ll mi1 = 1e18, ma1 = 0;
    ll mi2 = 1e18, ma2 = 0;
    REP(i,n){
        mi1 = min(mi1, a[i].first);
        ma1 = max(ma1, a[i].first);
        mi2 = min(mi2, a[i].second);
        ma2 = max(ma2, a[i].second);
    }
    return (ma1 - mi1) * (ma2 - mi2);
}

ll calc2(vector<PL> a){
    int n = a.size();
    ll mi = 1e18, ma = 0;
    REP(i,n){
        mi = min(mi, a[i].first);
        ma = max(ma, a[i].second);
    }
    ll dif = ma - mi;
    sort(ALL(a));
    ll ret = a[n-1].first - a[0].first;
    mi = 1e18, ma = a[n-1].first;
    REP(i,n){
        ma = max(ma, a[i].second);
        mi = min(mi, a[i].second);
        ret = min(ret, ma - min(mi, a[i+1].first));
    }
    return dif * ret;
}

int main() {
    int n;
    cin >> n;
    vector<PL> a(n);
    REP(i,n){
        scanf("%lld %lld", &a[i].first, &a[i].second);
        if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
    }

    cout << min(calc(a), calc2(a)) << endl;

    return 0;
}


Measured memory_bytes: 9600
a,b,c,d = [int(i) for i in input()]

if(a+b+c+d == 7):
    print("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
elif(a+b+c-d == 7):
    print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
elif(a+b-c+d == 7):
    print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
elif(a-b+c+d == 7):
    print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
elif(a+b-c-d == 7):
    print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
elif(a-b-c+d == 7):
    print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
elif(a-b+c-d ==7):
    print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
elif(a-b-c-d == 7):
    print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))
else:
    print("該当なし")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
	int N, K;
	std::cin >> N >> K;

	std::vector<int> h(N);
	for(int i = 0; i < N; i++) {
		std::cin >> h[i];
	}

	std::sort(h.begin(), h.end());

	int min = h[K - 1] - h[0];
	for(int i = 1;; i++) {
		const int j = i + K - 1;
		if(j >= N) {
			break;
		}
		const int value = h[j] - h[i];
		if(value < min) {
			min = value;
		}
	}

	std::cout << min << std::endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, d, mod = 1e9 + 7;
string s;
long long dp[ 10005 ][ 105 ][ 2 ];

long long solve( int pos, int sum, bool allowed )
{
	if( pos == n )
	{
		return !sum;
	}
	if( dp[ pos ][ sum ][ allowed ] != -1 )
	{
		return dp[ pos ][ sum ][ allowed ];
	}
	dp[ pos ][ sum ][ allowed ] = 0;
	for( int i = 0; i <= ( allowed ? 9 : s[ pos ] - '0' ); ++i )
	{
		dp[ pos ][ sum ][ allowed ] += solve( pos + 1, ( sum + i ) % d, ( allowed || i < ( s[ pos ] - '0' ) ) );
		if( dp[ pos ][ sum ][ allowed ] >= mod )
		{
			dp[ pos ][ sum ][ allowed ] -= mod;
		}
	}
	return dp[ pos ][ sum ][ allowed ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> s >> d;
	n = s.length();
	memset( dp, -1, sizeof( dp ) );
	cout << ( solve( 0, 0, 0 ) - 1 + mod ) % mod << "\n";
	return 0;
}

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

int main(){

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    // 1-based indexing is used for convenience

    int arr[n+1];
    arr[0] = 0;

    for (int i=1; i<n+1; i++)
        cin >> arr[i]; 

    vector<int> res(n+1, 0);

    //res[1] is 0 

    res[2] = abs(arr[2] - arr[1]);

    for (int i=3; i<n+1; i++){

        int temp = INT_MAX;
        for (int j=1; (j<=k) && (i-j)>=1; j++){
            temp = min (temp, res[i-j] + abs(arr[i]-arr[i-j]) );
        }
        res[i] = temp;

    }

    // for (int i=0; i<n+1; i++){
    //     cout << res[i] << endl;
    // }
    
    cout << res[n] << endl;

    return 0;
}



Measured memory_bytes: 3964
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int h,w;cin >> h >> w;
    string board[50];
    
    for (int i = 0; i < h; ++i) cin >> board[i];
    
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

    for (int i = 0; i < h; ++i) {
         for (int j = 0; j < w; ++j) {
            if (board[i][j] == '#') continue;
            
            int num = 0;
            for (int d = 0; d < 8; ++ d) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];
            
                if (ni < 0 or h <= ni) continue;
                if (nj < 0 or w <= nj) continue;
                if (board[ni][nj] == '#') num++;
                 }
             board[i][j] = char(num + '0');
         }
    }
    for (int i = 0; i < h; ++i) cout << board[i] << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
import sys
import math

MOD = 10 ** 9 + 7


def main():
    S = input()
    dic = {}

    for i in range(len(S)):
        if S[i] not in dic:
            dic[S[i]] = 1
        else:
            dic[S[i]] += 1

    if len(dic.keys()) == 2 and len([i for i in dic.values() if i == 2]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.Scanner;

class Main{
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a =sc.nextInt();
	    int b =sc.nextInt();
	    if(a<b){
	        System.out.println("a < b");
	    }else if(a>b){
	        System.out.println("a > b");
	    }else if(a==b){
	        System.out.println("a == b");
	    }
  }
}


Measured memory_bytes: 26240
#include <bits/stdc++.h>
#define loop(times) for(int i=0;i<(times);i++)

using namespace std;

int main() {
    while(1<2){
    int n,K;
    long long max;
    cin>>n>>K;
    if(n==0&&K==0)break;
    int S[n];
    int a[n];
    S[0]=0;
    loop(n) cin>>a[i];
    loop(K) S[0]+=a[i];
    max=S[0];
        
    for(int j=1;j<n-K+1;j++){
    S[j]=S[j-1]+a[j+K-1]-a[j-1];
    if(max<=S[j])max=S[j];
    }
        
    cout<<max<<endl;
    }
}


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

int main() {
  int H,W;
  char R[102][102];
  cin >> H >> W;
  for(int y=0;y<H+2;y++){
    for(int x=0;x<W+2;x++){
      if(x==0||y==0||x==W+1||y==H+1)
        R[x][y]='#';
      else
        cin>>R[x][y];
    }
  }

  for(int y=0;y<H+2;y++){
    for(int x=0;x<W+2;x++){
      cout<<R[x][y];
    }
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
#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 a, b;
    cin >> a >> b;
    cout << a / b << " " << a % b << " ";
    cout << fixed << setprecision(6) << a / (double)b << endl;
    return 0;
}


Measured memory_bytes: 3268
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	ms := map[rune]int{}
	for _, v := range s {
		ms[v]++
	}
	if len(ms) != 2 {
		fmt.Println("No")
		return
	}
	for _, v := range ms {
		if v != 2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 512
# ABC083B - Some Sums

# by me
N, A, B = map(int, input().split())


nums = list(range(1, N+1))
total = 0
for i in nums:
    k = i
    s = 0
    while k:
        k, remainder = divmod(k, 10)
        s += remainder
    if A <= s <= B:
        total += i
print(total)

# sample

##N, A, B = map(int, input().split())
##total = 0
##for i in range(N+1):
##    if A <= sum([int(s) for s in str(i)]) <=b:
##        total += i
##print(total)



Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>

using namespace std;

#define INF 100000000;
typedef long long LL;

int main() {
    int n;
    cin >> n;
    int _max = -INF;
    int _min = INF;
    LL total = 0;

    for (int i=0; i<n; i++)
    {
        int k;
        cin >> k;
        total += k;
        _max = max(_max, k);
        _min = min(_min, k);
    }

    cout << _min <<" "<<_max<<" "<<total<<endl; 

    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>

using namespace std;

typedef long long ll;
typedef vector <ll> vl;

const int ie = 1e5 + 1;
const greater <ll> gt;

int main() {
    int n, k; cin >> n >> k;
    ll u, v;
    vl box[ie];
    
    while(n--) {
        cin >> u >> v;
        box[u].push_back(v);
    }
    
    vl fir, el;
    
    for(int i = 1; i < ie; ++i) {
        sort(box[i].begin(), box[i].end(), gt);
        if(!box[i].empty()) fir.push_back(box[i][0]);
        for(int j = 1; j < box[i].size(); ++j)
            el.push_back(box[i][j]);
    }
    
    sort(fir.begin(), fir.end(), gt);
    sort(el.begin(), el.end(), gt);

    for(int i = 1; i < fir.size(); ++i)
        fir[i] += fir[i - 1];
    
    for(int i = 1; i < el.size(); ++i)
        el[i] += el[i - 1];

    ll mx = 0;
    for(int i = 0; i < min((int) fir.size(), k); ++i)
        if((int)el.size() > k - i - 2)
            mx = max(mx, fir[i] +
                (i + 1LL) * (i + 1LL) +
                (k - i - 2 < 0 ? 0LL : el[k - i - 2])
                );
    
    cout << mx;
    
    return 0;
}

Measured memory_bytes: 6904
#include<bits/stdc++.h>
#define sz 200002
#define pb push_back
#define ff first
#define ln '\n'
#define ss second
#define ll long long
#define VEC vector<ll int>v
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}


ll int ara[10];
int main()
{

    memset(ara,-1,sizeof(ara));
    int n,m,a,b,ok=1;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        if(ara[a]!=-1&&b!=ara[a])
        {
            ok=0;
        }
        ara[a]=b;
    }
    if(ara[1]==0&&n>1)
        ok=0;
        if(n==1&&m==0){cout<<"0"<<endl;return 0;}

    for(int i=1; i<=n; i++)
    {
        if(i==1&&ara[i]==-1)
            ara[i]=1;
        else if(ara[i]==-1&&i!=1)
            ara[i]=0;
    }


    if(ok)
        for(int i=1; i<=n; i++)
            cout<<ara[i];

    else
        cout<<"-1"<<endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

func main() {
	defer stdout.Flush()
	n := readInt()
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, 26)
	}
	for i := range x {
		b := []byte(readString())
		for _, c := range b {
			x[i][c-'a']++
		}
	}

	y := make([]int, 26)
	for i := range y {
		y[i] = math.MaxInt32
	}
	for i := range x {
		for j := range y {
			y[j] = minInt(y[j], x[i][j])
		}
	}
	ans := make([]byte, 0)
	for i := range y {
		for j := 0; j < y[i]; j++ {
			ans = append(ans, byte(i+'a'))
		}
	}
	println(string(ans))

}


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

using namespace std;

int main(){
	int n, c = 0,d = 0;
	cin >> n;
	int s[n];
	for(int i =0; i< n; i++){
		cin >> s[i];
		if(s[i] % 10 != 0)
			c++;
		d += s[i];
	}
	
	if(c == 0)
		cout << 0 << endl;
	
	sort(s, s + n);
	
	for(int i = 0; i < n; i++){
		if(c == 0)
			break;
		if(d % 10 == 0){
			if((d - s[i]) % 10 != 0){
				cout << d - s[i] << endl;
				break;
			}
		}
		else{
			cout << d << endl;
			break;
		}
	}
	
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin >> S;
    int n = S.size();
    int flag=1;
    for (int i=0;i<n;i++){
        if ((i%2==0)&&(S[i]=='L')) flag =0;
        if ((i%2==1)&&(S[i]=='R')) flag =0; 
    }
    if(flag) cout <<"Yes\n" ;
    else cout << "No\n";
}


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

using namespace std;

#define int long long int
#define INF 1e5
#define MoD 1e9 + 7
#define all(c) c.begin(), c.end()
#define sz(x) (int)(x).size()

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

	int a, b, c, d;
  	cin >> a >> b>> c>> d;
  cout << max(max(a*c, b*d), max(a*d, b*c))<<'\n';
  return 0;

}


Measured memory_bytes: 3572
#include <vector>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ANS = 0;
	cin >> N;
	vector<SINT32> DATA(N);

	for (SINT32 i = 0; i < N; i++) {
		cin >> DATA[i];
	}

	ANS = __gcd(DATA[0],DATA[1]);

	for (SINT32 i = 2; i < N; i++) {
		ANS = __gcd(ANS,DATA[i]);
	}
	

	cout << ANS << endl;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {

        try (final Scanner sc = new Scanner(System.in)) {
            final int n = sc.nextInt();
            final int[] h = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                h[i] = sc.nextInt();
            }
            final int[] step = new int[n + 1];
            if (n >= 2) {
                step[2] = Math.abs(h[2] - h[1]);
            }
            for (int i = 3; i <= n; i++) {
                int plus1 = Math.abs(h[i - 1] - h[i]) + step[i - 1];
                int plus2 = Math.abs(h[i - 2] - h[i]) + step[i - 2];
                step[i] = Math.min(plus1, plus2);
            }
            System.out.println(step[n]);
        }
    }

}


Measured memory_bytes: 48376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    multiset<int> index;
    index.insert(-1);
    index.insert(-1);
    index.insert(n);
    index.insert(n);
    vector<pii> PI(n);
    rep(i, n) {
        int p;
        cin >> p;
        PI[i] = {p, i};
    }
    sort(all(PI), greater<>());
    ll ans = 0;
    rep(i, n) {
        int p, idx;
        tie(p, idx) = PI[i];
        auto j = index.upper_bound(idx);
        int a, b, c, d;
        c = *j;
        d = *next(j);
        b = *prev(j);
        a = *prev(prev(j));
        ans += 1LL * ((d - c) * (idx - b) + (b - a) * (c - idx)) * p;
        index.insert(idx);
//        debug(a, b, c, d);
//        debug(ans);
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 8644
n, k = map(int, input().split())
dat_x = list(map(int, input().split()))
l = 0
r = k - 1
total = 0
for i in range(1, k):
    # print("{0} - {1}".format(dat_x[i] , dat_x[i - 1] ))
    # print("abc: {0}".format(abs(dat_x[i] - dat_x[i - 1])))
    total += abs(dat_x[i] - dat_x[i - 1])

total += min(abs(dat_x[l]), abs(dat_x[r]))

m = total
# print("m = {0}".format(m))

#print("check: {0}, {1} = {2}".format(l, r, total))
r += 1
l += 1

while r < n:
    #print("!!!!!!!!")
    #print(dat_x[l])
    #print(dat_x[l-1])
    total -= min(abs(dat_x[l-1]), abs(dat_x[r-1]))
    #print("check-0: {0}, {1} = {2}".format(l, r, total))
    total -= abs(dat_x[l] - dat_x[l - 1])
    #print("check-1: {0}, {1} = {2}".format(l, r, total))
    total += abs(dat_x[r] - dat_x[r - 1])
    #print("check-2: {0}, {1} = {2}".format(l, r, total))
    total += min(abs(dat_x[l]), abs(dat_x[r]))

    m = min(m, total)
    r += 1
    l += 1

print(m)


Measured memory_bytes: 62576