akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353

int main(){
    ll h,w;
    cin >> h >> w;
    string x[h];
    bool ww[w],hh[h];
    for (ll i=0;i<w;i++)ww[i]=true;
    for (ll i=0;i<h;i++)hh[i]=true;
    for (ll i=0;i<h;i++){
        cin >> x[i];
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (x[i][j]=='#')break;
            if (j==w-1){
                hh[i]=false;
            }
        }
    }
    for (ll i=0;i<w;i++){
        for (ll j=0;j<h;j++){
            if (x[j][i]=='#')break;
            if (j==h-1){
                ww[i]=false;
            }
        }
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (ww[j] && hh[i]){
                cout << x[i][j];
            }
        }
        if (hh[i])cout << endl;
    }
    return 0;
}




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e9

int dp[401][401];

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,ma,mb; cin>>n>>ma>>mb;
    vi a(n),b(n),c(n);
    rep(i,n) cin>>a[i]>>b[i]>>c[i];
    rep(j,401)rep(k,401) dp[j][k] = INF;
    dp[0][0] = 0;
    rep(i,n)RFOR(j,400,a[i])RFOR(k,400,b[i]){
        chmin(dp[j][k], dp[j-a[i]][k-b[i]]+c[i]);
    }
    int ans=INF;
    for(int i=1; ma*i<=400 && mb*i<=400; i++){
        chmin(ans,dp[ma*i][mb*i]);
    }
    ans = (ans==INF)?-1:ans;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

