akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 100000;
int n, h[100], dp[MX], dp2[MX];
int m, w[100], v[100];
bool single[100];

int main(){
	while(cin >> n, n){
		rep(i, n) cin >> h[i];
		cin >> m;
		rep(i, m){
			string s;
			cin >> s >> w[i] >> s >> v[i];
			single[i] = s == "Single";
		}
		
		rep(i, MX) dp[i] = dp2[i] = inf;
		dp[0] = dp2[0] = 0;
		rep(i, m) if(!single[i]) rep(j, MX){
			int nj = min(MX - 1, j + v[i]);
			dp[nj] = min(dp[nj], dp[j] + w[i]);
		}
		rep(i, m) if(single[i]) rep(j, MX){
			int nj = min(MX - 1, j + v[i]);
			dp2[nj] = min(dp2[nj], dp2[j] + w[i]);
		}
		for(int i = MX - 2; i >= 0; i--) dp2[i] = min(dp2[i], dp2[i + 1]);
		
		ll ans = inf;
		rep(i, MX){
			ll tmp = dp[i];
			rep(j, n) if(h[j] > i) tmp += dp2[h[j] - i];
			ans = min(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int ans[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, p;
    string s;
    cin >> n >> p >> s;
    if(p == 2){
        ll res = 0;
        for(int i = 0; i < n; i++){
            if((s[i] - '0') % 2 == 0){
                res += (i + 1);
            }
        }
        return cout << res, 0;
    }
    if(p == 5){
        ll res = 0;
        for(int i = 0; i < n; i++){
            if(s[i] == '0' || s[i] == '5'){
                res += (i + 1);
            }
        }
        return cout << res, 0;
    }
    int x = 1;
    for(int i = n - 1; i >= 0; i--){
        ans[i] = (x * (s[i] - '0') + ans[i + 1]) % p;
        x = (x * 10) % p;
    }
    map<int, ll> mp;
    mp[0] = 1;
    ll res = 0;
    for(int i = n - 1; i >= 0; i--){
        res += mp[ans[i]];
        mp[ans[i]]++;
    }
    cout << res;


    return 0;
}


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

const int MOD = (int)1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  int ans=0;
  for(int i=1;i<N;i++){
    if(a.at(i)==a.at(i-1)){
      ans++;
      i++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
(a, b, c, x, y)  = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i }

sum = 0
if a + b < c * 2
  sum = a * x + b * y
else
  m = [x, y].min
  sum = m * c * 2
  if x > y
    r = x - m
    if a < c * 2
      sum = sum + a * r
    else
      sum = sum + c * 2 * r
    end
  else
    r = y - m
    if b < c * 2
      sum = sum + b * r
    else
      sum = sum + c * 2 * r
    end
  end
end

puts sum.to_s


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z) << endl;
	return 0;
}

Measured memory_bytes: 256
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#include<bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
#include <map>
#include <string>
#define mi(lol) map<ll,ll>lol
#define fsort(vec) sort(vec.begin(),vec.end())
#define rsort(vec) sort(vec.begin(),vec.end(),compare)
#define inf ll inf=INT_MAX
//sorting according to the second element vector 

bool compare(pair<ll,ll> p,pair<ll,ll> q){
	return p.second < q.second;	
}

//   example:-
//   sort(vec.begin(),vec.end(),compare);


int main() {
	fast;
	readstr(s)
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, m;
Int s, t, u, v, d;
Int dists[108000], distt[108000];
Int ways[108000], wayt[108000];
Int res;

vector<P> edge[108000];
bool done[108000];

Int  dfs(Int x, Int *way, Int *dist){
  if(way[x] != -1)return way[x];
  way[x] = 0;
  for(auto e: edge[x]){
    Int to = e.first;
    Int cost = e.second;
    if(dist[to] + cost == dist[x]){
      (way[x] += dfs(to, way, dist)) %= MOD;
    }
  }
  return way[x];
}

void dijkstra(Int s, Int t,Int *dist, Int *way){
  fill(dist, dist + n, LINF);
  dist[s] = 0;
  way[s] = 1;
  priority_queue<P, vector<P>, greater<P> > pq;
  pq.push(P(0, s));
  while(!pq.empty()){
    P tmp = pq.top();pq.pop();
    Int from = tmp.second;
    Int d = tmp.first;
    if(dist[from] < d)continue;
    for(auto e:edge[from]){
      Int to = e.first;
      Int cost = e.second;
      if(dist[to] > dist[from] + cost){
	dist[to] = dist[from] + cost;
	pq.push(P(dist[to], to));
      }
    }
  }
  fill(way, way + 108000, -1);
  way[s] = 1;
  for(int i = 0;i < n;i++)dfs(i, way, dist);
}



int main(){
  cin >> n >> m;
  cin >> s >> t;s--,t--;
  for(Int i = 0;i < m;i++){
    cin >> u >> v >> d;
    u--,v--;
    edge[u].push_back(P(v, d));
    edge[v].push_back(P(u, d));
  }
  dijkstra(s, t, dists, ways);
  dijkstra(t, s, distt, wayt);
  
  Int st = dists[t];
  for(Int i = 0;i < n;i++){
    if(dists[i] + distt[i] != st)continue;
    if(dists[i] == distt[i]){
      //      cout << i << " same " << ways[i] << " " << wayt[i] << endl;
      (res -= ways[i] * wayt[i] %MOD * ways[i] % MOD*wayt[i] % MOD) %MOD;
    }
    else{
      for(auto e:edge[i]){
	Int to = e.first;
	Int cost = e.second;
	if(dists[i] + cost + distt[to] != st)continue;
	//cout << i << " same " << ways[i] << " " << wayt[i] << endl;
	if(dists[i] * 2 < st & distt[to] * 2 < st){
	  (res -= ways[i] * wayt[to] %MOD *ways[i] % MOD * wayt[to] %MOD) %MOD;
	}
      }
    }
  }
  res += ways[t] * ways[t] % MOD;
  res %= MOD;
  if(res < 0)res += MOD;
  cout << res << endl;
  
  return 0;
}

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

int main(){
	int H, W, N;
	cin >> H >> W >> N;
	int X[N], Y[N];
	int low[H];
	for(int i=0; i<H; i++){
		low[i] = 200001;
	}
	for(int i=0; i<N; i++){
		cin >> X[i] >> Y[i];
		if(low[X[i]-1] > Y[i]){
			low[X[i]-1] = Y[i];
		}
	}
	int possible[H];
	possible[0] = 1;
	for(int i=1; i<H; i++){
		if(low[i] <= possible[i-1]){
			cout << i << endl;
			return 0;
		}
		if(low[i] == possible[i-1]+1){
			possible[i] = possible[i-1];
		}else{
			possible[i] = possible[i-1]+1;
		}
	}
	cout << H << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>

int main()
{
    int x;
    std::cin >> x;
    int s = x % 60;
    int m = (x / 60) % 60;
    int h = x / (60 * 60);
    std::cout << h << ":" << m << ":" << s << std::endl;
    return 0;
}



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

int mod = 1e9 + 7;

long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    long long res = modpow(x, y / 2);
    return res * res % mod;
}

int main(void)
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> acc(n + 1, 0);
  for (int i = 0; i < n; i++) acc[i + 1] = (acc[i] + a[i]) % mod;
  long long ans = 0;
  for (int i = 0; i < n; i++)
  {
    ans += (long long)((mod + acc[n] - a[i]) % mod) * a[i] % mod;
    ans %= mod;
  }
  ans *= modpow(2, mod - 2);
  ans %= mod;
  cout << ans << endl;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

template<class T = int> struct SegmentTree {
using Func = function<T(T, T)>;
private:
    int n = 1;
    T def;
    vector<T> node;
    const Func f;
public:
    SegmentTree(int sz, T _def, Func _f) : def(_def), f(_f) {
        while (n < sz) n *= 2;
        node.resize(2 * n - 1, def);
    }
    void update(int x, T val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = f(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};

class UnionFind {
public:
    vector<int> uni;
    UnionFind(int s) : uni(s, -1) {}
    int root(int a) { return uni[a] < 0 ? a : uni[a] = root(uni[a]);}
    bool connect(int a, int b) {
        a = root(a); b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] = uni[a] + uni[b];
        uni[b] = a;
        return true;
    }
    bool isConnect(int a, int b) { return root(a) == root(b);}
    int size(int a) { return -uni[root(a)];}
};

int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N);
    for(auto &e : P) cin >> e;

    SegmentTree<int> seg_max(N, -1, [&](int a, int b){ return max(a, b); });
    SegmentTree<int> seg_min(N, INF, [&](int a, int b){ return min(a, b); });

    for(int i = 0; i < N; ++i) {
        seg_max.update(i, P[i]);
        seg_min.update(i, P[i]);
    }

    vector<int> C(N, 1);
    for(int i = N - 2; i >= 0; --i)
        if(P[i] < P[i + 1]) C[i] = C[i + 1] + 1;

    int M = N - K + 1;
    UnionFind uf(M);

    for(int i = 0; i < M - 1; ++i) {
        int mx = seg_max.query(i, i + K + 1);
        int mn = seg_min.query(i, i + K + 1);
        if(P[i] == mn and P[i + K] == mx) uf.connect(i, i + 1);
    }

    vector<int> sorted;
    for(int i = 0; i < M; ++i)
        if(C[i] >= K) sorted.push_back(i);

    for(int i = 1; i < sorted.size(); ++i)
        uf.connect(sorted[i - 1], sorted[i]);

    set<int> st;
    for(int i = 0; i < M; ++i)
        st.insert(uf.root(i));

    cout << st.size() << '\n';
    return 0;
}


Measured memory_bytes: 16000
#include <stdio.h>

int main(void)
{
    int a, b;
    char op;
    
    while(1)
    {
        scanf("%d %c %d", &a, &op, &b);
        
        if(op == '?')
        {
            break;
        }
        else
        {
            switch(op)
            {
                case '+':
                    printf("%d\n", a + b);
                    break;
                case '-':
                    printf("%d\n", a - b);
                    break;
                case '*':
                    printf("%d\n", a * b);
                    break;
                case '/':
                    printf("%d\n", a / b);
                    break;
                default:
                    break;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    for (int i = n-1; i >= 1; --i) {
        if (h[i]<h[i-1]) h[i-1]--;
    }

    bool ok=true;

    rep(i,n-1) {
        if (h[i]>h[i+1]) ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
 int N;
 cin >> N;
 if(N < 10){cout << N << endl;}
 else if(N < 100){cout << 9 << endl;}
 else if(N < 1000){cout << N - 90 << endl;}
 else if(N < 10000){cout << 909 << endl;}
 else if(N < 100000){cout << N - 9090 << endl;}
 else{cout << 90909 << endl;}
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
 
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int SIZE = 31;
const int INF = 1<<27;
 
int G[SIZE][SIZE], C[4];
int H, W;
 
class State {
public:
  int x, y, d, cost;
  State() {}
  State(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
  bool operator<(const State &s) const {
    return cost>s.cost;
  }
};
 
int solve() {
  int cost[4][SIZE][SIZE];
  priority_queue<State> pq;
  pq.push(State(0,0,0,0));
  fill(cost[0][0], cost[4][0], INF);
  cost[0][0][0] = 0;
  while(!pq.empty()) {
    const State s = pq.top(); pq.pop();
    if(s.x == W-1 && s.y == H-1) return s.cost;
    for(int i=0; i<4; i++) {
      State t = s;
      t.cost += ( G[s.y][s.x] == i ? 0 : C[i] );
      t.d = (s.d + i) % 4;
      t.x += dx[t.d], t.y += dy[t.d];
      if(0 <= t.x && t.x < W
     && 0 <= t.y && t.y < H
     && cost[t.d][t.y][t.x] > t.cost) {
    pq.push(t);
    cost[t.d][t.y][t.x] = t.cost;
      }
    }
  }
   
  return INF;
}
 
int main() {
  while(cin >> W >> H, W+H) {
    for(int i=0; i<H; i++)
      for(int j=0; j<W; j++)
    cin >> G[i][j];
     
    for(int i=0; i<4; i++) cin >> C[i];
     
    cout << solve() << endl;
  }
   
  return 0;
}

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

int main() {
  int N;
  cin >> N;

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

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

  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      bool answer = true;

      for (int k = 0; k < N; k++) {
        int original_k = k;

        if (k == i) {
          k = j;
        } else if (k == j) {
          k = i;
        }

        if (p[k] != sorted[original_k]) {
          answer = false;
          break;
        }

        k = original_k;
      }

      if (answer) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;
}

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

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

using namespace std;

typedef int Weight;
Weight INF = 1000000000;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Matrix &d, int s) {
  REP(i,g.size()) d[i].assign(10, INF);
  d[s][0] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    auto itr=find(begin(d[v]),end(d[v]),dist);
    if (itr == end(d[v])) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      REP(j,10) {
        if (d[e.dest][j] > dist + e.weight) {
          d[e.dest].insert(begin(d[e.dest])+j, dist + e.weight);
          d[e.dest].pop_back();
          que.push(P(d[e.dest][j], e.dest));
          break;
        }
      }
    }
  }
}

int main() {
  while(1){
    int n,m,l,k;
    cin>>n>>m>>l>>k;
    if(!n)break;
    --k;
    int z=1<<l;
    Graph g(n*z);
    vector<tuple<int,int,int>> es;
    REP(i,m){
      int u,v,c;
      cin>>u>>v>>c;
      --u;--v;
      es.emplace_back(u,v,c);
    }
    int s,t;
    cin>>s>>t;
    --s;--t;
    vector<int> db(l);
    REP(i,l)cin>>db[i];
    REP(i,l)--db[i];
    REP(i,m) {
      int u,v,c;
      tie(u,v,c)=es[i];
      REP(j,z){
        bitset<7> bs(j);
        bool tku = false;
        bool tkv = false;
        REP(p,l){
          if (!bs[p]) {
            if (db[p]==u) {
              add_edge(g,v*z+j,u*z+j+(1<<p),c);
              tku = true;
            }
            if(db[p]==v) {
              add_edge(g,u*z+j,v*z+j+(1<<p),c);
              tkv = true;
            }
          }
        }
        if(!tku) add_edge(g,v*z+j,u*z+j,c);
        if(!tkv) add_edge(g,u*z+j,v*z+j,c);
      }
    }
    Matrix dist(n*z);
    REP(i,dist.size()) dist[i]=Array(10);
    auto itr = find(begin(db),end(db),s);
    if (itr == end(db))
      dijkstra(g,dist,s*z);
    else
      dijkstra(g,dist,s*z+(1<<(itr-begin(db))));
    int ti=t*z+z-1;
    if(dist[ti][k] < INF)
      cout<<dist[ti][k]<<endl;
    else
      cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 8620
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};
typedef BinaryIndexedTree<int> BIT;

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

    ll N, K, S = 0;
    cin >> N >> K;
    vll a(N + 1), rs(N + 1), xx(N + 1), yy;
    rep(i, N)cin >> a[i], S += a[i];
    
    for (int i = N - 1; i >= 0; --i) {
        rs[i] = rs[i + 1] + a[i];
    }
    rep(r, N + 1)xx[r] = K*r - S + rs[r];
    yy = xx;
    sort(all(yy));

    auto lb = [&](ll y) {
        return (int)distance(yy.begin(), lower_bound(all(yy), y));
    };

    BIT bit(N + 1);
    rep(i, N + 1) {
        bit.add(lb(xx[i]), 1);
    }

    ll ans = 0, s = 0;
    rep(l, N) {
        bit.add(lb(xx[l]), -1);
        ans += bit.sum(0, lb(K*l - s + 1));
        s += a[l];
    }
    cout << ans << endl;
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  vector<int>vec(3);
  vec[0]=a;vec[1]=b;vec[2]=c;
  
  int cnt=0,k=0;
  for(int i=0;i<3;i++){
  if(vec[i]==5)cnt++;
    if(vec[i]==7)k++;
    
  }
  if(cnt==2 && k==1)cout<<"YES";
  else cout<<"NO";
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define MAX_N 1000000
typedef long long ll;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll h[MAX_N];
  ll hmax = 0;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    hmax = max(hmax, h[i]);
  }
  ll left = 0, right = hmax;

  while (abs(right - left) > 1) {
    ll T = left + (right - left) / 2;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      ll res;
      if (h[i] - B * T >= 0) {
        res = h[i] - B * T;
        cnt += res / (A - B);
        res -= (res / (A - B)) * (A - B);
        if (res) cnt++;
      }
    }

    if (cnt > T)
      left = T;
    else
      right = T;
  }

  cout << right << endl;
  return 0;
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            // 条件を順番に潰していく。
            // WAの条件に引っかかった時点で出力し、最後まで残ったものがACになる。

            // Aから始まるか判定
            if (!S.StartsWith("A"))
            {
                Console.WriteLine("WA");
                return;
            }

            // 3文字目と末尾から2文字目の間にCがあるか判定
            var tmp = S.Substring(2, S.Length - 3);
            if (tmp.Where(x => x == 'C').ToList().Count != 1)
            {
                Console.WriteLine("WA");
                return;
            }

            // 3文字目と末尾から2文字目に存在する大文字Cの位置を求める
            var cindex = tmp.IndexOf('C') + 2;
            // AとCを消す
            S = S.Remove(cindex, 1).Remove(0, 1);

            bool ret = false;
            foreach (var item in S)
            {
                ret = new Regex("[a-z]").IsMatch(item.ToString());
                if (!ret)
                {
                    break;
                }
            }

            if (ret)
            {
                Console.WriteLine("AC");
            }
            else
            {
                Console.WriteLine("WA");
            }
        }
    }
}

Measured memory_bytes: 14532
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;
/* -- template -- */

int main(){
    int N; cin >> N;
    int ball[N + 1];for(int i = 1;i <= N;++i)ball[i] = 0;
    int count = 0;
    int inball[N + 1];for(int i = 1;i <= N;++i) inball[i] = 0;
    int a[N + 1];for(int i = 1;i <= N;++i)cin >> a[i];
    for(int i = N;i >= 1;--i){
        int sum = 0;
        for(int j = i;j <= N;j += i){
            sum += ball[j];
        }
        if(a[i] != sum % 2){
            ball[i] = 1;
            inball[i] = 1;
            ++count;
        }
    }
    cout << count << endl;
    for(int i = 1;i <= N;++i){
        if(inball[i])cout << i << ' ';
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;

// 累乗a^b
ll mypow(ll a, ll b){
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
//二項係数mod
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k){
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
ll n , a , b , c ;
cin >> n >> a >> b >> c ;
COMinit();
for (ll i = n; i < 2*n; i++)
{
  ll v1=COM(i-1,n-1);
  ll v2=mypow(a,n)*mypow(b,i-n);v2%=mo;
  ll v3=mypow(b,n)*mypow(a,i-n);v3%=mo;
  ll v4=(v2+v3)%mo *i%mo *100%mo *COM(i-1,n-1)%mo;
  ll v5=mypow(a+b,i)*(100-c)%mo;

  ll v6=v4*mypow(v5,mo-2);v6%=mo;
  ans+=v6;
}
ans%=mo;
cout << ans << endl;
return 0;
}


Measured memory_bytes: 12160
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        int ij = 0;
        int xy = 0;
        int mapin = 0;
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                ij = j - i;
                xy = Math.abs(y - j) + Math.abs(x - i) + 1;
                if(ij<xy){
                    mapin = ij;
                }else{
                    mapin = xy;
                }
                if(map.containsKey(mapin)){
                    int value = map.get(mapin) + 1;
                    map.replace(mapin, value);
                }else{
                    map.put(mapin,1);
                }
            }
        }
        for(int i=1;i<n;i++){
            if(map.containsKey(i)){
                System.out.println(map.get(i));
            }else{
                System.out.println(0);
            }
        }
    }
}



