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

using namespace std;

class DSU {
private:
  std::vector<int> rank, p, size;
public:
  DSU(int n): rank(n, 0), p(n), size(n, 1) {
    std::iota(p.begin(), p.end(), 0);
  }

  int findRep(int x) {
    if (p[x] != x) {
      p[x] = findRep(p[x]);
    }
    return p[x];
  }

  void unite(int x, int y) {
    int p1 = findRep(x), p2 = findRep(y);
    if (p1 == p2) return;
    if (rank[p1] < rank[p2]) std::swap(p1, p2);
    
    if (rank[p1] == rank[p2]) rank[p1]++;
    p[p2] = p1;
    size[p1] += size[p2];
  }

  int getSize(int x) {
    int xRep = findRep(x);
    return size[xRep];
  }

  bool isSame(int x, int y) {
    return findRep(x) == findRep(y);
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  
  DSU fri(n);

  vector< vector<int> > G1(n);
  vector<int> cnts_f(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    fri.unite(a, b);
    // G1[a].push_back(b);
    // G1[b].push_back(a);
    cnts_f[a]++;
    cnts_f[b]++;
  }
  vector<int> cnts(n, 0);
  for (int i = 0; i < k; ++i) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if (fri.isSame(c, d)) {
      cnts[c]++;
      cnts[d]++;
    }
  }



  for (int i = 0; i < n; ++i) {
    int base = fri.getSize(i);
    int sub = cnts_f[i] + 1;
    base -= sub;
    base -= cnts[i];
    cout << base;
    if (i == n - 1) puts("");
    else cout << " ";
  }
  return 0;
}



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

a = []
for x in map(int, input().split()):
    a.append(x)

a.sort()
d = []

for i in range(m):
    d.append(list(map(int, input().split())))

d.sort(key=lambda x: -x[1])

I = 0
for pair in d:
  p, q = pair
  
  for _ in range(p):
    if I >= n:
      break
    elif a[I] < q:
      a[I] = q
    I += 1

  if I >= n:
    break

print(sum(a))

Measured memory_bytes: 36076
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

using Point = tuple<int, int, int>;

class UnionFind {
    vector<int> parent;
    vector<int> rank;

public:
    int root(int x) {
        return parent[x] >= 0 ? parent[x] = root(parent[x]) : x;
    }

