akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
using namespace std;
const int N=10005;
int n,k,mi,sz=sizeof(char);
char c[N],a[N*2],b[N*2],ans[N];
void get(int k,int i,int j){
	memcpy(a,c,(n+1)*sz);
	if(k==1&&j<n){
		fo(l,1,n)a[n+l]=a[n-l+1];
		memcpy(b+1,a+1,n*2);
		memcpy(a+1,b+i,n*sz);
		return;
	}
	if(j<n){
		--k;
		fo(l,1,n)a[n+l]=a[n-l+1];
		memcpy(b+1,a+1,n*2);
		memcpy(a+1,b+n-i+2,n*sz);
		i=j-i+1;
	}else i=n-i+1;
	if(k>=13||(i<<k)>=n){
		fo(l,1,n)a[l]=mi;
		return;
	}
	fo(l,1,n-i)b[l]=a[l];
	reverse(b+1,b+n-i+1);
	fo(l,1,i<<k)a[l]=mi;
	fo(l,(i<<k)+1,n)a[l]=b[l-(i<<k)];
}
bool pd(char *a,char *b){
	fo(i,1,n){
		if(a[i]<b[i])return 1;
		if(a[i]>b[i])return 0;
	}
	return 0;
}
int main(){
	scanf("%d%d\n%s",&n,&k,c+1);
	memcpy(ans,c,(n+1)*sz);
	mi=255;
	fo(i,1,n)mi=min(mi,(int)c[i]);
	fo(i,1,n)if(c[i]==mi){
		int j=i;
		for(;j<n&&c[j+1]==mi;)++j;
		get(k,i,j);
		if(pd(a,ans))memcpy(ans,a,(n+1)*sz);
		i=j;
	}
	fo(i,1,n)putchar(ans[i]);
}

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

bool is_squere(long N) {
        long r = (long) floor(sqrt(N));
        return (r * r) == N;
}

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int l = 0, n = 0;


    for(int i = 0; ; i++) {
        l += Z + Y;
        if(l + Z > X) {
            break;
        }
        n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
#define all(x) begin((x)), end((x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}

vector<ll> a;
ll n,m,v,p;
bool chk(int idx) {
    if (a[idx]+m<a[n-p]) {
        return false;
    }
    ll cnt = 0;
    rep(i,n) {
        if (i>n-p||i<=idx) {
            cnt += m;
        }
        else {
            cnt += max(0LL, a[idx]+m-a[i]);
        }
    }
    return cnt >= m*v;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>v>>p;
    a.assign(n,0);
    rep(i,n) cin>>a[i];
    sort(all(a));
    ll l=0,r=n-1;
    while(r>l) {
        ll mid = (l+r)/2;
        if (chk(mid)) {
            r = mid;
        } else {
            l = mid;
        }
        if (l+1==r) {
            if (chk(l)) {
                r = l;
            } else {
                l = r;
            }
        }
    }
    cout << n-l << endl;
    return 0;
}


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

int main(){
    int N = 3;
    int C[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> C[i][j];
        }
    }
    
    bool judge = false;
    vector<int> B(N, 0);
    B[0] = C[0][0];
    B[1] = C[0][1];
    B[2] = C[0][2];
    if (C[1][0] - B[0] == C[1][1] - B[1] && C[1][1] - B[1] == C[1][2] - B[2] && C[2][0] - B[0] == C[2][1] - B[1] && C[2][1] - B[1] == C[2][2] - B[2]) {
        judge = true;
    }
    cout << ((judge) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N; cin>>N;
  int A;
  rep(i,50){
    if(i==0)A=0;
    else A*=2;
    A++;
    if(pow(2,i)>N){
      cout<<A/2<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<ll,ll>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).sz())
#define cut(x) {cout<<x<<"\n"; continue;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order(1);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
const int N=1e5+5;
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll a[5],ans=-1e18;
  FOR(i,1,4) cin>>a[i];
  FOR(i,1,2)
  FOR(j,1,2)
  ans=max(ans,a[i]*a[2+j]);
  cout<<ans;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

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

    map<int, int> A;
    for (int i = 0; i < N - 1; i++)
    {
        int temp;
        cin >> temp;
        if (!A.count(temp - 1))
        {
            A[temp - 1] = 0;
        }
        A[temp - 1]++;
    }

    rep(i, N)
    {

        if (!A.count(i))
        {
            cout << 0 << endl;
        }
        else
        {
            cout << A[i] << endl;
        }
    }
}

Measured memory_bytes: 12904
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 2e5 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

int dp[110][M], pr[110][M], n, k, a[N];

int add(int a, int b) {
	return (a + b + ((a + b < 0) ? mod : 0)) % mod;
}

int main() {
	data();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	dp[0][0] = 1;
	for (int i = 0; i <= k; ++i)
		pr[0][i] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= k; ++j)
			dp[1][j] = add(pr[0][j], - (j > a[i] ? pr[0][j - a[i] - 1] : 0LL));	
		for (int j = 0; j <= k; ++j) {
			if (j)
				pr[1][j] = add(pr[1][j - 1], dp[1][j]);
			else
				pr[1][j] = dp[1][0];
		}
		for (int j = 0; j <= k; ++j)
			pr[0][j] = pr[1][j];
	}
	printf("%d", dp[1][k]);
}

