akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int h, w;
int dist;
int dist_;

void dfs1(int i, int j, vector<string> &s, vector<vector<int>> &dist1)
{
    if (j < w && s[i][j] == '.')
    {
        dist++;
        dfs1(i, j + 1, s, dist1);
        dist1[i][j] = dist;
    }
    if (j >= w || s[i][j] == '#')
    {
        return;
    }
}
void dfs2(int i, int j, vector<string> &s, vector<vector<int>> &dist2)
{
    if (i < h && s[i][j] == '.')
    {
        dist_++;
        dfs2(i + 1, j, s, dist2);
        dist2[i][j] = dist_;
    }
    if (i >= h || s[i][j] == '#')
    {
        return;
    }
}

int main()
{
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> dist1(h, vector<int>(w, -1));
    vector<vector<int>> dist2(h, vector<int>(w, -1));
    // cout << "AAAAAAAAAAAA" << endl;
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    // cout << "AAAAAAAAAAAA" << endl;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '.' && dist1[i][j] == -1)
            {
                dist = 0;
                dfs1(i, j, s, dist1);
            }
            if (s[i][j] == '.' && dist2[i][j] == -1)
            {
                dist_ = 0;
                dfs2(i, j, s, dist2);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            ans = max(ans, dist1[i][j] + dist2[i][j]);
        }
    }
    // for (int i = 0; i < h; i++)
    // {
    //     for (int j = 0; j < w; j++)
    //     {
    //         cout << dist1[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << "-----------" << endl;
    // for (int i = 0; i < h; i++)
    // {
    //     for (int j = 0; j < w; j++)
    //     {
    //         cout << dist2[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 35968
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
string s;
map<string, int> m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int ans=s.size();
    for (char c = 'a'; c <= 'z'; c++) 
    {
       int res=0;
       int count=0;
       for(int i=0;i<s.size();i++){
           if(c==s[i]){
               res=max(res,count);
               count=0;
           }
           else count++;
       }
       res=max(count,res);
       ans=min(res,ans);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scanf("%d %d", &n, &y)

	// a, b, c := findPair(0, 0, 0, n, y)
	a, b, c := findPair2(n, y)
	fmt.Println(a, b, c)
}

func findPair2(n, y int) (int, int, int) {
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			k := n - i - j
			if k >= 0 && i*10000+j*5000+k*1000 == y {
				return i, j, k
			}
		}
	}
	return -1, -1, -1
}

func findPair(a, b, c, n, y int) (int, int, int) {
	// fmt.Printf("a=%d, b=%d, c=%d, n=%d, y=%d\n", a, b, c, n, y)
	if y == 0 {
		if n == 0 {
			return a, b, c
		} else {
			return -1, -1, -1
		}
	} else if y < 0 {
		return -1, -1, -1
	}

	if n > 0 {
		if 10000*n < y {
			return -1, -1, -1
		}
		if r1, r2, r3 := findPair(a+1, b, c, n-1, y-10000); r1 != -1 {
			return r1, r2, r3
		}
		if 5000*n < y {
			return -1, -1, -1
		}
		if r1, r2, r3 := findPair(a, b+1, c, n-1, y-5000); r1 != -1 {
			return r1, r2, r3
		}
		if 1000*n < y {
			return -1, -1, -1
		}
		if r1, r2, r3 := findPair(a, b, c+1, n-1, y-1000); r1 != -1 {
			return r1, r2, r3
		}
	}
	return -1, -1, -1
}


Measured memory_bytes: 512
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

class SlidingWindowAggregation:
    """ https://scrapbox.io/data-structures/Sliding_Window_Aggregation """
    
    def __init__(self, f=sum):
        self.f = f
        self.front_stack = deque()
        self.back_stack = deque()
    
    def empty(self):
        return self.front_stack or self.back_stack

    def __len__(self):
        return len(self.front_stack) + len(self.back_stack)

    def fold_all(self):
        try:
            assert self.empty(), "Both stack is empty"
            if not self.front_stack:
                return self.back_stack[-1][1]
            elif not self.back_stack:
                return self.front_stack[-1][1]
            else:
                return self.f(self.front_stack[-1][1], self.back_stack[-1][1])
        except AssertionError as err:
            print("AssertionError :", err)

    def push(self, x):
        if not self.back_stack:
            self.back_stack.append((x, x))
        else:
            tmp = self.f(self.back_stack[-1][1], x)
            self.back_stack.append((x, tmp))

    def popleft(self):
        try:
            assert self.empty(), "Both stack is empty"
            if not self.front_stack:
                x,fx = self.back_stack.pop()
                self.front_stack.append((x, x))
                while self.back_stack:
                    x, fx = self.back_stack.pop()
                    fx = self.f(x, self.front_stack[-1][1])
                    self.front_stack.append((x, fx))
            self.front_stack.pop()

        except AssertionError as err:
            print("AssertionError :", err)