    void unite(int x, int y) {
        int rootX = root(x);
        int rootY = root(y);
        if (rootX == rootY)
            return;

        if (rank[rootX] > rank[rootY]) {
            parent[rootX] += parent[rootY];
            parent[rootY] = rootX;
        } else {
            if (rank[rootX] == rank[rootY])
                ++rank[rootY];

            parent[rootY] += parent[rootX];
            parent[rootX] = rootY;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int groupSize(int x) {
        return -parent[root(x)];
    }

    int numGroup() {
        int num = 0;
        for (int k : parent) {
            num += k < 0;
        }
        return num;
    }

    UnionFind(int size) : parent(size + 1, -1), rank(size + 1, 1) {
        parent[0] = rank[0] = 0;
    }
};

bool point_comp(const Point &l, const Point &r) {
    int u, sx, sy, v, tx, ty;
    tie(sx, sy, u) = l;
    tie(tx, ty, v) = r;
    return sy < ty || ((sy == ty) && (sx < tx));
}

int main() {
    int n;
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        p[i] = make_tuple(x, y, i + 1);
    }
    vector<tuple<int, Point, Point>> edges;
    sort(p.begin(), p.end());
    for (int i = 0; i < n - 1; ++i) {
        int u, sx, sy, v, tx, ty;
        tie(sx, sy, u) = p[i];
        tie(tx, ty, v) = p[i + 1];
        int dist = min(abs(sx - tx), abs(sy - ty));
        edges.push_back(make_tuple(dist, p[i], p[i + 1]));
    }

    sort(p.begin(), p.end(), point_comp);

    for (int i = 0; i < n - 1; ++i) {
        int u, sx, sy, v, tx, ty;
        tie(sx, sy, u) = p[i];
        tie(tx, ty, v) = p[i + 1];
        int dist = min(abs(sx - tx), abs(sy - ty));
        edges.push_back(make_tuple(dist, p[i], p[i + 1]));
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(n);
    ll ans = 0;
    for (int i = 0; i < edges.size(); ++i) {
        int dist;
        Point p1, p2;
        tie(dist, p1, p2) = edges[i];
        if (!uf.same(get<2>(p1), get<2>(p2))) {
            uf.unite(get<2>(p1), get<2>(p2));
            ans += dist;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<pair<int, int>> t(N);
    rep(i, N) cin >> t[i].first >> t[i].second;

    auto distance = [](long double x1, long double x2, long double y1,
                       long double y2) {
        long double dx = x2 - x1;
        long double dy = y2 - y1;
        return sqrt(dx * dx + dy * dy);
    };

    long double sm               = 0.0;
    function<void(vec<int>)> dfs = [&](vec<int> d) {
        if (d.size() == N) {
            rep(i, N - 1) {
                int a = d[i];
                int b = d[i + 1];
                sm +=
                    distance(t[a].first, t[b].first, t[a].second, t[b].second);
            }
            return;
        }
        rep(i, N) {
            if (find(all(d), i) != d.end()) continue;
            d.push_back(i);
            dfs(d);
            d.pop_back();
        }
    };
    dfs(vec<int>());
    int cnt = 1;
    rep(i, N) cnt *= (i + 1);
    cout << fixed << setprecision(15);
    cout << sm / cnt << endl;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c ;
  cin >> a >> b >> c ;
  if(c-(a+b)<0){
    no() ;
  }
  else{
    if(4*a*b<(c-(a+b))*(c-(a+b))){
      yes() ;
    }
    else{
      no() ;
    }
  }
  
  
  
  return 0 ;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1003

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define reft0(i, j) setfill('0') << setw(i) << j

int main(){
    int N;
    vector<int> h;

    cin >> N;
    rep(i, 0, N){
        int temp;
        cin >> temp;
        h.push_back(temp);
    }
    vector<int> ans;
    ans.push_back(0);
    ans.push_back(abs(h[1] - h[0]));
    rep(idx, 2, N){
        int fromPre1 = ans[idx - 1] + (abs(h[idx] - h[idx - 1]));
        int fromPre2 = ans[idx - 2] + (abs(h[idx] - h[idx - 2]));

        ans.push_back(min(fromPre1, fromPre2));
    }

    cout << ans[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, a, b, c, d; cin >> n >> a >> b >> c >> d, --a, --b, --c, --d;
  string s; cin >> s;
  for (int i = a + 1; i + 1 < c; ++i) if (s[i] == '#' and s[i + 1] == '#') {
    return cout << "No" << '\n', 0;
  }
  for (int i = b + 1; i + 1 < d; ++i) if (s[i] == '#' and s[i + 1] == '#') {
    return cout << "No" << '\n', 0;
  }
  if (c > d) {
    bool f = false;
    for (int i = b; i <= d; ++i) if (s.substr(i - 1, 3) == "...") {
      f = true;
      break;
    }
    if (!f) return cout << "No" << '\n', 0;
  }
  cout << "Yes" << '\n';
}

Measured memory_bytes: 592
#include <iostream>
#include <iomanip>

double dp(int i, int j, double DP[][4000], double p[])
{
  if (j < 0 || j > i + 1)
    return 0;
  if (DP[i][j] != -1)
    return DP[i][j];
  return (DP[i][j] = p[i]*dp(i - 1, j - 1, DP, p) + (1 - p[i])*dp(i - 1, j, DP, p));
}

int main()
{
  int N;
  std::cin >> N;
  
  double p[N];
  double DP[N][4000];
  for ( int i = 0; i < N; i++ )
    for ( int j = 0; j < 4000; j++ )
        DP[i][j] = -1;
  for ( int i = 0; i < N; i++ )
  	std::cin >> p[i];
  
  DP[0][0] = 1 - p[0];
  DP[0][1] = p[0];
  
  double ans = 0;
  for ( int i = N/2 + 1; i <= N; i++ )
    ans += dp(N - 1, i, DP, p);
  
  std::cout << std::setprecision(9) << ans;
  
  return 0;
}


Measured memory_bytes: 94208
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <numeric>
#include <limits>
#include <cmath>
#include <math.h>
#include <iomanip>

using namespace std;

double Softmax(double val) {
    if (val < 0) {
        val = 0;
    }
    return val;
}

double Min(double a, double b) {
    if (a > b) {
        swap(a, b);
    }
    return a;
}

int main() {
    double X_s, Y_s, X_t, Y_t;
    cin >> X_s >> Y_s >> X_t >> Y_t;
    int n;
    cin >> n;
    vector<vector<double>> rounds(n, vector<double> (3));
    for (auto & vec: rounds) {
        cin >> vec[0] >> vec[1] >> vec[2];
    }
    rounds.push_back({X_t, Y_t, 0});
    vector<pair<double, bool>> dist(n + 1); // distance from s to i-th circle
    for (int i = 0; i < n + 1; ++i) {
        dist[i].first = Softmax(sqrt((X_s - rounds[i][0]) * (X_s - rounds[i][0]) + (Y_s - rounds[i][1]) * (Y_s - rounds[i][1])) - rounds[i][2]);
        dist[i].second = false;
    }
    int iter = 0;
    while (iter < n + 1) {
        int index;
        double distance = numeric_limits<int>::max();
        for (int i = 0; i < n + 1; ++i) {
            if (distance > dist[i].first && !dist[i].second) {
                distance = dist[i].first;
                index = i;
            }
        }
        dist[index].second = true;
        for (int i = 0; i < n + 1; ++i) {
            if (!dist[i].second) {
                dist[i].first = Min(dist[i].first, dist[index].first + Softmax(sqrt((rounds[index][0] - rounds[i][0]) * (rounds[index][0] - rounds[i][0])
                                                 + (rounds[index][1] - rounds[i][1]) * (rounds[index][1] - rounds[i][1])) - rounds[i][2] - rounds[index][2]));
            }
        }
        ++iter;
    }
    cout << fixed << setprecision(10) << dist.back().first;
    return 0;
}


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

int H, W;
char s[50][50];

const int INF = 10000;
typedef pair<int, int> P;

int d[50][50]; // スタートからの距離
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // 移動ベクトル

int bfs() {
  queue<P> que;
  // 全ての点について距離をINFで初期化
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      d[i][j] = INF;
  d[0][0] = 0; // スタートの距離は0
  que.push(P(0, 0));
  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == H-1 && p.second == W-1) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W &&
          s[nx][ny] == '.' && d[nx][ny] == INF) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[H-1][W-1];
}

int main() {
  int ans = 0;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') ans++;
    }
  }
  if (bfs() == INF) ans = -1;
  else ans -= bfs() + 1;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int M=26;

int arr[404];
int n;
int c[26];
int s[404][26];
int las[26];

long long calc()
{
	for(int i=0;i<M;i++) las[i]=0;
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		las[arr[i]-1]=i+1;
		ans+=s[i][arr[i]-1];
		for(int j=0;j<M;j++)
			ans-=c[j]*(i+1-las[j]);
		//cout << ans << endl;
	}
	return ans;
}

int main()
{
	//auto start = std::chrono::system_clock::now();
	mt19937 rng(12342);
	cin >> n;
	for(int i=0;i<M;i++) cin >> c[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<M;j++) cin >> s[i][j];
	}
	for(int i=0;i<n;i++)
	{
		long long res[M],los[M];
		long long suml=0;
		for(int j=0;j<M;j++)
		{
			los[j]=(i+1-las[j])*c[j];
			suml+=los[j];
		}
		for(int j=0;j<M;j++) res[j]=s[i][j]-(suml-los[j]);
		arr[i]=1;
		for(int j=1;j<M;j++) if(res[j]>res[arr[i]-1]) arr[i]=j+1;
		las[arr[i]-1]=i+1;
	}
	//std::chrono::duration<double> elp=std::chrono::system_clock::now()-start;
	int t=1000;
	long long curs=calc();
	while(t--)
	{
		int x=uniform_int_distribution<int>(0, n-1)(rng);
		int y=uniform_int_distribution<int>(0, M-1)(rng);
		int oldx=arr[x];
		arr[x]=y+1;
		if(calc()<curs)
		{
			arr[x]=oldx;
		}
	}
	for(int i=0;i<n;i++)
		cout << arr[i] << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
//#define cin (type == 0?cin:fin)
//#define cout (type == 0?cout:fout)
#define tcn cin.tie(0);
#define tct cout.tie(0);
#define r_0 return 0
#define ll long long
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 1e3 + 7;
const long long MrBeast = 1e9;

ll T = 1, n, m, ans, cnt, a[N];
vector < ll > v, t;
int type = 0;
set< ll > st;
pair< ll ,ll > p[N];
int main()
{
    TIME
    //ifstream  fin("swap.in");
    //ofstream  fout("swap.out");
    cin >> n >> m >> ans;
    cout << ans << " " << n << ' ' << m;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 55,mo=1e9+7;
int n,f[N][N][N],g[N][N][N],C[N][N];
inline int getz(int x){return x>0?x:0;}
inline void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
int main() {
	read(n);rep(i,0,n){
		C[i][0]=C[i][i]=1;
		rep(j,1,i-1)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	}
	f[0][1][0]=1;
	rep(x,0,n)rep(a,0,n)rep(b,0,n)if(x+a+b<=n){
		if(a>0&&b>0)add(g[x][a][b],g[x][a-1][b-1]);add(f[x][a][b],g[x][a][b]);
		if(!f[x][a][b]||!(a+b))continue;
		rep(A,0,a+b){
			int B=a+b-A,aa=getz(a-A),bb=getz(A-a),t=1LL*f[x][a][b]*C[n-x][A]%mo*C[n-x-A][B]%mo;
			add(g[x+a+b][aa][bb],t);//rep(k,0,n>>1)add(f[x+a+b][aa+k][bb+k],t);
		}
	}
	printf("%d\n",f[n][0][0]);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  double t, a;
  cin >> t >> a;
  vector<double> ave;
  for (int i = 0; i < n; i++) {
	double s;
	cin >> s;
	ave.push_back(t - s * 0.006);
  }
  double dif = abs(ave[0] - a);
  int ans = 0;
  for (int i = 1; i < n; i++) {
	double temp = abs(ave[i] - a);
	if (temp < dif) {
	  ans = i;
	  dif = temp;
	}
  }
  cout << ans + 1 << endl;
  

  return 0;
}



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

map<ll,ll> mp;

ll n,m,a,b,cnt;

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(mp.count(a)==0){
            mp.insert(make_pair(a,0));
        }
        mp[a]+=b;
    }
    for(auto ite=mp.begin();ite!=mp.end();ite++){
        cnt+=ite->second;
        if(cnt>=m){
            cout<<ite->first<<endl;
            break;
        }
    }
}


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

#define Bye return 0
const int MAX = 1e6+1;

void solve(){
    long long n, x, t; cin>>n>>x>>t;
    
    long long cont = 0;
    long long minutes = 0;
    while(cont<n){
        cont += x;
        minutes += t;
    }
    cout<<minutes<<endl;
}

int main()
{
    solve();
    Bye;
}


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

using int32 = int_fast64_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,t;
    cin >> n >> t;
    vector<pii> ba(n);
    REP(i,n){
        int32 a,b;
        cin >> a >> b;
        ba[i] = pii(b,a);
    }
    vector<vector<int32>> dp(n+1, vector<int32>(t+1, 0));
    sort(ALL(ba),greater<pii>());
    REP(i,n){
        REP(j,t+1)dp[i+1][j] = dp[i][j];
        if(ba[i].second > t)continue;
        FORR(j, t - ba[i].second, 0){
            if(dp[i+1][j + ba[i].second] < dp[i][j] + ba[i].first){
                dp[i+1][j + ba[i].second] = dp[i][j] + ba[i].first;
            }
        }
    }
    // ostream_iterator<int32> out_it(cout, " ");
    // copy(ALL(dp[n]), out_it);
    // cout << endl;
    int32 ans = dp[n][t-1];
    set<int32> used;
    int32 cur = t-1;
    FORR(i,n-1,0){
        if(dp[i+1][cur] > dp[i][cur]){
            used.insert(i);
            cur -= ba[i].second;
        }
        if(cur <= 0)break;
    }
    REP(i,n){
        if(used.find(i) == used.end()){
            ans += ba[i].first;
            break;
        }
    }
    // cout << dp[n][t-1] << endl;
    // ostream_iterator<int32> out_it(cout, " ");
    // copy(ALL(used), out_it);
    // cout << endl;
    ans = max(ans, dp[n][t]);
    ANS(ans);
    return 0;
}

