akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    
    int a,b;
    cin>>a>>b;

    cout<<max(max(a*b,a+b),a-b)<<endl;
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3528
use std::io::Read;

fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_to_string(&mut buf);
    let mut it = buf.split_whitespace();
    let n: i32 = it.next().unwrap().parse().unwrap();
    let x: i32 = it.next().unwrap().parse().unwrap();
    let m: Vec<i32> = (0..n).map(|_| {
        it.next().unwrap().parse().unwrap()
    }).collect();
    let mut min = 100000;
    let mut sum = 0;
    for val in &m {
        min = std::cmp::min(min, *val);
        sum += *val;
    }
    println!("{}", n+(x-sum)/min);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
char s[10];
signed main(){
	scanf("%s",s+1);
	if((s[3]==s[4])&&(s[5]==s[6]))puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] = a[i] - (i+1);
    }
    sort(a.begin(), a.end());

    ll mid = a[n/2], ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(mid - a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4040
#include <stdio.h>
#define Max_N 100

int N,M;
int count;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
char map[Max_N+1][Max_N+1]; 

void dfs(int x,int y,char data){
	map[x][y]='0';
	for(int i=0;i<4;i++){
		int tx=x+dx[i],ty=y+dy[i];
		if(tx<0||ty<0||tx>=N||ty>=M) continue;
		if(map[tx][ty]==data){
			dfs(tx,ty,data);
		}
	}
}

void solve(){
	count=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			if(map[i][j]=='#'){
				count++;
				dfs(i,j,'#');
			}else if(map[i][j]=='*'){
				count++;
				dfs(i,j,'*');
			}else if(map[i][j]=='@'){
				count++;
				dfs(i,j,'@');
			}
		}
	}
	printf("%d\n",count);
}

int main(){
	while(true){
		scanf("%d%d",&N,&M);
		if(N==0&&M==0) break;
		for(int i=0;i<N;i++){
			scanf("%s",map[i]);
		}
		solve();
	}
	
	return 0;
} 


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) (v).begin(), (v).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
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; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vll a(n);
    ll all=0;
    vll ans(n);
    ll total=0;
    bool flag=false;
    rep(i, n){
        cin >> a[i];
        total+=min(a[i],n);
    }
    rep(i,k){
        vll sta(n);vll fin(n);
        ll alli=0;
        ll mi=0;
        vector<pll>b;
        rep(j,n){
            if(j-a[j]<0&&a[j]+j>n-1) alli++;
            else{
                sta[max((ll)0,j-a[j])]++;
                fin[min((ll)n-1,j+a[j])]++;
            }
        }
        sort(all(b));
        ll count=0;
        rep(j,n){
            count+=sta[j];
            ans[j]=count+alli;
            count-=fin[j];
        }
        a=ans;
        if(alli==n){
            flag=true;
            break;
        }
    }
    if(flag){
        rep(i,n-1)cout<<n<<" ";
        cout << n << endl;
        return 0;
    }
    rep(i,n-1) cout<<ans[i]<<" ";
    cout << a[n-1]<< endl;
}

Measured memory_bytes: 9592
a = [int(input()) for i in range(5)]

mn = a[0] % 10
for i in a:
    if i % 10 == 0:
        continue
    mn = min(mn, i % 10)

for i in a:
    if i % 10 == mn:
        mn = i
        break