#solve
def solve():
    n = II()
    lr = LIR(n)
    maxl = max([l for l, r in lr])
    minr = min([r for l, r in lr])
    ans = max(minr - maxl + 1, 0) + max([r - l + 1 for l, r in lr])
    lisminr = SlidingWindowAggregation(min)
    lr.sort()
    for _, r in lr:
        lisminr.push(r)

    for l, r in lr[:-1]:
        lisminr.popleft()
        ans = max(ans, max(minr - l + 1, 0) + max(lisminr.fold_all() - maxl + 1, 0))
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 72668
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] t = S.toCharArray();
        int N = t.length;
        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = t[i] - '0';
        }
        int[] sum_mod = new int[N+1];
        int ten_pow = 1;
        for (int i = 1; i <= N; i++) {
            int temp = d[N - i] * ten_pow;
            temp %= 2019;
            sum_mod[i] = sum_mod[i-1] + temp;
            sum_mod[i] %= 2019;
            ten_pow *= 10;
            ten_pow %= 2019;
        }
        int[] summary = new int[2019];
        for (int i = 0; i <= N; i++) {
            summary[sum_mod[i]] += 1;
        }
        long ans = 0;
        for (int i = 0; i < 2019; i++) {
            if (summary[i] < 2) {
                continue;
            }
            ans += summary[i] * (summary[i] - 1) / 2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 33020
import math

a,b,x = map(int,input().split())
v = a*a*b

if v <= 2*x:
    print(math.degrees(math.atan((2*a*a*b-2*x)/(a*a*a))))
else:
    print(math.degrees(math.atan((a*b*b)/(2*x))))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

string N;
ll ns;

ll free(ll pos, ll k) {
	if (k == 0)return 1;
	if (k == 1) {
		return (ns - pos) * 9;
	}
	if (k == 2) {
		return (ns - pos) * (ns - pos - 1) / 2 * 81;
	}
	if (k == 3) {
		return (ns - pos) * (ns - pos - 1) * (ns - pos - 2) / 6 * 729;
	}
}

ll dfs(ll pos, ll k) {
	if (k == 0)return 1;
	if (pos == ns)return 0;
	if (N[pos] == '0') {
		return dfs(pos + 1, k);
	}
	return free(pos + 1, k) + (N[pos] - 49) * free(pos + 1, k - 1) + dfs(pos + 1, k - 1);
}

int main() {
	cin >> N;
	ll K;
	cin >> K;
	ns = N.size();
	cout << dfs(0, K);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

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

ans = sum(B)

for k in range(N-1):
    if A[k+1] == A[k]+1:
        ans += C[A[k]-1]
print(ans)


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.length();
    map<string, bool> m;
    vector<string> v;
    repd(i, 1, min(5LL, n) + 1) {
        rep(j, n - i + 1) {
            string temp = s.substr(j, i);
            /* cout << temp << endl; */
            if (!m[temp]) {
                v.push_back(temp);
                m[temp] = true;
            }
        }
    }

    sort(v.begin(), v.end());
    /* rep(i, v.size()) { cout << v[i] << endl; } */
    cout << v[k - 1] << endl;
    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
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)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef string::const_iterator State;

map<char, int> op;

ll term(State&, int);
ll number(State&);

ll calc(ll x, char c, ll y){
    if (c == '+') x += y;
    if (c == '-') x -= y;
    if (c == '*') x *= y;
    return x;
}

ll term(State &begin, int d){
    ll ret;
    if (d < 4) ret = term(begin, d+1);
    while (1){
        if (d == 4){
            if (*begin == '('){
                begin++;
                ll ret = term(begin, 1);
                begin++;
                return ret;
            }else{
                return number(begin);
            }
        }else if (op[*begin] == d){
            char c = *begin;
            begin++;
            ret = calc(ret, c, term(begin, d+1));
        }else{
            break;
        }
    }
    return ret;
}

ll number(State &begin){
    int ret = 0;
    while (isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int main() {
    ll res = 0;
    bool f = 1;
    string s;
    cin >> s;
    REP(i,3) REP(j,3) REP(k,3){
        op['+'] = i+1;
        op['-'] = j+1;
        op['*'] = k+1;
        State begin = s.begin();
        if (f) res = term(begin, 1), f = 0;
        else res = max(res, term(begin, 1));
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
#define int long long
using namespace std;
inline int read()
{
	int kkk=0,x=1;
	char c=getchar();
	while((c<'0' || c>'9') && c!='-')
		c=getchar();
	if(c=='-')
		c=getchar(),x=-1;
	while(c>='0' && c<='9')
		kkk=(kkk<<3)+(kkk<<1)+(c-'0'),c=getchar();
	return kkk*x;
}
int n,a[19];
inline int fun(int l,int r,int nl,int nr)
{
	if(l+1==r)
		return nl*a[l]+nr*a[r];
	int bck=0x7f7f7f7f7f7f7f7f;
	for(register int i=l+1;i<r;++i)
		bck=min(fun(l,i,nl,nl+nr)+fun(i,r,nl+nr,nr)-a[i]*(nl+nr),bck);
	return bck;
}
signed main()
{
	n=read();
	for(register int i=1;i<=n;++i)
		a[i]=read();
	printf("%lld\n",fun(1,n,1,1));
	return 0;
}

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

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

signed main() {
    prepare
    int N, M;
    cin >> N >> M;
    vector<int> H(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    vector<int> A(M, 0);
    vector<int> B(M, 0);
    for (int j = 0; j < M; ++j) {
        cin >> A[j] >> B[j];
    }
    vector<bool> T(N, true);
    vector<int> cnt(N, 1);
    for (int k = 0; k < M; ++k) {
        int X = A[k] - 1;
        int Y = B[k] - 1;

        if (H[X] < H[Y]) {
            T[X] = false;
        }
        else if (H[Y] < H[X]) {
            T[Y] = false;
        }
        else if (H[X] == H[Y]) {
            T[X] = false;
            T[Y] = false;
        }

    }
    int ans = 0;
    for (int l = 0; l < N; ++l) {
        if (T[l] == true) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4784
#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int Zeller(int y, int m, int d){
	if (m == 1){ m = 13; --y; }
	else if (m == 2){ m = 14; --y; }
	return (int)(d + floor(26.0 * (m + 1.0) / 10.0) + (y % 100) + floor((y % 100) / 4.0) + (5.0 * (floor(y / 100.0))) + floor(floor(y / 100.0) / 4.0)) % 7;
}

int main(){
	string days[7] = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
	int m, d;
	
	while (true){
		cin >> m >> d;
		if (m == 0 && d == 0)break;
		cout << days[Zeller(2004, m, d)] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int K,X;
    cin>>K>>X;
    int N=X-K+1;
    rep(i,2*K-1){
        if(N>1000000||N<-1000000){
            continue;
        }
        cout<<N+i<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 3608
package main

import "fmt"

func Coin(A, B, C, X int) int{
	var counts int
	for m := 0; m < A + 1; m++{
		if X < 500 && m != 0 {
			return counts
		}
		rest1 := X - 500 * m
		if rest1 == 0{
			counts++
			break
		}
		for n := 0; n < B + 1; n++{
			if rest1 < 100 {
				return counts
			}
			rest2 := rest1 - 100 * n
			if rest2 == 0{
				counts++
			}
			for l := 1; l < C + 1; l++{
				if rest2 < 50{
					break
				}
				rest3 := rest2 - 50 * l
				if rest3 == 0 {
					counts++
					break
				}
			}
		}
	}
	return counts
}

func main(){
	var A, B, C, X int
	fmt.Scanln(&A)
	fmt.Scanln(&B)
	fmt.Scanln(&C)
	fmt.Scanln(&X)
	coins := Coin(A, B, C, X)
	fmt.Println(coins)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long n,a[200010],sum[200010]={0},ans=0;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i],sum[i]%=mod;
	for (int i=1;i<=n;i++) ans+=a[i]*sum[i-1],ans%=mod;
	cout<<ans<<endl;
	return 0;
}

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


int main()
{
    int n,m,x;
    cin >> n>>m>>x;
    vector<int> a(m);
    int l = 0, r = 0;
    for(int i = 0; i<m; i++){
        cin>>a[i];
        if(a[i] < x) l++;
        else r++;
    }

    cout << min(l,r) << endl;
    
    return 0;
}

Measured memory_bytes: 256
/**********************************************************************************
just to save and look at code later
Izeed's code
https://atcoder.jp/contests/abc133/submissions/6305191
*/
#include<bits/stdc++.h>
using namespace std;
#define M 100005
struct D{
	int t,c,d;
};
struct W{
	int id,c,d,p;
};
vector<D>edge[M];
vector<W>Q[M];
int n,F[M][20],q,dep[M],ans[M],cn[M],cd[M],dis[M];
//정점,부모 노드,쿼리, 깊이, 답, 카운트, 누적합, 루트에서 거리
void dfs(int x,int f,int d){
	F[x][0]=f,dep[x]=dep[f]+1,dis[x]=d;
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i].t;
		if(y==f)continue;
		dfs(y,x,d+edge[x][i].d);
	}
}
void up(int &x,int step){
	for(int i=0;i<20;i++)
		if(step&(1<<i))x=F[x][i];
}
int lca(int a,int b){
	if(dep[a]>dep[b])swap(a,b);
	up(b,dep[b]-dep[a]);
	if(a==b)return a;
	for(int i=19;i>=0;i--)
		if(F[a][i]!=F[b][i])a=F[a][i],b=F[b][i];
	return F[a][0];
}
void DFS(int x,int f){
	for(int i=0;i<Q[x].size();i++)ans[Q[x][i].id]+=Q[x][i].p*(dis[x]-cd[Q[x][i].c]+cn[Q[x][i].c]*Q[x][i].d); //
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i].t;
		if(y==f)continue;
		cn[edge[x][i].c]++;
		cd[edge[x][i].c]+=edge[x][i].d;
		DFS(y,x);
		cn[edge[x][i].c]--;
		cd[edge[x][i].c]-=edge[x][i].d;
	}
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1,a,b,c,d;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		edge[a].push_back((D){b,c,d});
		edge[b].push_back((D){a,c,d});
	}
	dfs(1,0,0);
	for(int i=1;i<=19;i++)
		for(int j=1;j<=n;j++)F[j][i]=F[F[j][i-1]][i-1];
	for(int i=1;i<=q;i++){
		int u,v,c,d;
		scanf("%d%d%d%d",&c,&d,&u,&v);
		Q[lca(u,v)].push_back((W){i,c,d,-2});
		Q[u].push_back((W){i,c,d,1});
		Q[v].push_back((W){i,c,d,1});
	}
	DFS(1,0);
	for(int i=1;i<=q;i++)printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 31220
#include<iostream>
#include<string>
using namespace std;
int main(){
	int m,n[100];
	while(true){
	cin>>m;
	if(m==0)
		break;
	for(int i=0;i<m;i++)
		cin>>n[i];
	int ans=31;
	int count=0;
	cout<<"31"<<endl;
	while(true){
		if(ans<=n[count]){
			cout<<"0"<<endl;
			break;
		}
		ans-=n[count];
		cout<<ans<<endl;
		ans-=(ans-1)%5;
		cout<<ans<<endl;
		count++;
		count%=m;
	}
	}
	return 0;
}

Measured memory_bytes: 1160
/*
	0071:Bombs Chain
*/
#include	<iostream>
#include	<queue>
#include	<utility>

using namespace std;

typedef pair<int, int> P;

char map[8][8];

int vx[4] = { 1, 0, -1, 0 };
int vy[4] = { 0, 1, 0, -1 };

void bomb(int sx, int sy);

int main(void) {
	int dt;
	cin >> dt;
	for(int s = 0; s < dt; s++) {
		int sx, sy;
		
		for(int i = 0; i < 8; i++) {
			for(int j = 0; j < 8; j++) {
				char c;
				cin >> c;
				map[i][j] = c;
			}
		}
		
		cin >> sy >> sx;
		bomb(sx - 1, sy - 1);
		
		cout << "Data " << s + 1 << ":" << endl;
		for(int i = 0; i < 8; i++) {
			for(int j = 0; j < 8; j++) {
				cout << map[i][j];
			}
			cout << endl;
		}
	}
	
	return 0;
}

void bomb(int sx, int sy) {
	queue<P> que;
	que.push( P(sx, sy) );
	map[sx][sy] = '0';
	
	while( que.size() ) {
		P point = que.front();
		que.pop();
		
		for(int i = 0; i < 4; i++) {
			for(int j = 1; j < 4; j++) {
				int nx = point.first + vx[i] * j;
				int ny = point.second + vy[i] * j;
				if(8 > nx && nx >= 0 && 8 > ny && ny >= 0) {
					if(map[nx][ny] == '1') {
						que.push(P(nx, ny));
						map[nx][ny] = '0';
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1196
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    System.out.println(A[N-1] - A[0]);
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N, ans;
  cin >> N;
  ans=0;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  if (N%2==0) {
    for (int j=0; j<N/2; j++) {
      if (a.at(2*j)%2==1) {
        ans=ans+1;
      }
    }
  }
  else {
    for (int k=0; k<(N+1)/2; k++) {
      if (a.at(2*k)%2==1) {
        ans=ans+1;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {
  int64_t X, K, D;
  cin >> X >> K >> D;
  int64_t move = abs(X) / D;
  if (K <= move) {
    cout << abs(X) - D * K << endl;
    return 0;
  }
  if (X < 0) {
    X += D * move;
  } else {
    X -= D * move;
  }
  K -= move;
  if (K % 2 == 0) {
    cout << abs(X) << endl;
  } else {
    cout << min(abs(X - D), abs(X + D));
  }
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  int month = int(S.at(5) - '0')*10 + int(S.at(6)-'0');
  string ans;
  if (month <= 4) {
    ans = "Heisei";
  } else {
    ans = "TBD";
  }
  
  cout << ans << endl;
  return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)print("YES");
	else print("NO");





	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N, 0);
    REP(i, N)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());

    int ans = INT32_MAX;
    for (int i = 0; i + K - 1< N; ++i)
    {
        ans = min(ans, h[i + K - 1] - h[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
import itertools

start=0
end=0
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

seq=(i for i in range(1,N+1))
All=list(itertools.permutations(seq))

for i in range(len(All)):
    if All[i]==P:
        start=i
    if All[i]==Q:
        end=i

print(abs(end-start))

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

int main(){
  int n,m; cin>>n >>m;
  vector<int> G[200010];
  for(int i=0;i<m;i++){
    int a,b; cin>>a >>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i: G[1]){
    for(int j: G[i]){
      if(j==n){
        cout<<"POSSIBLE"<<endl;
        return 0;
      }
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

int main() {
	string s;
	cin >> s;
	if (s.length() >= 4 && s.substr(0, 4) == "YAKI") {
		puts("Yes");
	} else {
		puts("No");
	}

	return 0;
}

Measured memory_bytes: 768
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
x, y = 1, 1
y_lst = []

for i in range(n-1):
    if a[i] == a[i+1]:
        y += 1
    else:
        x += 1
        y_lst.append(y)
        y = 1

    if i == len(a)-2:
            y_lst.append(y)

y_lst.sort()
t = x - k
if t <= 0:
    print(0)
else:
    print(sum(y_lst[:t]))


Measured memory_bytes: 25748
/**
  @file d2.cpp
  @title D - Cake 123
  @url https://atcoder.jp/contests/abc123/tasks/abc123_d
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<LL> A(X, 0);
  vector<LL> B(Y, 0);
  vector<LL> C(Z, 0);

  REP(i, X) { cin >> A[i]; }
  REP(i, Y) { cin >> B[i]; }
  REP(i, Z) { cin >> C[i]; }

  sort(ALL(A), std::greater<LL>());
  sort(ALL(B), std::greater<LL>());
  sort(ALL(C), std::greater<LL>());

  vector<LL> ABC;
  REP(i, X) {
    REP(j, Y) {
      REP(k, Z) {
        if (i * j * k <= K) {
          ABC.push_back(A[i] + B[j] + C[k]);
        }
      }
    }
  }
  sort(ALL(ABC), std::greater<LL>());

  REP(i, K) { cout << ABC[i] << "\n"; }

  return 0;
}


Measured memory_bytes: 35048
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, time;
int color[N], d[N], f[N];
int M[N][N];


void dfs()
{

  int u;
  
  for(u=0;u<n;u++){
    color[u] =  WHITE;
  }
  
  time = 0;
  
  for(u=0;u<n;u++){
    if(color[u] == WHITE){
      visit(u);
    }
  }

}


void visit(int u)
{
  
  int v;
  
  color[u] = GRAY; // White vertex u has just been discovered
  d[u] = ++time;
  
  for(v=0;v<n;v++){ // Explore edge (u,v)
    if(M[u][v] == 0){
      continue;
    }
    if(color[v] == WHITE){
      visit(v);
    }
  }
  
  color[u] = BLACK; // Blacken u; it is finished
  f[u] = ++time;

}


int main()
{

  int u, v, k, i, j;

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

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  
  dfs();

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
  
}
  



Measured memory_bytes: 2052
package main

import (
	"fmt"
	"math"
	"sort"
)

func updateMin(a *int,b int){
	if *a > b{
		*a = b
	}
}

func scanInt() int{
	var v int;
	fmt.Scan(&v)
	return v
}

func scanIntSlice(N int) []int {
	_slice := make([]int,N)
	for i:=0; i< N ; i++ {
		fmt.Scan(&_slice[i])
	}
	return _slice
}
func main() {
	N :=scanInt()
	K := scanInt()
	h := scanIntSlice(N)
	sort.Ints(h)
	ans := math.MaxInt32
	for i, value := range h {
		if i+K-1 >= N {
			break
		}
		updateMin(&ans,h[i+K-1]- value)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
from functools import reduce
def comb(n, max_k, mod):
    """
    (n,k) := n個からk個選ぶ組み合わせ
    k = 0~max_Kまでを計算して返す
    """
    res = [1]*(max_k+1)
    t = 1
    for i in range(max_k+1):
        res[i] *= t
        t *= n-i
        t %= mod

    n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
    n = pow(n,-1, mod)

    for i in reversed(range(max_k+1)):
        res[i] *= n
        res[i] %= mod
        n *= i
        n %= mod
    return res

MOD = 10**9+7

K = int(input())
N = len(input())

res = 0
x = 1

com = comb(N+K, K, MOD)

for c in com:
    res += x*c
    res %= MOD
    x *= 25
    x %= MOD

print(res)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1000000007;
const int MAX_N = 312345;
ll inv[MAX_N];
ll fact[MAX_N];
ll fact_inv[MAX_N];

ll choose(int n, int r) {
  if (n < r) return 0;
  ll res = fact[n] * fact_inv[r] % MOD * fact_inv[n-r] % MOD;
  return res;
}

ll solve(int N, int a) {
  if (a == 0) return 1;
  ll res = choose(N+2*a, a) - choose(N+2*a, a-1);
  res = (res % MOD + MOD) % MOD;
  return res;
}

int main2() {
  int N = nextInt();
  int M = nextInt();
  int K = nextInt();

  ll ans = 0;
  for (int a = 0; a <= K; a++) {
    int b = K - a;
    ans += solve(N, a) * solve(M, b) % MOD * choose(N+M+2*a+2*b, N+2*a) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < MAX_N; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < MAX_N; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}



Measured memory_bytes: 10584
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n = int(input())
    hs = list(map(int, input().split()))
    hs = hs[::-1]
    ans_list = [0]*n
    ans_list[1] = abs(hs[1]-hs[0])
    for i in range(2,n):
        ans_list[i] = min([ans_list[i-1]+abs(hs[i]-hs[i-1]), ans_list[i-2]+abs(hs[i]-hs[i-2])])
    print(ans_list[n-1])


Measured memory_bytes: 14016
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)x = x->left;
      else x = x->right;
    }

  z->parent = y;

  if(y == NIL)root = z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  
  return 0;
}



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

int main(){
	int n;
	cin >> n;
	int odd = 0;
	odd = min(n, 9);
	odd += min(max(n - 99, 0), 900);
	odd += min(max(n - 9999, 0), 90000);
	cout << odd << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<LL> divi(LL K){
    vector<LL> v;
    for(LL i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}


int main(){
    LL n;cin >> n;
    auto q = divi(n-1);
    LL cnt = q.size();
    cnt--;
    auto p = divi(n);
    for (LL i = 0; i < p.size(); i++) {
        if(p[i] == 1) continue;
        LL t = n;
        while(t){
            if(t % p[i] == 1){
                cnt++;
                break;
            }
            else if(t % p[i] == 0){
                t /= p[i];
            }
            else{
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli a,b;
	cin>>a>>b;
	cout<<max({(a+b),(a-b),(a*b)})<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int n,i,most=0,ans=0,p;
  	scanf("%d",&n);
  	
  	for(i=0;i<n;i++){
    	scanf("%d",&p);
      	if(p > most){
        	most = p;
        }
      	ans += p;
    }
  
  	ans -= (most/2);
  
  	printf("%d",ans);
  
	return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
 
int main(){
  int a, b, c, k; 
  int sum = 0;
  scanf("%d %d %d %d",&a,&b,&c,&k);
  int k1 = k-a;
  int k2 = k1-b;
  if(k1<0)
    sum = k;
  else if(k2<0)
    sum = a;
  else
    sum = a-k2;
  printf("%d",sum);
  return 0;
}

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

int main(){
    list<int> L;
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        L.push_front(a);
    }

    for(int i=0; i<n-1; i++){
        cout<<L.front()<<" ";
        L.pop_front();
    }
    cout<<L.front()<<endl;
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>



int main() {

	int alphabets[26] = {};
	char c;

	while (!(std::cin >> c).eof()) {
		c = tolower(c);
		if ('a' <= c && c <= 'z') alphabets[c - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		std::cout << static_cast<char>(i + 'a') << " : " << alphabets[i] << "\n";
	}

	int wait;
	std::cin >> wait;


	return 0;

}

Measured memory_bytes: 3068
#include <stdio.h>
#include <stdlib.h>

int main(void){
  char input[200][10];
  int op[100];
  int opLast = 0;
  int n = 0;
  int i;

  while(scanf("%s", input[n]) != EOF){
    n++;
  }
  for(i = 0; i < n; i++){
    if(input[i][0] >= '0' && input[i][0] <= '9'){
      op[opLast] = atoi(input[i]);
      opLast++;
    }else {
      if(input[i][0] == '+'){

        op[opLast-2] = op[opLast-2] + op[opLast-1];
        opLast--;
      }else if(input[i][0] == '-'){
        op[opLast-2] = op[opLast-2] - op[opLast-1];
        opLast--;
      }else if(input[i][0] == '*'){
        op[opLast-2] = op[opLast-2] * op[opLast-1];
        opLast--;
      }
    }
  }

  printf("%d\n", op[opLast-1]);

  return 0;
}

Measured memory_bytes: 2688
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		Pattern p = Pattern.compile("[ATCG]+");
		Matcher m = p.matcher(s);
		int length = 0;
		while(m.find()) {
			int l = m.group().length();
			if(length < l)
				length = l;
		}
		System.out.println(length);
	}
}

Measured memory_bytes: 23508
//#pragma  GCC optimize("Ofast")

//#ifdef  DEBUG
//#define _GLIBCXX_DEBUG
//#endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;
//using namesparsace __gnu_pbds;

void solve();

int main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

#define ld double
#define int long long

const int maxN = 1e5 + 10, maxK = 1e5 + 10, inf = 1e15 + 10, base = 223, mod = 1e9 + 7;

int d, dp[maxN][110][2];
string s;

void solve() {
    cin >> s >> d;
    dp[0][(s[0] - '0') % d][1] = 1;
    for (int i = 0; i < (s[0] - '0'); i++) {
        dp[0][i % d][0] += 1;
    }
    for (int i = 1; i < s.size(); i++) {
        for (int j = 0; j < d; j++) {
            for (int l = 0; l < 10; l++) {
                int e = (j - l + d * 10) % d;
                //cout << i << " " << j << " " << l << " " << e << endl;
                if (l < s[i] - '0') {
                    dp[i][j][0] += dp[i - 1][e][0] + dp[i - 1][e][1];
                    dp[i][j][0] %= mod;
                }
                if (l == s[i] - '0') {
                    dp[i][j][1] += dp[i - 1][e][1];
                    dp[i][j][1] %= mod;
                }
                if (l >= s[i] - '0') {
                    dp[i][j][0] += dp[i - 1][e][0];
                    dp[i][j][0] %= mod;
                }
                //cout << dp[i][j][0] << endl;
            }
        }
    }
    cout << (dp[s.size() - 1][0][0] + dp[s.size() - 1][0][1] - 1 + mod) % mod;
}
/*
00
08
13
22
04
17


 */

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b, z = 0;
    cin >> n;
    map<pair<ll, ll>, ll > mp;
    while(n--){
    	cin >> a >> b;
    	if(a != 0LL){
    		if(b != 0LL){
    			bool maki = false;
    			if(b < 0LL) maki ^= 1, b = -b;
    		    if(a < 0LL) maki ^= 1, a = -a;
    		    ll g = gcd(a, b);
    		    a /= g; b /= g;
    		    if(maki) mp[{-a, b}]++;
    		    else mp[{a, b}]++;
    		}else mp[{0LL, 1LL}]++;
    	}else{
    		if(b != 0LL) mp[{-1LL, 0LL}]++;
    		else z++;
    	}
    }
    ll ans = 1LL;
    map<pair<ll,ll> , bool> m;
    for(auto& i: mp){
    	a = i.first.first;
    	b = i.first.second;
    	ll c = -b, d = a;
    	if(d < 0LL) d = -d, c = -c;
    	if(m[{a, b}]) continue;
    	ans *= ((modpow(2LL, mp[{c, d}]) + modpow(2LL, i.second))%mod - 1) % mod;
    	ans %= mod;
    	m[{c, d}] = true;
    	m[{a, b}] = true;
    }
    ans--;
    ans += z;
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 53584
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n; cin >> n;
	vector<int> ls(n);
	for (auto& l : ls) {
		cin >> l;
	}

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

	int64_t ans = 0;
	FOR_LT(a, 0, n - 2) {
		int b = a + 1;
		int c = b + 1;
		//cout << ls[a] << " " << ls[b] << " " << ls[c] << endl;
		while (b < n + 1) {
			//cout << "1" << a << " " << b << " " << c << endl;
			while (ls[a] + ls[b] > ls[c]) {
				//cout << ls[a] << " " << ls[b] << " " << ls[c] << endl;
				ans += c - b;
				c++;
				if (c == n) {
					break;
				}
				//cout << "2" << a << " " << b << " " << c << endl;
			}

			if (c == n) break;

			//cout << "3" << a << " " << b << " " << c << endl;
			while (ls[a] + ls[b] <= ls[c]) {
				if (b == c) {
					c++;
					break;
				}
				//cout << ls[a] << " " << ls[b] << " " << ls[c] << endl;
				b++;
				//cout << "4" << a << " " << b << " " << c << endl;
			}
		}
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

divisorsList :: [Int] -> [Int]
divisorsList [h, l, divided] = filter (\x -> divided `mod` x == 0) [h..l]

answer :: [Int] -> String
answer = show . length . divisorsList

main = do
    x <- getLine
    putStrLn $ answer (map read $ words x)



Measured memory_bytes: 4116
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>


int main(){
	char s1[11],s2[11],s3[11];
	scanf("%s %s %s",s1,s2,s3);
	
	printf("%c%c%c",toupper(s1[0]),toupper(s2[0]),toupper(s3[0]));
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, m;
vector<pair<LL, LL>> p;

int main() {
	cin >> n >> m;
	inc(i, n) {
		LL a;
		cin >> a;
		p.EB(a, 1);
	}
	inc(i, m) {
		LL b, c;
		cin >> b >> c;
		p.EB(c, b);
	}
	sort(RALL(p));
	
	LL ans = 0, r = n;
	RF(e, p) {
		LL s = min(e.SE, r);
		ans += e.FI * s;
		r -= s;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6256
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
ans = [[0] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            ans[y][x] = "#"
            if not (y == H-1 or x == W-1):
                if S[y+1][x+1] != "#":
                    ans[y+1][x+1] += 1
            if not y == H - 1:
                if S[y+1][x] != "#":
                    ans[y+1][x] += 1
            if not x == W - 1:
                if S[y][x+1] != "#":
                    ans[y][x+1] += 1
            if not (y == H - 1 or x == 0):
                if S[y+1][x-1] != "#":
                    ans[y+1][x-1] += 1
            if not (y == 0 or x == W - 1):
                if S[y-1][x+1] != "#":
                    ans[y-1][x+1] += 1
            if not x == 0:
                if S[y][x-1] != "#":
                    ans[y][x-1] += 1
            if not y == 0:
                if S[y-1][x] != "#":
                    ans[y-1][x] += 1
            if not (y == 0 or x == 0):
                if S[y-1][x-1] != "#":
                    ans[y-1][x-1] += 1

for i in range(H):
    print(''.join(map(str, ans[i])))



Measured memory_bytes: 73804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  int h, w;
  cin >> h >> w;

  char a[110][110];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < h; i++) {
    cout << "#";
    for (int j = 0; j < w; j++) {
      cout << a[i][j];
    }
    cout << "#" << endl;
  }

  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
  return 0;
}

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

int main()
{
    int n,i,j;
    cin>>n>>str;
    if(n&1)printf("No\n"),exit(0);
    n/=2;
    for(i=0,j=n; i<n; i++,j++)
    {
        if(str[i]!=str[j])printf("No\n"),exit(0);
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
	string S,T;
	cin >> S >> T;
	for(int i=0; i<S.size(); i++){
		cout << S[i];
		if(T.size() > i) cout << T[i];
	}
	cout << endl;
}

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

const int M=1e5+5;
vector<int> g[M];
int f[M];
int dsub[M]; // dsub[i] the max dep of subtree i
int dep[M];

int n,a,b;

int dfs(int u,int fa,int d)
{
	dsub[u]=1;
	f[u]=fa;
	dep[u]=d;
	for(int v:g[u])
	{
		if(v==fa) continue;
		dsub[u]=max(dsub[u],dfs(v,u,d+1)+1);
	}
	return dsub[u];
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(b,-1,1);
	// d[a]-d[b] 1 2 0
	// d[a]-d[b] 3 4 1
	int step=(dep[a]-dep[b]-1)/2;
	int high=a;
	for(int i=0;i<step;i++)
		high=f[high];
	printf("%d\n",step+dsub[high]-((dep[a]-dep[b])&1));
	return 0;
}

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int64_t INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int64_t> h(n);
  rep(i, n) cin >> h.at(i);

  vector<int64_t> dp(n, INF);
  dp.at(0) = 0;

  for (int i = 1; i < n; i++) {
    int start = max(0, i - k);
    for (int j = start; j < i; j++) {
      chmin(dp.at(i), dp.at(j) + abs(h.at(i) - h.at(j)));
    }
  }

  cout << dp.at(n - 1) << endl;
  return 0;
}

Measured memory_bytes: 4804