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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};

int H, W, K;
int B[330][330];
set<pair<int, int>> p;

void he(int x, int y, int c) {
    if (B[x][y] > 0 || x < 0 || x >= H || p.count(make_pair(x, y)))return;
    B[x][y] = c;
    he(x + 1, y, c);
    he(x - 1, y, c);
}

void wi(int x, int y, int c) {
    if (B[x][y] > 0 || y < 0 || y >= W)return;
    B[x][y] = c;
    wi(x, y + 1, c);
    wi(x, y - 1, c);
}

int main() {
    cin >> H >> W >> K;
    REP(i, H) {
        string s;
        cin >> s;
        REP(j, W) {
            if (s[j] == '#') {
                p.insert(make_pair(i, j));
            }
        }
    }
    int c = 0;
    for (auto x :p) {
        c++;
        B[x.first][x.second] = c;
        he(x.first + 1, x.second, c);
        he(x.first - 1, x.second, c);
    }
    REP(j, W) {
        if (B[0][j] == 0)continue;
        REP(i, H) {
            wi(i, j + 1, B[i][j]);
            wi(i, j - 1, B[i][j]);
        }
    }

    REP(i, H) {
        REP(j, W) {
            cout << B[i][j] << " ";
        }
        cout << endl;
    }
    return 0;

}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll d;
    cin >> d;
    vector<ll> z(26);
    for (int i = 0; i < 26; i++) {
        cin >> z[i];
    }
    vector<vector<ll>> x(d, vector<ll>(26));
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> x[i][j];
        }
    }
    vector<ll> ans(d,1);
    for (int j = 0; j < d; j++) {
        ll mx = 0;
        ll atai = 0;
        for (int k = 0; k < 26; k++) {
            mx = max(x[j][k], mx);
            if (mx == x[j][k])atai = k;
        }
        ans[j] = atai + 1;
    }
    for (int i = 0; i < d; i++) {
        cout << ans[i] << endl;
    }
}

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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n, a[3];
    cin >> n >> a[0] >> a[1] >> a[2];

    int l[n];
    for (int i = 0; i < n; i++)
        cin >> l[i];
    
    int ans = INT_MAX, i[8];
    for (i[0] = 0; i[0] < 4; i[0]++)
    for (i[1] = 0; i[1] < 4; i[1]++)
    for (i[2] = 0; i[2] < 4; i[2]++)
    for (i[3] = 0; i[3] < 4; i[3]++)
    for (i[4] = 0; i[4] < 4; i[4]++)
    for (i[5] = 0; i[5] < 4; i[5]++)
    for (i[6] = 0; i[6] < 4; i[6]++)
    for (i[7] = 0; i[7] < 4; i[7]++) {

        int val[3] = {0}, num[3] = {0};
        for (int j = 0; j < n; j++) {
            val[i[j]] += l[j];
            num[i[j]] += 1;
        }

        if (num[0] and num[1] and num[2]) {
            int tmp = 0;
            for (int j = 0; j < 3; j++)
                tmp += abs(a[j] - val[j]) + 10*(num[j] - 1);
            ans = min(ans, tmp);
        }
    }

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


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

ka=[]
ans=0

for i in range(n):
    atmp=list(input().split())
    ka.append(atmp)


like=ka[0][1::]

if n>1:
    for i in range(1,n):
        liketmp=ka[i][1::]
        for k in range(0,len(like)):
            if like[k] not in liketmp:
                     like[k]='0'

for j in range(len(like)):
    if like[j]!='0':
        ans+=1
print(ans)


Measured memory_bytes: 3064
input = gets.chomp
input = input.split('')

bp = ['A', 'T', 'C', 'G']
length = input.length
count = 0
max = 0

input.each_with_index do |c, i|
  if !bp.include? c
	next 
  end
  
  count += 1
  
  for j in (i+1)..(length-1)
    if !bp.include? input[j]
      break
    end
    count += 1
  end
  
  if count > max
    max = count
  end
  
  count = 0
end

