akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,r=0,b=0;
    string s;
    cin>>n>>s;
    for(int i = 0; i < n; i++)
    {
        if(s[i]=='R') r++;
        else b++;
    }
    
    if(r>b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
 
    return 0;
}

Measured memory_bytes: 256
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
div=make_divisors(n)
if len(div)%2==1:
  print(div[(len(div)-1)//2]*2-2)
else:
  print(div[len(div)//2-1]+div[len(div)//2]-2)

Measured memory_bytes: 3268
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;
 
 
 
int main(){
  int x, n, p, result;
  int p_contents[100];
  cin >> x >> n;
  rep(i,100) p_contents[i]=0;
  rep(i,n){
    cin >> p;
    p_contents[p-1]=1;
  }
  int min1=INF, min2=INF;
  for(int i=x-1;i>=0; i--){
    if(p_contents[i]==0){
      min1=i+1;
      break;
    }
  }
  for(int i=x-1;i<100;i++){
    if(p_contents[i]==0){
      min2=i+1;
      break;
    }
  }
  if(min1==INF) min1=0;
  if(min2==INF) min2=101;
  if(x-min1<=min2-x){
    cout << min1 << endl;
  }else{
    cout << min2 << endl;
  }
  
}

Measured memory_bytes: 3588
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    
    t_max = 1
    h = 0
    for ai in A:
        if ai >= t_max:
            t_max = ai
        else:
            h += t_max-ai

    print(h)

        
    

    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 33288
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int a[200005];
int N;

int main(void) {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
    }

    int x = 1;
    for (int i = 0; i < N; i++) {
        if (a[i] == x) {
            x++;
        }
    }

    if (x == 1) puts("-1");
    else printf("%d\n", N-x+1); 

	return 0;
}


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

using namespace std;
int a[4];
int main()
{
	int n;cin >> n;
  while(n--)
  {
	string s;cin >> s;
    if(s[0] == 'A')a[0]++;
    else if(s[0] == 'W')a[1]++;
    else if(s[0] == 'T')a[2]++;
    else a[3]++;
  }
  printf("AC x %d\n",a[0]);
  printf("WA x %d\n",a[1]);
  printf("TLE x %d\n",a[2]);
  printf("RE x %d\n",a[3]);
  	



    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    100256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;

ll n, m, k;
ll a, b, c;
ll ans[N], sum, cnt, cur;
map < ll, ll > mp[N];
vector < ll > g[N];
queue < ll > q;

void solve()
{
    cin >> n;
    for( int i = 1; i < n ; i++ )
    {
        cin >> a >> b;
        mp[a][b] = i;
        mp[b][a] = i;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    q.push( 1 );
    while( !q.empty() )
    {
        ll v = q.front();
        q.pop();
        ll col = 1;
        map < int, bool > ok;
        ok.clear();
        for( ll i: g[v] )
        {
            if( ans[ mp[v][i] ] )ok[ ans[ mp[v][i] ] ] = 1;
        }
        for( ll i: g[v] )
        {
            if( !ans[ mp[v][i] ] )
            {
                while( ok[col] )col ++;
                ans[ mp[v][i] ] = col;
                ok[ col ] = 1;
                col ++;
                q.push( i );
            }
        }
        cnt = max( cnt, col - 1);
    }
    cout << cnt << endl;
    for( int i = 1; i < n; i ++ )cout << ans[i] << endl;
}
int main()
{
    ll tt = 1;
   // sc( "%d", &tt );
    for( ll i = 1; i <= tt; i ++ )
    {
        solve();
    }
}












Measured memory_bytes: 24576
//     THE ONLY WAY IS UP

#include<bits/stdc++.h>

#define ll              long long int
#define ld              long double
#define f1(i, a, b)     for(ll i = a; i < b; i++)
#define f2(a, b)        for(auto a : b)
#define ar(v, i)        v[i]
#define in_(x)          ll x; cin >> x;
#define ino_(type, x)   type x; cin >> x;
#define pb              push_back

using namespace std;

int main()
{
    ll k, n;
    cin >> k >> n;
    vector<ll> v;
    
    f1(i, 0, n)
    {
        in_(x)
        v.pb(x);
    }
    ll res = 0;
    ll maxdiff = 0;
    
    f1(i, 0, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            if(d > maxdiff)
            {
                maxdiff = d;
            }
        }
        else
        {
            ll d = abs(ar(v, i) - k) + ar(v, 0);
            if(d > maxdiff)
            {
                maxdiff = d;
            }
        }
    }
    
    ll ind;
    
    f1(i, 0, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            if(d == maxdiff)
            {
                ind = i + 1;
                break;
            }
        }
        else
        {
            ll d = abs(ar(v, i) - k) + ar(v, 0);
            if(d == maxdiff)
            {
                ind = 0;
                break;
            }
        }
    }
    
    // cout << ind << endl;
    
    f1(i, ind, n)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            res += d;
            // cout << res << "#" << endl;
        }
        else
        {
            if(ind != 0)
            {
                ll d = abs(ar(v, i) - k);
                res += d;
                res += v[0];
                // cout<< "THIS" << res << endl;
            }
        }
    }
    
    f1(i, 0, ind - 1)
    {
        if(i != n - 1)
        {
            ll d = abs(ar(v, i) - ar(v, i + 1));
            res += d;
            // cout << res << "@" << endl;
        }
        else
        {
            ll d = abs(ar(v, i) - ar(v, 0));
            res += d;
            // cout << res << "*" << endl;
        }
    }
    cout << res << endl;
    
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i,n;
    n=s.size();
    for(i=0;i<n;i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main() {
  ll i, j, k;
  
  ll N;
  cin >> N;
  vector<ll> g[MAX*2];
  
  for(i=1; i<N; i++) {
    ll a;
    cin >> a;
    a--;
    
    g[a].push_back(i);
  }
  
  for(i=0; i<N; i++) {
    pt(g[i].size());
  }
  
  
  
  
}




Measured memory_bytes: 14480
from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = set(A)
A = Counter(A)

for i in range(M):
    B, C = list(map(int, input().split()))
    A[C] += B
    a.add(C)
a = sorted(list(a), reverse=True)

ans = 0

for i in a:
    ans += i * min(A[i], N)
    N -= A[i]
    if N <= 0:
        break
print(ans)

Measured memory_bytes: 41760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
int main() {
    double n;
    cin >> n;
    double k=0;
    for(int i=1;i<=n;++i) {
        if(i%2!=0) ++k;
    }
    double ans=k/n;
    cout << fixed << setprecision(10) << ans << endl;
}

    


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210000;

int n,m;
int v[maxn];
struct node{int p,i;}a[maxn<<1]; int tot;
inline bool cmp(const node x,const node y){return x.p<y.p;}
int l[maxn],r[maxn],id;

ll re;

int main()
{
	scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	for(int i=1;i<n;i++)
	{
		if(v[i]<v[i+1])
		{
			re+=v[i+1]-v[i];
			if(v[i]+1!=v[i+1])
			{
				++id; l[id]=v[i]+1; r[id]=v[i+1]+1;
				a[++tot]=(node){l[id],id};
				a[++tot]=(node){r[id],id};
			}
		}
		else
		{
			re+=m-v[i]+v[i+1];
			if(v[i]%m+1!=v[i+1])
			{
				int kk=m-v[i];
				++id; l[id]=1-kk; r[id]=v[i+1]+1;
				a[++tot]=(node){l[id],id};
				a[++tot]=(node){r[id],id};
			}
			if(v[i]<m-1)
			{
				++id; l[id]=v[i]+1,r[id]=m+1;
				a[++tot]=(node){l[id],id};
			}
		}
	}sort(a+1,a+tot+1,cmp);
	
	int pos=1;
	ll ans=0,sum=0,num=0;
	for(int i=1;i<=m;i++)
	{
		while(pos<=tot&&a[pos].p<=i)
		{
			id=a[pos].i;
			if(a[pos].p!=r[id]) sum+=l[id],num++;
			else sum-=l[id],num--;
			pos++;
		}
		ans=max(ans,num*(ll)i-sum);
	}
	printf("%lld\n",re-ans);
	
	return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;
const int MAX = 200010;

int main(){
    int n;
    lint K;
    scanf("%d%lld", &n, &K);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    
    pil G[n];
    int Next[MAX];
    rep(i, MAX) Next[i] = n;
    rrep(i, n) Next[a[i]] = n + i;
    rrep(i, n){
        lint dist = 1LL * (Next[a[i]] - i + 1);
        int to = (Next[a[i]] + 1) % n;
        Next[a[i]] = i;
        G[i] = pil(to, dist);
    }
    
    lint td = 0;
    int v = 0;
    while(true){
        if(v == 0 && td != 0) break;
        td += G[v].se;
        v = G[v].fi;
    }
    
    K = K * n % td;
    while(G[v].se < K){
        K -= G[v].se;
        v = G[v].fi;
    }
    
    deque<int> dq;
    bool used[MAX];
    rep(i, MAX) used[i] = false;
    while(K--){
        if(!used[a[v]]){
            used[a[v]] = true;
            dq.push_back(a[v]);
        }
        else{
            while(*dq.rbegin() != a[v]){
                used[*dq.rbegin()] = false;
                dq.pop_back();
            }
            dq.pop_back();
            used[a[v]] = false;
        }
        v = (v+1) % n;
    }
    
    while(!dq.empty()){
        printf("%d ", dq[0]);
        dq.pop_front();
    }
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
const ll MAX_N = 100000;
ll Par[MAX_N],Rank[MAX_N] = {},Amount[MAX_N];
ll N;
void init(){
  ll i;
  for(i=0;i<N;i++){
    Par[i] = i;
    Amount[i] = 1;
  }
}
ll find(ll x){
  if(Par[x] == x) return x;
  else{
    Par[x] = find(Par[x]);
    Amount[x] = Amount[Par[x]];
    return Par[x];
  }
}
ll amount(ll x){
  find(x);
  return Amount[x];
}
bool same(ll x,ll y){
  return find(x) == find(y);
}
bool unite(ll x,ll y){
  x = find(x);y = find(y);
  if(x == y) return false;
  if(Rank[x] < Rank[y]) swap(x,y);
  Par[y] = x;
  Amount[x] += Amount[y];
  if(Rank[x] == Rank[y]) Rank[x]++;
  return true;
}
int main(){
  ll M,i;scanf("%lld%lld",&N,&M);
  init();
  pair<ll,ll> B[M];
  ll ans[M];
  for(i=M-1;i>=0;i--){
    scanf("%lld%lld",&B[i].first,&B[i].second);
    B[i].first--;B[i].second--;
  }
  ll sum = N*(N-1)/2,now = 0,l,r,lr;
  for(i=0;i<M;i++){
    ans[M-i-1] = sum-now;
    l = amount(B[i].first);r = amount(B[i].second);
    if(unite(B[i].first,B[i].second)){
      lr = amount(B[i].first);
      now += (lr*(lr-1)-l*(l-1)-r*(r-1))/2;
    }
  }
  for(i=0;i<M;i++) printf("%lld\n",ans[i]);
}

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


int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u) a--;    
    if (t == u) b--;    
    cout << a << " " << b << endl;
}

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll n;
    string buf;
    cin >> n;
    set<string> s;
    REP(i,n) {
        cin >> buf;
        s.insert(buf);
    }
    cout << s.size();
}

Measured memory_bytes: 19132
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, par[1000010], ranks[1000010], a, b, c, dist[400010], all, newNode[400010];
vector<pi> e[1000010];
vi adj[1000010];
bool used[1000010];

inline int find(int x)
{
	return par[x]==x?x:par[x]=find(par[x]);
}

inline void unite(int x, int y)
{
	x=find(x), y=find(y);
	if(x==y)
		return;
	if(ranks[x]<ranks[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(ranks[x]==ranks[y])
			ranks[x]++;
	}
}

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		while(M--)
		{
			a=in(), b=in();
			e[in()].eb(mp(a, b));
		}
		all=N;
		Forn(i, 1000000)
		{
			if(!e[i].size())
				continue;
			int pa;
			foreach(it, e[i])
	        {
	            used[it->f]=used[it->s]=false,
	            newNode[it->f]=newNode[it->s]=-1,
	            ranks[it->f]=ranks[it->s]=0;
	            par[it->f]=it->f;
				par[it->s]=it->s;
	        }
			foreach(it, e[i])
				unite(it->f, it->s);
			foreach(it, e[i])
	        {
	            if(!used[it->f])
	            {
	                used[it->f]=true;
	                pa=find(it->f);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->f].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->f);
	            }
	            if(!used[it->s])
	            {
	                used[it->s]=true;
	                pa=find(it->s);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->s].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->s);
	            }
	        }
		}
		queue<int> q;
		q.push(1);
		memset(dist, -1, sizeof(dist));
		dist[1]=0;
		while(!q.empty())
		{
			int cur=q.front();
			q.pop();
			foreach(it, adj[cur])
				if(dist[*it]<0)
					dist[*it]=dist[cur]+1, q.push(*it);
		}
		if(dist[N]<0)
			puts("-1");
		else
			printf("%d\n", dist[N]>>1);
		forn(i, all+1)
	    {
	    	e[i].clear();
	    	adj[i].clear();
	    	used[i]=0;
	    	newNode[i]=0;
	    }
	}
	return 0;
}


