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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll H,N;
    cin >> H >> N;
    ll sum = 0;

    REP(_,N) {
        int atk;
        cin >> atk;

        sum += atk;
    }
    string ans = sum >= H ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n*3];
  for (long i = 0; i < n*3; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n*3, sizeof(long), cmpnum);
  long sum = 0;
  for (long i = 1; i < n*2; i += 2) {
    sum += a[i];
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 4860
#include<cstdio>
#include<math.h>

using namespace std;
typedef long long ll;

int main(){
   ll q;
   scanf("%lld",&q);
   for(ll i=0;i<q;i++){
      ll a,b;
      scanf("%lld%lld",&a,&b);
      ll x=a*b;
      ll m=(ll)sqrt(x);
      if(m*m!=x){
         if(m*(m+1)<x) printf("%lld\n",2*m-1);
         else printf("%lld\n",2*(m-1));
      }else{
         if(m!=a) printf("%lld\n",2*(m-1)-1);
         else printf("%lld\n",2*(m-1));
      }
   }
}

Measured memory_bytes: 128
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n;
    for(;sc.hasNext();){
      n = sc.nextInt();
      n %= 39;
      if(n == 0)n = 39;
      out.printf("3C%02d%n", n);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

using namespace std;


int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i < N; i++){
    cin >> H[i];
  }
  int count = 0;
  int max_count = 0;
  for(int i=0; i < N-1; i++){
    if(H[i] < H[i+1]){
      if(max_count < count){
        max_count = count;
      }
      count = 0;
    }else{
      count++;
    }
  }
  if(max_count < count){
    max_count = count;
  }
  cout << max_count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
  int ocs[100], ods[100];
  for(int t = 1;; t++) {
    int n, r;
    cin >> n >> r;
    if(n == 0) break;
    int *cs = ocs;
    int *ds = ods;
    for(int i = 0; i < n; i++) {
      cs[i] = n - i;
    }
    for(int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      for(int j = 0; j < c; j++) {
        ds[j] = cs[p - 1 + j];
      }
      for(int j = 0; j < p - 1; j++) {
        ds[j + c] = cs[j];
      }
      for(int j = c + p - 1; j < n; j++) {
        ds[j] = cs[j];
      }
      int *tmp = cs;
      cs = ds;
      ds = tmp;
    }
    cout << cs[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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; }


i64 n, wide, k, x[202020], a[202020];
P p[202020];

i64 seg1[(1<<19)-1], seg2[(1<<19)-1];
void add(int a, int b, i64 x, int k, int l, int r){
	if(a <= l && r <= b){
		seg1[k] += x;
	}
	else if(l < b && a < r){
		seg2[k] += (min(b,r) - max(a,l)) * x;
		add(a,b,x,k*2+1,l,(l+r)/2);
		add(a,b,x,k*2+2,(l+r)/2,r);
	}
}
i64 sum(int a, int b, int k, int l, int r){
	if(b <= l || r <= a){
		return 0;
	}
	else if(a <= l && r <= b){
		return seg1[k] * (r-l) + seg2[k];
	}
	else{
		i64 res = (min(b,r) - max(a,l)) * seg1[k];
		res += sum(a,b,k*2+1,l,(l+r)/2);
		res += sum(a,b,k*2+2,(l+r)/2,r);
		return res;
	}
}

int main(){
	cin >> n >> wide >> k;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> a[i];
		p[i] = P(x[i], a[i]);
	}
	
	sort(p,p+n);
	for(int i = 0; i < n; i++){
		a[i] = p[i].second;
		x[i] = p[i].first;
	}
	
	for(int i = 0; i < n; i++){
		add(i,i+1, a[i], 0,0,n);
	}
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		a[i] = sum(i,i+1,0,0,n);
		if(a[i] <= 0) continue;
		
		int pos = upper_bound(x,x+n, x[i]+wide*2)-x;
		i64 m = (a[i]+k-1) / k;
		ans += m;
		add(i,pos,-m*k,0,0,n);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 14720
#include<iostream>
#include<stdlib.h>
 
using namespace std;
 
struct Node{
  int key;
  Node* next;
  Node* prev;
};
 
struct List{
  Node* nil;
 
  void init(){
    nil=(Node*)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
    nil->key=0;
  }
 
  Node* find(int key){
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(i->key==key)return i;
    }
    return nil;
  }
 
  void insert(Node *x){
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
  }
  
  void add(int x){
    Node* p = (Node*)malloc(sizeof(Node));
    p->key=x;
    insert(p);
  }
   
  void delete_x(int key){
    Node* x=find(key);
    if(x==nil)return;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
   
  void deleteFirst(){
    Node* x = nil->next;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
   
  void deleteLast(){
    Node* x = nil->prev;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);   
  }
 
  void output(){
    int flg=0;
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(flg)cout<<' ';
      cout<<i->key;
      flg=1;
    }
    cout<<endl;
  }
};
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  List list;
  list.init();
  int n,x;
  string str;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    if(str=="insert"){
      cin>>x;
      list.add(x);
    }else if(str=="delete"){
      cin>>x;
      list.delete_x(x);
    }else if(str=="deleteFirst"){
      list.deleteFirst();
    }else {
      list.deleteLast();
    }
  }
  //cout<<'-'<<endl;
  list.output();
}



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

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

  char x,y;cin>>x>>y;
  if(x==y){
    puts("=");
  }else if (x<y){
    puts("<");
  }else{
    puts(">");

  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static class Route {
		int to;
		int cost;
		long time;

		public Route(int to, int cost, long time) {
			this.to = to;
			this.cost = cost;
			this.time = time;
		}
	}
	static class Graph {
		int N;
		ArrayList<ArrayList<Route>> node;
		int[] exRate;
		long[] exTime;
		
		public Graph(int N) {
			this.N = N;
			node = new ArrayList<>();
			for(int i=0; i<N; i++)
				node.add(new ArrayList<Route>());
			exRate = new int[N];
			exTime = new long[N];
		}
		
		public void addEdge(int from, int to, int cost, int time) {
			node.get(from).add(new Route(to, cost, time));
			node.get(to).add(new Route(from, cost, time));
		}
		
		public void addEx(int i, int rate, int time) {
			exRate[i] = rate;
			exTime[i] = time;
		}
	}
	
	static class Path {
		int to;
		int have;
		long time;
		public Path(int to, int have, long time) {
			this.to = to;
			this.have = have;
			this.time = time;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int S = sc.nextInt();
		
		Graph g = new Graph(N);
		for(int i=0; i<M; i++) {
			g.addEdge(sc.nextInt()-1, sc.nextInt()-1, sc.nextInt(), sc.nextInt());
		}
		for(int i=0; i<N; i++) {
			g.addEx(i, sc.nextInt(), sc.nextInt());
		}
		
		int maxCost = (N-1)*50;
		if(S>maxCost)
			S = maxCost;
		final long INF = (long)1e20;
		long[][] time = new long[N][maxCost+1];
		for(int i=0; i<N; i++)
			Arrays.fill(time[i], INF);
		
		LinkedList<Path> q = new LinkedList<>();
		q.add(new Path(0, S, 0));
		
		while(!q.isEmpty()) {
			Path p = q.poll();
			if(time[p.to][p.have] <= p.time)
				continue;
			time[p.to][p.have] = p.time;
			for(Route r : g.node.get(p.to)) {
				int next = r.to;
				int have = p.have-r.cost;
				if(have<0)
					continue;
				long t = p.time + r.time;
				if(time[next][have]>t)
					q.add(new Path(next, have, t));
			}
			
			int afterCoin = Math.min(p.have + g.exRate[p.to], maxCost);
			long afterTime = p.time + g.exTime[p.to];
			if(time[p.to][afterCoin] > afterTime) {
				q.add(new Path(p.to, afterCoin, afterTime));
			}
		}
		
		for(int i=1; i<N; i++) {
			long min = Long.MAX_VALUE;
			for(int j=0; j<maxCost; j++) {
				min = Math.min(min, time[i][j]);
			}
			System.out.println(min);
		}
		
		sc.close();
	}
}



Measured memory_bytes: 89980
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define ll long long

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    //入力
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(m, 0));
    rep(j, n) {
        rep(i, m) { cin >> a[j][i]; }
    }
    vector<ll> b(m, 0);
    rep(i, m) { cin >> b[i]; }

    //処理 出力
    rep(j, n) {
        int c = 0;
        rep(i, m) { c += a[j][i] * b[i]; }
        cout << c << "\n";
    }

    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define INF 10000000000;
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll n, i, j;
    string s, t;
    cin >> n;
    ll ans[26];
    
    for(i=0; i<26; i++)
        ans[i]=INF;
    
    for(i=0; i<n; i++) {
        ll cnt[26]={0};
        cin >> s;
        
        for(j=0; j<(ll)s.size(); j++) {
            cnt[s[j]-'a']++;
        }
        
        for(j=0; j<26; j++) {
            ans[j]=min(ans[j], cnt[j]);
        }
    }
    
    for(i=0; i<26; i++) {
        for(j=0; j<ans[i]; j++)
            t+=(char)(i+'a');
    }
    cout << t << endl;
    
}

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

