akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        if(a > b) {
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
        if(a > b) {
            ans += a;
        } else {
            ans += b;
        }
        System.out.println(ans);
    }
}




Measured memory_bytes: 25172
import itertools

N = int(raw_input())
P = tuple(raw_input().split())
Q = tuple(raw_input().split())

N_list = []
for i in range(N):
    N_list.append(str(i+1))


perm = itertools.permutations(N_list)
index = 1

for item in perm:
    if P == item:
        index_p = index
    if Q == item:
        index_q = index
    index = index + 1

ans = index_p - index_q
if index_p - index_q < 0:
    ans = (-1)*ans

print ans



Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int ans = 0;
    string s, t;
    cin >> s >> t;
    rep(i,3){
        if(s[i]==t[i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long int a, b;
	cin >> a >> b;
	if((a+b)%2 == 1)
	    cout << "IMPOSSIBLE\n";
	else
	    cout << (a+b)/2 << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

using Graph=mat;
Graph G;

//入次数
vec in;
//頂点数
int V;

vec Topological_Sort(){
    vec v;

    //入次数0の頂点集合
    stack<int> st;

    for(int i=1;i<=V;i++)
        if(in[i]==0)st.push(i);
    
    while(st.size()){
        int i=st.top();st.pop();
        v.push_back(i);
        for(auto k:G[i]){
            in[k]--;
            if(in[k]==0)st.push(k);
        }
    }
    return v;
}

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

    int B[1010];
    B[N-1]=0;
    for(int i=1;i<=N-2;i++)
        B[N-i-1]=B[N-i]+i;
    
    int A[1010],X[1010],m,M;
    G.resize(500000);
    in.resize(500000);
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N-1;j++){
            cin>>A[j];
            m=min(i,A[j]);
            M=max(i,A[j]);
            X[j]=B[m]+M-m;
        }
        for(int j=1;j<=N-2;j++){
            G[X[j]].push_back(X[j+1]);
            in[X[j+1]]++;
        }
    }

    V=N*(N-1)/2;
    vec v=Topological_Sort();
    if(v.size()!=V){
        cout<<-1<<endl;
        return 0;
    }
    else{
        map<int,int> mp;
        for(int i=0;i<V;i++)
            mp[v[i]]=i;
        vec dp(500000);
        int ans=0;
        for(int i=1;i<=V;i++){
            dp[i]=1;
            for(auto x:G[v[V-i]])
                dp[i]=max(dp[i],dp[V-mp[x]]+1);  
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
        return 0;  
    }
    return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)


char o[5] = {'.' , ',' , '!' , '?' , ' '};
char a[3] = {'a' , 'b' , 'c'};
char d[3] = {'d' , 'e' , 'f'};
char g[3] = {'g' , 'h' , 'i'};
char j[3] = {'j' , 'k' , 'l'};
char m[3] = {'m' , 'n' , 'o'};
char p[4] = {'p' , 'q' , 'r' , 's'};
char t[3] = {'t' , 'u' , 'v'};
char w[4] = {'w' , 'x' , 'y' , 'z'};

void display(int num,int cnt){
	switch(num){
		case 1: cout<<o[cnt%5]; break;
		case 2: cout<<a[cnt%3]; break;
		case 3: cout<<d[cnt%3]; break;
		case 4: cout<<g[cnt%3]; break;
		case 5: cout<<j[cnt%3]; break;
		case 6: cout<<m[cnt%3]; break;
		case 7: cout<<p[cnt%4]; break;
		case 8: cout<<t[cnt%3]; break;
		case 9: cout<<w[cnt%4]; break;
	}
}
	
int main(void){
	int num;
	cin>>num;
	while(num--){
		string n;
		cin>>n;
		int cnt = 0;
		int num = - 1;
		rep(i,n.size()){
			if(n[i]=='0'){
//				cout<<cnt;
				display(num,cnt);
				cnt = 0;
			}
			if(n[i]-'0'==num && n[i]!='0')cnt++;
			
			num=n[i]-'0';
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;

//マクロ
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<long long, long long> 
#define vin(v,N) for(int i=0;i<N;i++) cin>>v.at(i)
#define pb push_back

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(ll x,ll N){
  ll ret=1;
  for(int i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//素因数分解(mapで返す)
map<ll,ll> factor(ll p){
  ll p1=p;
  map<ll,ll>ret;
  for(ll i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  ll N,W;cin>>N>>W;
  vector<P>item(N);
  rep(i,N) cin>>item[i].first>>item[i].second;
  //rep(i,N) cout<<item[i].first<<" "<<item[i].second<<endl;
  //cout<<endl;
  
  ll dp[110][100100];
  for(ll i=0;i<N;i++){
    for(ll w=0;w<=W;w++){
      //買わない
      chmax(dp[i+1][w],dp[i][w]);
      //買う
      if(w-item[i].first>=0){
        chmax(dp[i+1][w],dp[i][w-item[i].first]+item[i].second);
        //cout<<"☆";
      }
      //cout<<dp[i][w]<<"  ";
    }
    //cout<<endl;
  }
  cout<<dp[N][W];
}

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

int main()
{
  int n,k,t;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++){
    cin >> t;
    h[i] = t;
  }
  sort(h.begin(),h.end(),greater<int>());

  if(n <= k){
    cout << 0;
    return 0;
  }

  long long ans=0;
  for(int i=k; i<n; i++){
    ans += h[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1024
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;



int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    pair<ll,ll>pi[tc];
    for(cs=0;cs<tc;cs++)
    {
        cin>>a>>b;
        pi[cs]={a,b};
    }
    for(i=0;i<=tc-3;i++)
    {
           if(pi[i].fi==pi[i].si&&pi[i+1].fi==pi[i+1].si&&pi[i+2].fi==pi[i+2].si)
           {

           cout<<"Yes\n";
           return 0;
           }

    }
    cout<<"No\n";



    //code
    return 0;
}




Measured memory_bytes: 50524
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
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;}
const string YES = "Yes";
const string NO = "No";

void solve(){
    ll h,n;cin>>h>>n;
    vec a(n);rep(i,n)cin>>a[i];

    ll sum=0;
    rep(i,n){
        sum+=a[i];
    }
    if(sum>=h){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n;

int main() {
    cin >> n;
    vector<ll> A(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> A.at(i);
    }

    vector<bool> Ach(1000100, true);
    sort(A.begin(), A.end());
    A.push_back(1000100);
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ll ch = A.at(i);
        bool flg = true;
        if(i == 0) {
            if(ch == A.at(i+1)) flg = false;
        }else {
            if(ch == A.at(i+1) || ch == A.at(i-1)) flg = false;
        }
        if(Ach.at(ch)) {
            if(flg) ans++;
            ll now = ch;
            while(now <= 1000000) {
                // cout << now << endl;
                Ach.at(now) = false;
                now += ch;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n),y(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    for(int j=0;j<a[i];j++){
      int b,c;cin >> b >> c;
      b--;
      x[i].push_back(b);
      y[i].push_back(c);
    }
  }
  int ans=0;
  for(int i=0;i<(1<<n);i++){
    vector<bool> f(n,false);
    int cnt=0;
    for(int j=0;j<n;j++){
      if((i>>j)&1){
        f[j]=true;
        cnt++;
      }
    }
    bool t=true;
    for(int j=0;j<n;j++){
      if(!f[j]){
        continue;
      }
      for(int k=0;k<a[j];k++){
        if(f[x[j][k]]^y[j][k]){
          t=false;
        }
      }
    }
    if(t){
      ans=max(ans,cnt);
    }
  }
  cout << ans << endl;
}

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

int main(){

	int n,a,prev;
	cin >> n;
	cin >> prev;
	int count = 1;
	bool increasing = false, decreasing =false;
	for(int i = 1;i<n;i++){
		cin >> a;
		if(a>=prev && increasing) {prev=a;}
		else if(a<=prev && decreasing) { prev=a;}
		else if(a<prev && increasing) {count++; prev=a; increasing=false; continue;}
		else if(a>prev && decreasing) {count++; prev=a; decreasing = false; continue;}
		else if(a>prev) {increasing = true; prev=a;}
		else if (a<prev) {decreasing = true; prev=a;}
	}
	cout << count;
			
		
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

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

    }


}

Measured memory_bytes: 125696
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

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

    vector<int> idx_c;
    vector<int> idx_f;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'C') {
            idx_c.push_back(i);
        } else if (s[i] == 'F') {
            idx_f.push_back(i);
        }
    }

    for (int i = 0; i < idx_c.size(); i++) {
        for (int j = 0; j < idx_f.size(); j++) {
            if (idx_c[i] < idx_f[j]) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

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

int main(){
    int n, a;
    cin >> n >> a;
    int ans = n;
    for(int i = 0; i < a; i++){
        if(ans % 500 == 0){
            cout << "Yes" << endl;
            return 0;
        } else {
            ans--;
        }
    }
    if(n % 500 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

struct edge {
    ll cost, to;
    edge(ll c, ll t) : cost(c), to(t) {}
};

int main() {
    int N;
    cin >> N;
    vector<vector<edge>> G(N, vector<edge>());
    rep(i, N - 1) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        G[u].pb(edge(w, v));
        G[v].pb(edge(w, u));
    }
    vector<ll> dist(N, LINF);
    queue<pll> que;
    que.push(MP(0, 0));
    dist[0] = 0;
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        int v = p.first;
        ll d = p.second;
        for(auto e : G[v]) {
            if(dist[e.to] == LINF) {
                dist[e.to] = d + e.cost;
                que.push(MP(e.to, d + e.cost));
            }
        }
    }
    rep(i, N) { cout << dist[i] % 2 << endl; }

    return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> cnt(N, 0);
    int d, a;
    rep(i, 0, K) {
        cin >> d;
        rep(j, 0, d) {
            cin >> a;
            --a;
            ++cnt[a];
        }
    }
    int ans = 0;
    rep(i, 0, N) {
        if (!cnt[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	int inext=0;
	for(int i=111;i<=999;i++){
		if(i/100<=n&&i/100!=0&&i%100/10<=n&&i%100/10!=0&&i%10<=n&&i%10!=0){
//			printf("%d\n",i);
			inext++;
		}
	}
	printf("%d",inext);
	return 0;
} 

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	one, two, three := 0, 0, 0
	for i := 0; i < N; i++ {
		a := sc.nextInt()
		if a == 1 {
			one++
		} else if a == 2 {
			two++
		} else {
			three++
		}
	}
	var dp [310][310][310]float64
	for i := 0; i < 310; i++ {
		for j := 0; j < 310; j++ {
			for k := 0; k < 310; k++ {
				dp[i][j][k] = -1.0
			}
		}
	}
	var rec func(i, j, k int) float64
	rec = func(i, j, k int) float64 {
		if dp[i][j][k] >= 0 {
			return dp[i][j][k]
		} else if i == 0 && j == 0 && k == 0 {
			return 0.0
		}
		res := 0.0
		if i > 0 {
			res += rec(i-1, j, k) * float64(i)
		}
		if j > 0 {
			res += rec(i+1, j-1, k) * float64(j)
		}
		if k > 0 {
			res += rec(i, j+1, k-1) * float64(k)
		}
		res += float64(N)
		res *= 1.0 / float64(i+j+k)
		dp[i][j][k] = res
		return res
	}

	fmt.Fprintln(wtr, rec(one, two, three))
	wtr.Flush()
}


Measured memory_bytes: 241152
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

long long n, x;
int a[5000];
int minima[4000][4000];
long long ans = 1e18;

int main()
{
    cin >> n >> x;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n; i < 2 * n; i++) a[i] = a[i - n];
    for (int i = 0; i < 2 * n; i++)
    {
        int r = a[i];
        for (int j = i; j < 2 * n; j++)
        {
            r = min(r, a[j]);
            minima[i][j] = r;
        }
    }
    for (int c = 0; c < n; c++)
    {
        long long res = c * x;
        for (int j = n; j < 2 * n; j++)
        {
            res += minima[j - c][j];
        }
        ans = min(res, ans);
    }
    cout << ans;
}


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

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

    int ans = 0;
    char c = '@';
    for(int i = 0; i < n; ++i)
    {
        if(c == str[i])
        {
            continue;
        }
        ++ans;
        c = str[i];
    }
    cout << ans << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vll G[10005];
vll c;
vll res;
ll pos=0;
void dfs(ll v, ll p){
  for(auto nv: G[v]){
    if(nv==p) continue;
    res[nv]=c[pos++];
    dfs(nv,v);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  c.resize(n); res.resize(n);
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,n) cin>>c[i];
  sort(c.rbegin(),c.rend());
  ll sum=0;
  irep(i,1,n) sum+=c[i];
  
  res[0]=c[pos++];
  dfs(0,-1);
  
  cout<<sum<<endl;
  rep(i,n){
    cout<<res[i]<<endl;
  }
  
}


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

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int N, a, b, c;
	cin >> N;
	
	for(int i=0;i<N;i++){
		cin >> a >> b >> c;
		if(a*a+b*b==c*c || a*a==b*b+c*c || a*a+c*c==b*b){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
def main():
    A, B = map(int, input().split())

    white = [['.' for _ in [0] * 100] for _ in [0] * 50]
    black = [['#' for _ in [0] * 100] for _ in [0] * 50]
    paint(black, A)
    paint(white, B)

    print(100, 100)
    for wb in (white, black):
        for c in wb:
            print(*c, sep='')

def paint(color, n):
    if n == 1:
        return
    if color[0][0] == '.':
        char = '#'
    else:
        char = '.'
    for i in range(1, 50, 2):
        for j in range(1, 100, 2):
            color[i][j] = char
            n -= 1
            if n == 1:
                return

main()


Measured memory_bytes: 4468
import time
import math
a,b,x = map(int,input().split())
x /= a
c = a*b/2
if x<c:
    l,r = 0,90
    for i in range(1000):
        mid = (l+r)/2
        S = b*b*math.tan(math.radians(mid))/2
        if S<=x: l = mid
        else: r = mid
    print(90-mid)
elif x==c:
    print(math.degrees(math.atan(a/b)))
else:
    l,r = 0,90
    for i in range(1000):
        mid = (l+r)/2
        S = a*b-a*a/math.tan(math.radians(mid))/2
        if S<=x: l = mid
        else: r = mid
    print(90-mid)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main(void){
    string s;
    cin>>s;
    int n= s.size();
    vector <vector<int>> dp(100010 ,vector <int>(2 ));
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        //a+b=0
        if(s[i]=='0'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
        }else{
            dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
        }
        //a+b=1
        if(s[i]=='0'){
            //dp[i+1][1] += dp[i][1]*2;
             (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
        }else{
            //dp[i+1][0]+= dp[i][0]*2;
            //dp[i+1][1] += dp[i][1]*2;
            (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
            (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
        }
       
    }
    int ans = (dp[n][0]+dp[n][1]) % mod;
    cout << ans << endl;
}


Measured memory_bytes: 5760
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)...}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__) << '\n'
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;

	while(true) {
		c -= b;
		if (c <= 0) return true;
		a -= d;
		if (a <= 0) return false;
	}	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	cout << (Main() ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3652
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int n,i,j,k=0;cin>>n;
for(i=0;i<n;i++)
{
	cin>>j;k+=j-1;
}
cout<<k;


return 0;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]
n = I()
a = LI()
ans = 0
for i in range(n):
    if i % 2 == 0 and a[i]%2 == 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 27224
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ll a[305][305],d[305][305],ans=0;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,1,n)rep(j,1,n)cin>>a[i][j],d[i][j]=a[i][j],ans+=a[i][j];

rep(k,1,n)rep(i,1,n)rep(j,1,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

rep(i,1,n)rep(j,1,n)if(a[i][j]!=d[i][j])
{
	ol("-1");
	return 0;
}

rep(i,1,n)
{
	rep(j,1,n)
	{
		int f=0;
		rep(k,1,n)
		{
			if(i==k||j==k)continue;
			if(d[i][k]+d[k][j]==d[i][j])f=1;
		}
		if(f)ans-=d[i][j];
	}
}
ol(ans/2);
return 0;
}



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

int main(void)
{
   int n,tmp,i,c=0;

   scanf("%d",&n);


   for(i=0;i<n;i++){
      scanf("%d",&tmp);
      c+=tmp;
   }

   printf("%d\n",c-n);
   return 0;
}


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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right) {
	llint middle;
	if (right < left) {
		return -(INF64);
	} else {
		middle = left + (right - left) / 2;
		if (ary[middle] > key) {
			return my_binary_search(ary, key, left, middle - 1);
		} else if (ary[middle] < key) {
			return my_binary_search(ary, key, middle + 1, right);
		} else {
			return middle;
		}
	}
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main (void)
{
	//INPUT
	llint H,N;
	cin >> H >> N;
	vector<llint> A(N);
	rep(i,0,N) {
		cin >> A[i];
	}

	string ans;

	llint sum=0;
	rep(i,0,N) {
		sum+=A[i];
	}

	if (H<=sum){
		ans = "Yes";
	} else {
		ans = "No";
	}

	//OUTPUT
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3968
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
ll dp[100007];
void solve()
{
	ll w;
	int n;
	cin >> n >> w;
	fill(dp, dp + 100005, 1000000000000);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		for (int j = 100001 - b-1; j >= 0; j--)
			dp[j + b] = min(dp[j + b], dp[j] + a);
	}
	ll ans = 0;
	for (int i = 0; i <= 100000; i++)
	{
		if (dp[i] <= w)
			ans = i;
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string r,g,b;
    string num;
    int a=0;

    cin >> r >> g >> b;

    num=r+g+b;

    a=stoi(num);

    if(a%4==0)cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

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

solve :: [String] -> [String]
solve [] = []
solve (line:lines) =
    let [a,op,b] = words line in
    case (go (read a) op (read b)) of
    Just x -> show x : solve lines
    Nothing -> []
    where
    go :: Int -> String -> Int -> Maybe Int
    go a "+" b = Just $ a + b
    go a "-" b = Just $ a - b
    go a "*" b = Just $ a * b
    go a "/" b = Just $ a `div` b
    go _ _ _ = Nothing

main = 
    mapM_ putStrLn =<< solve . lines <$> getContents

Measured memory_bytes: 3976
import collections 
N=int(input())
A=list(map(int,input().split()))
s=0
cnt=collections.Counter(A)
for key in cnt.keys():
  s+=(cnt[key]*(cnt[key]-1))//2
for i in range(N):
  tmp=s
  tmp-=cnt[A[i]]*(cnt[A[i]]-1)//2
  tmp+=(cnt[A[i]]-1)*(cnt[A[i]]-2)//2
  print(tmp)

Measured memory_bytes: 26780
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define MAX_NUM 50001
#include <iomanip>
#include <string>
#include <utility>
#include <map>
using namespace std;


int main()
{
    map<int,int> a;
    int N;
    cin>>N;
    int num;
    for(int i=0;i<N;i++)
    {
        scanf("%d",&num);
        if(a.count(num))
            if(a[num]==0)
                a[num]++;
            else
                a[num]=0;
        else
            a[num]=1;
    }
    int count1=0;
    for(map<int,int>::iterator a_b=a.begin();a_b != a.end();a_b++)
    {
        if(a_b->second)
            count1++;
    }

    cout<<count1;


}

Measured memory_bytes: 4864
N = int(input())
xyz = []
for i in range(N):
    xyz.append(list(map(int, input().split())))
H = 0
h = 0
flag = False
maxz = xyz[0][2]
maxy = xyz[0][1]
maxx = xyz[0][0]
for k in range(N):
    if xyz[k][2] > maxz:
        maxz = xyz[k][2]
        maxx = xyz[k][0]
        maxy = xyz[k][1]
for i in range(101):
    for j in range(101):
        H = maxz + abs(maxx-i) + abs(maxy-j)
        for k in xyz:
            h = H -abs(k[0]-i)-abs(k[1]-j)
            if h < 0:
                h = 0
            if h == k[2]:
                continue
            else:
                break
        else:
            if H != 0:
                flag = True
                print("{} {} {}".format(i, j, H))
                break
    if flag:
        break


Measured memory_bytes: 3064
mod=7+10**9
n=int(input())
c=['$']+[int(input()) for _ in [0]*n]
data=[1]+[0]*n
s={}

for i in range(1,n+1):
  if c[i] in s.keys():
    if c[i]!=c[i-1]:
      s[c[i]]+=data[i-1]
      s[c[i]]%=mod
  else:
    s[c[i]]=data[i-1]
  data[i]=s[c[i]]%mod
        
print(data[n])


Measured memory_bytes: 34024
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

int main(int argc, char const* argv[])
{
  int64_t N, M, A, B;
  cin >> N >> M;
  vector<pair<int64_t, int64_t>> drinks(N, make_pair(0, 0));
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    drinks[i] = make_pair(A, B);
  }
  sort(drinks.begin(), drinks.end(), [](pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
    return a.first < b.first;
  });

  int64_t cost = 0, to_buy;
  for (auto d : drinks) {
    to_buy = min(M, d.second);
    cost += to_buy * d.first;
    if ((M -= to_buy) <= 0) break;
  }
  cout << cost << '\n';
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
a = list(map(int, input().split()))

num_list = {}
for i in a:
    if i in num_list:
        num_list[i] += 1
    else:
        num_list[i] = 1


count_rem = 0
for i in num_list:
    if i > num_list[i]:
        count_rem += num_list[i]
    elif i < num_list[i]:
        count_rem += num_list[i] - i

print(count_rem)


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

// 01-BFS
//
// NOTE:
// 全てコストが 0 の場合は queue や stack を使う。
// 全てコストが 1 の場合は queue を使う。
// コストが 0 と 1 の両方ある場合は deque を使う。
// --> コストが低い方を push_front、コストが高い方を push_back することで、コストが低い方から順番に幅優先探索を行う。
//
int main() {
  int h, w;
  cin >> h >> w;
  int si, sj, ti, tj;
  cin >> si >> sj >> ti >> tj;
  si--; sj--; ti--; tj--;

  // 入力受取
  vector<string> s(h);
  for (int i = 0; i < h; i++) { cin >> s.at(i); }

  // BFSのためのデータ構造
  const int INF = 1e9;
  vector<vector<int>> dist(h, vector<int>(w, INF)); // 全マスのコストを INF に初期化
  deque<pair<int, int>> que;

  // 初期条件
  dist.at(si).at(sj) = 0; // スタート地点をコスト0とする
  que.push_front(make_pair(si, sj));

  // キューから取り出した要素について、上下左右を探索する際に利用
  const vector<int> di { -1,  0, 1, 0 };
  const vector<int> dj {  0, -1, 0, 1 };

  // BFS開始（キューが空になるまで探索を行う）
  while (!que.empty()) {
#ifndef ONLINE_JUDGE
    // キューの状態を確認
    deque<pair<int, int>> dup = que;
    cout << "### deque status check" << endl;
    while (!dup.empty()) {
      pair<int, int> a1 = dup.front();
      dup.pop_front();
      cout << "(" << a1.first +1 << ", " << a1.second +1 << "), ";
    }
    cout << endl;
#endif

    // キューから先頭要素を取り出す
    int i = que.front().first;  // 縦軸
    int j = que.front().second; // 横軸
    int d = dist.at(i).at(j);   // 距離
    que.pop_front();

    // 徒歩
    for (int v = 0; v < 4; v++) {
      int next_i = i + di.at(v);
      int next_j = j + dj.at(v);
      // 移動先が表の外の場合は探索しない
      if (next_i < 0 || next_i >= h || next_j < 0 || next_j >= w) { continue; }
      // 移動先が壁の場合は探索しない
      if (s.at(next_i).at(next_j) == '#') { continue; }
      // 移動先のコストが「移動元のコスト」以下である場合は、コストを更新する必要がないため探索しない
      if (dist.at(next_i).at(next_j) <= d) { continue; }

      // 上下左右について、徒歩で移動できる場合は移動元と同じコストをセットする
      dist.at(next_i).at(next_j) = d;
      // 徒歩で移動可能なマスをキューの先頭に追加し、優先的に探索する
      que.push_front(make_pair(next_i, next_j));
    }

    // ワープ
    for (int ei = -2; ei <= 2; ei++) {
      for (int ej = -2; ej <= 2; ej++) {
        int next_i = i + ei;
        int next_j = j + ej;

        // 移動先がマスの外の場合はスキップ
        if (next_i < 0 || next_i >= h || next_j < 0 || next_j >= w) { continue; }
        // 移動先が壁の場合はスキップ
        if (s.at(next_i).at(next_j) == '#') { continue; }
        // 移動先のコストが「移動元+1」以下である場合は、ワープ1回で辿り着けるため、ワープを行う前提ではこれ以上の低コストはないため、探索しない
        // 移動先のコストが「移動元+2」以上である場合は、ワープ1回で辿り着ける方が低コストであるため、コストを「移動元+1」で更新する
        if (dist.at(next_i).at(next_j) <= d+1) { continue; }

        dist.at(next_i).at(next_j) = d+1;
        // ワープで移動可能なマスをキューの後尾に追加し、徒歩の探索が完了した後にワープの探索を行う
        que.push_back(make_pair(next_i, next_j));
      }
    }
  }

  // ゴールのコストを確認する
  int ans = dist.at(ti).at(tj);
  // コストが INF の場合は、ワープを使っても到達できなかったため -1 とする
  if (ans == INF) { ans = -1; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9544
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int decode(string s) {
  int ret = 0;
  ret += (s[0] - '0') * 100;
  ret += (s[1] - '0') * 10;
  ret += s[2] - '0';
  return ret;
}

int main() {
  string s;
  cin >> s;
  int diff = 10000;
  for (int i = 0; i < s.size() - 2; i++) {
    int b = decode(s.substr(i, 3));
    if (abs(b - 753) < diff) {
      diff = abs(b - 753);
    }
  }

  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    //与えられる値群を配列ではなくインデックス番号として解釈する
    int[] A = new int[100001];
    long sum = 0;
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt(); //値取得
      A[a] += 1; //該当インデックスの値の個数
      sum += a; //与えられた値群の合計
    }
    
    int Q = sc.nextInt();
    
    for (int i = 0; i < Q; i++) {
      int target = sc.nextInt(); //置換対象
      int value = sc.nextInt(); //置換先
      
      A[value] = A[value] + A[target]; //置換対象の値の個数を、置換先にマージ
      sum += (value - target) * A[target]; //合計値への影響は、(置換先-置換対象の差)×置換対象の値の個数
      
      A[target] = 0; //置換しちゃったので値がもうない
      System.out.println(sum);
    }
  }
}

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

const int N = 1005;
int n, tp, x[N], y[N];
bool d, ux[40], uy[40];

inline void calc(int x, bool* c) {
	bool fcheck = x < 0;
	if (fcheck)x = -x;
	c[30] = c[31] = 1;
	for (int i = 1; i <= 30; i++)c[i - 1] = x >> i & 1;
	if (fcheck)for (int i = 0; i < 31 + d; i++)c[i] ^= 1;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> tp;
		y[i] = x[i] - tp, x[i] += tp;
		if (!i)d = x[i] & 1;
		if (x[i] & 1 ^ d || y[i] & 1 ^ d)return puts("-1"), 0;
	}
	cout << 31 + d << endl;
	for (int i = 0; i < 30; i++)cout << (1 << i) << ' ';
	cout << (1 << 30) - 1;
	cout << (d ? " 1" : "") << endl;
	for (int i = 0; i < n; i++) {
		calc(x[i], ux), calc(y[i], uy);
		for (int j = 0; j < 31 + d; j++)cout << (ux[j] ? (uy[j] ? 'R' : 'U') : (uy[j] ? 'D' : 'L'));
		cout << endl;
	}

	return 0;
}

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

#include <limits.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;
}

const int INF = INT_MAX / 2;

int solve(const int bits, const int current, const int start,
        vector<vector<int> > &dp, const vector<vector<int> > &adj, const int V, const int E) {
    // cout << "bits, current, start: " << bits << "," << current << "," << start << endl;
    if (bits == (1 << V) - 1) {
        if (current == start) {
            // cout << "dp[" << bits << "][" << current << "] = " << 0 << endl;
            return 0;
        } else {
            // cout << "dp[" << bits << "][" << current << "] = " << INF << endl;
            return INF;
        }
    }

    if (dp[bits][current] != -1) {
        return dp[bits][current];
    }

    int min = INF;
    for (int i = 0; i < V; i++) {
        int next_bits = bits | (1 << i);
        if (next_bits == bits) continue;
        chmin(min, solve(next_bits, i, start, dp, adj, V, E) + adj[current][i]);
    }

    dp[bits][current] = min;
    // cout << "dp[" << bits << "][" << current << "] = " << min << endl;
    return min;
}

int main(void) {
    int V, E;
    cin >> V >> E;

    vector<vector<int> > adj(V, vector<int>(V, INF));
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        adj[s][t] = d;
    }

    vector<vector<int> > dp(((1 << V) - 1), vector<int>(V, -1));

    int answer = solve(0, 0, 0, dp, adj, V, E);
    if (answer == INF) answer = -1;

    cout << answer << endl;

    return 0;
}



Measured memory_bytes: 6304
a,b,x = map(int,input().split())
import math

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

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

inline void fastio(void) {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
template <typename T>
inline void read(T &x) {
  cin >> x;
}

namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline int pw(int a, int k) {
    int ans = 1;
    for (; k; k >>= 1, a = mul(a, a))
      if (k & 1) ans = mul(ans, a);
    return ans;
  }
}
const int N = 3e5 + 233;
int n, m, x;
pair <int, int> a[N];

signed main(void) {
  fastio();
  cin >> n;
  rep (i, n) cin >> x, a[++ m] = {x, 0};
  rep (i, n) cin >> x, a[++ m] = {x, 1};
  sort(a + 1, a + m + 1);
  int x = 0, y = 0, ans = 1;
  for (int i = 1; i <= m; i ++) {
    if (a[i].second == 0) {
      if (y) ans *= y --;
      else x ++;
    } else {
      if (x) ans *= x --;
      else y ++;
    }
    ans %= mo;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4352