akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid;//固定高速

	int d;
	cin >> d;
	if (d == 25)cout << "Christmas" << rt;
	if (d == 24)cout << "Christmas Eve" << rt;
	if (d == 23)cout << "Christmas Eve Eve" << rt;
	if (d == 22)cout << "Christmas Eve Eve Eve" << rt;

	please AC;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[int], nb: int) -> int:
    for _v in values:
        pass
    return nb


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    prev = input()
    print("ABC" if prev == "ARC" else "ARC")


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 82340
/*
  AOJ 2619
  Title:Thread tree
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
int N;
struct node_st 
{
  char message[51];
  int  link_ch;         
  int  link_br;
} node[1001];
 
void write_thread(int node_no,int depth)
{
  int i;
  for(i=0;i<depth;i++)
    printf(".");
  printf("%s\n",node[node_no].message);
  if(node[node_no].link_ch>0)
    write_thread(node[node_no].link_ch,depth+1);
  if(node[node_no].link_br>0)
    write_thread(node[node_no].link_br,depth);
}
 
void set_link(int x,int y)
{
  if(node[x].link_ch==0)
    {
      node[x].link_ch=y;
    }
  else
    {
      x=node[x].link_ch;
      while(node[x].link_br>0)
    {
      x = node[x].link_br;
    }
      node[x].link_br=y;
    }
}
 
main()
{
  int i,re;
   
  scanf("%d",&N);
  for(i=1;i<=N;i++)
    {
      scanf("%d",&re);
      if(i>0)
    set_link(re,i);
      scanf("%s",&(node[i].message[0]));
    }
  write_thread(1,0);
   
  return(0);
}

Measured memory_bytes: 2704
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator++() { return *this += mint(1); }
    mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator--() { return *this -= mint(1); }
    mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint& a) const { mint res(*this); return res+=a; }
    mint operator-(const mint& a) const { mint res(*this); return res-=a; }
    mint operator*(const mint& a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const {
        mint res = mint(1),a(*this);
        while(t > 0) {
            if(t&1) res *= a;
            t >>= 1;
            a *= a;
        }
        return res;
    }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { mint res(*this); return res/=a; }
};
ostream& operator<<(ostream& os,const mint& m) { return os << m.x; }

mint dp[3100][3100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,s;
    cin >> n >> s;
    vi a(n);
    cin >> a;
    dp[0][0] = 1;
    rep(i,n) rep(j,s+1) {
        dp[i+1][j] += dp[i][j]*2;
        if(j+a[i] <= s) dp[i+1][j+a[i]] += dp[i][j];
    }
    cout << dp[n][s] << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

ll calc (string s) {
  ll ret = 0;
  rep(i, 0, s.size()) {
    char ch = s[s.size()-1-i];
    ll num = (ll) ch - '0';
    ret += num * POWLL(10, i);
  }

  return ret;
};

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

  string s;
  cin >> s;
  int size = s.size();
  vector<string> vec;
  rep(i, 0, (1 << (size-1))) {
    string e = "";
    rep(j, 0, size-1) {
      e += s[j];
      if (i >> j & 1) e += '+';
    }
    e += s[size-1];
    vec.pb(e);
  }

  ll ans = 0ll;
  for (string e: vec) {
    int idx = 0;
    ll tmp = 0ll;
    while (idx < e.size()) {
      string s_ = "";
      while (idx < e.size()) {
        if (e[idx] == '+') break;
        s_ += e[idx];
        idx++;
      }
      tmp += calc(s_);
      idx++;
    }
    ans += tmp;
  }

  cout << ans << endl;



  return 0;
};


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[110];
int p[110][15];
int f(int x,int y){
	if(x+y==0) return 0;
	if(x%2==0 || y%2==0) return f(x/2,y/2);
	if(x%2==y%2) return f(x/2,y/2)+1;
	return f(x/2,y/2);
}
int main(){
//	freopen("c.in","r",stdin);
	//freopen("c.out","w",stdout);
	int n;
	cin>>n;
	int x;
	for(int i=1;i<=n;++i){
		for(int j=9;j>=0;--j){
			scanf("%d",&x);
			a[i]+=x*(1<<j);
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=0;j<=10;++j)
			scanf("%d",&p[i][j]);
	}
	int m=1<<10;
	int ans=-2147483647;
	for(int i=1;i<m;++i){
		int s=0;
		for(int j=1;j<=n;++j){
			s+=p[j][f(i,a[j])];	
		}
		if(s>ans) ans=s;
	}
	cout<<ans;
	return 0;	
}


Measured memory_bytes: 256
N,K=map(int,input().split())
potential=[x for x in range(N+1) if x>0 and x<K]
win_count=[]
for x in potential:
    y=1
    able=0
    while 1:
        if x*2**y>=K:
            able=(2**y-1)/(2**y)
            win_count+=[able]
            break
        y+=1

answer=1-(sum(win_count)/N)
#print(potential)
#print(win_count)
print(round(answer,12))


Measured memory_bytes: 3700
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	ll h, w;
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = min(h, w);
	FOR(i, 1, h) {
		ll a = w * i;
		ll b = w / 2 * (h - i);
		ll c = w * (h - i) - b;
		ll m = max(max(a, b), c);
		ll n = min(min(a, b), c);
		ans = min(m - n, ans);
	}
	FOR(i, 1, w) {
		ll a = h * i;
		ll b = h / 2 * (w - i);
		ll c = h * (w - i) - b;
		ll m = max(max(a, b), c);
		ll n = min(min(a, b), c);
		ans = min(m - n, ans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int arr[100005];
int cost[100005];

int main()
{
	int n, k;
	cin>>n>>k;
	for(int i = 1; i<=n; i++)
	{
			cin>>arr[i];
			cost[i]=1000000000;
	}
	cost[1]=0;
	for(int i = 1; i<=n; i++)
	{
		for(int j=1; j<=k; j++)
		{
			if(i+j>n)
					break;

		int x = arr[i+j]-arr[i];
		x = x>0?x:-x;
		cost[i+j]=min(cost[i+j],cost[i]+x);
		
		}
	}
	cout<<cost[n];
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int a,b;
        cin>>a>>b;
        if(b==1){
        	cout<<0;
        	r0;
        }
        int cur = 1;
        rep(i,1,100){
        	cur += a-1;
        	if(cur>=b){
        		cout<<i;
        		r0;
        	}
        }
    }   
}     

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

int main(void) {
  int N, X;
  cin >> N >> X;
  int minm = 1e8;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    X -= m;
    minm = min(minm, m);
  }
  cout << N + X / minm << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

Measured memory_bytes: 26780
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

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

using namespace std;


int main(){
    const int INF = 1<<28;
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> D(N);
    vector<int> c(N);
    REP(i,N){
        int a, b;
        cin >> a >> b >> c[i];
        a *= Mb;
        b *= Ma;
        D[i] = a - b;
    }

    map<int, int> memo;

    int res = INF;
    int m = N/2;
    REP(i, 1<<m){
        if(i==0)continue;
        int sum_d = 0;
        int sum_c = 0;
        REP(j, m){
            if((i>>j)&1){
                sum_d += D[j];
                sum_c += c[j];
            }
        }
        if(sum_d==0)res = min(res, sum_c);
        sum_d = -sum_d;
        if(memo.count(sum_d) == 0){
            memo[sum_d] = INF;
        }
        memo[sum_d] = min(memo[sum_d], sum_c);
    }

    int L = N - m;
    REP(i, 1<<L){
        if(i==0)continue;
        int sum_d = 0;
        int sum_c = 0;
        REP(j, L){
            if((i>>j)&1){
                int k = m + j;
                sum_d += D[k];
                sum_c += c[k];
            }
        }
        if(sum_d==0)res = min(res, sum_c);
        if(memo.count(sum_d) == 0){
            continue;
        }
        // cout << i << " " << sum_d << endl;
        res = min(res, memo[sum_d] + sum_c);
    }

    cout << (res == INF ? -1 : res) << endl;

    return 0;
}


Measured memory_bytes: 256
inf = float('inf')
V,E,P = map(int,input().split())
edge = []
for i in range(E):
    A,B,C = map(int,input().split())
    edge.append([A-1,B-1,P-C])

d = [inf]*V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break

ans = d[V-1]

for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break
loop = ans != d[V-1]

if loop:
    print(-1)

else:
    ans = -d[-1]
    print(max(0,ans))

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

int main(){
    ll N;
    cin >> N;
    vector<ll> C(N), S(N), F(N);
    rep(i, 0, N-1) cin >> C[i] >> S[i] >> F[i];
    rep(i, 0, N){
        ll ans = 0;
        rep(j, i, N-1){
            if(ans < S[j]) ans = S[j];
            else if(ans % F[j] != 0) ans += F[j] - ans % F[j];
            ans += C[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())

int h,w,m,a[300005],b[300005],p1,p2;
set<pii> st;

signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	cin>>h>>w>>m;
	vector<int> l,r;
	int x,y;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y;
		st.insert(mk(x,y));
		a[x]++;
		b[y]++;
		if(a[x]>p1)
		{
			l.clear();
			p1=a[x];
		}
		if(a[x]==p1)
			l.pb(x);
		if(b[y]>p2)
		{
			r.clear();
			p2=b[y];
		}
		if(b[y]==p2)
			r.pb(y);
	}
	for(i=0;i<l.size();i++)
	{
		for(j=0;j<r.size();j++)
		{
			if(st.find(mk(l[i],r[j]))==st.end())
			{
				cout<<p1+p2<<endl;
				return 0;
			}
		}
	}
	cout<<p1+p2-1<<endl;
	return 0;
}


Measured memory_bytes: 21892
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//################################################################
const int N=100009;
int n,a[N],b[N],c[N];
int mem[N][4];

int main() {
    n=D();
    for(int i=0;i<n;i++){
        a[i]=D(),b[i]=D(),c[i]=D();
    }
    mem[0][0]=a[0];
    mem[0][1]=b[0];
    mem[0][2]=c[0];
    for(int i=1;i<n;i++){
        mem[i][0]=a[i]+max(mem[i-1][1],mem[i-1][2]);
        mem[i][1]=b[i]+max(mem[i-1][0],mem[i-1][2]);
        mem[i][2]=c[i]+max(mem[i-1][0],mem[i-1][1]);
    }
    printf("%d",max(max(mem[n-1][0],mem[n-1][1]),mem[n-1][2]));

}

Measured memory_bytes: 2944
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}
/*

 */