ans = 0
for i in a:
    if i == mn:
        ans += i
        mn = -1
        continue
    t = ((i + 9) // 10) * 10
    ans += t

print(ans)


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
	int a, b, c, d;
 	cin >> a >> b >> c >> d;
 	cout << min(a, b) + min(c, d) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
 long long a=0;
 cin >> N;
  for(int i=1;i<N+1;i++){
    if(i%3==0||i%5==0){
     continue;
    }
    a=a+i;
  }
  cout << a << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> p[100005];
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    p[a].push_back(b);
  }

  priority_queue<int> que;
  int ans = 0;
  REP(i, m) {
    for(int u : p[i]) {
      que.push(u);
    }
    if(!que.empty()) {
      ans += que.top(); que.pop();
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 8960
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,a,b,c,sum=0,dp[3]={0},temp[3]={0};
    cin>>n;
    cin>>dp[0]>>dp[1]>>dp[2];
    n--;
    while(n--)
    {
        cin>>a>>b>>c;
        temp[0]=max(a+dp[1],a+dp[2]);
        temp[1]=max(b+dp[0],b+dp[2]);
        temp[2]=max(c+dp[0],c+dp[1]);

        dp[0]=temp[0];
        dp[1]=temp[1];
        dp[2]=temp[2];
    }
    cout<<max(dp[0],max(dp[1],dp[2]));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    vector <long> a(n);
    vector <long> snuke;
    long cnt = 1;
    long ans = 0;
    for(long i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]==cnt){
            snuke.push_back(a[i]);
            cnt++;
        }
    }
    if(snuke.size()==0){
        ans = -1;
    }else{
        ans = n-snuke.size();
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> counter(n, 0);
  
  for (int i = 0; i < n-1; i++){
    counter[i+1] = counter[i];
    if (s.substr(i, 2) == "AC"){
      counter[i+1]++;
    }
  }
  int l, r;
  int ans;
  for (int i = 0; i < q; i++){
    cin >> l >> r;
    ans = counter[r-1] - counter[l-1];
    cout << ans << endl;
  }
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
    int n,m,temp=0,ans=0;
    pair<int,bool>a[1000000];
    scanf("%d%d",&n,&m);
    n*=2;
    for(int i=0;i<n;i+=2){
        scanf("%d%d",&a[i].first,&a[i+1].first);
        a[i].second=true;
        a[i+1].second=false;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)if(a[i].second){
        temp++;
        if(temp>ans)ans=temp;
    }
    else temp--;
    printf("%d\n",ans);
}

Measured memory_bytes: 10564
using System;

class UnevenNumbers
{
    static void Main (string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int count = 0;

        for (int i = 1; i <= n; i++)
        {
            int ans = (int)Math.Log10(i);            

            if (ans % 2 == 0)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


Measured memory_bytes: 13140
while 1:
    n = input()
    if n == 0:
        break
    F = [0]*n
    W = [0]*n
    S = [0]*n

    def dfs(c, state, used, su):
        if c == n:
            return [sum((1+i)*W[state[n-1-i]] for i in xrange(n)), state[::-1]]
        mi = [10**9, None]
        for i in xrange(n):
            if not used[i] and S[i] >= su:
                state[c] = i
                used[i] = 1
                mi = min(mi, dfs(c+1, state, used, su + W[i]))
                used[i] = 0
        return mi

    for i in xrange(n):
        F[i], w, s = raw_input().split()
        W[i] = int(w)
        S[i] = int(s)
    for i in dfs(0, [0]*n, [0]*n, 0)[1]:
        print F[i]

Measured memory_bytes: 6304
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n;
    cin >> n;
    
    ll dp[64][3] = {};
    dp[0][0] = 1;
    REP(i, 63){
        if(n >> (62 - i) & 1){
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD;
            dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1] * 2) % MOD;
        }
        else{
            dp[i + 1][0] = (dp[i][0] + dp[i][1]) % MOD;
            dp[i + 1][1] = dp[i][1];
            dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % MOD;
        }
    }
    cout << (dp[63][0] + dp[63][1] + dp[63][2]) % MOD << endl;
}

Measured memory_bytes: 256
// Problem : A - Blackjack
// Contest : AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a, b, c; cin >> a >> b >> c;
    if(a + b + c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}



Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def modinv(a):
    return pow(a, MOD-2, MOD)


def cmb(n, r):
    p = 1
    c = 1
    for i in range(r):
        p *= (n - i)
        c *= (i + 1)
        p = p % MOD
        c = c % MOD
    return p * modinv(c) % MOD


