akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter
import heapq as hq

n, m = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
hq.heapify(a_list)

temp_list = [[int(x) for x in input().split()] for _ in range(m)]
temp_list.sort(key=itemgetter(1), reverse=True)
for b, c in temp_list:
    for i in range(b):
        if a_list[0] < c:
            hq.heapreplace(a_list, c)
        else:
            print(sum(a_list))
            exit()
print(sum(a_list))

Measured memory_bytes: 27108
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
//ll mod=1000000007;
//ll mod=67280421310721;
ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
//			re%=mod;
		}
		a=(a*a);
//		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		ll a[n];
		map<ll,int> cn;
		ll ans=0;
		FOR(i,0,n)
		{
			cin>>a[i];
			if(a[i]<=(i+1))
			ans+=cn[i+1-a[i]];
			cn[a[i]+i+1]++;
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 18896
#include<iostream>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    if (n == 1 || m == 1)
        cout << "1\n";
    else
        cout << n / 2 * m + n % 2 * ((m + 1) / 2) << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        s = s.Replace("BC", "X");

        Console.WriteLine(Regex.Matches(s, "[AX]*").Cast<Match>().Select(x => getScore(x.Value)).Sum());
    }
    static long getScore(string s)
    {
        long countA = 0;
        long res = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'A') countA++;
            else res += countA;
        }
        return res;
    }
    /*
    static long getScore(string s)
    {
        var a = s.TakeWhile(x => x == 'A').Count() - 1;
        var abc = s.Count(x => x == 'A') - a;
        var bc = s.Count(x => x == 'C') - abc;
        var score = getScore(a, abc, bc);
        Console.WriteLine($"{s} a : {a} abc : {abc} bc : {bc}\nscore : {score}");
        return score;
    }
    static long getScore(long a, long abc, long bc)
    {
        long res = 0;
        var incr = Min(a, bc);

        res += abc * (incr + 1) + incr * (incr + 1) / 2;

        var stay = Abs(a - bc);
        abc += incr;

        res += stay * abc;

        abc -= 1;

        res += abc * (abc + 1) / 2;

        return res;
    }*/
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b;
  cin>>a>>b;
  puts(a==2 || b==2 ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

bool chmin(ll& a, ll b) {
	bool x = a > b;
	a = min(a, b);
	return x;
}

int main() {
	ll H, W, K;
	cin >> H >> W >> K;
	ll x1, x2, y1, y2;
	cin >> x1 >> y1;
	cin >> x2 >> y2;
	x1--, x2--, y1--, y2--;
	vector<string> S(H);
	vector<vector<vector<ll>>> M(4, vector<vector<ll>>(H, vector<ll>(W, MOD)));
	for (ll i = 0;i < H;i++) {
		cin >> S[i];
	}
	queue<tuple<ll, ll, ll, ll>> Q;
	Q.push(make_tuple(0, x1, y1, 0));
	Q.push(make_tuple(0, x1, y1, 1));
	Q.push(make_tuple(0, x1, y1, 2));
	Q.push(make_tuple(0, x1, y1, 3));
	ll d, x, y, t;

	M[0][x1][y1] = M[1][x1][y1] = M[2][x1][y1] = M[3][x1][y1] = 0;

	while (!Q.empty()) {
		tie(t, x, y, d) = Q.front();
		Q.pop();
		if (d == 0) {
			for (ll i = 1;i <= K;i++) {
				if (x - i < 0)break;
				if (M[0][x - i][y] <= t)
					break;
				if (S[x - i][y] == '@')break;

				M[0][x - i][y] = t + 1;
				if (i == K)Q.push(make_tuple(t + 1, x - i, y, 0));

				if (chmin(M[1][x - i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x - i, y, 1));
				}
				if (chmin(M[2][x - i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x - i, y, 2));
				}
				if (chmin(M[3][x - i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x - i, y, 3));
				}
			}
		}

		else if (d == 1) {
			for (ll i = 1;i <= K;i++) {
				if (x + i >= H)break;
				if (M[1][x + i][y] <= t)
					break;
				if (S[x + i][y] == '@')break;

				M[1][x + i][y] = t + 1;
				if (i == K)Q.push(make_tuple(t + 1, x + i, y, 1));

				if (chmin(M[0][x + i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x + i, y, 0));
				}
				if (chmin(M[2][x + i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x + i, y, 2));
				}
				if (chmin(M[3][x + i][y], t + 1)) {
					Q.push(make_tuple(t + 1, x + i, y, 3));
				}
			}
		}

		else if (d == 2) {
			for (ll j = 1;j <= K;j++) {
				if (y - j < 0)break;
				if (M[2][x][y - j] <= t)
					break;
				if (S[x][y - j] == '@')break;

				M[2][x][y - j] = t + 1;
				if (j == K)Q.push(make_tuple(t + 1, x, y - j, 2));

				if (chmin(M[1][x][y - j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y - j, 1));
				}
				if (chmin(M[0][x][y - j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y - j, 0));
				}
				if (chmin(M[3][x][y - j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y - j, 3));
				}
			}
		}
		else {
			for (ll j = 1;j <= K;j++) {
				if (y + j >= W)break;
				if (M[3][x][y + j] <= t)
					break;
				if (S[x][y + j] == '@')break;

				M[3][x][y + j] = t + 1;
				if (j == K)Q.push(make_tuple(t + 1, x, y + j, 3));

				if (chmin(M[1][x][y + j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y + j, 1));
				}
				if (chmin(M[0][x][y + j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y + j, 0));
				}
				if (chmin(M[2][x][y + j], t + 1)) {
					Q.push(make_tuple(t + 1, x, y + j, 2));
				}
			}
		}
	}
	d = min({ M[0][x2][y2],M[1][x2][y2],M[2][x2][y2],M[3][x2][y2] });
	if (d >= MOD) {
		cout << -1 << endl;
	}
	else {
		cout << d << endl;
	}
}

Measured memory_bytes: 50192
n, m = gets.split.map(&:to_i)
edge = Array.new(n+1) {[]}
m.times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

x = Array.new(n+1)
x[1] = 0
edge[1].each {|i| x[i] = 1}
que = edge[1]
while y = que.shift
    edge[y].each do |i|
        next if x[i]
        x[i] = y
        que << i
    end
end

puts "Yes", x[2..-1]

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

int main(void) {

    int N;

    while (cin >> N, N) {
        int cnt = 0;
        pair<bool, bool> legs;
        legs.first = false;
        legs.second = false;
        bool onfloor = true;

        for (int i = 0; i < N; i++) {
            string f; cin >> f;

            if (f == "lu") {
                legs.first = true;
                if (onfloor && legs.second) {
                    cnt++;
                    onfloor = false;
                }
            }
            else if (f == "ru") {
                legs.second = true;
                if (onfloor && legs.first) {
                    cnt++;
                    onfloor = false;
                }
            }
            else if (f == "ld") {
                legs.first = false;
                if (!onfloor && !legs.second) {
                    cnt++;
                    onfloor = true;
                }
            }
            else if (f == "rd") {
                legs.second = false;
                if (!onfloor && !legs.first) {
                    cnt++;
                    onfloor = true;
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3112
<?php
  
  $n = trim(fgets(STDIN));

  $a = explode(" ",trim(fgets(STDIN)));
  $b = [];

  $count=count($a);
  for($i=0;$i<$count;$i++){
    if(isset($b[$a[$i]])){
      echo "NO";
      exit;
    }
    $b[$a[$i]] = "";
  }
  echo "YES";

Measured memory_bytes: 33780
#include <iostream>                                                                           
using namespace std;                                                                          
int main(){                                                                                   
  int a,b,ret;                                                                                
  string op;                                                                                  
  cin >> a >> op >> b;                                                                        
  while (op!="?"){                                                                            
    if  (op=="+"){                                                                            
      ret = a+b;                                                                              
    } else if(op == "-"){                                                                     
      ret = a-b;                                                                              
    } else if (op== "*"){                                                                     
      ret = a*b;                                                                              
    } else if (op=="/"){                                                                      
      ret = a/b;                                                                              
    } else{                                                                                   
      return -1;                                                                              
    }                                                                                         
    cout << ret << endl;                                                                      
    cin >> a >> op >> b;                                                                      
  }                                                                                           
}                                                                                             
                                                                                              
               


Measured memory_bytes: 3120
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long LL;
typedef long double LD;

bool possible(int n, int k, LD x, const vector<LD>& a) {
	int cnt = 0;
	for (LD d : a) {
		cnt += (int)ceil(d / x);
		--cnt;
	}
	return cnt <= k;
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1, k;
		cin >> n >> k;
		if (n < 0) return 0;
		vector<LD> a(n);
		for (LL i = 0; i < n; ++i) {
			cin >> a[i];
		}
		LD left = 0.1, right = 1e10;
		for (int t = 0; t < 1000; ++t) {
			LD mid = (left + right) / 2;
			if (possible(n, k, mid, a)) {
				right = mid;
			} else {
				left = mid;
			}
		}
		cout << ceil(left) << endl;
	}
	return 0;
}


Measured memory_bytes: 6280
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 1e5;
const int MV = 1e5;
const int INF = 2e9;
const int MOD = 1e9 + 7;
int MA = -INF , MI = INF , ANS;

ll n , m , s , tmp , last = 0 , len;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;

    while(true)
    {
      //  cerr << m << "\n";
        if( m +  9ll*pow(10,len) <= n )
            m = m + 9ll*pow(10,len) , s += 9 , len++;
        else
        {
            for( ll i=0 ; i<=9 ; i++)
            {
                if( m + i*pow(10,len) <= n )
                    last = i;
            }
            s += last;
            break;
        }
    }

    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 512
(defun solve (n k)
  (when (= k 0)
    (return-from solve (* n n)))
  (loop for b from (1+ k) to n
        sum (+ (* (floor (/ n b)) (max 0 (- b k))) (max 0 (+ (mod n b) (- k) 1)))))
(let ((n (read)) (k (read)))
  (princ (solve n k)))

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

#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int n;
    cin >> n;

    ll ans = 1;
    long double k = 1.0;

    vector<ll> v(n);

    rep(i, n){
        cin >> v[i];
    }

    sort(ALL(v));

    rep(i, n){
        k *= v[i];

        if(k > 1000000000000000000){
            ans = -1;
            break;
        }

        if(v[i] == 0){
            ans = 0;
            break;
        }

        ans *= v[i];
    }

    cerr << k << endl;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

double PI = 6.28318530717958623200 / 2.0;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int r;
    cin >> r;
    cout << fixed << setprecision(18) << 2 * r * PI << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int N; cin >> N;
	vector<int> a(N);

	REP(i,N) cin >> a[i];
	REP(i,N) a[i]--;


	int i = 0;
	int idx = 0;
	int ans = 0;
	while(i < N){
		if(idx == 1){
			cout << ans << endl;
			return 0;
		}
		idx = a[idx];
		ans++;
		i++;
	}

	cout << -1 << endl;

	return 0;

}


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

int main()
{
    int n;
    int r[200001];
    cin>>n;
    for(int i=0;i<n;i++) cin>>r[i];
    int minr = r[0];
    int maxr = INT_MIN;
    for(int i=1;i<n;i++)
    {
        maxr = max(maxr, r[i]-minr);
        minr = min(minr, r[i]);
    }
    cout<<maxr<<endl;

    return 0;
}



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

int main(){
  int A,B; cin >> A >> B;
  string ans;
  if (A == 1 && B != 1) ans = "Alice";
  else if (B == 1 && A!= 1) ans = "Bob";
  else if (A == B) ans = "Draw";
  else if (A > B) ans = "Alice";
  else ans = "Bob";
  cout << ans <<endl;                   
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
#define MAX 30
#define NIL -1

struct Node{int p,l,r;};
Node T[MAX];
int D[MAX],H[MAX];

int setHeight(int u){
	int hl = (T[u].l!=NIL?setHeight(T[u].l)+1:0);
	int hr = (T[u].r!=NIL?setHeight(T[u].r)+1:0);
	return H[u] = (hl>hr?hl:hr);
}

void setDepth(int u,int d){
	if(u==NIL)return;
	D[u] = d;
	setDepth(T[u].r,d+1);
	setDepth(T[u].l,d+1);
}

int getSibling(int u){
	if(T[u].p == NIL)return NIL;
	else if(T[T[u].p].l==u && T[T[u].p].r!=NIL)return T[T[u].p].r;
	else if(T[T[u].p].r==u && T[T[u].p].l!=NIL)return T[T[u].p].l;
	else return NIL;
}

void print(int i){
	int deg=0;
	if(T[i].l!=NIL)deg++;
	if(T[i].r!=NIL)deg++;

	cout << "node " << i << ": parent = "<< T[i].p;
	cout << ", sibling = " << getSibling(i);
	cout << ", degree = " << deg;
	cout << ", depth = " << D[i];
	cout << ", height = " << H[i] << ", ";
	if(T[i].p==NIL)cout << "root";
	else if(T[i].l==NIL&&T[i].r==NIL)cout << "leaf";
	else cout << "internal node";
	cout << endl;
}

int main(){
	int r,l,a,n;
	cin >> n;
	for(int j=0;j<n;j++)T[j].p=NIL;
	for(int s=0;s<n;s++){
		cin >> a >> l >> r;
		T[a].l = l;T[a].r = r;
		if(l!=NIL)T[l].p = a;
		if(r!=NIL)T[r].p = a;
	}
	for(int j=0;j<n;j++){
		if(T[j].p == NIL) r=j;
	}

	setDepth(r,0);
	setHeight(r);

	for(int j=0;j<n;j++)print(j);

	return 0;
}



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

int main()
{
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> a(n,vector<int>(3));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> a[i][j];
    }
  }
  vector<vector<int>> dp(n, vector<int>(3));
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
  for (int i = 1; i < n; i++)
  {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 088 C / Link: http://abc088.contest.atcoder.jp/tasks/abc088_c  ----- */


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

	int N = 3;
	vector<vector<LL>> c(N, vector<LL>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> c[i][j];
		}
	}

	LL ans = 0LL;
	FOR(i, -100, 101) {
		FOR(j, -100, 101) {
			FOR(k, -100, 101) {
				VI a({ i,j,k });
				VI b(3);
				FOR(m, 0, 3) {
					b[m] = c[0][m] - a[0];
				}
				bool ok = 1;
				FOR(s, 0, N) {
					FOR(t, 0, N) {
						ok &= a[s] + b[t] == c[s][t];
					}
				}
				ans |= ok;
			}
		}
	}



	cout << (ans?"Yes":"No") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,m,i;
ll q[N],ans[N];
map<ll,ll>mp;
int main(){
	scanf("%lld%d",q,&m);
	for(i=1;i<=m;++i)scanf("%lld",q+i);mp[q[m]]=1;
	for(i=m-1;i>=0;--i)for(auto it=--mp.end();it->first>q[i];mp.erase(it--)){
		ll x=it->first/q[i],y=it->first-q[i]*x;
		mp[q[i]]+=x*it->second;if(y)mp[y]+=it->second;
	}
	for(i=*q;i;--i)ans[i]=ans[i+1]+mp[i];
	for(i=1;i<=*q;++i)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
  int n;
  cin >> n;
  set<char> s;
  
  rep(i,n) {
    char c;
    cin >> c;
    s.insert(c);
  }
  if(s.size() == 3) cout << "Three" << endl;
  else cout << "Four" <<endl;
}

Measured memory_bytes: 256
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
using namespace std;

int P, Q, R;   //A-B,B-C,C-A

void solve() {
	cin >> P >> Q >> R;
	cout << min(P + Q, min(Q + R, R + P)) << endl;
	return;
}

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

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

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

    rep(i,s.size()){
        char c=s.at(i);
        c=s.at(i)+n;
        if((int)c-'Z'>0){ 
            c=c-26;
        }
        s.at(i)=c;
    }
    rep(i,s.size()) cout << s.at(i); 
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());

            if (num == 1)
            {
                Console.WriteLine("Hello World");
            }
            else if (num == 2)
            {
                int sum = 0;

                for(int i = 0; i < 2; i++)
                {
                    var num2 = int.Parse(Console.ReadLine());
                    sum += num2;
                }

                Console.WriteLine(sum);
                    
            }

            #if DEBUG
                Console.WriteLine("続行するには何かキーを押してください．．．");
                Console.ReadKey();
            #endif
        }
    }
}




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

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

	if (S == "Sunny")
	{
		cout << "Cloudy";
	}
	
	else if (S == "Cloudy")
	{
		cout << "Rainy";
	}

	else if (S == "Rainy")
	{
		cout << "Sunny";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const int MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

// 3이상만 사용 가능
pii vec[200000];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d %d", &vec[i].first, &vec[i].second);

    ll mav = -1e18;
    ll maxy = -1e18, mixy = 1e18;
    ll mayx = -1e18, miyx = 1e18;

    for (int i = 0; i < n; i++) {
        ll xy = vec[i].first + vec[i].second;
        ll yx = vec[i].first - vec[i].second;
        maxy = max(maxy, xy);
        mixy = min(mixy, xy);

        mayx = max(mayx, yx);
        miyx = min(miyx, yx);
    }

    for (int i = 0; i < n; i++) {
        ll xy = vec[i].first + vec[i].second;
        ll yx = vec[i].first - vec[i].second;

        mav = max(mav, abs(xy - maxy));
        mav = max(mav, abs(xy - mixy));

        mav = max(mav, abs(yx - mayx));
        mav = max(mav, abs(yx - miyx));
    }
    printf("%lld", mav);
}


