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

#define debug(x) cerr << #x <<" = " << x << endl;

const int MAX = 1e5 + 100;
int cost[3][MAX], dp[MAX][3];

int dp_solve(int idx, int last)
{
	if(idx == 0)
	{
		int ans = 0;
		for(int i = 0; i < 3; i++)
			if(i != last)
				ans = max(ans, cost[i][0]);
		return ans;
	}
	int &ans = dp[idx][last];
	if(~ans) return ans;
	ans = 0;
	for(int i = 0; i < 3; i++)
		if(last != i)
			ans = max(ans, dp_solve(idx-1, i) + cost[i][idx]);
	return ans;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < 3; j++)
			scanf("%d", &cost[j][i]);

	memset(dp, -1, sizeof dp);
	int ans = -1;
	for(int i = 0; i < 3; i++)
		ans = max(ans, dp_solve(n-1, i));
	printf("%d\n", ans);
	return 0;
}


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

typedef vector<int> vi;
const int maxn = 100010;
#define pb push_back

vi g[maxn];

int f[maxn];

void dfs(int u,int par) {
	for(auto v: g[u]) if(v != par) dfs(v, u);
	vi t;
	for(auto v: g[u]) if(v != par) t.pb(f[v]);
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	f[u] = 0;
	for(int i = 0; i < t.size(); ++i)
		f[u] = max(f[u], t[i] + i + 1);
}

int main() {
	int n; scanf("%d", &n);
	for(int i = 2; i <= n; ++i) {
		int x; scanf("%d", &x);
		g[x].pb(i);
	}
	dfs(1, 1);
	printf("%d\n", f[1]);
	return 0;
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(c-(a-b),0) << endl;
}


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

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto& p : mp) {
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include "bits/stdc++.h"

using namespace std;

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

    int N;
    cin >> N;
    vector<vector<int>> sum(1010, vector<int>(1010, 0));
    while (N--)
    {
        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        sum[sx][sy]++;
        sum[sx][gy]--;
        sum[gx][sy]--;
        sum[gx][gy]++;
    }
    int ret = sum[0][0];
    for (int i = 0; i <= 1000; i++)
        for (int j = 0; j <= 1000; j++)
        {
            if (i == 0 && j == 0)
                continue;
            else if (i == 0)
                sum[i][j] += sum[i][j - 1];
            else if (j == 0)
                sum[i][j] += sum[i - 1][j];
            else
                sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]);
            ret = max(ret, sum[i][j]);
        }
    cout << ret << endl;
}



Measured memory_bytes: 6848
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int n, a[N];