string s;

int main()
{
  cin >> s;
  int e[2] = {0, 0};
  int o[2] = {0, 0};
  for (size_t i = 0; i < s.size(); i++)
  {
    if(i%2==0){
      e[s[i]-'0']++;
    } else {
      o[s[i]-'0']++;
    }
  }

  int ans = min(e[0] + o[1], e[1] + o[0]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n, p int
	var s string
	fmt.Scan(&n, &p, &s)

	if p == 2 || p == 5 {
		ans := 0
		for i := 0; i < len(s); i++ {
			if int(s[i]-'0')%p == 0 {
				ans += i + 1
			}
		}
		fmt.Println(ans)
		return
	}

	s = reverse(s)
	ms := make(map[int]int)
	ms[0] = 1
	m := 0
	x := 1
	ans := 0
	for i := 0; i < len(s); i++ {
		m = (m + int(s[i]-'0')*x) % p
		ans += ms[m]
		ms[m]++
		x *= 10
		x %= p
	}
	fmt.Println(ans)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqA = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

        var dp = new (long Balance, long Price)[seqA.Length + 1];
        dp[0] = (1000, long.MaxValue);
        for (int i = 1; i < dp.Length; ++i)
        {
            for (int j = 0; j < i; ++j)
            {
                if (dp[j].Balance > dp[i].Balance)
                {
                    dp[i] = (dp[j].Balance, seqA[i - 1]);
                }

                var b = dp[j].Balance + (dp[j].Balance / dp[j].Price) * (seqA[i - 1] - dp[j].Price);
                if (b > dp[i].Balance)
                {
                    dp[i] = (b, seqA[i - 1]);
                }
            }
        }

        Console.WriteLine(dp.Last().Balance);
    }
}