Measured memory_bytes: 61928
#include <bits/stdc++.h>
#define  f(i,n)       for(int i=0; i<n; i++)
#define  ff(i,j,n)    for(int i=int(j);i<=int(n);++i)
#define  sf(i)        scanf("%d",&i)
#define  pf(i)        printf("%d",i)
#define  pb(x)        push_back(x);
#define  in(x)        int x; cin>>x;
#define  w(t)         int t; cin>>t; while(t--)
#define  d(x)         cout<<x<<"\n"
#define  endl         "\n"
#define  fopen        freopen("in.txt", "r" , stdin),freopen("out.txt", "w" , stdout)
#define  fastio       ios::sync_with_stdio(0),cin.tie(0)
#define  PI           acos(-1.0)
#define  all(v)       v.begin(),v.end()
#define  mem(a,value) memset(a,value,sizeof(a))
#define  vi           vector<int>

typedef long long     ll;

const int mod = 1000000007;
using namespace std;

int main() {

    in(n);
    ll sum = 0;
    ff(i,1,n) {

        if(i%3 == 0 || i%5 == 0)
            sum = sum;
        else sum += i;


    }
    d(sum);
}



Measured memory_bytes: 3624
#include <iostream>

using namespace std;

const long long P = 1000000007;

long long fac[300001];
long long ifac[300001];