def main():
    n, a, b = MI()
    first = cmb(n, a)
    second = cmb(n, b)
    ans = pow(2, n, MOD) - 1
    print((ans - first - second) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>


using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int maxnum = 0, ans = 0;
	vector<int> vec(5);
	for (int i = 0; i < 5; i++) {
		cin >> vec[i];
	}

	for (int i = 0; i < 5; i++) {
		if (vec[i] % 10 == 0){
			ans += vec[i];
		}
		else {
			maxnum = max(maxnum, (10 - vec[i] % 10));
			ans += vec[i] + (10 - vec[i] % 10);
		}
	}
	
	cout << ans - maxnum << endl;




}




Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.nextLine();
        String T = scanner.nextLine();
        if(T.length()-1!=S.length()){
            System.out.print("No");
        }
        else {
            if(S.equals(T.substring(0,S.length()))){
                System.out.print("Yes");
            }
            else {
                System.out.print("No");
            }
        }
    }
}


Measured memory_bytes: 35784
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;

int main() {
	long double W, H;
	long double x, y;
	cin >> W >> H >> x >> y;
	W / 2 == x && H / 2 == y ? cout << fixed << setprecision(9) <<W * H / 2 << " " << 1: cout << W * H / 2 << " " << 0;



}

Measured memory_bytes: 256
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            flag=0
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x<H and 0<=y<W:
                    if s[x][y]=="#":
                        flag=1
            if flag==0:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

int n, m, x, y, xmax, ymin;

int main(){
    int i, t;
    while(scanf("%d%d%d%d", &n, &m, &x, &y)!=EOF){
        xmax = -INF;
        ymin = INF;
        for(i = 1; i <= n; i++){
            scanf("%d", &t);
            xmax = MAX(xmax, t);
        }
        for(i = 1; i <= m; i++){
            scanf("%d", &t);
            ymin = MIN(ymin, t);
        }
        if(x<y && xmax<ymin && xmax<y && x<ymin)
            printf("No War\n");
        else
            printf("War\n");
    }

    return 0;
}

Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//



int32_t main()
{
    //io;
    int n;
    cin>>n;
    vll cnt(n+1), contri(n+1), inp(n);
    for(int i =0 ;i < n;i++)
    {
        cin>>inp[i];
        cnt[inp[i]]++;
    }
    ll tot = 0;
    for(int i = 0; i<= n; i++)
    {
        contri[i] = cnt[i]*(cnt[i] - 1)/2;
        tot += contri[i];
    }

    for(int i =0 ;i < n; i++)
    {
        ll ans = tot - contri[inp[i]] + (cnt[inp[i]] - 1)*(cnt[inp[i]] - 2)/2;
        cout<<ans<<"\n";
    }
    return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MAX = 10000007;
const int MOD = 1e9+7;

int fat[2007], inv[2007];

int binExp(int x, int p){
	int ans = 1;
	while(p){
		if(p&1)
			ans = 1LL * ans * x % MOD;
		p>>=1;
		x = 1LL * x * x % MOD; 
	}
	return ans;
}

int comb(int a, int b){
	int add = 1LL * fat[a] * inv[b] % MOD;
	return 1LL * add * inv[a-b] % MOD;
}

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

	fat[0] = inv[0] = 1;
	for(int i = 1; i < 2007; i++){
		fat[i] = 1LL * fat[i-1] * i % MOD;
		inv[i] = binExp(fat[i], MOD-2);
	}

	int n; cin >> n;

	int ans = 0;
	for(int i = 1; i < n; i++){
		if(n < 3*i) break;
		int add = comb(n-2*i-1, i-1);
		ans = ((ll) ans + add) % MOD;
	}

	cout << ans << '\n';
	

	return 0;
}


