akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

std::vector<int> L(1000);

int N,M;
int main(void){
    while(std::cin >> N >> M){
        if(N == 0 && M == 0) break;
        for(int i=0; i<N; ++i){
            std::cin >> L[i];
        }

        bool f;
        std::vector<int> b(1012);
        for(int S=0; S<(1<<M); ++S){
            int sum = 0;
            for(int i=0; i<M; ++i){
                sum += b[i] = (S>>i&1);
            }
            for(int i=0; i<N-1; ++i){
                b[M+i] = L[i+1] - L[i] + b[i];
            }

            f = (sum == L[0]);
            for(int i=0; i<N+M-1; ++i){
                if(b[i] != 0 && b[i] != 1){
                    f = false;
                }
            }
            if(f){
                break;
            }
        }

        if(f){
            for(int i=0; i<N+M-1; ++i){
                std::cout << b[i];
            }
            std::cout << std::endl;
        }else{
            std::cout << "Goofy" << std::endl;
        }
    }
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  long long h,w,a,b;
    cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    if(i<b){
    	string s(a,'0');
    	string t(w-a,'1');
    	s+=t;
    	cout<<s<<endl;
    }
    else{
      string s(a,'1');
    	string t(w-a,'0');
    	s+=t;
    	cout<<s<<endl;
    }
  }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, a;
  cin >> n;
  int m[n + 1] = { };
  rep(i,n-1)
  {
    cin >> a;
    m[a]++;
  }
  for (int i = 1; i <= (int) (n); ++i) {
    cout << m[i] << endl;
  }
}

Measured memory_bytes: 4432
import java.util.Scanner;
import java.util.Stack;

public class Main {
    static int n;
    static Scanner sc = new Scanner(System.in);
    
    static boolean aun(){
        Stack<String> au = new Stack<>();
        for(int i=0;i<n;i++){
            String say = sc.next();
            //System.err.println(say);
            if(say.equals("A")){
                au.push("A");
            }
            if(say.equals("Un")){
                if(au.isEmpty()){
                    return false;
                }else{
                    au.pop();
                }
            }
            //System.err.println(au);
        }
        if(au.isEmpty()){
        	return true;
        }else {
        	return false;
        }
    }
    
    public static void main(String[] args) {
        n = sc.nextInt();
        if(n%2 == 1) {
        	System.out.println("NO");
        	return;
        }
        if(aun()){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }    
    }
}


Measured memory_bytes: 26336
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
#define all(x) x.begin(),x.end()
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int N=1e5+9;
const ll mod=998244353;
int a[N],b[N];
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	rep(i,1,n+1)scanf("%d",&a[i]);
	rep(i,1,m+1)scanf("%d",&b[i]);
	int ans=a[1]+b[1]; 
	while(k--){
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		ans=min(ans,a[x]+b[y]-c);
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	ans=min(ans,a[1]+b[1]);
	cout<<ans; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint ans[300][300];

int main() {
    lint h, w, k;
    cin >> h >> w >> k;

    vector<string> s(h);
    for(lint i=0; i<h; i++)  cin >> s[i];

    lint label = 1;
    bool exist;
    for(lint i=0; i<h; i++) {
        exist = false;
        if(count(begin(s[i]), end(s[i]), '#') == 0)  continue;
        for(lint j=0; j<w; j++) {
            if(exist && s[i][j] == '#')  label++;
            else if(s[i][j] == '#')  exist = true;
            ans[i][j] = label;
        }
        if(exist)  label++;
    }

    lint prev = -1;
    for(lint i=0; i<h; i++) {
        if(ans[i][0] != 0)  prev = i;
        for(lint j=0; j<w; j++) {
            if(ans[i][j] == 0 && prev != -1)  ans[i][j] = ans[prev][j];
        }
    }

    prev = -1;
    for(lint i=h-1; i>=0; i--) {
        if(ans[i][0] != 0)  prev = i;
        for(lint j=0; j<w; j++) {
            if(ans[i][j] == 0 && prev != -1)  ans[i][j] = ans[prev][j];
        }
    }

    for(lint i=0; i<h; i++) {
        for(lint j=0; j<w; j++) {
            cout << ans[i][j] << " \n"[j==w-1];
        }
    }

}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> cnt(100010, 0);
    rep(i, N) ++cnt[A[i]];
    ll sum = 0;
    rep(i, 100010) sum += i * cnt[i];
    int Q;
    cin >> Q;
    rep(i, Q) {
        int B, C;
        cin >> B >> C;
        sum -= B * cnt[B];
        sum += C * cnt[B];
        cnt[C] += cnt[B];
        cnt[B] = 0;
        cout << sum << "\n";
    }
    return 0;
}