Measured memory_bytes: 28152
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long int N,A,B;
	scanf("%lld%lld%lld",&N,&A,&B);
	if(A>B) {
		printf("0\n");
		return 0;
	}
	if(N==1) {
		if(A==B) {
			cout<<"1"<<endl;
			return 0;

		} else {
			cout<<"0"<<endl;
			return 0;
		}
	}
	printf("%lld",((B-A)*(N-2)+1));
	return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ds = list(mapint())
M = int(input())
Ts = list(mapint())

from collections import Counter
c = Counter(Ds)
for t in Ts:
    if c[t]==0:
        print('NO')
        break
    else:
        c[t] -= 1
else:
    print('YES')

Measured memory_bytes: 137160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int K;
    string S;
    cin >> K >> S;
  
    if(K >= S.size()) {
        cout << S << endl;
    } 
    else {
        for (int i=0;i<K;i++) {
            cout << S[i];
        }
        cout << "..." << endl;
    }
   
 
    
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-12;

ll a[MAXN];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, A, B;
	cin >> n >> A >> B;
	for(int i = 0; i < n; i++) cin >> a[i];
	ll ans = abs(a[n - 1] - B);
	ll mn;
	for(int i = 0; i < n - 1; i++){
		mn = abs(a[i] - a[n - 1]);
		for(int j = i + 1; j < n - 1; j++){
			mn = min(mn, abs(a[n - 1] - a[j]));
		}
		ans = max(mn, ans);
	}
	cout << ans;
	return 0;
}