// author: rdd6584


Measured memory_bytes: 5380
#include<bits/stdc++.h>
using namespace std;
long long m,n;
long long gcd(long long a,long long b) {
    return b==0?a:gcd(b,a%b);
}
int main() {
	cin>>m>>n;
	cout<<m/gcd(m,n)*n;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const double PI = 3.1415926535897932;
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    double a, b, x;
    cin >> a >> b >> x;
    
    double res;
    if(2 * x >= a * a * b){
        double d = 2 * (b - (x / (a * a)));
        res = atan2(d, a);
    }
    else{
        double d = 2 * x / (a * b);
        res = atan2(b, d);
    }

    cout << fixed << setprecision(10);
    cout << res / PI * 180 << "\n";
}

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

int main() {
    int64_t n, d;
    cin >> n >> d;

    int i = 0;
    int c = 0;
    while(i < n) {
        int64_t x, y;
        cin >> x >> y;
        if (sqrt(x*x+y*y) <= d) c++;
        i++;
    }

    cout << c << endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
	int n;
	cin >> n ;
	vector<int> h(n),c(n);
	for(int i=0;i<n;i++)
	{		
		cin >> h[i];
	}
	c[0]=0;
	c[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		c[i]=min(abs(c[i-1]+abs(h[i]-h[i-1])),abs(c[i-2]+abs(h[i]-h[i-2])));
	}
	cout << c[n-1];
}