long long mod_pow(long long a, long long p) {
	long long ans = 1;

	while (p != 0) {
		if (p & 1) {
			ans = ans * a % P;
		}
		a = a * a % P;
		p = p >> 1;
	}
	return ans;
}

void init_fac_table(void) {
	fac[0] = 1;
	ifac[0] = 1;
	for (int i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % P;
		ifac[i + 1] = ifac[i] * mod_pow(i + 1, P - 2) % P;
	}
}

long long nCr(long long n, long long r) {
	if (n == 0 && r == 0) {
		return 1;
	}
	if (n < r || n < 0) {
		return 0;
	}
	long long t = ifac[n - r] * ifac[r] % P;
	return t * fac[n] % P;
}

int main(int argc, char *argv[])
{
	int M, N;

	cin >> N >> M;
	init_fac_table();

	cout << nCr(M, 2) + nCr(N, 2) << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <cstdlib>
#include <algorithm>
#include <iostream>


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

  int a, b, c;
  std::cin >> a >> b >> c;
  std::cout << std::min({a + b, b + c, c + a}) << std::endl;

  return EXIT_SUCCESS;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[2020],NC[2020];
vector<int> E[2020];
int C[2020];

ll dp[2020][2020][3];
ll mo=1000000007;

ll fact[2020];
ll dp2[2020][3];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<N;i++) {
		cin>>P[i];
		P[i]--;
		E[P[i]].push_back(i);
	}
	
	fact[0]=1;
	FOR(i,N) fact[i+1]=fact[i]*(i+1)%mo;
	
	
	
	for(i=N-1;i>=0;i--) {
		C[i]=1;
		dp[i][1][0]=1;
		
		FORR(e,E[i]) {
			
			for(x=1;x<=C[i];x++) for(y=1;y<=C[e];y++) {
				// not con
				(dp2[x+y][0]+=dp[i][x][0]*(dp[e][y][0]+2*dp[e][y][1]+2*dp[e][y][2]))%=mo;
				(dp2[x+y][1]+=dp[i][x][1]*(dp[e][y][0]+2*dp[e][y][1]+2*dp[e][y][2]))%=mo;
				(dp2[x+y][2]+=dp[i][x][2]*(dp[e][y][0]+2*dp[e][y][1]+2*dp[e][y][2]))%=mo;
				// con
				(dp2[x+y-1][1]+=dp[i][x][0]*(dp[e][y][0]+dp[e][y][1]))%=mo;
				(dp2[x+y-1][2]+=dp[i][x][1]*(dp[e][y][0]+dp[e][y][1]))%=mo;
			}
			
			
			C[i]+=C[e];
			FOR(j,C[i]+2) FOR(x,3) dp[i][j][x]=dp2[j][x], dp2[j][x]=0;
		}
	}
	
	ll ret=0;
	for(i=1;i<=N;i++) {
		if((N-i)%2==0) ret+=(dp[0][i][0]+2*dp[0][i][1]+2*dp[0][i][2])*fact[i]%mo;
		else ret-=(dp[0][i][0]+2*dp[0][i][1]+2*dp[0][i][2])*fact[i]%mo;
	}
	
	cout<<(ret%mo+mo)%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
	int n;
	int a[10001] , b[10001];
	int scoreA=0 , scoreB=0;
	int i;
	while(1){
		cin>>n;
		if(n==0) break;
		for(i=0 ; i<n ; i++){
			cin >> a[i] >> b[i];
			if(a[i]>b[i]){
				scoreA+=a[i]+b[i];
			} else if (a[i]<b[i]){
				scoreB+=a[i]+b[i];
			} else {
				scoreA+=a[i];
				scoreB+=b[i];
			}
		}
		cout << scoreA << " " << scoreB << endl;
		scoreA=scoreB=0;
	}
	return 0;
}

