akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 1<<16;

//head

int n;
int a[20][20];
ll sum[N];
ll dp[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i, n) rep(j, n) cin >> a[i][j];
	rep(i, 1<<n) {
		rep(j, n) if(i>>j&1) rep(k, j) if(i>>k&1) sum[i] += a[k][j];
	}
	rep(i, 1<<n) {
		for(int j = i; j > 0;) {
			j--;
			j &= i;
			int u = i^j;
			chmax(dp[i], dp[j] + sum[u]);
		}
	}

	cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 4676
while True:
    N, Q = map(int, raw_input().split())
    if (N, Q) == (0, 0):
        break
    count = [Q-1] + [0] * 100
    for _ in xrange(N):
        for d in map(int, raw_input().split())[1:]:
            count[d] += 1
    print count.index(max(count))

Measured memory_bytes: 4204
#include <stdio.h>

int main(void) {  

int a, b, c;    

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

if(a<b && b<c){      

printf("Yes\n");     

}    

else{      

printf("No\n");     

}    

return 0;  

}
 

Measured memory_bytes: 580
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, K: int, D: int):
    if X<0:
        X *= -1
    a = X % D
    b = X // D
    if K<b:
        ans = X - K * D
    else:
        if ((K-b) % 2)==0:
            ans = a
        else:
            ans = -(a-D)
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(X, K, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27116
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M=2e5+10;
int n;
pair<ll,ll> p[M];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&p[i].first,&p[i].second);
    vector<ll> a(n);
    for(int i=0;i<n;i++)
        a[i]=p[i].first+p[i].second;
    sort(a.begin(),a.end());
    ll ans=a.back()-(*a.begin());

    for(int i=0;i<n;i++)
        a[i]=p[i].first-p[i].second;
    sort(a.begin(),a.end());
    ans=max(ans,a.back()-(*a.begin()));

    for(int i=0;i<n;i++)
        a[i]=-p[i].first+p[i].second;
    sort(a.begin(),a.end());
    ans=max(ans,a.back()-(*a.begin()));

    for(int i=0;i<n;i++)
        a[i]=-p[i].first-p[i].second;
    sort(a.begin(),a.end());

    ans=max(ans,a.back()-(*a.begin()));
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 8020
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n-1) {
        int a;
        cin >> a;
        ++b[a-1];
    } 
    rep(i,n) cout << b[i] << endl;
    

    return 0;   
}

Measured memory_bytes: 4052
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	int n, m;
	cin >> n >> m;
	vector <vector <int>> a(n, vector <int> (m));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	int g = 1e9;
	vector <bool> done(m, false);
	int iter = 0;
	while(iter < m) {
		vector <int> cnt(m, 0);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(!done[a[i][j]]) {
					cnt[a[i][j]]++;
					break;
				}
			}
		}
		int el = max_element(all(cnt)) - cnt.begin();
		g = min(g, cnt[el]);
		done[el] = true;
		iter++;
	}
	cout << g << endl;

    return 0;
}

Measured memory_bytes: 3744
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 5e5 + 100;
const int LG = 60;

int n;
ll k;
int a[N];

int go[LG][N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		a[i + n] = a[i];
	map<int, int> lst;
	for (int i = 2 * n - 1; i >= n; --i) {
		lst[a[i]] = i;
	}
	for (int i = n - 1; i >= 0; --i) {
		int x = lst[a[i]] + 1;
		if (x >= n)
			go[0][i] = x - n;
		else
			go[0][i] = go[0][x];
		lst[a[i]] = i;
	}
	go[0][n] = 0;
	for (int i = 1; i < LG; ++i)
		for (int j = 0; j <= n; ++j)
			go[i][j] = go[i - 1][go[i - 1][j]];
	int now = 0;
	--k;
	for (int i = LG - 1; i >= 0; --i)
		if ((1ll << i) <= k) {
			k -= (1ll << i);
			now = go[i][now];
		}
	lst.clear();
	vector<int> ans;
	for (int i = now; i < n; ++i) {
		if (lst.count(a[i])) {
			while (ans.back() != a[i])
				lst.erase(ans.back()), ans.pop_back();
			ans.pop_back();
			lst.erase(a[i]);
		}
		else {
			lst[a[i]] = ans.size();
			ans.push_back(a[i]);
		}
	}
	for (int i: ans)
		cout << i << " ";
	cout << "\n";
	return 0;
}




Measured memory_bytes: 129276
from sys import stdin
n,m = map(int,stdin.readline().split())
a = map(int,stdin.readline().split())
b = map(int,stdin.readline().split())
a.sort()
b.sort()
x = []
y = []
for i in xrange(1,n):
    x.append(a[i] - a[i-1])
for i in xrange(1,m):
    y.append(b[i] - b[i-1])   
