akhauriyash/Code-Regression huggingface dataset:
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

count = int(input())

for c in range(count):
    (b, f, r, v) = [int(x) for x in input().split()]
    data[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    print('#' * 20) if b < 4 - 1 else print(end='')

Measured memory_bytes: 6728
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int a;
	std::cin >> a;
	print(a+a*a+a*a*a);
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	double w=0;
	
	rep(i, n) w += 1.0 / a[i];
	double ans = 1.0 /w;
	printf("%.14f\n", ans);
	return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    int n;
    cin >> n;
    vi a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(all(a));
    int cnt = 0;
    for(int i=0; i<n; i++){
        int q=i+1;
        for(int p=i+1; p<n; p++){
            if(p==q)
                q++;
            if(q>=n)
                break;
            while(a[p]+a[i]>a[q]){
                q++;
                if(q>=n)
                    break;
            }
            q--;
            cnt+=q-p;
        }
    }
    cout << cnt;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  vi y = x;
  sort(all(y));
  int a = y[n/2-1];
  int b = y[n/2];
  double mid = (double(a) + double(b)) / 2;
  rep(i,n) {
    if(x[i] <= mid) cout << b << endl;
    else cout << a << endl;
  }
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x,h,temp,result;
	
	while(1){
		result=0;
		scanf("%lf %lf",&x,&h);
		
		if(x==0 && h==0)
			break;
		
		temp=(x/2)*(x/2)+h*h;
		temp=sqrt(temp);
		result=x*x+temp*x*2;
		
		printf("%f\n",result);
	}
	
	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */
int main(){
	int n, d, ans=0; scanf("%d", &n);
	for(int i=1; i<=n; ++i){
		scanf("%d", &d);
		if (d != i) ans++;
	}
	printf("%s\n", ans <=2 ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
int main ()
{
	int n;
	cin>>n;
    ll a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int zero =0;
	for(int i=0;i<n;i++)if(a[i]==0) zero ++;

   if(zero >0){
		cout<<"0"<<endl;
		return 0;
	}
	ll prod =1;
	for(int i=0;i<n;i++){
        if(a[i ] <=1000000000000000000/ prod ){
            prod *=a[i];
        }else{
            cout<<"-1"<<endl;
            return 0;
        }
	}
 cout<<prod<<endl;
  return 0;
}


Measured memory_bytes: 4356
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int *A = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int c = 0,temp;
	for (int i = 0; i < n -1; i++) {
		for (int j = n-1; j > i; j--) {
			if (A[j] < A[j-1]) {
				temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				++c;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << A[i];
		if (i != n - 1)
			cout << ' ';
		else
			cout << endl;
	}
	cout << c << endl;
	delete[] A;
	return 0;
}


Measured memory_bytes: 3076
N = int(input())
A = [int(a) for a in input().split()]

A_divided = []
for n in range(N):
  nm = A[n]
  cnt = 0
  while nm % 2 == 0:
    cnt += 1
    nm //= 2
  A_divided.append(cnt)
ans = min(A_divided)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n; cin >> n;
    vector<int> s(1<<n);
    multiset<int> t;
    rep(i, (1<<n)) {
        cin >> s[i];
    }
    sort(all(s));
    rep(i, (1<<n) - 1) {
        t.insert(s[i]);
    }
    vector<int> u;
    u.push_back(s[(1<<n) - 1]);
    rep(i, n) {
        auto w = u;
        for(auto j: u) {
            auto ite = t.lower_bound(j);
            if(ite == t.begin()) {
                cout << "No" << endl;
                return;
            }
            ite--;
            w.push_back(*ite);
            t.erase(ite); //erase(iterator)を使いべし！！　//erase(value) だと全valueが消える
        }
        sort(all(w));
        reverse(all(w));
        swap(u, w);
    }
    cout << "Yes" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 13568
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <numeric>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> arr(n);
    vector<int> res(n);

    int back = n - 1;
    int front = 0;

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

    for(int i = 0; i < n; i ++)
    {
        int k = arr[n - 1 - i];
        if (i % 2 == 1)
        {
            res[back] = k;
            back--;
        }
        else
        {
            res[front] = k;
            front++;
        }
    }

    for (auto& r : res)
        printf("%d ", r);

    return 0;
}

Measured memory_bytes: 3712
k = gets.to_i
a = gets.split.map(&:to_i)

def clac(n,k,a)
  k.times do |i|
    n -= n%a[i]
  end
  return n
end

min = 2
max = 10**14
while min <= max
  mid = min+(max-min)/2
  m = clac(mid,k,a)
  if m < 2
    min = mid+1
  else
    max = mid-1
  end
end
ans_min = min

min = 2
max = 10**14
while min <= max
  mid = min+(max-min)/2
  m = clac(mid,k,a)
  if m > 2
    max = mid-1
  else
    min = mid+1
  end
end
ans_max = max

if clac(ans_min,k,a) == 2
  puts "#{ans_min} #{ans_max}"
else
  puts -1
end

Measured memory_bytes: 10500
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Miguel Mini
 */

#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int maxn = 2e5 + 10;
bool composite[maxn];
vector<int> prime;
int mu[maxn];
const int mod = 1e9 + 7;
int add(int a, int b) {
    return (a+b)%mod;
}
int mul(ll a, ll b) {
    return a*b%mod;
}
int ex(int a, int b) {
    int r = 1;
    while (b > 0) {
        if (b&1) r = mul(r, a);
        a = mul(a, a);
        b >>= 1;
    }
    return r;
}

int memo[maxn];

class E {
public:
    void sieve(int n) {
        mu[1] = 1;
        for (int i = 2; i <= n; ++i) {
            if (!composite[i]) {
                prime.emplace_back(i);
                mu[i] = -1;
            }
            trav(p, prime) {
                if (p * i > n) break;
                composite[p * i] = true;
                if (i % p == 0) {
                    mu[p * i] = 0;
                    break;
                } else mu[p * i] = -mu[i];
            }
        }
    }
    int testNumber = 0;
	void solve(istream& in, ostream& out) {
        //out << "Case #" << ++testNumber << ": ";
        int n, k;
        in >> n >> k;
        sieve(1e5);
        memo[0] = 0;
        for (int i = 1; i <= k; ++i) {
            memo[i] = ex(i, n);
        }
        int ans = 0;
        for (int d = 1; d <= k; ++d) {
            int cnt = 0;
            for (int i = 1; d*i <= k; ++i) {
                cnt = add(cnt, mul(mod + mu[i], memo[k/d/i]));
            }
            ans = add(ans, mul(cnt, d));
        }
        out << ans << endl;
	}
};

int main() {
	E solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 4588
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	while (true) {
		C -= B;
		if (C <= 0) {
			cout << "Yes";
			exit(0);
		}
		A -= D;
		if (A <= 0) {
			cout << "No";
			exit(0);
		}
	}
}

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

int main(){
	set<long long> people;
	long long N, K;
	cin >> N >> K;

	for(long long i = 0; i < N; i++) {
		people.insert(i);
	}

	for(long long i = 0; i < K; i++){
		long long d;
		cin >> d;
		for(long long j = 0; j < d; j++){
			long long a;
			cin >> a;
			a--;
			people.erase(a);
		}
	}
	cout << people.size() << endl;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        for (int a = 1; a <= 1000; a++) {
            for (int b = -1000; b < a; b++) {
                if ((long)a*a*a*a*a - (long)b*b*b*b*b == X) {
                    System.out.println(a+" "+b);
                    return;
                }
            }
        }
    }
}



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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    int numOf5 = 0, numOf7 = 0;

    if (A == 5) {
        numOf5++;
    } else if (A == 7) {
        numOf7++;
    }

    if (B == 5) {
        numOf5++;
    } else if (B == 7) {
        numOf7++;
    }

    if (C == 5) {
        numOf5++;
    } else if (C == 7) {
        numOf7++;
    }

    if (numOf5 == 2 && numOf7 == 1) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}

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

const double pi = 4 * atan(1);
const double r = 6378.1;
const double circ = 2 * r * pi;

double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}