Measured memory_bytes: 1236
L=[]
for i in range(3):
    S=list(map(int,input().split()))
    L.append(S)
#print(L)

for i in range(2):
    for j in range(2):
        if L[2-i][2-j]-L[1-i][2-j]!=L[2-i][1-j]-L[1-i][1-j]:
            print("No")
            exit()
        
for i in range(2):
    for j in range(2):
        if L[2-j][2-i]-L[1-j][2-i]!=L[2-j][1-i]-L[1-j][1-i]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
a = 'abcdefghijklmnopqrstuvwxyz'
b = [0 for i in range(len(a))]
while True:
	try:
		S = raw_input().lower()
	except:
		break
	for j in range(26):
		b[j] += S.count(a[j])
for i in range(len(a)):
	print str(a[i])+" : "+str(b[i])

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

struct node{
	int key;
	struct node *parent;
	struct node *left;
	struct node *right;
};

typedef struct node *Node;

Node root,NIL;

Node getMinimum(Node x){
	while(x->left != NIL){ x = x->left; }
  return x;
}


Node find(Node x,int k){
	while( x != NIL && k != x->key ){
		if(k < x->key){ x = x->left; }
		else{ x = x->right; }
	}
	return x;
}

Node getSuccessor(Node x){
	Node y;
	if(x->right != NIL){ return getMinimum(x->right); }

	y = x->parent;
	while( y != NIL && x ==y->right ){
		x = y;
		y = y->parent;
	}
	return y;
}