/*
6  3
1  1  3  3  3  5
10  2  3
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/




Measured memory_bytes: 384
#include <cstdio>


int N,K;
const int mod=1e9+7;
const int MAXN=1e5+10;

typedef long long int ll;

ll count[MAXN];

ll fast_power(ll base,int exp){
    if (exp==0) return 1ll;

    ll temp=fast_power(base,exp/2);
    temp=(temp*temp)%mod;

    if (exp%2) temp=(temp*base)%mod;

    return temp;
}

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

    for(int k=K;k>=1;k--){
        int c=K/k;
        ll total=fast_power(c,N);

        for(int i=k*2;i<=K;i+=k) total=(total+(mod-count[i]))%mod;

        count[k]=total;
    }

    ll sum=0ll;
    for(int i=1;i<=K;i++){
        ll temp=(i*count[i])%mod;
        sum=(sum+temp)%mod;

    }

    printf("%lld\n",sum);

    return 0;
}

Measured memory_bytes: 2504
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define maxn 100005
vector<int> tree[maxn];
vector<int> query[maxn];
int father[maxn];
int depth[maxn];
ll ans = 0;
int findSet(int x)//路径??
{
	if (x == father[x])
		return x;
	else
		return father[x] = findSet(father[x]);
}
void unionSet(int x, int y)//把y并到x中去
{
	int fx = findSet(x);
	int fy = findSet(y);
	if (fy == fx)
		return;
	father[fy] = fx;
}
void bfs()
{
	queue<int> Q;
	Q.push(1);
	int last = 0;
	int t;
	while (!Q.empty())
	{
		t = Q.front();
		if (last != 0)
		{
			query[last].push_back(t);
		}
		last = t;
		Q.pop();
		for (unsigned int i = 0; i < tree[t].size(); ++i)
		{
			Q.push(tree[t][i]);
		}
	}
}
void Tarjan_LCA(int u)
{
	father[u] = u;
	int t;
	for (unsigned int i = 0; i < tree[u].size(); ++i)
	{
		t = tree[u][i];
		depth[t] = depth[u] + 1;
		Tarjan_LCA(t);
		unionSet(u, t);
	}
	for (unsigned int i = 0; i < query[u].size(); ++i)
	{
		t = query[u][i];
		if (father[t] != 0)
		{
			//printf("sum %d %d\n", u, t);
			ans += (ll)depth[u] + (ll)depth[t] - 2 * (ll)depth[findSet(t)];
		}
		else
		{
			query[t].push_back(u);
		}
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	scanf("%d", &n);
	int tmp;
	for (int i = 2; i <= n; ++i)
	{
		scanf("%d", &tmp);
		tree[tmp].push_back(i);
	}
	bfs();
	/*for (int i = 1; i <= n; ++i)
	{
		for (unsigned int j = 0; j < query[i].size(); ++j)
			printf("%d ", query[i][j]);
		printf("\n");
	}*/
	Tarjan_LCA(1);
	/*for (int i = 1; i <= n; ++i)
		printf("%d ", depth[i]);
	printf("\n");*/
	printf("%lld\n", ans);
	//system("pause");
	//while (1);
	return 0;
}

