akhauriyash/Code-Regression huggingface dataset:
// C - Train Ticket
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(const string &S){
	int a=S[0]-'0', b=S[1]-'0', c=S[2]-'0', d=S[3]-'0';
	char op1,op2,op3;
	rp(i, 0, 2){
		rp(j, 0, 2){
			rp(k, 0, 2){
				int x = a;
				x += i? -b: b;
				x += j? -c: c;
				x += k? -d: d;
				if(x == 7){
					cout<<a<< (i? '-': '+') <<b<< (j? '-': '+')
						<<c<< (k? '-': '+') <<d<<"=7"<<endl;
					return;
				}
			}
		}
	}
}

int main(){
	string S; cin>>S;
	solve(S);
}

Measured memory_bytes: 256
/*
[abc123] C - Five Transportations
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const ll INF = 1e18;

ll N;
ll A[5];

ll solve() {
    ll d = *min_element(A, A + 5);
    return ((N + d - 1) / d + 5 - 1);
}

int main() {
    cin >> N;
    for (int i = 0; i < 5; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]

D = A - B

L = -1
R = 10 ** 9

while L + 1 < R:
  M = (L + R) // 2
  
  cnt = 0
  for h in H:
    rest = h - M * B
    if rest > 0:
      cnt += - (- rest // D)
  if M >= cnt:
    R = M
  else:
    L = M
print(R)

Measured memory_bytes: 50520
#include<cstdio>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
int a,b,c,d;
map<ll,ll> mp;
ll Dfs(ll x){
	//printf("Dfs %lld\n",x);
	if(!x) return 0;
	if(mp.count(x)) return mp[x];
	ll res=1ll<<60,w;
	if((double)d*x<res) res=d*x;
	w=x/2;
	if(w<x) res=min(res,Dfs(w)+abs(w*2-x)*d+a);
	w=x/2+1;
	if(w<x) res=min(res,Dfs(w)+abs(w*2-x)*d+a);
	w=x/3;
	if(w<x) res=min(res,Dfs(w)+abs(w*3-x)*d+b);
	w=x/3+1;
	if(w<x) res=min(res,Dfs(w)+abs(w*3-x)*d+b);
	w=x/5;
	if(w<x) res=min(res,Dfs(w)+abs(w*5-x)*d+c);
	w=x/5+1;
	if(w<x) res=min(res,Dfs(w)+abs(w*5-x)*d+c);
	return mp[x]=res;
}
int main(){
	int _;
	scanf("%d",&_);
	while(_--){
		scanf("%lld%d%d%d%d",&n,&a,&b,&c,&d);
		printf("%lld\n",Dfs(n));
		mp.clear();
	}
	return 0;
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ii pair<int ,int >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int dp[(int)(1e5+1)][3];
int main(){
	IOS
 	
 	int n;
 	cin>>n;

 	vi av(n);
 	vi bv(n);
 	vi cv(n);

 	int a,b,c;
 	for(int i=0;i<n;i++)
 	{
 		cin>>a>>b>>c;
 		av[i]=a;
 		bv[i]=b;
 		cv[i]=c;
 	}

 	dp[1][0] = av[0];
 	dp[1][1] = bv[0];
 	dp[1][2] = cv[0];
 	for(int i=2;i<=n;i++)
 	{
 		dp[i][0] = max(dp[i-1][1]+av[i-1],dp[i-1][2]+av[i-1]);
 		dp[i][1] = max(dp[i-1][0]+bv[i-1],dp[i-1][2]+bv[i-1]);
 		dp[i][2] = max(dp[i-1][0]+cv[i-1],dp[i-1][1]+cv[i-1]);
 	}
 	cout<<max({dp[n][0],dp[n][1],dp[n][2]});



 
	return 0;	
}

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

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> A(N), dp(N, INF);
    rep(i, N) cin >> A[i];

    dp[0] = 0;
    rep(i, N) {
        for (int j = 1; j <= K; j++) {
            if (i + j < N)
                dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i + j]));
        }
    }
    cout << dp[N - 1] << endl;

    return 0;
}

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

int main() {
	string s; cin >> s;
	char before_one, before_two;
	if(s[0] == s[1]) {
		cout << "1 2" << endl;
		return 0;
	}
	else if(s.size() == 2) {
		cout << "-1 -1" << endl;
		return 0;
	}
	else {
		before_one = s[1], before_two = s[0];
		for (int i = 2; i < s.size(); i++)
		{
			if(s[i] == before_two) {
				cout << i-1 << " " << i+1 << endl;
				return 0;
			}
			else if(s[i] == before_one) {
				cout << i << " " << i+1 << endl;
				return 0;
			}
			else {
				before_two = before_one;
				before_one = s[i];
			}
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
	public static void main (String[] args){ 
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
      	String T = sc.next();
      	if(T.length() == S.length()+1 && T.indexOf(S) == 0){
          System.out.println("Yes");
        }
        else{
        System.out.println("No");
        }
    }
}

Measured memory_bytes: 26964
M,K=map(int,input().split())
if K>=2**M:
  print("-1")
elif M==1 and K==0:
  print("0 0 1 1")
elif M==1 and K==1:
  print("-1")
else:
  print(K)
  for i in range(K):
    print(i)
  for i in range(K+1,2**M):
    print(i)
  print(K)
  for i in range(2**M-1,K,-1):
    print(i)
  for i in range(K-1,-1,-1):
    print(i)
  


Measured memory_bytes: 4944
def gcm(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
    if x==y:
        return x
    if x>y:
        return gcm(x%y,y)
    else:
        return gcm(y%x,x)


x, y = list(map(int, input().split()))

print(gcm(x, y))


Measured memory_bytes: 5600
s = str(input())

if "erase" in s:
  s = s.replace("erase", "E")
if "dream" in s:
  s = s.replace("dream", "D")

if "Er" in s:
  s = s.replace("Er", "")
if "Der" in s:
  s = s.replace("Der", "")

if "E" in s:
  s = s.replace("E", "")
if "D" in s:
  s = s.replace("D", "")

if s == "":
  print("YES")
else:
  print("NO")

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

int N[40];

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) break;
    N[0]=1;
    N[1]=1;
    N[2]=2;
    for(int i=3;i<n+1;++i){
      N[i]=N[i-1]+N[i-2]+N[i-3];
    }
    cout <<1 + ( N[n] / 3650 ) << endl;
  }
}

Measured memory_bytes: 1160
N,M=map(int,input().split())
A=list(map(int,input().split()))

S=0
for i in range(N):
    S+=A[i]

G=S/(4*M)

T=0
for j in range(N):
    if A[j]>=G:
        T+=1

if M<=T:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
if(N == 1):
    print(1)
    exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
    if(cur == A[i]): continue
    if(flag == -1):
        if(A[i] > cur): flag = 1
        elif(A[i] < cur): flag = 0
    elif(flag == 1 and A[i] < cur):
        flag = -1
        ans += 1
    elif(flag == 0 and A[i] > cur):
        flag = -1
        ans += 1
    cur = A[i]
print(ans)


Measured memory_bytes: 14436
#include <stdio.h>
int main(void)
{
    int i, n;
    char t[4];
    int c[4];
    for (i=0; i<4; ++i) c[i]=0;
    while (scanf("%d,%s", &n, t) != EOF) {
        switch (t[0]) {
            case 'A': if (t[1]=='B') c[2]++; else c[0]++; break;
            case 'B': c[1]++; break;
            case 'O': c[3]++; break;
        }
    }
    for (i=0; i<4; ++i) printf("%d\n", c[i]);
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int n;
           string s;
           cin>>n>>s;
           int ans=0,x=0;
           for(int i=0;i<n;i++){
               if(s[i]=='I')x++;
               else x--;
               ans=max(ans,x);
           }
           cout<<ans;

        }


Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Shine Like a Sun , Burn like a Sun 

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
signed main()
{
    fast;
   
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9) cout<<a*b;
    else cout<<"-1";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;


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

    int a[n][3], dp[n][3];

    for(int i=0; i<n; i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        dp[i][0] = a[i][0];
        dp[i][1] = a[i][1];
        dp[i][2] = a[i][2];
    }

    for(int i=1; i<n; i++){
        dp[i][0]+= max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]+= max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]+= max(dp[i-1][1], dp[i-1][0]);
    }

    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    set<char> st;
    REP(i,s.size()){
        st.insert(s[i]);
    }
    if(st.size()==s.size())
        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
 
    vector<int> ws(n), bs(n);
    for(int i=0, w=0, b=0; i<n; i++){
        if(s[i] == '#')
            b++;
        else // '.'
            w++;
        ws[i] = w;
        bs[i] = b;
    }

    int wa = ws[n-1], min_cost = wa;
    for(int i=0, cost; i<n; i++){
        cost = bs[i] + wa - ws[i];
        if(cost < min_cost)
            min_cost = cost;
    }
 
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x) cout << "Yes";
	else cout << "No";
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    
    W += 2;
    
    for (int j = 0; j < W; j++) {
        cout << "#";
    }
    
    cout << endl;
    for (int i = 0; i < H; i++) {
        cin >> a.at(i);
        cout << "#" << a.at(i) << "#" << endl;
    }
    
    for (int k = 0; k < W; k++) {
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

sys.setrecursionlimit(100005)

n, k = na()
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)


def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    return p+mod if p < 0 else p


# res
def dfs(cur, pre, k, g):
    mod = 1000000007
    ret = 1
    nc = 0 if pre == -1 else 1
    for e in g[cur]:
        if e == pre: continue
        nc += 1
        ret = ret * (k-nc) % mod
        ret = ret * dfs(e, cur, k, g) % mod
    return ret % mod


print(dfs(0, -1, k, g) * k % 1000000007)



Measured memory_bytes: 92924
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = (int)1e9 + 7;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif

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

    int n, k; cin >> n >> k;
    vi a(n); for (int i = 0; i < n; ++i) cin >> a[i];
    vi psa(n);
    psa[0] = a[0];
    for (int i = 1; i < n; ++i) psa[i] = psa[i-1] + a[i];

    vi dp(k+1, 0);
    vi ps(k+1, 0);
    for (int j = 0; j <= a[0]; ++j) dp[j] = 1;
    ps[0] = dp[0];
    for (int j = 1; j <= k; ++j) ps[j] = (ps[j-1] + dp[j]) % MOD;

    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= min(k, psa[i]); ++j) {
            dp[j] = ps[j];
            if (j - a[i] - 1 >= 0) dp[j] = (dp[j] - ps[j - a[i] - 1] + MOD) % MOD;
        }
        ps[0] = dp[0];
        for (int j = 1; j <= k; ++j) ps[j] = (ps[j-1] + dp[j]) % MOD;
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fi first
#define se second
#define fr front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int 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() {
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
using namespace std;
signed main(){
	int n;
	string s,lr;
	cin>>n>>s;
	if(s[0]=='W' || s[2*n-1]=='W'){
		cout<<0<<endl;
		return 0;
	}
	int cnt=0;
	lr.pb('R');
	for(int i=1;i<2*n;i++){
		if(s[i] == s[i-1]){
			lr.pb( 'L'+'R'-lr[i-1]);
		}
		else{
			lr.pb(lr[i-1]);
		}
	}
	//cout<<lr<<endl;
	if(lr[2*n-1]!='L'){
		cout<<0<<endl;
		return 0;
	}
	int lc=0,rc=0;
	for(int i=0;i<2*n;i++){
		if(lr[i]=='L')lc++;
		else rc++;
	}
	if(lc!=rc){
		cout<<0<<endl;
		return 0;
	}
	ll ans = 1;
	ll lcnt = 0;
	for(int i=0;i<2*n;i++){
		if(lr[i]=='R')lcnt++;
		else{
			ans *= lcnt;
			ans %= inf;
			lcnt--;
		}
	}
	for(int i=1;i<=n;i++){
		ans *= i;
		ans %= inf;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	string s; cin >> s;
	bool dir[4] = { false };
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'N')dir[0] = true;
		else if (s[i] == 'W')dir[2] = true;
		else if (s[i] == 'S')dir[1] = true;
		else dir[3] = true;
	}

	if (dir[0] != dir[1] || dir[2] != dir[3]) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,x,i,j,k,a,b;

	while(1)
	{
		scanf("%d %d",&n,&x);
		if((n==0)&&(x==0))
		{
			break;
		}
		b=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				for(k=1;k<=n;k++)
				{
					if((i==j)||(j==k)||(k==i))
					{}
					else
					{
						a = i+j+k;
						if(a==x)
						{
							b += 1;
						}
					}
				}
			}
		}
		printf("%d\n",b/6);
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll rows[300005];
ll cols[300005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll r,c,i,j,n,k;
    cin>>r>>c>>n;
    map<pair<ll,ll>,ll>mat;
    while(n--)
    {
        cin>>i>>j;
        rows[i]++;
        cols[j]++;
        mat[{i,j}]++;
    }
    ll ans=0;
    map<ll,vector<ll>>row_max,col_max;
    for(i=1;i<=r;i++)
    {
        row_max[rows[i]].push_back(i);
    }
    for(i=1;i<=c;i++)
    {
        col_max[cols[i]].push_back(i);
    }
    auto it1=row_max.rbegin();
    vector<ll>g1=it1->second;
    auto it2=col_max.rbegin();
    vector<ll>g2=it2->second;
    for(auto a:g1)
    {
        for(auto b:g2)
        {
            if(mat[{a,b}] >= 1)
            {
                ans=max(ans,rows[a]+cols[b]-1);
            }
            else
            {
                cout<<rows[a]+cols[b];
                return 0;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 36000
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
vll div(ll N)
{
    vll yakusuu;
    for (ll i = 1; i * i <= N; i++)
    {
        if (N % i == 0)
        {
            yakusuu.push_back(i);
            if (i * i != N)
                yakusuu.push_back(N / i);
        }
    }
    return yakusuu;
}
int main()
{
    int N, K;
    cin >> N >> K;
    vint A(N);
    ll sum = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    auto divs = div(sum);
    sort(all(divs), greater<ll>());
    for (auto &&i : divs)
    {
        auto tmp = A;
        int num = 0;
        for (size_t j = 0; j < N; j++)
        {
            tmp[j] %= i;
        }
        sort(all(tmp));
        int first = 0, last = N - 1;
        while (first < last)
        {
            int diff = min((ll)tmp[first],i-tmp[last]);
            num += diff;
            tmp[first] -= diff;
            tmp[last] = (tmp[last] + diff)% i;
            if(tmp[first] == 0)
            first++;
            if(tmp[last]==0)
            last--;
        }
        num += min(tmp[first],((int)i-tmp[first]));
        if (num <= K)
        {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
int main()
{
	string s;
	cin >> s;
	char c[2];

	c[0] = s[0];
	c[1] = 0;

	for (int i = 1; i < s.length(); i++) {
		if (s[i] == c[0] || s[i] == c[1])
			continue;
		if (c[1] == 0) {
			c[1] = s[i];
			continue;
		}
		cout << "No";
		return 0;
	}
	if (c[1] == 0) {
		cout << "No";
		return 0;
	}
	cout << "Yes";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define mod 1000000007
ll n,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> a(n),b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  std::vector<P> v;
  rep(i,n) v.emplace_back(a[i],0);
  rep(i,n) v.emplace_back(b[i],1);
  sort(all(v));
  ll ans = 1;
  ll x = 0 , y = 0;
  rep(i,v.size()){
    if(v[i].se == 0){
      if(y) ans *= y--;
      else x++;
    } else {
      if(x) ans *= x--;
      else y++;
    }
    ans%=mod;
  }
  cout<<ans%mod<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main(){
	long long int a,b,x;
	cin>>a>>b>>x;
	long long int count=0;
	
	long long int k=b/x+1;
	long long int j=(a-1)/x+1;
	
	if(a==0){
		j=0;
		}
		
	count = k-j;
	cout<<count<<endl;
	/*for(int i=b;i>=a;i--){
		count++;
		}
	cout<<count<<endl;*/
	}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	String s = sc.next();
    int n = s.length();
    String c[] = new String[n];

    for(int i=0; i<n; i++) {
      c[i] = s.substring(i, i+1);
    }
    
    for(int i=0; i<n; i++){
      if (i%2 == 1) { //even
        if (c[i].equals("R")) {
          System.out.println("No");
          return;
        }
      } else { //odd
        if (c[i].equals("L")) {
          System.out.println("No");
          return;
        }
      }
    }
    
    System.out.println("Yes");
    
  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string str1,str2;
    cin >> str1 >> str2;
    if(str1.size()>str2.size()){
      string temp = str1;
      str1 = str2;
      str2 = temp;
    }

    int len1 = str1.size(),len2 = str2.size();
    int kuriagari = 0;
    for(int j=1;len2-j>=0;j++){
      if(len1-j>=0){
        int sum = (str2[len2-j]-'0') + (str1[len1-j]-'0') + kuriagari;
        if(sum>=10){
          sum -=10;
          kuriagari = 1;
        }else{
          kuriagari = 0;
        }
        str2[len2-j] = sum+'0';
      }else{
        if(kuriagari){
          int sum = (str2[len2-j]-'0') + kuriagari;
          if(sum>=10){
            sum -=10;
            kuriagari = 1;
          }else{
            break;
          }
          str2[len2-j] = sum+'0';
        }else{
          break;
        }
      }
    }
    if(kuriagari){
      str2 = "1" + str2;
    }
    if(str2.size()>80){
      cout << "overflow" << endl;
    }else{
      cout << str2 << endl;
    }
  }
}