Measured memory_bytes: 1024
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  bool operator< (const Point &p1) {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}


struct Edge {
  Int to, w;
  Edge(Int to, Int w): to(to), w(w) {}
};

#define MAX_N 100001
#define MAX_W 1000000001
Int N;
vector<Edge> G[MAX_N];
vector<Int> colors(MAX_N, -1);

void input() {
  cin >> N;
  Int v, u, w;
  rep(N-1) {
    cin >> v >> u >> w;
    v--, u--;
    G[v].push_back(Edge(u, w));
    G[u].push_back(Edge(v, w));
  }
}

void dfs(Int n, Int next_color) {
  if (colors.at(n) >= 0) return;
  Int w;
  colors.at(n) = next_color;

  for (auto edge: G[n]) {
    if (edge.w == MAX_W) continue;
    if (edge.w % 2 == 0) dfs(edge.to, next_color);
    else dfs(edge.to, (next_color + 1) % 2);
  }
}

void solve() {
  dfs(0, 0);
  loop(x,0,N) {
    cout << colors.at(x) << endl;
  }
}

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


Measured memory_bytes: 10240
import java.util.*;

public class Main {
    public static int solve(long n) {
        long a = 1;
        long b;
        long border = (long)Math.sqrt(n);
        int min = getNumDigit(n);

        while (a <= border) {
            if (n % a == 0) {
                b = n / a;
                if (getNumDigit(Math.max(a, b)) <= min) {
                    min = getNumDigit(Math.max(a,b));
                }
            }
            a++;
        }
        return min;
    }