fir = 0
sec = 0
n = len(x)
m = len(y)
for i in xrange(n):
    fir += (i+1) * (n-i)*x[i]
for i in xrange(m):
    sec += (i+1) * (m-i) * y[i]
mod = 10**9 + 7
print (fir * sec)%mod

Measured memory_bytes: 15460
N, M = map(int, input().split())
switch = list()
for i in range(M): 
  x = list(map(int, input().split()))
  switch.append(x[1:])
mod = list(map(int, input().split()))

ans = 0
for n in range(2**N):
  flag = 1
  useswitch = list()
  cnt = [0] * M
  for i in range(N):
    if n>>i & 1 == 1:
      useswitch.append(i+1)
      
  for m in range(M):
    for s in useswitch:
      if s in switch[m]:
        cnt[m] = (cnt[m]+1)%2
        
  
  for i in range(M):
    if(cnt[i] != mod[i]):
      flag = 0
      
  if(flag == 1):
    ans += 1
  
    
print(ans)

Measured memory_bytes: 3064
from bisect import bisect_left, bisect_right

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

A.sort()
C.sort()

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)

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


int main() {
    char cur, prev = '.';
    bool ans = 1;
    for(int i=0; i<4; i++) {
        cin >> cur;
        if(cur == prev) {
            ans = 0;
        }
        prev = cur; 
    }
    cout << (ans ? "Good" : "Bad") << "\n";
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int i;
	bool ok = false;
	int arr[26] = {0};
	for(i=0; i<s.length(); i++){
		arr[s[i]-'a']++;
	}
	for(i=0; i<26; i++){
		if(arr[i]==0){
			ok = true;
			break;
		}
	}
	if(ok){
		//cout << 'a'+i << endl;
		printf("%c\n", 'a'+i);
	}
	else{
		cout << "None\n";
	}
	return 0;
}


Measured memory_bytes: 3840
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int res = 0;
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
            res += b[i];
        }
        for (int i = 0; i < n-1; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 1; i < n; i++) {
            if(a[i]-a[i-1] == 1){
                res+=c[a[i-1]-1];
            }
        }
        System.out.println(res);
    }
}

class io{

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }
}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



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

using namespace std;
long long n,k,sum;
long long a[200009];
int main()
{
    cin>>n>>k;

    for(int i=0;i<n;i++){
        cin>>a[i];
            }
    sort(a,a+n);
    for(int i=0;i<n-k;i++)
        sum+=a[i];
    cout<<sum;


    return 0;
}


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

using namespace std;

int main(void) {
   int a, b;
   cin >> a >> b;
   for(int i = 0;i < 2000;i++) {
     int store_a = (int)(i*0.08);
     int store_b = (int)(i*0.1);
     if(store_a == a && store_b == b) {
       cout << i << endl;
       return 0;
     }

   }
   cout << -1 << endl;
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 15

void set(int);
void print(int);

int tbl[MAX][MAX];

int main(void) {
    int n;
    for(; scanf("%d", &n), n; set(n), print(n));
    return 0;
}

void set(int n) {
    int i, x = n / 2, y = x + 1;
    memset(tbl, 0, sizeof(tbl));
    for(i = 1; i <= n * n; i++) {
        tbl[y][x] && (y = -~y % n, x = (~-x + n) % n);
        tbl[y][x] = i, y = -~y % n, x = -~x % n;
    }
}

void print(int n) {
    int i, j;
    for(i = 0; i < n; printf("\n"), i++) {
        for(j = 0; j < n; printf("%4d", tbl[i][j++]));
    }
}

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

using namespace std;

int main(void){
    int N,K,l;
    vector<int> ls;
    cin>>N>>K;
    for(int i = 0; i < N; i++){
        cin>>l;
        ls.push_back(l);
    }
    sort(ls.begin(),ls.end(),greater<int>()); //降順ソート
    int sum=0;
    for(int i = 0; i < K; i++){
        sum+=ls[i];
    }
    cout<<sum<<endl;
    return 0;
}

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

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    int same = 0;
    rep(i, N - 1) {
        if(S[i] == S[i + 1]) {
            same++;
        }
    }
    cout << min(same + K * 2, N - 1) << endl;

    return 0;
}