/*
	Timus: 288481RF
	CodeForces: fractal
*/


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
}
const int m=2000000;
 vi arr(m);
 int dp[m];
  int memo(int in,int k)
  {
      
      if(in==1)
      return dp[in]=0;
      if(in==2)
      return dp[in]=abs(arr[1]-arr[2]);
      
      if(dp[in]!=-1)
      return dp[in];
      int ans=9999999999999;
      for(int i=1;i<=k and in-i>=1;i++)
      {
          ans=min(ans,abs(arr[in]-arr[in-i])+memo(in-i,k));
      }
      return dp[in]=ans;
  }
 
int32_t main()
{
    c_p_c();
    //memset(dp,-1,sizeof(dp));
   int n,k;
   cin>>n>>k;
     
   for(int i=0;i<m;i++)
   {
       dp[i]=-1;
   }
   for(int i=1;i<=n;i++)
   {
       cin>>arr[i];
   }
   int x=memo(n,k);
   cout<<dp[n];
     
    return 0;
}


Measured memory_bytes: 39296
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

string s;
ll K;
vector<string> S;
set<string> st;

int main() {
    cin >> s;
    cin >> K;
    rep(i,s.size()){
        ll len = 1;
        while(i+len-1 < s.size() && len <= K){
            string sub = s.substr(i,len);
            st.insert(sub);
            len++;
        }
    }
    for (auto i = st.begin(); i!= st.end(); i++){
        S.push_back(*i);
    }
    sort(S.begin(),S.end());
    cout << S[K-1] << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  ll x; cin >> x;
  ll cur = 100;
  int i;
  for (i = 0; cur < x; i++) {
    cur += cur/100;
  }
  cout << i << '\n';
  return 0;
}



Measured memory_bytes: 3668
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int n,k;
vector<int> edge[2222];
bool is_gone[2222];

int dist1,dist2,mx;

void dfs(int v,int d){
    if(d<=k/2) dist1++;
    if(d==(k+1)/2) dist2++;

    for(int i=0;i<edge[v].size();i++){
        if(is_gone[edge[v][i]]) continue;
        is_gone[edge[v][i]]=1;

        dfs(edge[v][i],d+1);
    }
}