Measured memory_bytes: 4232
import java.io.*;
import  java.util.*;

import static java.lang.System.in;

class Main{
    static HashMap<Integer,Integer>[] rec;
    static int[] count;
    static int n,m;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt();
        count = new int[m];
        rec = new HashMap[m];
        for(int i=0;i<m;i++) rec[i]=new HashMap<>();
        for(int i=0;i<n;i++){
            int x = sc.nextInt();
            int pos = x%m;
            count[pos]++;
            rec[pos].put(x,rec[pos].getOrDefault(x,0)+1);
        }
        int ans = 0;
        for(int i=1;i<=(m-1)/2;i++){
            ans += help(i);
        }
        ans += count[0]/2;
        if(m%2==0) ans += count[m/2]/2;
        System.out.println(ans);
    }
    static int help(int i){
        int j = m-i;
        if(count[i]==count[j]) return count[i];
        int remain = Math.abs(count[i]-count[j]);
        HashMap<Integer,Integer> map = count[i]<count[j]?rec[j]:rec[i];
        int ans = Math.min(count[i],count[j]);
        for(int w:map.keySet()){
            if(remain==0) break;
            int cur = Math.min(remain,map.get(w))/2;
            ans += cur;
            remain -= cur*2;
        }
        return ans;
    }
}