Measured memory_bytes: 70912
K = gets.to_i

def sim(as, k)
  as.map.with_index{|a, i|
    i == k ? a-50 : a+1
  }
end

div, mod = K/50, K%50
x = 49 + div + 1
as = [x]*50
(50 - mod).times do |k|
  as = sim(as, k)
end

puts as.size
puts as.join(' ')


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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, b, a) for(int i = b; i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (1000*1000*1000+7)
#define inf (2*1000*1000*1000+9)
#define infl ((ll)2*1000*1000*1000*1000*1000*1000+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/


void solve(){
	int n; cin>>n; 
	vi a(n); 
	multiset<int> s; 
	rep(i,0,n-1) { cin>>a[i]; s.insert(a[i]);   }
	ll ans=0; 
	while(!s.empty()){
		auto it=s.end(); it--; 
		int num=*it; 
		s.erase(it); 
		bitset<32> bs(num); 	
		int la=0; rep(i,0,31) { if(bs[i]) la=i; }
		int i=0; 
		for(i;i<32;i++){
			if(bs[i]){ i++; break; }
		}
		while(i<=la){
			bs[i]=!bs[i]; 	
			i++; 
		}
		num=bs.to_ulong(); 
		it=s.find(num); 
		if(it!=s.end()){
			ans++; s.erase(it); 
		}
	}
	cout<<ans; 
}


int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 10624
/*  CREATED BY
    STREAM_CIPHER
    07-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        int ten=1,nine=1,eight=1;
        for(int i=1;i<=n;i++)
        {
        	ten*=10,ten%=mod;
        	nine*=9,nine%=mod;
        	eight*=8,eight%=mod;
        }
        cout<<(ten-nine+mod-nine+eight+mod)%mod;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int K = 50;

int can(int mask, int a, int b, int ch) {
	set<int> hv = {a};
	for (int i = K; i > ch; i--) {
		if ((mask >> i) & 1) {
			set<int> nhv = hv;
			for (auto t : hv) {
				nhv.insert(t % i);
			}
			hv = nhv;
		}
	}
	for (int i = ch - 1; i > 0; i--) {
		set<int> nhv = hv;
		for (auto t : hv) {
			nhv.insert(t % i);
		}
		hv = nhv;
	}
	return hv.count(b);
}

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

	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (auto &t : b) {
		cin >> t;
	}
	for (int i = 0; i < n; i++) {
		if (!can(0, a[i], b[i], K + 1)) {
			cout << -1 << endl;
			return 0;
		}
	}
	int ans = 0;
	for (int i = K; i > 0; i--) {
		int any = 0;
		for (int j = 0; j < n; j++) {
			any |= !can(ans, a[j], b[j], i);
		}
		if (any) ans |= (1LL << i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int n = sc.nextInt();
		int r[] = new int[10000];
		int c;
		int count=0;
	while(true){
		if(count>0){
			x = sc.nextInt();
			y = sc.nextInt();
			z = sc.nextInt();
		if(x==0 && y==0 && z==0)
			break;
		n = sc.nextInt();
			}


		for(int i=0;i<n;i++)
			r[i] = sc.nextInt();
		int a;
		int b;
		if(x>y)
			if(x>z){
				a = y;
				b = z;
			}
			else{
				a = x;
				b = y;
			}
		else if(y>z){
			a = x;
			b = z;
		}
		else{
			a = x;
			b = y;
		}
		c = (int) Math.sqrt(a*a+b*b);
		for(int i=0;i<n;i++)
			if(r[i]*2<=c)
				System.out.println("NA");
			else
				System.out.println("OK");
		count++;
	}
	}	
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <string.h>
 
int main()
{
    long long n;
    scanf("%lld",&n);
    char x[100]={0};
    int i=0;
    n--;
    while(n>=0){
        x[i]=n%26+'a';
        n/=26;
        i++;
        n--;
    }
    for(int j=i-1;j>=0;j--){
        printf("%c",x[j]);
    }
    return 0;
}

Measured memory_bytes: 1644
k=int(input())
if k==1:
  print(1)
  exit()
if k==10:
  print(10)
  exit()
if k==36:
  print(100)
  exit()
if k==111:
  print(1000)
  exit()
if k==328:
  print(10000)
  exit()
if k==957:
  print(100000)
  exit()
if k==2783:
  print(1000000)
  exit()
if k==8090:
  print(10000000)
  exit()
if k==23528:
  print(100000000)
  exit()
if k==68469:
  print(1000000000)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")

Measured memory_bytes: 97652
#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAXN 100100
#define pb push_back
using namespace std;


// 0 1 2 ... x representa uma cor APENAS
// quantas sequencias possiveis?

int cnt[100000+100];

const int M = 1e9+7;
int32_t main(){
	fastio;
	int n;
    cin>>n;
    vector<int> v(n);
	cnt[0] = 3;
	
	int ans = 1;
	for(int i=0;i<n;i++){
		cin>>v[i];
		v[i]++;
		ans = (ans*cnt[v[i]-1])%M;
		cnt[v[i]-1]--;
		cnt[v[i]]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
import sys
n = int(sys.stdin.readline())
dictionary = {}
for i in range(110):
    dictionary[i] = 0
for line in sys.stdin:
    num = int(line.rstrip("\n"))
    dictionary[num] += 1
mochi = 0
for i in range(110):
    if dictionary[i] > 0:
        mochi += 1
print(mochi)

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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	if(s[n-1] == '1' || s[0] == '0' || s[n-2] == '0'){
		cout << -1 << endl;
		return 0;
	}else{
		for(int i=0; i<n-1; i++){
			if(s[i] != s[n-2-i]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	int now = 1;
	for(int i=2; i<=n; i++){
		cout << now << " " << i << endl;;
		if(s[i-2] == '1') now = i;
	}
	return 0;
}

Measured memory_bytes: 1664
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X = sorted(X)
    diff = []
    pre = X[0]
    for i in range(1, M):
        diff.append(X[i] - pre)
        pre = X[i]
    diff = sorted(diff)
    print(sum(diff[:M - N]))

Measured memory_bytes: 13960
#include<iostream>
using namespace std;
int main()
{
    int n;cin >> n;
    int arr[n];
    int ans = 0;
    for(int i = 0;i < n;i++)cin >> arr[i];
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
            if(j != i)ans += arr[j]*arr[i];
    }
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll a[300005],b[300005],x[300005];
int n;
int main(){
	cin >> n;
	for(int i=1;i<=3*n;i++){
		scanf("%lld",&x[i]);
	}
	priority_queue<ll,vector<ll>,greater<ll> >Q;
	ll S = 0;
	for(int i=1;i<=3*n;i++){
		Q.push(x[i]); S += x[i];
		if(Q.size() > n){
			S -= Q.top(); Q.pop();
		}
		a[i] = max(a[i-1],S);
	}
	priority_queue<ll>R;
	S = 0;
	b[3*n+1] = 1e18;
	for(int i=3*n;i>=1;i--){
		R.push(x[i]); S += x[i];
		if(R.size() > n){
			S -= R.top(); R.pop();
		}
		if(R.size() == n) b[i] = min(S,b[i+1]);
		else b[i] = 1e18;
	}
	ll ans = -1e18;
	for(int i=n;i<=2*n;i++) ans = max(ans,a[i]-b[i+1]);
	cout << ans << endl;
}

Measured memory_bytes: 9588
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n + 1];
    int sum = 0;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
      if(i == 0){
        b[i] = a[i];
      }else{
        b[i] = a[i] - a[i - 1];
      }
      b[n] = k - a[n - 1];
    }
    int last = b[0] + b[n];
    int max = last;
    for(int j = 1;j < n;j++){
      max = Math.max(max , b[j]);
    }  
    int ans = k - max;
    System.out.println(ans);
  }
}

Measured memory_bytes: 65772
#include <stdio.h>
int main() {
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = (double)a / (double)b;
  printf("%d %d %f\n", d, r, f);
  return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if( (A+B)>(C+D) ){
    cout << "Left" << endl;
  }
  else if( (A+B)==(C+D) ){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};


int main() {
	IOS();
	ll n, k;
	cin >> n >> k;
	ll r, s, p;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	ll ans = 0;
	for (int i = 0; i < k;i++) {
		char prev = '0';
		bool ok = true;
		for(int j = i;j < n;j += k){
			if(t[j] != prev || ok){
				if(t[j] == 'r')ans += p;
				if(t[j] == 's')ans += r;
				if(t[j] == 'p')ans += s;
				ok = false;
			}else {
				ok = true;
			}
			prev = t[j];
		}
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int seisu[] = new int[n];
        
        for(int i=0; i<n; i++){
        	seisu[i] = sc.nextInt();   
        }
        
        for(int i=1; i < seisu[n-1]; i++){
        	if(n == 3){
                if(seisu[0] % i == 0 && seisu[1] % i == 0 && seisu[2] % i == 0){
                	System.out.println(i);
                }
            }else if(seisu[0] % i == 0 && seisu[1] % i == 0){
             	System.out.println(i);   
            }
        }
    }
}


Measured memory_bytes: 26356
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
  int a,b; cin >> a >> b;
  int ans = 0;
  if(a > 0) ans = 1;
  else if(b < 0){
    if((b-a+1) % 2 == 0) ans = 1;
    else ans = -1;
  }
  else ans = 0;
  if(ans == 1) cout << "Positive" << endl;
  else if(ans == 0) cout << "Zero" << endl;
  else cout << "Negative" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        vector<pair<int,int> > v;
        int p, d1, d2;
        for (int i=0; i<n; ++i) {
            cin >> p >> d1 >> d2;
            v.push_back(make_pair(-d1-d2, p));
        }
        sort(v.begin(), v.end());
        cout << v[0].second << " " << -v[0].first << endl;
    }
    return 0;
}

Measured memory_bytes: 1328
#define S(i) scanf("%d",i);

int i,n,D,tmp,d[500001],Q,memo[500001],now=1,ans[500001];

main() {
    S(&n)S(&D)
    tmp = D;
    for(i=0;i<n;++i) {
        S(&d[i])
        if (tmp*2 > d[i]) tmp = abs(tmp-d[i]);
        memo[i] = tmp;
    }
    for(i=n;i>0;--i) {
        if (memo[i-1] >= now) ans[i] = 1;
        if (2*now > d[i]) now += d[i];
    }
    if (D >= now) ans[0] = 1;
    S(&Q)
    for(i=0;i<Q;++i) {
        S(&D)
        if (ans[D-1]) printf("YES ");
        else printf("NO ");
    }
}



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

int main() {
  string s;
  cin >> s;
  if (s == "KIHBR" || s == "AKIHBR" || s == "KIHABR" || s == "AKIHABR" || s == "KIHBAR" || s == "AKIHBAR" || s == "KIHABAR" || s == "AKIHABAR" || s == "KIHBRA" || s == "AKIHBRA" || s == "KIHABRA" || s == "AKIHABRA" || s == "KIHBARA" || s == "AKIHBARA" || s == "KIHABARA" || s == "AKIHABARA")
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys

def solve(n, s, t):
    ans = ""
    for i, s_i in enumerate(s):
        ans += s_i + t[i]
    print(ans)

if __name__ == '__main__':
    n = sys.stdin.readline().strip()
    s, t = sys.stdin.readline().strip().split(" ")
    solve(n, s, t)

Measured memory_bytes: 38384
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+ j*100 + k*50 == x:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
int A,B,n;
int stk[5005];
char s[10];
bool f[5005];

bool query(int x,int y)
{
	--x,--y;
	printf("? %d %d\n",x,y);
	fflush(stdout);
	scanf("%s",s);
	return s[0]=='Y';
}

int main()
{
	scanf("%d%d",&A,&B);
	if(A<=B) return puts("Impossible"),0;
	n=A+B;
	rep(i,1,n)
	{
		if(!*stk) {stk[++*stk]=i; continue;}
		if(!query(stk[*stk],i)) --*stk; else stk[++*stk]=i;
	}
	rep(i,1,n) f[i]=query(stk[*stk],i);
	printf("! ");
	rep(i,1,n) if(f[i]) putchar('1'); else putchar('0');
	return puts(""),fflush(stdout),0;
}

Measured memory_bytes: 716
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  std::vector<ll> a(100005);
  rep(i,n) cin>>a[i];
  std::map<ll,int> mod;
  ll sum[100005];
  sum[0] = 0;
  mod[0] = 1;
  rep(i,n){
    sum[i+1] = a[i] + sum[i];
    sum[i+1] = sum[i+1]%m;
    mod[sum[i+1]]++;
  }

 ll ans = 0,b;
 for(auto i : mod){
        b=i.second;
        b*=i.second-1;
        b/=2;
        ans+=b;
    }

    cout<<ans<<endl;
    return ;
}

int main(){
  solve();
  return 0;
}


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

int main(){
    using namespace std;

    const auto& modplus = [](unsigned long i, unsigned long j){return (i + j) % 1000000007;};

    unsigned long N;
    cin >> N;

    vector<unsigned long> dp{1}, prev;

    string S;
    cin >> S;
    for(const auto& c : S){
        unsigned long M{dp.size()};
        dp.swap(prev);
        dp.resize(M + 1);
        fill(begin(dp), end(dp), 0);

        if(c == '<')partial_sum(begin(prev), end(prev), begin(dp) + 1, modplus);
        else partial_sum(rbegin(prev), rend(prev), rbegin(dp) + 1, modplus);
    }

    cout << accumulate(begin(dp), end(dp), 0UL, modplus) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    string s;
    ll K;
    cin >> s;
    cin >> K;

    ll dp[101][2][5]={0,};

    int len = s.size();

	dp[0][0][0] = 1;

	for ( int i = 0; i < len; ++i ){
		const int D = s[i] - '0';
		for ( int j = 0; j < 2; ++j ){
			for ( int k = 0; k < 4; ++k ){
				for ( int d = 0; d <= ( j ? 9 : D ); ++d ){
                    if(d==0){
                        dp[ i + 1 ][ j || ( d < D ) ][ k ] += dp[i][j][k];
                    }else{
                        int v = k+1;
                        if(k+1==5){v--;}
                        dp[ i + 1 ][ j || ( d < D ) ][ v ] += dp[i][j][k];
                    }
				}
			}
		}
	}
    cout << dp[len][0][K]+dp[len][1][K] << endl;
    return 0;

}


Measured memory_bytes: 256
def main():
    N = int(input())

    ans = f(N)
    print(ans)


def f(N):
    ns = map(int, list(str(N)))
    s = 0
    for n in ns:
        s += n

    if N % s == 0:
        return "Yes"
    else:
        return "No"


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def inpl():
    return list(map(int, input().split()))


S = input()

if len(S) % 2 == 1:
    print("No")
    exit()

for i in range(0, len(S), 2):
    if S[i:i + 2] != "hi":
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 2940
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int x;
    cin >> x;
    x -= 400;
    const int kyu = 8 - x / 200;
    cout << kyu << endl;
}


Measured memory_bytes: 3648
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

NX = input()
N,X = NX.split()
N = int(N)
X = [int(X)]
indice = input()
x = indice.split()
for i in x:
    X.append(int(i))

Y = sorted(X)    
d = [i for i in range(N)]
for j in range(len(Y)-1):
    d[j] = Y[j+1]-Y[j]

if len(d)>2:
    f = gcd(d[0],d[1])
    for i in range(len(d)-2):
        f = gcd(f,d[i+2])
elif len(d)>1:
    f = gcd(d[0],d[1])
else: f = d[0]

print(f)


Measured memory_bytes: 21956
import java.util.Scanner;

//Trading
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] t = new int[1001];
		int[] t2 = new int[1001];
		while(true){
			String s = sc.nextLine();
			if(s.equals(""))break;
			t[Integer.parseInt(s.split(",")[0])]++;
		}
		while(sc.hasNext()){
			int x = Integer.parseInt(sc.nextLine().split(",")[0]);
			t2[x]++;
		}
		for(int i=0;i<=1000;i++)if(t[i]>0&&t2[i]>0)System.out.println(i+" "+(t[i]+t2[i]));
	}
}

Measured memory_bytes: 26056
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  string s; cin >> s;
  vector<int> a(n);
  rep(i, n) {
    if (s[i] == '0') {
      a[i] = -1;
    } else {
      a[i] = 1;
    }
  }

  int before = 0;
  vector<int> b;
  rep(i, n) {
    if (before*a[i] > 0) {
      b[b.size()-1] += a[i];
    } else {
      b.push_back(a[i]);
    }
    before = a[i];
  }

  n = b.size();
  // 0: use forward, 1: use forward-1, 2: use backward, 3: no-op
  int dp[2][4];
  rep(i, 2) rep(j, 4) dp[i][j] = 0;
  before = 0;
  rep(i, n) {
    //debugln(b[i]);
    if (b[i] > 0) {
      if (before > 0) {
        chmax(dp[1][0], dp[0][1] + b[i]);
        chmax(dp[1][0], dp[0][3] + b[i]);
        if (before > 1) {
          chmax(dp[1][0], dp[0][2] + b[i]);
        }
        chmax(dp[1][1], dp[0][1] + b[i]-1);
        chmax(dp[1][1], dp[0][3] + b[i]-1);
        if (before > 1) {
          chmax(dp[1][1], dp[0][2] + b[i]-1);
        }
        chmax(dp[1][2], dp[0][1] + 1);
        chmax(dp[1][2], dp[0][3] + before);
        if (before > 1) {
          chmax(dp[1][2], dp[0][2] + before-1);
        }
        rep(j, 4) {
          chmax(dp[1][3], dp[0][j]);
        }

        rep(j, 4) {
          //debug(dp[1][j]);
          dp[0][j] = dp[1][j];
        }
        //cerr << endl;
      }
      before = b[i];
    } else if (b[i] < -1) {
      before = 0;
      int ma = 0;
      rep(j, 4) chmax(ma, dp[0][j]);
      rep(j, 4) dp[0][j] = ma;
    }
  }
  int ans = 0;
  rep(i, 4) chmax(ans, dp[0][i]);
  cout << ans << endl;
}


Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=a+b;
	if(a%3==0||b%3==0||c%3==0)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:break
    h = list(map(int,input().split()))
    sa = []
    for i in range(n):
        sa.append(h[i+1] - h[i])
    v = sorted(set(sa),key=lambda x:sa.count(x))[-1]
    for i in range(n):
        if i == 0 and h[i+1] - h[i] != v:
            if h[i+2] - h[i+1] == v:
                print(h[i])
            else:
                print(h[i+1])
            break
        elif h[i+1] - h[i] != v:
            print(h[i+1])
            break
        #pass
            
#    for i,v in enumerate(h):
#        if i == 0:
#            r = (1,2,3)
#
#        elif i == len(h) - 2:
#            r = (i-2,i-1,i+1)
#
#        elif i == len(h) -1:
#            # iが答え
#            print(v)
#            break
#        else:
#            r = (i-1,i+1,i+2)
#        if (h[r[2]] - h[r[1]] == h[r[1]] - h[r[0]]):
#            if i != 0:
#                print(v)
#                break
#            elif h[1] - h[0] != h[2] - h[1]:
#                print(v)
#                break
#

Measured memory_bytes: 6724
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    S = SI()
    T = SI()
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]: ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 70652
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    for(int x = 0; x < n; x++){
      a[x] = sc.nextInt();
    }
    for(int y = n-1; y > 0; y--){
      System.out.print(a[y]+" ");
    }
    System.out.println(a[0]);
  }
}



Measured memory_bytes: 26328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int n;
		long x;
		long[] as;
		n = sc.nextInt();
		x = sc.nextLong();
		as = new long[n];

		for (int i = 0; i < n; i++) {
			as[i] = sc.nextLong();
		}
		long[][] b = new long[2][n];
		Arrays.fill(b[0], 1L << 50);
		int idx = 1;
		long ans = 1L << 50;
		for (int k = 0; k < n; k++) {
			long sum = 0;
			for (int i = 0; i < n; i++) {
				b[idx][i] = Math.min(b[1 - idx][i], as[(i + n - k) % n]);
				sum += b[idx][i];
			}
			ans = Math.min(ans, k * x + sum);
			idx = 1 - idx;
		}
		System.out.println(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 23380