akhauriyash/Code-Regression huggingface dataset:
// abc176_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    int mn = A[0];
    REPN(i, 1, N){
        ans += max(0, mn - A[i]);
        mn = max(A[i], mn);
    }
    print(ans);


    return 0;
}


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

double concentration(double water, double suger) {
	return 100 * suger / (water + suger);
}

int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	pair<double, pair<int, int>> a;
	for (int i = 0; i <= F; i += 100 * A) {
		for (int j = 0; i + j <= F; j += 100 * B) {
			for (int k = 0; i + j + k <= F; k += C) {
				for (int l = 0; i + j + k + l <= F; l += D) {
					if (!i && !j && !k && !l) continue;
					if (concentration(i + j, k + l) <= concentration(100, E)) {
						if (a.first <= concentration(i + j, k + l)) {
							a.first = concentration(i + j, k + l);
							a.second.first = i + j + k + l;
							a.second.second = k + l;
						}
					}
				}
			}
		}
	}
	cout << a.second.first << ' ' << a.second.second;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
using namespace std;

typedef long long ll;

int main()
{
    int n, m, c;
    int a[20][20] = {};
    int b[20] = {};

    cin >> n >> m >> c;
    FOR(i, 0, m)
    {
        cin >> b[i];
    }
    FOR(i, 0, n)
    {
        FOR(j, 0, m)
        {
            cin >> a[i][j];
        }
    }
    int res = 0, tmp;

    FOR(i, 0, n)
    {
        tmp = c;
        FOR(j, 0, m)
        {
            tmp += a[i][j] * b[j];
        }
        if (tmp > 0)
            res++;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sort, groupBy)
import Data.Function (on)

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    bs = map ((,) <$> length <*> map snd) . groupBy ((==) `on` fst) . sort . flip zip [0..] $ as :: [(Int, [Int])]
    m = sum . map (comb . fst) $ bs :: Int
    cs = map snd . sort $ bs >>= map <$> flip (,) . fst <*> snd :: [Int]
  mapM_ print . map (\l -> m - comb l + comb (pred l)) $ cs

comb :: Int -> Int
comb l = (l * pred l) `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
using ll = long long;

int N, M, s, g1, g2;
ll dist[101][101];
void init() {
    REP(i, N) {
        REP(j, N) { dist[i][j] = 1e9; }
    }
    REP(i, N) dist[i][i] = 0;
}

bool solve() {
    cin >> N >> M >> s >> g1 >> g2;
    if (N == 0) return false;
    init();
    REP(i, M) {
        int u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        dist[u][v] = c;
    }
    s--, g1--, g2--;
    REP(k, N) REP(i, N) REP(j, N) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
    int ans = 1e9;
    REP(m, N) { ans = min(ans, dist[s][m] + dist[m][g1] + dist[m][g2]); }
    cout << ans << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}



Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>

typedef long long Long;

std::map<int, int> count;
void AddNum(int num)
{
    auto found = count.find(num);
    if (found == count.end())
        count[num] = 1;
    else ++found->second;
}

int arr[200001];
Long dp[200001];

int main()
{
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%d", arr + i);
        AddNum(arr[i]);
    }

    std::vector<Long> cases;
    Long left = 0, right = 0;
    for (auto p : count)
    {
        cases.push_back((Long)p.second * (p.second - 1) / 2);
        right += cases.back();
    }

    int i = 0;
    for (auto p : count)
    {
        right -= cases[i];
        if (i > 0)
            left += cases[i-1];
        
        dp[p.first] = left + right + (((Long)p.second - 1)*(p.second - 2) / 2);
        ++i;
    }

    for (i = 0; i < n; ++i)
        printf("%lld\n", dp[arr[i]]);

    return 0;
}

Measured memory_bytes: 10996
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll dp[1001][1001];
int main()
{
	boost
	ll n,m;
	cin>>n>>m;
	string s[n];
	for(ll i=0;i<n;i++)
	{
		cin>>s[i];
	}
	
	dp[n-1][m-1]=1;
	for(ll i=n-1;i>=0;i--)
	{
		for(ll j=m-1;j>=0;j--)
		{
			if(i==n-1&&j==m-1) continue;
			if(i+1<n&&s[i+1][j]=='.')
			{
				dp[i][j]=(dp[i][j]+dp[i+1][j])%M;
			} 
			if(j+1<m&&s[i][j+1]=='.')
			{
				dp[i][j]=(dp[i][j]+dp[i][j+1])%M;
			} 
			if(i-1>=0&&s[i-1][j]=='.')
			{
				dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
			} 
			if(j-1>=0&&s[i][j-1]=='.')
			{
				dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
			} 
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}

Measured memory_bytes: 9088
/*
[exawizards2019] B - Red or Blue
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N;
string s;

bool solve() {
    int cnt_r = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') {
            cnt_r++;
        }
    }

    return cnt_r > (N - cnt_r);
}

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

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int n;
int MAX_N=50;
string name[50];
int time_song[50];
string fin;

void solve();
int main(){
  scanf("%d",&n);
  for (int i=0;i<n;i++){
    cin >> name[i];
    scanf("%d",&time_song[i]);
  }
  cin >> fin;
  solve();
  return 0;
}

void solve(){
  bool sleap = false;
  int total_time=0;
  for(int i=0;i<n;i++){
    if(sleap){
      total_time+=time_song[i];
    }
    if(name[i]==fin){
      sleap=true;
    }
  }
  printf("%d\n",total_time);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <climits>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,max=0;
	cin>>N;
	vector<int> A(N),B(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		B[i]=A[i];
	}
	sort(B.begin(),B.end(),greater<int>());
	for(int i=0;i<N;i++){
		if(A[i]!=B[0]){
			cout<<B[0]<<endl;
		}else if(A[i]==B[0]){
			cout<<B[1]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct edge
{
	int to,cap,rev;
};
vector<edge>G[30005];
bool used[30005];

void add_edge(int from,int to,int cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}
int dfs(int v,int t,int f)
{ 
	if(v==t) return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0)
		{ 
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0) 
			{ 
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t)
{ 
	int flow=0;
	while(1)
	{ 
		memset(used,0,sizeof(used));
		int f=dfs(s,t,INF);
		if(!f) return flow;
		flow+=f;
	}
}
int n,m;
string f[105];
int main(){
	cin >> n >> m;
	for(int i=0;i<n;i++) cin >> f[i];
	int si,sj,ti,tj;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(f[i][j] == 'S'){ si=i,sj=j;
				for(int x=0;x<m;x++){
					if(x==j) continue;
					if(f[i][x] == 'o'){
						add_edge(30000,i*m+x,INF);
					}
				}
				for(int x=0;x<n;x++){
					if(x==i) continue;
					if(f[x][j] == 'o'){
						add_edge(30000,x*m+j,INF);
					}
				}
			}
			if(f[i][j] == 'T'){ ti=i,tj=j;
				for(int x=0;x<m;x++){
					if(x==j) continue;
					if(f[i][x] == 'o'){
						add_edge(i*m+x+10000,30001,INF);
					}
				}
				for(int x=0;x<n;x++){
					if(x==i) continue;
					if(f[x][j] == 'o'){
						add_edge(x*m+j+10000,30001,INF);
					}
				}
			}
		}
	}
	if(si==ti || sj==tj) { puts("-1"); return 0;}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(f[i][j] != 'o') continue;
			add_edge(i*m+j,i*m+j+10000,1);
			for(int x=0;x<n;x++){
				if(x == i || f[x][j] != 'o') continue;
				add_edge(i*m+j+10000,x*m+j,INF);
				add_edge(x*m+j+10000,i*m+j,INF);
			}
			for(int x=0;x<m;x++){
				if(x == j || f[i][x] != 'o') continue;
				add_edge(i*m+j+10000,i*m+x,INF);
				add_edge(i*m+x+10000,i*m+j,INF);
			}
		}
	}
	cout << max_flow(30000,30001) << endl;
}

Measured memory_bytes: 125824
package main

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

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

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

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

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

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

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

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	nk := readLineNum64s(bf)
	N, K := nk[0], nk[1]

	A := make([][]int64, N)
	for i := range A {
		A[i] = readLineNum64s(bf)
	}

	dp := make([][]int64, N) // dp[i][j]: i到j经过k步到达的方案数量
	t := make([][]int64, N)
	for i := range dp {
		dp[i] = make([]int64, N)
		t[i] = make([]int64, N)
		dp[i][i] = int64(1) // i到i经过0步就可以到达的方案数
	}

	var m int64 = 1000000007
	mul := func(a [][]int64, b [][]int64, c [][]int64) {
		for i:=0; i<int(N); i++ {
			for j:=0; j<int(N); j++ {
				c[i][j] = 0
				for k:=0; k<int(N); k++ {
					c[i][j] += a[i][k]*b[k][j]
					c[i][j] %= m
				}
			}
		}
	}

	for K > 0 {
		if K%2 == 1 {
			mul(dp, A, t) // 结果临时保存在ndp
			dp, t = t, dp
		}
		mul(A, A, t)
		A, t = t, A
		K /= 2
	}

	var ans int64
	for i:=0; i<int(N); i++ {
		for j:=0; j<int(N); j++ {
			ans += dp[i][j]
			if ans >= m {
				ans -= m
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 768
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    x, y = li_input()
    p1, p2 = [1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11]

    if x in p1:
        xg = 1
    elif x in p2:
        xg = 2
    else:
        xg = 3

    if y in p1:
        yg = 1
    elif y in p2:
        yg = 2
    else:
        yg = 3

    if xg == yg:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 4720
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          Y = parseInt(args[1], 10);

    var result = '-1 -1 -1';
    
    for (var a = 0; a <= N; a++) {
        for (var b = 0; b <= N; b++) {
            if ((a + b) > N) {
                continue;
            }

            var sum = (a * 10000) + (b * 5000) + ((N - a - b) * 1000);
            if (sum === Y) {
                result = `${a} ${b} ${N - a - b}`;
                break;
            }
        }        
    }
    
    console.log(result);

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


Measured memory_bytes: 7628
#include <stdio.h>

#define endl '\n'

int main()
{
    long long n, a, b, min, max;
    scanf("%lld %lld %lld", &n, &a, &b);

    if(a>b) printf("0");
    else if(n==1 && a-b) printf("0");

    else
    {
        min=a+b+a*(n-2);
        max=a+b+b*(n-2);

        printf("%lld", max-min+1);
    }
    return 0;
}


Measured memory_bytes: 1732
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, ans, l, f, t;
  string s, u, vowel = "aiueo";
  while (cin >> n, n) {
    ans = -1;
    vector< vector<string> > C(50);
    for (int i = 0; i < n; ++i) {
      cin >> s;
      l = s.size();
      u = s[0];
      C[0].push_back(u);
      t = 0;
      for (int j = 1; j < l; ++j) {
	if (vowel.find(s[j-1]) < 5) {
	  u += s[j];
	  ++t;
	  C[t].push_back(u);
	}
      }
      for (int j = u.size(); j < 50; ++j) C[j].push_back(u);
    }
    for (int i = 0; i < 50; ++i) sort(C[i].begin(), C[i].end());
    f = 0;
    t = 0;
    while (!f) {
      f = 1;
      if (t > 49) {
	f = 0;
	break;
      }
      for (int i = 1; i < n; ++i) {
	if (C[t][i] == C[t][i-1]) {
	  f *= 0;
	}
      }
      ++t;
    }
    if (f) ans = t;
    cout << ans << endl;
    C.erase(C.begin(), C.end());
  }
  return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
double dot(P a, P b){
    return (conj(a)*b).X;
}

int main(){
	double x,y;
	while(cin >> x >> y){
		VP p(4);
		for(int i=0; i<4; i++){
			if(i!=0) cin >> x >> y;
			p[i] = P(x, y);
		}
		if(EQ(dot(p[1]-p[0], p[3]-p[2]), 0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
 
using ll = long long;
using weight = ll;
using P = pair<ll, ll>;
 
int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; ++i) {
        cin >> A[i];
    }
    ll sum = accumulate(A.begin(), A.end(), 0LL);
    ll cnt = 0;
    while(N*(N+1)/2*cnt < sum) {
        cnt++;
    }
    if(sum != N*(N+1)/2*cnt) {
        cout << "NO" << endl;
        return 0;
    }
    bool ok = true;
    for(int i=0; i<N; ++i) {
        ll t = A[(i+1)%N] - A[i] - cnt;
        ok &= t <= 0 && abs(t) % N == 0;
    }
    if(ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int long long i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 200005;

i64 n;
i64 d[MAXN];
i64 c[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 1; i <= n; i++) {
        cin >> d[i] >> c[i];
    }

    i64 S = 0;
    i64 cnt = 0;
    for (i64 i = 1; i <= n; i++) {
        cnt += c[i];
        S += d[i] * c[i];
    }

    i64 R = cnt + (S - 1) / 9 - 1;
    cout << R << endl;

    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

const ll L = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll A, B;
    cin >> A >> B;

    if(A<=8 && B<=8)
    {
        cout << "Yay!" << endl;
    }

    else
    {
        cout << ":(" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;
    // cout << n << endl;
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    vector<double> arr(n);
    F0R(i,n) 
        cin >> arr[i];
    // F0R(i,n) cout << arr[i] << " ";
    // cout << endl;
    dp[0][0]=1-arr[0];
    dp[0][1]=arr[0];
    FOR(i,1,n)
    {
        dp[i][0]=dp[i-1][0]*(1-arr[i]);
    }
    FOR(i,1,n)
    {
        FOR(j,1,i+2)
        {
            dp[i][j]=arr[i]*dp[i-1][j-1] + (1-arr[i])*dp[i-1][j];
        }
    }
    double tot=0;
    FOR(j,n/2+1,n+1)
        tot+=dp[n-1][j];
    cout << tot << endl;

    return 0;
}


Measured memory_bytes: 70784
while True:
    H,W = map(int,input().split())
    
    if H == W == 0:
        break
    
    for i in range(H):
        if i == 0 or i == H-1:
            print('#' * W)
        else:
            print('#','.'*(W-2),'#',sep='')
    print('')


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define umap unordered_map
#define uset unordered_set
#define frw(i, a, b) for(int i = a; i < b; i++)
#define bck(i, a, b) for(int i = a; i > b; i--)
#define fi first
#define se second
#define pow asdihagsiduh
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpll vector<pll>
#define vpii vector<pii>

#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> 
void ZZ(const char* name, Arg1&& arg1){
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

vi wt, val;
int n, w; 
vector<vll> dp;

ll rec(int n, int W){
	if(W == 0)	return 0;
	if(n == 0)	return 1e15;
	ll &aux = dp[n][W];
	if(aux != -1)	return aux;
	aux = 1e15;
	aux = rec(n - 1, W);
	if(val[n] <= W)	aux = min(aux, wt[n] + rec(n - 1, W - val[n]));
	return aux;
}

int main(){
	ios::sync_with_stdio(0);
	cin >> n >> w;
	int W = 0;
	wt.assign(n + 1, 0);
	val.assign(n + 1, 0);
	frw(i, 1, n + 1)	cin >> wt[i] >> val[i], W += val[i];
	dp.assign(n + 1, vll (W + 1, -1));
	int ans = 0;
	frw(i, 1, W + 1){
		ll aux = rec(n, i);
		if(aux <= w)	ans = i;
	}
	cout << ans;
}

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

using namespace std;

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

#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple

#define iv inline void
#define ii inline int
#define ill inline ll

template <typename S, typename T>
inline bool smin(S &l, T r) {
  return r < l ? l = r, 1 : 0;
}
template <typename S, typename T>
inline bool smax(S &l, T r) {
  return l < r ? l = r, 1 : 0;
}

constexpr int MOD = 1e9 + 7;  // 998244353;

template <typename S>
inline S mod(S &l) {
  return l = (l % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}
ill po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

constexpr int N = 1e6 + 10;

int n, A, B;
vi res;

void solve(int mask, int last, int VAL) {
  if (__builtin_popcount(mask) == 1) {
    res.pb(VAL);
    res.pb(VAL ^ mask);
    return;
  }
  int bit = 1 << __builtin_ctz(last);
  int bit2 = 1 << __builtin_ctz(mask ^ bit);
  solve(mask ^ bit, bit2, VAL);
  solve(mask ^ bit, last ^ bit ^ bit2, VAL ^ bit2 ^ bit);
}

int main() {
#ifndef LOCAL
  // fileIO("");
#endif

  cin >> n >> A >> B;

  if ((__builtin_popcount(A ^ B) & 1) == 0) return cout << "NO\n", 0;

  cout << "YES\n";

  solve((1 << n) - 1, B ^ A, A);

  for (auto e : res) cout << e << ' ';

  return 0;
}


Measured memory_bytes: 1656
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if(500*i+100*j+k*50)==x:
                ans+=1
print(ans)


Measured memory_bytes: 3068
table=[[0]*3 for _ in range(3)]
A=[list(map(int,input().split())) for _ in range(3)]
A=sum(A,[])
N=int(input())
B=[int(input()) for _ in range(N)]

for b in B:
    tmp=[i for i,x in enumerate(A) if x==b]
    for t in tmp:
        table[t//3][t%3]=1

flag=False
n1,n2=0,0
for i in range(3):
    if sum(table[i])==3: flag=True
    if sum([table[j][i] for j in range(3)])==3: flag=True
    n1+=table[i][i]
    n2+=table[i][2-i]
if n1==3 or n2==3: flag=True
if flag: print('Yes')
else: print('No')


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n;
	cin >> n;
	cout << mod(n, 2) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input =sys.stdin.readline
import numpy as np
import itertools

H,W,K=(int(x) for x in input().rstrip('\n').split())

for i in range(H):
  x = list(input().rstrip('\n'))
  y = [0 if p=='.' else 1 for p in x]
  if i == 0:
    stage=np.array([y])
    stage=np.reshape(stage,(1,W))
  else:
    sta = np.array([y])
    sta=np.reshape(sta,(1,W))
    stage = np.append(stage,sta,axis=0)
total_h = [x for x in itertools.product((0,1),repeat=H)]
total_w = [x for x in itertools.product((0,1),repeat=W)]
res = 0
for h in total_h:
  for w in total_w:
    sta2 = [[0]*W]*H
    for i in range(H):
      if h[i]==1:
        sta2[i]=[1]*W
      else:
        sta2[i]=list(w)
    sta2 =np.array(sta2)
    sta_n = stage-sta2
    if np.sum(sta_n>0)==K:
      res += 1
print(res)


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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define fi first
#define se second
#define x first
#define y second
#define pb push_back
#define last(s) (s)[(s).size()-1]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("little.in", "r", stdin);freopen("little.out", "w", stdout);

using namespace std;

using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int,int>;\
using ull = unsigned long long;
using pll = pair<llong, llong>;
using psi = pair<string, int>;
using ll = pair<llong, llong>;

const llong over999 = 1e9;
const ld over999ld = 1e18+1;
const llong md = 1e9+7;
const ld eps = 1e-9;
const ld Pi = acos(-1);
const llong nich = 0;
const int mnogo = 300;

/**/

llong n, cnt[400];
string s;
int32_t main() {
    kchay;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> s;
        cnt[s[0]]++;
    }
    
    cout << cnt['M']*cnt['A']*cnt['R'] + cnt['M']*cnt['A']*cnt['C'] + cnt['M']*cnt['A']*cnt['H'] + cnt['M']*cnt['R']*cnt['C'] + cnt['M']*cnt['R']*cnt['H'] + cnt['M']*cnt['C']*cnt['H'] + cnt['A']*cnt['R']*cnt['C'] + cnt['A']*cnt['R']*cnt['H'] + cnt['A']*cnt['C']*cnt['H'] + cnt['R']*cnt['C']*cnt['H']; 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)



int main() {
	long long A[100001] = { 0 };
	long long N, K;
	cin >> N >> K;
	rep(i, 0, N) {
		int a, b;
		cin >> a >> b;
		A[a] += b;
	}
	int i = 0;
	long long sum = 0;
	while (sum < K && i < 100001) {
		i++;
		sum += A[i];

	}
	cout << i;


	return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);

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

    map<int, int> p;

    for (int i = 0; i < N; i++)
    {
        p[A[i] - 1] += 1;
        p[A[i] + 1] += 1;
        p[A[i]] += 1;
    }
    
    int max = 0;
    for(auto i : p) {
        if (max < i.second)
        {
            max = i.second;
        }
        
    }

    cout << max << endl;
    return 0;

}

Measured memory_bytes: 8440
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define ss second
#define ff first

using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
#define E 2000 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     if(a.first==b.first)
     {
     return (a.second < b.second); 
     }
     else
     {
       return (a.first > b.first); 
     }
     
} 
bool sortin(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     return (a.second < b.second);   
} 
signed main()
{   
  IOS


int n,k;
cin>>n>>k;
int h[n+1];
int dp[n+1];
dp[0]=dp[1]=0;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
dp[2]=abs(h[2]-h[1]);
for(int i=3;i<=n;i++)
{

  int val = INT_MAX;
  for(int j=i-1; j>=max((i-k),1*1LL); j--)
  {
   int hp = abs(h[i]-h[j]);

   val = min(val,hp+dp[j]);
    }
  dp[i]=val;
}
cout<<dp[n]<<endl;
}




 /* int h1 = abs(h[i]-h[i-1]);
  int h2 = abs(h[i]-h[i-2]);
 dp[i] = min(h1+dp[i-1],h2+dp[i-2]); */

Measured memory_bytes: 5176
package main

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

func isPalindrome(S string) bool {
	for i := 0; i < len(S)/2; i++ {
		if S[i] != S[len(S)-i-1] {
			return false
		}
	}
	return true
}

func main() {
	sc := NewScanner()
	S := sc.Next()
	N := len(S)

	if isPalindrome(S) && isPalindrome(S[:(N-1)/2]) && isPalindrome(S[(N+3)/2-1:]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func mapToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}

func PrintI(args ...int64) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn N, B[110];
void solve()
{
    itn ans = 0;
    ans += B[0];
    ans += B[N - 2];
    FOR(i, 0, N - 2)
    {
        ans += min(B[i], B[i + 1]);
    }
    cout << ans << endl;
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N - 1)
    cin >> B[i];
    solve();
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    int n, h;
    cin >> n >> h;

    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));

    int x = b.end() - upper_bound(all(b), a.back());

    int ans = 0;
    for(int i = n-1; i >= n-x; --i){
        ans++;
        h -= b[i];
        if(h <= 0) {
            h = 0;
            break;
        }
    }

    //cout << a.back() << "\n";
    ans += ceil(h / (double)a.back());
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 4004
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n", (a < b + c) ? (b + c - a) : 0);
	return 0;
}


Measured memory_bytes: 128
from collections import Counter

def modpow(a, n, m):
	r = 1
	while n > 0:
		if n & 1:
			r = r*a%m
		a = a*a%m
		n >>= 1
	return r

S,r = input(),0
dp = list(range(len(S)+1))
dp[-1],dp[-2] = 0,int(S[-1])

for i in range(3,len(S)+2):
	dp[-i] = (dp[-i+1] + modpow(10,i-2,2019)*int(S[-i+1])) % 2019

for x in Counter(dp).values():
	r += x*(x-1)//2
print(r)

Measured memory_bytes: 76316
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <list>
#include <queue>

using namespace std;

static const int INFTY = 2001;

int H;
int A[101];
int NodeNum[101];
int IndexInA[100];


int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return 2 * i + 1;
}

void minHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int smallest = i;
	if (l <= H && A[l] < A[i]) {
		smallest = l;
	}
	if (r <= H && A[r] < A[smallest]) {
		smallest = r;
	}
	if (smallest != i) {
		int temp = A[i];
		A[i] = A[smallest];
		A[smallest] = temp;
		temp = NodeNum[i];
		NodeNum[i] = NodeNum[smallest];
		NodeNum[smallest] = temp;
		IndexInA[NodeNum[i]] = i;
		IndexInA[NodeNum[smallest]] = smallest;

		minHeapify(smallest);
	}
}

void insert(int d, int nodeNum) {
	int i = ++H;
	A[i] = d;
	NodeNum[i] = nodeNum;
	IndexInA[nodeNum] = i;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int heapExtractMinNodeNum() {
	int minNodeNum = NodeNum[1];
	A[1] = A[H];
	NodeNum[1] = NodeNum[H];
	IndexInA[NodeNum[1]] = 1;
	H--;
	minHeapify(1);

	return minNodeNum;
}

void decrese(int i, int value) {
	A[i] = value;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int main() {
	int Dist[101];
	int AdjacenceyList[100][100];
	int AdjacenceyWeightList[100][100];
	int Degree[100];
	int i, j;
	int N;
	int W;
	int Deg;
	int MinTotalWeight = 0;
	int u, v;
	bool inT[100];

	cin >> N;

	for (i = 0; i < N; i++) {
		inT[i] = false;
		Dist[i] = INFTY;
		Deg = -1;
		for (j = 0; j < N; j++) {
			cin >> W;
			if(W != -1){
				AdjacenceyList[i][++Deg] = j;
				AdjacenceyWeightList[i][Deg] = W;
			}
		}
		Degree[i] = Deg + 1;
	}
	Dist[100] = INFTY;



	H = 0;
	u = 0;
	inT[u] = true;
	Dist[u] = 0;
	for (i = 1; i <= N - 1; i++) {
		for (j = 0; j < Degree[u]; j++) {
			v = AdjacenceyList[u][j];
			if (inT[v] == false) {
				W = AdjacenceyWeightList[u][j];
				if (Dist[v] == INFTY) {
					Dist[v] = W;
					insert(W, v);
				}
				else if (W < Dist[v]) {
					Dist[v] = W;
					decrese(IndexInA[v], W);
				}
			}
		}

		int minNodeNum = heapExtractMinNodeNum();
		inT[minNodeNum] = true;
		MinTotalWeight += Dist[minNodeNum];
		u = minNodeNum;

	}

	printf("%d\n", MinTotalWeight);

	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <sstream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
//#define min(A,B) ((A>B)?B:A)
//#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

#define M_PI 3.14159265358979

#define TOP 0
#define SOUTH 1
#define EAST 2
#define WEST 3
#define NORTH 4
#define BOTTOM 5

class Dice {
public:

	Dice(int args[]){
		for (int i = 0; i < 6; ++i) {
			labels[i] = args[i];
		}
	}
	void move(char d){
		int tmp[6];
		for (int i = 0; i < 6; ++i) {
			tmp[i] = labels[i];
		}

		switch(d){
	    case 'N':
	      labels[TOP] = tmp[SOUTH];
	      labels[SOUTH] = tmp[BOTTOM];
	      labels[BOTTOM] = tmp[NORTH];
	      labels[NORTH] = tmp[TOP];
	      break;
	    case 'S':
	      labels[SOUTH] = tmp[TOP];
	      labels[BOTTOM] = tmp[SOUTH];
	      labels[NORTH] = tmp[BOTTOM];
	      labels[TOP] = tmp[NORTH];
	      break;
	    case 'E':
	      labels[TOP] = tmp[WEST];
	      labels[WEST] = tmp[BOTTOM];
	      labels[BOTTOM] = tmp[EAST];
	      labels[EAST] = tmp[TOP];
	      break;
	    case 'W':
	      labels[WEST] = tmp[TOP];
	      labels[BOTTOM] = tmp[WEST];
	      labels[EAST] = tmp[BOTTOM];
	      labels[TOP] = tmp[EAST];
	      break;
		}
	}

	void prt(){
		for (int i = 0; i < 6; ++i) {
			cout << labels[i] << " ";
		}
		cout << endl;
	}

	int getPosOfLabel(int label){
		for (int i = 0; i < 6; ++i) {
			if(labels[i]==label)
				return i;
		}
		return -1;
	}

	void setST(int southLabel, int topLabel){
		switch(getPosOfLabel(southLabel)){
		case SOUTH:
			break;
		case NORTH:
			move('S');move('S');
			break;
		case EAST:
			move('W');move('S');
			break;
		case WEST:
			move('E');move('S');
			break;
		case TOP:
			move('S');
			break;
		case BOTTOM:
			move('N');
			break;
		}

		while(labels[TOP]!=topLabel){
			move('W');
		}
	}

	bool isSame(Dice another){
		Dice tmp(another.labels);
		tmp.setST(labels[SOUTH],labels[TOP]);
		for (int i = 0; i < 6; ++i) {
			if(tmp.labels[i]!=labels[i]){
				return false;
			}
		}
		return true;
	}


	string toString(){
		stringstream ret;
		for (int i = 0; i < 6; ++i) {
			ret << labels[i] << " ";
		}
		return ret.str();
	}

	void Normalize(){
		int tmp[6];
		for (int i = 0; i < 6; ++i) {
			tmp[i] = labels[i];
		}
		sort(tmp,tmp+6);
		if(getPosOfLabel(tmp[0])+getPosOfLabel(tmp[1])!=5){
			setST(tmp[0],tmp[1]);
		}else{
			setST(tmp[0],tmp[2]);
		}
	}

	int labels[6];
};

int main(){
	int n;
	cin >> n;
	string dstr[n];

	for (int i = 0; i < n; ++i) {
		int labels[6];
		for (int j = 0; j < 6; ++j) {
			cin >> labels[j];
		}
		Dice d(labels);
		d.Normalize();
		dstr[i] = d.toString();
//		println(dstr[i]);
	}
	sort(dstr,dstr+n);
	for (int i = 0; i < n-1; ++i) {
		if(dstr[i]==dstr[i+1]){
			println("No");
			return 0;
		}

	}

	println("Yes");

	return 0;
}



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



#define pi acos(-1)
typedef  long long ll;
typedef  unsigned long long ull;
typedef  unsigned un;

//defined taking input;
#define sf           scanf
#define si(a)        sf("%d",&a)
#define sc(a)        sf("%c",&a)
#define sii(a,b)     sf("%d %d",&a,&b)
#define siii(a,b,c)  sf("%d %d %d",&a,&b,&c)
#define sl(a)        sf("%lld",&a)
#define sll(a,b)     sf("%lld %lld",&a,&b);
#define slll(a,b,c)  sf("%lld %lld %lld",&a,&b,&c);

#define pf           printf
#define pfi(a)       pf("%d\n",a)
#define pfl(a)       pf("%ld\n",a)
#define pfn          pf("\n")
#define pfyes        pf("YES\n")
#define pfno         pf("NO\n")
#define pfYes        pf("Yes\n")
#define pfNo         pf("No\n")

#define wh            while
#define wht(t)        while(t--)


int main()
{
    //freopen("input","r",stdin);
    int a,b;
    sii(a,b);
    cout<<a*b<<endl;
    return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W ;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S.at(i);
  }
  vector<vector<int>> ans(H, vector<int>(W, 1001));
  ans.at(0).at(0)=0;
  if(S.at(0).at(0)=='#'){
    ans.at(0).at(0)++;
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int x=1000,y=1000;
      if(j!=0){
        if(S.at(i).at(j)==S.at(i).at(j-1)){
          x=ans.at(i).at(j-1);
        }else{
          x=ans.at(i).at(j-1)+1;
        }
      }
      if(i!=0){
        if(S.at(i).at(j)==S.at(i-1).at(j)){
          y=ans.at(i-1).at(j);
        }else{
          y=ans.at(i-1).at(j)+1;
        }
      }
      ans.at(i).at(j)=min(ans.at(i).at(j),min(x,y));
    }
  }
  if(S.at(H-1).at(W-1)=='#'){
    ans.at(H-1).at(W-1)++;
  }
  cout << ans.at(H-1).at(W-1)/2 << endl;
  
}
    

Measured memory_bytes: 256
n,m=map(int,input().split())
city={}
year=[]
for i in range(m):
    p,y=map(int,input().split())
    city[y]=p
    year.append(y)
city=sorted(city.items())
answer={}
count=[]
for i in range(n):
    count.append(1)
for i in city:
    f=str(i[1]).zfill(6)
    l=str(count[i[1]-1]).zfill(6)
    count[i[1]-1]=count[i[1]-1]+1
    answer[i[0]]=f+l
for i in year:
    print(answer[i])
    




Measured memory_bytes: 93656
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;


int main(){
   ll N,A,B; cin >> N >> A >> B;
   ll dis = abs(A-B);
   if(dis%2==0){
       cout << dis/2 << endl;
   }else{
       cout << min(A-1,N-B)+1+(B-A-1)/2<<endl;
   }

    return 0;
}


Measured memory_bytes: 3588