void delete(Node z){
	Node x;
	Node y;

	if(z->left == NIL || z->right == NIL){ y = z; }
	else{ y = getSuccessor(z); }

	if(y->left != NIL){ x = y->left; }
	else{ x = y->right; }

	if(x != NIL){ x->parent = y->parent; }

	if(y->parent == NIL){ root = x; }
	else{
		if(y == y->parent->left){ y->parent->left = x; }
		else{ y->parent->right = x; }
	}

	if(y != z){ z->key = y->key; }
}


void insert(int k){
	Node y = NIL;
	Node x = root;

	Node z = (Node)malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key){ x = x->left; }
		else{ x = x->right; }
	}
	z->parent = y;

	if(y == NIL){ root = z; }
	else if(z->key < y->key){ y->left = z; }
	else{ y->right = z; }
}

void inorder(Node u){
	if(u == NIL){ return; }
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node u){
	if(u == NIL){ return; }
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

void print(){
	inorder(root);
	puts("");
	preorder(root);
	puts("");
}

int main(){
	int n,i,j,z,x;
	char s[10];

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",s);
		if(s[0] == 'f'){
			scanf("%d",&x);
			Node t = find(root,x);
			if(t == NIL)printf("no\n");
			else printf("yes\n");
		}
		else if(s[0] == 'i'){
			scanf("%d",&z);
			insert(z);
		}
		else if(s[0] == 'd'){
			scanf("%d", &z);
			delete(find(root,z));
		}
		else{ print(); }
	}
	return 0;
}




