akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4765
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  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 c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
mint f2(int n, int k) {
  return comb(n+k-1,k-1);
}
mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  if (k < 1) return 0;
  return f2(n-k,k);
}

int main() {
  init();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    mint blue = f(k,i);
    mint red = f2(n-k-(i-1),i+1);
    mint ans = blue*red;
    printf("%lld\n", ans.x);
  }
  return 0;
}


Measured memory_bytes: 125696
import java.util.*;
import java.math.BigInteger;
// warm-up
// Reconciled???
public class Main {

	static BigInteger fact (BigInteger n) {
		BigInteger p = BigInteger.ONE;
		BigInteger m = new BigInteger("1000000007");
		int no = n.intValue();
		while (no-->0) {
			p = p.multiply(n).mod(m);
			n = n.subtract(BigInteger.ONE);
		}
		return p;
	}

	static void solve() {
		Scanner sc = new Scanner(System.in);
		BigInteger a = sc.nextBigInteger(), b = sc.nextBigInteger(), s = BigInteger.ZERO;
		BigInteger m = new BigInteger("1000000007");
		if (Math.abs(a.intValue()-b.intValue())==1) s = fact(a).multiply(fact(b)).mod(m); 
		else if (a.intValue()==b.intValue()) s = fact(a).multiply(fact(b)).multiply(new BigInteger("2")).mod(m);
		else { System.out.println(0); System.exit(0); }
		System.out.println(s);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 55596
A, B, C, D, E, F = gets.split.map(&:to_i)

w = [ 100 * A, 100 * B ]
water = Array.new(2+1) { Array.new(F+1, false) }
3.times { |i| water[i][0] = true }

2.times do |i|
  (1..F).each do |j|
    water[i+1][j] |= water[i][j]
    water[i+1][j] |= water[i+1][j-w[i]] if j >= w[i]
  end
end

s = [ C, D ]
sugar = Array.new(2+1) { Array.new(F+1, false) }
3.times { |i| sugar[i][0] = true }

2.times do |i|
  (1..F).each do |j|
    sugar[i+1][j] |= sugar[i][j]
    sugar[i+1][j] |= sugar[i+1][j-s[i]] if j >= s[i]
  end
end

max = -1
max_w, max_s = 0, 0
w, s = 0, 0
until w >= F
  if water[2][w]
    until s >= F
      if sugar[2][s]
        con = (100 * s) / (w + s).to_f
        if max < con
          max = con
          max_w = w
          max_s = s
        end
      end
      break if s + 1 > (w / 100) * E
      break if w + s + 1 > F
      s += 1
    end
  end
  w += 100
  break if w + s > F
end

puts [max_w + max_s, max_s] * " "

Measured memory_bytes: 1916
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}

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

ll comb(ll n, ll r){
  ll res=1;
    for(ll i=0;i<r;i++){
      res*=n-i;
      res%=MOD;
    }
  res*=modpow(factorial(r),MOD-2,MOD);
  res%=MOD;
  return res;
}
int main(){
  ll n,m;cin>>n>>m;
  map<ll,ll>M=prime_factor(m);
  ll ans=1;
  for(auto p:M){
    ll k=p.second;
    ans*=comb(k+n-1,k);
    ans%=MOD;
  }
  cout<<ans<<endl;
}
  
    
  
  

Measured memory_bytes: 256
#include<stdio.h>

int W, H, x, y, r;

int main(){
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    int flag = 0;
    if (0 <= x-r && x+r <= W){
        if (0<= y-r && y+r <= H){
            flag = 1;
        }
    }

    if (flag){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define maxarray 110
using namespace std;

int main() {
	int N, a[maxarray], b[maxarray], i, j, k;
	bool can = true,numset[maxarray];
	cin >> N;
	for (i = 1; i <= N; i++)
	{
		numset[i] = false;
		cin >> b[i];
		if (i < b[i])
			can = false;
	}
	if(!can)
		cout << "-1" << endl;
	else
	{
		for (i = 1; i <= N; i++)
		{
			j = i ;
			k = N + 1;
			while (1)
			{
				k--;
				while (1)
				{
					if (!numset[k])
						break;
					k--;
					j--;
				}
				if (b[k] == j)
				{
					numset[k] = true;
					cout << j << endl;
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=1e8;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	int a=0,b=0;
	rep(i,n){
		int q;cin>>q;
		if(q%2)a++;
		else b++;
	}
	int t=a/2;
	a-=t*2;
	b+=t;
	if(a&&b)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}











Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split()))
dic = {}

for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

total = 0
for value in dic.values():
    total += value * (value-1) / 2   # 使えないボールがない場合のtotal

for num in A:
    print(int(total - dic[num] + 1))


Measured memory_bytes: 107088
using System;

struct S
{
    public int A, B;
}

public class Program
{
    private int N;
    private long K;
    private S[] AB;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextLong();
        AB = new S[N];
        for (int i = 0; i < N; i++)
        {
            AB[i] = new S() {A = sc.NextInt(), B = sc.NextInt()};
        }
        
        Array.Sort(AB,(a,b)=>a.A.CompareTo(b.A));

        long min = -1;
        long max = 0;

        for (int i = 0; i < N; i++)
        {
            // [min,max)がA
            min = max;
            max += AB[i].B;
            if (min <= K - 1 && K - 1 < max)
            {
                Console.WriteLine(AB[i].A);
                return;
            }
        }
        
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 15944
// Created by Nikolay Budin

#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int n;
	cin >> n;
	if (n == 1) {
		cout <<	"First\n";
		return;
	}
	vector<vector<int>> graph(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	int best = -1, mem = -1;
	function<void(int, int, int)> dfs = [&](int v, int p, int d) {
		if (d > best) {
			best = d;
			mem = v;
		}
		for (int to : graph[v]) {
			if (to != p) {
				dfs(to, v, d + 1);
			}
		}
	};

	dfs(0, 0, 0);
	int tmp = mem;
	mem = -1, best = -1;

	dfs(tmp, tmp, 0);

	int diam = best;

	vector<int> d(diam + 1);
	d[0] = 1;
	d[1] = 0;
	for (int i = 2; i <= diam; ++i) {
		d[i] = !d[i - 1] | !d[i - 2];
	}

	if (d[diam]) {
		cout << "First\n";
	} else {
		cout << "Second\n";
	}
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 27648
#include <iostream>
#include <stdio.h>

using namespace std;


int main(int argc, char const *argv[])
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    int left = x - r;
    int right = x + r;
    int up = y + r;
    int down = y - r;

    bool L = ( left >= 0 && left <= W ) ? true : false;
    bool R = ( right >= 0 && right <= W ) ? true : false;
    bool U = ( up >= 0 && up <= H) ? true : false;
    bool D = ( down >= 0 && down <= H ) ? true : false;


    if ( L and R and U and D )
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }


    return 0;
}


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

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

    int main(){
        int a, b, c;
        std::cin >> a >> b >> c;
        if (a == b && b == c) std::cout << "No"<< "\n";
        else if (a != b && b != c && a != c) std::cout << "No" << "\n";
        else std::cout << "Yes" << "\n";
        return 0;
    }
    

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int k, a, b;
void in(){
    cin >> k >> a >> b;
}

void solve(){

    if(a >= b - 2){
        print(1 + k);
    }else{
        int d = b - a;
        k -= (a - 1);
        int ans = a;
        ans += k / 2 * d;
        if(k % 2 == 1) ans++;
        print(ans);

    }


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = 0
    var l = mutableListOf(n)
    for(i in 1..10000){
        when(l.last() % 2){
            0 -> l.add(l.last() / 2)
            1 -> l.add(l.last() * 3 + 1)
        }
        if(l.distinct() != l && a == 0){
            a = i + 1
        }
    }
    println(a)
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int n;
    cin>>n;
    int r=sqrt(n);
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def f(S):
    '''
    >>> f('(')
    '('
    >>> f(')(')
    ')('
    >>> f('()')
    ''
    >>> f('(())(')
    '('
    >>> f('())')
    ')'
     '''
    stack = []
    for s in S:
        if s == ')':
            if stack and stack[-1] == '(':
                stack.pop()
            else:
                stack.append(')')
        else:
            stack.append(s)
    return ''.join(stack)


def solve(N: int, S: str):
    s = f(S)
    return '(' * s.count(')') + S + ')' * s.count('(')


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(N, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 7404
import heapq
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)[:x]
qs = sorted(list(map(int, input().split())), reverse=True)[:y]
rs = sorted(list(map(int, input().split())))
apples = ps + qs
heapq.heapify(apples)
m = heapq.heappop(apples)
M = rs.pop()
while 1:
    if m < M:
        heapq.heappush(apples, M)
        if rs: 
            m = heapq.heappop(apples)
            M = rs.pop()
        else:
            break
    else:
        heapq.heappush(apples, m)
        break 
print(sum(apples))


Measured memory_bytes: 107660
#include<iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
#define lrep(i,n) for(long int i=0;i<(n);i++)
using namespace std;
int main(){
	long int k;
	cin >>k;
	long int num=0;
	lrep(i,k){
		num=(num*10+7)%k;
		if(num==0){
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout <<-1<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);
  vector<int> v;
  REP(i,n){
    int t;
    scanf("%d", &t);
    v.pb(t - 1);
  }

  bool pushed[100000] = {};
  
  int cur = v[0];
  int ans = 1;
  while(true){
    if(cur == 1){
      break;
    }
    if(pushed[cur]){
      printf("-1\n");
      return 0;
    }

    pushed[cur] = true;
    cur = v[cur];
    ans++;
    
  }
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	    Scanner s = new Scanner(System.in);
	    while(true){
		int in = s.nextInt();
		if(in==0)break;
		System.out.println(1+(int)(call(in)/3650));
	    }
      	}
	    static int call(int in){
		if(in==0)
		    return 0;
		if(in==1)
		    return 1;
		if(in==2)
		    return 2;
		if(in==3)
		    return 4;
		else
		    return call(in-3)+call(in-2)+call(in-1);
	    }
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = a*x + b*y;
  ans = min(ans, 2*c*min(x, y) + a*(x - min(x, y)) + b*(y - min(x, y)));
  ans = min(ans, 2*c*max(x, y));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
def breadth_first_search ms, visit_qs, paths
  i = visit_qs.shift
  ms[i].each do |a|
    if paths[a - 1] == -1
      paths[a - 1] = paths[i] + 1
      visit_qs << a - 1
    end
  end
  breadth_first_search ms, visit_qs, paths if visit_qs.length > 0
end

n = gets.to_i
ms = Array.new(n)
paths = Array.new(n, -1)
n.times do
  num, _, *adjacents = gets.chomp.split(' ').map(&:to_i)
  ms[num - 1] = adjacents
end
paths[0] = 0
breadth_first_search ms, [0], paths
paths.each_with_index do |p, i|
  puts "#{i + 1} #{p}"
end


Measured memory_bytes: 8904
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


//template<class T>
//inline bool chmax(T &a, T b) {
//    if (a < b) {
//        a = b;
//        return true;
//    }
//    return false;
//}

ll inf = 10000000;

int main() {
    int N, M;
    cin >> N >> M;
    int L, R, maxL = 0, minR = inf;
    REP(i, M) {
        cin >> L >> R;
        if (L > maxL) { maxL = L; }
        if (R < minR) { minR = R; }
    }
    cout << max(minR - maxL + 1,0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[100010];
int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
	sort (a + 1, a + n + 1);
	reverse (a + 1, a + n + 1);
	int x; for (x = 1; a[x] >= x; x++); x--;
	if ((a[x] - x) & 1) { printf ("First\n"); return 0; }
	int t; for (t = x; t <= n && a[t] >= x; t++); t--;
	if ((t - x) & 1) printf ("First\n");
	else printf ("Second\n");
	return 0;
}

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

int main() {
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  
  sort(a.begin(),a.end());
  
  if(a[0]+a[1]==a[2]){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0] * (W + 1) for i in range(N+1)]
for i in range(N):
  w, v = map(int, input().split())
  for j in range(W+1):
      if j - w >= 0:
        dp[i+1][j] = max(dp[i][j], dp[i][j-w] + v)
      else:
        dp[i+1][j] = dp[i][j]
print(max(dp[N]))

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

using namespace std;

int W, H;
int M[20][20];
int ans;

bool in(int x, int y) {
  return 0<=x && x<W && 0<=y && y<H;
}

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

void dfs(const int& sx, const int& sy, int k) {
  if(k >= 11) return;
  
  for(int i=0; i<4; i++) {
    int x = sx, y = sy;
    int nx = x + dx[i], ny = y + dy[i];
    
    if(in(nx, ny) && M[ny][nx] == 1) continue;
    
    while(in(nx, ny)) {
      if(M[ny][nx] == 3) { ans = min(ans, k); break; }
      if(M[ny][nx] == 1) {
	M[ny][nx] = 0;
	dfs(x, y, k+1);
	M[ny][nx] = 1;
	break;
      }
      x = nx, y = ny;
      nx = x + dx[i], ny = y + dy[i];
    }
    
  }
}

int main() {
  
  int stx, sty;
  
  while(cin >> W >> H && (W|H)) {
    for(int i=0; i<H; i++) {
      for(int j=0; j<W; j++) {
	cin >> M[i][j];
	if(M[i][j] == 2) stx = j, sty = i;
      }
    }
    
    ans = 11;
    dfs(stx, sty, 1);
    
    cout << ( ans<=10 ? ans : -1 ) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
数値の区切り位置を誤読しない
cout << fixed;
cout << setprecision(n) << ans;
 */

int main() {
    int n;
    cin >> n;
    int sum=0;
    int a[n];
    int len=1;
    rep(i,n){
        cin >> a[i];
        if(i!=0){
            if(a[i]==a[i-1]){
                len++;
            }
            else{
                sum+=len/2;
                len=1;
            }
            if(i==n-1){
                sum+=len/2;
            }
        }
      	//cerr << len << ' ' << sum << endl;
    }
    cout << sum;


    
}

/*
*/



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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  string ans = "Impossible";
  int A, B;
  cin >> A >> B;

  if (A % 3 == 0) {
    ans = "Possible";
  }
  if (B % 3 == 0) {
    ans = "Possible";
  }
  if ((A + B) % 3 == 0) {
    ans = "Possible";
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    S = input()
    count = 0
    for i in range(0,1000):
        num = str(i).zfill(3)
        digit = 0
        for j in range(N):
            if S[j] == num[digit]:
                digit += 1
            if digit == 3:
                break
        if digit ==3:
            count += 1

    print(count)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 40176
#include <stdio.h>
#define abs(a) ((a)>(0)?(a):-(a))
int main(){
  char a;
  int b=0,c=0;
  while(scanf("%c",&a)!=EOF){
  if(a=='0')b++;
  else if(a=='1') c++;
  }
  if(b>0&&c>0)printf("%d",b+c-(abs(b-c)));
  else printf("0");
}

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

using namespace std;

int main()
{
	int K, X;
	cin >> K >> X;

	int start = X - K + 1;
	int end = X + K - 1;
	for (int i = start; i <= end; i++) {
		cout << i << " ";
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 256
#146
S = input()

if S == 'MON':
    print("6")

elif S == 'TUE':
    print("5")

elif S == 'WED':
    print("4")

elif S == 'THU':
    print("3")

elif S == 'FRI':
    print("2")

elif S == 'SAT':
    print("1")

elif S == 'SUN':
    print("7")

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

int main() {
  int ans = 0;
  string s1;
  cin >> s1;
  for (int i = 0; i < 3; i++) {
    if (s1.at(i) == '1') {
      ans++;
    }
  }
  cout << ans << endl;
} 

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

using namespace std;

int main() {
	vector<int> v;
	int a, b, c; cin >> a >> b >> c;

	v.push_back(a);
	v.push_back(b);
	v.push_back(c);

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

	cout << abs(v[1] - v[0]) + abs(v[2] - v[1]) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g){
  for(int i=g;i<n;i++){
    int v = A[i];
    int j = i - g;
    while(j>=0 && A[j] > v){
      A[j+g] = A[j];
      j -=g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[],int n){
  for(int h = 1; ; ){
    if(h>n) break;
    G.push_back(h);
    h = 3*h +1;
  }
  for(int i=G.size()-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++) scanf("%d",&A[i]);
  cnt = 0;

  shellSort(A,n);

  printf("\n");
  
  cout << G.size() << endl;
  for(int i=G.size()-1;i>=0;i--){
    printf("%d",G[i]);
    if(i) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  for(int i=0;i<n;i++) printf("%d\n",A[i]);

  return 0;
}



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

int n, tmp;
std::map<int, int> m;
std::vector<int> vec;
int ans = 0;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> tmp;
        m[tmp]++;
        vec.push_back(tmp);
    }
    for (auto i = m.begin(); i != m.end(); i++) {
        if (i->first < i->second) {
            ans += (i->second - i->first);
        }
        else if (i->first > i->second) {
            ans += i->second;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 5112
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
string str;
map<string,bool> used;
int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    used.clear();
    cin>>str;
    int ans=0;
    for(int i=1;i<(int)str.size();i++){
      string a=str.substr(0,i);
      string b=str.substr(i);
      string c=a;
      string d=b;
      reverse(c.begin(),c.end());
      reverse(d.begin(),d.end());
      string t[]={a,c,b,d};
      for(int j=0;j<2;j++){
	for(int k=2;k<4;k++){
	  string e=t[j]+t[k];
	  string f=t[k]+t[j];
	  if(!used[e])ans++;
	  used[e]=true;
	  if(!used[f])ans++;
	  used[f]=true;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1304
func main() {
    let n = Int(readLine()!)!
    let aArray = readLine()!.split(separator: " ").map{Int($0)!}
    var sum = 0
    var add = 0
    for i in 0..<n-1 {
        if aArray[i+1] < aArray[i] + add {
            add = aArray[i] + add - aArray[i+1]
            sum += add
        } else {
            add = 0
        }
    }
    print(sum)
}

main()

Measured memory_bytes: 21328
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846 
const int mod = 1e9 + 7;

double calcAngle(double h, double m)  
{  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;  
}

int32_t main()
{
    fastio;

    double a, b; cin >> a >> b;
    double h, m; cin >> h >> m;

    double angle = calcAngle(h,m);
    // cout << angle << endl;
    double ans = sqrt(a*a+b*b-2*a*b*cos((M_PI*angle)/180));
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

/*
3 1 2 4
1 2 3
*/

Measured memory_bytes: 4184
def main():
    n = input()
    a_list = [int(i) for i in input().split()]

    rate_list = [0 for i in range(9)]

    for a in a_list:
        if 1 <= a and a < 400: rate_list[0] = 1
        elif 400 <= a and a < 800: rate_list[1] = 1
        elif 800 <= a and a < 1200: rate_list[2] = 1
        elif 1200 <= a and a < 1600: rate_list[3] = 1
        elif 1600 <= a and a < 2000: rate_list[4] = 1
        elif 2000 <= a and a < 2400: rate_list[5] = 1
        elif 2400 <= a and a < 2800: rate_list[6] = 1
        elif 2800 <= a and a < 3200: rate_list[7] = 1
        else: rate_list[8] += 1

    if 1 in rate_list[:-1]: minv = sum(rate_list[:-1])
    else: minv = 1

    print("{} {}".format(minv, sum(rate_list)))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int X,Y,Z;
	cin >> X >> Y >> Z;
	cout << (X-Z)/(Y+Z) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a,b,c,sum,d,f,g,sumz;
  scanf("%d %d %d",&a,&b,&c);

  while(!(a==-1 && b==-1 && c==-1)){

    sum=a*3600+b*60+c;
    sum=7200-sum;
    sumz=sum;

    d=sum/3600;
    sum%=3600;

    f=sum/60;
    sum%=60;

    g=sum;

    if(d<10){
      printf("0");
    }
    printf("%d:",d);

    if(f<10){
      printf("0");
    }
    printf("%d:",f);

    if(g<10){
      printf("0");
    }
    printf("%d\n",g);

    d=sumz/1200;
    sumz%=1200;

    f=sumz/20;
    sumz%=20;

    g=sumz*3;

    while(g>=60){
      f+=1;
      g-=60;
    }

    if(d<10){
      printf("0");
    }
    printf("%d:",d);

    if(f<10){
      printf("0");
    }
    printf("%d:",f);

    if(g<10){
      printf("0");
    }
    printf("%d\n",g);

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

  }

  return(0);
}

Measured memory_bytes: 0
k=int(input())
a=[]
a.append(list(map(int,input().split(" "))))
a.append(list(map(int,input().split(" "))))
s_max=0

for i in range(k):
	s=sum(a[0][0:i+1])+sum(a[1][i:])
	if(s>s_max):
		s_max=s;


print(s_max)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    bool flag=true;
    REP(i,n){
        int x;
        cin >> x;
        if(x%2==0){
            if(!(x%3==0 || x%5==0)) flag=false;
        }
    }
    if(flag) cout << "APPROVED";
    else cout << "DENIED";
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using  namespace std;
ll tree[N];
ll a[N];
ll fans[N];
vector<array<ll,2>>ta[N];
void update(ll x,ll ind){
	while(ind<=N){
		tree[ind]+=x;
		ind+=(ind&(-ind));
	}
}
ll sum(ll ind){
	ll ans=0;
	while(ind!=0){
		ans+=tree[ind];
		ind-=(ind&(-ind));
	}
	return ans;
}
int main(void){
	fast;
	ll n,i,q,x,y;
	cin>>n>>q;
	map<ll,ll>mp;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<q;i++){
		cin>>x>>y;
		ta[y].pb({x,i+1});
	}
	for(i=0;i<n;i++){
		if(mp[a[i]])
		update(-1,mp[a[i]]);
		update(1,i+1);
		mp[a[i]]=i+1;
		for(array<ll,2> p:ta[i+1])
			fans[p[1]]=sum(i+1)-sum(p[0]-1);
	}
	for(i=1;i<=q;i++){
		cout<<fans[i]<<endl;
	}
}


Measured memory_bytes: 83356
#include <stdio.h>
#include <string.h>

int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<10;i++){
		if(N%i==0&&N/i<10){
			printf("Yes\n");
			break;
		}else if(i==9){
			printf("No\n");
		}
	}
}



Measured memory_bytes: 1664
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}

//}}}

// -------------------- Spliters ------------------------
const int maxn = 1010;

long long a, b;
#define R return

int main() {
	find_me_at: 
	http://codeforces.com
	ios::sync_with_stdio(0);
	cin>>a>>b;
	if(a * b <= 0) { puts("Zero"); R 0; }
	if(a > 0) { puts("Positive"); R 0; }
	// a < 0, b < 0
	int cnt = abs(a - b) + 1;
	if(cnt & 1) puts("Negative");
	else puts("Positive");
	return 0;
}
// --USE C++11
// *-USE O2


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int main() {
	int A, B, T;
	cin >> A >> B >> T;

	int tmp = ((T + 0.5) / A);

	cout << B * tmp << endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define f first
#define s second
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vi vector<int>
#define vll vector<ll>
#define be begin
#define en end
#define endl '\n'
#define SIZE 1000000
#define w(t) int t;cin>>t;while(t--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define value_at_idx find_by_order
#define idx order_of_key
#define MOD 1000000007
#define reset(dp) memset(dp,0,sizeof(dp))

typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 

int dp[SIZE];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	reset(dp);
	dp[1] = 0;
	int n;
	cin>>n;
	vi v(n);
	for(int i=0;i<n;i++)
	cin>>v[i];
	
	dp[1] = abs(v[1] -v[0]);

	for(int i=2;i<n;i++)
	{
		dp[i] = min((dp[i-2] + abs(v[i]-v[i-2])),(dp[i-1] + abs(v[i]-v[i-1])));
	}
	cout<<dp[n-1]<<endl;


	return 0;
		
		

	
	
}
	
	


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
int H, W, N;
set<pair<int, int>> F, cand;
ll ans[10];

void add_cand(int y, int x) {
   if (y >= 0 && y < H-2 && x >= 0 && x < W-2) cand.insert({y, x});
}

int main() {
   cin >> H >> W >> N;
   rep (i, N) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      F.insert({a, b});
      rep (dy, 3) {
         rep (dx, 3) {
            add_cand(a-dy, b-dx);
         }
      }
   }

   ans[0] = (ll)(H-2) * (W-2);
   for (auto c : cand) {
      int y = c.first, x = c.second;
      int num = 0;
      rep (i, 3) {
         rep (j, 3) {
            if (F.find({y+i, x+j}) != F.end()) ++num;
         }
      }
      ans[0]--;
      ans[num]++;
   }

   rep (i, 10) {
      cout << ans[i] << endl;
   }

   return 0;
}

Measured memory_bytes: 47104
#include <iostream>

using namespace std;

int main(){
    int M1, M2, D1, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if(M1 != M2){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
from collections import Counter

input = sys.stdin.readline


def main():
    n = int(input())
    H = list(map(int, input().split()))
    if n == 1:
        print(0)
        return
    # 連続した場合、同値
    acc = list(accumulate([H[i] < H[i + 1] for i in range(n - 1)]))
    x, y = Counter(acc).most_common(1)[0]
    print(y if x == 0 else y - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22560
package main

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

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

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

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

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

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

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

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

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

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

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

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

// -----------------------------------------------------------------------------

var (
	memo = make(map[int]map[int]int64)
)

func ncr(n, r int) int64 {
	m, ok := memo[n]
	if ok {
		v, ok := m[r]
		if ok {
			return v
		}
	} else {
		memo[n] = make(map[int]int64)
	}

	if r == 0 || r == n {
		memo[n][r] = 1
		return 1
	}
	if n == 0 {
		memo[n][r] = 0
		return 0
	}

	v := ncr(n-1, r-1) + ncr(n-1, r)
	memo[n][r] = v
	return v
}

func main() {
	defer stdout.Flush()

	N := readInt()
	P := readInt()
	var even, odd int
	for i := 0; i < N; i++ {
		a := readInt()
		if a%2 == 0 {
			even++
		} else {
			odd++
		}
	}

	var ans int64
	for i := 0; i <= N; i++ {
		for e := 0; e <= even; e++ {
			o := i - e
			if o < 0 {
				break
			}
			if P == 0 && o%2 == 1 {
				continue
			}
			if P == 1 && o%2 == 0 {
				continue
			}
			ans += ncr(even, e) * ncr(odd, o)
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){
 
	return;
}
void solve(){
	ll n,m;
	cin>>n>>m;
	min_heap<pll>pq;
	for(int i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		pq.emp(a,b);
	}
	ll cnt=0,ans=0;
	while(cnt<m){
		pll u=pq.top();
		pq.pop();
		ans+=min(m-cnt,u.se)*u.fi;
		cnt+=min(m-cnt,u.se);
	}
	cout<<ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5380
eval"X,Y,*A=#"+`tr ' ' ,`
b=X+Y-a=A.inject(0,:^)
r=b/2
50.downto(0){|i|r+2**i>X||r|=a[i]<<i}
p r<1||r>X||b/2&a|b%2>0?-1:X-r

Measured memory_bytes: 14364
#include <bits/stdc++.h>
using namespace std;
int partition(vector<char> &S, vector<int> &V, int p, int r){
  int x = V[r];
  int i = p - 1;
  for (int j = p; j < r; j++){
    if (V[j] <= x){
      i++;
      swap(S[i], S[j]);
      swap(V[i], V[j]);
    }
  }
  swap(S[i + 1], S[r]);
  swap(V[i + 1], V[r]);
  return i + 1;
}
void quicksort(vector<char> &S, vector<int> &V, int p, int r){
  if (p < r){
    int q = partition(S, V, p, r);
    quicksort(S, V, p, q - 1);
    quicksort(S, V, q + 1, r);
  }
}
int main(){
  int n;
  cin >> n;
  vector<char> S(n);
  vector<int> V(n);
  for (int i = 0; i < n; i++){
    cin >> S[i] >> V[i];
  }
  map<int, queue<char> > M;
  for (int i = 0; i < n; i++){
    M[V[i]].push(S[i]);
  }
  quicksort(S, V, 0, n - 1);
  bool stable = true;
  for (int i = 0; i < n; i++){
    if (M[V[i]].front() != S[i]){
      stable = false;
      break;
    } else {
      M[V[i]].pop();
    }
  }
  if (stable){
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
  for (int i = 0; i < n; i++){
    cout << S[i] << ' ' << V[i] << endl;
  }
}


Measured memory_bytes: 21280
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <deque>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define INF 2*1e9
#define pb push_back
#define mp make_pair
#define Sort(v) sort(v.begin(),v.end());
#define SSort(v) sort(v.begin(),v.end(),greater<int>); 
using namespace std;
int main(void){
    while(1){
        int n;
        int rx=10,ry=10;
        cin>>n;
        if(n==0)break;
         vector<vector<int>> v(21,vector<int> (21,0));
        rep(i,0,n){
            int x,y;
            cin>>x>>y;
            v[x][y]=1;
        }
        
        int m;
        cin>>m;
        rep(i,0,m){
            char c;
            int x;
            cin>>c>>x;
            rep(j,0,x){
                if(c=='N')ry++;
                else if(c=='E')rx++;
                else if(c=='S')ry--;
                else if(c=='W')rx--;
                v[rx][ry]=0;
            }
        }
        
        rep(i,0,21){
            rep(j,0,21){
                if(v[i][j]==1){
                    cout<<"No"<<endl;
                    goto AWAY;
                }
            }
        }
        cout<<"Yes"<<endl;
        
        AWAY:;
    }
}

Measured memory_bytes: 3112