Measured memory_bytes: 81468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> sunuke(N + 1);
    rep(i, K) {
        ll d;
        cin >> d;
        vector<ll> A(d);
        rep(j, d) {
            ll a;
            cin >> a;
            sunuke[a]++;
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        if (sunuke[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

// マクロ
#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX 9223372036854775807
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}

// ***<ここから>****************************************************************

long long Pow(long long a, long long n) {
	long long x = 1;
	while (n > 0) {
		if (n & 1) x = x * a;
		a = a * a;
		n = n >> 1;
	}
	return x;
}

int main(void) {

	string n;
	cin >> n;
	rep(i, 3) {
		if (n[i] == '1') {
			n[i] = '9';
		}
		else {
			n[i] = '1';
		}
	}

	cout << n << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    c = int(input())
    big = max(a,b)
    count =0
    if c % big > 0:
        count = c//big +1
    else:
        count = c//big
    

    print(count)


Measured memory_bytes: 4596
H,W = map(int,raw_input().split(" "))

matel = {}

for i in range(H):
    line = raw_input()
    for c in line:
        if not c in matel:
            matel[c] = 0
        matel[c] += 1




def cnter():
    cnt4 = 0
    cnt2 = 0
    cnt1 = 0

    for key in matel.keys():
        vs = matel[key]
        while vs >= 4:
            cnt4+=1
            vs-=4
        while vs >= 2:
            cnt2 += 1
            vs-=2
        cnt1 +=vs

    return cnt1,cnt2,cnt4



def solve():
    cnt1,cnt2,cnt4 = cnter()

    if H%2 == 0 and W%2 == 0:
        if cnt2 == 0 and cnt1 == 0:
            print "Yes"
        else:
            print "No"
    elif H%2 == 1 and W%2 == 1:
        if cnt1 != 1:
            print "No"
            return
        po = (W/2)+(H/2) - cnt2
        if po < 0:
            print "No"
            return

        if po %2 == 0:
            print "Yes"
        else:
            print "No"

    else:
        if cnt1:
            print "No"
            return 
        if H%2 == 1:
            po = W/2 - cnt2
        else:
            po = H/2 - cnt2

        if po < 0:
            print "No"
            return
        if po % 2 == 0:
            print "Yes"
        else:
            print "No"

solve()


Measured memory_bytes: 2820
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int count=0;
  string S;
  cin >> S;
  for(int k=0;k<=((int)S.length()/2)-1; k++){
    if(S.at(k)!=S.at(S.length()-(k+1))) count++;
  }
  cout << count << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  string floorCeil;
  for (int i=0; i<W+2; i++) {
    floorCeil.push_back('#');
  }
  
  for (int i=0; i<H; i++) {
    if (i == 0) {
      cout << floorCeil << endl;
    }
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  cout << floorCeil << endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int getonemore(int i, int j) {
    if (i < 3 && j < 3)
        if (i < j)
            if (j-i==1)
                return 3-i-j;
            else
                return 5-(3-i-j);
        else
            if (i-j==1)
                return 5-(3-i-j);
            else
                return 3-i-j;
    else if (2 < i && 2 < j)
        if (i < j)
            if (j-i==1)
                return 12-i-j;
            else
                return 5-(12-i-j);
        else
            if (i-j==1)
                return 5-(12-i-j);
            else
                return 12-i-j;
    else if (2 < j) {
        int k = 5-j;
        if (i < k)
            if (k-i==1)
                return 5-(3-i-k);
            else
                return 3-i-k;
        else
            if (i-k==1)
                return 3-i-k;
            else
                return 5-(3-i-k);
    }
    else if (2 < i) {
        int k = 5-i;
        if (k < j)
            if (j-k==1)
                return 5-(3-j-k);
            else
                return 3-j-k;
        else
            if (k-j==1)
                return 3-j-k;
            else
                return 5-(3-j-k);
    }
    return 0;
}
bool check(int *d1, int *d2) {
    for (int i = 0; i < 6; i++) {
        if (d1[0] == d2[i] && d1[5] == d2[5-i]) {
            for (int j = 0; j < 6; j++) {
                if (i == j || 5-i == j)
                    continue;
                if (d1[1] == d2[j] && d1[4] == d2[5-j]) {
                    int k = getonemore(i,j);
                    if (d1[2] == d2[k] && d1[3] == d2[5-k]) {
                        return 1;
                    }
                }
            }
        }
    }
    return 0;
}
void check2(int** d, int n) {
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (check(d[i], d[j])) {
                cout << "No\n";
                return;
            }
        }
    }
    cout << "Yes\n";
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int **d;
    d = new int*[n];
    for (int i = 0; i < n; i++) {
        d[i] = new int[6];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++)
            cin >> d[i][j];
    }
    check2(d, n);
}

Measured memory_bytes: 3144
h = []
w = []
while True:
    h1,w1 = map(int,input().split())
    if (h1 == 0)*(w1 == 0) :
        break
    h.append(int(h1))
    w.append(int(w1))
    

for i in range(len(h)):
    for j in range(h[i]):
        print("#"*w[i])
    print()




Measured memory_bytes: 5628
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new Main().run();
    }

    void solve() {
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        if (A == B) {
            out.println(C);
        } else if (A == C) {
            out.println(B);
        } else if (B == C) {
            out.println(A);
        }
    }

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
  ll i,j;
  ll h,w;
  cin>>h>>w;
  string s[h];
  for(i=0;i<h;i++){
    cin>>s[i];
  }
  VVI y(h,vector<ll>(w,0));
  VVI t(h,vector<ll>(w,0));

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(y[i][j]==0){
        ll x=0;
        ll jo=j;
        while(j<w&&s[i][j]=='.'){
          x++;
          j++;
        }
        for(ll k=jo;k<j;k++){
          y[i][k]=x;
        }
      }
    }
  }

  for(j=0;j<w;j++){
    for(i=0;i<h;i++){
      if(t[i][j]==0){
        ll x=0;
        ll io=i;
        while(i<h&&s[i][j]=='.'){
          x++;
          i++;
        }
        for(ll k=io;k<i;k++){
          t[k][j]=x;
        }
      }
    }
  }

  ll ans=0;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      ans=max(ans,t[i][j]+y[i][j]);
    }
  }
  cout<<ans-1<<endl;

  return 0;
}

Measured memory_bytes: 67072
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	A := getInt()
	B := getInt()

	if A != 1 && B != 1 {
		fmt.Println(1)
	} else if A != 2 && B != 2 {
		fmt.Println(2)
	} else if A != 3 && B != 3 {
		fmt.Println(3)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
class Max_Bit:
    """区間の最大値のＢＩＴ

    viの更新をする。
    v1からｖiまでの最大値を取得する。
    どちらもO(logn)時間にできる

    Attributes:
        size (int): BITのサイズ
        tree (list of int): 区間の最大値を管理するための二分木
    """
    def __init__(self, n):
        """
        Args:
            n(int): BITのサイズ
        """
        self.size = n
        self.tree = [0] * (n + 1)

    def get_max(self, i=None):
        if i is None:
            i = self.size
        m = 0  # -INF
        while i > 0:
            m = max(m, self.tree[i])
            i -= i & -i
        return m

    def update(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
def main():
    """
    dp: 花iを使うとした場合の1からiまでつかった美しさの最大値
    短い花から更新する

    """
    N = int(input())
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))
    dp = Max_Bit(N)
    sort_H_i = sorted((h, i) for i, h in enumerate(H))
    for h, i in sort_H_i:
        dp.update(i+1,dp.get_max(i) + A[i])
    print(dp.get_max())