Measured memory_bytes: 1212
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    lst = [sum(A)]
    for j in A:
        lst.append(lst[-1] - j)
    ans = 0
    for index, i in enumerate(A):
        ans += i * lst[index + 1] % mod
    print(ans % mod)


if __name__ == '__main__':
    main()


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

string s;
bool a,b,c;
int main(){
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='a')a=true;
    if(s[i]=='b')b=true;
    if(s[i]=='c')c=true;
  }
  if(a==true && b==true && c==true)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while (true){
        cin >> H >> W;
        if (H == 0 && W == 0){
            break;
        }
        for (int j = 0; j < W; j++){
            cout << '#';
        }
        cout << endl;
        for(int i = 1; i < H-1; i++){
            cout << '#';
            for(int j = 1; j < W-1; j++){
                cout << '.';
            }
            cout << '#' << endl;
        }
        for(int j = 0; j < W; j++){
            cout << '#';
        }
        cout << endl << endl;
    }
}    


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // 入力データの取得
        Scanner scanner = new Scanner(System.in);
        double member = scanner.nextDouble();
        double[] memberCoordinate = new double[(int) member];
        double sumMemberCoordinate = 0;
        for (int index = 0; index < member; index++) {
            memberCoordinate[index] = scanner.nextDouble();
            sumMemberCoordinate += memberCoordinate[index];
        }
        scanner.close();

        // 処理を行う
        // 最適な座標の算出
        double meetingCoordinate = Math.round(sumMemberCoordinate / member);

        // それぞれの消費体力の算出とその合計値の算出
        double totalEnergy = 0;
        for (int index = 0; index < memberCoordinate.length; index++) {
            totalEnergy += Math.pow(memberCoordinate[index] - meetingCoordinate, 2);
        }

        // 結果の出力
        System.out.println((int) totalEnergy);

    }

}

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

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