puts max

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,inf=mod*mod*3ll;;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H,W;
ll d[205][205];
void warshall_floyd(ll N){
	for(ll k=0; k<N; k++)
	for(ll i=0; i<N; i++)
	for(ll j=0; j<N; j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
ll ans;

int main(){

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

cin>>H>>W;

rep(i,10)rep(j,10) cin>>d[i][j];
warshall_floyd(10);

rep(i,H)rep(j,W){
 ll A;
 cin>>A;
 if(A!=-1){
 	ans+=d[A][1];
 }
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 256
N,M = map(int,input().split())
G = {}
for _ in range(M):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(a)
hist = [0 for _ in range(N+1)]
stack = [1]
hist[1] = 1
cnt = 0
F = {}
while stack:
    cur = stack[-1]
    if cur not in F:
        F[cur] = G[cur][:]
        F[cur] = iter(F[cur])
    F1 = list(F[cur])
#     print("cur={},F1={}".format(cur,F1))
    if len(F1)>0:
        F[cur] = iter(F1)
        x = next(F[cur])
        if hist[x]==0:
            stack.append(x)
            hist[x] = 1
        else:
            if sum(hist)==N:
                cnt += 1
                hist[cur]=0
                del F[cur]
                stack.pop()
    else:
#         print("cur={}".format(cur))
#         print("stack={}".format(stack))
        if sum(hist)==N:
            cnt += 1
        hist[cur]=0
        del F[cur]
        stack.pop()
print(cnt)

Measured memory_bytes: 45548
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  string n,q;
  cin >> n >> q;
  cout << q<< n << endl;
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

table = []
row = [0 for _ in range(h)]
column = [0 for _ in range(w)]
for j in range(h):
    temp = [] + list(input())
    table.append(temp)
    check = 0
    for i in range(w):
        if temp[i] == '#':
            check = 1
            column[i] = 1
    row[j] = check

for i in range(h):
    if row[i] == 0:
        continue

    temp = [] + table[i]
    for j in range(w):
        if column[j] == 0:
            temp[j] = ''

    print(''.join(temp))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N;
  cin >> N;
  rep(i,N){
    int A;
    cin >> A;
    if(A % 2 == 0){
      if(A % 3 != 0 && A % 5 != 0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>

using namespace std;

/*?????????????´???????????????????*/

void trace(int A[], int N) {
    int i;
    for (i=0; i <N; i++){
        if(i >0){
            cout << " ";
        }
            cout << A[i];
    }
    cout << endl;
}

/*?????\????????????0?????????????????????*/

void insertionSort(int A[], int N) {
    int j, i, v;
    for ( i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
        
    }
}
int main(int argc, const char * argv[]) {
    
    int N;
    int A[100];
    
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    trace(A,N);
    insertionSort(A, N);
    
    return 0;
}

Measured memory_bytes: 3084
N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = 0

robot_1 = 0
robot_2 = K
for i in range(N):
    distance_1 = abs(robot_1 - x[i])*2
    distance_2 = abs(robot_2 - x[i])*2

    ans += min(distance_1, distance_2)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
  
ll N,W;
ll v[40],w[40];
vector<P> x,y;
  
void func(int si,int ti,vector<P> &x){
  int size=ti-si;
  for(int bit=0;bit<(1<<size);bit++){
    P p=P(0,0);
    for(int i=0;i<size;i++){
      if(bit>>i&1){
        p.first+=w[si+i];
        p.second+=v[si+i];
      }
    }
    x.push_back(p);
  }
}
  
int main(){
  cin>>N>>W;
  for(int i=0;i<N;i++)cin>>v[i]>>w[i];
    
  func(0,N/2,x);
  sort(x.begin(),x.end());
  func(N/2,N,y);
  sort(y.begin(),y.end());
    
  ll target=0,maxm=-(1LL<<60),ans=0;
    
  for(int i=(int)x.size()-1;i>=0;i--){
    P p=x[i];
    while(target<(int)y.size() && p.first+y[target].first <=W ){
      maxm=max(maxm,y[target].second);
      target++;
    }
    ans=max(ans,maxm+p.second);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 43664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if(n > k) cout << 0 << endl;
    else{
        ll ans = 1;
        for(int i=k;n>0;i--,n--){
            ans *= i;
            ans %= MOD;
        }
        cout << ans << endl;
    }
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long K;
	scanf("%lld",&K);
	long long X;
	scanf("%lld",&X);

	cout << (500 * K >= X ? "Yes" : "No") << endl;

	return 0;
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    int st = h1*60 + m1;
    int ed = h2*60 + m2;

    ed -= k;

    cout<<ed - st<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h;
void maxHeapify(int *A,int i){
  int l=i*2+1;
  int r=i*2+2;
  int largest;
  if(l<h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<h&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(A,largest);
  }
}
void insert(int *A,int x){
  int i=h++;
  A[i]=x;
  while(i&&A[(i-1)/2]<A[i]){
    swap(A[(i-1)/2],A[i]);
    i=(i-1)/2;
  }
}
int extract(int *A){
  int res=A[0];
  A[0]=A[--h];
  maxHeapify(A,0);
  return res;
}
int A[2222222];
signed main(){
  string s;
  while(cin>>s,s!="end"){
    if(s=="insert"){
      int x;
      cin>>x;
      insert(A,x);
    }
    if(s=="extract") cout<<extract(A)<<endl;
  }
  return 0;
}

Measured memory_bytes: 10964
#include <bits/stdc++.h>
using namespace std;
const string w = "AKIHABARA";
int main() {
    string s;
    cin >> s;

    for (int i = 0; i < w.size(); i++) {
        if (s.size() - 1 < i || (w[i] != s[i] && w[i] == 'A')) {
            string t = "A";
            s.insert(i, t);
        }
    }
    if (s != w) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end

int mod=998244353;
struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x):val(x>=0?x%mod:x%mod+mod){}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    bool operator==(const Mint& x) const{return val==x.val;}
    bool operator!=(const Mint& x) const{return val!=x.val;}
    bool operator<(const Mint& x) const{return val<x.val;}
    bool operator<=(const Mint& x) const{return val<=x.val;}
    bool operator>(const Mint& x) const{return val>x.val;}
    bool operator>=(const Mint& x) const{return val>=x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
    int n; scanf("%d",&n);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    if(a[0]!=0){
        printf("0\n"); return 0;
    }
    rep(i,1,n)if(a[i]==0){
        printf("0\n"); return 0;
    }
    int cnt[100010]={};
    rep(i,0,n)cnt[a[i]]++;
    Mint ans=1,pre=1;
    rep(i,1,n){
        cerr<<pre.val<<endl;
        ans*=pre.pow(cnt[i]); pre=Mint(cnt[i]);
    }
    printf("%d\n",ans.val);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define INF 100000000
int dp[20001][256],n,m,b[17],a[20001];
main(){
  while(cin>>n>>m,n){
    r(i,m)cin>>b[i];
    r(i,n)cin>>a[i+1];
    r(i,n+1)r(j,256)if(dp[i][j]!=INF)dp[i][j]=INF;
    dp[0][128]=1;
    r(i,n)r(j,256)
        if(dp[i][j]!=INF)r(k,m){
          int p=j+b[k];
          if(p>255)p=255;
          if(p<0)p=0;
          dp[i+1][p]=min(dp[i+1][p],dp[i][j]+(a[i+1]-p)*(a[i+1]-p));
        }
    int p=100000000;
    r(i,256)if(dp[n][i]!=INF)
      p=min(p,dp[n][i]);
    cout<<p-1<<endl;
  }
}

Measured memory_bytes: 23080
n = gets.chomp.to_i
s = []
n.times do
  s.push(gets.chomp)
end
m = 0
a = 0
r = 0
c = 0
h = 0
s.each do |e|
  case e[0]
  when 'M'
    m += 1
  when 'A'
    a += 1
  when 'R'
    r += 1
  when 'C'
    c += 1
  when 'H'
    h += 1
  end
end

ans = 0
[m, a, r, c, h].combination(3) do |arr|
  ans += arr.inject(:*)
end
p ans


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

using namespace std;
typedef long long ll;
const int N=1e5;
int n ,k;
int arr[N+1];
int dp[N+1];
/*int rec(int i)
{
    if(i>=n)
    {
        return 0;
    }
    int &ret=dp[i];
    if(ret!=-1)
    {
        return ret;
    }
    ret=1e9;
    if(i+1<=n)
    {
        ret=min(ret , rec(i+1)+abs(arr[i+1]-arr[i]));
    }
    if(i+2<=n)
    {
        ret=min(ret , rec(i+2)+abs(arr[i+2]-arr[i]));
    }
    return ret;
}
*/
int main()
{
    cin >>  n>>k;
    memset(dp , -1 , sizeof dp);
    for(int i = 1 ; i <=n ; i++)
    {
        cin >> arr[i];
    }
    ll ans = 1e10 , x;
    dp[1]=0;
    memset(dp , 0 , sizeof dp);
    for(int i = 2 ; i<= n ; i++)
    {
        dp[i]=1e10;
        for(int j = i-1; j>=max(1 , i-k) ;j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
        }
    }
    cout << dp[n] ;
    return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

//----------------------------------------------------------------------
void solve() {

	ll n;
	cin >> n;
	vector<ll> vec(n);
	rep(i,n) cin >> vec[i];

	ll ans = 0;

	ll _min = LLONG_MAX;
	rep(i,n) {
		if (vec[i] < _min) {
			ans++;
			_min = vec[i];
		}
	}

	cout << ans;

}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 4836
import java.util.*;

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

        int a = sc.nextInt();
        String b = sc.next();

        String[] strArray = new String[105];

        int Rcount = 0;
        int Bcount = 0;

        for(int i = 0; i < b.length(); i++){
            strArray[i] = String.valueOf(b.charAt(i));

            if(strArray[i].equals("R")){
                Rcount = Rcount + 1;
            }
            if(strArray[i].equals("B")){
                Bcount = Bcount + 1;
            }
        }
        if(Rcount > Bcount){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }           
    }
}

Measured memory_bytes: 21844
'use strict';

function Main(input) {
  const H = input.split("\n")[1].split(" ").map(x => Number(x))
  
  let height = 0
  let ans = 0

  for (let h of H) {
    if (h >= height) {
      ans++
      height = h
    }
  }

  console.log(ans)  
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21064
#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))

using namespace std;
typedef pair<llint, llint> P;

llint n;
string s = "pphbhhphph";

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	cout << s[n%10] << "on" << endl;
	
	return 0;
}

Measured memory_bytes: 3612
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a = INT()
s = input()

if a >= 3200:
    print(s)
else:
    print("red")



Measured memory_bytes: 5972
N,A=map(int,input().split())
arr=[int(input()) for i in range(A)]

dp=[0]*(N+1)
ans=[1,1]


for i in range(A):
    dp[arr[i]]=-1

if dp[1]==-1:
    ans[1]=0

for i in range(2,N+1):
    if dp[i]!=-1:
        ans.append(ans[i-1]+ans[i-2])
    elif dp[i]==-1:
        ans.append(0)
    
print(ans[-1]%1000000007)
        

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

int main(){
	int N;
	int x;
	int count = 0;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> x; 
		for(int j = 2; j * j <= x; j++)
		{
			if(x%j == 0){
				count++;
				break;
			} 
		}
	}
	cout << N - count << endl;
	return 0;
}


Measured memory_bytes: 3060
/*
    JAI JAGANNATH!
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

void ss()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
lli add(lli a, lli b) {
	return ((a % mod) + (b % mod)) % mod;
}
void solve() {
	lli n, s;
	cin >> n >> s;
	vector <lli> v(n + 1);
	for (lli i = 1; i <= n; i++) cin >> v[i];
	vector < vector <lli >> dp(n + 1, vector <lli>(s + 1));
	dp[0][0] = 1;
	for (lli i = 1; i <= n; i++) {
		for (lli j = 0; j <= s; j++) {
			dp[i][j] = add(dp[i][j], dp[i - 1][j]);
			dp[i][j] = add(dp[i][j], dp[i - 1][j]);
			lli x = j + v[i];
			if (x <= s) {
				dp[i][x] = add(dp[i - 1][j], dp[i][x]);
			}
		}
	}
	cout << dp[n][s] << endl;;
}
int main()
{
	ss();
	solve();
	return 0;
}

Measured memory_bytes: 73676
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


	int N; std::cin >> N;
	std::vector<int> a(N);
	std::vector<int> b(N);
	rep(i, N)std::cin >> a[i];


	for(int i = N; i > 0; i--){
		int sum = 0;
		for(int j = 1; i * j <= N; j++){
			sum += b[i * j - 1];
		}
		if(sum % 2 == a[i - 1]){
			b[i - 1] = 0;
		}else{
			b[i - 1] = 1;
		}
	}

	int M = 0;
	rep(i, N){
		if(b[i] == 1)M++;
	}
	std::cout << M << std::endl;

	rep(i, N){
		if(b[i] == 1)std::cout << i + 1 << " ";
	}


	return 0;
}

Measured memory_bytes: 2432
# 最大で5文字になりそうなので上位K個を保持しつつ全探索
s = input() + " "
k = int(input())
ans = []
for i in range(len(s)):
    for j in range(i + 1, min(len(s), i + 5 + 1)):
        t = "".join(s[i:j])
        if t not in ans:
            ans.append(t)
            ans = sorted(ans)[:6]
print(ans[k - 1])


Measured memory_bytes: 9184
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int max=0,min=0;
        max=min(a,b);
        if(a+b>=n){
            min=a+b-n;
        }
        out.println(max+" "+min);
    }
}

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

int main()
{
    int nn,k,s;
    cin>>nn>>k>>s;
    int m;
    if(s==1) m=2;
    else m=s-1;
    for(int i=0;i<k;i++) cout<<s<<" ";
    k=nn-k;
    for(int i=0;i<k;i++) cout<<m<<" ";
}


Measured memory_bytes: 1280
#include<stdio.h>

int main(){
  int a,b,c,gcd; //gcd: greatest common divisor
  
  scanf("%d%d",&a,&b);

  if(a<b){
    while(b!=0){
      c=a%b;
      a=b;
      b=c;
    }
    gcd=a;
  }
  else {
    while(a!=0){
      c=b%a;
      b=a;
      a=c;
    }
    gcd=b;
  }
  
  printf("%d\n",gcd);
  
  return 0;
}

Measured memory_bytes: 592
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

// #include"binary_heap.cpp"
// #include"d_heap.cpp"
// #include"pqueue.cpp"

template<class T>
class d_heap_for_Dijkstra{
	static const int N_MAX=100;
	int n,d,key[N_MAX],pos[N_MAX];
	T val[N_MAX];

	void sift_up(int i,const T &x){
		val[i]=x;
		while(i!=0 && val[(i-1)/d]>val[i]){
			int p=(i-1)/d;
			swap(pos[key[p]],pos[key[i]]);
			swap(key[p],key[i]);
			swap(val[p],val[i]);
			i=p;
		}
	}
	void sift_down(int i,const T &x){
		val[i]=x;
		for(int j,k,c;;i=j){
			j=i;
			for(c=0,k=d*i+1;c<d;c++,k++) if(k<n && val[j]>val[k]) j=k;
			if(j==i) break;
			swap(pos[key[j]],pos[key[i]]);
			swap(key[j],key[i]);
			swap(val[j],val[i]);
		}
	}
public:
	d_heap_for_Dijkstra(int d):n(0),d(d){}
	int find_min()const{ return key[0]; }
	void insert(int u,const T &x){
		int i=n++;
		key[i]=u;
		pos[u]=i;
		sift_up(i,x);
	}
	void delete_min(){
		n--;
		pos[key[n]]=pos[key[0]];
		key[0]=key[n];
		sift_down(0,val[n]);
	}
	void decrease_key(int u,const T &x){
		sift_up(pos[u],x);
	}
	bool empty()const{ return n==0; }
	int size()const{ return n; }
	// bool member(int u)const{ return pos[u]}
	void print(){
		puts("-------");
		printf("n=%d:\n",n);
		rep(i,n) printf("  key[%d] = %d, val[%d] = %d\n",i,key[i],i,val[i]);
		// rep(i,5) printf("  pos[%d] = %d\n",i,pos[i]);
		puts("-------");
	}
};

const int INF=1<<29;

struct edge{ int v,cost1,cost2; };

int main(){
	for(int m,n;scanf("%d%d",&m,&n),n;){
		vector<edge> G[100];
		rep(i,m){
			int u,v,cost1,cost2; scanf("%d%d%d%d",&u,&v,&cost1,&cost2); u--; v--;
			G[u].push_back((edge){v,cost1,cost2});
			G[v].push_back((edge){u,cost1,cost2});
		}

		int q; scanf("%d",&q);
		while(q--){
			int s,t,type; scanf("%d%d%d",&s,&t,&type); s--; t--;
// printf("s=%d, t=%d\n",s+1,t+1);

			int d[100];
			rep(u,n) d[u]=(u==s?0:INF);
			d_heap_for_Dijkstra<int> H(2+m/n);
			H.insert(s,0);
			while(!H.empty()){
// H.print();
				int u=H.find_min();
// printf("  u=%d, d[%d]=%d\n",u,u,d[u]);
				H.delete_min();

				rep(i,G[u].size()){
					const edge &e=G[u][i];
					int d2=d[u]+(type==0?e.cost1:e.cost2);
					if(d[e.v]>d2){
// printf("    v=%d, d2=%d\n",e.v,d2);
						if(d[e.v]==INF) H.insert(e.v,d2);
						else            H.decrease_key(e.v,d2);
						d[e.v]=d2;
					}
				}
			}

			printf("%d\n",d[t]);
		}
	}

	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
const int MAX = 2e5;
vll tree(MAX*4),dp(MAX+1);
void update(int node,int l,int r,int index){
    if(l > index || r < index) return;
    if(l == r){
        tree[node] = max(tree[node],dp[index]);
        return;
    }
    int mid = l + (r-l)/2;
    update(node*2+1,l,mid,index);
    update(node*2+2,mid+1,r,index);
    tree[node] = max(tree[node*2+1],tree[node*2+2]);
}
ll query(int node,int l,int r,int low,int high){
    if(low > r || high < l) return 0;
    if(low <= l && high >= r)
        return tree[node];
    int mid = l + (r-l)/2;
    ll m1 = query(node*2+1,l,mid,low,high);
    ll m2 = query(node*2+2,mid+1,r,low,high);
    return max(m1,m2);
}
int main(){
    int n;
    sci(n);
    vi h(n),b(n);
    rep(i,0,n-1){
        sci(h[i]);
    }
    rep(i,0,n-1){
        sci(b[i]);
    }
    rep(flower,0,n-1){
        ll best = query(0,0,n-1,0,h[flower]);
        dp[h[flower]] = best + b[flower];
        update(0,0,n-1,h[flower]);
    }
    ll ans = 0;
    rep(i,1,n){
        ans =max(ans,dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12784
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 5000005
typedef long long ll;
using namespace std;
int main()
{
    int t,a,b;
    cin>>t>>a>>b;
    cout << min(a*t,b) << endl;
    return 0;
}


Measured memory_bytes: 256
# 2020/08/15
# AtCoder Beginner Contest 175 - C

# Input
x, k, d = map(int,input().split())

# Calc
# d * k < x -> 足りない場合
if d * k < abs(x):
    # 足りない場合：
    ans = abs(x) - k * d
else:
    # 飛び越す場合：
    # 0に近い正の値までの回数
    wkc = x // d
    
    if k % 2 == 0:
        # kが偶数の場合：留まれるのは偶数回目
        if wkc % 2 == 0:
            ans = x % d
        else:
            ans = abs(x % d - d)
    else:
        # kが奇数の場合：留まれるのは奇数回目
        if wkc % 2 == 0:
            ans = abs(x % d - d)
        else:
            ans = x % d

# Output
print(ans)


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n; cin >> n;
    ll a[n]; rep(i,0,n) cin >> a[i];
    //長方形を作るためには、同じ長さの棒が2つ必要
    //線形探索して、出現した棒の個数をカウント
    //カウンタが2になったらカウンタをリセットしてリストに追加
    vector<ll> v;
    map<ll,ll> d;
    rep(i,0,n){
        d[a[i]]++;
        if(d[a[i]] == 2){
            d[a[i]] = 0;
            v.pb(a[i]);
        }
    }
    sort(all(v),greater<ll>());
    if(v.size() < 2) cout << 0 << ednl;
    else cout << v[0]*v[1] << ednl;
}

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

int main()
{
    int n, x, sum = 0, minv, a;
    cin >> n >> x;
    vector<int> m(n);
    for (int i = 0; i < n; i++)
    {
        cin >> m[i];
    }
    for (int i = 0; i < n; i++)
    {
        sum += m[i];
    }
    minv = *min_element(m.begin(), m.end());
    a = x - sum;
    cout << (a / minv) + n << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
l_max = 0
r_min = 100001

for i in range(M):
  l, r = map(int, input().split())
  if l > l_max:
    l_max = l
  if r < r_min:
    r_min = r
    
mylist = list(range(l_max,r_min+1))

print(len(mylist))

Measured memory_bytes: 6900
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static long[] ans = new long[]{-1,-1,-1};
	public static void main(String[] args) throws Exception {


		long K = nextLong();
		long A = nextLong();
		long B = nextLong();

		long bis = 1;


		if(A>bis){
			if(K-(A-bis)>0){
				K-=A-bis;
				bis+=A-bis;
			}else{
				bis+=K;
				K=0;
			}
		}
		//円に交換しないほうが効率がいい場合
		if(B-A-2<=0){
			bis+=K;
			K=0;
		}else{
			//円に交換したほうがいい場合はコスト2を払ってビスケットが1枚以上増える
			bis+=(B-A)*(K/2);
			//最後にビスケットに交換できない場合は残りの手数（１）回分を増やす
			if(K%2==1){
				bis++;
			}
		}

		System.out.println(bis);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    i64 ans = 0;
    vector<i64> ab(n);
    for (auto& e : ab) {
        i64 a, b;
        cin >> a >> b;
        ans -= b;
        e += a + b;
    }
    sort(begin(ab), end(ab), greater<>());

    for (i64 i = 0; i < n; i += 2) ans += ab[i];
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 998244353;
const int Maxn = 1e6 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll mul(ll a, ll b){
	a %= Mod;
	b %= Mod;
	return (a * b) % Mod;
}
ll bin_pow(ll b,ll p){
	ll res = 1;
	for(ll j = 1, pw = b; j <= p; j<<=1,pw = mul(pw, pw)) if(p & j) res = mul(res, pw);
	return res;
}

ll cnt[Maxn], g[Maxn];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	ll v;
	ll s = 0;
	for(int i = 0; i < n; i++){
		cin >> v;
		s += v;
		cnt[v] += v;
	}
	s %= Mod;
	ll ans = 0;
	ans %= Mod;
	for(int i = 1; i < Maxn; i++){
		for(int j = i; j < Maxn; j+=i) g[i] += cnt[j];
		g[i] %= Mod;
		g[i] = (g[i] * g[i]) % Mod;
		//if(g[i]) cerr << i << ' ' << g[i]<< '\n';
	}
	ll d;
	for(int i = Maxn - 1; i > 0; i--){
		for(int j = i + i; j < Maxn; j+=i) g[i] -= g[j];
		//if(g[i]) cerr << i << ' ' << g[i] << '\n';
		g[i] %= Mod;
		ans += mul(bin_pow(i, Mod - 2), g[i]);
	}
	//cerr << g[2] << ' ';
	ans -= s;
	ans %= Mod;
	ans = mul(ans, (Mod + 1) / 2LL);
	cout << (ans + Mod) % Mod;
	return 0; 
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


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

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int x = scanner.nextInt();
        System.out.println((1999 - x) / 200+1);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

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

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

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

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 32720
#include<stdio.h>
#define MAX 100

int main()
{
  int n, i, j, temp, count=0, a[MAX];
  scanf("%d", &n);
  
  for( i=0; i<n; i++)
    {
      scanf("%d", &a[i]);
    }

  for (i = 0; i < n - 1; i++)
    {
      for (j = n - 1; j >= i + 1; j--)
	{  
	  if (a[j] < a[j-1])
	    {
	      temp = a[j];
	      a[j] = a[j-1];
	      a[j-1] = temp;
	      count++;
	    }
	}
    }
  
  for(i = 0; i < n-1; i++)
    {
      printf("%d ", a[i]);
    }
  printf("%d\n", a[n-1]);
  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2104
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
ans = [0 for i in range(N)]
for i in range(M):
	a[i], b[i] = map(int, input().split())
	ans[a[i]-1] += 1
	ans[b[i]-1] += 1
for i in range(N):
	print(ans[i])

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

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

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> frac, ifrac;
    combination(int n):frac(n+1), ifrac(n+1) {
        assert(n < mod);
        frac[0] = 1;
        for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
        ifrac[n] = frac[n].inv();
        for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return frac[n]*ifrac[k]*ifrac[n-k];
    }
} c(2000005);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();
    n += k;

    mint ans = 0;
    rep(i, k+1) {
        ans += mint(25).pow(i)*c(n, i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    if(n > 1 && b >= a || n == 1 && a == b){
    	cout << (n-2) * (b-a) + 1 << endl;
	}
    else cout << 0 << endl; 
} 

Measured memory_bytes: 256