int main() {
    double a, b, c, d;
    while (cin >> a >> b >> c >> d, (a!=-1 || b!=-1 || c!=-1 || d!=-1)) {
        a = a * pi / 180.0;
        b = b * pi / 180.0;
        c = c * pi / 180.0;
        d = d * pi / 180.0;

        double x1 = r * cos(a) * cos(b);
        double y1 = r * cos(a) * sin(b);
        double z1 = r * sin(a);

        double x2 = r * cos(c) * cos(d);
        double y2 = r * cos(c) * sin(d);
        double z2 = r * sin(c);

        double d = dist(x1, y1, z1, x2, y2, z2);

        double angle = acos((2*r*r - d*d) / (2*r*r));
        double res = circ * angle / (2 * pi);

        cout << (int)(res + 0.5) << endl;
    }
    return 0;
}

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

vector<int> zalg(string s){
  int n=s.size();
  vector<int> a(n,0);
  a[0]=n;
  int i=1,j=0;
  while(i<n){
    while(i+j<n && s[i+j]==s[j]) ++j;
    a[i]=j;
    if(j==0){
      ++i;
      continue;
    }
    int k=1;
    while(i+k<n && a[k]<j-k){
      a[i+k]=a[k];
      ++k;
    }
    i += k;
    j -= k;
  }

  return a;
}