#define EPS 1e-9

#define bool int
#define false 0
#define true 1

#define max(x,y) x>y?x:y
#define maxch(x,y) x=max(x,y)

//typedef vector<double> vec;
//typedef vector<vec> mat;

void swap(double* a,double* b){
	double tmp=*a;*a=*b;*b=tmp;
}

double X[2];

void gauss_jordan(const double A[2][2],const double b[]){
	int n=2;
	double B[n][n+1];
	int i,j,k;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			B[i][j]=A[i][j];
		}
		B[i][n]=b[i];
	}
	X[0]=X[1]=-114514;
	for(i=0;i<n;i++){
		int piv=0;
		for(j=i;j<n;j++){
			if(fabs(B[j][i])>fabs(B[piv][i]))piv=j;
		}
		rep(j,n+1)swap(&B[i][j],&B[piv][j]);
		if(fabs(B[i][i])<EPS)return;
		for(j=i+1;j<=n;j++)B[i][j]/=B[i][i];
		for(j=0;j<n;j++){
			if(i!=j){
				for(k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
			}
		}
	}
	for(i=0;i<n;i++)X[i]=B[i][n];
	return;
}

int n;
double x[11],y[11],l[11];

bool judge(double xx,double yy,double zz){
	bool ok=true;
	int i;
	rep(i,n){
		if(pow(xx-x[i],2)+pow(yy-y[i],2)+pow(zz,2)-pow(l[i],2)>EPS)ok=false;
	}
	return ok;
}

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int i,j,k;
		rep(i,n)scanf("%lf%lf%lf",x+i,y+i,l+i);
		double res=0;
		{ /// 1
			rep(i,n){
				if(judge(x[i],y[i],l[i])){
					maxch(res,l[i]);
				}
			}
		}
		{ /// 2
			rep(i,n)rep(j,i){
				if(pow(x[i]-x[j],2)+pow(y[i]-y[j],2)-pow(l[i]+l[j],2)>EPS)continue;
				double d=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
				double xx=(l[i]*l[i]-l[j]*l[j]+d*d)/(2*d);
				double vx=(xx/d)*x[j]+((d-xx)/d)*x[i];
				double vy=(xx/d)*y[j]+((d-xx)/d)*y[i];
				if(l[i]*l[i]-xx*xx<EPS)continue;
				double vz=sqrt(l[i]*l[i]-xx*xx);
				if(judge(vx,vy,vz)){
					maxch(res,vz);
				}
			}
		}
		{ /// 3
			rep(i,n)rep(j,i)rep(k,j){
				double A[2][2];
				double b[2];
				A[0][0]=2*(x[j]-x[i]); A[0][1]=2*(y[j]-y[i]);
				A[1][0]=2*(x[k]-x[i]); A[1][1]=2*(y[k]-y[i]);
				b[0]=l[i]*l[i]-l[j]*l[j]-(x[i]+x[j])*(x[i]-x[j])-(y[i]+y[j])*(y[i]-y[j]);
				b[1]=l[i]*l[i]-l[k]*l[k]-(x[i]+x[k])*(x[i]-x[k])-(y[i]+y[k])*(y[i]-y[k]);
				gauss_jordan(A,b);
				if(X[0]==-114514)continue;
				else{
					double vx=X[0], vy=X[1];
					if(l[i]*l[i]-pow(vx-x[i],2)-pow(vy-y[i],2)<EPS)continue;
					double vz=sqrt(l[i]*l[i]-pow(vx-x[i],2)-pow(vy-y[i],2));
					if(judge(vx,vy,vz)){
						maxch(res,vz);
					}
				}
			}
		}
		printf("%.10f\n",res);
	}
	return 0;
}

