akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import pdb


def main():
    AB = raw_input().split(' ')
    A = int(AB[0])
    B = int(AB[1])
    S = np.array(list(raw_input()))
    if checkpostal(S,A,B):
        print 'Yes'
    else:
        print 'No'

def checkpostal(S, A, B):
    integers = [str(k) for k in range(10)]
    checkpasses = True
    if len(S) !=  A + B + 1:
        return False

    for k in range(len(S)):
        if k == A:
            mypass = (S[k] == '-')
            checkpasses = checkpasses and mypass
        else:
            mypass = S[k] in integers
            checkpasses = checkpasses and mypass

    return checkpasses

if __name__ == '__main__':
    main()


Measured memory_bytes: 20828
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define Yes(n) cout<<((n)?"Yes\n":"No\n")
#define pb push_back
using namespace std;
using ll = long long;

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<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
vector<string> split(const string&s,char d){vector<string>r;stringstream ss(s);string k;while(getline(ss,k,d))if(!k.empty())r.pb(k);return r;}

// Template ends here

int main() {
    ll a, b, c, cnt = 0; cin >> a >> b >> c;
    if (a == b && b == c) {
        if (a % 2) cout << "0\n";
        else cout << "-1\n";
        return 0;
    }

    ll base = (a + b + c) / 2;
    while((a % 2 == 0) && (b % 2 == 0) & (c % 2 == 0)) {
        a = base - a / 2;
        b = base - b / 2;
        c = base - c / 2;
        cnt++;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

//////////////////////////



int main(){fastio
    ll n;cin>>n;
    n%=10;
    if(n==3){
        cout<<"bon";
    }else if(n==0||n==1||n==6||n==8){
        cout<<"pon";
    }else{
        cout<<"hon";
    }
    return 0;
}


Measured memory_bytes: 3652
S = gets.chomp.split(//)

g_count = 0
p_count = 0
win_count = 0
lose_count = 0

S.each do |c|
  if c == 'g'
    if p_count + 1 <= g_count
      win_count += 1
      p_count += 1
    else
      g_count += 1
    end
  else
    if p_count + 1 <= g_count
      p_count += 1
    else
      lose_count += 1
      g_count += 1
    end
  end
end

p win_count - lose_count

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 3e3+34;
const ll inf = 1e18+7;
ll dp[MAX],arr[MAX];
int main(){
  fastio;
  ll n;
  cin>>n;
  f(i,0,n){
    cin>>arr[i];
    dp[i]=arr[i];
  }
  f(i,1,n){
    f(j,0,n-i) dp[j]=max(arr[i+j]-dp[j],arr[j]-dp[j+1]);
  }
  cout<<dp[0]<<"\n";
  return 0; 
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);
const long long MOD = 1000000007;

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, k;

    cin >> n >> k;

    ll ct = 0;
    REP(i, n-k+2){
        ll x = i+k;
        ll mn = x%2==0 ? (x/2 + (x/2-1)*x) : (x*(x/2));
        ll mx = n*x - mn;
        ct += (mx-mn+1)%MOD;
        ct %= MOD;
    }

  	cout << ct << endl;

    return 0;
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll x, y, z, need;
	cin >> x >> y >> z >> need;

	vector<vector<ll>>a(3);
	a[0].resize(x);
	a[1].resize(y);
	a[2].resize(z);

	for (int i = 0; i < 3; i++) {
		for (auto &x : a[i]) cin >> x;
		sort(rall(a[i]));
	}

	vector<ll>ans;

	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			for (int k = 0; k < z; k++) {
				if ((i + 1) * (j + 1) * (k + 1) <= need) ans.emplace_back(a[0][i] + a[1][j] + a[2][k]);
				else break;
			}
		}
	}
	sort(rall(ans));
	for (int i = 0; i < need; i++) cout << ans[i] << '\n';
 	return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
long long  h,w,dp[1005][1005];
char arr[1005][1005];
long long  f(long long  r, long long  c){
	if(r>h||c>w)return 0;
	if(arr[r][c]=='#')return dp[r][c]=0;
	if(dp[r][c]!=-1)return dp[r][c];
	if(r==h&&c==w)return dp[r][c]=1;
	return dp[r][c]=(f(r+1,c)+f(r,c+1))%1000000007;
}
int main(){
	cin>>h>>w;
	memset(dp,-1,sizeof(dp));
	for(long long  i =1;i<=h;i++){
		for(long long  j =1;j<=w;j++){
			cin>>arr[i][j];
		}
	}
	cout<<f(1,1)<<endl;
	// for(long long  i =1;i<=h;i++){
	// 	for(long long  j =1;j<=w;j++){
	// 		cout<<dp[i][j]<<' ';
	// 	}
	// 	cout<<endl;
	// }
}

Measured memory_bytes: 9216
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main (int argc,char **argv)
{
	int x = 0,a = 0,b = 0;
	int i = 0, k = 0,l = 0;

	scanf("%d\n %d\n %d",&x,&a,&b);

	if(((1 <= a)&&(b <= 1000)) && ((a + b <= x)&&(x <= 10000)))
	{
		i = x - a;
		k = i / b;
		l = i - k * b;

		printf("%d\n",l);
	}

}

Measured memory_bytes: 128
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	a := []int{}
	for i := 0; i < n; i++ {
		a = append(a, stdin.ReadInt())
	}

	d := map[int]bool{}
	for i, v := range a {
		d[v] = i%2 == 0
	}

	ans := 0
	sort.Sort(sort.IntSlice(a))
	for i, v := range a {
		if (d[v] && i%2 != 0) || (!d[v] && i%2 == 0) {
			ans++
		}
	}

	stdout.Println(ans / 2)
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


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

using namespace std;

    const int n = 1e5+5;
    int num;
    int act[n][3];
    int dyn[3][n];
    
    int init(int a, int i){
        
    	if(i == num) return 0;
    	
    	if(dyn[a][i] != -1) return dyn[a][i];
    	int& res = dyn[a][i];
    	
    	if(a==0){
    	    
    		res=max(res, init(1, i+1)+act[i][0]);
    		res=max(res, init(2, i+1)+act[i][0]);
    	}
    	
    	if(a==1){
    	    
    		res=max(res, init(0, i+1)+act[i][1]);
    		res=max(res, init(2, i+1)+act[i][1]);
    	}
    	
    	if(a==2){
    	    
    		res=max(res, init(0, i+1)+act[i][2]);
    		res=max(res, init(1, i+1)+act[i][2]);
    	}
    	
    	
    	return res;
    }
    
    int main(){
        
    	cin>>num;
    	for(int i=0; i<num; i++) cin>>act[i][0]>>act[i][1]>>act[i][2];
    	memset(dyn, -1, sizeof dyn);
    	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";
    	return 0;
    	
    }

Measured memory_bytes: 7296
// ABC077A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	string a, b;
	cin >> a >> b;

	if ((a[0] == b[2])&&(a[1] == b[1])&&(b[0] == a[2])) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.ans = n*(n-1)//2

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
    
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        sx = self.size(x)
        sy = self.size(y)
        self.ans += sx*(sx-1)//2 + sy*(sy-1)//2
        self.ans -= (sx+sy)*(sx+sy-1)//2

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def cnt(self):
        return sum([uf.size(i)*(uf.size(i)-1)//2 for i in self.roots()])

######
N,M = map(int,input().split())
ansal = int(N*(N-1)/2)
uf = UnionFind(N)
ans = [uf.ans]
pp = [list(map(int,input().split())) for i in range(M)]
for i in range(M,1,-1):
  uf.union(pp[i-1][0]-1, pp[i-1][1]-1)
  ans.append(uf.ans)
for i in range(M-1,-1,-1):
  print(ans[i])

Measured memory_bytes: 34636
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int n;
cin>>n;

int v[n];
int c[n];
for(int i=0;i<n;i++){
    cin>>v[i];
}
for(int i=0;i<n;i++){
    cin>>c[i];
}
int ans=0;
for(int i=0;i<n;i++){
    if(v[i]-c[i]>0){
        ans+=v[i]-c[i];
    }
}
cout<<ans<<endl;


return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
fn main() {
    input!{
        s: chars,
    };
    let mut c = HashMap::new();
    for v in s{
        *c.entry(v).or_insert(0) += 1;
    }
    println!("{}", c.get(&'1').unwrap_or(&0));
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val (n, p) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.reversed()

    val ans = if (10 % p == 0) {
        (0 until n)
                .filter { (s[it] - '0') % p == 0 }
                .map { 0L + n - it }
                .sum()
    } else {
        val cnt = IntArray(p)
        var x = 0
        var b = 1
        var ans = 0L
        for (i in 0 until n) {
            cnt[x]++
            x += (s[i] - '0') * b
            x %= p
            ans += cnt[x]
            b = b * 10 % p
        }
        ans

    }

    println(ans)
}


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

int main(void) {
	int N;
	int a, max_a, min_a;

	max_a = -1;
	min_a = 10000;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		if (a > max_a)
			max_a = a;
		if (a < min_a)
			min_a = a;
	}
	int ans = max_a - min_a;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

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

void dfs(int s, int n, vector<vector<int>> &g, vector<bool> flg, int cnt, int &ans) {
    //cout << cnt << endl;
    if (cnt==n) {
        ++ans;
        return;
    }
    flg[s] = true;
    for (auto v: g[s]) {
        if (flg[v]) continue;
        dfs(v, n, g, flg, cnt+1, ans);
    }
    return;
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    vector<bool> flg(n, false);
    dfs(0, n, g, flg, 1, ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
members = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    members[b-1][f-1][r-1] += v

for b in range(4):
    if b > 0:
        print("####################")
    for f in range(3):
        print(" " + " ".join(map(str, members[b][f])))


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
};

istream& operator >> (istream& is, Point& p) {
  return is >> p.x >> p.y;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  Point a1, a2, b1, b2;
  while (cin >> a1 >> a2 >> b1 >> b2) {
    cout << (b2.x < a1.x || a2.x < b1.x || b2.y < a1.y || a2.y < b1.y ? "NO" : "YES") << endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> g[200005];
bool vis[200005];
int n,k;
int mod = 1e9 + 7;
int DFS(int node,int parent){
    if(vis[node])   return 1;
    vis[node] = 1;
    int ks = k - 2;
    int ans = 1,unvisC = 0;
    if(parent == -1){
        ks = k-1;
    }
    if(k <=0)   return 0;
    for(auto j:g[node]){
        if(j != parent){
            unvisC++;
        }
    }
    for(int p = 0; p < unvisC; p++){
        ans*=ks--;
        ans%=mod;
    }

    for(auto j:g[node]){
            if(node == parent)  continue;
        ans*=DFS(j,node);
        ans%=mod;
    }

    return ans;
}
 main()
{

    cin>>n>>k;
    for(int i =0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int res = k * DFS(1,-1);
    res%=mod;
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 11648
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	m := make(map[int]int)
	N, M := ReadInt(), ReadInt()
	for i := 0; i < N; i++ {
		m[ReadInt()]++
	}
	for i := 0; i < M; i++ {
		B, C := ReadInt(), ReadInt()
		m[C] += B
	}
	ints := make([]int, len(m))
	for i, _ := range m {
		ints = append(ints, i)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ints)))
	rest := N
	sum := 0
	for _, i := range ints {
		num := m[i]
		if num >= rest {
			sum += rest * i
			break
		}
		sum += num * i
		rest -= num
	}
	fmt.Println(sum)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 24496
#include<bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int  i = a; i < b; ++i)
#define fr2(i, b, a) for (int i = b; i >= a; --i)
#define set0(a) memset(a, 0, sizeof(a))
#define setneg(a) memset(a, -1, sizeof(a))
#define mod 1000000007
#define ll long long




int main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
               int s,w;
               cin>>s>>w;
               if(w>=s)
                cout<<"unsafe"<<endl;
        else
                cout<<"safe"<<endl;
        
        return 0;
}





Measured memory_bytes: 3624
from collections import Counter

n = int(input())
x = []
for i in range(n):
    x.append(input())

c = Counter(x)
y = c.most_common()
c_m = (c.most_common(1))[0][1]
z = []
for j in range(len(y)):
    if y[j][1] == c_m:
        z.append(y[j][0])
z.sort()
for result in z:
    print(result)

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

int selectionSort(int A[], int N)
{
  int sw = 0;

  for (int i = 0; i < N; i++)
  {
    int minj = i;
    for (int j = i + 1; j < N; j++)
    {
      if (A[minj] > A[j])
        minj = j;
    }
    if (i != minj)
    {
      swap(A[i], A[minj]);
      sw++;
    }
  }

  return sw;
}

int main(void)
{
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = selectionSort(A, N);

  for (int i = 0; i < N; i++)
  {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
const int mod = 998244353;
int n;
ll lea[N], sum[N], a[N], ans = 1;
int main() {
	scanf("%d", &n);
	for (int i = 0; i <= n; i++)scanf("%lld", &lea[i]);
	if (lea[0] > 1) { puts("-1"); return 0; }
	for (int i = n; i >= 0; i--)sum[i] = sum[i + 1] + lea[i];
	a[0] = 1;
	for (int i = 1; i <= n; i++) {
		if (lea[i] > 2 * (a[i - 1] - lea[i - 1])) { puts("-1"); return 0; }
		a[i] = min(2 * (a[i - 1] - lea[i - 1]), sum[i]);
		ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6164
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <chrono>

using namespace std;

int main() {
	long long N, A, B;

	cin >> N >> A >> B;

	if( abs(A-B) % 2 == 0 ){
		cout << (abs(A-B)+1)/2 << endl;
		return 0;
	}

	long long a, b;
	a = min(A, B);
	b = max(A, B);

	if( a + b <= N ){
		cout << a + (b-a)/2 << endl;
	}
	else{
		cout << min(a-1, N-b) + 1 + (b-a-1)/2 << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	ll N,K;
	cin >> N >> K;
	ll H[N];
	ll i;
	for(i=0;i<N;i++){
		cin >> H[i];
	}
	sort(H,H+N);
	ll ans=0;
	for(i=0;i<N-K;i++){
		ans+=H[i];
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int M = GetInt();
		string s = GetString();

		var adj = Enumerable.Range(0, N).Select(_ => new List<int>()).ToArray();
		for(int i = 0; i < M; i++)
		{
			int a = GetInt() - 1;
			int b = GetInt() - 1;
			adj[a].Add(b);
			adj[b].Add(a);
		}

		int[] degA = new int[N];
		int[] degB = new int[N];
		for(int v = 0; v < N; v++)
		{
			int[] deg = (s[v] == 'A') ? degA : degB;
			foreach(int u in adj[v])
				deg[u]++;				
		}

		var queue = new Queue<int>();
		for(int v = 0; v < N; v++)
		{
			if(degA[v] == 0 || degB[v] == 0)
				queue.Enqueue(v);
		}

		bool[] deleted = new bool[N];
		while(queue.Count > 0)
		{
			int v = queue.Dequeue();
			deleted[v] = true;

			int[] deg = (s[v] == 'A') ? degA : degB;
			foreach(int u in adj[v])
			{
				if(deleted[u])
					continue;
				
				deg[u]--;
				if(deg[u] == 0)
					queue.Enqueue(u);
			}
		}

		Console.WriteLine((deleted.Count(x => x) < N) ? "Yes" : "No");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 36748
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int M = 110;
const int INF = 1e9 + 7;
int dp[N][M],v[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for(int i=0;i<N;++i)
		for(int j=0;j<M;++j)
			dp[i][j] = INF;

	int n,k;
	cin>>n>>k;

	for(int i=1;i<=n;++i) cin>>v[i];

	dp[1][0] = 0;

	for(int i=1;i<=n;++i)
		for(int j=1;j<=k;++j)
		{
			dp[i][j] = min(dp[i][j],dp[i][j-1]);
			int id = i - j;
			if(id < 0) continue;

			int x = abs(v[id] - v[i]);
			dp[i][j] = min(dp[i][j],dp[id][k] + x);
		}

	cout<<dp[n][k]<<"\n";
}

Measured memory_bytes: 43648
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e6+10;
const int N = 1e5+10;
const int E = 2e5+10;  
int n,k;

int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	int t=1;
	while(a>0&&c>0){
		if(t%2==1){
			c-=b;
			t++;
		}
		else{
			a-=d;
			t++;
		}
	}
	if(a<=0){
		printf("No\n");
	} 
	else printf("Yes\n");
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main()
{
	int t;
	int s[100];
	char l[100][102];
	int N,L;
	int i,j;
	scanf("%d %d",&N,&L);
	for(i=0;i<N;i++){
		scanf("%s",l[i]);
		s[i]=i;
	}
	for(i=1;i<N;i++){
		j=i;
		while(j>0){
			if(strcmp(l[s[j-1]],l[s[j]])>0){
				t=s[j-1];
				s[j-1]=s[j];
				s[j]=t;
			}
			else{
				break;
			}
			j--;
		}
	}
	for(i=0;i<N;i++){
		printf("%s",l[s[i]]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val B = A.map { Math.abs(it) }
    val sum = B.sumByDouble { it.toDouble() }.toLong()
    val min = B.min()!!
    val fu = A.count { it < 0 }
    val ans = if (fu % 2 == 1) sum - min * 2 else sum
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 59884
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 10001;

int gcd(int a, int b)
{
	while(b)
	{
		a %= b;
		swap(a, b);
	}
	return a;
}

int s[N], a[N], t[N];

bool check(int p, int n)
{
	memset(t, 0, sizeof t);
	for(int i=n; i>=p; i--)
	{
		int x = (a[i] + t[i]) % p;
		t[i - p + 1] += x;
		t[i - p + 1] %= p;
	}
	for(int i=p-1; i>=0; i--)
		if((a[i] + t[i]) % p)
			return false;
	return true;
}

int main()
{
	fio;
	int n, g = 0;
	cin >> n;
	for(int i=n; i>=0; i--)
	{
		cin >> a[i];
		g = gcd(abs(a[i]), g);
	}
	set<int> ans;
	for(int i=2; i*i<=g; i++)
	{
		if(g % i == 0)
		{
			ans.insert(i);
			while(g % i == 0)
				g /= i;
		}
	}
	if(g > 1)
		ans.insert(g);
	for(int i=2; i<=n; i++)
	{
		if(s[i] == 0)
		{
			if(check(i, n))
				ans.insert(i);
			for(int j=i+i; j<=n; j+=i)
				s[j] = 1;
		}
	}
	for(int it : ans)
		cout << it << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int mod = 1000000007;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if (a + b == c || a + c == b || b + c == a) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
x = int(input())
l = []

for i in range(1,32):
    for j in range(2,9):
        l.append(i ** j)
        
l = list(sorted(set(l)))
c = 1        
for i in range(len(l)):
    if l[i] <= x and x< l[i+1]:
        c = l[i]
        break
print(c)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
        int a, b;
        int R, S;
        
        cin >> a >> b;
        
        S = a * b;
        R = 2 * (a + b);
        
        cout << S << " " << R << endl;
        
        return 0;
}

Measured memory_bytes: 1164
use proconio::input;

fn main()
{
    input! {
    (a,b,c,d,e,k):(i32,i32,i32,i32,i32,i32),
    }

    let ans = if e - a <= k {
        "Yay!"
    } else {
        ":("
    };
    println!("{}", ans);
}

Measured memory_bytes: 2136
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)
ans = 0
for l in range(N + 1):
    for r in range(N + 1):
        if re.match(r'^[AGCT]*$', S[l:r]):
            ans = max(ans, r - l)
print(ans)


Measured memory_bytes: 13368
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;


int main(){
  int a,b;
  cin>>a>>b;
  if(a+b<10){
    cout<<a+b<<endl;
  }else{
    cout<<"error"<<endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define sort(v) sort(v.begin(), v.end())

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){ return (a+ b-1)/b; }
void flaged(bool flag){
    if(flag) cout << "Yes\n";
    else cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf(){
    fact[0] = finv[0] = 1;
    for(ll i = 1; i < maxa; i++){fact[i] = (fact[i-1]*i) %MOD;finv[i] = (finv[i-1]*power(i))%MOD;}
}
// nCr
ll ncr(ll N, ll R){ if(R > N) return 0; return (fact[N]*((finv[R]*finv[N-R])%MOD))%MOD;}

void solve(){
    /*ll n, k;
    cin >> n >> k;
    ll a[n];
    ll z = 0, p = 0;
    vector<ll> neg, pos;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0) z++;
        else if(a[i] < 0) {
            neg.pb(a[i]);
        }
        else {
            p++; pos.pb(a[i]);
        }
    }n -= (z+p);
    ll total = n+p+z;
    ll ns = n*p, ps = (p*(p-1))/2 + (n*(n-1))/2;
    ll zs = ((total-1)*total)/2 - ns-ps; cout << zs << " " << ns << " " << ps << endl;
    if(k <= ns){

    }
    else if( k > ns && k <= ns + zs){cout << "0";}
    else{

    }*/

    ll n, d ,a;
    cin >> n >> d >> a;
    vector<pii> v;
    rep(i, 0, n)
    {
        ll x, y; cin >> x >> y; v.pb({x, y});
    }
    sort(v);
    ll c[n+1]; mem(c, 0);
    ll ans = 0;
    for(ll i = 0, j = 0; i < n; i++){
        while(j < n && v[j].ft - v[i].ft <= 2*d) j++;
        ll con = max(0ll, ceil(v[i].sd - c[i]*a, a)); //cout << con << " ";
        ans += con;  
        c[i] += con;
        c[j] -= con;
        c[i+1] += c[i];
    }
    cout << ans;

}

int main()
{
    fast();
    ll t = 1;//cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6384
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()

res = 10**1000

for _ in range(2):
    a,b = h // 3 + 1, h // 3 + 1
    c = h - a - b
    if c < 0:
        h,w = w,h
        continue
    mx = max(a,b,c)
    mn = min(a,b,c)
    res = min(res, mx*w-mn*w)
    h,w = w,h

for _ in range(2):
    a,b = h // 3, h // 3
    c = h - a - b
    mx = max(a,b,c)
    mn = min(a,b,c)
    res = min(res, mx*w-mn*w)
    h,w = w,h

for _ in range(2):
    for i in range(1,h):
        l = [i * w]
        j = h - i
        a = w // 2
        l.append(a * j)
        l.append((w - a) * j)
        res = min(res, max(l) - min(l))
    h,w = w,h

print(res)


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

char c[11][1001];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cin >> c[i][j];
    }
    int msk = (1 << n), ans = INF;
    for (int mask = 0; mask < msk; mask++) {
        int kol = 0;
        bool ok = true;
        for (int i = 0; i < n; i++) if ((mask >> i) & 1) kol++;
        vi tek(kol + 1, 0), lst(kol + 1, 0);
        for (int j = 0; j < m; j++) {
            int lol = 0;
            bool ok1 = false;
            for (int i = 0; i < n; i++) {
                if (c[i][j] == '1') tek[lol]++;
                if (((mask >> i) & 1) || i + 1 == n) {
                    if (tek[lol] > k) ok = false;
                    if (tek[lol] + lst[lol] > k) ok1 = true;
                    lol++;
                }
            }
            lol = 0;
            for (int i = 0; i < n; i++) {
                if (((mask >> i) & 1) || i + 1 == n) {
                    if (ok1) lst[lol] = tek[lol];
                    else lst[lol] += tek[lol];
                    tek[lol] = 0;
                    lol++;
                }
            }
            if (ok1) kol++;
            if (!ok) break;
        }
        if (ok) ans = min(ans, kol);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+7;

LL fr[MAXN];

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

    LL sum = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        fr[x]++;
        sum += x;
    }

    int q;
    cin >> q;

    while (q--) {
        int b, c;
        cin >> b >> c;

        sum -= fr[b]*b;
        sum += fr[b]*c;
        fr[c] += fr[b];
        fr[b] = 0;

        cout << sum << "\n";
    }

    return 0;
}


Measured memory_bytes: 4412
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		if(N.equals("a")) {
			System.out.println("vowel");
		}else if(N.equals("i")) {
			System.out.println("vowel");
		}else if(N.equals("u")) {
			System.out.println("vowel");
		}else if(N.equals("e")) {
			System.out.println("vowel");
		}else if(N.equals("o")) {
			System.out.println("vowel");
		}else {
			System.out.println("consonant");
		}

	}

}

Measured memory_bytes: 21844
package main

import "fmt"

func main() {
	// Code for B - Time Limit Exceeded
	var N, T int
	fmt.Scanf("%d %d", &N, &T)

	var c, t int
	var min int = 1000
	var flag int = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &c, &t)
		if t <= T {
			flag = 1
			if min >= c {
				min = c
			}
		}
	}

	if flag == 1 {
		fmt.Println(min)
	} else {
		fmt.Println("TLE")
	}
}


Measured memory_bytes: 1836
import queue
pq=queue.PriorityQueue()
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
pq.put((-(A[0]+B[0]+C[0]),(0,0,0)))
D=[[1,0,0],[0,1,0],[0,0,1]]

for _ in range(K):
    value,index=pq.get()
    x,y,z=index
    print(-value)
    for dx,dy,dz in D:
        if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
            pq.put((-(A[x+dx]+B[y+dy]+C[z+dz]),(x+dx,y+dy,z+dz)))
            searched.add((x+dx,y+dy,z+dz))

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int t,n,h[100],maxup[100]={},maxdown[100]={},flag=0;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n;
    for(int j=0;j<n;j++){
      cin>>h[j];
    }
    for(int j=0;j<n-1;j++){
      if(h[j]>h[j+1] && maxdown[i]<h[j]-h[j+1]) maxdown[i]=h[j]-h[j+1];
      if(h[j+1]>h[j] && maxup[i]<h[j+1]-h[j]) maxup[i]=h[j+1]-h[j];
    }
  }
  for(int i=0;i<t;i++){
    cout<<maxup[i]<<" "<<maxdown[i]<<endl;
  }  
  return 0;
}
   
 
      
 
  
   
  
	
	  
	  
	  
	  
	  
	  
     
  
  
  
  
  

  

 
  


 

    
  



Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> p(N,0);
  int s = 0,ma = 0;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (p[i] > ma) {
      ma = p[i];
    }
    s += p[i];
  }
  cout << s - ma/2;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

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


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

	int sum = 0;
	REP(i, 4) {
		int a; cin >> a;
		sum += a;
	}
	cout << sum / 60 << endl << sum % 60 << endl;

    return 0;
}




Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(void){
    int n; cin>>n;
    vector <int> a(n);
    vector <int> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    int tmp = 0;
    vector <int> excess(n);
    int ans = 0;
    for(int i=0;i<n;i++){
        if(a[i]<b[i]) { tmp+=b[i]-a[i]; a[i]=b[i]; ans++;}
        excess[i]=a[i]-b[i];
    }
    sort(excess.begin(),excess.end());
    reverse(excess.begin(),excess.end());
    
    for(int i=0;i<n;i++){
        if(tmp<=0) break;
        if(excess[i]>0){
        tmp -= excess[i];
        ans++;}
    }
    if(tmp>0) {cout<<-1<<endl; return 0;}
    cout<<ans<<endl;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;



int main() {
	
	int n;
	cin >> n;
	VI v(n);
	REP(i, n)cin >> v[i];

	VI ans;

	REP(i, n) {
		if (i + 1 < v[i]) {
			cout << -1 << endl;
			return 0;
		}
	}

	REP(i, n) {
		int a = -1;
		REP(j, v.size()) {
			if (j + 1 == v[j])a = j;
		}
		v.erase(a + v.begin());
		ans.push_back(a);
	}

	reverse(ALL(ans));

	REP(i, n)cout << ans[i]+1 << ' ';



}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  int L,R;
  L = a+b;
  R = c+d;
  if(L>R){
    printf("Left");
  }else if(L==R){
    printf("Balanced");
  }else{
    printf("Right");
  }
  return 0;
}

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

int main()
{
  double N, T, A;
  double t[1001];
  double res=INF;
  cin >> N >> T >> A;

  rep(i,N) {
    double h;
    cin >> h;
    t[i]= abs(A - (T - h*0.006));
  }

  int index = 0;
  rep(i,N){
    if(res > t[i]) {
      res = t[i];
      index = i+1;
    }
  }

  cout << index << endl;
}

Measured memory_bytes: 256
n = int(input())
balls = list(map(int, input().split()))
 
list_a = [0 for i in range(n)]
 
# 同じ数の個数を導出
for e in balls:
    list_a[e-1] += 1
# 同じ数の組合せを導出    
list_b = list(map(lambda x: x *(x-1) // 2, list_a))
# N個すべての組合せ
c = sum(list_b)

for e in balls:
  print(c - list_a[e-1] + 1)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    int n = N % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
        cout << "hon" << endl;
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3596
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)5e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], dp[N], mx[N], mx2[N];

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 0; i < (1 << n); i ++) cin >> a[i], mx[i] = a[i], mx2[i] = -mod;
   dp[1] = a[0] + a[1];
   mx[0] = a[0];
   mx2[0] = -mod;
   for (int i = 0; i < n; i ++) {
      for (int mask = 0; mask < (1 << n); mask ++) {
         if (!(mask & (1 << i))) {
            int new_mask = (mask | (1 << i));
            if (mx[new_mask] <= mx[mask]) {
               mx2[new_mask] = max (mx2[mask], mx[new_mask]);
               mx[new_mask] = mx[mask];
            }
            else if (mx2[new_mask] <= mx[mask]) mx2[new_mask] = mx[mask];
         }
      }
   }
   for (int mask = 2; mask < (1 << n); mask ++) {
      dp[mask] = max (dp[mask - 1], mx[mask] + mx2[mask]);
      mx[mask] = -mod;
   }
   for (int i = 1; i < (1 << n); i ++) cout << dp[i] << endl;
}               
 
signed main () {                                       
   //#ifdef QWERTY
  //    freopen("input", "r", stdin);
  // #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 9088
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 102
#define MAX 100005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;
vector < int > v[MAX] , pre[MAX] , suff[MAX];
int up[MAX] , down[MAX];
int mod;
void dfs(int x , int p){
	down[x] = 1 ;
	vec t;
	pre[x].pb(1);
	pre[x].pb(1);
	suff[x].pb(1);
    suff[x].pb(1);
  for(int i = 0 ; i < v[x].size() ; i++){
  	int y = v[x][i];
  	if(y == p){
  		t.pb(1);
  		continue;
  	}
  	dfs(y , x);
  	down[x] *= (down[y] + 1);
  	down[x] %= mod;
  	t.pb(down[y] + 1);
    
  }
  if(v[x].size() == 0)
  	down[x] = 1;
  down[x] %= mod;
   // cout << x << " "<< down[x] << endl;
  for(int i = 1 ; i <= t.size() ; i++ ){	
  	pre[x][i] = (pre[x][i-1] * t[i-1] ) % mod;
   
  }
  for(int i = t.size() ; i > 0 ; i-- ){
  	suff[x][i] = (suff[x][i+1] * t[i-1] ) % mod;
  }  
}


void dfs2(int x , int p){
	for(int i = 0 ; i <  v[x].size() ; i++){
		int y = v[x][i];
		if(y == p) continue;
		up[y] = (pre[x][i] * suff[x][i+2]) % mod ;
		up[y] %= mod;
		up[y]*= (up[x] + 1);
		up[y] %= mod;
		// cout << y << " "<< up[y] << endl;
		dfs2(y , x);
	}
}


signed main(){
  fast;
 int n , x , y;
  cin >> n >> mod;
  for(int i = 1 ; i < n ; i++){
  	cin >> x >> y;
  	v[x].pb(y);
  	v[y].pb(x);
  	pre[x].pb(1);
  	pre[y].pb(1);
  	suff[x].pb(1);
  	suff[y].pb(1);
  }



  dfs(1 , 0);
  up[1] = 0;
  dfs2(1 , 0);

  for(int i = 1 ; i <= n ; i++)
  	cout << ((up[i] + 1) * down[i] ) % mod << endl;
  


}	

Measured memory_bytes: 34048