Measured memory_bytes: 19644
//
//  main.cpp
//  procon
//
//  Created by ???????????? on 2015/05/21.
//  Copyright (c) 2015??´ y. inoue. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

int main(int argc, const char * argv[]) {
    while (true) {
        string s;
        cin >> s;
        int hand[26] = {0, 0, 0, 0, 0, 0, 0,
            1, 1, 1, 1, 1, 1, 1, 1, 1,
            0, 0, 0, 0,
            1, 0, 0, 0, 1, 0};

        if (s == "#") {
            break;
        }

        int ans = 0;
        for (int i = 1; i < s.length(); i++) {
            if (hand[s[i-1] - 97] != hand[s[i] - 97]) {
                ans++;
            }
        }

        cout << ans << "\n";
    }
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> z(n + 3);
    z.at(0) = 1;
    z.at(1) = 0;
    z.at(2) = 0;
    vector<ll> u(n + 3);
    u.at(0) = 1;
    u.at(1) = 1;
    u.at(2) = 1;
    for (int i = 3; i < n + 3; i++) {
        z.at(i) = z.at(i - 1) + u.at(i - 3);
        z.at(i) %= 1000000007;
        u.at(i) = z.at(i)+u.at(i-1);
        u.at(i) %= 1000000007;
    }
    cout << ((z.at(n + 2)*n%1000000007-u.at(n-1)*(n-1)%1000000007+1000000007)%1000000007 * (n-1) % 1000000007 +1)%1000000007<< endl;
}

