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

using namespace std;
#define int int64_t
#define endl '\n'
#define fi first
#define se second

/*struct matrix {
     
     int n, m;
     
     vector<vector<int>> a;
     matrix() {};
     matrix(int n, int m) {
          this->n = n;
          this->m = m;
          a.resize(n, vector<int>(m));
     }
     matrix(int n, int m, vector<vector<int>> pat) {
          this->n = n;
          this->m = m;
          a = pat;
     }
     
     friend matrix operator * (matrix a, matrix b) {
          if (a.m != b.n) {
               cout << "Error";
               exit(0);
          }
          matrix res(a.n, b.m);
          for (int i = 0; i < res.n; ++i) {
               for (int j = 0; j < res.m; ++j) {
                    for (int k = 0; k < a.m; ++k) {
                         res.a[i][j] += a.a[i][k] * b.a[k][j];
                    }
               }
          }
          return res;
     }
     
     friend matrix operator + (matrix a, matrix b) {
          matrix res(a.n, a.m);
          for (int i = 0; i < a.n; ++i) {
               for (int j = 0; j < a.m; ++j) {
                    res.a[i][j] = a.a[i][j] + b.a[i][j];
               }
          }
          return res;
     }
     
     friend matrix operator - (matrix a, matrix b) {
          matrix res(a.n, a.m);
          for (int i = 0; i < a.n; ++i) {
               for (int j = 0; j < a.m; ++j) {
                    res.a[i][j] = a.a[i][j] - b.a[i][j];
               }
          }
          return res;
     }
     
     friend matrix operator ! (matrix a) {
          matrix res = a;
          res.transpone();
          return res;
     }
     
     void transpone() {
          matrix res(m, n);
          for (int i = 0; i < n; ++i) {
               for (int j = 0; j < m; ++j) {
                    res.a[j][i] = a[i][j];
               }
          }
          swap(n, m);
          a = res.a;
     }
     void show() {
          cout << n << ' ' << m << endl;
          for (int i = 0; i < n;++i) {
               for (int j = 0; j < m; ++j) {
                    cout << a[i][j] << ' ';
               }
               cout << endl;
          }
     }
};*/

signed main()
{
     //srand(time(nullptr));
     ios::sync_with_stdio(false);
     cin.tie();
     cout.tie();
     int n, x;
     cin >> n >> x;
     vector<int> a(n);
     for (int i = 0; i < n; ++i) {
          cin >> a[i];
     }
     sort(a.begin(), a.end());
     int ans = 0;
     for (int i = 0; i < n && x >= a[i]; ++i) {
          if (i == n - 1 && x != a[i]) {
               continue;
          }
          x -= a[i];
          ans++;
     }
     cout << ans;
     return 0;
}


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