Measured memory_bytes: 20436
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e6 + 7;
int n, ans, hd = 1, tl;
int a[N], q[N];
char s[N], t[N];
int main() {
#ifdef fwat
#endif
	n = gi();
	scanf("%s%s", s + 1, t + 1);
	if(strcmp(s + 1, t + 1) == 0) return puts("0"), 0;
	for(int i = n, j = n; i; --i) {
		if(t[i] == t[i - 1]) continue;
		j = min(j, i);
		while(j && s[j] != t[i]) --j;
		if(!j) return puts("-1"), 0;
		for(; hd <= tl && q[hd] - (tl - hd + 1) >= i; ++hd);
		if(i != j)
			q[++tl] = j, Max(ans, tl - hd + 1);
	}
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};

vector<P> v1, v2;
map<P, int> Rank;
map<P, P> Parent;
vector<pair<int,  pair<P, P> > > man;

P find(P a);
bool isSame(P a, P b);
void unite(P a, P b);

int main() {

    int N; cin >> N;
    int x, y;
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        v1.push_back(P(x, y));
        v2.push_back(P(y, x));
        Rank[P(x, y)] = 0;
        Parent[P(x, y)] = P(x, y);
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    for (int i = 1; i < N; i++) {
        int cost1 = v1[i].first - v1[i-1].first;
        int cost2 = v2[i].first - v2[i-1].first;
        P temp1 = make_pair(v2[i].second, v2[i].first);
        P temp2 = make_pair(v2[i-1].second, v2[i-1].first);
        man.push_back(make_pair(cost1, make_pair(v1[i], v1[i-1])));
        man.push_back(make_pair(cost2, make_pair(temp1, temp2)));
    }

    sort(man.begin(), man.end());
    /*
    for (int i = 0; i < N; i++){ 
        cout << "cost " << man[i].first << " pair " 
            << man[i].second.first.first <<
            ' ' << man[i].second.first.second << ':' << 
            man[i].second.second.first << ' ' <<  
            man[i].second.second.second << '\n';
    }
    */

    int ans = 0;

    for (int i = 0; i < man.size(); i++) {
        if (isSame(man[i].second.first, man[i].second.second))
            continue;
        unite(man[i].second.first, man[i].second.second);
        ans += man[i].first;

    }

    cout << ans << '\n';

}