Measured memory_bytes: 15872
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {
	static int n, m;
	static char[][] imageN, imageM;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		imageN = new char[n][n];
		for(int i = 0; i < n; i++)
			imageN[i] = sc.next().toCharArray();
		imageM = new char[m][m];
		for(int i = 0; i < m; i++)
			imageM[i] = sc.next().toCharArray();
			
		boolean flag = false;
		for(int i = 0; i < n - m + 1; i++) {
			for(int j = 0; j < n - m + 1; j++) {
				flag = func(i, j);
				if(flag) break;
			}
			if(flag) break;
		}
		if(flag) out.println("Yes");
		else out.println("No");
		out.close();
	}
	//同一性判定。引数は始点（左上）の座標
	static boolean func(int y, int x) {
		boolean flag = true;
		for(int i = y; i < y + m; i++) {
			for(int j = x; j < x + m; j++) {
				if (imageN[i][j] != imageM[i - y][j - x]) {
					flag = false;
					break;
				}
			}
			if(!flag) break;
		}
		return flag;
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 23380
fun main(args: Array<String>) {
    val max = 1000000000
    val (N, K, S) = listOfInt()
    val A = mutableListOf<Int>()
    for (k in 0 until K) {
        A.add(S)
    }
    for (n in 0 until N - K) {
        A.add(if (S != max) max else max-1)
    }
    println(A.joinToString(separator = " "))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 46368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;

ll mini(vector<ll> a, vector<ll> b, ll x) {
  ll res = 1e18;
  rep(i, a.size()) {
    res = min(res, a[i] + b[i] * x);
  }
  return res;
}

ll maxi(vector<ll> a, vector<ll> b, ll x) {
  ll res = -1e18;
  rep(i, a.size()) {
    res = max(res, a[i] + b[i] * x);
  }
  return res;
}

// f(x+1)-f(x)>=d
ll boundmin(vector<ll> a, vector<ll> b, ll d) {
  ll l = -1;
  ll r = 4e8;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (-mini(a, b, m + 1) + mini(a, b, m) >= d) r = m; else l = m;
  }
  return r;
}

ll boundmax(vector<ll> a, vector<ll> b, ll d) {
  ll l = -1;
  ll r = 4e8;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (maxi(a, b, m + 1) - maxi(a, b, m) >= d) r = m; else l = m;
  }
  return r;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> X(N), Y(N);
  vector<ll> DX(N), DY(N);
  rep(i, N) {
    cin >> X[i] >> Y[i];
    X[i] *= 2;
    Y[i] *= 2;
    char c;
    cin >> c;
    if (c == 'L') DX[i] = -1;
    if (c == 'R') DX[i] = 1;
    if (c == 'D') DY[i] = -1;
    if (c == 'U') DY[i] = 1;
  }
  set<ll> events;
  events.insert(0);
  events.insert(boundmin(X, DX, 0));
  events.insert(boundmin(X, DX, 1));
  events.insert(boundmax(X, DX, 0));
  events.insert(boundmax(X, DX, 1));
  events.insert(boundmin(Y, DY, 0));
  events.insert(boundmin(Y, DY, 1));
  events.insert(boundmax(Y, DY, 0));
  events.insert(boundmax(Y, DY, 1));
  ll ans = 9e18;
  for (ll x : events) {
    ll dx = maxi(X, DX, x) - mini(X, DX, x);
    ll dy = maxi(Y, DY, x) - mini(Y, DY, x);
    ans = min(ans, dx * dy);
  }
  cout << ans/4 << '.' << ans%4*25 << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int max_n = 1011, inf = 1000111222;
const int mod = 1000000007;

int n, m, a[max_n], b[max_n], used1[max_n], used2[max_n];
int cnt1, cnt2, cnt_free;
int ans;
pair<int, int> v[max_n * max_n];

void fin() {
	cout << 0 << endl;
	exit(0);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	cin >> n >> m;
	for (int i = 0; i < max_n * max_n; ++i) v[i] = {-1, -1};
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (v[a[i]].F != -1) {
			fin();
		}
		v[a[i]].F = i;
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
		if (v[b[i]].S != -1) {
			fin();
		}
		v[b[i]].S = i;
	}
	ans = 1;
	for (int i = n * m; i > 0; --i) {
		//cout << i << ": (" << v[i].F << ", " << v[i].S << "), " << cnt1 << ", " << cnt2 << ", " << cnt_free << endl;
		if (v[i].F != -1 && v[i].S != -1) {
			cnt_free += cnt1 + cnt2;
			++cnt1;
			++cnt2;
			if (used1[v[i].F] || used2[v[i].S]) fin();
			used1[v[i].F] = 1;
			used2[v[i].S] = 1;
			continue;
		}
		int add = 0;
		if (v[i].F == -1 && v[i].S == -1) {
			add = cnt_free;
			--cnt_free;
		} else {
			if (v[i].F == -1) {
				add = cnt1;
				cnt_free += cnt1 - 1;
				++cnt2;
				if (used2[v[i].S]) fin();
				used2[v[i].S] = 1;
			} else {
				add = cnt2;
				cnt_free += cnt2 - 1;
				++cnt1;
				if (used1[v[i].F]) fin();
				used1[v[i].F] = 1;
			}
		}
		ans = 1LL * ans * add % mod;
	}
	if (cnt1 != n || cnt2 != m || cnt_free != 0) fin();
	cout << ans << endl;
    return 0;
}


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