int b(string s){
  int n=s.size();
  vector<int> a=zalg(s);
  int res=0;
  for(int i=1;i<s.size();++i){
    res=max(res,min(a[i],i));
  }
  return res;
}


int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<n;++i){
    string t;
    for(int j=i;j<n;++j) t.push_back(s[j]);
    ans=max(ans,b(t));
  }
  cout<<ans<<endl;
}

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

int main()
{
    int X; cin>>X;
    vector<bool> dp(X+1);
    dp[0]=true;
    for(int a=100;a<=105;a++){
        for(int i=0;i+a<=X;i++) if(dp[i]){
            dp[i+a]=true;
        }
    }   
    cout<<dp[X]<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define int ll
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
#define in insert
#define er erase
#define fd find
string s;
int ans1, ans2;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>s;
    for(int i=0; i<s.sz; i++){
        if(s[i]=='0') ans1++;
        else ans2++;
    }
    cout<<2*min(ans1, ans2);
}

Measured memory_bytes: 512
X = int(input())

dp = [False] * (X + 1)
dp[0] = True
for i in range(X):
  if dp[i]:
    for x in [100, 101, 102, 103, 104, 105]:
      if i+x <= X:
        dp[i+x] = True

if dp[-1]:
  print(1)
else:
  print(0)