Measured memory_bytes: 70912
from collections import Counter

N = int(input())
S = []
for _ in range(N):
    s = list(input())
    s.sort()
    s = ''.join(s)
    S.append(s)

counter = Counter(S)

ans = 0
for v in counter.values():
    ans += v * (v - 1) // 2
print(ans)


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

const int MOD = (int)1e9+7;

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

  vector<long long> dp(2);
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='B')  dp.at(0)++;
    else  dp.at(1)+=dp.at(0);
  }
  cout << dp.at(1) << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 100100100;

int main(){
  ll N;
  cin >> N;
  ll cmin = INF;
  ll ans = 0;
  rep(i, N){
    ll p;
    cin >> p;
    if(p <= cmin){
      cmin = p;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		long a = sc.nextLong(), b = sc.nextLong(), m = sc.nextLong();
		long[] fr = new long[(int)a], wa = new long[(int)b];
		
		long frm = Long.MAX_VALUE;
		for(int i = 0; i < a; i++) {
			long frn = sc.nextLong();
			fr[i] = frn;
			if(frn < frm) frm = frn;
		}
		
		long wam = Long.MAX_VALUE;
		for(int j = 0; j < b; j++) {
			long wan = sc.nextLong();
			wa[j] = wan;
			if(wan < wam) wam = wan;
		}
		
		long to = frm + wam;
		
		long ans = Long.MAX_VALUE;
		
		for(; m > 0; m--) {
			long x = sc.nextLong(), y = sc.nextLong(), c = sc.nextLong();
			long total = fr[(int)x-1]+wa[(int)y-1]-c;
			if(total < ans) ans = total;
		}
		
		if(ans > to) ans = to;
		
		pw.print(ans);
		pw.close();
		
	}
	
	
	static 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: 56924
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		str = br.readLine().split(" ");

		long max = 0;
		long g = 0;

		for (int i = 0; i < n; i++) {
			long a = Long.parseLong(str[i]);
			max = Math.max(max, a);
			g = gcd(a, g);
		}

		if (k <= max && k % g == 0) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 45536
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), L(N), R(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  L[0] = A[0];
  R[N-1] = A[N-1];
  for (int i = 1; i < N; i++) {
    L[i] = __gcd(L[i-1], A[i]);
  }
  for (int i = N-2; i >= 0; i--) {
    R[i] = __gcd(R[i+1], A[i]);
  }
  ll ans = max(R[1], L[N-2]);
  for (int i = 1; i < N-1; i++) {
    ans = max(ans, __gcd(L[i-1], R[i+1]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int ud = 0, st = 0;
    int ans = 0;
    while(st < N){
        ans++;
        for(int i=st; i<N; i++){
            if(A[i] != A[i+1]){
                if(A[i] < A[i+1]){
                    while(A[i] <= A[i+1]) i++;
                }
                else{
                    while(A[i] >= A[i+1]) i++;
                }
                st = i+1;
                break;
            }
            if(i == N-1) st = N;
        }
    }

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

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";
/*
class Compare
{
  public:
    bool operator()(pi a,pi b)
    {
      if(a.first<b.first || (a.first==b.first && a.second>b.second))
        return true;
      return false;
    }
};
*/
int main() 
{
  int k;cin>>k;
  string s;
  cin>>s;
  int n=s.length();
  if(n<=k)
    cout<<s<<endl;
  else
  {
    cout<<s.substr(0,k)+"..."<<endl;
  }
  return 0;
}






























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

#define range(i, start, end) for(int i=start; i<end; i++)
#define rep(i, n) for(int i=0; i<n; i++)

int main() {
  int n;
  cin >> n;
  int a1[n];
  int a2[n];
  rep(i, n) {
    cin >> a1[i];
  }
  rep(i, n) {
    cin >> a2[i]; 
  }
  int max = 0;
  rep(i, n) {
    int sum = 0;
    range(j, 0, i+1) {
      sum += a1[j]; 
    }
    range(j, i, n) {
      sum += a2[j]; 
    }
    max = sum>max ? sum : max;
  }
  cout << max << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		int g,r;

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			g = scan.nextInt();
			r = scan.nextInt();

			if( (g|r) == 0) break;

			for(int i=0; i<g; i++)
			{
				for(int j=0; j<r; j++)
				{
					System.out.print("#");
				}

				System.out.println();
			}

			System.out.println();

		}

		scan.close();

	}
}

Measured memory_bytes: 33100
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
    char c;
    int cnt=0;
    while(cin>>c) if(c=='1') ++cnt;
    cout<<cnt;
    return 0;
  }

Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret


from collections import defaultdict
n = int(input())
A = tuple(map(int, input().split()))
x = A[0]
M1 = defaultdict(int)
M2 = defaultdict(int)
b = False
for a in A:
    x = gcd(x, a)
    if b:
      continue
    for f, cnt in primeFactor(a).items():
      if cnt >= M1[f]:
        M2[f] = M1[f]
        M1[f] = cnt
      elif cnt >= M2[f]:
        M2[f] = cnt
      if M2[f] >= 1:
        b = True
        break
if x != 1:
    print("not coprime")
    exit()
if b:
  print("setwise coprime")
  exit()
print("pairwise coprime")

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

int main() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (a + b) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (a, b, c, d) = {
    let v: Vec<u64> = read_vec();
    (v[0], v[1], v[2], v[3])
  };

  let n_c: u64 = b / c - (a - 1) / c;
  let n_d: u64 = b / d - (a - 1) / d;
  let lcm = (c * d) / gcd(c, d);
  let n_cd: u64 = b / lcm - (a - 1) / lcm;

  println!("{}", (b - a + 1) - (n_c + n_d - n_cd));
}


fn gcd(a: u64, b: u64) -> u64 {


  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r: u64 = a % b;

  return gcd(b, r);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(){
  int x;
  char s[200];
  signed long long stack[200];
  int esp = 0;
 
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      esp--;
      stack[esp - 1] += stack[esp];
    } else if ( s[0] == '-' ){
      esp--;
      stack[esp - 1] -= stack[esp];
    } else if ( s[0] == '*' ){
      esp--;
      stack[esp - 1] *= stack[esp];
    } else {
      x = atoi(s);
      stack[esp] = x;
      esp++;
    }
  }
 
  printf("%lld\n", stack[0]);
 
  return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())