int main(){
    scanf("%d %d",&n,&k);
    for(int i=1;i<n;i++){
        int a,b;

        scanf("%d %d",&a,&b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) is_gone[j]=0;
        is_gone[i]=1; dist1=1; mx=0;

        for(int j=0;j<edge[i].size();j++){
            is_gone[edge[i][j]]=1; dist2=0;
            dfs(edge[i][j],1);
            mx=max(mx,dist2);
        }

        if(k%2) ans=max(ans,dist1+mx);
        else ans=max(ans,dist1);
    }

    printf("%d",n-ans);

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int a;
  int b;
  int sum = 0;
  cin>>a;
  cin>>b;
  int arr[a];
  for(int i = 0;i < a;i++){
    cin>>arr[i];
  }
  sort(arr,arr + (a));
  for(int i = 0;i < b;i++){
    sum += arr[i];
  }
  cout<<sum<<'\n';
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = Int64.Parse(nm[0]);
            var m = Int64.Parse(nm[1]);
            Console.WriteLine(Math.Min(n % m, Math.Abs(m - (n % m))));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#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
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int left = 0, right = 100000;
  rep(i, m){
    int l,r;
    cin >> l >> r;
    left = max(left, l);
    right = min(right, r);
  }
  int ans = max(0, right - left + 1);
  cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt = 0
if((len(A)-K)%(K-1) == 0):
    ans = 1 + (len(A)-K)//(K-1)
else:
    ans = 1 + (len(A)-K)//(K-1)+1
print(ans)  

Measured memory_bytes: 13880
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, M = mis()
    if N&1:
        q = deque(range(M*2))
        while q:
            print(q.popleft()+1, q.pop()+1)
    else:
        q1 = deque(range(N))
        q2 = deque(range(N-1))
        p1 = []
        while q1:
            p1.append((q1.popleft()+1, q1.pop()+1))
        p2 = []
        while len(q2)>=2:
            p2.append((q2.popleft()+1, q2.pop()+1))
        p2.reverse()
        for _ in range(M):
            print(*p1.pop())
            p1, p2 = p2, p1


main()



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

using namespace std;

int main()
{
  int a, b, c, d;

  scanf("%d %d %d %d", &a, &b, &c, &d);

  if (a * b < c * d)
  {
    printf("%d", c * d);
  }
  else
  {
    printf("%d", a * b);
  }
}

Measured memory_bytes: 256
from collections import deque
n, l, b = input(), raw_input().split(), deque()
for t in xrange(n):
    if (t + 1) % 2:
        b.append(l[t])
    else:
        b.appendleft(l[t])
print ' '.join(reversed(b)) if n % 2 else ' '.join(b)

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

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int64_t> C(N);
    vector<int> sz(N);
    for(int i=0; i<N; i++){
        cin >> S[i] >> C[i];
        sz[i] = S[i].size();
    }

    static int64_t dp[50][21][50][21];
    const int64_t INF = 5e18;
    for(int i=0; i<N; i++) for(int a=0; a<=20; a++) for(int j=0; j<N; j++) for(int b=0; b<=20; b++) dp[i][a][j][b] = INF;
    using V = tuple<int64_t, int, int, int, int>;
    priority_queue<V, vector<V>, greater<V>> que;
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        dp[i][0][j][sz[j]] = C[i]+C[j];
        que.emplace(C[i]+C[j], i, 0, j, sz[j]);
    }

    while(que.size()){
        auto [d, i, a, j, b] = que.top(); que.pop();
        if(d > dp[i][a][j][b]) continue;
        if(a == sz[i]){
            for(int s=0; s<N; s++){
                if(d+C[s] < dp[s][0][j][b]){
                    dp[s][0][j][b] = d+C[s];
                    que.emplace(d+C[s], s, 0, j, b);
                }
            }
        }else if(b == 0){
            for(int s=0; s<N; s++){
                if(d+C[s] < dp[i][a][s][sz[s]]){
                    dp[i][a][s][sz[s]] = d+C[s];
                    que.emplace(d+C[s], i, a, s, sz[s]);
                }
            }
        }else if(S[i][a] == S[j][b-1]){
            if(d < dp[i][a+1][j][b-1]){
                dp[i][a+1][j][b-1] = d;
                que.emplace(d, i, a+1, j, b-1);
            }
        }
    }

    int64_t ans = INF;
    for(int i=0; i<N; i++) for(int j=0; j<=sz[i]; j++){
        ans = min(ans, dp[i][j][i][j] - C[i]);
        if(j) ans = min(ans, dp[i][j-1][i][j] - C[i]);
    }
    if(ans > INF/2) ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int a[N];
    rep(i,N){
        cin >> a[i];
    }
    map<int,int> l;
    rep(i,N){
        if(l.find(i+a[i])!=l.end()){
            l[i+a[i]]++;
        }else{
            l[i+a[i]]=1;
        }
    }
    ll count=0;
    rep(j,N){
        if(l.find(j-a[j])!=l.end()){
            count+=l[j-a[j]];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 13636
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
double mp[11][11];
int main(){
   cin.tie(0);  
   ios::sync_with_stdio(false);
   int n,d,cnt=0;
   cin>>n>>d;
   FOR(i,n){
     FOR(j,d) cin>>mp[i][j];
   }
   FOR(i,n){
     SFOR(j,i+1,n){
       double ans=0;
       FOR(s,d){
         ans+=pow((mp[i][s]-mp[j][s]),2);
       }
       ans=sqrt(ans);

       if(ans-(int)ans==0.0) cnt++;
     }
   }
   cout<<cnt<<endl;

   return 0;
}



Measured memory_bytes: 256
/**
*    author:  yuya1234
*    created: 17.07.2020 13:29:55
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long double eps = 1.0E-14;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  int n;
  cin>>n;

  int a[n],b[n];
  ll a_sum,b_sum;
  a_sum=b_sum=0;
  REP(i,n)
  {
    cin>>a[i];
    a_sum+=a[i];
  }
  vector<int> v1;
  vector<int> v2;
  REP(i,n)
  {
    cin>>b[i];
    b_sum+=b[i];
    if(a[i]>=b[i])v1.emplace_back(a[i]-b[i]);
    else v2.emplace_back(b[i]-a[i]);
  }

  if(a_sum<b_sum)
  {
    cout<<-1<<endl;
    return 0;
  }

  if(SZ(v2)==0)
  {
    cout<<0<<endl;
    return 0;
  }

  SORTD(v1);
  SORTD(v2);
  int idx=0;

  for(auto vv:v2)
  {
    while(vv!=0)
    {
      if(vv>=v1[idx])
      {
        vv-=v1[idx];
        idx++;
      }
      else
      {
        v1[idx]-=vv;
        vv=0;
      }
    }
  }

  cout<<SZ(v2)+idx+1<<endl;


  return 0;
}

Measured memory_bytes: 4616
import sys

N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))

up = []
dsum = 0
dnum = 0

for i in range(N):

    if A[i] > B[i]:
        up.append(A[i] - B[i])
    elif B[i] > A[i]:
        dsum += (B[i] - A[i])
        dnum += 1

up.sort()
up.reverse()

if sum(up) < dsum:
    print (-1)
    sys.exit()
elif dnum == 0:
    print (0)
    sys.exit()

usum = 0

for i in range(len(up)):

    usum += up[i]

    if usum >= dsum:
        print (dnum + i + 1)
        sys.exit()


Measured memory_bytes: 81328
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, k = MAP()
ans = 0
if k == 0:
    print(pow(n, 2))
    exit()

for b in range(k + 1, n + 1):
    ans += (b - k) * (n - n % b) // b 
    if n % b >= k:
        ans += n % b - k + 1
print(ans)

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

int		main(void)
{
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	vector<string> b(m);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	for (int i = 0; i <= n - m; i++)
	{
		for (int j = 0; j <= n - m; j++)
		{
			int k = 0;
			int l = i;
			while (k < m && a[l].substr(j, m) == b[k])
			{
				l++;
				k++;
			}
			if (k == m)
			{
				cout << "Yes" << endl;
				return (0);
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
def ans(i):
    return i - (i//C + i//D - i//lcm(C,D))

print(ans(B)-ans(A-1))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int mini=n;
    for(int z=0;z*z*z<=n;z++){
      int y=(int)sqrt(n-z*z*z);
      mini=min(mini,z+y+n-y*y-z*z*z);
    }
    cout<<mini<<endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
int n,A[20],M[200];

int result(int i,int m)
{
  if(A[i]==m) return 1;
  if(i==n) return 0;
  else
    {
      if(result(i+1,m)||result(i+1,m-A[i]))
	return 1;
    }
  return 0;
}

main(){
  int i,q;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&M[i]);
    }

  for(i=0;i<q;i++)
    {
      if(result(0,M[i]))
	printf("yes\n");
      
      else 
	printf("no\n");
    }
  return 0;
}

Measured memory_bytes: 580
mm = [0,gets.to_f]
gets.to_f>mm[1] ? mm[0]=$_.to_f : (mm[0],mm[1]=mm[1],$_.to_f)
while gets
  p=$_.to_f
  mm[0]=p if p>mm[0]
  mm[1]=p if p<mm[1]
end
puts mm[0]-mm[1]

Measured memory_bytes: 8600
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    P(N*N*N);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
struct rbtree: tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>{};
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define mp make_pair
#define pb push_back
#define lowb lower_bound
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mem0(a) memset((a), 0, sizeof(a))
#define mem(a, b) memset((a), (b), sizeof(a))
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const int N = 1e4+10;
char a[N];
char t[30];

int main(){
    IOS;
    int n;
    cin>>n>>a;
    for(int i = 0; i < 26; i++)t[i]='A'+i;
    int len = strlen(a);
    for(int i = 0; i < len; i++){
        int tt = a[i]-'A';
        //cout<<"1==="<<tt<<endl;
        cout<<t[(tt+n)%26];
    }



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int t,n,a[150005],b[150005],c[1000005],ans=0,ha,pos;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,f;
    float c;
    cin>>n;
    f=n*100/108;
    c=f*1.08;
    while(true)
    {
       if(c<n+1&&c>=n)
    {
        cout<<f;
        return 0;
    }
    else
    {
        if(c>=n+1)
        {
            cout<<":(";
            return 0;
        }
        f++;
        c=f*1.08;
    }
    }

}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll p = n / 1000;
    if(n % 1000 != 0) {
    	p++;
    }
    cout << 1000 * p - n << "\n";
}

Measured memory_bytes: 3648
use std::vec::Vec;
use std::cmp;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, w) = {
        let v: Vec<usize> = read_vec();
        (v[0], v[1])
    };

    let mut wv = Vec::new();
    for _ in 0..n {
        let temp: Vec<i64> = read_vec();
        wv.push((temp[0], temp[1]));
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; w+1]; n+1];


    for i in 1..n+1 {
        for j in 0..w+1 {
            if j >= wv[i-1].0 as usize {
                dp[i][j] = cmp::max(dp[i - 1][j - wv[i-1].0 as usize] + wv[i-1].1, dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    println!("{:?}", dp[n][w]);
}


Measured memory_bytes: 106748
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

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

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<int> res;
vector<int> ord;

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);
   
   ll n, m, i, j, k;

   cin>>n;

   if(n%10 == 7 ){
       cout<<"Yes\n";
       return 0;
   }
   n/=10;
    if(n%10 == 7 ){
       cout<<"Yes\n";
       return 0;
   }
   n/=10;

      if(n%10 == 7 ){
       cout<<"Yes\n";
       return 0;
   }
   cout<<"No\n";
   return 0;



}




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

int f(int n){
    if(n%2==0) return n/2;
    else return 3*n+1;
}

int main(){
    int s;
    //cin>>s;
    scanf("%d",&s);
    vector<int> num(1000005,0);
    
    bool exist=true;
    int i=1;
    num[s]++;
    while(exist){
        s=f(s);
        num[s]++;
        if(num[s]>1) exist=false;
        i++;
    }
    
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 7180
#include<bits/stdc++.h>
using namespace std;
int n;
double x,d,x1,x2,p;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%lf%lf",&n,&x,&d);
	n*=2;
	while(n)
	  {
	   p+=x+d*(n-1)/2;
	   x1=(x+2*d+(n-2)*x+3*x+3*d)/n;
	   x2=(2*(x+3*d)+(n-3)*(x+d)+3*x+6*d)/n;
	   x=x1;
	   d=x2-x1;
	   n-=2;
	  }
	printf("%.12lf\n",p);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

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

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    ll N;

    vector<ll> g1, g2;

    void input() {
        cin >> N;
        g1.resize(3);
        g2.resize(3);
        rep(i, 0, 3) cin >> g1[i];
        rep(i, 0, 3) cin >> g2[i];
    }

    ll atob() {
        ll n = N;
        vector<vector<ll>> dp(4, vector<ll>(n + 1));
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j <= n; ++j) {
                if (j < g1[i]) {
                    dp[i + 1][j] = dp[i][j];
                } else {
                    dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - g1[i]] + g2[i]);
                }
            }
        }

        ll ret = n;
        for (int i = 0; i <= n; ++i) {
            ll tmp = n - i + dp[3][i];
            chmax(ret, tmp);
        }

        return ret;
    }

    ll btoa(ll n) {
        vector<vector<ll>> dp(4, vector<ll>(n + 1));
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j <= n; ++j) {
                if (j < g2[i]) {
                    dp[i + 1][j] = dp[i][j];
                } else {
                    dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - g2[i]] + g1[i]);
                }
            }
        }

        ll ret = n;
        for (int i = 0; i <= n; ++i) {
            ll tmp = n - i + dp[3][i];
            chmax(ret, tmp);
        }
        return ret;
    }

    void solve() {
        input();

        ll val = atob();
        ll ans = btoa(val);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 976996
#include <bits/stdc++.h>
#define P pair<int, int>

using namespace std;
const int INF=1e5;

int main(){
  string s;
  cin >> s;
  long long n=s.length();
  long long last=n-1;
  while(s[last]=='B')last--;
  long long ans=0;
  for(long long i=last-1;i>=0;i--){
    if(s[i]=='B'){
      ans += last - i;
      last--;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3728
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	
	public static void main(String[] args) {
		int n = in.nextInt();
		double p = (double)n/3;
		System.out.println(p*p*p);
		
		out.flush();
		out.close();
		
	}
	
	

	//NONPROBLEM CODE
	
	private static InputReader in = new InputReader(System.in);
	private static PrintWriter out = new PrintWriter(System.out);
	
	private static class InputReader {
		 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
 
		public InputReader(InputStream st) {
			this.stream = st;
		}
 
		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
 
		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
 
	}
	
	private static void debug(Object... o) {
		for(Object x: o) {
			out.write(x+" ");
		}
		out.write("\n");
		out.flush();
	}
	
}


Measured memory_bytes: 20948
#include <cstdio>
#include <cstdlib> 
#include <queue>
#include <algorithm> 
using namespace std;
#define N 100005
#define pi pair<int,int>
#define mk(x,y) make_pair(x,y)
deque <pi> q;
int k,vis[N]={0};

int main()
{
	scanf("%d",&k);
	q.push_front(mk(1,1));
	for (;!q.empty();){
		int num = q.front().first;
		int val = q.front().second;
		q.pop_front();
		if (vis[num]) continue;
		vis[num] = 1;
		if (num==0){
			printf("%d",val);
			break;
		}
		q.push_front(mk(num*10%k,val));
		q.push_back(mk((num+1)%k,val+1));
	}
	return 0;
}

Measured memory_bytes: 4100
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String[] EM=new String[100];
		int[] EM_CNT=new int[100];
		int em_cnt=0;
		boolean em_find=false;
		String[] EN=new String[100];
		int[] EN_CNT=new int[100];
		int en_cnt=0;
		boolean en_find=false;
		String source="";

		for(int i=0; i<100; i++) {
			EM_CNT[i]=0;
			EN_CNT[i]=0;
		}
		int kosu1=sc.nextInt();
		for(int i=0; i<kosu1; i++) {
			source=sc.next();
			em_find=false;
			if(em_cnt==0) {
				EM[0]=source;
				EM_CNT[0]++;
				em_cnt++;
			}
			else {
				for(int j=0; j<em_cnt; j++) {
					if(EM[j].equals(source)) {
						em_find=true;
						EM_CNT[j]++;
						break;
					}
				}
				if(em_find==false) {
					EM[em_cnt]=source;
					EM_CNT[em_cnt]++;
					em_cnt++;
				}
			}
		}

		int kosu2=sc.nextInt();
		for(int i=0; i<kosu2; i++) {
			source=sc.next();
			en_find=false;
			if(en_cnt==0) {
				EN[0]=source;
				EN_CNT[0]++;
				en_cnt++;
			}
			else {
				for(int j=0; j<en_cnt; j++) {
					if(EN[j].equals(source)) {
						en_find=true;
						EN_CNT[j]++;
						break;
					}
				}
				if(en_find==false) {
					EN[en_cnt]=source;
					EN_CNT[en_cnt]++;
					en_cnt++;
				}
			}
		}
		int max=-114514810;
		String moji="";
		String tm2="";
		int tmp=0;
		for(int i=0; i<em_cnt; i++) {
			moji=EM[i];
			tmp=EM_CNT[i];

			for(int j=0; j<en_cnt; j++) {
				if(EN[j].equals(moji)) {
					tmp-=EN_CNT[j];
				}
			}

			if(tmp>max) {
				max=tmp;
			}
		}
		if(max>=0) {
			System.out.println(max);
		}
		/*else {
			for(int i=0; i<en_cnt; i++) {
				en_find=false;
				tm2=EN[i];

				for(int j=0; j<em_cnt; j++) {
					if(tm2.equals(EM[j])) {
						en_find=true;
						break;
					}
				}
				if(en_find==false) {
					if(-1*EN_CNT[i]>max) {
						max=-1*EN_CNT[i];
					}
				}
			}
			System.out.println(max);
		}*/
		else {
			System.out.println("0");
		}
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll total = 1;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    ll rtn = 0;
    for(int i=0; i<n; i++) {
        rtn += a[i]-1; 
    }
    cout << rtn << endl;


    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
H,W = map(int,input().split())
G = []
for i in range(H):
  G.append(list(input()))

for i in range(H):
  for j in range(W):
    if G[i][j] == '#':
      if i == 0:
        if j == 0:
          if G[0][1] == '.' and G[0][0] == '.':
            print("No")
            exit()
        if 0<j<W-1:
          if G[0][j-1] == '.' and G[0][j+1] == '.' and G[1][j] == '.':
            print("No")
            exit()
        if j == W-1:
          if G[0][j-1] == '.' and G[1][j] == '.':
            print("No")
            exit()
      elif 0<i<H-1:
        if j==0:
          if G[i-1][j] == '.' and G[i][1] == '.' and G[i+1][0] == '.':
            print("No")
            exit()
        elif 0<j<W-1:
          if G[i-1][j] == '.' and G[i][j-1] == '.' and G[i][j+1] == '.' and G[i+1][j] == '.':
            print("No")
            exit()
        elif j == W-1:
          if G[i-1][j] == '.' and G[i][j-1] == '.' and G[i+1][j] == '.':
            print("No")
            exit()
      elif i == H-1:
        if j == 0:
          if G[H-2][j] == '.' and G[H-1][j+1] == '.':
            print("No")
            exit()
        elif 0<j<W-1:
          if G[i-1][j] == '.' and G[i][j-1] == '.' and G[i][j+1] == '.':
            print("No")
            exit()
        elif j == W-1:
          if G[i-1][j] == '.' and G[i][j-1] == '.':
            print("No")
            exit()
            
print("Yes")

Measured memory_bytes: 3192
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <cassert>

using namespace std;

#define MAX 4
#define MAX2 16
#define LIMIT 100

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[MAX2][MAX2];
struct Puzzle{int f[MAX2],space,MD;};

Puzzle state;
int limit;
int path[LIMIT];

int getALLMD(Puzzle p){
  int sum=0;
  for(int i=0;i<MAX2;i++){
    if(p.f[i]==MAX2)continue;
    sum += MDT[i][p.f[i]-1];
  }
  return sum;
}
bool isSolved(){
  for(int i=0;i<MAX2;i++)if(state.f[i]!=i+1)return false;
  return true;
}
bool DFS(int depth,int prev){
  if(state.MD==0)return true;
  if(depth+state.MD>limit)return false;

  int sx=state.space/MAX;
  int sy=state.space%MAX;
  Puzzle tmp;

  for(int r=0;r<4;r++){
    int tx=sx+dx[r];
    int ty=sy+dy[r];
    if(tx<0 || ty<0 || tx>=MAX || ty>=MAX)continue;
    if(max(prev,r)-min(prev,r)==2)continue;
    tmp=state;
    state.MD -= MDT[tx*MAX+ty][state.f[tx*MAX+ty]-1];
    state.MD += MDT[sx*MAX+sy][state.f[tx*MAX+ty]-1];
    swap(state.f[tx*MAX+ty],state.f[sx*MAX+sy]);
    state.space=tx*MAX+ty;
    if(DFS(depth+1,r)){
      path[depth]=r;
      return true;
    }
    state=tmp;
  }
  return false;
}

string iterative_deepening(Puzzle in){
  in.MD=getALLMD(in);
  for(limit=in.MD;limit<=LIMIT;limit++){
    state=in;
    if(DFS(0,-100)){
      string ans = "";
      for(int i=0;i<limit;i++)ans+=dir[path[i]];
      return ans;
    }
  }
  return "unsolvable";
}

int main() {
  for(int i=0;i<MAX2;i++)
    for(int j=0;j<MAX2;j++)
      MDT[i][j]=abs(i/MAX-j/MAX)+abs(i%MAX-j%MAX);
      
  Puzzle in;

  for(int i=0;i<MAX2;i++){
    cin >> in.f[i];
    if(in.f[i]==0){
      in.f[i]=MAX2;
      in.space=i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;
  
  return 0;
}



Measured memory_bytes: 3232
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

vector <int> arr[26];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < len(s); i++)
    {
        arr[s[i] - 'a'].pb(i);
    }
    int last = -1;
    int ans = 0;
    for (auto c : t)
    {
        c -= 'a';
        if (arr[c].empty())
        {
            cout << -1;
            return 0;
        }
        if (last >= arr[c].back())
        {
            ans += len(s) - last + arr[c][0];
            last = arr[c][0];
        }
        else
        {
            int x = arr[c][(int)(upper_bound(all(arr[c]), last) - arr[c].begin())];
            ans += x - last;
            last = x;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 1736
package main

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

func main() {
	var h int
	fmt.Scan(&h)

	heap := make([]int, h+1)
	
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 1; i <= h; i++ {
		sc.Scan()
		heap[i], _ = strconv.Atoi(sc.Text())
	}
	for i := h/2; i >= 1; i-- {
		maxHeapify(&heap, i)
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 1; i <= h; i++ {
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(heap[i]))
	}
	wr.WriteString("\n")
	wr.Flush()
}

func maxHeapify(heap *[]int, i int) {
	l := 2*i
	r := 2*i+1

	var large int
	if l < len(*heap) && (*heap)[l] > (*heap)[i] {
		large = l
	} else {
		large = i
	}
	if r < len(*heap) && (*heap)[r] > (*heap)[large] {
		large = r
	}

	if large != i {
		(*heap)[large], (*heap)[i] = (*heap)[i], (*heap)[large]
		maxHeapify(heap, large)
	}
}



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

int main() {
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> s(n+1);
  rep(i, n) s[i+1] = s[i] + a[i];
  ll ans = 2e16;
  rep(i, n) {
    ll tmp = abs(s[i]*2 - s[n]);
    if (tmp < ans) ans = tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328