Measured memory_bytes: 512
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	V a(n);
	SCAN(a);
	std::sort(ALL(a));
	std::reverse(ALL(a));

	int mid = n-1;
	for(int i=n-1; i>0; i--) if(a[i]<=0) mid = i;
	
	ll ans = 0;
	REP(i, 0, n){
		if(i<mid) ans += a[i];
		else ans -= a[i];
	}
	printf("%ld\n", ans);

	ll cnt = a[mid];
	for(int i=mid-1; i>0; i--){
		printf("%ld %ld\n", cnt, a[i]);
		cnt -= a[i];
	}
	printf("%ld %ld\n", a[0], cnt);
	cnt = a[0] - cnt;

	for(int i=mid+1; i<n; i++){
		printf("%ld %ld\n", cnt, a[i]);
		cnt -= a[i];
	}
	return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int k;
  cin>>k;
  string s;
  cin>>s;cerr<<s;
  if(k>=s.size())cout<<s<<endl;
  else
  {
    rep(i,k)cout<<s[i];
    cout<<"..."<<endl;
  }
}

Measured memory_bytes: 3624
import os
import sys

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()

LMR = np.zeros(N * 3, dtype=str)
counts = np.zeros(N, dtype=int)
rgb = {'R': 0, 'G': 0, 'B': 0}
for i, c in enumerate(S):
    LMR[i] = 'LMR'[counts[rgb[c]]]
    counts[rgb[c]] += 1
    rgb[c] += 1

# 解説AC
LC = (LMR == 'L').cumsum()
RC = (LMR == 'R')[::-1].cumsum()[::-1]
ans = 1
for i, mi in enumerate(np.where(LMR == 'M')[0]):
    ans *= (LC[mi] - i) * (RC[mi] - (N - i - 1))
    ans %= MOD
for i in range(1, N + 1):
    ans *= i
    ans %= MOD
print(ans)


Measured memory_bytes: 22024
//*Here I go out to sea again
//*The sunshine fills my hair
//*And dreams hang in the air

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

#define ll long long
#define mp make_pair
#define pb push_back
void input(){freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
   int c = 0;
   for (int i = 1; i < n; i++) {
       c+=n/i;
       if(n%i==0) {
           c--;
       }
   }
   cout<<c<<"\n";

    return 0;
}


Measured memory_bytes: 3624
n, m = map(int, input().split())

if n==1 and m==1:
    print(1)
    
elif n==1 and m!=1:
    print(max(n,m)-2)
    
elif n!=1 and m==1:
    print(max(n,m)-2)
    
else:
    print((n-2)*(m-2))

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	sort(d.begin(),d.end());
	int ans =  d[n/2] - d[n/2-1];
	cout << ans << endl;
    return 0;
}



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

#define int long long
const int N = 1e6 + 10 ;
int val[N] ;
int32_t main(){
	for(int i = 1 ; i < N ; i++){
		for(int j = i ; j < N ; j += i){
			val[j]++ ;
		}
	}
	int n;
	cin >> n ;
	int sum = 0 ;
	for(int i = 0 ; i < n ; i++) sum += val[i] ;
	cout << sum ;
	return 0 ;
}



Measured memory_bytes: 11444
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;
vp a;