int numofbits(int bits){
  int num;
  num = (bits >> 1) & 03333333333;
  num = bits - num - ((num >> 1) & 03333333333);  
  num = ((num + (num >> 3)) & 0707070707) % 077;
  return num;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> D(M, 0);
  for(auto& d : D){
    int num;
    cin >> num;
    for(int ii=0; ii<num; ii++){
      int s;
      cin >> s;
      d |= (1 << (s-1));
    }
  }

  int P = 0;
  for(int ii=0; ii<M; ii++){
    int p;
    cin >> p;
    P |= (p<<ii);    
  }

  /*
  for(auto& d : D){
    cout << bitset<10>(d) << endl;
  }
  cout << bitset<10>(P) << endl;
  */

  int total = (1<<N);
  int ans = 0;
  for(int ii=0; ii<total; ii++){
    for(int jj=0; jj<M; jj++){
      int s = (D[jj] & ii);
      if(numofbits(D[jj] & ii) % 2 != ((P >> jj) & 1)){
        ans--;
        break;
      }
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;

int main(){
    int time;
    int h, m, s;
    scanf("%d", &time);
    
    h = time / 3600;
    
    m = (time % 3600) / 60;
    
    s = time % 60;
    
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2756
#include<stdio.h>

int log[110] = { 0 };

int main() {
	int inp_d;
	int current_max = 0;

	while ((scanf("%d", &inp_d)) ==1) {
		if (++log[inp_d] > current_max)current_max = log[inp_d];
	}
	for (int i = 1; i <= 100; i++) {
		if (log[i] == current_max)printf("%d\n", i);
	}
	return 0;
}


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

using namespace std;


int main(){
    int n;
    cin >> n;
    
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    long long ans = 0;
    
    for (int i = 0; i <n; i++){
        
        while (a[i] % 2 == 0){
            a[i] /= 2;
            ans++;
        }
    }
    
    cout << ans << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    S[3] = '8';

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;
    out(n*n*n);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<int, int>      P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
bool check(string &dst, string &src, char addChar)
{
	if (dst == "X") {
		return true;
	}
	if (dst.size() < src.size() + 1) {
		return true;
	} else if (dst.size() == src.size() + 1) {
		string srcJoin = src + addChar;
		if (dst < srcJoin) {
			return true;
		}
	}

	return false;
}

int main()
{
	const static int machiNum[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	REP(i, M) cin >> A[i];

	vector<string> dp(N + 1, "X");
	dp[0] = "";
	REP(i, N + 1) {
		if (dp[i] == "X") continue;
		REP(j, M) {
			auto one = machiNum[A[j]];
			if (i + one <= N) {
				char addChar = A[j] + '0';
				if (check(dp[i + one], dp[i], addChar)) {
					dp[i + one] = dp[i] + addChar;
				}
			}
		}
	}

	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 43648
fun main(args: Array<String>) {
    val mod = 1e9.toLong() + 7
    val n = readLine()!!.toInt()
    val xs = readLine()!!.split(' ').map { it.toInt() }

    val counters = IntArray(n)
    for (x in xs) {
        if (n % 2 == x % 2) {
            println(0)
            return
        }

        counters[x]++
        if (x == 0 && counters[x] > 1) {
            println(0)
            return
        }
        if (counters[x] > 2) {
            println(0)
            return
        }
    }

    var ans = 1L
    for (i in 0 until n / 2) {
        ans *= 2
        ans %= mod
    }
    println(ans)
}


Measured memory_bytes: 49796
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M);
  rep(i, N) cin >> a[i] >> b[i];
  rep(i, M) cin >> c[i] >> d[i];
  rep(i, N) {
    int mn=1e9, num;
    rep(j, M) {
      int dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dist < mn) {
        mn = dist;
        num = j+1;
      }
    }
    cout << num << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using dd = double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<dd, dd>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<dd>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

template <class T, class V>
istream& operator>>(istream& in, pair<T, V>& pair) {
    return in >> pair.first >> pair.second;
}

template <class T>
istream& operator>>(istream& in, vector<T>& elements) {
    for (size_t i = 0; i < elements.size(); ++i) {
        in >> elements[i];
    }
    return in;
}

template <class Container, class Element>
bool Contains(const Container& container, const Element& element) {
    return container.find(element) != container.end();
}

template <class T>
ostream& operator<<(ostream& out, const vector<T>& elements) {
    for (const T& element : elements) {
        out << element << ' ';
    }
    return out;
}

template <class T, class V>
ostream& operator<<(ostream& out, const pair<T, V>& pair) {
    return out << pair.first << ' ' << pair.second;
}

#define FOR(i,n) for(size_t i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(c) sort((c).begin(), (c).end())
#define SUM(c) accumulate((c).begin(), (c).end(), 0ll)

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    
    int n;
    cin >> n;
    
    vd v(n);
    cin >> v;
    
    SORT(v);
    
    double result = v[0];
    for (int i = 1; i < n; ++i) {
        result = (result + v[i]) / 2;
    }
    cout << fixed << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
    
int main() {
  int h,w;
  char b[1010][1010];
  int cnt[1010][1010];
  cin>>h>>w;
  queue<P> que;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin>>b[i][j];
      cnt[i][j]=-1;
      if (b[i][j]=='#') {
	cnt[i][j]=0;
	que.push(P(i,j));
      }
    }
  }

  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  int ans;
  while (que.size()) {
    P p=que.front();
    que.pop();
    int x=p.first,y=p.second;
    for (int i=0; i<4; i++) {
      if (x+dx[i]>=0&&x+dx[i]<h&&y+dy[i]>=0&&y+dy[i]<w&&b[x+dx[i]][y+dy[i]]!='#') {
	b[x+dx[i]][y+dy[i]]='#';
	cnt[x+dx[i]][y+dy[i]]=cnt[x][y]+1;
	que.push(P(x+dx[i],y+dy[i]));
	ans=cnt[x][y]+1;
      }
    }
  }

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

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

int main() {
  int h,n;
  cin>>h>>n;
  vector<int> a(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  cout<<(h<=sum?"Yes":"No")<<endl;
}

Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

void Search(vector<vector<int>>&edge, vector<int>&depth, vector<long long int>&ydp, vector<long long int>&ndp, int node = 0) {
	long long int sum = 1;
	long long int y = 1;
	for (auto i : edge[node]) {
		if (depth[i]>depth[node]) {
			Search(edge, depth, ydp, ndp, i);
			sum *= (ydp[i] + ndp[i]) % MOD;
			y *= ndp[i];
			sum %= MOD;
			y %= MOD;
		}
	}
	ydp[node] = y;
	ndp[node] = sum;
}

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

	cin >> N;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>depth(N, MOD);
	Calculate_Depth(edge, depth, 0);
	vector<long long int>ydp(N);
	vector<long long int>ndp(N);
	Search(edge, depth, ydp, ndp);
	cout << (ydp[0] + ndp[0]) % MOD << endl;
	return 0;
} 

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
using namespace std;
using Graph = vector<vector<int>>;

struct UnionFind {
  vector<int> data;
  UnionFind(int sz) {data.assign(sz, -1);}
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
	int N, M, K; cin >> N >> M >> K;
	vector<ll> numF(N), numB(N);
	UnionFind uf(N);

	for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
    numF[a]++;
    numF[b]++;
	}

	for (int i = 0; i < K; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
		if (uf.find(a) == uf.find(b)) {
			numB[a]++;
			numB[b]++;
		}
	}

	rep(i, N) {
    ll ans = uf.size(i) - numF[i] - numB[i] - 1;
    cout << ans << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.rbegin(),a.rend());
  ll ans=0;
  if(n%2) {
    ll tans=0;
    for(ll i=0;i<(n+1)/2;i++) {
      if((n+1)/2-i>2) {
        tans+=a[i]*2;
      }
      else {
        tans+=a[i];
      }
    }
    for(ll i=(n+1)/2;i<n;i++) {
      tans-=a[i]*2;
    }
    ans=max(ans,tans);
    sort(a.begin(),a.end());
    tans=0;
    for(ll i=0;i<(n+1)/2;i++) {
      if((n+1)/2-i>2) {
        tans-=a[i]*2;
      }
      else {
        tans-=a[i];
      }
    }
    for(ll i=(n+1)/2;i<n;i++) {
      tans+=a[i]*2;
    }
    ans=max(ans,tans);
  }
  else {
    ll tans=0;
    for(ll i=0;i<n/2;i++) {
      if(n/2-i>1) {
        tans+=a[i]*2;
      }
      else {
        tans+=a[i];
      }
    }
    for(ll i=n/2;i<n;i++) {
      if(i!=n/2) {
        tans-=a[i]*2;
      }
      else {
        tans-=a[i];
      }
    }
    ans=max(ans,tans);
    sort(a.begin(),a.end());
    tans=0;
    for(ll i=0;i<n/2;i++) {
      if(n/2-i>1) {
        tans-=a[i]*2;
      }
      else {
        tans-=a[i];
      }
    }
    for(ll i=n/2;i<n;i++) {
      if(i!=n/2) {
        tans+=a[i]*2;
      }
      else {
        tans+=a[i];
      }
    }
    ans=max(ans,tans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
    long long N=inputValueLongLong();
    long long i=0,j=0;
    long long P[N];
    long long count = N;
    long long min;
    P[0] = inputValueLongLong();
    min = P[0];
    for(i=1;i<N;i++){
        P[i] = inputValueLongLong();
        if(min>P[i]){
            min = P[i];
        }else{
            count--;
        }
    }
    cout << count;
    return 0;
}

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

using namespace std;

using ll = long long;
using T = tuple<ll, int, int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, K;
    cin >> x >> y >> z >> K;
    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];

    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());

    priority_queue<T> pq;
    pq.emplace(a[0] + b[0] + c[0], 0, 0, 0);
    set<vector<int> > s;
    for (int i = 0; i < K; ) {
        ll sum;
        int ai, bi, ci;
        tie(sum, ai, bi, ci) = pq.top();
        pq.pop();
        vector<int> v = {ai, bi, ci};
        if (s.find(v) != s.end()) continue;
        s.insert(v);
        i++;
        cout << sum << endl;
        
        if (ai + 1 < x) {
            pq.emplace(sum - a[ai] + a[ai + 1], ai + 1, bi, ci);
        }

        if (bi + 1 < y) {
            pq.emplace(sum - b[bi] + b[bi + 1], ai, bi + 1, ci);
        }

        if (ci + 1 < z) {
            pq.emplace(sum - c[ci] + c[ci + 1], ai, bi, ci + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 768
A, B = map(int, input().split())

#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

#最小公倍数
def lcm(a, b):
    return a*b//gcd(a, b)

print(lcm(A,B))

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

int main(){
  int n, m; cin >> n >> m;
  vector<int> h(n), a(m), b(m), ans(n, 0);
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
  
  for(int i = 0; i < m; i++){
  	if(h[a[i]-1]>h[b[i]-1]) ans[b[i]-1]++;
  	else if(h[a[i]-1]<h[b[i]-1]) ans[a[i]-1]++;
  	else{
    	ans[a[i]-1]++; ans[b[i]-1]++;
    }
  }
  int answer = 0;
  for(int i = 0; i < n; i++) if(ans[i]==0) answer++;
  cout << answer << endl;
  //for(int i = 0; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4844
from itertools import accumulate


N, *A = map(int, open(0).read().split())
MOD = 1_000_000_007

acc = list(accumulate(A, initial=0))
ans = 0
for i in range(1, N):
    ans += A[i - 1] * (acc[N] - acc[i])
    ans %= MOD
print(ans)


Measured memory_bytes: 31764
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=(b-a+1);
    if(n==1 && b!=a || (n>1 && a>b))
    cout<<0;
    else if(n==1 && a==b)
    cout<<1;
    else
    {
        cout<<(b-a)*(n-2) + 1;
    }
  }  
  return 0;
}

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

string str[10];

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int h, w, k, ans = 0; cin >> h >> w >> k;
	for(int i = 0; i < h; i++) cin >> str[i];
	for(int i = 0; i < (1 << h); i++) {
		for(int j = 0; j < (1 << w); j++) {
			int cnt = 0;
			for(int p = 0; p < h; p++) {
				for(int q = 0; q < w; q++) {
					if(str[p][q] == '#' && ((i >> p) & 1) == 0 && ((j >> q) & 1) == 0) {
						++cnt;
					}
				}
			}
			ans += cnt == k;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=100005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int n;
string s,t;
vvl dp;

ll f(ll i,ll j){
	if(dp[i][j]!=-1) return dp[i][j];
	if(!i&&!j) return dp[i][j]=1;
	ll res=0;
	if(j) res=j*j*f(i,j-1)%mod;
	if(i&&j) (res+=i*j*f(i-1,j))%=mod;
	return dp[i][j]=res;
}

int main(){
	Init();
	cin>>s>>t;
	n=s.size();
	int A=0,B=0;
	for(int i=0;i<n;i++) if(s[i]=='1'){
		if(t[i]=='1') A++;
		else B++;
	}
	if(!B){
		cout<<F[A]*F[A]%mod<<endl;
		return 0;
	}
	dp=vvl(A+1,vl(B+1,-1));
	ll res=0;
	for(int i=0;i<=A;i++){
		(res+=F[i]*F[i]%mod*nCk(A,i)%mod*nCk(A+B,i)%mod*f(A-i,B)%mod)%=mod;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 99584
D,N = map(int,input().split())

temperature = []
for _ in range(D):
	temperature.append(int(input()))
temperature.insert(0,0)
clothes = []
for _ in range(N):
	a,b,c = map(int,input().split())
	clothes.append([a,b,c])

dp = [[0]*N for i in range(D+1)]
t1 = temperature[1]
for i in range(N):
	if not (clothes[i][0] <= t1 <= clothes[i][1]):
		dp[1][i] = -10**10

for day in range(2,D+1):
	temp = temperature[day]
	pred = dp[day-1]

	for i in range(N):
		ci = clothes[i][2]
		if clothes[i][0] <= temp <= clothes[i][1]:
			max_hadesa = 0
			for j in range(N):
				cj = clothes[j][2]
				if ci >= cj:
					tmp = pred[j]+ci-cj
				else:
					tmp = pred[j]+cj-ci
				if max_hadesa<tmp:
					max_hadesa = tmp
			dp[day][i] = max_hadesa

print(max(dp[D]))


Measured memory_bytes: 6364
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

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

	ll x;cin >> x;
	if(30 <= x){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint h, w, d;
llint ans[505][505];

int main(void)
{
	cin >> h >> w >> d;
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			if((x+y)%(2*d) < d) ans[x][y] |= 1;
			if(((x-y)%(2*d)+2*d)%(2*d) < d) ans[x][y] |= 2;
		}
	}
	
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			cout << "RYGB"[ans[x][y]];
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 2432
N = int(input())
C = [0,0,0,0]
for i in range(N):
  S = input()
  if(S=="AC"):
    C[0] += 1
  elif(S=="WA"):
    C[1] += 1
  elif(S=="TLE"):
    C[2] += 1
  elif(S=="RE"):
    C[3] += 1
    
print("AC x "+str(C[0]))
print("WA x "+str(C[1]))
print("TLE x "+str(C[2]))
print("RE x "+str(C[3]))

Measured memory_bytes: 9212
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var p, q, t string
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		p += t
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		q += t
	}

	nums := []int{}
	for i := 1; i <= n; i++ {
		nums = append(nums, i)
	}
	perms := permutations(nums)

	s := []string{}
	for _, t := range perms {
		ss := intToString(t)
		s = append(s, ss)
	}
	sort.Strings(s)

	var a, b int
	for i := 0; i < len(s); i++ {
		if s[i] == p {
			a = i
		}
		if s[i] == q {
			b = i
		}
	}

	ans := a - b
	if ans < 0 {
		ans = -ans
	}
	fmt.Println(ans)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func intToString(a []int) string {
	return strings.Trim(strings.Replace(fmt.Sprint(a), " ", "", -1), "[]")
}


Measured memory_bytes: 11156
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int s=0;
  if(a<b)
  {
    swap(a,b);
  }
  if(a<c)
  {
    swap(a,c);
  }
  if(b<c)
  {
    swap(b,c);
  }
  cout<<b+c;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1e9;
    for(int p = 1; p <= 100; ++p){
        int cost = 0;
        rep(i,n) cost += (x[i] - p) * (x[i] - p);
        chmin(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<s.size();i++){
      if(s.at(i)=='o') count++;
  }
  if(15-s.size()+count>=8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

int main() {
	int X, Y;
	cin >> X >> Y;
	if (X > 50){
		cout << "No" << endl;
		return 0;
	}

	int crane, sum;

	for (crane = 0; crane <= X; crane++){
		sum = 2 * crane + 4 * (X - crane);
		if (sum == Y){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}

Measured memory_bytes: 3108
x, y =(int(a) for a in input().split())
w = [[] for j in range(x+1)]
for i in range(x):
    num = 0
    k = [int(a) for a in input().split()]
    for j in  range(len(k)):
        w[i].append(k[j])
        num += k[j]
    else:
        w[i].append(num)
for i in range(y + 1):
    e = 0
    for j in range(x):
        e += w[j][i]
    else:
        w[x].append(e)
for i in range(x+1):
    for j in range(y):
        print(w[i][j],end = " ")
    else:
        print(w[i][j+1])


Measured memory_bytes: 6244
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)

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

	int max = 0;
	for (int i = 1; i < N; i++) {
		if (p[max] < p[i]) {
			max = i;
		}
	}
	p[max] = (int)(p[max] / 2);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += p[i];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e7;
int divisors[maxN + 1];

int main()
{
  for (int i = 1; i <= maxN; i ++)
    for (int j = i; (lli)i*j <= maxN; j++)
      divisors[i*j] += 1 + (i != j);

  int n;
  while (scanf("%d", &n) != EOF)
  {
    lli ans = 0;
    for (int i = 1; i <= n; i++)
      ans += (lli)i * divisors[i];
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 42848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long x = sc.nextLong();
		long total = 100;
		int y = 0;

		while (total < x) {
			total *= 1.01;
			y++;
		}
		System.out.println(y);
	}
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll n;
bool t[300000];

signed main() {
  ll ans = -1;
  t[0] = true;
  cin >> n;
  rep(i, n) {
    ll x;
    cin >> x;
    if (!t[x - 1])
      continue;
    t[x] = true;
    chmax(ans, x);
  }
  if (ans == -1)
    cout << -1 << endl;
  else
    cout << n - ans << endl;
  return 0;
}


Measured memory_bytes: 384
import bisect
N = int(input())

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

List.sort()

a = []

for i in range(N):
  for j in range(i+1,N):
    a.append(List[i] + List[j])
    
a.sort()
ans = N * (N-1) * (N-2) / 6

for i in range(len(a)):
  b = a[i]
  c = bisect.bisect_left(List, b)
  ans -= (N-c)

print(int(ans))

Measured memory_bytes: 109068
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  for (int i = 0; i < M; i++){
    cin >> P[i] >> Y[i];
  }
  vector<vector<pair<int, int>>> C(N);
  for (int i = 0; i < M; i++){
    C[P[i] - 1].push_back(make_pair(Y[i], i));
  }
  for (int i = 0; i < N; i++){
    sort(C[i].begin(), C[i].end());
  }
  vector<string> ID(M);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < C[i].size(); j++){
      string S = to_string(i + 1);
      string T = to_string(j + 1);
      while (S.size() != 6){
        S = '0' + S;
      }
      while (T.size() != 6){
        T = '0' + T;
      }
      ID[C[i][j].second] = S + T;
    }
  }
  for (int i = 0; i < M; i++){
    cout << ID[i] << endl;
  }
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, M = -10000000, m = 1000000;
  long long count = 0;
  cin >> n;
  vector<int> vec(n);
  
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
    m = min(m, vec.at(i));
    M = max(M, vec.at(i));
    count += vec.at(i);
  }
  cout << m << " " << M << " " << count << endl;
  
}


Measured memory_bytes: 3128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  int odd = 0, yon = 0;
  rep(i, n) {
    int a; cin >> a;
    if (a % 2 == 1) odd++;
    else if (a % 4 == 0) yon++;
  }
  // debug2(odd, yon);
  if (odd <= yon) Yes();
  else if (odd == yon + 1 && odd + yon == n) Yes();
  else No();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m; cin >> n >> m;
  char a[n][n], b[m][m];

  rep(i, n) rep(j, n) cin >> a[i][j];
  rep(i, m) rep(j, m) cin >> b[i][j];

  rep(i, n - m + 1) rep(j, n - m + 1) {
    bool ok = true;
    rep(k, m) rep(l, m) if (a[i+k][j+l] != b[k][l]) ok = false;

    if (ok) {
      cout << "Yes\n";
      return (0);
    }
  }

  cout << "No\n";
  
  return (0);
}

Measured memory_bytes: 3640
n, k = map(int, input().split())
ans = []
for i in range(k):
    x = int(input())
    x = list(map(int, input().split()))
    for j in x:
        ans.append(j)
ans = set(ans)
cnt = 0
for i in range(1, n+1):
    if not i in ans:
        cnt += 1
print(cnt)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

string IntTo26(int n,bool small){
    string ans="";
    char key;
    if(small){
        key='a';
    }else{
        key='A';
    }
    while(n>0){
        n--;
        int r=n%26;
        ans+=key+r;
        n/=26;
    }

    reverse(all(ans));
    return ans;
}

signed main(){ 
    int n; cin>>n;
    string ans=IntTo26(n,true);

    cout<<ans<<endl;
    
}  

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

char s[200'009];

int main() {
  int a, b, c, d;
  scanf("%*d%d%d%d%d", &a, &b, &c, &d);
  --a;
  --b;
  --c;
  --d;
  scanf("%s", s);
  if (c < d) {
    swap(a, b);
    swap(c, d);
  }
  while (a != c || b != d) {
    if (a + 1 <= c && s[a + 1] == '.' && a + 1 != b) {
      a += 1;
    } else
    if (a + 2 <= c && s[a + 2] == '.' && a + 2 != b) {
      a += 2;
    } else
    if (b + 1 <= d && s[b + 1] == '.') {
      b += 1;
    } else
    if (b + 2 <= d && s[b + 2] == '.') {
      b += 2;
    } else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 384
a, b = map(int, input().split())


def prime_factorize(n):
    ans = []
    while n % 2 == 0:
        ans.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            ans.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        ans.append(n)
    return ans


cnt = list(set(prime_factorize(a)) & set(prime_factorize(b)))
print(len(cnt)+1)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch){
    if(ch == 'A') return 2;
    else if(ch == 'C') return 3;
    else if(ch == 'G') return 4;
    else if(ch == 'T') return 5;
    else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){
    long long sum = 0, p=1, i;
    for(i=0; i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *=5;
    }
    return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 +(key % (M-1));}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (i=0;;i++){
        h=(h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str)==0) return 1;
        else if (strlen(H[h])== 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h=(h1(key)+ i*h2(key))%M;
        if(strcmp(H[h], str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for (i=0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i =0; i<n;i++){
        scanf("%s %s", com, str);

        if(com[0]=='i'){
            insert(str);
        }else {
            if(find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16048
#include <iostream>
#include <vector>
using namespace std;
int main() {
    string s;
    int A_cnt=0;
    cin>>s;
    for(int i=0;i<s.length();i++) {
        if(s[i]=='A'){
            A_cnt++;
        }
    }
    if(A_cnt == 0 || A_cnt == 3) {
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define rem(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;

#define max 1000000000000000000

int main() {
	int n;
	cin >> n;
	vector <ll>c(n);
	rep(i, 0, n) {
		cin >> c[i];
	}
	sort(c.begin(), c.end());

	ll ans = 1;
	ll che = max;
	if (c[0] == 0) {
		cout << 0 << '\n';
		return 0;
	}

	rem(i, n - 1, -1) {
		if (che / c[i] == 0) {
			cout << -1 << '\n';
			return 0;
		}
		che = che / c[i];
		//cout << che << '\n';
		ans *= c[i];
	}
	
	cout << ans << '\n';
	return 0;

}

Measured memory_bytes: 4052
import math , sys

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

count = [0 for _ in range( 10**5 + 1)]

for each in A:
    count[each]+=1
ans = sum(A)
for _ in range(Q):
    B , C = list( map( int , input().split() ) )
    D = count[B]
    ans += (C-B) * D
    count[B] = 0
    count[C] += D
    print(ans)


Measured memory_bytes: 91088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    vector<vector<int> > v(26);
    int n;cin>>n;
    rep(i,n){
        char c;int a;cin>>c>>a;
        int t=c-'A';
        v[t].emplace_back(a);
    }
    int S='S'-'A';
    int H='H'-'A';
    int C='C'-'A';
    int D='D'-'A';
    rep(i,26)sort(v[i].begin(),v[i].end());
    repi(j,1,14){
        bool f=false;
        rep(k,v[S].size())if(v[S][k]==j)f=true;
        if(f==false)cout<<'S'<<" "<<j<<endl;
    }
    repi(j,1,14){
        bool f=false;
        rep(k,v[H].size())if(v[H][k]==j)f=true;
        if(f==false)cout<<'H'<<" "<<j<<endl;
    }
    repi(j,1,14){
        bool f=false;
        rep(k,v[C].size())if(v[C][k]==j)f=true;
        if(f==false)cout<<'C'<<" "<<j<<endl;
    }
    repi(j,1,14){
        bool f=false;
        rep(k,v[D].size())if(v[D][k]==j)f=true;
        if(f==false)cout<<'D'<<" "<<j<<endl;
    }
    return 0;
}


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

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

typedef long long ll;
typedef long double ld;

using namespace std;

string s;

int main()
{
    cin >> s;
    if (s == "ABC")
        cout << "ARC";
    else
        cout << "ABC";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  bool ok = false;
  for(int i=0; i<=N/7; i++){
    for(int j=0; j<=(N-i*7)/4; i++){
      if((N-i*7) % 4 == 0){
	ok = true;
	break;
      }
    }
    if(ok)
      break;
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
	
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int n;
    cin >> n;
    VI a(n);
    rep(i,n)cin >> a.at(i);
    int cnt=0;
    int chk=0;
    rep(i,n-1){
        if(a.at(i)==a.at(i+1)){
            chk++;
            if(chk%2==1)cnt++;
        }
        else{
            chk=0;
        }
    }
    cout << cnt << endl;
}



    
   


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#define foor for(int i=0;i<n;i++)
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define ic int a;cin>>a;
#define ic2 ic int b;cin>>b;
#define ic3 ic2 int c;cin>>c;
int s = 0;
using namespace std;
int main() {
	ic2
		s = a - b * 2;
	if (s < 0)s = 0;
	cout << s << endl;
}

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

int main() {
	int n , x;
	cin >> n >> x;
	int a[n] , sum = 0 , cn = 0 , l = INT_MAX;
	for(int i = 0 ; i < n ; i++){
	    cin >> a[i];
	    sum += a[i];
	    cn++;
	    l = min(l , a[i]);
	}
	x -= sum;
	int c = x / l;
	cn += c;
	cout << cn;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maxi = -1, mini = 1e9 + 1;
  for (int i = 0; i < n; i++) {
    // if(maxi<a[i]){
    //   maxi = a[i];
    // }
    maxi = max(maxi, a[i]);
    mini = min(mini, a[i]);
  }

  cout << maxi - mini << endl;
}

Measured memory_bytes: 256