Measured memory_bytes: 668
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日  1/14 20:06:55 2018

*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

int n, a, b;

int main()
{
	while(~scanf("%d %d %d", &n, &a, &b)){
			if((b - a) % 2 == 0) printf("Alice\n");
			else printf("Borys\n");
	}
    return 0;
}


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

int main()
{
    ll n,k;cin>>n>>k;
    ll arr[n];for(int i=0;i<n;i++) cin>>arr[i];
    //ll dp[n]; dp[0]=arr[0];
    //for(int i=1;i<k;i++) dp[i]=arr[i]*dp[i-1];
    //ll curr=dp[k-1];
  //for(int i=0;i<n;i++) cout<<dp[i]<<" "<<endl;
    for(int i=k;i<n;i++)
    {
      if(arr[i]>arr[i-k]) cout<<"Yes\n";
      else cout<<"No\n";
    }
}

Measured memory_bytes: 5124
#include"bits/stdc++.h"
using namespace std;
using ll = long long;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

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

    const ll N = s.size();
    vector<ll> v;
    vector<char> c;
    ll cnt = 1;
    rep(i, N - 1) {
        if (s[i] == s[i + 1]) {
            cnt++;
        }
        else {
            v.push_back(cnt);
            c.push_back(s[i]);
            cnt = 1;
        }
    }
    v.push_back(cnt);
    c.push_back(s.back());

    ll res = 0;
    rep(i, v.size() - 1) if (c[i] == '<'&&c[i + 1] == '>') {
        ll siz = max(v[i], v[i + 1]);
        ll siz2 = min(v[i], v[i + 1]);
        //if (siz != siz2) {
        res += siz * (siz + 1) / 2;
        res += (siz2 - 1)*siz2 / 2;
        //}
        //else {}
    }
    if (s.front() == '>') {
        ll siz = v.front();
        res += siz * (siz + 1) / 2;
    }
    if (s.back() == '<') {
        ll siz = v.back();
        res += siz * (siz + 1) / 2;
    }
    cout << res << endl;
    return 0;
}


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