Measured memory_bytes: 3828
#include<stdio.h>
int main(void) {
	int n, s[100] = {0}, max, min,sum,count;
	while(1){
		sum = 0;
		count = 0;
		scanf("%d", &n);
		if (n== 0) break;
		for (int i = n; i > 0; i--) {
			scanf("%d", &s[i]);
			if (i == n) {
				max = s[i];
				min = s[i];
			}
			if (max < s[i]) max = s[i];
			if (min > s[i]) min = s[i];
			count++;
			sum += s[i];
		}
		sum = sum - (max + min);
		printf("%d\n", sum / (count - 2));
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    ll n; cin >> n;
    ll a[3 * n + 100];

    rep(i,3 * n) cin >> a[i];
    sort(a,a + 3 * n,greater<ll>());

    ll sum = 0;
    for (ll i = 0; i < n; ++i) {
        sum += a[2 * i + 1];
    }

    print(sum);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int n; cin >> n;
  if(n/10==9 || n%10==9){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef long long LL;
const int maxn = 1e5+5;
std::vector<int> v[maxn];
int p[maxn], r[maxn];

int find(int x) {
	int t = x;
	while(t != p[t]){
		t = p[t];
	}
	return t;
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	p[1] = 1;
	while(cin >> n >> q && n){
		LL ans = 0;
		for(int i = 2; i <= n; i++){
			int x;
			cin >> x;
			p[i] = x;
		}
		while(q--){
			char op[2];
			int x;
			cin >> op >> x;
			if(op[0] == 'M') p[x] = x;
			else ans += find(x); 
		}
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 5728
<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
list($H,$W) = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$H;$i++) {
  $S[]=trim(fgets(STDIN));
}
for($i=0;$i<$H;$i++) {
  for($j=0;$j<$W;$j++) {
    if ($S[$i][$j]==".") {
      //空きマスの場合は数えて置き換える
      $S[$i][$j]=countbomb($i,$j);
    }
  }
}
foreach($S as $l) {
  printf("%s\n",$l);
}
function countbomb($h,$w) {
  global $S,$H,$W;
  $cnt=0;
  $hfrom=max($h-1,0);
  $hto  =min($h+1,$H);
  $wfrom=max($w-1,0);
  $wto  =min($w+1,$W);

  //printf("%d %d %d %d %d %d\n",$h,$w,$hfrom,$hto,$wfrom,$wto);
  for($i=$hfrom;$i<=$hto;$i++) {
    for($j=$wfrom;$j<=$wto;$j++) {
      if ($S[$i][$j]=="#") $cnt++;
    }
  }
  return $cnt;
}


Measured memory_bytes: 3828
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
//import java.util.PriorityQueue;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n ;i++){
            a[i] = stdIn.nextInt();
        }

        int count = 0;

        Arrays.sort(a);

        for(int i = 0;i < n;i++){
            int x = 1;
            int y = i;
            if(i == n-1){
                count++;
                break;
            }
            while(a[y] == a[y+1]){
                x++;
                //System.out.println(100);
                if(y >= n-2){
                    break;
                }
                y++;
            }
            if(x%2==1){
                count++;
            }
            i+=(x-1);
        }
        System.out.println(count);
    }

}

Measured memory_bytes: 50404
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define ull unsigned long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

ll rm2 = 0;
int factor( ull m , ll& sq , ll& q){
        ull d = 2;
        sq = 0;
        q = 1;
        vector<int> cnt;
        while(1){
                if( d * d > m ) break;
                if( m % d == 0 ){
                        cnt.push_back(1);
                        ll cu = d;
                        while( m % d == 0 ) {
                            m /= d;
                            cu *= d;
                            cnt.back() += 1;
                        }
                        if( cnt.back() % 2 == 0) {
                          sq *= sqrt( cu );
                        }
                        else if( cnt.back() % 2 == 1 ){
                          sq *= sqrt( cu/d );
                          q *= d;
                        }
                }
                d++;
        }
        if( m > 1 ) {
            q *= m;
        }
        return 0;
}
int calc(ll c ,int a, int b) {
  ll sqa;
  ll sqb;
  ll ra;
  ll rb;

  ull p = a * b;
  /*
  factor(p,sqa,ra);
  if( c <= sqa * 2 ) return 0;
  c = c - sqa - sqa;
  if( ra * ra >= c * c ) return 0;
  return 1;
  */
  ull left =  (ull) 4 * a * b;
  ull right = (ull) c * c;
  if( left < right ) return 1;
  return 0;
}
int main(){
        cin.tie(0);
  ios::sync_with_stdio(false);
  unsigned ll  a,b,c;
  cin >> a >> b >> c;
  if( a + b > c ){
    cout << "No" << endl;
    return 0;
  }
  c = c - a - b;
  //c - 2* sqrt(ab)
  if (calc(c,a,b) ){
    cout << "Yes" << endl;
    return 0;
  }
  else{
    cout << "No" << endl;
    return 0;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 10;

int dp[2010][2010];

int N;
pii A[2010];

signed main()
{
	cin >> N;

	rep(i, N) {
		cin >> A[i].fst;
		A[i].scd = i;
	}

	sort(A, A + N, greater<pii>());

	rep(i, N) {
		int cur = i;
		rep(j, cur + 1) {
			int l = cur - j, r = j;

			chmax(dp[l + 1][r], dp[l][r] + A[cur].fst * abs(l - A[cur].scd));
			chmax(dp[l][r + 1], dp[l][r] + A[cur].fst * abs(N - 1 - r - A[cur].scd));
		}
	}

	int mx = 0;

	rep1(i, N) {
		chmax(mx, dp[i][N - i]);
	}

	cout << mx << endl;
}




Measured memory_bytes: 26300
from itertools import accumulate
import collections

n = int(input())
A = list(map(int, input().split()))
S = list(accumulate(A))

C = collections.Counter(S)
cnt = C[0]
mc = C.most_common()
for c in mc:
    if c[1] > 1:
        cnt += c[1]*(c[1]-1)//2
print(cnt)   

Measured memory_bytes: 48272
#include "bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 256
//Author : Siriuslight
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0),cout<<setprecision(10)<<fixed;
#define int long long
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const ll inf = 1e9+100, N = 3e3+5;
const ll INF = 1e18+100, MOD = 1e9+7;

ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

//ordered_set X;
//X.insert(3);
//X.order_of_key(3) no of elements less than 3
//*X.find_by_order(n) nth greatest element(0-indexed)

int n, a[N], dp[2][N][N];
bool vis[2][N][N];

int solve(int player, int l, int r){
    if(l > r) return 0;
    if(l == r){
        if(player) return a[l];
        else return (-a[l]);
    }
    int &res = dp[player][l][r];
    if(vis[player][l][r]) return res;
    vis[player][l][r] = true;
    if(player)
        res = max(solve(!player, l + 1, r) + a[l], solve(!player, l, r - 1) + a[r]);
    else
        res = min(solve(!player, l + 1, r) - a[l], solve(!player, l, r - 1) - a[r]);
    return res;
}

int32_t main(){
    FIO;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(1, 1, n);
}


Measured memory_bytes: 159104
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
X = int(input())
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]
yokin = 100
i=0
while(yokin < X):
    yokin = int(yokin*1.01)
    #print(yokin)
    i=i+1
#while(i<3760):
#    yokin=yokin*1.01
#    i=i+1
print(i)
#print(yokin)


Measured memory_bytes: 9156
n = int(input())
s = set()
q = [0,0]
import heapq as hq
for a in map(int, input().split()):
  if a > q[0]:
    try:
      s.remove(a)
      hq.heapreplace(q, a)
    except:
      s.add(a)

print(q[0]*q[1])


Measured memory_bytes: 20140
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EHandshake {
public:

    ll upper(int k, vector<ll>& a) {
      int idx = a.size()-1;
      ll ret = 0;
      for(int i=0; i<a.size(); i++) {
        while (idx >= 0 && a[i]+a[idx] > k) {
          idx--;
        }
        ret += (a.size()-1-idx);
      }
      return ret;
    }

    ll upper2(int k, vector<ll>& a) {
      int idx = a.size()-1;
      vector<ll> sum(a.size()+1);
      rep(i, a.size()) {
        sum[i+1] = sum[i] + a[i];
      }
      ll ret = 0;
      for(int i=0; i<a.size(); i++) {
        while (idx >= 0 && a[i]+a[idx] > k) {
          idx--;
        }
        ret += (sum[a.size()] - sum[idx+1]) + a[i] * (a.size() - idx - 1);
      }
      return ret;
    }

    ll lower(int k, vector<ll>& a) {
      int idx = 0;
      ll ret = 0;
      for(int i=a.size()-1; i>=0; i--) {
        while(idx < a.size() && a[i]+a[idx] < k) {
          idx++;
        }
        ret += idx;
      }
      return ret;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, m; cin >> n >> m;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      sort(all(a));

      ll mi = 0;
      ll ma = INT_MAX/2;
      ll chk = -1;
      while(mi+1 < ma) {
        ll med = (mi+ma)/2;

        ll up = upper(med, a);
        ll lo = lower(med, a);
        if (up > m) {
          mi = med;
        } else if (lo > n*n-m) {
          ma = med;
        } else {
          chk = med;
          break;
        }
      }
      debug(chk);

      ll cnt = upper(chk, a);
      ll ret = (m-cnt)*chk;
      debug(ret);
      ret += upper2(chk, a);
      debug(ret);
      cout << ret << endl;

    }
};

signed main() {
  EHandshake solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int a,b;
	int menseki, nagasa;
	scanf("%d", &a);
	scanf("%d", &b);
	menseki = a * b;
	nagasa = 2*(a+b);
	printf("%d %d\n", menseki, nagasa);
	return 0;
}


Measured memory_bytes: 1948
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    string o,e;
    cin>>o>>e;
    int oe=o.size()+e.size();
    for(int i=0;i<oe;i++){
        if(i%2==0) cout<<o.at(i/2);
        else cout<<e.at(i/2);
    }
}