int comp(const void* a, const void* b)  
{ return *(int*)a > *(int*)b ; }  
  
 
int findNumberOfTriangles(int arr[], int n)  
{  
 
    qsort(arr, n, sizeof( arr[0] ), comp);  
  
      
    int count = 0;  
  
    
    for (int i = 0; i < n - 2; ++i)  
    {  
        
        int k = i + 2;  
  
       
        for (int j = i + 1; j < n; ++j)  
        {  
           
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
  
           
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
}  
  
 
int main()  
{  
    int a[100000],n;
    cin>>n;
    
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
  
    cout<<findNumberOfTriangles( a, n );  
  
    return 0;  
}

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


using namespace std;





long long dp[(int)2e5+7];
vector<int>v;

int n,a,b;
long long solve(int idx){
    
    if(idx==n-1){
        return 0;
    }
    long long &ret=dp[idx];
    if(ret!=-1)return ret;

    
    
    ret=min(solve(idx+1)+(a * (v[idx+1]-v[idx])),solve(idx+1)+b);
    cerr<<idx<<" "<<ret<<endl;
    
    return ret;
}
int main(){

#ifndef ONLINE_JUDGE
    //freopen("in","r",stdin);
#endif
     ios::sync_with_stdio(false);
     cin.tie(0);

     cin>>n>>a>>b;
     v.resize(n);
     
     for(int i=0;i<n;i++){
         cin>>v[i];
     }
     long long ans=0;
     for(int i=0;i<n-1;i++){
         ans+=min(1ll*(v[i+1]-v[i])*a,1ll*b);
     }
     
     cout<<ans<<endl;
    
   

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vl a(n+1);
    cin>>a;
    vl b(n);
    cin>>b;
    ll ans=0;
    REP(i,n){
        ans+=min(a[i],b[i]);
        b[i]-=min(a[i],b[i]);
        ans+=min(b[i],a[i+1]);
        a[i+1]-=min(b[i],a[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
a=[0,1]
2.upto(n=gets.to_i){|i|
  l=[]
  p=3
  2.times{
    p+=3
    d=1
    l<<a[i-d]until(d*=p)>i
  }
  l<<a[i-1]
  a[i]=l.min+1
}
p a[n]

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

const ll INF = 1LL << 60;

ll N;
int main() {
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    rep(i, N) {
        ll b = B[i];
        ll a_idx = upper_bound(A.begin(), A.end(), b - 1) - A.begin();
        ll c_idx = lower_bound(C.begin(), C.end(), b + 1) - C.begin();

        // cout << a_idx << " " << (N - c_idx) << endl;
        ll tmp = a_idx * (N - c_idx);
        ans += tmp;
        // cout << c << " " << b << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2688
import java.util.*;
class Main{
  public static void main(String args[]){
    StringBuilder bl = new StringBuilder();
    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();
    }
    int i = partition(A,0,A.length-1);
    if(0==i)bl.append('[').append(A[0]).append(']');
    else bl.append(A[0]);
    for(int j = 1; j<A.length; j++){
      if(j==i)bl.append(' ').append('[').append(A[j]).append(']');
      else bl.append(' ').append(A[j]);
    }
    System.out.println(bl);

  }
  static int partition(int A[], int p, int r){
    int x = A[r];
    int i = p-1;
    int tmp;
    for(int j =p; j<r; j++){
      if(A[j]<=x){
        i = i+1;
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    return i+1;
  }
}


Measured memory_bytes: 68884
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i;
    cin>>n;
    vector<ll> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    ll con=0;
    sort(v.begin(),v.end(),greater<ll>());
    con+=v[0];
    if(n%2==1)
    {
        ll p=n-1;
        for(i=1;i<p/2;i++)
        {
            con+=v[i];
            con+=v[i];
        }
        con+=v[i];
    }
    else
    {
        ll p=n-1;
       // cout<<p<<" "<<p/2<<endl;
        for(i=1;i<=p/2;i++)
        {
            con+=v[i];
            con+=v[i];
        }
    }
    cout<<con;
    return 0;
}

Measured memory_bytes: 4780
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
x=0;y=0;z=0
for i in range(n):
  if p[i]<=a:x+=1
  elif p[i]>b:z+=1
  else:y+=1
print(min(x,y,z))

Measured memory_bytes: 3064
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
total = 0
for i in range(n+1):
  total += abs(a[i] - a[i+1])

for i in range(1,n+1):
  ans = total - abs(a[i+1] - a[i]) - abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1])
  print(ans)

Measured memory_bytes: 14048