int main() {
  int n; cin >> n;
  vector<string> s(n);
  map<char,int> m;
  rep(i,n) cin >> s[i];
  rep(i,n) {
    if (i==0) {
      rep(j,s[i].size()) {
        m[s[i][j]]++;
      }
    } else {
      map<char,int> mt;
      rep(j,s[i].size()) {
        mt[s[i][j]]++;
      }
      for (auto a: m) {
        if (mt.count(a.first)) {
          if (mt[a.first] < a.second) m[a.first] = mt[a.first];
        } else m.erase(a.first);
      }
    }
  }
  for (auto a: m) {
    rep(i,a.second) cout << a.first;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

vector<pair<int, int>> mov = {make_pair(0, 1),make_pair(0, -1),make_pair(1, 0),make_pair(-1, 0) };
int bfs(vector<vector<char>>& field, int H, int W, int sh, int sw, int gh, int gw) {
    deque<pair<pair<int, int>, int>> nd;
    nd.push_back(make_pair(make_pair(sh, sw), 0));
    vector<vector<bool>> is_visited(H, vector<bool>(W, false));
    is_visited[sh][sw] = true;
    int ans = 0;
    while (1) {
        if (nd.size() <= 0) break;
        auto now = nd.front();
        nd.pop_front();
        for (auto &m : mov) {
            int new_h = now.first.first + m.first;
            int new_w = now.first.second + m.second;
            if (new_h >= 0 && new_h < H && new_w >= 0 && new_w < W) {
                if (field[new_h][new_w] == '#') continue;
                if (is_visited[new_h][new_w] == true) continue;
                if (new_h == gh && new_w == gw)
                    return now.second + 1;
                nd.push_back(make_pair(make_pair(new_h, new_w), now.second + 1));
                is_visited[new_h][new_w] = true;
            }
        }
    }
    return -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    vector<vector<char>> field(H, vector<char>(W, '.'));
    rep(i, H) {
        rep(j, W) cin >> field[i][j];
    }
    int ans = 0;
    rep(sh, H) {
        rep(sw, W) {
            rep(gh, H) {
                rep(gw, W) {
                    if (gw == sw && gh == sh) continue;
                    if (field[sh][sw] == '#') continue;
                    if (field[gh][gw] == '#') continue;
                    ans = max(ans, bfs(field, H, W, sh, sw, gh, gw));
                }
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;


int main(){
  int N;cin>>N;
  vector<ll>A(N);
  rep(i,N){cin >>A[i];}
  int flag=0;
  ll memo=A[N-1],g=A[N-1];
  for(ll i=N-2;i>=0;i--){
  	ll h=A[i];
  	if(h>=2ll+g){flag=1;break;}
    else if(h==(g+1ll)){continue;}
    else{g=h;}
  }
  if(flag==1){cout<<"No";}
  else{cout<<"Yes";}
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int main(){
    int a,b,c;
    cin >> a >> b >>c;
    if(b-a == c-b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

#define all(x) (x).begin(), (x).end()
#define pb push_back

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

int main(){
	int r,g,b,n;
	cin>>r>>g>>b>>n;

	int ans=0;
	for (int i = 0; i <= 3000; ++i){
		if(i*r>n)continue;
		for (int j = 0; j <= 3000; ++j){
			if(i*r+j*g>n)break;
			if(i*r+j*g==n){
				ans++;
				continue;
			}
			if((n-i*r-j*g)>=b&&(n-i*r-j*g)%b==0)ans++;
		}
	}

	cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];	
	ll res=0;
	sort(a,a+n);
	{
		int l=0; int r=n-1;
		deque<ll> vec;
		for(int i=0;i<n-2;i++)
		{
			if(i%2==0) vec.pb(a[r--]);
			else vec.pb(a[l++]);
		}
		vec.push_front(a[l]); vec.pb(a[l+1]);
		/*
		for(int i=0;i<n;i++)
		{
			cerr<<vec[i]<<' ';
		}cerr<<'\n';
		*/
		ll ans=0;
		for(int i=0;i+1<n;i++)
		{
			ans+=abs(vec[i]-vec[i+1]);
		}
		res=max(res,ans);
	}
	{
		int l=0; int r=n-1;
		deque<ll> vec;
		for(int i=0;i<n-2;i++)
		{
			if(i%2==0) vec.pb(a[r--]);
			else vec.pb(a[l++]);
		}
		vec.pb(a[l]); vec.push_front(a[l+1]);
		/*
		for(int i=0;i<n;i++)
		{
			cerr<<vec[i]<<' ';
		}cerr<<'\n';
		*/
		ll ans=0;
		for(int i=0;i+1<n;i++)
		{
			ans+=abs(vec[i]-vec[i+1]);
		}
		res=max(res,ans);
	}
	{
		int l=0; int r=n-1;
		deque<ll> vec;
		for(int i=0;i<n-2;i++)
		{
			if(i%2==1) vec.pb(a[r--]);
			else vec.pb(a[l++]);
		}
		vec.push_front(a[l]); vec.pb(a[l+1]);
		/*
		for(int i=0;i<n;i++)
		{
			cerr<<vec[i]<<' ';
		}cerr<<'\n';
		*/
		ll ans=0;
		for(int i=0;i+1<n;i++)
		{
			ans+=abs(vec[i]-vec[i+1]);
		}
		res=max(res,ans);
	}
	{
		int l=0; int r=n-1;
		deque<ll> vec;
		for(int i=0;i<n-2;i++)
		{
			if(i%2==1) vec.pb(a[r--]);
			else vec.pb(a[l++]);
		}
		vec.pb(a[l]); vec.push_front(a[l+1]);
		/*
		for(int i=0;i<n;i++)
		{
			cerr<<vec[i]<<' ';
		}cerr<<'\n';
		*/
		ll ans=0;
		for(int i=0;i+1<n;i++)
		{
			ans+=abs(vec[i]-vec[i+1]);
		}
		res=max(res,ans);
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 1920
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		int y = 0;
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			y ^= a[i];
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; ++i) {
			int x = y ^ a[i];
			char c = (i < n - 1) ? ' ' : '\n';
			pw.printf("%d%c", x, c);
		}
		pw.flush();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public String nextLine() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}

		while (b != '\n') {
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

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

Measured memory_bytes: 99312
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()

	if (a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7) && a+b+c == 17 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
	string input;
	cin >> input;
	int a,b,c,d,w,x,y;
	a = input[0]-'0';
	b = input[1]-'0';
	c = input[2]-'0';
	d = input[3]-'0';
	bool flag;
	flag=true;
	for(int i = 0;i<2&&flag;i++){
		for(int j = 0;j<2&&flag;j++){
			for(int k = 0;k<2&&flag;k++){
				w=(i*2-1)*b;
				x=(j*2-1)*c;
				y=(k*2-1)*d;
				if(a + w + x + y==7){
					cout << a;
					if(w>=0)
						cout  << "+";
					cout << w;
					if(x>=0)
						cout  << "+";
					cout << x;
					if(y>=0)
						cout  << "+";
					cout << y << "=7" <<endl;
					flag=false;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

int digit(int n) {
        if(n == 0) return 1;
        int ret = 0;
        while(n > 0) {
                ret++;
                n /= 10;
        }
        return ret;
}

int main() {
        int n, m;
        cin >> n >> m;
        vector<int> s(m), c(m);
        for(int i = 0; i < m; i++) {
                cin >> s[i] >> c[i];
        }

        for(int i = 0; i <= 999; i++) {
                if(digit(i) == n) {
                        bool flag = true;
                        for(int j = 0; j < m; j++) {
                                if(s[j] > n) continue;
                                if(s[j] == 1) {
                                        if(i / (int)pow(10, n - 1) != c[j]) flag = false;
                                } else if(s[j] == 2) {
                                        if((int)(i / (int)pow(10, n - 2)) % 10 != c[j]) flag = false; 
                                } else {
                                        if(i % 10 != c[j]) flag = false;
                                }
                        }
                        if(flag) {
                                cout << i << endl;
                                return 0;
                        }
                }
        }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,s;
	cin>>k>>s;
	int x,y,z;
	int ct=0;
	for(x=0;x<=k;x++)
	{
		for(y=0;y<=k;y++)
		{
			if(s-x-y>=0&&s-x-y<=k)ct++;
		}
	}
	cout<<ct;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <list>
//#include <unordered_map>
//#include <unordered_set>
#include <ctime>

using namespace std;

typedef long long			LL;
typedef long double			LD;
typedef unsigned long long	ULL;
typedef unsigned int		UI;
typedef unsigned short		US;

//#define FILE
#define fr			first
#define sc			second
#define mp			make_pair
#define pb			push_back
#define all(x)		(x).begin(), (x).end()
#define sz(x)		LL((x).size())
#define F(i,a,b)	for (int i = a; i < b; i++)
#define R(i,a,b)	for (int i = a - 1; i >= b; i--)

const UI		N = 200005;
const LL		Mod = 1000000007;
const LL		INF = 1000000000;
const LL		INF64 = 1000000000000000000;
const LD		PI = acos(-1.0);
const LD		E = 2.7182818284590452353602874713527;
const UI		dir = 4;
const int		prime = 31;

LL gcd(LL a, LL b) { return a != 0 ? gcd(b%a, a) : b; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL length(LL n) { return n < 10 ? 1 : 1 + length(n / 10); }

LL W, H;
string S[400];
bool visited[400][400];
vector< set< pair<int, int> > > components;



void dfs(int r, int c) {
	visited[r][c] = true;
	components.back().insert(mp(r, c));
	F(i, -1, 2)
		F(j, -1, 2) {
			if (abs(i + j) == 1 && r + i >= 0 && r + i < H && c + j >= 0 && c + j < W && S[r][c] != S[r + i][c + j] && !visited[r + i][c + j]) {
				dfs(r + i, c + j);
			}
		}
}

void input()
{
	cin >> H >> W;
	F(i, 0, H)
		cin >> S[i];
}

void solve()
{
	F(i, 0, H)
		F(j, 0, W) {
			if (!visited[i][j]) {
				components.pb(set< pair<int, int> >());
				dfs(i, j);
			}
		}

	LL ans = 0;
	for (auto& component : components) {
		LL w = 0, b = 0;
		for (auto elem : component) {
			w += (S[elem.fr][elem.sc] == '.');
			b += (S[elem.fr][elem.sc] == '#');
		}
		ans += w * b;
	}
	cout << ans << endl;
}	

int main()
{

#ifdef FILE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int testcases = 1;
	// cin >> testcases;
	while (testcases--) {
		input();
		//clock_t start = clock();
		solve();
		//printf("---------------------\n%.5f seconds\n---------------------\n", (clock() - start + 0.) / CLOCKS_PER_SEC);
	}

	return 0;
}

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

#define fore(i, a, b) for(int i = a; i < b; i++)
#define forn(i, n) fore(i, 0, n)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ford(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;

typedef long long ll;

const int N = 100005;

int main(){
	int n, k, x;

	scanf("%d %d", &n, &k);

	map<int, int> m;

	forn(i, n) scanf("%d", &x), m[x]++;

	vector<int> v;
	for(pair<int, int> q : m) v.pb(q.ss);

	sort(v.begin(), v.end());

	int ans = 0;

	int l = int(v.size()) - k;

	forn(i, l) ans += v[i];

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




    return 0;
}


Measured memory_bytes: 10748
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.IO
import qualified Data.Vector.Unboxed.Mutable as UM
import Control.Monad.State.Strict

main = do
  [h,w] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  -- h, w <= 400
  ss <- V.replicateM h BS.getLine
  -- forall s in ss. BS.length s == w
  arr <- newArray ((0,0),(h-1,w-1)) (-1) :: IO (IOUArray (Int,Int) Int)
  -- num_b_w <- UM.new (h * w) :: IO (UM.IOVector (Int,Int))
  let search :: Int -> Int -> Int -> Int -> IO Int
      search !acc !k !i !j
        | i >= h = return acc
        | j >= w = search acc k (i+1) 0
        | otherwise = do
            v <- readArray arr (i,j)
            (nb,nw) <- if (v == -1)
                       then flip execStateT (0,0) $
                            if (ss V.! i) `BS.index` j == '#'
                            then search_black k i j -- black
                            else search_white k i j
                       else return (0,0)
            -- (nb,nw) <- UM.read num_b_w k
            search (acc + nb * nw) (k+1) i (j+1)
      search_black :: Int -> Int -> Int -> StateT (Int,Int) IO ()
      search_black !k !i !j
        | i < 0 || j < 0 || i >= h || j >= w = return ()
        | (ss V.! i) `BS.index` j == '#' = do
            v <- lift $ readArray arr (i,j)
            when (v == -1) $ do
              lift $ writeArray arr (i,j) k
              modify' (\(b,w) -> let !b' = b+1 in (b',w))
              -- UM.modify num_b_w (\(b,w) -> (b+1,w)) k
              search_white k (i-1) j
              search_white k i (j-1)
              search_white k (i+1) j
              search_white k i (j+1)
        | otherwise = return ()
      search_white :: Int -> Int -> Int -> StateT (Int,Int) IO ()
      search_white !k !i !j
        | i < 0 || j < 0 || i >= h || j >= w = return ()
        | (ss V.! i) `BS.index` j == '.' = do
            v <- lift $ readArray arr (i,j)
            when (v == -1) $ do
              lift $ writeArray arr (i,j) k
              modify' (\(b,w) -> let !w' = w+1 in (b,w'))
              -- UM.modify num_b_w (\(b,w) -> (b,w+1)) k
              search_black k (i-1) j
              search_black k i (j-1)
              search_black k (i+1) j
              search_black k i (j+1)
        | otherwise = return ()
  result <- search 0 0 0 0
  {-
  arr' <- freeze arr :: IO (UArray (Int,Int) Int)
  forM_ [0..h-1] $ \i -> do
    print [arr' ! (i,j) | j <- [0..w-1]]
  -}
  print result


Measured memory_bytes: 11004
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int main(int argc, char *argv[]){
    // int a, b, c; cin >> a >> b >> c;
    v X(3); cin >> X[0] >> X[1] >> X[2]; //sort(all(X), greater<int>);
    int cnt = 0;
    int even = 0; int odd = 0;
    v Y(3);
    rep(i, 3){
        if(X[i] % 2 == 0){
            even++; 
            Y[i] = 1;
        }else{
            odd++;
            Y[i] = 0;
        }
    }
    if(even == 2 && odd == 1){
        cnt++;
        rep(i, 3){ if(Y[i] == 1) X[i]++; }
    }else if(even == 1 && odd == 2){
        cnt++;
        rep(i, 3){ if(Y[i] == 0) X[i]++; }
    }
    sort(all(X), greater<int>());
    while(X[0] != X[1]){ X[1] += 2; cnt++; }
    while(X[0] != X[2]){ X[2] += 2; cnt++; }
    cout << cnt << endl;
    // cout << X[0] << " " << X[1] << " " << X[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

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

	set<string> memo;
	vector<string> subs;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 1; j <= k; j++) {
			auto t = s.substr(i, j);
			if (memo.count(t) == 0) {
				memo.insert(t);
				subs.emplace_back(t);
			}
		}
	}

	sort(subs.begin(), subs.end());
	// for (auto t: subs) {
	// 	cout << t << endl;
	// }
	cout << subs[k-1] << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

int N;

void dfs(string s, char mx){
    if(s.length()==N){
        cout<<s<<endl;
    }else{
        for (char i = 'a'; i <= mx; ++i) {
            dfs(s+i, (i==mx)?(char)(mx+1):mx);
        }
    }
}

int main(void){

    cin>>N;
    dfs("", 'a');


    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
using namespace std;
const int mod=1e9+7;
int ans,fac[2000005],inv[2000005],x[10],y[10];
int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)r=1ll*r*a%mod;return r;}
int C(int n,int m){return n<m||n<0||m<0?0:1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int count(int xx,int yy,int kd)
{
	int xx1,xx2,yy1,yy2;
	if(!kd){xx1=xx-x[1],xx2=xx-x[0],yy1=yy-y[1],yy2=yy-y[0];}else{xx1=x[4]-xx,xx2=x[5]-xx,yy1=y[4]-yy,yy2=y[5]-yy;}
	int res=(((C(xx1+yy1,xx1)-C(xx1+yy2+1,xx1)+mod)%mod-C(xx2+yy1+1,yy1)+mod)%mod+C(xx2+yy2+2,xx2+1))%mod;
	return res; 
}
int main()
{
	for(int i=fac[0]=1;i<=2000000;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[2000000]=pw(fac[2000000],mod-2);
	for(int i=2000000;i>=1;i--)inv[i-1]=1ll*inv[i]*i%mod; 
	for(int i=0;i<=5;i++)scanf("%d",&x[i]);
	for(int i=0;i<=5;i++)scanf("%d",&y[i]);
	for(int i=x[2];i<=x[3];i++)
	{
		(ans+=1ll*count(i,y[2],1)*count(i,y[2]-1,0)%mod*(mod-i-y[2])%mod)%=mod;
		(ans+=1ll*count(i,y[3]+1,1)*count(i,y[3],0)%mod*(i+y[3]+1)%mod)%=mod;
	}
	for(int i=y[2];i<=y[3];i++)
	{
		(ans+=1ll*count(x[2],i,1)*count(x[2]-1,i,0)%mod*(mod-i-x[2])%mod)%=mod;
		(ans+=1ll*count(x[3]+1,i,1)*count(x[3],i,0)%mod*(i+x[3]+1)%mod)%=mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

constexpr int mod = 1000000007;
struct mint {
    long long x;
    constexpr mint(long long x = 0) : x((x% mod + mod) % mod) {}
    constexpr mint operator-() const {
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    constexpr mint inv() const {
        return pow(mod - 2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
};
ostream& operator<<(ostream & os, const mint & m) {
    os << m.x;
    return os;
}

mint comb(ll n, ll r)
{
    mint res = 1;
    for (int i = 1; i <= r; i++)
    {
        res *= n;
        res /= i;
        n--;
    }
    return res;
}

int main()
{
    mint n, a, b; cin >> n.x >> a.x >> b.x;
    mint multi = 2;
    cout << multi.pow(n.x) - comb(n.x, a.x) - comb(n.x, b.x) - 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define M 1000000
int main(){

  int i,j,n,q,C=0,S[M],T[M];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	C++;
	break;
      }
    }
  }

  printf("%d\n",C);
  return 0;
}



Measured memory_bytes: 2108
from collections import Counter
n = int(input())
s = [0]*n
for i in range(n):
  s[i] = input()
dum = Counter(s)
s_most = dum.most_common()
s_len = len(s_most)
ans = 0
for i in range(s_len):
  if s_most[i][1]%2 != 0:
    ans += 1
print(ans)

Measured memory_bytes: 24428
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int H,N;
    ll A;
    ll ans=0;
    cin>>H>>N;
    rep(i,N) {cin>>A; ans+=A;}
    if(H<=ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

typedef long long LL;

LL n, ans;

int main() {
    read(n);
    for (int i = 1; i <= n; ++i)    ans += i % 3 != 0 && i % 5 != 0 ? i : 0;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3764
N = int(input())
X = list(map(int,(input().split())))
xs = sorted(X)

a = int(N/2)
b = a-1

aa = xs[a]
bb= xs[b]

A = aa
B = bb


for i in X:
  if i >= A:
    print(B)
  else:
    print(A)
                

Measured memory_bytes: 93780
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int cnt = 0;
	if (A == B) { cnt += 1; }
	if (B == C) { cnt += 1; }
	if (C == A) { cnt += 1; }
	if (cnt == 1) {
		cout <<"Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100
#define MAX_W 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, W;
ll v[MAX_N], w[MAX_N];
ll dp[MAX_N + 1][MAX_W + 1];

void solve()
{
  dp[0][0] = 0;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = W; j >= 0; j--) {
      if (j < w[i])
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
    }
  }
  cout << dp[N][W] << endl;
}

int main(void)
{
  cin >> N >> W;
  REP(i, N) cin >> w[i] >> v[i];
  solve();
  return 0;
}


Measured memory_bytes: 78336
import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
A=list(itertools.permutations(range(1,N+1)))
L=len(A)
X=[]
for l in range(L):
    if A[l]==P or A[l]==Q:
        X.append(l)
print(max(X)-min(X))


Measured memory_bytes: 8052
import math

l = [int(input()) for i in range(5)]

time = 0
last = 0
for i in range(5):
    time += math.ceil(l[i] / 10) * 10
    if l[i] % 10 == 0:
        continue
    else:
        last = max(last, 10 - (l[i] % 10))

print(time - last)


Measured memory_bytes: 9080
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'B'){
			int j = 1;
			while(true){
				if(s[i-j] != 'B'){
					s[i-j] = 'B';
					break;
				}
				else{
					j++;
				}
			}
		}
	}
	for(int i = 0; i < s.length(); i++){
		if(s[i] != 'B') cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int m,w;
  while(cin>>m>>w){
    if(m==0)break;
    int a,an=0,dp[1<<12]={};
    vector<int>bm,bw;
    for(int i=0;i<m;i++)cin>>a,bm.push_back(a);
    for(int i=0;i<w;i++)cin>>a,bw.push_back(a);
    if(m>w)swap(bm,bw),swap(m,w);
    for(int i=0;i<m;i++)
      for(int S=0;S<(1<<w);S++)
	if(__builtin_popcount(S)==i)
	  for(int j=0;j<w;j++){
	    if(!(S&(1<<j))){
	      int p=abs(bm[i]-bw[j]);
	      int e=p*(p-30)*(p-30);
	      dp[S+(1<<j)]=max(dp[S+(1<<j)],dp[S]+e);
	      an=max(an,dp[S+(1<<j)]);
	    }
	  }
    cout<<an<<endl;
  }
  return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int N,ll A,ll B,vi& x) {
    vi dx(N-1);
    rep(i,N-1) dx[i] = x[i+1] - x[i];
    vector<ll> cx(N-1);
    rep(i,N-1) {
        cx[i] = min(A*dx[i], B);
    }
    return accumulate(ALL(cx), 0LL);
}

int main() {
    int N,A,B; cin >> N >> A >> B;
    read_cr();
    vi x(N);
    loadvec(x, N);
    cout << solve(N,A,B,x) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>

int main()
{
    long long int a,b,x;
    scanf("%lld %lld %lld",&x,&a,&b);

    {
        if( b <= a )
        {
            printf("delicious");
        }
        else if ( b > a + x )
        {
            printf("dangerous");
        }
        else
        {
            printf("safe");
        }
    }

return 0;
}


Measured memory_bytes: 1692
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"
const int MOD=1e9+7 , N=200009;
int power(int x, int y, int p=MOD)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p  
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res%p;  
}  



signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>x;
    map<int,int> mp;
    
    for(i=-1000;i<=1000;i++)
    {
        temp = pow(i,5);
        mp[temp]=i;
    }
    
    
    for(auto it : mp)
    {
        curr = it.first;
        int reqd = curr-x;
        if(mp.count(reqd))
        {
            cout<<it.second<<" "<<mp[reqd]<<endl;
            break;
        }
    }
    
    
}

Measured memory_bytes: 4172
import java.util.Scanner;

public class Main {
    
  public static void main(String[] args) {
    String s;
    Scanner scanner = new Scanner(System.in);
    s = scanner.nextLine();
    for (int i = 0; i < 12; i++) {
        if (i == 4) {
            System.out.print(" ");
        }
        System.out.print(s.charAt(i));
    }
    scanner.close();

    System.out.println();
  }
}

Measured memory_bytes: 9556
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

using namespace std;

typedef long long li;
typedef unsigned long long lu;
const li infl = ~0LLU >> 2;

template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}

int mod;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

// ----------------------------------------

const int maxn = 3000;
int n;
int S[maxn + 1][maxn + 2];
int bin[maxn + 1][maxn + 1];
int pw2[maxn * maxn + 1];

int PowEx(int x, int y, int mod) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) {
      z = (int)((li)z * x % mod);
    }
    x = (int)((li)x * x % mod);
  }
  return z;
}

int main(void) {
  scanf("%d%d", &n, &mod);
  for (int i = 0; i <= n; ++i) {
    S[i][0] = (i == 0);
    bin[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      S[i][j] = Add(S[i - 1][j - 1] + Mul(S[i - 1][j], j));
      bin[i][j] = Add(bin[i - 1][j - 1] + bin[i - 1][j]);
    }
  }
  pw2[0] = 1;
  for (int i = 1; i <= n * n; ++i) {
    pw2[i] = Add(pw2[i - 1] << 1);
  }

  int ans = 0;
  for (int m = 0; m <= n; ++m) {
    int coeff = Mul(bin[n][m], Pow(2, PowEx(2, n - m, mod - 1)));
    int sum = 0;
    for (int k = 0; k <= m; ++k) {
      Add(sum, Mul(Add(S[m][k] + Mul(k + 1, S[m][k + 1])), pw2[k * (n - m)]));
    }
    if (m & 1) {
      Sub(ans, Mul(sum, coeff));
    } else {
      Add(ans, Mul(sum, coeff));
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 105728
n=int(input())
A=list(map(int,input().split()))
q=int(input())
coun=[0]*10**5
A_=sum(A)
for i in A:
  coun[i-1]+=1
for _ in range(q):
  b,c=map(int,input().split())
  A_+=(c-b)*coun[b-1]
  coun[c-1]+=coun[b-1]
  coun[b-1]=0
  print(A_)

Measured memory_bytes: 84828
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	char c;
	cin>>c;
	char a=c+1;
	cout<<a;
	
}

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

int main()
{
  ll N;
  cin >> N;
  vector<ll> a(N);
  vector<ll> b(N);
  ll a_sum = 0, b_sum = 0;
  for (ll i = 0; i < N; ++i) {
    cin >> a.at(i);
    a_sum += a.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    cin >> b.at(i);
    b_sum += b.at(i);
  }
  ll num = b_sum - a_sum;
  ll dif = 0;
  for (ll i = 0; i < N; ++i) {
    if (a.at(i) < b.at(i)) {
      dif += (1 + b.at(i) - a.at(i)) / 2;
    }
  }
  if (num >= dif) {
    cout << "Yes" << "\n";
  }
  else {
    cout << "No" << "\n";
  }
}


Measured memory_bytes: 384