Measured memory_bytes: 3548
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a + b == c + d) cout << "Balanced" << endl;
    else if(a + b < c + d) cout << "Right" << endl;
    else cout << "Left" << endl;
}


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

int main(){
int num,temp;

while(1){
   cin>>num;
   if(num==0){
   break;
   }
   int min=10000000,max=0,sum=0;
   for(int i=0;i<num;i++){
   cin>>temp;
   if(min>temp)min=temp;
   if(max<temp)max=temp;
   sum+=temp;
   }
   sum=sum-max-min;
   cout<<sum/(num-2)<<endl;
}

return 0;
}

Measured memory_bytes: 1156
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

n = int(input())
nums = list(map(int, stdin.readline().split()))
q = int(input())

freq = dd(int)
ssf = 0
for i in nums:
    freq[i]+= 1
    ssf += i

for _ in range(q):
    b, c = map(int, input().split())
    if freq[b] == 0:
        print(ssf)
        continue
    else:
        minus = b*freq[b]
        plus = c*freq[b]
        ssf += (plus - minus)
        freq[c] += freq[b]
        freq[b] = 0
        print(ssf)




Measured memory_bytes: 92496
n,m=map(int,input().split())
h=list(map(int,input().split()))
info=[]
for i in range(m):
    a,b=map(int,input().split())
    info.append([a,b])