signed main()
{
  int N;
  cin >> N;
  cout << N * N * N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll x;
  cin >> x;
  exrep(a,-1000,1000){
    exrep(b,-1000,1000){
      if(pow(a,5)-pow(b,5)==x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;     
}


Measured memory_bytes: 4076
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

if sum(a) < x:
    print(n-1)
else:
    t = 0
    s = 0
    for i in sorted(a):
        s += i
        if s <= x:
            t += 1
            continue
        else:
            break
    print(t)


Measured memory_bytes: 2696
#include<bits/stdc++.h>
#define int long long

using namespace std;


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

    int n, k, t;
    cin >> n >> k;
    while (k--)
        cin >> t, n -= t;
    if (n <= 0)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

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

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


Measured memory_bytes: 256
void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], w = tmp[1];

    long[][] items = new long[][](4);
    tmp = rdRow;
    long w0 = tmp[0];
    items[0] ~= tmp[1];
    foreach (i; 0 .. n-1)
    {
        tmp = rdRow;
        long wi = tmp[0] - w0, v = tmp[1];
        items[wi] ~= v;
    }

    foreach (i; 0 .. 4)
    {
        items[i].sort!"a > b";
    }

    long[] len = new long[4];
    long[][] total = new long[][](4);
    foreach (i; 0 .. 4)
    {
        total[i].length = items[i].length + 1;
        len[i] = total[i].length;
        foreach (j; 0 .. items[i].length)
        {
            total[i][j+1] = total[i][j] + items[i][j];
        }
    }

    long result;
    foreach (i; 0 .. len[0])
    {
        long w1 = w0 * i;
        if (w1 > w) break;

        long v1 = total[0][i];

        foreach (j; 0 .. len[1])
        {
            long w2 = w1 + (w0 + 1) * j;
            if (w2 > w) break;

            long v2 = v1 + total[1][j];

            foreach (k; 0 .. len[2])
            {
                long w3 = w2 + (w0 + 2) * k;
                if (w3 > w) break;

                long v3 = v2 + total[2][k];

                foreach (l; 0 .. len[3])
                {
                    long w4 = w3 + (w0 + 3) * l;
                    if (w4 > w) break;

                    long v4 = v3 + total[3][l];

                    result = max(result, v4);
                }
            }
        }
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

b = list(map(int, input().split()))

result = 0
for k in range(n):
  a = list(map(int, input().split()))
  
  f = c
  for i, v in enumerate(a):
    f += v * b[i]
  
  if f > 0:
    result += 1
    
print(result)

Measured memory_bytes: 3060
/*
                     .--.  .--.
                    /    \/    \
                   | .-.  .-.   \
                   |/_  |/_  |   \
                   || `\|| `\|    `----.
                   |\0_/ \0_/    --,    \_
 .--"""""-.       /              (` \     `-.
/          \-----'-.              \          \
\  () ()                         /`\          \
|                         .___.-'   |          \
\                        /` \|      /           ;
 `-.___             ___.' .-.`.---.|             \
    \| ``-..___,.-'`\| / /   /     |              `\
     `      \|      ,`/ /   /   ,  /
             `      |\ /   /    |\/
              ,   .'`-;   '     \/
         ,    |\-'  .'   ,   .-'`
       .-|\--;`` .-'     |\.'
      ( `"'-.|\ (___,.--'`'   
       `-.    `"`          _.--'
          `.          _.-'`-.
            `''---''``       `.
*/

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for (char &c : s) {
        if (c == '?') c = 'D';
    }
    cout << s << '\n';
    return 0;
} 

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, t;

  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
  return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import accumulate
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = (accumulate(reversed(a)))
    a_sum = list(reversed(list(a_sum)))
    sum = 0
    mod = 1000000007
    for i in range(n-1):
        sum += a[i]*a_sum[i+1]
    print(sum%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31260
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int s;
   cin >> s;
   int D = s % 10;
   s /= 10;
   int C = s % 10;
   s /= 10;
   int B = s % 10;
   s /= 10;
   int A = s % 10;
   int pm[] = {-1, 1};
   char pm2[] = {'-', '+'};
   for (int ab = 0; ab < 2; ab++) {
      for (int bc = 0; bc < 2; bc++) {
         for (int cd = 0; cd < 2; cd++) {
            int tmp = A;
            tmp += pm[ab] * B;
            tmp += pm[bc] * C;
            tmp += pm[cd] * D;
            if (tmp == 7) {
               cout << A << pm2[ab] << B << pm2[bc] << C << pm2[cd] << D << "=7" << endl;
               return 0;
            }
         }
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int x, gra = 0;

  scanf("%d", &x);

  while (x >= 500) {
    x -= 500;
    gra += 1000;
  }
  while (x >= 5) {
    x -= 5;
    gra += 5;
  }

  printf("%d\n", gra);

  return 0;
}






Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, A, B;
	cin >> N >> A >> B;
	VI X(N);
	REP(i, N)cin >> X[i];

	int ans = 0;
	REP(i, N - 1) {
		ans += min((X[i + 1] - X[i])*A, B);
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int x1, x2, y1_, y2_;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> x1 >> y1_ >> x2 >> y2_;
    int x3 = x2-(y2_-y1_), y3 = y2_+(x2-x1), x4 = x3-(x2-x1), y4 = y3-(y2_-y1_);
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
d = {i:0 for i in range(1,M+1)}

for _ in range(N):
  L = list(map(int,input().split()))[1:]
  for i in L:
    d[i] += 1
    
cnt = sum([1 for k,v in d.items() if v == N])
print(cnt)
  

Measured memory_bytes: 9120
#include <iostream>
#include <vector>

using namespace std;

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

	vector<char> v;

	v.push_back(str.at(0));
	int i = 1;
	while (i < str.length()) {
		char c = str.at(i);
		if (v.size() == 0) {
			v.push_back(c);
		}
		else if (c == 'S') {
			v.push_back(c);
		}
		else {
			char &tmp = v.back();
			if (tmp == 'S') {
				v.pop_back();
			}
			else {
				v.push_back(c);
			}
		}
		i++;
	}

	cout << v.size() << endl;
}


Measured memory_bytes: 772
#include <iostream>

using namespace std;
using ll = long long;

const int MAX_N = 1000;
const int MAX_M = 2000;
const ll INF = 1LL << 50;

// 頂点fromから頂点toへのコストcostの辺
struct edge {
    int from, to;
    ll cost;
};

edge es[MAX_M];     // 辺

ll d[MAX_N];       // 始点から各頂点への最大距離
int N, M;

// s番目の頂点から各頂点への最短距離を求める
bool shortest_path(int s) {
    for (int i = 0; i < N; ++i) {
        d[i] = INF;
    }
    d[s] = 0;
    for (int loop = 0; loop < N - 1; ++loop) {
        for (int i = 0; i < M; ++i) {
            edge e = es[i];
            if ((d[e.from] != INF && d[e.to] > d[e.from] + e.cost)) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    bool negative[MAX_N];
    for (int i = 0; i < N; ++i) {
        negative[i] = false;
    }
    for (int loop = 0; loop < N; ++loop) {
        for (int i = 0; i < M; ++i) {
            edge e = es[i];
            if ((d[e.from] != INF && d[e.to] > d[e.from] + e.cost)) {
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
//            if (negative[e.from] == true) {
//                negative[e.to] = true;
//            }
        }
    }
    return negative[N - 1];
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int from, to;
        ll cost;
        cin >> from >> to >> cost;
        es[i].from = from - 1;
        es[i].to = to - 1;
        es[i].cost = -cost;
    }
    if (shortest_path(0)) {
        cout << "inf" << endl;
    } else {
        cout << -d[N - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x,y; scanf ("%d %d",&x,&y);
  for (int i=0;i<=x;i++){
if (i * 2 + (x-i)*4==y){
puts("Yes");
  return 0;
}
  }
  puts("No");
return 0;
}

Measured memory_bytes: 3132
#include<stdio.h>

int main(void){
    int i,j,r,c,x[101][101]={0};
    
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&x[i][j]);
            x[i][c]+=x[i][j];
        }
    }
    
    for(i=0;i<=c;i++){
        for(j=0;j<r;j++){
            x[r][i]+=x[j][i];
        }
    }
    
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            if(j==c){
                printf("%d",x[i][j]);
            }else{
                printf("%d ",x[i][j]);
            }
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2040
import java.util.*;
import java.io.*;
import java.util.Arrays; 
import java.util.ArrayList; 
import java.util.Collections; 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try (PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            FastScanner in = new FastScanner(System.in);
            int nRolls = in.nextInt();
            int nDices = nRolls*2;
            int[] dices = in.nextIntArray(nDices);

            boolean check = false;

            for(int i = 0; i < nDices - 4; i = i+2) {
                if(dices[i] == dices [i+1] && dices[i+2] == dices [i+3] && dices[i+4] == dices [i+5]) {
                    check = true;
                    break;
                }
            }
            if(check) {
                out.println("Yes");
            } else {
                out.println("No");
            }



        } finally {
            //out.close();
        }
        
           
    }
}


class FastScanner {
   private final BufferedReader br;
   private StringTokenizer st;
 
    FastScanner(InputStream InputStream) {
        br = new BufferedReader(new InputStreamReader(InputStream));
    }
    
    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    
    int nextInt() {
        return Integer.parseInt(next());
    }
    
    long nextLong() {
        return Long.parseLong(next());
    }
    
    double nextDouble() {
        return Double.parseDouble(next());
    }


    
    ArrayList<Integer> nextIntList(int count) {
        ArrayList<Integer> array = new ArrayList<>();
        for (int n = 0; n < count; n++) {
            int number = nextInt();
            array.add(number);
        }
        return array;
    }
    
    int[] nextIntArray(int count) {
        int[] array = new int[count];
        for (int n = 0; n < count; n++) {
            array[n] = nextInt();
        }
        return array;
    }
}

Measured memory_bytes: 33016