if __name__ == '__main__':
    main()


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

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

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

int H, W;
char maze [21][21];

int bfs(int sh, int sw) {
    int cnt[20][20];
    queue<int> qx;
    queue<int> qy;
    qx.push(sw);
    qy.push(sh);
    rep(i, 20) rep(j, 20) cnt[i][j] = 100000;
    cnt[sh][sw] = 0;
    while(qx.size() != 0) {
        int x = qx.front();
        int y = qy.front();
        qx.pop();
        qy.pop();
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 or nx >= W or ny < 0 or ny >= H) continue;
            if (maze[ny][nx] != '#' and cnt[ny][nx] == 100000) {
                cnt[ny][nx] = cnt[y][x] + 1;
                qx.push(nx);
                qy.push(ny);
            }
        }
    }

    int ret = 0;
    rep(i, H) rep(j, W) {
        if (cnt[i][j] != 100000) ret = max(cnt[i][j], ret);
    }
    return ret;
}

int main() {
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> maze[i][j];

    int ans = 0;
    rep(i, H) rep(j, W) {
        if(maze[i][j] != '#') {
            ans = max(bfs(i, j), ans);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    cout<<"bust";
    else cout<<"win";

}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
//     cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
long long cau[100][100];
int main()
{    int n,m;
      cin>>n>>m;
      long long  J=0;
      long long  O=0;
      memset(cau,0,sizeof(cau));
      int i=0;
      int b;
      while(n--)
      {
            cin>>b;
          if(b%2)
            J++;
          else
            O++;
      }
      memset(cau,0,sizeof(cau));
      cau[0][1]=1;
      cau[0][0]=1;
      for(int i=0;i<55;i++)
        cau[0][i]=1;
      for(int i=0;i<=50;i++)
        for(int is=0;is<=i;is++)
      {    if(is==0)
              continue;
          cau[is][i]=cau[is-1][i-1]+cau[is][i-1];
      }
     long long fd=1;
     for(int i=0;i<O;i++)
     {
         fd=fd*2;
     }
     long long num=0;
      if(m%2)
      {
          for(int i=1;i<=J;i=i+2)
          {    long long t=cau[i][J];
              num=num+(t*fd);
          }
          cout<<num;
      }
      else
      { for(int i=0;i<=J;i=i+2)
          {    long long t=cau[i][J];
              num=num+t*fd;
          }
          cout<<num;

      }
     return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int P = scn.nextInt(), Q = scn.nextInt(),R = scn.nextInt();
		System.out.println(P+Q+R-Math.max(P, Math.max(Q,R)));
	}

}


Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static IEnumerable<int[]> Solve(int H, int W, int[][] A)
        {
            var list = new List<int[]>();
            for (int y = 0; y < H; ++y)
            {
                if (y % 2 == 0)
                {
                    for (int x = 0; x < W; ++x)
                    {
                        int y1 = y;
                        int x1 = x;
                        int y2 = (x + 1 < W) ? y1 : y1 + 1;
                        int x2 = (x + 1 < W) ? x1 + 1 : x1;
                        if (y2 < H && A[y1][x1] % 2 != 0)
                        {
                            --A[y1][x1];
                            ++A[y2][x2];
                            list.Add(new[] { y1 + 1, x1 + 1, y2 + 1, x2 + 1 });
                        }
                    }
                }
                else
                {
                    for (int x = W - 1; x >= 0; --x)
                    {
                        int y1 = y;
                        int x1 = x;
                        int y2 = (x - 1 >= 0) ? y1 : y1 + 1;
                        int x2 = (x - 1 >= 0) ? x1 - 1 : x1;
                        if (y2 < H && A[y1][x1] % 2 != 0)
                        {
                            --A[y1][x1];
                            ++A[y2][x2];
                            list.Add(new[] { y1 + 1, x1 + 1, y2 + 1, x2 + 1 });
                        }
                    }
                }
            }
            return list;
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int H = V[0];
            int W = V[1];
            var A = new int[H][];
            for (int i = 0; i < H; ++i) { A[i] = ReadInts(); }
            var lines = Solve(H, W, A);
            Console.WriteLine(lines.Count());
            foreach (int[] ans in lines)
            {
                Console.WriteLine(string.Join(" ", ans));
            }
        }
    }
}