int main(){
	cin>>n;
	a=vp(n);
	vi ans(n*n,-1);
	for(int i=0;i<n;i++){
		cin>>a[i].first;
		a[i].second=i;
		ans[a[i].first-1]=i+1;
	}
	sort(a.begin(),a.end());
	int I=0;
	for(int i=0;i<n;i++){
		int f=a[i].first-1,s=a[i].second+1;
		int num=s-1;
		while(num){
			if(I>f){
				cout<<"No"<<endl;
				return 0;
			}
			if(ans[I]!=-1){
				I++;
				continue;
			}
			ans[I]=s;
			num--;
		}
	}
	I=n*n-1;
	for(int i=n-1;i>=0;i--){
		int f=a[i].first-1,s=a[i].second+1;
		int num=n-s;
		while(num){
			if(I<f){
				cout<<"No"<<endl;
				return 0;
			}
			if(ans[I]!=-1){
				I--;
				continue;
			}
			ans[I]=s;
			num--;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<n*n;i++){
		if(i) cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
//コンビネーションを10^9+7で割った余りを求める
const int MOD=1000000007;
const int MAX = 1000000;
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;
}
int main(){
    int n,k;
    cin >>n >> k;
    vector<int64_t> a(n);
    rep(i,n){
        cin>>a[i];
    }
    COMinit();
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    all(a);
    int64_t maxx=0,minx=0;
    for(int i=k-1;i<n;i++){
        maxx += (a[i]%MOD*COM(i,k-1))%MOD;
        maxx %= MOD;
    }
    for(int i=n-k;i>=0;i--){
        minx += (a[i]%MOD*COM(n-i-1,k-1))%MOD;
        minx %= MOD;
    }
    if((maxx-minx)%MOD>=0){
        cout <<(maxx-minx)%MOD<<endl;
    }
    else{
        cout<<(maxx-minx)%MOD+MOD<<endl;
    }
}

Measured memory_bytes: 24448
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define MAX 101
#define MAX_V 15
#define mset(a,x) memset(a,x,sizeof(a))

int main() {
	int l = 0, r = 0;
	string s;
	cin >> s;
	for (l = 0; l < s.length(); l++) {
		if (s[l] == 'A') break;
	}
	for (r = s.length() - 1; r >= 0; r--) {
		if (s[r] == 'Z') break;
	}
	cout << r - l + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end(), greater<int>());
    int sum = accumulate(L.begin() + 1, L.end(), 0);
    if (sum > L[0])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int M{200001};
unordered_map<int,int> m;
char s[M];
int b,i,dp[M];
inline int h(int a){
    auto p=m.find(a);
    return p!=m.end()?p->second:M;
}
int main(){
    scanf("%s",s);
    fill_n(dp,M,M);
    m.reserve(M*26);
    for(dp[0]=m[0]=0;s[i];++i){
        b^=1<<(s[i]-'a');
        dp[i+1]=min(dp[i+1],h(b)+1);
        for(int j{};j<26;++j)
            dp[i+1]=min(dp[i+1],h(b^(1<<j))+1);
        if(h(b)>dp[i+1])m[b]=dp[i+1];
    }
    printf("%d\n",dp[i]);
}


Measured memory_bytes: 50560
#include <stdio.h>
#include <string.h>
char a[123], b[123];
int main(){
	int sa, sb, cor, res;
	scanf(" %s %s", a, b);
	sa = strlen(a);
	sb = strlen(b);
	if(sa != sb){
		res = sa - sb;
		/*if(sa > sb){
			cor = sa - sb;
			for(int i = sb-1; i >= 0; --i){
				b[i+cor] = b[i];
			}for(int i = 0; i < cor; ++i) b[i] = '0';
		}else{
			cor = sb - sa;
			for(int i = sa-1; i >= 0; --i){
				a[i+cor] = a[i];
			}for(int i = 0; i < cor; ++i) a[i] = '0';
		}*/
	}else{
		res = strcmp(a, b);
	}
	if(res){
		if(res>0){
			printf("GREATER");
		}else{
			printf("LESS");
		}
	}else{
		printf("EQUAL");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
ma = -float('inf')
mi = float('inf')
for x,y in xy:
  ma = max(ma,x-y)
  mi = min(mi,x-y)
ans = ma - mi

ma = -float('inf')
mi = float('inf')
for x,y in xy:
  ma = max(ma,x+y)
  mi = min(mi,x+y)
  
ans = max(ans, ma - mi)
print(ans)

Measured memory_bytes: 106976
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;

signed main(){
    int n,m;
    cin>>n>>m;
    vector<P> w(n);
    for(int i=0;i<n;i++){
        cin>>w[i].first>>w[i].second;
    }
    sort(w.begin(),w.end());
    int ans=0;
    int p=0;
    prique s;
    for(int i=1;i<=m;i++){
        while(w[p].first<=i&&p<n){
            s.push(w[p].second);
            p++;
        }
        if(!s.empty()){
            ans+=s.top();
            s.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2936
import copy

def main():
    string = input()
    str_list = list(string)
    if str_list[0] == "A":
        cnt = 0
        index = 0
        for i in range(2, len(str_list)-1):
            if str_list[i] == "C":
                cnt += 1
                index = i
        if cnt == 1:
            str_list[0] = "a"
            str_list[index] = "c"
            str_changed = "".join(str_list)
            if str_changed.islower():
                print("AC")
            else:
                print("WA")
        else:
            print("WA")

    else:
        print("WA")


if __name__ == "__main__":
    main()

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

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

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

    int tmp, cnt=0; 

    tmp=A.at(0);
    while(true){
        cnt++;

        if(tmp==2){
            break;
        }
        if(cnt==N){
            cnt = -1;
            break;
        }

        tmp = A.at(tmp-1);
    }

    cout << cnt << endl;

}




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

int main() {
    int x; cin >> x;
    for (int i=1;;i++) {
        if ((x*i) % 360 == 0) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3580
#include<cstdio>
#include<map>
using namespace std;

const int N_MAX = 200005;

int roadprt[N_MAX];
int roadrank[N_MAX];

int railprt[N_MAX];
int railrank[N_MAX];

int find(int i, int *prt){
    if (prt[i] == i) return i;

    return prt[i] = find(prt[i], prt);
}

void unite(int i, int j, int *prt, int *rank){
    int x = find(i, prt);
    int y = find(j, prt);
    if (x == y) return;

    if (rank[x] > rank[y]) prt[y] = x;
    else prt[x] = y;
    if (rank[x] == rank[y]) rank[y]++;
}

bool same(int i, int j, int *prt){
    return find(i, prt) == find(j, prt);
}

int main(){
    int n, k, l;
    scanf("%d %d %d", &n, &k, &l);


    for(int i = 1; i <= n; i++){
        roadprt[i] = i;
        roadrank[i] = 0;
        railprt[i] = i;
        railrank[i] = 0;
    }

    for(int i = 0; i < k; i++){
        int p, q;
        scanf("%d %d", &p, &q);
        unite(p, q, roadprt, roadrank);
    }
    for(int i = 0; i < l; i++){
        int r, s;
        scanf("%d %d", &r, &s);
        unite(r, s, railprt, railrank);
    }

    map<pair<int, int>, int> con;
    int connum[N_MAX];
    for(int i = 1; i <= n; i++){
        int s = find(i, roadprt);
        int t = find(i, railprt);
        map<pair<int, int>, int>::iterator it = con.find(make_pair(s, t));
        if (it == con.end()) con.insert(make_pair(make_pair(s, t), 1));
        else it->second++;
    }
    for(int i = 1; i <= n; i++){
        int s = find(i, roadprt);
        int t = find(i, railprt);
        map<pair<int, int>, int>::iterator it = con.find(make_pair(s, t));
        int ans = it->second;
        printf("%d", ans);
        if (i < n) printf(" ");
        else printf("\n");
    }
    return 0;
}

Measured memory_bytes: 15104
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

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

int main(){
    int n;
    int a[100005]={};
    scanf("%d",&n);
    REP(i,n)scanf("%d",&a[i]);
    sort(a,a+n);
    int pl=0;
    int mi=0;
    int zero=0;
    REP(i,n){
        if(a[i]>0)pl++;
        else if(a[i]==0)zero++;
        else mi++;
    }
    long long int ans=a[n-1];
    REP(i,n-1){
        if(i==0)ans-=a[0];
        else{
            if(a[i]>=0)ans+=a[i];
            else ans-=a[i];
        }
    }
    printf("%lld\n",ans);
    int max=a[n-1];
    int min=a[0];
    for(int i=1;i<n-1;i++){
        if(a[i]<=0){
            printf("%d %d\n",max,a[i]);
            max-=a[i];
        }
    }
    for(int i=1;i<n-1;i++){
        if(a[i]>0){
            printf("%d %d\n",min,a[i]);
            min-=a[i];
        }
    }
    printf("%d %d\n",max,min);
    return 0;
}

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

const int maxn = 2e5+10;
typedef long long ll;

ll k, a, b;
ll solve()
{

  if (a >= k)
    return 1;
  else if (a <= b)
    {
      return -1ll;
    }
  else
    {
      ll dif = a-b;;
      k -= a;
      return 1ll+2*((k+dif-1)/dif);
    }
}
int main()
{
  scanf("%lld %lld %lld", &k, &a, &b);
  printf("%lld\n", solve());
}


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 _GLIBCXX_DEBUG

using _loop_ll = long long;
#define REP(i,n) for(_loop_ll (i)=0; (i)<(_loop_ll)(n); (i)++)
#define FOR(i,a,b) for(_loop_ll (i)=(_loop_ll)(a); (i)<(_loop_ll)(b); (i)++)
#define FORR(i,a,b) for(_loop_ll (i)=(_loop_ll)(b)-1; (i)>=(_loop_ll)(a); (i)--)
 
#define ALL(v) (v).begin(),(v).end()
 
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

constexpr long long int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int h, a;
    cin >> h >> a;

    int ans = 0;
    while(h > 0){
        h -= a;
        ans++;
    }
    cout << ans << endl;

    return 0;
};


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int H;

int heap[500001];

void MaxHeapify(int index) {
    int left = index * 2;
    int right = index * 2 + 1;
    int largest;

    if (left <= H && heap[left] > heap[index]) {
        largest = left;
    } else {
        largest = index;
    }

    if (right <= H && heap[right] > heap[largest]) {
        largest = right;
    }

    if (index != largest) {
        swap(heap[index], heap[largest]);
        MaxHeapify(largest);
    }
}

int main() {

    cin >> H;
    for (int i = 1; i <= H; ++i) {
        int x;
        cin >> x;
        heap[i] = x;
    }

    for (int i = H / 2; i >= 1; --i) {
        MaxHeapify(i);
    }

    for (int i = 1; i <= H; ++i) {
        cout << " " << heap[i];
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 5012
from collections import Counter
def solve():
  ans = 0
  N = int(input())
  V = list(map(int, input().split()))
  V1 = [V[i] for i in range(0,N,2)]
  V2 = [V[i] for i in range(1,N,2)]
  v1 = Counter(V1)
  v2 = Counter(V2)
  v1 = sorted(v1.items(),key=lambda x:-x[1])
  v2 = sorted(v2.items(),key=lambda x:-x[1])
  if v1[0][0]!=v2[0][0]:
    ans = N-(v1[0][1]+v2[0][1])
  else:
    if len(v1)==1:
      if len(v2)==1:
        return N//2
      return N-(v1[0][1]+v2[1][1])
    if len(v2)==1:
      return N-(v1[1][1]+v2[0][1])
    ans = N-max(v1[1][1]+v2[0][1],v1[0][1]+v2[1][1])
  return ans
print(solve())

Measured memory_bytes: 25256
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    from decimal import Decimal
    a,b = map(Decimal,input().split())
    print(int(a*b))
    # print(int(a*(b*10**2))//10**2)
    # print(int(a),int(b*10**2))
    # print(int(a)*int(b*10**2)//10**2)
    
main()
#999999999999999 9.99

Measured memory_bytes: 71284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

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

    int tt = 1;
    FOR (t, 1, tt + 1) {
	// cout << "Case #" << t << ": ";
	solve();
    }

    return 0;
}


Measured memory_bytes: 3652
{-# LANGUAGE TupleSections #-}
import Data.List
main = do
  n <- readLn
  let edges = g $ f n
  print $ length edges
  mapM_ printT edges

f :: Int -> [[Int]]
f x
  | odd x     = [x] : f (x-1)
  | otherwise = zipWith (\a b -> [a,b]) [1..x `div` 2] [x,x-1..]

g :: [[Int]] -> [(Int, Int)]
g [] = []
g (x:xs) = ((,) <$> x <*> concat xs) ++ g xs

printT (a,b) = putStrLn $ show a ++ " " ++ show b

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long X;
    cin>>X;
    int ans=0;
    long long tmp=100;
    while(tmp<X){
        ans++;
        tmp=floor(tmp*1.01);
        // cout << tmp<<endl;
    }
    
    cout << ans<<endl;
    return 0;
}

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

using namespace std;
int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int total = 0;
  for (int i = 1; i <= n; i++) {
    if (i <= k)
      total += x;
    else
      total += y;
  }
  cout << total << endl;

  return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
u,d,r,l=h,0,w,0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1 and x>l: l=x
    if a==2 and x<r: r=x
    if a==3 and y>d: d=y
    if a==4 and y<u: u=y
if u>d and r>l: print((u-d)*(r-l))
else: print(0)

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

int main(){
  int num;
  int work;


  while(true){
    cin >> num;

    if(num == 0) break;
    
    for(int i = 0; i<9; ++i){
      cin >> work;

      num -= work;
    }
    cout << num << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3096
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n; cin>>n;
    vector<vector<ll>>a(n,vector<ll>(26));
    vector<string>s(n);
    rep(i,n){
        cin>>s[i];
        rep(j,s[i].size()){
            int x='z'-s[i][j];
            x=26-x;
            x--;
            a[i][x]++;
        }
    }
    char c='`';
    rep(i,26){
        ll mn=1000;
        c++;
        rep(j,n){
            mn=min(mn,a[j][i]);
        }
        rep(k,mn)cout<<c;
    }
    cout<<endl;

}








































Measured memory_bytes: 3560
/*
Author:loceaner
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 5e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
	char c = getchar(); int x = 0, f = 1;
	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return x * f;
}

int h, w, k, ans;
char q[7][7];
bool chose[13], H[10], L[10];

void count() {
	int tot = 0;
	memset(H, 0, sizeof H);
	memset(L, 0, sizeof L);
	for (int i = 1; i <= h; ++i)
		if (chose[i] == 1) H[i] = 1;
	for (int i = h + 1; i <= h + w; ++i)
		if (chose[i] == 1) L[i - h] = 1;
	for (int i = 1; i <= h; ++i) {
		if (H[i] == 1) continue;
		for (int j = 1; j <= w; ++j) {
			if(L[j] == 1) continue;
			if(q[i][j] == '#') ++tot;
		}
	}
	if (tot == k) ++ans;
}

void dfs(int step) {
	if (step == h + w + 1) return count();
	for (int i = 0; i <= 1; ++i) {
		if (i == 0) dfs(step + 1);
		else {
			chose[step] = 1;
			dfs(step + 1);
			chose[step] = 0;
		}
	}
}

int main() {
	h = read(), w = read(), k = read();
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) cin >>q[i][j];
	dfs(1);
	cout << ans << '\n';
	return 0;
}


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

#define _STLR(___stl_cl_) std::begin(___stl_cl_), std::end(___stl_cl_)

int solve(const std::vector<int> &original)
{
	size_t size = original.size();
	std::vector<char> flag_array(size);
	std::fill(_STLR(flag_array), -1);
	int answer = 0;
	
	do
	{
		int sum_mul = 1;
		for (int i = 0; i < size; ++i)
		{
			sum_mul *= (flag_array[i] + original[i]);
		}
		if (!(sum_mul & 1))
		{
			/*
			* 偶数
			*/
			
			++answer;
		}

		if (flag_array[0] < 1)
		{
			++flag_array[0];
		}
		else
		{
			for (int i = 1; i < size; ++i)
			{
				if (flag_array[i] < 1)
				{
					for (int n = 0; n < i; ++n)
					{
						flag_array[n] = -1;
					}
					++flag_array[i];
					break;
				}
			}
		}
		
	} while (std::count(_STLR(flag_array), 1) != size);

	int sum_mul = 1;

	for (int i = 0; i < size; ++i)
	{
		 sum_mul *= (1 + original[i]);
	}
	if (!(sum_mul & 1))
	{
		++answer;
	}

	return answer;

}

int main()
{
	int array_size, value;
	std::cin >> array_size;
	std::vector<int> original_array;

	while (array_size--)
	{
		std::cin >> value;
		original_array.push_back(value);
	}

	std::cout << solve(original_array) << std::endl;

	return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = (int) s.length();
	long long curr = 0, c = 0;
	for(int i=0;i<n;i++)
	{
		if(s[i] == 'B')
		{
			curr++;
		}
		else
			c+= curr;
	}
	cout << c << "\n";
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int poi[7][5];
int l[5]={100,200,300,400,500};
int ka[7]={0,30,60,90,120,150,180};
int main(){
  int f=0;//1 == // 2 <
  int ff=0;
  int r,k;
  //mk map
  for(int i=0;i<7;i++){
    for(int j=0;j<5;j++){
      poi[i][j]=i*5+j+1;
      // cout << poi[i][j];
    }
  }
  //in
  int n;
  cin >> n;
  for(int m=0;m<n;m++){

    cin >> r >> k;
    //cout<<1;//find len

    int p1=0,p2=0;
    for(int i=0;i<5;i++){
      if(r<=l[i]){
	p1=i;
	f=1;
	if(r<l[i]){
	  p2=i-1;
	  f=2;
	}
	break;
      }
    }
    // cout <<2;//find kaku

    int k1,k2=0;
    for(int j=0;j<7;j++){
      if(k<=ka[j]){
	k1=j;
	ff=1;
	if(k<ka[j]){
	  k2=j-1;
	  ff=2;
	}
	break;
      }
    }
    //find poi
    int ans[4];
    int c=0;
    c=f*ff;
    for(int i=0;i<c;i++){
      if(i==0)ans[0]=poi[k1][p1];
      if(i==1){
	if(ff==1)ans[1]=poi[k1][p2];
	else ans[1]=poi[k2][p1];
      }
      if(i==2)ans[2]=poi[k1][p2];
      else ans[3]=poi[k2][p2];
    }
    //out ans
    sort(ans,ans+c);
    for(int i=0;i<c;i++){
      cout << ans[i];
      if(i+1!=c)cout << " ";
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int X = A * 60 + B, Y = C * 60 + D;
  cout << Y - X - E << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long i=0; i<n; ++i) { cout<<a[i]; if(i!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> vl;
typedef vector<vector<long long> > vll;
typedef vector<P> vp;
typedef vector<vector<P> > vpp;

vector<vector<ll> > WarshallFloyd(vector<vector<P> >& adj) {
	int n=(int)adj.size();
	vector<vector<vector<ll> > > dp(n+1, vector<vector<ll> >(n, vector<ll>(n, INF*INF)));
	for(int i=0; i<n; ++i) dp[0][i][i]=0;
	for(int i=0; i<n; ++i) {
		for(int j=0; j<adj[i].size(); ++j) {
			dp[0][i][adj[i][j].first]=adj[i][j].second;
		}
	}

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

int main() {
	ios::sync_with_stdio(false);
	int N,M,R;
	cin>>N>>M>>R;
	vector<int> r(R);
	REP(i,R) cin>>r[i];
	REP(i,R) --r[i];
	vector<int> perm(R);
	REP(i,R) perm[i]=(int)i;
	vector<vector<P> > adj(N);
	REP(i,M) {
		int a,b,c;
		cin>>a>>b>>c;
		--a;
		--b;
		adj[a].pb(P(b,c));
		adj[b].pb(P(a,c));
	}
	vector<vector<ll> > wf=WarshallFloyd(adj);
	ll res=INF*INF;
	do {
		bool d=true;
		ll buf=0;
		FOR(i,1,R) {
			if(wf[r[perm[i]]][r[perm[i-1]]]!=INF*INF) {
				buf+=wf[r[perm[i]]][r[perm[i-1]]];
			} else {
				d=false;
				break;
			}
		}
		if(d) res=min(res,buf);
	} while(next_permutation(ALL(perm)));
	cout<<res<<endl;
}


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

const int K = 20;
int n, q, l;
int x[100000];
int d[K][100000];
void pre() {
  int j = 0;
  for (int i = 0; i < n; ++i) {
    while (j < n && x[j] - x[i] <= l) {
      ++j;
    }
    d[0][i] = j - 1;
  }
  
  for (int k = 1; k < K; ++k) {
    for (int i = 0; i < n; ++i) {
      d[k][i] = d[k - 1][d[k - 1][i]];
    }
  }
}

int sub(int a, int b) {
  int cnt = 0;
  int i = a;
  for (int k = K - 1; k >= 0; --k) {
    int ni = d[k][i];
    if (ni < b) {
      cnt += 1 << k;
      i = ni;
    }
  }
  return cnt + 1;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> x[i];
  cin >> l >> q;
  pre();
  
  for (int j = 0; j < q; ++j) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    if (a > b) swap(a, b);
    cout << sub(a, b) << endl;
  }
}

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

using namespace std;

int H, W;
char mp[101][101];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int visited[101][101] = {false};

void dfs(int x, int y, char f)
{
    visited[y][x] = true;

    for (int i = 0; i < 4; i++)
    {
        int mx = x + dx[i];
        int my = y + dy[i];

        if (mx < 0 || my < 0 || H <= my || W <= mx || f != mp[my][mx])
            continue;
        
        if (visited[my][mx])  
            continue;

        dfs(mx, my, f);
    }

    return;
}

int main()
{
    while (cin >> H >> W, H || W)
    {
        for (int y = 0; y < H; y++)
        {
            for (int x = 0; x < W; x++)
            {
                cin >> mp[y][x];
                visited[y][x] = false;
            }
        }

        int N = 0;





        for (int y = 0; y < H; y++)
        {
            for (int x = 0; x < W; x++)
            {
                if (!visited[y][x])
                {
                    N++;
                    dfs(x, y, mp[y][x]);
                }
            }
        }

        cout << N << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
inline void readLong(ll &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
/*================Header Template==============*/
multiset<int> s;
int n,x;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>x;
		s.insert(x);
	}
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>x;
		multiset<int>::iterator it=s.find(x);
		if(it==s.end()) {
			puts("NO");
			return 0;
		}
		s.erase(it);
	}
	puts("YES");
	return 0;
} 

Measured memory_bytes: 9600
#include<stdio.h>
 
typedef struct T{
    int id;
    int d;
    int h;

     struct T *p;
    struct T *c[2];
  
}t;
 
t tree[100];

int Node(t *n, int d);
 

 
int main(){
    int n, id, id2, i, j;
    t *root = NULL;
    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        tree[i].id = -1;
        tree[i].p = NULL;
        tree[i].c[0] = NULL;
        tree[i].c[1] = NULL;
        tree[i].d = -1;
        tree[i].h = -1;
    }
    for( i = 0; i < n; i++ ){
        scanf("%d", &id);
        tree[id].id = id;
        scanf("%d", &id2);
        if( 0 <= id2 && id2 < n ){
            tree[id].c[0] = &tree[id2];
            tree[id2].p = &tree[id];
        }
        scanf("%d", &id2);
        if( 0 <= id2 && id2 < n ){
            tree[id].c[1] = &tree[id2];
            tree[id2].p = &tree[id];
        }
    }
    for( i = 0; i < n; i++ ){
        if( tree[i].p == NULL ){
            root = &tree[i];
            break;
        }
    }
    Node(root, 0);
    for( i = 0; i < n; i++ ){

       char *nodetype[3] = {"root", "internal node", "leaf"};
    int pid, sibling = -1, degree = 0, ni;
    if( tree[i].c[0] != NULL ){ degree++; }
    if( tree[i].c[1] != NULL ){ degree++; }
    if( tree[i].p != NULL ){
        if( tree[i].p->c[0] != NULL && tree[i].p->c[0]->id != tree[i].id ){
            sibling = tree[i].p->c[0]->id;
        }else if( tree[i].p->c[1] != NULL && tree[i].p->c[1]->id != tree[i].id ){
            sibling = tree[i].p->c[1]->id;
        }
        if( degree == 0 ){
            ni = 2;
        }else{
            ni = 1;
        }
        pid = tree[i].p->id;
    }else{
        ni = 0;
        pid = -1;
    }
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
        tree[i].id, pid, sibling, degree, tree[i].d, tree[i].h, nodetype[ni]
    );

    }
    return 0;
}



int Node(t *n, int d){
    if( n == NULL ){ return -1; }
    n->d = d;
    int lh = Node(n->c[0], d+1);
    int rh = Node(n->c[1], d+1);
    n->h = (lh>rh?lh:rh) + 1;
    return n->h;
}



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

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

    long long int ans = 0;
    for(int i=1; i<=n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588