class UnionFind {
    vector<int> par, h;
public:
    UnionFind(int size) {
        par.assign(size, 0);
        h.assign(size, 0);
        REP(i, size) par[i] = i;
    }
    void unite(int u, int v) {
        u = root(u), v = root(v);
        if (u == v) return;
        if (h[u] > h[v]) {
            par[v] = u;
        }
        else if (h[u] < h[v]) {
            par[u] = v;
        }
        else {
            ++h[u];
            par[v] = u;
        }
    }
    bool isUnited(int u, int v) {
        return root(u) == root(v);
    }
    int root(int v) {
        if (par[v] == v) return v;
        return par[v] = root(par[v]);
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, m; cin >> n >> m;
    vector< vector<int> > L(m);
    REP(i, n) {
        int K; cin >> K;
        REP(j, K) {
            int l; cin >> l; --l;
            L[l].pb(i);
        }
    }
    UnionFind uf(n);
    REP(i, m) {
        FOR(j, 1, L[i].size()) {
            uf.unite(L[i][j-1], L[i][j]);
        }
    }
    set<int> s;
    REP(i, n) s.insert( uf.root(i) );
    if (s.size() == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	ll ans = 0;
	FOR(i, 1, N + 1) {
		ll c = N / i;
		ans += (1 + c) * c * i / 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
    long long minu(long long a, long long b){
        return mod(mod(a)-mod(b));
    }
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
    
    vector<int>dirX={-1,0,1};
    vector<int>dirY={-1,0,1};


    void solve(){
        ll n;
        cin>>n;
        if(n==1){
            cout<<0;
            return;
        }
        if(n==2){
            cout<<2;
            return;
        }
        ll ans=minu(add(modPow(10LL,n),modPow(8LL,n)),mul(2LL,modPow(9LL,n)));
        cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
        //    cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

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

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

  int num[26] = {0};
  for (int i = 0; i < S.length(); i++) {
    num[S[i] - 'a']++;
  }
  
  for (int i = 0; i < 26; i++) {
    if (!num[i]) {
      cout << char(i + 'a') << endl;
      return 0;
    }
  }

  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll N,M;
	string S;
	cin>>N>>M>>S;
	ll now=N;
	vector<ll> ans;
	while(1){
		ll i;
		for(i=M;i>=1;i--){
			if(now-i<0)continue;
			if(S[now-i]=='0'){
				ans.push_back(i);
				now-=i;
				break;
			}
		}
		if(i==0){
			cout<<-1<<endl;
			return 0;
		}
		//cout<<now<<" ";//
		if(now==0)break;
	}
	//cout<<endl;//
	REP(i,ans.size()){
		cout<<ans[ans.size()-i-1]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    sort(all(A), greater<ll>());
    ll res = -1;
    if(n%2 == 0){
        ll tmp = 0; vector<int> lst{1,-1};
        rep(i, n-2){
            if(i%2==0) lst.push_back(2);
            else lst.push_back(-2);
        }
        sort(all(lst), greater<int>());
        rep(i, n) tmp += A[i] * lst[i];
        chmax(res, tmp);
    }else{
        ll tmpA = 0, tmpB = 0; vector<int> lstA{-1,-1}, lstB{1,1};
        rep(i, n-2){
            if(i%2==0) {lstA.push_back(2); lstB.push_back(-2);}
            else {lstB.push_back(2); lstA.push_back(-2);}
        }
        sort(all(lstA), greater<int>());
        sort(all(lstB), greater<int>());

        rep(i, n){
            tmpA += A[i] * lstA[i];
            tmpB += A[i] * lstB[i];
        }
        chmax(res, tmpA);
        chmax(res, tmpB);
    }
    cout << res << ln;
}


Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

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

  if(a>=13) cout<<b<<endl;
  else if(a<=5) cout<<0<<endl;
  else cout<<b/2<<endl;
}

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

struct edge{ll to; ll cost;};
ll V;
vector<ll> d;
vector<vector<edge>> G;

void dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P>> que;
    d = vector<ll>(V,INF);
    d[s]=0;
    que.push(P(s,0));
    while(!que.empty()){
        P p = que.top();que.pop();
        ll v = p.second;
        if(d[v]<p.first)continue;
        for(edge e:G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,E; cin>>n>>E;
    V = 1LL<<n;
    G = vector<vector<edge>>(V);
    for (int i=0; i<E; ++i) {
        int  a,b;cin>>a>>b;
        int k = 0;
        for(int i=0; i<b; i++){
            ll c; cin>>c; c--;
            k = k|(1<<c);
        }
        for(int i=0; i<V; i++){
            if((i|k)!=i){
                edge e = {(i|k),a};
                G[i].push_back(e);
            }
        }
    }
    dijkstra(0);
    if(d[V-1]==INF)cout<<-1;
    else cout<<d[V-1];


    return 0;
}



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

using namespace std;

const int N = 1e5 + 5;
long long arr[N];
long long com[N];

int main() {
    //freopen("in.txt", "rt", stdin);
    int n;
    long long m;
    scanf("%d %lld", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%lld", arr + i);
    sort(arr, arr + n);
    for (int i = n - 1; ~i; --i) {
        com[i] = arr[i] + com[i + 1];
    }
    int s = 0, e = 2e6;
    while (s < e) {
        int mid = s + (e - s) / 2;
        long long c = 0;
        for (int i = 0; i < n; ++i) {
            c += (arr + n) - lower_bound(arr, arr + n, mid - arr[i]);
        }
        if (c < m) e = mid;
        else s = mid + 1;
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int id = lower_bound(arr, arr + n, s - arr[i]) - arr;
        ans += com[id];
        ans += (1ll * (n - id) * arr[i]);
        m -= (n - id);
    }
    ans += (1ll * m * (s - 1ll));
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr front()
#define tp top()
typedef long long int ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
#define iofast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define iofile freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
const ll LLINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 100005;

string S;
string Akiba="AKIHABARA";
string lel="KIHBR";
int cnt[26];

int main (){
	
	iofast;
	memset(cnt,0,sizeof(cnt));
	
	cin>>S;
	int n=S.size();
	int m=Akiba.size();
	for(int i=0;i<n;i++){
		cnt[S[i]-'A']++;
	}
	bool valid=true;
	if(n==m){
		for(int i=0;i<n;i++){
			if(S[i]!=Akiba[i]) valid=false;
		}
	} else if(n>m){
		valid=false;
	} else if(n<m){
		for(int i=0;i<(int)lel.size();i++){
			if(cnt[lel[i]-'A']!=1) valid=false;
		}
		if(valid==true){
			valid=false;
			int indx=0;
			for(int i=0;i<m;i++){
				if(indx==n){
					valid=true;
					break;
				}
				if(S[indx]==Akiba[i]){
					indx++;
				}
			}
			if(indx==n) valid=true;
		}
	}
	if(valid==true) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
  int n,W;
  cin>>n>>W;
  vector<pair<int,int>> v;
  for(int i=0;i<n;++i){
    int a,b;
    cin>>a>>b;
    v.push_back({a,b});
  }
  int dp[n+1][W+1];
  memset(dp,0,sizeof(dp));
  
  for(int i=1;i<=n;++i){
    for(int j=0;j<=W;++j){
      if(v[i-1].first>j)dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],v[i-1].second+dp[i-1][j-v[i-1].first]);
    }
  }
  cout<<dp[n][W];
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int inc = 0, diff = 0, ans = 0;
    for(int i=0;i<n-1;i++){
        diff = a[i] - a[i+1];
        if(inc == 0){
            if(diff == 0){
                continue;
            }else if(diff>0){
                inc = -1;
            }else{
                inc = 1;
            }
        }else if(inc == 1 && diff > 0 || inc == -1 && diff < 0){
            inc = 0;
            ans++;
        }
    }
    ans++;
    cout << ans << endl;

}


Measured memory_bytes: 640
#+swank (declaim (optimize (speed 0) (safety 3) (debug 3)))
#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))

(defconstant +mod+ 1000000007)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))) body...)


(defmethod fast-sort ((sequence list) &key (test #'<))
  (declare (inline sort)
           (inline sb-impl::stable-sort-list))
  (sort sequence (lambda (x y)
                   (funcall test x y))))


(defmethod fast-sort ((sequence array) &key (test #'<))
  (declare (inline sort))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read)))



(defmacro read-numbers-to-array (size)
  `(progn
     (when (not (integerp ,size))
       (error "Size must be integer."))
     (when (< ,size 0)
       (error "Size must be plus or zero."))
     (make-array ,size :initial-contents (read-numbers-to-list ,size))))

(defmacro read-numbers-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size))))
       (dotimes (,r ,row-size)
         (dotimes (,c ,column-size)
           (setf (aref ,board ,r ,c) (read))))
       ,board)))


(defun princ-for-each-line (list)
  (format t "~{~a~&~}" list))

(defun unwrap (list)
  (format nil "~{~a~^ ~}" list))



(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))




;;; Write code here

(defun solve (w a b)
  (if (< a b)
      (if (< (+ a w) b)
          (- b (+ a w))
          0)
      (if (< (+ b w) a)
          (- a (+ b w))
          0)))


(defun main ()
  (let ((w (read))
        (a (read))
        (b (read)))
    (format t "~a~&" (solve w a b))))

#-swank (main)


Measured memory_bytes: 25100
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    long long int n;
    cin>>n;
    vector<long long int> city(n+1);
    rep(i,n+1){
        cin>>city[i];
        //cerr<<city[i]<<" ";
    }
    long long int x,ans=0;
    rep(i,n){
        cin>>x;
        if(x>city[i]){
            //次の街を倒し切ってしまうパターン
            if(x>=city[i]+city[i+1]){
                ans+=city[i]+city[i+1];
                city[i]=0;
                city[i+1]=0;
            }else{
                ans+=x;
                city[i+1]-=x-city[i];
                city[i]=0;
            }
        }else{
            ans+=x;
            city[i]-=x;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
    int n, m, c, sum = 0, ans, a = 0;
    vector<int> b;
    cin >> n >> m >> c;
    b.resize(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int j = 0; j < n; j++)
    {
        ans = c;
        for (int i = 0; i < m; i++)
        {
            cin >> a;
            ans += a * b[i];
        }
        if (ans > 0)
            sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 1000100
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
ll ans;
int n,tot,cnt[N][28];
bool ok[N][28];
char s[N];
struct Trie{
	int ch[26],ed;
}trie[N];
void Insert(char *s){
	int len=strlen(s+1);
	int u=1;
	for(int i=1;i<=len;++i){
		for(int c=0;c<26;++c){
			ok[i][c]=ok[i-1][c];
		}
		ok[i][s[i]-'a']=true;
	}
	for(int i=len;i>=1;--i){
		int c=s[i]-'a';
		if(!trie[u].ch[c])trie[u].ch[c]=++tot;
		for(int j=0;j<26;++j){
			if(ok[i][j])++cnt[u][j];
		}
		u=trie[u].ch[c];
	}
	++trie[u].ed;
}
void dfs(int u){
	int qwq[26];
	for(int i=0;i<26;++i)qwq[i]=0;
	for(int c=0;c<26;++c){
		int v=trie[u].ch[c];
		if(!v)continue;
		qwq[c]+=trie[v].ed;
		dfs(v);
	}
	for(int i=0;i<26;++i){
		ans+=1LL*qwq[i]*cnt[u][i];
	}
}
int main(){
	n=read();
	tot=1;
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		Insert(s);
	}
	dfs(1);
	cout<<ans-n<<endl;
	return 0;
}



Measured memory_bytes: 395200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define BIG 100000000

ll  lcm(ll a,ll b)
{
    ll GCD=__gcd(a,b);
    ll lcm=(a*b)/GCD;
    return lcm;
}
ll dp[100005];
ll weight[1000005],value[1000005];
ll total,val;
ll call(ll n)
{
    if(n>=total)
        return 0;

    if(dp[n]!=-1)
        return dp[n];

    ll res1=BIG,res2=BIG;

   // if(weight[n]+c<=val)
    res1=abs(weight[n]-weight[n+1]) + call(n+1);
    if(n+2<=total) res2=abs(weight[n]-weight[n+2]) + call(n+2);
    //cout<<n<<" "<<res1<<" "<<res2<<endl;
    dp[n]=min(res1,res2);
    return dp[n];

}
int main()
{
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    cin>>total;
    for ( int i = 1; i <=total; ++i )
        cin>>weight[i];

    memset(dp, -1, sizeof(dp));
    ll ret=call(1);
    cout<<ret<<endl;
    return 0;
}



Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;

int main()
{
    std::string n;
    cin >> n;
    /*
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    */
    if(n.find("7") == std::string::npos)
        cout << "No" << endl;
    else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3624
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a = ni()
b = ni()
if a > b:
    print('GREATER')
elif a < b:
    print('LESS')
else:
    print('EQUAL')

Measured memory_bytes: 3572
#include        <bits/stdc++.h>
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define MOD     1000000007
#define pii     pair<int,int>
#define vi      vector<int>
#define fio     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define N       200010
#define M       1000000000000000
#define O       1LL
using namespace std;


int main()
{
    fio;
    int x,n,d=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>x;
        while(x%2==0){
            x/=2;
            d++;
        }
    }
    cout<<d;
    
    
    
    return 0;
}







Measured memory_bytes: 256
#include<cstdio>
const int MaxN=100010,MaxQ=100010;
long long q[MaxN],c[MaxN],f[MaxQ];
long long go(long long&x,int&r){
	int l=r-1,mid;
	while(l>1&&q[l]>=x)l=l*2-r;
	for(l<1?l=1:1;r-l>1;)
		q[mid=l+r>>1]<x?l=mid:r=mid;
	long long t=x/q[l];
	x%=q[l];r=l;
	return t;
}
int main(){
	int N,Q,n=1;
	long long x;
	scanf("%d%d",&N,&Q);
	q[1]=N;
	while(Q--){
		scanf("%lld",&x);
		while(n&&q[n]>=x)--n;
		q[++n]=x;
	}
	f[n]=1;
	for(int i=n;i;i--){
		x=q[i];
		int j=i;
		while(x>q[1]){
			long long t=go(x,j);
			f[j]+=t*f[i];
		}
		c[x]+=f[i];
	}
	for(int i=N;--i;)c[i]+=c[i+1];
	for(int i=1;i<=N;i++)printf("%lld\n",c[i]);
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N,cnt = 0;
    while(cin >> N){
        for(int i = 0;i <= 9;i++)for(int j = 0;j <= 9;j++)for(int k = 0;k <= 9;k++)
        if(N-i-j-k >= 0 && N-i-j-k <= 9)cnt++;
        cout << cnt << endl;
        cnt = 0;
    }
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair



int main() {
    int a; cin >> a;
    int ans = a + a * a + a * a * a;
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3592
// #include <iostream>
// #include <string>
// #include <math.h>
// #include <map>
// #include <vector>
// #include <tuple>
// #include <algorithm>
// #include <queue>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
int main(){
  int N, M;
  cin >> N >> M;
  lli sum = 0;
  priority_queue<int> pqi;
  F(i, N){
    lli tmp = 0;
    cin >> tmp;
    pqi.push(tmp);
  }
  F(i, M){
    lli max = pqi.top();
    lli q = max / 2;
    pqi.pop();
    pqi.push(q);
  }
  F(i, N){
    sum += pqi.top();
    pqi.pop();
  }
  cout << sum << endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N; cin>>N;
	set<int> ele;
	int nax = 0;
	rep(i,N){
		int t; cin>>t;
		ele.insert(t);
		nax = max(nax, t);
	}
	ele.erase(nax);
	// show(ele);
	auto it1 = ele.upper_bound(nax/2);
	// cout<<*it1<<endl;
	auto it2 = it1;
	it2--;
	if(it1 == ele.end())it1 = it2;
	int ans = ((abs((double)nax/2-*it1) < abs((double)nax/2-*it2))?*it1:*it2);
	cout<<nax<<' '<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/11/ITP1_11_A


class Dice(object):
    def __init__(self, top, front, right, left, back, bottom):
        self.t = top
        self.f = front
        self.r = right
        self.l = left
        self.bc = back
        self.bt = bottom

    def roll(self, direction):
        if direction == 'N':
            self.t, self.f, self.bt, self.bc = self.f, self.bt, self.bc, self.t
        elif direction == 'S':
            self.t, self.f, self.bt, self.bc = self.bc, self.t, self.f, self.bt
        elif direction == 'E':
            self.t, self.l, self.bt, self.r = self.l, self.bt, self.r, self.t
        elif direction == 'W':
            self.t, self.l, self.bt, self.r = self.r, self.t, self.l, self.bt

    def show_top(self):
        print(self.t)

    def __str__(self):
        # top, front, right, left, back, bottom
        return f'{self.t}, {self.f}, {self.r}, {self.l}, {self.bc}, {self.bt}'


def solve():
    dice = Dice(*input().split())

    for direction in input():
        dice.roll(direction)
    dice.show_top()


if __name__ == '__main__':
    solve()



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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point{
  ld x, y;
  Point(ld x, ld y):x(x), y(y){}
  Point(){}
};

Point operator+(const Point &a, const Point &b){
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b){
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b){
  return Point(a.x * b, a.y * b);
}
Point operator*(const Point &a, const Point &b){
  return Point(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}
Point operator/(const Point &a, const ld b){
  return Point(a.x / b, a.y / b);
}

ld dot(const Point &a, const Point &b){
  return a.x*b.x + a.y*b.y;
}
ld norm(const Point &a){
  return dot(a, a);
}

struct Line:vector<Point>{
  Line(Point a = Point(0, 0), Point b = Point(0, 0)){
    this->push_back(a);
    this->push_back(b);
  }
};

// 写像
Point projection(const Line &l, const Point &p){
  ld t = dot(p-l[0], l[1]-l[0]) / norm(l[0] - l[1]);
  return l[0] + (l[1] - l[0]) * t;
}

// 反射
Point reflection(const Line &l ,const Point &p){
  return p + (projection(l, p) - p) * 2;
}

int main(){
  double x1, y1, x2, y2, xq, yq;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) != EOF){
    Line l = Line(Point(x1, y1), Point(x2, y2));
    Point p = Point(xq, yq);
    
    Point ans = reflection(l, p);
    printf("%.6Lf %.6Lf\n", ans.x, ans.y);    
  }  
  return 0;
}

Measured memory_bytes: 1240
using System;
using System.Text.RegularExpressions;

namespace CitySavers
{
    class Program
    {
        static void Main(string[] args)
        {
            int Savernum = Convert.ToInt32(Console.ReadLine());
            Double[] CityMonster = new Double[Savernum + 1];
            Double[] Saver = new Double[Savernum];
            int tmpnum = 0;
            foreach (string x in Regex.Split(Console.ReadLine(), @"\s+"))
            {
                CityMonster[tmpnum] = Convert.ToDouble(x);
                tmpnum += 1;
            }
            Double destroy = 0;
            tmpnum = 0;
            foreach (string x in Regex.Split(Console.ReadLine(), @"\s+"))
            {
                destroyMons(ref destroy, ref CityMonster, Convert.ToDouble(x), tmpnum);
                tmpnum += 1;
            }
            Console.WriteLine(destroy);
        }

        public static void destroyMons(ref Double destroy,ref Double[] CityMonster,Double Saver,int num)
        {
            Double saver = Saver;
            Double sum = CityMonster[num] + CityMonster[num + 1];

            if (saver >= sum)
            {
                destroy += sum;
                CityMonster[num] = 0;
                CityMonster[num + 1] = 0;
            }
            else
            {
                destroy += saver;
                Double tmpnum = CityMonster[num] - saver;
                if (tmpnum < 0)
                {
                    CityMonster[num] = 0;
                    CityMonster[num + 1] += tmpnum;
                }
                else
                {
                    CityMonster[num] = tmpnum;
                }
                
            }
        }
    }
}


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

int min;
int num;
int map[20];

void check(int pos , int *pair){
  
  if(pos%4 != 3){
    if(map[pos] == map[pos+1])pair[0] = pos + 1;
    else pair[0] = 0;
  }
  else pair[0] = 0;
  
  if(pos < 16){
    if(pos%4 != 0){
      if(map[pos] == map[pos+3])pair[1] = pos + 3;
      else pair[1] = 0;
    }
    else pair[1] = 0;
    
    if(map[pos] == map[pos+4])pair[2] = pos + 4;
    else pair[2] = 0;
    
    if(pos%4 != 3){
      if(map[pos] == map[pos+5])pair[3] = pos + 5;
      else pair[3] = 0;
    }
    else pair[3] = 0;
  }
  else{
    pair[1] = 0;
    pair[2] = 0;
    pair[3] = 0;
  }

}

void pick(int pos,int pair){
  int i;
  int c;


  map[pos] = 0;
  map[pair] = 0;
  c = 0;
  for(i=0;i<num-2;i++){
    if(!map[i+c]){
      c++;
      if(i+c == pair)c++;
    }
    if(c)map[i]  =  map[i+c];
  }

  map[num-1] = 0;
  map[num-2] = 0;

}

void recover(int pos, int pair,int value){
  int i;
  int c;

  c = 2;
  for(i=num-1;i>pos;i--){
    if(i == pair){
      map[i] = value;
      c--;
    }else map[i] = map[i-c];
  }
  map[pos] = value;

}

int patience(void){
  int i,j,k;
  int pair[4];
  int value;
  int tmp;

  if(num == 0)return 0;

  for(i=0;i<num;i++){

    check(i,pair);
    value = map[i];

    for(j=0;j<4;j++){
      if(pair[j]){
	pick(i,pair[j]);
	num -= 2;

	if(min > num)min = num;

	tmp = patience();
	if(min > tmp)min = tmp;

	num += 2;
	recover(i,pair[j],value);
      }
    }
    
  }

  return min;
}
    


int main(void){
  int i,j;
  int n;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    for(j=0;j<20;j++)scanf("%d ",&map[j]);

    min = 20;
    num = 20;

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

  }

  return 0;
}

Measured memory_bytes: 408
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
ll in(){ll x; cin >> x; return x;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec x(n), y(m);
	rep(i, n) cin >> x[i];
	rep(i, m) cin >> y[i];
	sort(all(x));
	sort(all(y));

	ll sumx = 0;
	rep(i, n){
		sumx += x[i]*(i*2-(n-1));
		sumx %= MOD;
	}
	ll sumy = 0;
	rep(i, m){
		sumy += y[i]*(i*2-(m-1));
		sumy %= MOD;
	}
	co(sumx*sumy%MOD);

	return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e1 + 5);

int n;
int p[MAX_N];

int q[MAX_N];

bool check() {
  for (int i = 1; i < n; ++i) {
    if (q[i - 1] > q[i]) return false;
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  for (int i = 0; i < n; ++i) {
    q[i] = p[i];
  }

  if (check()) {
    printf("YES\n");
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int i = 0; i < n; ++i) {
        q[i] = p[i];
      }

      int tmp = p[i];
      q[i] = q[j];
      q[j] = tmp;

      if (check()) {
        printf("YES\n");
        return 0;
      }
    }
  }

  printf("NO\n");

  return 0;
}


Measured memory_bytes: 256
require "pp"

N, M = gets.split.map(&:to_i)
city_array = []
M.times{|index|
  nums = gets.split.map(&:to_i)
  city_array << {index: index, prefec: nums[0], year: nums[1]}
}

sorted_array = city_array.sort{|a, b|
  a[:year] <=> b[:year]
}

backet_hash = {}

city_id_array = sorted_array.map{|item|
  index = backet_hash[item[:prefec].to_s.to_sym]
  index ||= 1
  p_id = format("%06d", item[:prefec]).to_s
  city_id = format("%06d", index).to_s
  index += 1
  backet_hash[item[:prefec].to_s.to_sym] = index

  {index: item[:index], id: (p_id + city_id).to_i}
}

city_id_array.sort{|a, b|
  a[:index] <=> b[:index]
}.each{|item|
  puts format("%012d", item[:id])
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

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

    int n;
    cin >> n;
    vector<ll> a(n);
    priority_queue<ll, vector<ll>, greater<ll> > que;
    rep(i, n){
        cin >> a[i];
        que.push(a[i]);
    }

    ll ans = a[0];
    for(int i = 1; i < n; ++i){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;
int mp[2][101][101];
int n,m;

int visit(int p,int q,int r) {


  bool flg[101] = {};
  long long dis[101];
  for(int i=1;i<=m;i++) dis[i] = INF;

  dis[p] = 0;
 
  while(1) {
    int mindis = INF;
    int ima;
    for(int i=1;i<=m;i++) 
      if(mindis > dis[i] && flg[i] == 0) {
	mindis = dis[i];
	ima = i;
      }

    flg[ima] = 1;
    if(ima == q) return dis[ima];

    for(int i=1;i<=m;i++) 
      if(dis[i] > mp[r][ima][i]+dis[ima]) 
	dis[i] = dis[ima] + mp[r][ima][i];
    
  }


}


int main (){

  while(1) {
    cin >> n >> m;
    if(n == 0 && m == 0) break;
  
  for(int k=0;k<2;k++) 
    for(int i=0;i<=m;i++) 
      for(int j=0;j<=m;j++)
	mp[k][i][j] = INF;

	
  for(int i=0;i<n;i++){
  int a , b , cost,time;
  cin >> a >> b >> cost >> time;
  mp[0][a][b] = min(mp[0][a][b] ,cost);
  mp[0][b][a] = min(mp[0][b][a] ,cost);
  mp[1][a][b] = min(mp[1][a][b] ,time);
  mp[1][b][a] = min(mp[1][b][a] ,time);
  }

  int qu;
  cin >> qu;
  int p,q,r;

  for(int i=0;i<qu;i++) {
    cin >> p >> q >> r;

    int ans = visit(p,q,r);
    cout << ans << endl;
  }
  }
  
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n;
    cin>>n;
    string ans="";
    while(n){
        n--;
        ans+=(char)('a'+(n%26));
        n/=26;
    }
    reverse(all(ans));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = sorted(map(int, input().split()), reverse=True)
    AB = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
            if r >= K:
                return True
            if t < 0:
                return False
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    t = len(C) - 1
    for ab in AB:
        while t >= 0 and C[t] + ab < l + 1:
            t -= 1
        if t < 0:
            break
        r.extend(ab + c for c in C[:t + 1])
    r.sort(reverse=True)
    r += [l] * (K - len(r))
    print('\n'.join(str(i) for i in r))

main()

Measured memory_bytes: 55268
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>

using namespace std;
//debug

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

#define pb push_back

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;



#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()

ll S(ll N) {
	if (N < 10) return N;
	else return N % 10 + S((N - (N % 10)) / 10);
}

int main() {
	ll N;
	cin >> N;
	if (N% S(N) == 0) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
   int n,k,ans=0;
   int a[51];
   cin>>n>>k;
   for(int i=1;i<=n;i++)
    {
    cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=k;i++)   
    {
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int>n(5);
    rep(i,5){
        cin>>n[i];
        if(n[i] == 0)cout<<i+1<<endl;
    }
   
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "P" || S == "W" || S == "G") {
      if (i < N - 1) {
        continue;
      }
      if (i == N - 1) {
        cout << "Three" << endl;
      }
    }
    else if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=5e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


int n,q,a[N],bit[N],vis[N],ans[N];

void upd(int ind,int val) {
	  for(int i=ind;i<=n;i+=(i&(-i)))
	      bit[i]+=val;	  
	}

int  get(int ind) {
	   int res=0;
	   for(int i=ind;i>0;i-=(i&(-i))) 
	       res+=bit[i];
	   
	   return res;   
	}
	
	
void solve() {
     cin>>n>>q;
     rep1(i,1,n) cin>>a[i];
     
     
     vector<pair<int,pi> >vp; 
          
     rep(i,0,q) {
		   int x,y;
		   cin>>x>>y;
		   if(x>y) swap(x,y);
		   vp.pb({y,{x,i}});      	   
		 }
		 
		 sort(all(vp));
		 int ind=0;
		 
		 rep1(i,1,n) {
			    if(vis[a[i]]!=0)
			        upd(vis[a[i]],-1);
			    vis[a[i]]=i;
			    upd(i,1);
			    
			    while(ind<q && vp[ind].fe==i) {
					    ans[vp[ind].se.se]=get(vp[ind].fe)-get(vp[ind].se.fe-1);
					    ind++;
					}		    
			 }
		rep(i,0,q)
		  cout<<ans[i]<<endl;	    
              
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}


Measured memory_bytes: 31276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

char ans[101][101];
int main(){
    int A, B;
    cin >> A >> B;

    cout << 100 << " " << 100 << endl;
    
    for(int i = 0; i < 100; ++i) for(int j = 0; j < 100; ++j){
        ans[i][j] = (j < 50 ? '#' : '.');
    }
    
    --A, --B;
    for(int i = 0; i < 100; ++i) for(int j = 0; j <= 49; ++j){
        if(A <= 0) break;
        if(i % 2 == 0 && j % 2 == 0){
            ans[i][j] = '.';
            --A;
        }
    }
    for(int i = 0; i < 100; ++i) for(int j = 50; j < 100; ++j){
        if(B <= 0) break;
        if(i % 2 == 0 && j % 2 == 1){
            ans[i][j] = '#';
            --B;
        }
    }

    for(int i = 0; i < 100; ++i){
        for(int j = 0; j < 100; ++j){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256