Measured memory_bytes: 30256
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

def dp(sums,depth,data):
	if sums < 0 or sums > sum(data):
		return False
	if sums == 0:
		return True
	if depth >= len(data):
		return False

	return dp(sums,depth+1,data) or dp(sums-data[depth],depth+1,data)

for i in m:
	if i < min(A) or i > sum(A):
		print("no")
	else:
		print("yes" if dp(i,0,A) else "no")



Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <atcoder/lazysegtree>

namespace ac = atcoder;

using lint = long long;

struct Data {
    lint zero, one, rev;
    Data(lint zero = 0, lint one = 0, lint rev = 0)
        : zero(zero), one(one), rev(rev) {}

    static Data op(Data l, Data r) {
        return Data(l.zero + r.zero, l.one + r.one,
                    l.rev + r.rev + l.one * r.zero);
    }
    static Data e() { return Data(); }
};

struct Ope {
    bool rev;
    Ope(bool rev = false) : rev(rev) {}

    static Ope op(Ope l, Ope r) {
        return Ope(l.rev != r.rev);
    }
    static Ope e() { return Ope(); }
};

Data apply(Ope f, Data d) {
    if (f.rev) {
        std::swap(d.zero, d.one);
        d.rev = d.zero * d.one - d.rev;
    }
    return d;
};

void solve() {
    int n, q;
    std::cin >> n >> q;

    std::vector<Data> ds(n);
    for (auto& d : ds) {
        int x;
        std::cin >> x;
        ++(x == 0 ? d.zero : d.one);
    }

    ac::lazy_segtree<Data, Data::op, Data::e,
                     Ope, apply, Ope::op, Ope::e>
        seg(ds);

    while (q--) {
        int t, l, r;
        std::cin >> t >> l >> r;
        --l;

        switch (t) {
            case 1: {
                seg.apply(l, r, Ope(true));
                break;
            }
            case 2: {
                std::cout << seg.prod(l, r).rev << "\n";
                break;
            }
        }
    }
}

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

    solve();

    return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    if(n % 2 == 1){
        cout << "No" << endl;
    } else if(n % 2 == 0){
        for(int i = 0; i < n/2; i++){
            if(s.at(i) == s.at(i + n / 2)){
                count++;
            }
        }
        if(count == n/2){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a,b;
  cin >> a >> b;
  if (a == 'D') {
    if (b == 'H') {
      b = 'D';
    } else {
      b = 'H';
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int A, B, C; cin >> A >> B >> C;
    cout << (B + C < A ? 0 : C - (A - B)) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    if (n % 2) {
        cout << "No\n";
    } else {
        for (int i = 0; i < n / 2; ++i) if (s.at(i) != s.at(i + n / 2)) {
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i,N){
    cin >> w[i] >> v[i];
  }

  long **dp=(long **)malloc(sizeof(long *)*N);
  rep(i,N){
    dp[i]=(long *)calloc((W+1),sizeof(long));
  }
  srep(j, w[0], W+1){
    dp[0][j]=v[0];
  }

  rep(i,N-1){
    rep(j,W+1){
      dp[i+1][j]=max(dp[i+1][j], dp[i][j]);
      if(j+w[i+1]<=W){
        dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]], dp[i][j]+v[i+1]);
      }
    }
  }

  // rep(i,N){
  //   rep(j,W+1){
  //     printf("%d ", dp[i][j]);
  //   }
  //   printf("\n");
  // }

  long ans=0;
  rep(j,W+1){
    ans=max(ans, dp[N-1][j]);
  }

  printf("%ld\n", ans);
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())

using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int a , b , t;
    cin >> a >> b >> t;
    cout << (t / a) * b << "\n";
 }


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

using namespace std;