int main(){
	int s;
	int sum = 0;
	for(int i = 0; i < 5; i++){
		cin >> s;
		if(s < 40) sum += 40;
		else sum += s;
	}
	cout << sum/5 << endl;
	return 0;
}


Measured memory_bytes: 3096
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,x,y;

int get(int a, int b){
	int ans = 1e9;
	if(a > b) swap(a,b);
	ans = min(ans,b-a);
	ans = min(ans,abs(a-x)+1+abs(b-y));
	ans = min(ans,abs(a-y)+1+abs(b-x));
	return ans;
}

int main(){

	fastio;
	cin >> n >> x >> y;
	vector<int> adj[2048];
	for(int i = 1; i < n; ++i){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[x].pb(y);
	adj[y].pb(x);

	vector<int> s[2048];
	int dist[2048];
	queue<int> q;
	fill(dist,-1);
	dist[x] = 0;
	q.push(x);
	while(sz(q)){
		int u = q.front();
		q.pop();
		s[dist[u]].pb(u);
		for(int v : adj[u]) if(v >= x && dist[v] == -1){
			dist[v] = dist[u] + 1;
			q.push(v);
		}
	}
	REP(i,0,2048) sort(s[i].begin(),s[i].end());

	for(int d = 1; d < n; ++d){
		int ans = 0;
		for(int i = x+1; i <= n; ++i){ 
			int res = d-(i-x);
			if(res < 0){
				ans += (i+d) <= n;
			}else{
				vector<int> op;
				for(int u : s[res]) op.pb(u);
				if(i+d <= n) op.pb(i+d);
				sort(op.begin(),op.end());
				op.erase(unique(op.begin(),op.end()),op.end());
				for(int u : op) ans += get(i,u) == d && u > i;
			}
		}
		for(int i = x; i >= 1; --i){
			int res = d-(x-i);
			if(res < 0){
				ans++;
			}else{
				ans += sz(s[res]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
# define int long long
# define mo 1000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

signed main()
{
   gok
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==c+1)
        {
            c++;
        }
    }
    if(c==0)
        cout<<-1;
    else
    cout<<n-c;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
const int mod = 1e9+7;
void ad(int &x,int y) { x+=y; if(x>=mod)x-=mod; }
int zy[8][2] = {{6,1},{3,2},{2,2},{4,1},{3,3},{6,1},{7,5},{6,6}};
char ss[300005];
int n;
int dp[300005][8];
int main() {
	scanf("%s",&ss[1]);
	n = strlen(ss+1);
	dp[0][0] = 1;
	for(int i=0;i<n;i++) {
		for(int j=0;j<8;j++) {
			if(ss[i+1]!='0') ad(dp[i+1][zy[j][1]],dp[i][j]);
			if(ss[i+1]!='1') ad(dp[i+1][zy[j][0]],dp[i][j]);
		}
	}
	int ans = (dp[n][1] + dp[n][2])%mod;
	printf("%d",ans);
}

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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;
using tTree=__gnu_pbds::tree< ll , __gnu_pbds::null_type, less< ll >, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;

  ll cnt=0;

  for(ll i=1;i<=n;i++){

    if((ll)(log10(i))%2==0) cnt++;

  }

  cout << cnt << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long prev = sc.nextLong();
        long ans = 0;
        for(int i = 1; i < n; i++){
            long tmp = sc.nextLong();
            ans += Math.min(b,(tmp-prev)*a);
            prev = tmp;
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 35668
import re
 
def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    
    for i in range(ls - lt + 1):
        m = re.match(s[i:i+lt], t)
        if m is None:
            continue
        ans.append( (s[:i] + t + s[i+lt:]).replace('.', 'a') )
        
    if not ans:
        return 'UNRESTORABLE'
    
    return min(ans)
 
S = input()
T = input()
 
print(solve(S, T))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int L;
    while(cin>>L,L){
        bool endFlag=false;
        int ans,sum=0;
        for(int i=0;i<12;i++){
            int M,N;
            cin>>M>>N;
            if(endFlag)continue;
            sum+=(M-N);
            if(L<=sum){
                ans=i+1;
                endFlag=true;
            }
        }
        if(!endFlag)cout<<"NA"<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;



int main() {
    ll x;
    cin >> x;
    ll n = 100;
    int cnt = 0;
    
    while(n < x){
        n += n/100;
        cnt++;
    }
    
    dunk(cnt);
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  string s; ll k;
  cin >> s >> k;
  ll n = s.size();
  ll ans = 0;
  int cnt = 1;
  rep(i,n-1) {
    if (s[i] == s[i+1]) cnt++;
    else break;
  }
  if (cnt == n) {
    ans = n*k/2;
    cout << ans << endl;
    return 0;
  }else {
    rep(i,n-1) {
      if (s[i] == s[i+1]) {ans++; s[i+1] = '#';}
    }
    ans *= k;
    if (s[0] == s[n-1] && cnt % 2 == 1) ans += k-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> x(n);
    vector<ll> sort_x(n);
    rep(i, n){
        cin >> x[i];
        sort_x[i] = x[i];
    }
    sort(all(sort_x));
    rep(i, n){
        if(x[i] > sort_x[n / 2 - 1]){
            cout << sort_x[n / 2 - 1] << endl;
        }
        else if(x[i] <= sort_x[n / 2]){
            cout << sort_x[n / 2] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
	int sen[10000];
	int bit[1024];
	int num[1024],s;
	for(int i=0;i<1024;i++)
		for(num[i]=0,s=i;s>0;s >>= 1)num[i]+=s&1;
	
  int r,c,cc;
  while(true){
		scanf("%d %d",&r,&c);
		if (!r&&!c)break;
		for(int i=0;i<c;i++) sen[i] = 0;
		
		for(int j=0;j<r;j++){
			for(int i=0;i<c;i++){
				scanf("%d",&cc);
				sen[i] <<= 1;
				sen[i] += cc;
			}
		}
		for(int i=0;i<1024;i++) bit[i] = 0;
		for(int i=0;i<c;i++) bit[sen[i]]++;

		int n,sum = 0,smax = 0,k=1;
		k <<= r-1;
		for(int i=0;i<k;i++){
			sum = 0;
			for(int j=0;j<1024;j++){
				s = j^i;
				sum += max(num[s],r-num[s]) * bit[j];
			}
			if (sum>smax)smax = sum;
		}
		printf("%d\n",smax);
  }
  return 0;
}

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

using namespace std;
 
int main(){
  	string s, t;
  	cin >> s >> t;
	
	int counter = 0;
    if (s[0] == t[0]) ++counter;
    if (s[1] == t[1]) ++counter;
    if (s[2] == t[2]) ++counter;
  	cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int PMAX = 1e7;

template <typename T>
struct node {
	T val, add;
	node *l, *r;
	node() {}
	node(T val, T add, node *left = nullptr, node *right = nullptr) : val(val), add(add), l(left), r(right) {}
	void init(T v, T a, node *left, node *right) {
		val = v;
		add = a;
		l = left;
		r = right;
	}
};

node<ll> pool[PMAX];

template <typename T>
class SaikyoSegmentTree {
	const ll n;
	const T id;
	int it;
	vector<node<T>*> root;
	T getval(node<T> *x) {
		return x == nullptr ? id : x->val;
	}
	T getadd(node<T> *x) {
		return x == nullptr ? id : x->add;
	}
	node<T>* getl(node<T> *x) {
		return x == nullptr ? nullptr : x->l;
	}
	node<T>* getr(node<T> *x) {
		return x == nullptr ? nullptr : x->r;
	}
	ll size(ll n) {
		assert(n < (1ll << 62ll));
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node<T> *new_node(T val, T add, node<T> *l = nullptr, node<T> *r = nullptr) {
		pool[it].init(val, add, l, r);
		return &pool[it++];
	}
	node<T> *fix(node<T> *x, ll l, ll r, T val, ll lb, ll ub) {
		if (r <= lb || ub <= l) return x;
		if (l <= lb && ub <= r) return new_node(getval(x), getadd(x) + val, getl(x), getr(x));
		ll c = (lb + ub) / 2;
		auto nl = fix(getl(x), l, r, val, lb, c);
		auto nr = fix(getr(x), l, r, val, c, ub);
		return new_node(getval(x) + val * (min(r, ub) - max(l, lb)), getadd(x), nl, nr);
	}
	T sub(node<T> *x, ll l, ll r, ll lb, ll ub) {
		if (x == nullptr) return id;
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return x->val + x->add * (ub - lb);
		ll c = (lb + ub) / 2;
		return sub(getl(x), l, r, lb, c) + sub(getr(x), l, r, c, ub) + x->add * (min(r, ub) - max(l, lb));
	}
public:
	SaikyoSegmentTree(ll n_) : n(size(n_)), id(0), it(0) {
		root.push_back(nullptr);
	}
	void add(ll l, ll r, T val, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		root.push_back(fix(root[rt], l, r + 1, val, 0, n));
	}
	T getSum(ll l, ll r, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		return sub(root[rt], l, r + 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	SaikyoSegmentTree<ll> lst(n);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.getSum(s, t));
		}
		else {
			cin >> x;
			lst.add(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 82368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int H,W,h,w;
	cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> num;
  if (s[0] == '0') num.push_back(0);
  for (int i = 0; i < s.size();) {
    int j = i;
    while (j < s.size() && s[j] == s[i]) ++j;
    num.push_back(j - i);
    i = j;
  }
  if (s[n - 1] == '0') num.push_back(0);
  vector<int> sum(num.size() + 1, 0);
  rep(i, num.size()) sum[i + 1] = sum[i] + num[i];
  int ans = 0;
  for (int left = 0; left < sum.size(); left += 2) {
    int right = min((int)sum.size() - 1, left + 2 * k + 1);
    ans = max(ans, sum[right] - sum[left]);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define LL long long
#define pii pair<int, int>
#define MP make_pair
#define ls i << 1
#define rs ls | 1
#define md (ll + rr >> 1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define mod 1000000007
#define inf 0x3f3f3f3f
#define Pi acos(-1.0)
#define eps 1e-12
#define N 220
#define M 400020

char s[N][N];
int sx, sy;
int n, m;
int d[N][N];

int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

bool in(int x, int y) {
	return x >= 1 && y >= 1 && x <= n && y <= m && s[x][y] != '#';
}

void bfs() {
	queue<int> q;
	q.push(sx); q.push(sy);
	memset(d, -1, sizeof d);
	d[sx][sy] = 0;
	while(!q.empty()) {
		int x = q.front(); q.pop();
		int y = q.front(); q.pop();
		for(int i = 0; i < 4; ++i) {
			int dx = x + dir[i][0];
			int dy = y + dir[i][1];
			if(!in(dx, dy)) continue;
			if(d[dx][dy] == -1) {
				d[dx][dy] = d[x][y] + 1;
				q.push(dx); q.push(dy);
			}
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= m; ++j) {
			if(s[i][j] == '%') {
				sx = i, sy = j;
			}
		}
	}
	bfs();
	int d1 = inf, d2 = inf;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(s[i][j] == '@') d1 = d[i][j];
			if(s[i][j] == '$' && d[i][j] != -1) {
				d2 = min(d2, d[i][j]);
			}
		}
	}
	if(d1 < d2) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3452