P find(P a) {
    
    if (a == Parent[a]) return a;
    else {
        return Parent[a] = find(Parent[a]);
    }
}

bool isSame(P a, P b) {
    return find(a) == find(b);

}

void unite(P a, P b) {
    
    P x = find(a);
    P y = find(b);

    if (x == y) return;

    if (Rank[x] < Rank[y]) {
        Parent[x] = y;
    }
    else {
        Parent[y] = x;
        if (Rank[x] == Rank[y])
            Rank[x]++;
    }
}


Measured memory_bytes: 21984
N = int(input())
A, B = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

n1 = sum(x <= A for x in P)

n2 = len([1 for x in P if (x>A and x < B+1)])  

n3 = sum(x > B for x in P)

print(min(n1, n2, n3))

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

using namespace std;

#define MAX 100
int INFTY = (1<<21);
int num,M[MAX][MAX];
int d[MAX];

void bfs(int s){
  queue<int> q;
  q.push(s);
  int u,i,v;
  for( i = 0; i < num; i++){
    //d[i] = INFINITY;
    d[i] = INFTY;
  }
  d[s] = 0;
  while( !q.empty()){
    u = q.front();
    q.pop();
  for(v = 0; v < num; v++){
    if( M[u][v] == 0){
      continue;
    }
    //if( d[v] != INFINITY){
    if( d[v] != INFTY){
      continue;
    }
    d[v] = d[u]+1;
    q.push(v);
  }
  }
  for(i = 0; i < num; i++){
    //cout << i+1 << " ";
    /*
    if(d[i] == INFINITY){
      cout << (-1);
    }
    else{
      cout << d[i] << endl;
    } 
    */
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
  }
}