int main()
{
	vector<int> V;
	int n;
	cin >> n;
	while (n--)
	{
		int a;
		cin >> a;
		V.push_back(a);	
	}
	
	int q;
	cin >> q;
	while (q--)
	{
		int b, e, k;
		cin >> b >> e >> k;
		cout << count(V.begin()+b,V.begin()+e, k) << endl;	
	}

	
} 


Measured memory_bytes: 3164
min_d = None
total = 0
for _ in range(5):
    i = int(input())
    total += i // 10 * 10
    d = i % 10
    if d != 0:
        if min_d is None:
            min_d = d
        else:
            min_d = min(min_d, d)
        total += 10
if min_d is None:
    print(total)
else:
    print(total - (10 - min_d))


Measured memory_bytes: 2940
S = input()
ans_lis = []

flag_lis = [abs(7-int(x)) for x in S[:len(S)-2]]

for _ in range(len(flag_lis)):
    if  flag_lis[_] == min(flag_lis):
        flag = _
        ans_lis.append(int(S[flag:flag+3:]))
tp = [abs(_-753) for _ in ans_lis]
ans = min(tp)
print(ans)


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

int main(){
  int n;
  cin>>n;
  int cnt=0,mx=0;
  rep(i,n){
    int a,b; cin>>a>>b;
    if(a==b)cnt++;
    else cnt=0;
    mx=max(mx,cnt);
  }
  cout<<(mx>=3?"Yes":"No")<<endl;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B, N; cin >> A >> B >> N;
  ll k = min(B-1, N);
  cout << A * k / B << endl;

  return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vi l(n);
    rep(i,n) cin >>l[i];
    int ans = 0;
    sort(all(l));
    rep(i,n){
        repk(j,i+1,n){
            int x = l[i]+l[j];
            int k = lower_bound(all(l),x) - l.begin();
            ans += max(k - (j+1) ,0);
        }
    }
    cout << ans <<endl;
    return 0;
}

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

const int N = 305;
const int INF = 1e9;