    public static int getNumDigit(long n) {
        return Long.toString(n).length();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        System.out.println(solve(N));
    }
}


Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		int d = sc.nextInt();
		
		int cnt = 0;
		for (int i = l; l <= r; l++) {
			if (l % d == 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 35632
import java.util.Scanner;

public class Main {

    public static long find_max(int i, int N, int[] A, long[] dp) {
        return  i == N-1 ? 0 : Long.max(dp[i+1], A[i] + find_max(i+2, N, A, dp));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        long[] dp = new long[N+1];

        for(int i = 0;i < N;i++) {
            A[i] = scanner.nextInt();
        }

        dp[N-1] = A[N-1];
        int i = N-3;
        while(i >= 0) {
            dp[i] = dp[i+2] + A[i];
            i -= 2;
        }

        i = N-2;
        while(i >= 0) {
            dp[i] = Long.max(dp[i+1], A[i]+dp[i+2]);
            i-=2;
        }

        System.out.println(N % 2 == 0 ? dp[0] : find_max(0, N, A, dp));
    }
}


Measured memory_bytes: 76048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int x; cin >> x;
    if(400 <= x && x <= 599) cout << 8 << endl;
    if(600 <= x && x <= 799) cout << 7 << endl;
    if(800 <= x && x <= 999) cout << 6 << endl;
    if(1000 <= x && x <= 1199) cout << 5 << endl;
    if(1200 <= x && x <= 1399) cout << 4 << endl;
    if(1400 <= x && x <= 1599) cout << 3 << endl;
    if(1600 <= x && x <= 1799) cout << 2 << endl;
    if(1800 <= x && x <= 1999) cout << 1 << endl;
}

Measured memory_bytes: 3632
MAIN : {
	my $s1 = <STDIN>;
	chomp $s1;
	my ($a, $b, $k) = split(" ", $s1);

	my $wari = 100;
	my $cnt = 0;
	while (true) {
		if ($wari <= $a and $wari <= $b) {
			if ($a % $wari eq 0 and $b % $wari eq 0) {
#				print STDOUT $wari, "\n";
				$cnt++;
			}
			if ($cnt == $k) {
				print STDOUT $wari, "\n";
				last;
			}
		}
		$wari--;
	}
}

__END__


Measured memory_bytes: 512
n,x,m=map(int,input().split())
seen=[-1]*(2*10**5)
A=[0]*(2*10**5)
A[0]=x


now=x ;seen[x]=0
for i in range(1,n):
    now= (now**2)%m 
    A[i]=now
    if seen[now]!=-1:
        st = sum(A[:seen[now]])
        gr = sum(A[seen[now]: i ])
        naga= i-seen[now]
        ret = (n-seen[now])//naga
        print(st+ gr*ret + sum(A[seen[now]: seen[now]+(n-seen[now])%naga]))
        exit()
    else:
        seen[now]=i
else:
    print(sum(A[:n]))

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char ch;
	int ret=0;
	while(cin>>ch)
		if(ch=='+') ret++;
		else ret--;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    ll ng = 1;
    bool flag = false;
    rep(i,100010){
        if(ng*(ng-1) == 2*N){
            flag = true;
            break;
        }
        ng++;
    }
    if(!flag){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << ng << endl;
    ll ne = ng-1;
    vector<vector<ll>> v(ne);
    ll num = 1;
    rep(i,ne){
        rep(j,i+1){
            v[i].push_back(num);
            num++;
        }
    }
    rep(i,ng-1){
        cout << ne;
        ll yoko = i+1;
        ll tate = ne - yoko + 1;
        ll t = i;
        ll u = 0;
        rep(j,ne){
            cout << " " << v[t][u];
            if(u == yoko-1){
                t++;
            }else{
                u++;
            }
        }
        cout << endl;
    }
    cout << ne;
    rep(i,ne){
        cout << " " << v[i].back();
    }
    cout << endl;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int s,w;
  cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans=0;

		if (n>=2) {
			ans += (n*(n-1))/2;
		}

		if(m>=2) {
			ans +=(m*(m-1))/2;
		}

		System.out.println(ans);


		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
	//----------------------------------------
	//メソッド置き場


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

Measured memory_bytes: 22868
#import numpy as np
#import collections
#import math

#f = open('./input_C.txt')
#
#X,K,D=map(int, f.readline().split())

X,K,D=map(int, input().split())

Xabs = abs(X)
move1 = Xabs//D
if K <= move1:
    ans = Xabs - K * D
else:
    Xabs -= move1*D
    K -= move1
    if K%2==0:
        ans = Xabs
    else:
        ans = D - Xabs


print(ans)

Measured memory_bytes: 61644
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int a, b, ab, o;
    a = b = ab = o = 0;
    while(cin >> s)
    {
        string t;
        int idx = -1;
        for(int i = 0; i < s.size(); i++) if(s[i] == ',') { idx = i; break; }
        t = s.substr(idx + 1);
        if(t.size() == 2) ab++;
        else if(t == "A") a++;
        else if(t == "B") b++;
        else if(t == "O") o++;
    }
    cout << a << "\n" << b << "\n" << ab << "\n" << o << endl;
    return 0;
}




Measured memory_bytes: 3144
#include<stdio.h>
int max_num(int x, int y, int z)
{
	int max = x;
	if (y > max)max = y;
	if (z > max)max = z;
	return max;
}
int main()
{
	int N;
	
	int(*a)[3] = (int(*)[3])malloc(100010*3 * sizeof(int));
	int(*dp)[3] = (int(*)[3])malloc(100010*3 * sizeof(int));
	scanf("%d", &N);
	for (int i = 1;i <= N;i++)
	{
		/*a[i][0]はa,a[i][1]はb,a[i][2]はc*/
		for (int j = 0;j < 3;j++)scanf("%d", &a[i][j]);
	}
	for (int j = 0;j < 3;j++)dp[0][j] = 0;
	for (int i= 1;i <= N;i++)
	{
		dp[i][0] = a[i][0] + max_num(dp[i - 1][1], dp[i - 1][2],0);/*0はダミー*/
		dp[i][1] = a[i][1] + max_num(dp[i - 1][0], dp[i - 1][2],0);
		dp[i][2] = a[i][2] + max_num(dp[i - 1][0], dp[i - 1][1],0);
		
	}
	printf("%d", max_num(dp[N][0], dp[N][1], dp[N][2]));
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(){
    char sa[100],sb[100],sc[100];
    char s;
    int i=1,j=0,k=0,l=0;

    scanf("%s",sa);
    scanf("%s",sb);
    scanf("%s",sc);
    
    s=sa[0];
    while(l<=350){
        if(s=='a'){
            if(sa[i]=='\0'){
                printf("A\n");
                break;
            }
            s=sa[i];
            i++;
        }
        else if(s=='b'){
            if(sb[j]=='\0'){
                printf("B\n");
                break;
            }
            s=sb[j];
            j++;
        }
        else if(s=='c'){
            if(sc[k]=='\0'){
                printf("C\n");
                break;
            }
            s=sc[k];
            k++;
        }
        l++;
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int maxn = 2020;
// struct histogram_solver{
//     vector<int> dp;
//     vector<int> he;
//     static long long solve(vector<int> values){
//         stack<int> s;
//         int i = 0;
//         long long ans = 0;
//         while(i < values.size()){
//             if(s.empty() || values[s.top()] <= values[i]) s.push(i++);
//             else{
//                 int tp = s.top(); s.pop();
//                 long long area = 1ll * values[tp] * (s.empty() ? i : i - s.top() - 1);
//                 ans = max(ans, area);
//             }
//         }
//         while(!s.empty()){
//             int tp = s.top(); s.pop();
//             long long area = 1ll * values[tp] * (s.empty() ? i : i - s.top() - 1);
//             ans = max(ans, area);
//         }
//         return ans;
//     }
// };
struct histogram_solver{
    vector<int> dp;
    vector<int> he;
    static long long solve(vector<int> values){
        stack<int> s;
        int i = 0;
        long long ans = 0;
        while(i < values.size()){
            if(s.empty() || values[s.top()] <= values[i]) s.push(i++);
            else{
                int tp = s.top(); s.pop();
                long long area = 1ll * (values[tp] + 1) * (s.empty() ? i + 1: i - s.top());
                ans = max(ans, area);
            }
        }
        while(!s.empty()){
            int tp = s.top(); s.pop();
            long long area = 1ll * (values[tp] + 1) * (s.empty() ? i + 1: i - s.top());
            ans = max(ans, area);
        }
        return ans;
    }
};
char g[maxn][maxn];
int M(){
    int n, m;
    if(!(cin >> n >> m)) return 0;
    for(int e = 0; e < n; e++)
        scanf("%s", g[e]);
    int ans = max(n, m);
    vector<int> histo(m - 1, 0);
    for(int e = 0; e < n - 1; e++){
        for(int f = 0; f < m - 1; f++){
            int cnt = 0;
            cnt += (g[e][f] == '#');
            cnt += (g[e+1][f] == '#');
            cnt += (g[e][f+1] == '#');
            cnt += (g[e+1][f+1] == '#');
            if(cnt % 2 == 0) histo[f]++;
            else histo[f] = 0;
        }
        ans = max(ans, (int)histogram_solver::solve(histo));
    }
    cout << ans << endl;
    return 1;
}
int main(){
    while(M());
    return 0;
}


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int N = 10000;
int a[N];
int n;

bool is_prime(int k) {
  for (int i=2; i*i<=k; i++)
  if (k%i == 0) return false;
  return k != 1;
}

int main() {
  int i;
  int res = 0;
  scanf("%d ", &n);
  for (i=0; i<n; i++) {
    scanf("%d ", a+i);
    if (is_prime(a[i])) res++;
  }

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

  return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, V, P;
	cin >> N >> M >> V >> P;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.rbegin(), A.rend());

	int ok = P - 1;
	int ng = N;
	while (ng - ok > 1) {
		int m = (ng + ok) / 2;
		vector<int> B = A;
		int r = V * M;
		r -= M;
		B[m] += M;
		bool f = true;
		if (B[m] < A[P - 1]) {
			f = false;
		} else {
			for (int i = 0; i < P - 1; i++) {
				B[i] += M;
				r -= M;
			}
			for (int i = P - 1; i < N; i++) {
				if (i != m) {
					if (B[m] > B[i] + M) {
						r -= M;
					} else {
						r -= B[m] - B[i];
					}
				}
			}
			f = (r <= 0);
		}
		if (f) {
			ok = m;
		} else {
			ng = m;
		}
	}
	cout << ok + 1 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N,K;
    int sunuke[101] = {0};
    cin >> N >> K;
    int temp;
    int d;
    REP(i,K){
        cin >> d;
        REP(j,d){
            cin >> temp;
            //1だったら持ってる
            sunuke[temp-1] = 1;
        }
    }
    int cnt = 0;
    REP(i,N) if(sunuke[i] == 0) cnt++;
    fin(cnt);
    return 0;
}

Measured memory_bytes: 3192
from collections import deque

def main():
    n = int(input())
    d = deque()
    for _ in range(n):
        command = input()
        if command == "deleteFirst":
            d.popleft()
        elif command == "deleteLast":
            d.pop()
        else:
            com, num = command.split(" ")
            if com == "insert":
                d.appendleft(num)
            elif com == "delete":
                try:
                    d.remove(num)
                except:
                    pass
    print(" ".join(d))


main()


Measured memory_bytes: 69732
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(ll, n, a, b);
  if (a > b) {
    puts("0");
    return;
  }
  if (n == 1) {
    cout << (a != b ? 0 : 1) << endl;
    return;
  }

  ll mmin = (n - 1) * a + b;
  ll mmax = (n - 1) * b + a;

  ll ans = mmax - mmin + 1;

  cout << ans << endl;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque as dq
n=int(input())
lis=dq([])
for i in range(n):
	c=list(map(str,input().split()))
	a=c[0]
	if len(c)==2:
		b=c[1]
	if a=="insert":
		lis.appendleft(b)
	elif a=="delete":
		try:
			lis.remove(b)
		except:
			continue
	elif a=="deleteFirst":
		lis.popleft()
	else:
		lis.pop()
print(*lis)


Measured memory_bytes: 69736
n,m = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
yen = 0
cnt = 0
for i, a_b in enumerate(ab):
    if cnt + a_b[1] < m:
        yen += a_b[0] * a_b[1]
        cnt += a_b[1]
    else:
        tmp = m - cnt
        cnt += tmp
        yen += tmp * a_b[0]
print(yen)


Measured memory_bytes: 16908
#include <stdio.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

int main(void) {
    int i, j, k;
    int n;
    int sum[101] = {0}, dp[101][101] = {0}, max;

    scanf("%d", &n);

    max = -10000;
    for (i = 0; i < n; i++) {
        for (j = 1; j <= n; j++) {
            int a;
            scanf("%d", &a);
            sum[j] = sum[j - 1] + a;
        }

        for (j = 1; j <= n; j++)
            for (k = j; k <= n; k++) {
                dp[j][k] = max(dp[j][k] + sum[k] - sum[j - 1], sum[k] - sum[j - 1]);
                max = max(max, dp[j][k]);
            }
    }

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

    return 0;
}

Measured memory_bytes: 648
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
divisors = make_divisors(n)
ans = n + 1

for di in divisors:
    ans = min(ans, di + n // di - 2)
print(ans)


Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  
 cin>>n;
  
 for(int a=1;a<=9;a++){
   for(int b=1;b<=9;b++){
   	if(a*b==n){
 		cout<<"Yes"<<endl;
 	return 0;
 	}
   }
 }
 cout<<"No"<<endl;
 }


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[200007];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        a[i]-=i;
    }
    sort(a+1,a+n+1);
    int b;
    if(n%2==1)b=a[n/2+1];
    else b=(a[n/2]+a[n/2+1])/2+0.5;
    unsigned long long ans=0;
    for(int i=1;i<=n;++i)
    ans+=abs(a[i]-b);
    cout<<ans;
    return 0;
}

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

int main() {
  long long q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  if (n % 2 == 0){
    cout << n * min(q * 8, min(h * 4, min(s * 2, d))) / 2 << endl;
  }
  else{
    cout << ((n - 1) * min(q * 8, min(h * 4, min(s * 2, d))) / 2) + min(q * 4, min(h * 2, s)) << endl;
  }
}

Measured memory_bytes: 256