int check(int x) {
    int res = 0;
    for (int i = 1; i <= n; i++) res += (a[i] - x)*(a[i] - x);
    return res;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int res = 1e9;
    for (int i = -100; i <= 100; i++) {
        res = min(res, check(i));
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N, M;
  cin >> N >> M;
  priority_queue<ll> pq;
  for (ll i=0; i<N; i++) {
    ll num;
    cin >> num;
    pq.push(num);
  }
  for (ll i=0; i<M; i++) {
    ll top = pq.top();
    pq.pop();
    pq.push(top/2);
  }
  ll res = 0;
  while (!pq.empty()) {
    res += pq.top();
    pq.pop();
  }
  cout << res << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> A = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    cout << A[N%10] << endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())

MAXN = 66666
sieve = [0,0] + [1]*MAXN
p = 2
while p*p <= MAXN:
    if sieve[p]:
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

ans = []
for n in range(11,MAXN,10):
    if sieve[n]:
        ans.append(n)
        if len(ans) == N: break
print(*ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int s = 0;
    rep(i,n) s ^= a[i];
    rep(i,n) a[i] ^= s;
    rep(i,n) cout << a[i] << endl;
    return 0;
}

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

int main(){
	long long a;
	string b;
	cin >> a >> b;
	b.erase(1,1);
	long long bout=(long long)stoi(b);
	long long ans=a*bout/100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, sum=0,x, distB;
  cin >> N >> K;

  while(N > 0){
    cin >> x;
    distB = K - x;
    if(x > distB) sum += distB*2;
    else sum += x*2;
   
    N--;
  }

  cout << sum << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
const ll inf = 1e15;
struct edge{
  ll to, cost;
  edge(ll t, ll c) {
    to = t, cost = c;
  }
};
int N, M;
ll d[100005];
vector<edge> G[100005];
void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >que;
  FOR(i,1,N+1) d[i] = inf;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto &e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int s, t; cin >> N >> M >> s >> t;
  ll dd[N]; FOR(i,0,N) cin >> dd[i];
  FOR(i,0,M) {
    int a, b; cin >> a >> b;
    if(b <= s) dd[b-1] = 0;
    G[a].push_back(edge(b, dd[b-1]));
  }
  FOR(i,1,N) {
    G[i+1].push_back(edge(i, 0));
  }
  if(s >= t) {
    cout << 0 << endl;
    return 0;
  }
  dijkstra(s);
  ll ans = 1e15;
  FOR(i,t,N+1) {
    ans = min(ans, d[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14260
def solve(string):
    a, b, q, *stx = map(int, string.split())
    s = sorted(stx[:a] + [-10**10, 2 * 10**10])
    t = sorted(stx[a:a + b] + [-10**10, 2 * 10**10])
    x = {_q: -1 for _q in stx[-q:]}
    i_s = 0
    i_t = 0
    for _x in sorted(x.keys()):
        while s[i_s] < _x:
            i_s += 1
        while t[i_t] < _x:
            i_t += 1
        l_s, r_s = s[i_s - 1], s[i_s]
        l_t, r_t = t[i_t - 1], t[i_t]
        r_max = max(r_s, r_t)
        l_min = min(l_s, l_t)
        x[_x] = min([
            r_max - _x, _x - l_min, r_t - l_s + min(r_t - _x, _x - l_s),
            r_s - l_t + min(r_s - _x, _x - l_t)
        ])
    return "\n".join([str(x[_x]) for _x in stx[-q:]])


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


Measured memory_bytes: 42508
n = gets.to_i
l = gets.chomp.split.map(&:to_i)

cnt = 0

n.times do |a|
  (a+1).upto(n-1) do |b|
    (b+1).upto(n-1) do |c|
      x = l[a]
      y = l[b]
      z = l[c]

      if (x != y and y != z and z != x) and (x + y > z and x + z > y and y + z > x)
        cnt += 1
      end
    end
  end
end

puts cnt

Measured memory_bytes: 14408
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int a, b, c;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c;
    a -= b;
    c = max(0, c - a);
    cout << c << '\n';
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

string a="abcdefghijklmnopqrstuvwxyz";

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

  string s;
  cin>>s;
  int ans=INT_MAX;
  for(auto it:a){
    bool all=true;
    for(auto c:s)if(c!=it)all=false;
    if(all){
      ans=min(ans,0);
      break;
    }
    string ss=s;
    for(int i=0;i<100;i++){
      string sss="";
      for(int j=0;j<ss.size()-1;j++){
        if(ss[j]==it||ss[j+1]==it)sss.push_back(it);
        else sss.push_back('*');
      }
      ss=sss;
      bool ok=true;
      for(auto c:ss)if(c!=it)ok=false;
      if(ok){
        ans=min(ans,i+1);
        break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    bool solve(vector<vector<int>>& M, vector<int>& A) {
        set<int> st(A.begin(), A.end());

        int n = M.size();
        int m = M[0].size();
        assert(n == m);

        vector<vector<pair<int,int>>> C;
        for (int i = 0; i < n; ++i) {
            C.emplace_back();
            for (int j = 0; j < m; ++j) {
                C.back().emplace_back(i, j);
            }
        }
        for (int j = 0; j < m; ++j) {
            C.emplace_back();
            for (int i = 0; i < n; ++i) {
                C.back().emplace_back(i, j);
            }
        }

        C.emplace_back();
        for (int i = 0; i < n; ++i) {
            C.back().emplace_back(i, i);
        }
        C.emplace_back();
        for (int i = 0; i < n; ++i) {
            C.back().emplace_back(i, n - 1 - i);
        }

        for (auto & X : C) {
            int cnt = 0;
            for (auto& p : X) {
                if (st.count(M[p.first][p.second]) != 0) {
                    ++cnt;
                }
            }
            if (cnt == n) {
                return true;
            }
        }
        return false;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    vector<vector<int>> M(3, vector<int>(3, 0));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> M[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;

    if (sol.solve(M, A)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll, ll> P;

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

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

struct BIT {
	typedef ll input_t;

	vector<input_t> bit_;
	const long long n_;

	BIT(long long n) :n_(n) {
		bit_.resize(n + 1LL, 0);
	}

	input_t sum(int i) {
		input_t s = 0;
		while (i > 0) {
			s += bit_[i];
			i -= i & (-i);
		}
		return s;
	}

	void add(int i, input_t x) {
		while (i <= n_) {
			bit_[i] += x;
			i += (i & (-i));
		}
	}
};


int main() {
	ll n, q;
	cin >> n >> q;
	vector<ll> cs(n+1);
	rep(i, n) cin >> cs[i+1];
	vector<ll> pos(n+1, -1);
	vector<P> range(q);
	rep(i, q){
		cin >> range[i].first >> range[i].second;
	}
	vector<vector<int>> qs(n + 1);
	rep(i, q) {
		qs[range[i].second].push_back(i);
	}
	BIT bit(n+10);
	vector<ll> ans(q);
	ll rightSum = 0;
	for (int i = 1; i <= n; i++) {
		auto c = cs[i];
		if (pos[c] >= 0) {
			bit.add(pos[c], -1);
			rightSum--;
		}
		pos[c] = i;
		bit.add(i, 1);
		rightSum++;
		ll sum = rightSum;
		for (auto query : qs[i]) {
			auto index = query;
			auto left = range[index].first;
			if (left > 1) {
				ans[index] = sum - bit.sum(left - 1);
			}
			else {
				ans[index] = sum;
			}
		}
	}
	rep(i, q) {
		cout << ans[i] << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	ll a, b, k;
	cin >> a >> b >> k;
	ll ra, rb;
	if (k <= a) {
		ra = a - k;
		rb = b;
	} else if (k>a && k <= a+b) {
		ra = 0;
		rb = b + a - k;
	} else {
		ra = 0;
		rb = 0;
	}
	cout << ra << " " << rb << endl;
	return 0;
}

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

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

    vector<long long> A(n-1);
    for(int i=0; i<n-1; i++){
        cin >> A.at(i);
    }

    vector<long long> B(n,0);

    for(int i=0; i<n-1; i++){
        B.at(A.at(i)-1)++;
    }

    for(int i=0; i<n; i++){
        cout << B.at(i) << endl;
    }

    
}


Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main() {
    string s=sin();
    ll count=0;
    ll ans=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s.at(i)=='A'){
            ans+=count;
        }
        else if(i>0){
            if(s.at(i)=='C'&&s.at(i-1)=='B'){
                count++;
                i--;
            }
            else{
                count=0;
            }
        }
        else{
            count=0;
        }
    }
    cout<<ans<<endl;
}

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


int main(){
    ll n; cin>>n;
    vector<ll> a(n), b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) b[i] = a[i] + i;
    map<ll,ll> m;
    rep(i,n) m[b[i]]++;
    ll res=0;
    for(ll i=n-1; i>=0; i--){
        m[a[i] + i]--;
        res += m[i - a[i]];
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; s.at(i) != 'A';++i){
    count++;
  }
  int zcount = s.size();
 for(int i = s.size()-1; s.at(i) != 'Z'; --i){
   zcount--;
 }
  
  cout << zcount - count<< endl;
}


Measured memory_bytes: 640
def f(k):
    c = 0
    while k % 2 == 0:
        k = k // 2
        c += 1
    return c


def main():
    input()
    a = [int(a) for a in input().split()]

    c = 0
    for k in a:
        c += f(k)
    print(c)


if __name__ == '__main__':
    main()


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


int main()
{
  int n,k;
  cin>>n;
  cin>>k;
  int ar[n];
  for(int i=0 ; i<n ; ++i)
  {
    cin>>ar[i];
  }
  sort(ar,ar+n);
  int ans=0;
  for(int i=0 ; i<k ; ++i)
  ans+=ar[i];
  cout<<ans;
  
  return 0 ; 
}


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

using ll = long long int;

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

ll a, b;

vector<ll> store;

ll ans = 0;

ll count_one(ll k, ll x) {
  ll band = (ll) powl(2, k + 1);

  ll dude = (ll) powl(2, k);

  ll part = (x + 1) / band;

  ll num = dude * part;

  ll cut = (x + 1) % band;

  if (cut == 0) {
    return num;
  }
  else {
    if (cut >= (band / 2) + 1) {
      return num + cut - ((band / 2) + 1) + 1;
    }
    else {
      return num;
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%lld %lld", &a, &b);

  int size = log2(b) + 1;

  for (int i = 0; i <= size; ++i) {
    ll bottom = count_one(i, a - 1);
    ll top = count_one(i, b);

    ll num_one = top - bottom;

    if (num_one % 2 == 0) {
      store.push_back(0);
    }
    else {
      store.push_back(1);
    }
  }

  for (int i = 0; i < store.size(); ++i) {
    ll tmp = (ll) powl(2, i);
    ll diff = tmp * store[i];
    ans += diff;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 512
N = int(input())
a = list(map(int,input().split()))

numbers = [0] * (max(a)+1)
for i in range(N):
    numbers[a[i]] += 1

ans = 0

if len(numbers) < 3:
    print(sum(numbers))
    exit()

for i in range(len(numbers)-2):
    ans = max(ans,sum(numbers[i:i+3]))

print(ans)

Measured memory_bytes: 13964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, d;
  cin >> n >> d;
  int ans = 0;
  rep(i, n){
    ll x, y, dist;
    cin >> x >> y;
    dist = x*x + y*y;
    if(dist <= d*d) ans++;
    else continue;
  }
  
  cout << ans << endl;
return 0;
}



Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)>(b) ? (b):(a))
int main(){
  int n,i;
  int x = 1000000000;
  int y = 0;
  scanf("%d",&n);
  int a[n+100];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    x = min(x,a[i]);
    y = max(y,a[i]);
  }

  printf("%d",y-x);

  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int a = sc.nextInt();
			if (n == 0 && m == 0 && a == 0)
				break;
			int[][] amida = new int[1000][n];

			int max = 0;
			for (int i = 0; i < m; i++) {
				int h = sc.nextInt();
				int p = sc.nextInt();
				int q = sc.nextInt();

				amida[h - 1][p - 1] = i + 1;
				amida[h - 1][q - 1] = i + 1;
				if (h > max)
					max = h;
			}

			// for (int i = 0; i < 1000; i++) {
			// for (int j = 0; j < n; j++) {
			// System.out.print(amida[i][j]);
			// }
			// System.out.println();
			// }

			System.out.println(search(amida, max - 1, a - 1));
		}
		sc.close();
	}

	private static int search(int[][] amida, int max, int a) {
		int ans = 0;
		while (max >= 0 && a >= 0 && a <= amida[max].length) {
			if (amida[max][a] == 0) {
				max = max - 1;
			} else if (a - 1 >= 0 && amida[max][a] == amida[max][a - 1]) {
				a -= 1;
				max -= 1;
			} else if (a + 1 <= amida[max].length
					&& amida[max][a] == amida[max][a + 1]) {
				a += 1;
				max -= 1;
			}
			ans = a + 1;
		}
		return ans;
	}
}

Measured memory_bytes: 69024
#include <stdio.h>
int main()
{
int a, b ,c, d, e, f;
d = 0 ;
e = 0 ;
f = 0 ;
scanf("%d %d %d",&a, &b, &c);
if(a > b)
{ d = a;
  a = b;
  b = d;
}
while(a <= b)
{
  e = c % a;
  if(e == 0){
  f++;
 }
  a++;
}
printf("%d\n",f);
 
return 0 ;
}


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

int main()
{
  long long a, b, k;
  cin >> a >> b >> k;
  
  if (k > a) {
	  if ((k - a) > b)
    		cout << 0 << " " << 0;
	  else
	  cout << 0 << " " << b - (k - a);
  }
  else {
    cout << a - k << " " << b;
  }
}


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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n){
		cin>>a[i];
	}
	ll s=0;
	rep(i,1,n){
		if(a[i]<a[i-1]){
			s+=a[i-1]-a[i];
			a[i]=a[i-1];
		}

	}
	cout<<s;
	
	
	
	return 0;
}

Measured memory_bytes: 5156
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;


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

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

    if(total % 10 == 0){
        for(int i=0; i<N; i++){
            if(v[i] % 10 != 0){
                cout << total - v[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
        return 0;
    } else {
        cout << total << endl;
        return 0;
    }
}


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

int main() {
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++){
      cin>>L[i];
  }
  int C=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(L[i]+L[j]>L[k]&&L[i]+L[k]>L[j]){
          if(L[j]+L[k]>L[i]&&L[i]!=L[j]){
            if(L[i]!=L[k]&&L[j]!=L[k]){
              C+=1;
            }
          }
        }
      }
    }
  }
  cout<<C<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N, M;
  IN(N,M);
  vpll AB;
  REP(n,N){
    ll A, B;
    IN(A, B);
    if(A>M) continue;
    AB.pb(make_pair(A, -B));
  }

  sort(ALL(AB));

  vll M_map(M+1, 0);

  priority_queue<pair<ll, ll>> que;
  /*
  REP(i,AB.size()) que.push(make_pair(-AB[i].second, i));
  while(!que.empty()){
    pair<ll, ll> tmp = que.top(); que.pop();
    printf("%lld %lld\n", tmp.first, tmp.second);
  }
  */
  ll n_start = 0;
  FOR(m,1,M+1){
    if(n_start>=AB.size()){
      if(que.empty()) break;
      pair<ll, ll> tmp = que.top();
      M_map[m] = tmp.first;
      que.pop();
    }else{
      if(que.empty() && AB[n_start].first>m) continue;
      if(AB[n_start].first<=m){
        while(AB[n_start].first<=m){
          que.push(make_pair(-AB[n_start].second, n_start));
          n_start++;
          if(n_start>=AB.size()) break;
        }
      }
      if(!que.empty()){
        pair<ll, ll> tmp = que.top();
        M_map[m] = tmp.first;
        //printf("%lld %lld\n", m, M_map[m]);
        que.pop();
      }
    }
  }

  ll ans = 0;
  REP(m,M+1) ans += M_map[m];
  OUT(ans);


  return 0;
}

Measured memory_bytes: 5616
// AOJ 1192: Tax Rate Changed
// 2017.9.14 bal4u@uu
// 2017.12.22

#include <stdio.h>
 
 char buf[15], *p;
 
 int in()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
    int x, y, s, p1, p2, t, ans;
 
    while (fgets(p=buf, 15, stdin) && *p != '0') {
		x = in(), y = in(), s = in();
		ans = 0;
        for (p1 = 1; p1 < s; p1++) for (p2 = s-p1; p2 >= p1; p2--) {
			t = p1*(100+x)/100 + p2*(100+x)/100;
			if (t < s) break;
			if (t != s) continue;
            t = p1*(100+y)/100 + p2*(100+y)/100;
			if (t > ans) ans = t;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1752
N,W = map(int,input().split())
dp = [[0 for i in range(W+1)]for j in range(N+1)]
v_list = []
w_list = []
for i in range(N):
    v,w = map(int,input().split())
    v_list.append(v)
    w_list.append(w)


for i in range(N):
    for j in range(W+1):
        if j - w_list[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j-w_list[i]]+v_list[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])



Measured memory_bytes: 42268
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,d;
    cin>>n>>d;
    d=2*d+1;
    cout<<ceil(double(n)/double(d))<<endl;
    return 0;
}


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

typedef long long int ll;

const int MAX = 2e5 + 10;

int main()
{
	int n; cin>>n;
	int a[MAX]; int ans=0;
	for(int i=0;i<n;i++) cin>>a[i];

	for(int i=0;i<n;i++){
		if(a[i] == i+1){
			swap(a[i],a[i+1]); ans++;
		}
	}

	cout<<ans;	
}

// abcab

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
int main(){
    int n;
    cin>>n;
    string s, t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 3596
import numpy as np
s = input()
temp = s
temp = temp.replace("x","")
is_rev = True

mirro = []

if len(temp) == 0:
    print(0)
else:
    for i in range(len(temp)//2):
        if temp[i] == temp[-i-1]:
            mirro.append(temp[i])
            continue
        else:
            is_rev = False
    if len(temp) %2 == 1:
        mirro.append(temp[len(temp)//2])

    if is_rev:
        ind = 0
        i = 0
        lx = np.array([0 for i in range(len(temp)//2+len(temp)%2)])
        rx = np.array([0 for i in range(len(temp)//2+len(temp)%2)])
        temp = 0
        while (True):
            if s[i] == mirro[ind]:
                lx[ind] = temp
                temp = 0
                ind += 1
                i += 1
            else:
                temp += 1
                i += 1

            if ind > len(mirro)-1:
                break
        ind = 0
        i = -1
        temp = 0
        while (True):
            if s[i] == mirro[ind]:
                rx[ind] = temp
                temp = 0
                ind += 1
                i -= 1
            else:
                temp += 1
                i -= 1

            if ind > len(mirro)-1:
                break
        # print(lx)
        # print(rx)
        print(np.sum(np.abs(lx-rx)))
    else:
        print(-1)

Measured memory_bytes: 14656
#include <stdio.h>

int main(void) {

        int a, b;

        

        scanf("%d%d", &a, &b);

        

        if(a == b) {

            printf("a == b\n");

        }

        else if(a > b) {

            printf("a > b\n");

        }

        else {

            printf("a < b\n");

        }

        return 0;

}



Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int s,mod = 1000000000;
	cin >> s;
	int a,b,c = 1,d;
	a = ((s % mod) ? (mod - s % mod) : 0);
	s += a;
	d = s / mod - 1;
	b = mod - a;
	printf("%lld %lld %lld %lld %lld %lld\n",0ll,0ll,a,c+d,a+b,c);
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
w1 = 0
w2 = W
h1 = 0
h2 = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1 and w1 < x:
    w1 = x
  elif a == 2 and w2 > x:
    w2 = x
  elif a == 3 and h1 < y:
    h1 = y
  elif a == 4 and h2 > y:
    h2 = y
wa = w2 - w1
if wa < 0:
  wa = 0
ha = h2 - h1
if ha < 0:
  ha = 0
ans = wa * ha
print(ans)
    

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


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

	//typedef tree<
			//int,
			//null_type,
			//less<int>,
			//rb_tree_tag,
			//tree_order_statistics_node_update>
	//ordered_set;
	

//#define REP(i,m) for(int i=0;i<(m);++i)
//struct dsu{
	//static const int MAXN=105;
	//int par[MAXN];
	//int size[MAXN];
	//void init(){
		//memset(par,-1,sizeof(par));
		//REP(i,MAXN) size[i]=1;
	//}
	//int root(int a){
		//if(par[a]==-1) return a;
		//return par[a]=root(par[a]);
	//}
	//void unite(int a,int b){
		//a=root(a);b=root(b);
		//if(a==b) return;
		//if(size[a]<size[b]) swap(a,b);
 
		//par[b]=a;
		//size[a]+=size[b];
	//}
	//bool same(int a,int b){
		//return root(a)==root(b);
	//}
//};	

#define ll long long 

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	ll n;cin>>n;
	ll ac=0,wa=0,tle=0,re=0;
	for(int i=0;i<n;i++){
		string str;cin>>str;
			if(str=="AC") ac++;
			else if(str=="WA") wa++;
			else if(str=="TLE") tle++;
			else re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
	return 0;
	
}


Measured memory_bytes: 3664
N=int(input())
S=input()

numlist=[1 for i in range(N)]

if S=="E"*N or S=="W"*N:
    numlist[0]=0
else:
    num_0=0
    for i in range(1,N):
        if S[i]=="E":
            num_0+=1
    numlist[0]=num_0

for i in range(1,N):
    p=numlist[i-1]
    if S[i-1]=="W":
        p+=1
    if S[i]=="E":
        p-=1
    numlist[i]=p

print(max(min(numlist),0))

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;

map<string, ll> mp;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  rep(i, n){
    string t;
    cin >> t;
    sort(all(t));
    mp[t]++;
  }
  ll res = 0;
  irep(itr, mp){
    res += (itr->second) * (itr->second - 1) / 2;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
	string s; cin>>s;
	int cnt=1;
	for(int i=0; i<n-1; i++){
		if(s[i]!=s[i+1]) cnt++;
	}
	cnt=max(1, cnt-2*k);
	cout<<n-cnt<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using namespace std;
map<string,ll> f;
vector<string> e;
int main(){
  ll n,k,ans=1,tmp=1;
  string x;
  cin>>n;
  rep(i,0,n){cin>>x;f[x]++;}
  for(auto i:f)ans=max(ans,i.second);
  for(auto i:f)if(i.second==ans)e.pb(i.first);
  sort(e.begin(),e.end());
  for(auto i:e)cout<<i<<endl;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
    int n; cin >> n;
    
    v a(n);
    
    rep(i,n)cin >> a[i];
    
    sort(a.rbegin(), a.rend());
    
    ll ans=1;
    int count=0;
    
    rep(i,n-1){
        if(count==2)break;
        if(a[i]==a[i+1]){
            ans *= a[i];
            i++;
            count++;
        }
    }
    if(count!=2){
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int idx = partition(a, 0, a.length - 1);
		StringBuilder sb = new StringBuilder();
		if (idx == 0) {
			sb.append("[").append(a[0]).append("]");
		} else {
			sb.append(a[0]);
		}
		for (int i = 1; i < n; i++) {
			sb.append(' ');
			if (idx == i) {
				sb.append("[").append(a[i]).append("]");
			} else {
				sb.append(a[i]);
			}
		}
		System.out.println(sb.toString());
	}

	private static int partition(int[] a, int p, int r) {
		int x = a[r];
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (a[j] <= x) {
				i++;
				swap(a, i, j);
			}
		}
		swap(a, i + 1, r);
		return i + 1;
	}
	
	private static void swap(int[] a, int i, int j) {
		int temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	}
}



Measured memory_bytes: 38748
import java.util.Scanner;

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

        int rowCount = Integer.parseInt(sc.nextLine());

        int minNum = Integer.parseInt(sc.nextLine());
        int maxProfit = Integer.MIN_VALUE;

        for (int i = 1; i < rowCount; i++) {

            int num = Integer.parseInt(sc.nextLine());

            maxProfit = Math.max(maxProfit, num - minNum);
            minNum = Math.min(minNum, num);

            // System.out.printf("num:%3d, minNum:%3d, profit:%3d\n", num, minNum, maxProfit);
        }

        System.out.println(maxProfit);
    }
    // public static void main(String[] args) {

    //     Scanner sc = new Scanner(System.in);

    //     int N = Integer.parseInt(sc.nextLine());

    //     int[] nums = new int[N];
    //     for(int i=0; i<N; i++) {
    //         // int a = Integer.parseInt(sc.nextLine());
    //         int a = sc.nextInt();
    //         nums[i] = a;
    //     }

    //     int maxProfit = Integer.MIN_VALUE;
    //     for (int i = 1; i < nums.length; i++) {
    //         for (int j = 0; j < i; j++) {
    //             // System.out.printf("%d %d -> %d\n", nums[i], nums[j], nums[i] - nums[j]);

    //             maxProfit = Math.max(maxProfit, nums[i] - nums[j]);
    //         }
    //     }


    //     System.out.println(maxProfit);
    // }
}


Measured memory_bytes: 165224
//
//  main.cpp
//  B - Popular Vote
//
//  Created by Hashizo on 2020/04/04.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll ans = 0;
	
	
	ll n,m;
	cin >> n >> m;
	
	
	ll sum = 0;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	double aa = ceil(((double)((double)sum / (double)(4*m))));
	ans  = (ll) aa;
	
	ll cnt = 0;
	REP(i, n) {
		
		if (ans <= a[i]) {
			cnt++;
			if( cnt >= m ) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
struct node{
	int a,bianhao;
	bool operator<(const node &b)const{
		if(a!=b.a) return a<b.a;
	}
}A[100005];
using namespace std;
int N;
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i].a);A[i].bianhao=i;
	}
	sort(A,A+N);
	for(int i=0;i<N;i++){
		if(i==N-1)  printf("%d\n",A[i].bianhao+1);
		else printf("%d ",A[i].bianhao+1);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H, W; cin >> H >> W;
	vector<string> c(H);
	rep (i, H) cin >> c[i];
	rep (i, H){
		cout << c[i] << endl;
		cout << c[i] << endl;
	} // end rep

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)

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

  a*b>c*d ? cout<<a*b<<endl : cout<<c*d<<endl;


  return 0;
}


Measured memory_bytes: 256
inputs = list(map(lambda x: int(x), input().strip().split()))

H = inputs[0]
W = inputs[1]

ahw = []

for i in range(H):
    w =list(map(lambda x: int(x), input().strip().split())) 
    ahw.append(w)

N = 0
hasCoin = 0
sousa = []

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            if ahw[i][j] % 2 == 0:
                continue

            if not j == W - 1:
                ahw[i][j] = ahw[i][j] - 1
                ahw[i][j+1] = ahw[i][j+1] + 1
                sousa.append("{} {} {} {}".format(i+1, j+1, i+1 , j+2))
                N += 1
            else:
                if i != H - 1:
                    ahw[i][j] = ahw[i][j] - 1
                    ahw[i+1][j] = ahw[i+1][j] + 1
                    sousa.append("{} {} {} {}".format(i+1, j+1, i+2 , j+1))
                    N += 1
    else:
        for j in range(W - 1, -1, -1):
            if ahw[i][j] % 2 == 0:
                continue

            if not j == 0:
                ahw[i][j] = ahw[i][j] - 1
                ahw[i][j-1] = ahw[i][j-1] + 1
                sousa.append("{} {} {} {}".format(i+1, j+1, i+1 , j))
                N += 1
            else:
                if i != H - 1:
                    ahw[i][j] = ahw[i][j] - 1
                    ahw[i+1][j] = ahw[i+1][j] + 1
                    sousa.append("{} {} {} {}".format(i+1, j+1, i+2 , j+1))
                    N += 1

print(N)
for el in sousa:
    print(el)


Measured memory_bytes: 16476
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B; cin >> A >> B;
    cout << 6 - A - B << "\n";
}

Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
query = []

for i in range(n):
	n, t = map(str, input().split())
	query.append([n, int(t)])

d = deque(query)

ans = []

time = 0
while len(d) > 0:
	tmp = d.popleft()
	if tmp[1] > q:
		res = [tmp[0], tmp[1] - q]
		time += q
		d.append(res)
	else:
		time += tmp[1]
		ans.append([tmp[0], time])

for v in ans:
	print(v[0], v[1])


Measured memory_bytes: 19576
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    int n;
    cin >> n;
    ll power = 1;
    for (int i = 1; i < n+1; i++)
    {
        power *= i;
        power %= MOD;
    }
    cout << power << endl;
}

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

Measured memory_bytes: 256
[N, K] = list(map(int, input().split()))
dList = []
AList = []
snuckSnack = {}
for i in range(K):
    dList.append(int(input()))
    AList.append(list(map(int, input().split())))
for i in range(1,N+1):
    snuckSnack[i] = set()
for i in range(K):
    for j in AList[i]:
        snuckSnack[j].add(dList[i])
vicCount = 0
for i in range(1,N+1):
    if snuckSnack[i] == set():
        vicCount += 1
print(vicCount)

Measured memory_bytes: 9212
N, M = [int(_) for _ in input().split()]
PY = [[int(_) for _ in input().split()] + [_] for _ in range(M)]
# 2番目のKeyでソート
PY.sort(key = lambda x : x[1])
# 順番カウント用
cnt = [0] * (N + 1)
ans = [""] * M

for p, y, i in PY:
    # 何番目かカウント
    cnt[p] += 1
    # 答え
    ans[i] = str(p).zfill(6) + str(cnt[p]).zfill(6)

print("\n".join(ans))

Measured memory_bytes: 34500
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def bfs(field, sx, sy, seen):
    queue = deque([(sx, sy)])
    seen[sx][sy] += 1
    
    while queue:
        x, y = queue.popleft()

        for dx, dy in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
            nx = x + dx
            ny = y + dy
            
            if seen[nx][ny] == -1 and field[nx][ny] != "#":
                seen[nx][ny] = seen[x][y] + 1
                queue.append((nx, ny))

    return seen[x][y]


def main():
    H,W = map(int, readline().split())
    c = ["#" * (W + 2)]
    for _ in range(H):
        c.append("#" + readline().strip() + "#")
    c.append("#" * (W + 2))

    ans = 0
    for sx in range(1,H+1):
        for sy in range(1,W+1):
            if c[sx][sy] == ".":
                seen = [[-1] * (W + 2) for i in range(H+2)]
                dist = bfs(c, sx, sy, seen)
                ans = max(ans, dist)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3436