string s;
int n, k;
int dp[N][N][N];
int res;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s >> k;
	n = s.size();
	s = ' ' + s;
	s = s + '&';

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int c = 0; c <= k; ++c) dp[i][j][c] = -INF;
		}
	}
	for (int i = 0; i <= n + 1; ++i) dp[0][i][0] = 0;
	for (int i = 0; i <= n + 1; ++i) dp[i][n + 1][0] = 0;
	for (int gap = n; gap >= 1; --gap) {
		for (int i = 1; i <= n - gap + 1; ++i) {
			int j = i + gap - 1;
			for (int c = 0; c <= k; ++c) {
				dp[i][j][c] = max(dp[i][j][c], dp[i - 1][j][c]);
				dp[i][j][c] = max(dp[i][j][c], dp[i][j + 1][c]);
				
				bool more = (s[i] == s[j] ? 0 : 1);
				if (c >= more) {
					dp[i][j][c] = max(dp[i][j][c], dp[i - 1][j + 1][c - more] + (i == j ? 1 : 2));
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int c = 0; c <= k; ++c) {
				res = max(res, dp[i][j][c]);
			}
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 111104
#include <iostream>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){

    ll s,w;
    cin >> s >> w;
    if(s<=w)
        cout << "unsafe" << endl;
    else
        cout << "safe"<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

const ll MAX = 1e5+10;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t * b; swap(a,b);
        u -= t * v; swap(u,v);
    }
    u %= m;
    if(u < 0) u += m;
    return u;

}

int main(){
    ll n; cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    ll ans = 0;
    // assert(n <= 2000);
    vector<ll> dp(n+10,0);
    dp[0] = 1;
    rep(i,n)dp[i+1] = dp[i] * (i+1) % MOD;
    // print(dp);
    // rep(i,n-1){
    //     ll dis = x[i+1]- x[i];
    //     ll temp = dp[n-1];
    //     temp = (temp * dp[n-1] / (n-i-1));
    //     ans += temp * dis;
    //     ans %= MOD;
    // }
    COMinit();
    // rep(i,n)rep(j,n){
    //     if(i >= j)continue;
    //     ll dis = x[j] - x[i];
    //     ll temp;
    //     if(j == n-1){
    //         temp = dp[n-1] * modinv((j-i), MOD);
    //     }
    //     else{
    //         temp = (COM(n-1, j-i+1) * dp[j-i-1]) % MOD;
    //         temp = (temp * dp[n-j+i-2]) % MOD;
    //     }
    //     temp %= MOD;
    //     // debug(i);debug(j);
    //     // debug(temp);
    //     ans = (ans + (temp * dis) % MOD) % MOD;
    // }
    vector<ll> dp2(n+10);
    dp2[0] = 0;
    rep(i,n+1){
        dp2[i+1] = (dp2[i] * (i+1)) % MOD + (dp[i+1] * modinv((i+1), MOD)) % MOD;
        dp2[i+1] %= MOD;
    }
    // print(dp2);
    rep(i,n-1){
        ll dis = x[i+1]- x[i];
        ll temp = dp2[i+1];
        temp *= (dp[n-1] * modinv(dp[i+1], MOD)) % MOD;
        temp %= MOD;
        ans = (ans + (temp * dis) % MOD) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
	int t,n,m,p[1234],h,i,l;
	char a;
	
	scanf("%d",&n);
	scanf("%d",&m);
	
	for(t=1;t<=n;t++){
		p[t]=t;
	}
	
	for(t=1;t<=m;t++){
		scanf("%d",&h);
		scanf("%c",&a);
		scanf("%d",&i);
		
		l=p[h];p[h]=p[i];p[i]=l;
	}
	
	for(t=1;t<=n;t++){
		printf("%d\n",p[t]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int A,B,X;
  cin>>A>>B>>X;
  if(2*X<A*A*B){
    double Y=A*B*B;
    Y/=(2*X);
    cout<<setprecision(10)<<atan2(Y,1.0)*180/M_PI<<endl;
  }else{
    double Y=2*A*A*B-2*X;
    Y/=(A*A*A);
    cout<<setprecision(10)<<atan2(Y,1.0)*180/M_PI<<endl;
  }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,c;
    cin>>r>>c;
    char grid[r][c];
    for(int i=0;i<r;i++)
    for(int j=0;j<c;j++)
    cin>>grid[i][j];
    int dp[r][c];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<r;i++)
    {
        if(grid[i][0]=='#')
            break;
        dp[i][0]=1;
    }
    for(int j=0;j<c;j++)
    {
        if(grid[0][j]=='#')
            break;
        dp[0][j]=1;
    }
    for(int i=1;i<r;i++)
    {
        for(int j=1;j<c;j++)
        {
            if(grid[i][j]=='#')
            continue;
            if(grid[i][j-1]=='#' && grid[i-1][j]=='#')
            dp[i][j]=0;
            else if(grid[i][j-1]=='#')
            dp[i][j]=dp[i-1][j];
            else if(grid[i-1][j]=='#')
            dp[i][j]=dp[i][j-1];
            else
            dp[i][j]=(dp[i][j-1]+dp[i-1][j])%1000000007;
        }
    }
    cout<<dp[r-1][c-1] % 1000000007<<endl;
}


Measured memory_bytes: 5120
N = int(input())
# input().split()をi+1と前後させると挙動が変化する
X = [[input().split(), i + 1] for i in range(N)]
X_sorted = sorted(X, key=lambda x: (x[0][0], -int(x[0][1])))

for x in X_sorted:
    print(x[1])


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

int n;

void dfs(string s, char mx) {
	if (s.length() == n)
		printf("%s\n", s.c_str());
	else {
		for (char c = 'a'; c <= mx; c++)
			dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
	}
}

int main()
{
	cin >> n;
	dfs("", 'a');
}


Measured memory_bytes: 1536
/* **********************************JAI SAI RAM ************************************* */
//HELP IN CODEFORCES ROUND 641
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll P=1000000007;
ll MAX=1e15;
ll MIN=-1*(1e15);
ll a[200001];
void  solve()
{
    ll n,i,j,k,l,m,o,q,r,t;
    ll ans=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ans+=a[n-1];
    j=n-2;
    for(i=n-3;i>=0;)
    {
      if(i>=0)
      {
      ans+=a[j];
      i--;
      }
      if(i>=0)
      {
      ans+=a[j];
      i--;
      }
      j--;
    }
    cout<<ans<<endl;
}
int main()
{
    ll t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5176
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n = int(readline())
# O(N)解法
ans = 0
for i in range(1,n+1):
    a = n//i
    ans += a*(a+1)*i//2
print(ans)


Measured memory_bytes: 63820