Measured memory_bytes: 3656
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define sz(a) (int)(a.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a, b;
    cin>>n>>a>>b;
    int arr[n];
    for0(i,n) cin>>arr[i];
    int ans = 0;
    for1(i,n-1) {
        ans += min(a*(arr[i]-arr[i-1]), b);
    }
    cout<<ans;

    return 0;
}   

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> isOpen(h + 2, vector<bool>(w + 2));
  rep(i, h) {
    int y = i + 1;
    string s;
    cin >> s;
    rep(j, w) {
      int x = j + 1;
      if('.' == s[j]) isOpen[y][x] = true;
    }
  }
  vector<vector<int>> nOpenL(h + 2, vector<int>(w + 2));
  vector<vector<int>> nOpenR(h + 2, vector<int>(w + 2));
  vector<vector<int>> nOpenU(h + 2, vector<int>(w + 2));
  vector<vector<int>> nOpenD(h + 2, vector<int>(w + 2));
  rep(i, h) rep(j, w) {
    int x = j + 1;
    int y = i + 1;
    if(isOpen[y][x])
      if(isOpen[y][x - 1])
        nOpenL[y][x] = nOpenL[y][x - 1] + 1;
  }
  rep(i, h) for(int j = w - 1; j >= 0; j--) {
    int x = j + 1;
    int y = i + 1;
    if(isOpen[y][x])
      if(isOpen[y][x + 1])
        nOpenR[y][x] = nOpenR[y][x + 1] + 1;
  }
  rep(i, h) rep(j, w) {
    int x = j + 1;
    int y = i + 1;
    if(isOpen[y][x])
      if(isOpen[y - 1][x])
        nOpenU[y][x] = nOpenU[y - 1][x] + 1;
  }
  for(int i = h - 1; i >= 0; i--) rep(j, w) {
      int x = j + 1;
      int y = i + 1;
      if(isOpen[y][x])
        if(isOpen[y + 1][x])
          nOpenD[y][x] = nOpenD[y + 1][x] + 1;
    }
  int ans = 0;
  rep(i, h) rep(j, w) {
    int x = j + 1;
    int y = i + 1;
    int now = nOpenL[y][x] + nOpenR[y][x] + nOpenU[y][x]
              + nOpenD[y][x] + 1;
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string Ans;
  int N,K,Q; cin>>N>>K>>Q;
  vector<int> p(N,K);
  REP(i,Q) {
    int who; cin>>who;
    who--;
    p.at(who)++;
  }
  REP(i,N){
    p.at(i)-=Q;
    Ans=p.at(i)>0? "Yes" : "No";
    cout << Ans << '\n';
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  set<string> dic;
  char order[64] = { '\0' };
  char key[64] = { '\0' };
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%s", order);
    fscanf(stdin, "%s", key);
    if (order[0] == 'i') {
      dic.insert(key);
    }
    else {
      if (dic.count(key)) {
        fprintf(stdout, "yes\n");
      }
      else {
        fprintf(stdout, "no\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 27048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>

using namespace std;

typedef long long ll;

const ll prime = 10000000000 + 7;

/*
vector<int> z_algorithm(const string& s) {
	vector<int> prefix(s.size());
	for (int i = 1, j = 0; i < s.size(); i++)
	{
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
	}
}
*/

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

	// gcd
	ll gcd, c;
	if (a < b) {
		c = a;
		a = b;
		b = c;
	}
	// a >= b
	while (true) {
		c = a % b;
		if (c == 0) {
			gcd = b;
			break;
		}
		else {
			a = b;
			b = c;
		}
	}

	vector<ll> primeList;

	for (ll i = 2; i < pow(gcd, 0.5) + 1; i++)
	{
		if (gcd % i == 0) {
			// i で割れる
			primeList.push_back(i);
			while (true) {
				if (gcd % i == 0) {
					gcd /= i;
				}
				else {
					break;
				}
			}
		}
		if (gcd == 1) {
			break;
		}
		if (i * i > gcd) {
			primeList.push_back(gcd);
			break;
		}
	}

	cout << (1 + primeList.size()) << endl;


	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> w;
  int w_total = 0;
  for(int i = 0; i < n; i++){
    int w_i; cin >> w_i;
    w.push_back(w_i);
    w_total += w_i;
  }

  int w_sum_tmp = 0;
  int dif[n+10];
  for(int i = 0; i < n; i++){
    w_sum_tmp += w[i];
    w_total -= w[i];    
    dif[i] = w_sum_tmp - w_total;
    if(w_sum_tmp - w_total >= 0){
      cout<<min(abs(dif[i]),abs(dif[i-1]))<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>

using namespace std;

const int MAXN = 100005;

int n, sol;
int l[MAXN];
int p[MAXN];

int main () {
    cin >> n;
    for (int i=0; i<n; i++) {
        scanf("%d", &l[i]);
        l[i]++;
        p[l[i]]++;
        p[l[i]-1]++;
        p[l[i]+1]++;
    }
    for (int i=0; i<MAXN; i++) {
        sol=max(sol, p[i]);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 1024
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let w = nextIntArray()
    let total = 0
    for(let el of w){
        total += el
    }
    let min = Number.POSITIVE_INFINITY
    let sub = 0
    for(let el of w){
        sub += el
        min = Math.min(min, Math.abs(sub-(total-sub)))
    }
    console.log(min)
}
Main()


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 1010

using namespace std;

typedef pair<int,int> ii;

struct Edge{
  int to,index;
  Edge(int to=IINF,int index=IINF):to(to),index(index){}
};

struct Data{
  int cur,cost,rev;
  Data(int cur=IINF,int cost=IINF,int rev=IINF):cur(cur),cost(cost),rev(rev){}
  bool operator < (const Data& data)const{
    if( cost != data.cost ) return cost > data.cost;
    return rev > data.rev;
  }
};

int N,M,S,T,a,b;
vector<Edge> G[MAX][2];
ii mincost[MAX][2];

inline void dijkstra(){
  priority_queue<Data> Q;

  Q.push(Data(S,0,IINF));
  mincost[S][0] = ii(0,IINF);
  while(!Q.empty()){
    Data data = Q.top(); Q.pop();
    int cur = data.cur;
    bool r = (data.rev!=IINF);
    if( mincost[cur][r].first < data.cost ) continue;
    rep(j,2){
      if( j && r ) break;
      if( j )r = true;
      rep(i,(int)G[cur][j].size()){
        if( j )data.rev = G[cur][j][i].index;
        int to = G[cur][j][i].to;
        int ncost = data.cost + 1;
        if( mincost[to][r].first == ncost && r && data.rev < mincost[to][r].second ){
          mincost[to][r].second = data.rev;
          Q.push(Data(to,ncost,data.rev));
        } else if( mincost[to][r].first > ncost ){
          mincost[to][r] = ii(ncost,data.rev);
          Q.push(Data(to,ncost,data.rev));
        }
      }
    }
  }

  int answer_cost = min(mincost[T][0].first,mincost[T][1].first);
  int answer_rev = mincost[T][1].second;
  if( mincost[T][0].first <= mincost[T][1].first ) answer_rev = -1;
  cout << answer_cost << ' ' << answer_rev+1 << endl;
}

int main(){
  while(cin>>N,N){
    rep(i,N)rep(j,2)G[i][j].clear(),mincost[i][j] = ii(IINF,IINF);
    cin >> S >> T;
    --S, --T;
    cin >> M;
    rep(i,M){
      cin >> a >> b;
      --a,--b;
      G[a][0].push_back(Edge(b,i));
      G[b][1].push_back(Edge(a,i));
    }
    dijkstra();
  }
  return 0;
}

Measured memory_bytes: 1780
max_1 = 0
max_2 = 0
max_3 = 0
for i in range(10):
    m = int(input())
    if max_1 < m:
        max_3 = max_2
        max_2 = max_1
        max_1 = m
    elif max_2 < m:
        max_3 = max_2
        max_2 = m
    elif max_3 < m:
        max_3 = m
print(max_1)
print(max_2)
print(max_3)


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

using namespace std;

#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x++)
#define ps printf(" ")
#define pn printf("\n")

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll w, a, b;
    cin >> w >> a >> b;

    if(a <= b)
    {
    	cout << max(b - (a + w), 0LL);
    }
    else
    	cout << max(a - (b + w), 0LL);
    return 0;
}


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

using namespace std;

typedef long long ll;

#define INF 1LL<<60

ll n;
ll s;

ll f(ll b, ll n) {
    if (n < b) {
        return n;
    } else {
        ll nn = floor((double) n / b);
        return f(b, nn) + (n % b);
    }
}

int main(int argc, char* argv[]) {
    //cin >> n >> s;
    scanf("%lld", &n);
    scanf("%lld", &s);

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    ll ans = INF;

    for (ll b = 2; b < sqrt(n) + 1; ++b) {
        if (f(b, n) == s) {
            ans = min(ans, b);
        }
    }

    ll d = n-s;

    for (ll i = 1; i < sqrt(d) + 1; ++i) {
        ll b = (n-s)/i + 1;

        if (f(b, n) == s) {
            ans = min(ans, b);
        }
    }

    if (ans == INF) {
        printf("%lld\n", -1LL);
    } else {
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void y(bool c) { if (c)print("Yes"); else print("No"); };


void solve() {
	int ans = 0;
	int N; cin >> N;
	FOR(i, 1, N + 1) {
		if (i % 3 != 0 && i % 5 != 0)ans += i;
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}




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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll N,K;cin>>N>>K;
  ll ans=K;
  rep(i,N-1){
    ans *=(K-1);
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

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

 return 0;
}

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

#define N_MAX 100

int N; 
int kiji_cost, topping_cost;
int kiji_cal;
int topping_cal[N_MAX];

int solve() {
    int average = kiji_cal / kiji_cost;
    int sum = kiji_cal;
    for (int i = 0; i < N; i++) {
        sum += topping_cal[i];
        if (average > sum / (kiji_cost + topping_cost * (i+1))) break;
        average = sum / (kiji_cost + topping_cost * (i+1));
    }
    return average;
}

int main() {
    cin >> N;
    cin >> kiji_cost >> topping_cost;
    cin >> kiji_cal;
    for (int i = 0; i < N; i++) {
        int c; cin >> c;
        topping_cal[i] = c;
    }
    sort(topping_cal, topping_cal+N, greater<int>());
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;


ll N,cur,flag=0;
pair<ll,ll> P[200005];


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	FOR(i, 0, N) {
		cin >> P[i].second >> P[i].first;
	}
	sort(P, P + N);

	FOR(i, 0, N) {
		cur += P[i].second;
		if (P[i].first < cur)flag = 1;
	}

	if (flag == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int a[200000];

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

	long long int res = 0, cur = 0, r = 0;
	for(int l = 0;l < N; l++){
		for(; r < N && !(cur & a[r]); r++){
			cur ^= a[r];
		}
		cur ^= a[l];
		res += (r - l);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int p[n],q[n];
    for(int i = 0;i < n;i++)
    {
        cin >> p[i];
    }
    for(int i = 0;i < n;i++)
    {
        cin >> q[i];
    }
    int r[n];
    for(int i = 0;i < n;i++)
    {
        r[i] = i + 1;
    }
    long long int p_count = 0,q_count = 0;
    while(true)
    {
        bool check = true;
        for(int i = 0;i < n;i++)
        {
            if(p[i] != r[i])
            {
                check = false;
                break;
            }
        }
        if(check)
        {
            break; 
        }
        p_count++;
        next_permutation(r,r + n);
    }
    for(int i = 0;i < n;i++)
    {
        r[i] = i + 1;
    }
    while(true)
    {
        bool check = true;
        for(int i = 0;i < n;i++)
        {
            if(q[i] != r[i])
            {
                check = false;
                break;
            }
        }
        if(check)
        {
            break; 
        }
        q_count++;
        next_permutation(r,r + n);
    }
    cout << fabs(p_count - q_count) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

static const int MAXN = 200;
ll d[MAXN][MAXN];
int n, m, r;

void floyd() {
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            if (d[i][k] == LINF) continue;
            for (int j = 0; j < n; ++j) {
                if (d[k][j] == LINF) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> r;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            d[i][j] = ((i == j) ? 0 : LINF);
        }
    }

    vector<int> R(r);
    rep(i, r) {
        int t;
        cin >> t;
        --t;
        R[i] = t;
    }

    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        d[a][b] = c;
        d[b][a] = c;
    }

    floyd();

    ll ans = LINF;
    sort(R.begin(), R.end());
    do {
        ll sum = 0;
        for (int i = 1; i < r; ++i) {
            sum += d[R[i-1]][R[i]];
        }
        chmin(ans, sum);
    } while(next_permutation(R.begin(), R.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
string s[26][26] = {};
int main() {
    int h,w;
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j] == "snuke") {
                cout << char(j+'A');
                cout << i+1<< endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}
ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	ll r=0, g=0, b=0;
	for (char i : s) {
		if (i == 'R')r++; if (i == 'G')g++; if (i == 'B')b++;
	}
	ans = r * b * g;
	rep(j, n) {
		rep(i,j) {
			ll k = 2 * j - i;
			if (k < n) {
				if (s[i] == s[j] || s[i] == s[k] || s[j] == s[k])continue;
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}













Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int D;
vector<int> c;
vector<vector<int>> s;

int calcScore(vector<int> &out){
	int score = 0;
	vector<int> last(26, 0);
	rep(d, (int)out.size()){
		last[out[d]] = d + 1;
		score += s[d][out[d]];
		rep (i, 26){
			score -= (d+1 - last[i])*c[i];
		} // end rep
	} // end rep
	return score;
}

int evalute(vector<int> &out, int k){
	int score = 0;
	vector<int> last(26, 0);
	rep (d, (int)out.size()){
		last[out[d]] = d + 1;
		score += s[d][out[d]];
		rep (i, 26){
			score -= (d + 1 - last[i]) * c[i];
		} // end rep
	} // end rep
	for (int d = (int)out.size(); d < min((int)out.size() + k, D); d++){
		rep (i, 26){
			score -= (d + 1 - last[i]) * c[i];
		} // end rep
	} // end for
	return score;
}

vector<int> solve(int k){
	vector<int> out; out.clear();
	rep (d, D){
		int maxScore = -(int)1e7;
		int best_i = 0;
		rep (i, 26){
			out.emplace_back(i);
			int score = evalute(out, k);
			if (maxScore < score){
				maxScore = score;
				best_i = i;
			} // end if
			out.pop_back();
		} // end rep
		out.emplace_back(best_i);
	} // end rep
	return out;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> D;
	c.clear(); c.resize(26, 0);
	rep (i, 26){
		cin >> c[i];
	} // end rep
    s.clear(); s.resize(D, vector<int>(26, 0));
	rep (i, D){
		rep (j, 26){
			cin >> s[i][j];
		} // end rep
	} // end rep

	int maxScore = -(int)1e7;
	vector<int> ans; ans.clear();
	rep (k, 13){
		vector<int> tmp = solve(k);
		int score = calcScore(tmp);
		if (score > maxScore){
			maxScore = score;
			ans = tmp;
		} // end if
	}

	rep (i, (int)ans.size()){
		cout << ans[i] + 1 << endl;
	} // end rep

	return 0;
}


Measured memory_bytes: 3696
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    int N;
    cin >> N;

    ll a;
    vector<ll> A;
    cin >> a;
    A.push_back(a);

    for(int i=1;i<N;i++){
      cin >> a;
      if(A.back()!=a) A.push_back(a);
    }

    int ans = 0;
    int i=0;
    int l = A.size();
    while(i<l){
      int j=1;
      while(i+j<l-1 && (A[i+j]-A[i+j-1])*(A[i+j+1]-A[i+j])>0){
        j++;
      }
      ans++;
      i = i+j+1;
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 1400