high=[[0,0] for i in range(n)]
for i in range(m):
    x=info[i][0]-1
    y=info[i][1]-1
    high[x][1]+=1
    high[y][1]+=1
    if h[x]<=h[y]:
        high[x][0]+=1
    if h[y]<=h[x]:
        high[y][0]+=1
    #print(high)
ans=0
for i in range(n):
    if high[i][1]==0:
        ans+=1
    else:
        if high[i][0]==0:
            ans+=1
print(ans)
#print(info)
#print(high)
#print(h)

Measured memory_bytes: 107272
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int i = (0);i < (n);++i)
#define rep(i,s,g) for(int i = (s);i < (g);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;



int main()
{
	ll n,m;
	cin >> n >> m;
	iiv v(n+2);
	
	REP(i,m)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].PB(b);v[b].PB(a);
	}
	
	set<int> can;
	set<int> dont;
	
	
	queue<pair<int,int> > q;
	
	REP(i,v[1].size())
	{
		q.push(MP(v[1][i],1));
	}
	
	while(!q.empty())
	{
		pair<int,int> tmp = q.front();q.pop();
		REP(i,v[tmp.FI].size())
		{
			int tt = v[tmp.FI][i];
			int iscan,isdont;
			if(can.find(tt) != can.end())
			{
				iscan = 1;
			}
			else
			{
				iscan = 0;
			}

			if(dont.find(tt) != dont.end())
			{
				isdont = 1;
			}
			else
			{
				isdont = 0;
			}
			
			
			if(iscan == 0 && isdont == 0)
			{
				q.push(MP(tt,(tmp.SE+1) % 2));
					
				if((tmp.SE+1) % 2 == 1)
				{
					can.insert(tt);
				}
				else
				{
					dont.insert(tt);
				}
			}
			else
			{
				if( iscan == 1 && (tmp.SE+1) % 2 == 0)
				{
					q.push(MP(tt,0));
				}
				else if( isdont == 1 && (tmp.SE+1) % 2 == 1)
				{
					can.insert(tt);
					dont.erase(tt);
					q.push(MP(tt,1));
				}
			}
		}
	}

	
	ll num1 = can.size();
	ll num2 = dont.size();
	//cout << can.size() << ' ' << dont.size() << endl;
	ll ans = 0;
	
	if(num1 == n)
	{
		ans = ((n * (n - 1ll)) / 2ll) - m;
	}
	else
	{
		ans = num1*(n - num1) - m;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>

int main(void){
   int i,work=0,n,loopable;

   scanf("%d",&n);
   int num[n];

   for(i=0;i<n;i++)
      scanf("%d",&num[i]);

   while(1){
      loopable=1;
      for(i=0;i<n;i++)
         if(num[i]%2==1) loopable=0;
      if(loopable==0) break;

      for(i=0;i<n;i++)
         num[i]=num[i]/2;

      work++;
   }

   printf("%d\n",work);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
 /* AtCoder Beginner Contest 107 (๑•﹏•๑｀) */

int main(){
    int N,i; SCD2(N,i);
    PRINTD(N-i+1);

    return 0;
}

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

int main() {
  string o, e;
  cin >> o;
  cin >> e;
  int l = o.size() + e.size();
  for (int i = 0; i < l; i++) {
    if (i % 2 == 0)
      cout << o[(i/2)];
    else
      cout << e[(i-1)/2];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(ll, n, a);
    VEC(ll, x, n);
    
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(2501)));

    REP(i, n+1) dp[i][0][0] = 1;
    FOR(i, 1, n+1) FOR(j, 1, n+1) FOR(k, 1, 2501){
        dp[i][j][k] = dp[i - 1][j][k];
        if(k - x[i-1] >= 0) dp[i][j][k] += dp[i - 1][j - 1][k - x[i-1]];
    }
    ll ans = 0;
    FOR(i, 1, n+1) ans += dp[n][i][i*a];
    OUTL(ans);
RET;}

Measured memory_bytes: 52224
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    vector<int> c(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        res += b[a[i] - 1];
        if (i + 1 < n && a[i] + 1 == a[i + 1]) {
            res += c[a[i] - 1];
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
import numpy as np

i = input()
N = int(i)
A = np.array([0]*N)
i = input()
a = int(i)
A[0] = a
i = input()
b = int(i)
A[1] = b
snd = min(a, b)
fst = max(a, b)
for x in range(N - 2):
    j = input()
    y = int(j)
    A[x+2] = y
    if y <= fst:
        snd = max(snd, y)
    fst = max(fst, y)

for x in range(N):
    if A[x] < fst:
        print(fst)
    else:
        print(snd)


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

int main(){
	int H , W , K;
	long long int MOD = 1000000007;
	cin >> H >> W >> K;
	if(W==1){
		cout << 1 << endl;
		return 0;
	}                                                
	long long int dp[H+1][W];
	int fib[8] = {1,2,3,5,8,13,21,34};
	dp[0][0] = 1;
	for(int i=1;i<W;i++)dp[0][i] = 0;
	if(W==2){
		for(int i=1;i<H+1;i++){
			dp[i][0] = (dp[i-1][0] + dp[i-1][1])%MOD;
			dp[i][1] = dp[i][0]%MOD;
		}
		cout << dp[H][K-1] << endl;
		return 0;
	}
	for(int i=1;i<H+1;i++){
		dp[i][0] = (dp[i-1][0]*fib[W-2] + dp[i-1][1]*fib[W-3])%MOD;
		if(W==3){
			dp[i][1] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2])%MOD;
		}else{
			dp[i][1] = (dp[i-1][0]*fib[W-3] + dp[i-1][1]*fib[W-3] + dp[i-1][2]*fib[W-4])%MOD;
		}
	for(int j=2;j<W-2;j++){
			dp[i][j] = (dp[i-1][j-1]*fib[j-2]*fib[W-j-2] + dp[i-1][j]*fib[j-1]*fib[W-j-2] + dp[i-1][j+1]*fib[j-1]*fib[W-j-3])%MOD;
		}
		if(W==3){
			dp[i][2] = (dp[i-1][1] + dp[i-1][2]*fib[1])%MOD;
		}else{
			dp[i][W-2] = (dp[i-1][W-3]*fib[W-4] + dp[i-1][W-2]*fib[W-3] + dp[i-1][W-1]*fib[W-3])%MOD;
			dp[i][W-1] = (dp[i-1][W-2]*fib[W-3] + dp[i-1][W-1]*fib[W-2])%MOD;
		}
	}
	cout << dp[H][K-1] << endl;
	return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;
vector<i64> fact(2010);

i64 comb(i64 n, i64 r) {
  return fact[n] * inv(fact[r], M) % M * inv(fact[n - r], M) % M;
}

signed main() {
  i64 n, m;
  cin >> n >> m;
  vector<vector<i64>> G(n);
  REP(_, m) {
    i64 u, v;
    cin >> u >> v;
    u -= 1;
    v -= 1;
    G[u].push_back(v);
  }
  i64 s, t;
  cin >> s >> t;
  s -= 1;
  t -= 1;
  vector<i64> k1(n, inf<i64>);
  vector<i64> k2(n, inf<i64>);
  vector<i64> pa(n, inf<i64>);
  queue<i64> st;
  st.push(s);
  pa[s] = 0;
  while (st.size()) {
    i64 u = st.front();
    st.pop();
    for (i64 v : G[u]) {
      if (k1[v] > pa[u] + 1) {
        k1[v] = pa[u] + 1;
        st.push(v);
      }
      if (k2[v] > k1[u]) {
        k2[v] = k1[u];
        st.push(v);
      }
      if (pa[v] > k2[u]) {
        pa[v] = k2[u];
        st.push(v);
      }
    }
  }
  cout << (pa[t] == inf<i64> ? -1 : pa[t]) << endl;
}


Measured memory_bytes: 8064
#include<stdio.h>
int main(){
  int n,m,f[310],d[310][310],r[310],i,j,mi,min=310;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    for(j=r[i]=0;j<m;j++)scanf("%d",&d[i][j]);
  }
  for(i=0;i<m;i++){
    int c[310]={};
    for(j=0;j<n;j++){
      while(f[d[j][r[j]]])r[j]++;
      c[d[j][r[j]]]++;
    }
    for(j=mi=1;j<305;j++){
      if(c[mi]<c[j])mi=j;
    }
    if(min>c[mi])min=c[mi];
    f[mi]=1;
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

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

    string s, str;
    cin >> str;

    string v[] = {
        "maerd", 
        "remaerd", 
        "esare", 
        "resare"
    };

    s = str;
    REP(i, str.length()){
        s[i] = str[str.length()-i-1];
    }

    REP(i, s.length()){
        bool f=false;
        REP(j, 4){
            if(i+v[j].length()-1 >= s.length()) continue;
            string t = s.substr(i, v[j].length());
            
            if(t==v[j]){
                i+=(v[j].length()-1);
                f=true;
                break;
            }
        }

        if(!f){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 512
//
// C - 白昼夢 / Daydream
//

#include <iostream>

using namespace std;

string suf[] = {"dream", "dreamer", "erase", "eraser",};
int len[] = {5, 7, 5, 6};

int main() {
    string S;
    cin >> S;
    S += '-';

    bool match = true;
    int last = S.length() - 1;

    while (match) {
        match = false;
        for (int i = 0; i < 4; i++) {
            int pos = last - len[i];
            if (S.find(suf[i], pos) != string::npos) {
                last = pos;
                S[last] = '-';
                match = true;
                break;
            }
        }
    }

    cout << (last == 0 ? "YES" : "NO") << endl;
}

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

using namespace std;
using ii = pair<int, int>;

#define fi first
#define se second

const int Lim = 1e5 + 2;

int n, m, a[Lim];
long long ans = 0;
ii op[Lim];

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i <= m; ++i)
    cin >> op[i].se >> op[i].fi;
  sort(a + 1, a + n + 1);
  sort(op + 1, op + m + 1, greater<ii>());
  for (int i = 1, j = 1; i <= n; ++i) {
    if (!op[j].se) ++j;
    if (a[i] < op[j].fi) ans += op[j].fi, --op[j].se;
    else ans += a[i];
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main()
{
  int n,i;

  scanf("%d",&n);

  int A[n+1];

  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
    }

  
  for(i=1;i<=n;i++)
    {
      printf("node %d: key = %d, ",i,A[i]);

      if(i!=1)printf("parent key = %d, ",A[i/2]);
     
      if(2*i<=n)printf("left key = %d, ",A[2*i]);

      if(2*i+1<=n)printf("right key = %d, ",A[2*i+1]);

      printf("\n");
    }

  return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;

int main(){
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> t(n);

    for(int i = 0; i < n; i++){
        cin >> t[i];
    }

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

    //出れない授業の総数
    int cnt = 0;
    for(int i = 0; i < n && t[i] < b; i++){
        if(a <= t[i]){
            cnt++;
        }
    }
    int ans = n - cnt;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256