int main(){
  int u,k,v,i,j;
  cin >> num;
  for(i = 0; i < num; i++){
    for(j = 0; j < num; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0; i < num; i++){
    cin >> u >> k;;
    u--;
    for(j = 0; j < k; j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  bfs(0);
  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;

int main(){

    ll n, t, a;
    cin >> n >> t >> a;

    int c = 1000;

    vector<ll> h(n, 0);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
        h[i] = c*t - h[i]*6;
    }

    int ans = -1;
    ll ans_h = 10000000;
    for(int i = 0; i < n; i++)
    {
        if (ans_h > abs(c*a-h[i])) {
            ans_h = abs(c*a-h[i]);
            ans = i;
        }
    }
    
    cout << ans+1 << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (c == 1 || a + b == 2)cout << "Open" << endl;
	else cout << "Close" << endl;
	return 0;
}

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

int main(){
   int a,b;
   cin>>a>>b;
   if(a+b == 0){
      cout << 0 << endl;
   }else if(a+b > 0){
      cout << 1 << endl;
   }else if(a+b < 0){
      cout << -1 << endl;
   }
   return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<queue>
using namespace std;
const int MOD=1000000007;
const int MAX = 1000001;

int main(){
    int n,m;
    cin >> n;
    cin >> m;
    vector<long long> p;
    vector<string> s;
    vector<bool> ac;
    vector<long long> ac_n;
    for(int i=0;i<n;i++){
        ac.push_back(false);
        ac_n.push_back(0);
    }
    for(int i=0;i<m;i++){
        long long p_;
        string s_;
        cin >> p_;
        cin >> s_;
        if(ac[p_-1] == false){
            if(s_ == "AC"){
                ac[p_-1] = true;
            }
            else{
                ac_n[p_-1]++;
            }
        }
    } 
    long long ans_ac = 0;
    long long ans_wa = 0;
    for(int i=0;i<n;i++){
        if(ac[i]){
            ans_ac++;

            ans_wa += ac_n[i];
        }
    }
    cout << ans_ac <<" " <<  ans_wa << endl;
}

Measured memory_bytes: 4276
n = int(input())
a = list(map(int, input().split()))

dict = {}
newdict = {}
key = 1
for i in a:
  dict.setdefault(key,i)
  key += 1
newdict = sorted(dict.items(), key=lambda x: x[1])

for a in newdict:
  print(a[0], end="")
  if(a[1] != n):
    print(" ", end="")

Measured memory_bytes: 25564
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ca=dict(Counter(a))
if len(ca.keys())>2:
  print('No')
elif len(ca.keys())==1:
  if 2*a[0]<=n or a[0]==n-1:
    print('Yes')
  else:
    print('No')
else:
  c=max(ca.keys())
  d=min(ca.keys())
  # cといった猫はその猫しかかぶっていない帽子をかぶっている
  # dといった猫はその猫以外にもかぶっている帽子をかぶっている
  if c!=d+1:
    print('No')
  else:
    tmp=c-ca[d]
    # tmp:dといった猫たちがかぶっている帽子の種類数
    if tmp>0 and 2*tmp<=ca[c]:
      print('Yes')
    else:
      print('No')


Measured memory_bytes: 102056
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = max(a * c, max(b * d, max(a * d, b * c)));
    if((a <= 0 && b >= 0) || (c <= 0 && d >= 0)){
        ans = max((ll)0, ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define in auto&it
#define out auto it 
#define rep(i,si,n) for(int i=si;i<n;++i)
#define all ar.begin(),ar.end()
const double pi=acos(-1);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif
	fastio
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=0,ans=0;
	for(int i=0;i<n;++i) if(s[i]=='R') ++ cnt;
	for(int i=0;i<cnt;++i) if(s[i]=='W') ++ans;
		cout<<ans;
	cerr<<"time:  "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<'\n';
	return 0;
}


Measured memory_bytes: 3888
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int N, W; cin >> N >> W;
    vector<int> ws(N), vs(N);
    for (int i = 0; i < N; i++) cin >> ws[i] >> vs[i];
    long long w0 = ws[0];
    for (int i = 0; i < N; i++) ws[i] -= w0;
    vector<vector<int>> dp(N * 3 + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int w = i * 3; w >= 0; w--) for (int k = i; k >= 0; k--) {
            chmax(dp[w + ws[i]][k + 1], dp[w][k] + vs[i]);
        }
    }
    int ma = 0;
    for (int w = 0; w <= N * 3; w++) for (int k = 0; k <= N; k++) {
        long long weight = w0 * k + w;
        if (weight > W) continue;
        chmax(ma, dp[w][k]);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 384
N,K = map(int, input().split())

MOD = 998244353

PAT = []
for _ in range(K):
  l,r = map(int, input().split())
  PAT.append((l,r))
  
IMOS = [0] * (N+10)
IMOS[1] = 1
for i in range(0,N):
  if IMOS[i] == 0:
    continue
  for l,r in PAT:
    if i+l > N+1:
      continue
    IMOS[i+l] += IMOS[i]
    if i+r-1 > N+1:
      continue
    IMOS[i+r+1] -= IMOS[i]
  #print(i, IMOS)
  IMOS[i+1] += IMOS[i]
  IMOS[i+1] %= MOD
  
print((IMOS[N] - IMOS[N-1]) % MOD)
    

Measured memory_bytes: 69508
fun main(args: Array<String>) {
    var n = readLong() - 1
    val a = mutableListOf<Int>()

    while (n >= 0L) {
        val t = (n % 26).toInt()
        a.add(t)
        n /= 26
        n -= 1
    }
    val ans = StringBuilder()
    for (i in a.size - 1 downTo 0) {
        ans.append('a' + a[i])
    }
    println(ans.toString())
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 34340
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
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> h(N + 10);
  REP(i, N) cin >> h[i];
  vector<ll> dp(N+10,1e9);
  dp[0] = 0;
  REP(i, N) {
    chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 4792
# C. One-stroke Path
# https://atcoder.jp/contests/abc054/tasks/abc054_c

from collections import deque

def dfs(i, visited):
    stack = deque()
    total = 0
    stack.append((i, visited))
    while stack:
        idx, vis = stack.popleft()
        if all(vis):
            total += 1
        for j in graph[idx]:
            if not vis[j]:
                v = vis[:]
                v[j] = True
                stack.append((j, v))
    return total

N, M = map(int, input().split())
graph = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

visited = [False] * N
visited[0] = True
print(dfs(0, visited))



Measured memory_bytes: 4332
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iostream>
#include <utility>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
 
using namespace std;
using ll = long long;
using ld = long double;
using Vl = vector<ll>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
using vs = vector<string>;

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

ll N;

int main() {
    cin >> N;
    ll A[N];
    REP(i,N) cin >> A[i];
    ll manzoku=0;
    REP(i,N){
        ll b=0; 
        cin >> b;
        manzoku+=b;
    }
    ll C[N-1];
    REP(i,N-1) cin >> C[i];
    REP(i,N){
        if((A[i+1] -A[i] ) ==1 ){
            manzoku += C[A[i]-1];
        }
    }
    cout << manzoku;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] cnt = new int[m];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                cnt[sc.nextInt() - 1]++;
            }
        }

        for (int i = 0; i < m; i++) {
            if (cnt[i] == n) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23212