akhauriyash/Code-Regression huggingface dataset:
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int N = 2e5 + 10;
const int K = 3e3 + 10;
const int mod = 1e9 + 7;
int f[N];
int vf[N];
int dp[K];
vector<pii> v;
int h,w,n;


int power(int n, int k)
{
    if(k == 0) return 1;
    int tmp = power(n,k/2); tmp *= tmp; tmp %= mod;
    return (k&1 ? (tmp*n)%mod : tmp);
}

int binomial(int n,int k){
    return ((f[n]*vf[k] % mod)*vf[n - k]) % mod;
}

int invoker(int n, int m)
{
    return binomial(n+m-2,m-1);
}

int bad_path(int id, int i) //
{
    int a = v[id].first; int b = v[id].second;
    int x = v[i].first; int y = v[i].second;
    if(a >= x && b >= y){
        return (invoker(a-x+1,b-y+1) * dp[i]) % mod;
    }
    return 0;
}

void calc(int id)
{
    int tmp = 0;
    for(int i = 0; i < id; i++){
        tmp += bad_path(id,i);
        tmp %= mod;
    }
    int ans = invoker(v[id].first, v[id].second);
    ans -= tmp; ans %= mod; ans += mod; ans %= mod;
    dp[id] = ans;
}
int32_t SALI()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> h >> w >> n; f[0] = vf[0] = 1;
    for(int i = 1; i < N; i++){f[i] = (f[i-1] * i) % mod; vf[i] = power(f[i] , mod-2);}
    for(int i = 0; i < n; i++){int x,y; cin >> x >> y; v.pb(pii(x,y));}
    v.pb(pii(h,w)); sort(v.begin(),v.end());
    
    for(int i = 0; i <= n; i++) calc(i);
    cout << (((dp[n]%mod)+mod)%mod);
}



/**< WRITEN BY ALI ADELKHAH */



Measured memory_bytes: 6908
n, k = map(int, input().split())
s = 0
lim = (10**9+7)
for i in range(k, n + 2):
    s += (((n - i + 1 + n) * i // 2) - (i-1) * (i) // 2 + 1) % lim
print(s % lim)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

ll mp[30][30];
ll dx[4] = {0,0,1,-1},dy[4] = {1,-1,0,0};
ll n,m;
vector<string> vs;

ll bfs(P st)
{
	queue<ll> que;
	que.push(st.fi);que.push(st.se);
	memset(mp,-1,sizeof(mp));
	mp[st.fi][st.se] = 0;
	ll ma = -INF;
	while(que.size())
	{
		ll xx = que.fr;que.pop();
		ll yy = que.fr;que.pop();
		FOR(i,0,4)
		{
			ll sx = xx+dx[i];
			ll sy = yy+dy[i];
			if( sx<0 || sx>=n || sy<0 || sy>=m || vs[sx][sy] == '#' )
			{
				continue;
			}
			if( mp[sx][sy] == -1 )
			{
				que.push(sx);que.push(sy);
				mp[sx][sy] = mp[xx][yy]+1;
				ma = max(ma,mp[sx][sy]);
			}
		}
	}
	return ma;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	cin>>n>>m;
	FOR(i,0,n)
	{
		string s;
		cin>>s;
		vs.pb(s);
	}
	ll ans = -INF;
	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			if(vs[i][j] == '.')
				ans = max(ans,bfs(P(i,j)));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define si(x) scanf("%d",&x)
#define pi(x) printf("%d\n",x)
#define s(x) scanf("%I64d",&x)
#define p(x) printf("%I64d\n",x)
#define sc(x) scanf("%s",x)
#define pc(x) printf("%s",x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define M 1000000007
#define N 200002
#define inf 1e15
#define PQG priority_queue< int,std::vector<int>,std::greater<int> >
#define PQL priority_queue< int,std::vector<int>,std::less<int> >
#define PQPL priority_queue<pii ,vector< pii >, less< pii > >
#define PQPG priority_queue<pii ,vector< pii >, greater< pii > >

using namespace std;

int main(){
int n;
cin>>n;
ll a[3*n];
for(int i=0;i<3*n;i++) cin>>a[i];
sort(a,a+3*n);
ll sum=0;
int cnt=0;
for(int i=3*n-2;i>=0;i-=2){
    if(cnt==n) break;
    sum+=a[i];
    cnt++;
}
cout<<sum<<endl;

return 0;
}


Measured memory_bytes: 2560
#include <iostream>

std::string solve(const std::string &s) {
    std::string ans = "";
    int idx = 0;
    while (idx < s.size()) {
        switch( s[idx] ) {
            case '0':
                ans += '0';
                break;
            case '1':
                ans += '1';
                break;
            case 'B':
                if (ans.size() > 0) ans = ans.substr(0, ans.size()-1);
                break;
        }
        ++idx;
    }
    return ans;
}

int main() {
    std::string s;
    std::cin >> s;
    std::cout << solve( s ) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 1e6 + 69;

ll n,m,k,x,y,ans,l,r,d;

ll A[N],fix[N];

ll tree[4*N],toadd[4*N];

pair<ll,ll>P[N];
void upd(int node,int tl,int tr){

    if(tl>r || tr<l)return ;

    if(l<=tl && tr<=r){
        tree[node] += x * (tr-tl+1);
        toadd[node] += x;
        return ;
    }

    int mid = (tl+tr)>>1;
    int left = node<<1;
    int right = left+1;

    if(toadd[node]){
        tree[left] += toadd[node]*(mid-tl+1);
        toadd[left] += toadd[node];
        tree[right] += toadd[node]*(tr-mid);
        toadd[right] += toadd[node];
        toadd[node] = 0;
    }

    upd(left,tl,mid);
    upd(right,mid+1,tr);

    tree[node] = tree[left] + tree[right];

}

ll get(int node,int tl,int tr){

    if(tl>r || tr<l)return 0;

    if(l<=tl && tr<=r){
        return tree[node];
    }

    int mid = (tl+tr)>>1;
    int left = node<<1;
    int right = left+1;

    if(toadd[node]){
        tree[left] += toadd[node]*(mid-tl+1);
        toadd[left] += toadd[node];
        tree[right] += toadd[node]*(tr-mid);
        toadd[right] += toadd[node];
        toadd[node] = 0;
    }
    return get(left,tl,mid) + get(right,mid+1,tr);
}

int find(ll x){

    int l = 1,r = n;

    int ans = -1;

    while(l<=r){
        int mid = (l+r)/2;
        if(P[mid].ff<=x){
            ans = mid;
            l = mid+1;
        } else {
            r = mid-1;
        }
    }

    return ans;

}

int main(){

    ios::sync_with_stdio(0);

    cin>>n>>d>>k;

    for(int i=1;i<=n;i++){
        cin>>P[i].ff>>P[i].ss;
    }

    sort(P+1,P+1+n);

    for(int i=1;i<=n;i++){
        x = P[i].ss; l = i, r = i;
        upd(1,1,n);
    }

    for(int i=1;i<=n;i++){
        l = i,r = i;
        ll h = get(1,1,n);
        if(h<=0) continue;
        if(h%k==0){
            x = -h;
            ans += h/k;
        } else {
            x = -(h/k+1)*k;
            ans += h/k + 1;
        }
        l = i, r = find( P[i].ff + 2*d );
        upd(1,1,n);
    }

    cout<<ans<<endl;



}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  int64_t ans=0;
  sort(L.begin(),L.end(),greater<int64_t>());
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(L.at(j)==L.at(i)){
        continue;
      }
      int diff=L.at(i)-L.at(j);
      for(int k=j+1;k<N;k++){
        if((L.at(k)==L.at(i))||(L.at(k)==L.at(j))){
          continue;
        }
        if(L.at(k)>diff){
          ans++;
        }else{
          break;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  vector<long long int> bestL1(N, -1), bestL2(N, -1);
  long long int ct = 0;
  bestL1[1] = A[0];
  bestL2[1] = A[1];
  for (int i = 2; i < N; i++) {
    bestL1[i] = bestL1[i - 1];
    bestL2[i] = bestL2[i - 1] + A[i];
    while (abs(bestL1[i] + 2 * A[ct + 1] - bestL2[i]) < abs(bestL1[i] - bestL2[i])) {
      bestL1[i] += A[ct + 1];
      bestL2[i] -= A[ct + 1];
      ct++;
    }
  }
  
  vector<long long int> bestR1(N, -1), bestR2(N, -1);
  ct = N - 1;
  bestR1[N - 2] = A[N - 1];
  bestR2[N - 2] = A[N - 2];
  for (int i = N - 3; i >= 0; i--) {
    bestR1[i] = bestR1[i + 1];
    bestR2[i] = bestR2[i + 1] + A[i];
    while (abs(bestR1[i] + 2 * A[ct - 1] - bestR2[i]) < abs(bestR1[i] - bestR2[i])) {
      bestR1[i] += A[ct - 1];
      bestR2[i] -= A[ct - 1];
      ct--;
    }
  }
  
  long long int ans = 4000000000;
  for (int i = 1; i < N - 2; i++) {
    long long int ansMax = max(bestL1[i], bestL2[i]);
    ansMax = max(ansMax, bestR1[i + 1]);
    ansMax = max(ansMax, bestR2[i + 1]);
    
    long long int ansMin = min(bestL1[i], bestL2[i]);
    ansMin = min(ansMin, bestR1[i + 1]);
    ansMin = min(ansMin, bestR2[i + 1]);
    
    ans = min(ans, ansMax - ansMin);
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const ll INF = LLONG_MAX;
// const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;
#define PI acosl(-1)
#define MAX_N 100 + 2

void exec(){
  int a[3];
  for (int i = 0; i < 3; i++){
    scanf("%d", &a[i]);
  }
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 256
from itertools import product
from collections import Counter

if __name__ == '__main__':
    n = input()
    length = len(n)
    ans = 0
    for i in range(length + 1):
        for s in (''.join(list(t)) for t in product(*(['357'] * i))):
            s = (' ' * (length - i)) + s
            if n < s:
                break
            count_set = set(Counter(s.strip()).keys())
            if count_set != {'3', '5', '7'}:
                continue
            ans += 1
    print(ans)


Measured memory_bytes: 3572
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
///*二進数割り算*/div2(ll x,ll y){}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 ll a[n+10],b[n+10];
 vector<ll>c;
 ll sum_a=0,sum_b=0;
 rep(i,0,n){
  sc(a[i]);
  sum_a+=a[i];
 }
 rep(i,0,n){
  sc(b[i]);
  sum_b+=b[i];
 }  
 if(sum_a<sum_b){
  puts("-1");
  return 0;
 }
 ll lend=0;
 rep(i,0,n){
  push(c,a[i]-b[i]);
 }
 sort(c);
 //rep(i,0,n)cout<<c[i]<<" ";pnn;
 ans=0;
 rep(i,0,n){
  if(c[i]>=0)break;
  lend-=c[i];
  ans++;
 }
 rrp(i,n,0){
  if(lend<=0)break;
  lend-=c[i];
  ans++;
 }
 pr(ans);
return 0;}

Measured memory_bytes: 5812
var s:string;
    i:integer;
    ok:boolean; 

begin
readln(s);
ok:=true;
for i:=1 to length(s)-1 do begin
                           if s[i]=s[i+1] then begin
                                               Writeln('Bad');
                                               ok:=false; 
                                               break;
                                               end;
                           end;
if ok=true then Writeln('Good');
end.

Measured memory_bytes: 128
def lastDigit(num)
  return num % 10
end

def nextLine(list)
  acc = []
  list.each_cons(2) do |a, b|
    acc << lastDigit(a + b)
  end
  return acc
end

if __FILE__ == $0
  while line = gets
    first_line = line.split('').map{|i| i.to_i}
    currentLine = first_line
    9.times do 
      currentLine = nextLine(currentLine)
    end
    puts currentLine[0]
  end
end

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

int main()
{
    int n;
    cin >> n;
    int arr[n+1];
    int dp[n+1] = {0};
    for(int i=1; i<=n; i++)
        cin >> arr[i];
    arr[0] = 0;
    dp[2] = abs(arr[2]- arr[1]);
    for(int i=3; i<=n; i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i]- arr[i-1]), dp[i-2] + abs(arr[i-2]- arr[i]));
    }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int h,w; cin >> h >> w;
    int a,b; cin >> a >> b;
    cout << h*w-((a*w)+(h-a)*b) << endl;
return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    t = 0
    kind = set()
    for e in v:
        if e // 400 >= 8:
            t += 1
        else:
            kind.add(e // 400)
    print(max(1,len(kind)), len(kind) + t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
def insertionSort(a, n)
	(1..n-1).each{|i|
		v = a[i]
		j = i - 1
		while j >= 0 && a[j] > v
			a[j+1] = a[j]
			j -= 1
		end
		a[j+1] = v
		puts a * " "
	}
end

n = gets.to_i
a = gets.split.map(&:to_i)
puts a * " "
insertionSort a, n

Measured memory_bytes: 8780
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll n;
    ll t = 1, a = 1;
    cin >> n;
    imfor(i, n) {
        ll T, A;
        cin >> T >> A;
        ll x, y;
        if (t % T == 0) {
            x = t / T;
        }
        else {
            x = (t / T) + 1;
        }
        if (a % A == 0) {
            y = a / A;
        }
        else {
            y = (a / A) + 1;
        }
        ll k = max(x, y);
        t = k * T;
        a = k * A;
    }
    cout << t + a << endl;
}

Measured memory_bytes: 256
from collections import deque

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

A.sort()
A_d = deque(A)

if (A_d[0] <= 0 and A_d[n-1] > 0) or (A_d[0] < 0 and A_d[n-1] >= 0):
    print(sum(list(map(abs, A_d))))
    while A_d[-2] >= 0:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)
elif A_d[0] > 0:
    atama = A_d.popleft()
    tugi = A_d.popleft()
    new = atama - tugi
    A_d.appendleft(new)
    print(sum(list(map(abs, A_d))))
    print(atama, tugi)
    while len(A_d) != 2:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    atama = A_d.popleft()
    ketu = A_d.pop()
    print(ketu, atama)
else:
    ketu = A_d.pop()
    tugi = A_d.pop()
    new = ketu - tugi
    A_d.append(new)
    print(sum(list(map(abs, A_d))))
    print(ketu, tugi)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int N = 2e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

struct DSU {
	int fa[N];
	
	I int findfa(int x) {return fa[x] == x ? x : fa[x] = findfa(fa[x]);}
	I void Merge(int x, int y) {
		int fx = findfa(x), fy = findfa(y);
		fa[fx] = fy;
	}
} f;
int fa[N], s[N][2];
struct node {
	int x;
	
	I friend bool operator < (const node &a, const node &b) {
		if((LL)s[a.x][0] * s[b.x][1] == (LL)s[a.x][1] * s[b.x][0]) return a.x > b.x;
		return (LL)s[a.x][0] * s[b.x][1] > (LL)s[a.x][1] * s[b.x][0];
	}
}; set<node> q;

int main() {
	reg n = read();
	fo(i, 2, n) fa[i] = read();
	fo(i, 1, n) s[i][read()]++, f.fa[i] = i;
	fo(i, 2, n) q.insert(node{i});
	LL ans = 0;
	while(!q.empty()) {
		reg x = f.findfa(q.begin() -> x), F = f.findfa(fa[x]);
		q.erase(q.begin()), q.erase(node{F});
		ans += (LL)s[F][1] * s[x][0];
		f.Merge(x, F), s[F][0] += s[x][0], s[F][1] += s[x][1];
		if(F ^ 1) q.insert(node{F});
	} pr2(ans);
	return 0;
}



Measured memory_bytes: 14848
n,m=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]=-l[i]
from heapq import heappush,heappop,heapify
heapify(l)
for i in range(m):
    heappush(l,-(-heappop(l)//2))
print(-sum(l))

Measured memory_bytes: 72172
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	double total = 0, a;
  	string s;
  	int n;
	cin >>n ;
	rep(i, n){
		cin >> a >> s;
      	total += (s == "BTC" ? a * 380000.0 : a);
	}
	printf("%8.8lf\n", total);	
}


Measured memory_bytes: 256
#include<cstdio>
    int N,K,Ans;
    int main(){
    	scanf("%d %d",&N,&K);
    	for(int i=1;i<=N;i++)
    		scanf("%*d");
    	Ans=(N-K)/(K-1);
    	if((N-K)%(K-1)!=0) Ans++;
    	printf("%d\n",Ans+1);
    	return 0;
    }

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

int main()
{
    int w, a, b;
    int answer;
    cin >> w >> a >> b;

    if (a < b) {
        if (a + w < b) {
            answer = b - (a + w);
        } else {
            answer = 0;
        }
    } else if (a == b) {
        answer = 0;
    } else {
        if (b + w < a) {
            answer = a - (b + w);
        } else {
            answer = 0;
        }
    }

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  string s;
  cin>>s;
  n=s.size();
  rep(i,n-8)cout<<s[i];
  cout<<endl;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

ll gcd( ll a, ll b ){
    if( a < b ) swap(a,b);
    ll tmp;
    while( b ){
        tmp = b;
        b = a%b;
        a = tmp;
    }
    return a;
}

int main() {

    int N;
    Scd(N);

    ll a,b,c,d;
    bool ans;

    while(N--){
        ans = true;
        Scll2(a,b);
        Scll2(c,d);

        if( a < b ) ans = false;
        if( d < b ) ans = false;

        if( c >= b-1) {
            // 勝　利　確　定
        }else{
            ll g = gcd(b,d);
            if( b-g+a%g > c ) ans = false;
        }

        YesNo(ans);
    }

    return 0;
}



Measured memory_bytes: 256
n=int(input())
l=input().split()
li=[int(i) for i in l]
sumi=0
for i in li:
    sumi+=i
sum2=0
for i in li:
    sum2+=(i*i)
sumi=sumi*sumi
z=(sumi-sum2)//2
print(z%1000000007)


Measured memory_bytes: 94216
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[200010];

signed main(){
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
	}
	sort(A,A+N,greater<>());
	int ans=0;
	for(int i=K;i<N;i++){
		ans+=A[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
int n,a[100],s=0;

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(15);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	int t=s/n;
	if (abs(s-n*t)>abs(s-n*(t+1)))
		t++;
	s=0;
	for (int i=0;i<n;i++)
		s+=(a[i]-t)*(a[i]-t);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin, n, a, b;
    ll loop = n / (a + b), rem = n % (a + b);
    cout << loop * a + min(rem, a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
typedef long long ll;

ll a[100 + 10];

int main(){
    a[0] = 2;
    a[1] = 1;
    int N;
    cin >> N;
    for(int i = 2; i <= N; i++){
        a[i] = a[i-1] + a[i-2];
    }
    cout << a[N] << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String S1 ="";
		String S2 ="";
		String ans="";
		int cnt1 = 0;
		int cnt2 = 0;
		int i1 = 0;
		int i2 = 0;
		S1=S.substring(0, 2);
		S2=S.substring(2, 4);
		i1 = Integer.parseInt(S1);
		i2 = Integer.parseInt(S2);
		for(int i=1;i<=12;i++){
			if (i1==i) {
				cnt1= cnt1+1;
			}
		}	
		for(int j=1;j<=12;j++){
			if (i2==j) {
				cnt2=cnt2+1;
			}
		}
		if (cnt1==1&&cnt2==1) {
			ans="AMBIGUOUS";
			System.out.println(ans);
		}
		if (cnt1==1&&cnt2!=1) {
			ans="MMYY";
			System.out.println(ans);
		}
		if (cnt1!=1&&cnt2==1) {
			ans="YYMM";
			System.out.println(ans);
		}
		if (cnt1!=1&&cnt2!=1) {
			ans="NA";
			System.out.println(ans);
		}
    }
}

Measured memory_bytes: 23124
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: usize,
        p: [usize; n*n],
    }

    macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ z : expr ) ,+ ) => { { std :: cmp :: min ( $ x , min ! ( $ ( $ z ) ,* ) ) } } }

    let mut cost = vec![vec![0usize; n]; n];
    for i in 0..n {
        for j in 0..n {
            cost[i][j] = min!(i, j, n - 1 - i, n - 1 - j);
        }
    }
    let mut exist = vec![vec![true; n]; n];
    let dx = [0, 0, 1, -1];
    let dy = [1, -1, 0, 0];
    let mut res = 0usize;
    for e in p {
        let x = (e - 1) % n;
        let y = (e - 1) / n;
        let mut queue = VecDeque::new();
        queue.push_back((x, y));
        res += cost[x][y];
        exist[x][y] = false;
        while let Some((x, y)) = queue.pop_front() {
            for i in 0..4 {
                let nx = x as isize + dx[i];
                let ny = y as isize + dy[i];
                if nx < 0 || ny < 0 || nx as usize >= n || ny as usize >= n {
                    continue;
                }
                let nx = nx as usize;
                let ny = ny as usize;
                if cost[nx][ny] > cost[x][y] + exist[x][y] as usize {
                    cost[nx][ny] = cost[x][y] + exist[x][y] as usize;
                    queue.push_back((nx, ny));
                }
            }
        }
    }
    println!("{}", res);
}


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

int main(){
  int N, X;
  cin >> N >> X;
  int count = 1;
  int now = 0;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    now += tmp;
    if(now <= X){
      count++;
    }
    if(now > X){
      break;
    }
  }
  cout << count << endl;
  
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl a(n),b(n),c(n);
  ll samecount = 0;
  REP(i,n) cin >> a[i];
  REP(i,n){
    cin >> b[i];
    c[i] = b[i];
  }
  priority_queue<pair<ll,ll>> que;
  REP(i,n){
    if(a[i]!=b[i] && b[i]>b[(i-1+n)%n]+b[(i+1+n)%n]) que.push(make_pair(b[i],i));
    if(a[i]==b[i]) samecount++;
  }
  ll ans = 0;
  while(que.size()>0){
    ll num = que.top().first;
    ll ind = que.top().second;
    ll ip = (ind-1+n)%n;
    ll in = (ind+1+n)%n;
    ll diff = c[ip]+c[in];
    que.pop();
    ll tmp = (c[ind]-a[ind])/diff;
    ans += tmp;
    c[ind] -= tmp*diff;
    if(c[ind]==a[ind]) samecount++;
    if(c[ip]>a[ip] && c[ip]>c[(ip-1+n)%n]+c[ind]) que.push(make_pair(c[ip],ip));
    if(c[in]>a[in] && c[in]>c[(in+1+n)%n]+c[ind]) que.push(make_pair(c[in],in));
  }
  if(samecount==n) cout << ans<< endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 7156
/*
a より b の方が大きければ

a < b
a より b の方が小さければ、

a > b
a と b が等しければ、

a == b
*/
#include <stdio.h>
int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b) {
        printf("a < b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2092
#include <iostream>
#define mod (long long)(1e9+7)
using namespace std;
int main(void){
    
    long long a,b,x;
    scanf("%lld%lld%lld",&a,&b,&x);
    if(x<a)printf("%lld\n",x%mod);
    else{
        long long syo;
        syo=(x-b)/(a-b);
        long long ans=0;
        ans+=(syo%mod)*(a%mod)%mod;
        ans%=mod;
        ans+=(x-(syo%mod)*((a-b)%mod))%mod;
        ans%=mod;
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3204
#include <cstdio>

int N;
long long C;
long long xi[100010];
long long vi[100010];
long long S1[100010], S2[100010];
long long N1[100010], N2[100010];
long long res;

void solve()
{
	int i;
	long long cur=0;
	for(i=1; i<=N; i++){
		cur += vi[i-1];
		S1[i] = S1[i-1];//
		if(cur-xi[i-1]>S1[i])
			S1[i] = cur-xi[i-1];
		S2[i] = S2[i-1];
		if(cur-xi[i-1]-xi[i-1]>S2[i])
			S2[i] = cur-xi[i-1]-xi[i-1];
	}
	long long tmp;
	cur = 0;
	for(i=N; i>=1; i--){
		cur += vi[i-1];
		tmp = C-xi[i-1];
		N1[i] = N1[i+1];
		if(cur-tmp>N1[i])
			N1[i] = cur-tmp;
		N2[i] = N2[i+1];
		if(cur-tmp-tmp>N2[i])
			N2[i] = cur-tmp-tmp;
	}
	res = S1[N];
	for(i=0; i<N; i++){
		if(S2[i]+N1[i+1] > res)
			res = S2[i]+N1[i+1];
	}
	for(i=N; i>0; i--){
		if(N2[i]+S1[i-1] > res)
			res = N2[i]+S1[i-1];
	}
	printf("%lld\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d", &N);
	scanf("%lld", &C);
	for(i=0; i<N; i++){
		scanf("%lld %lld", &xi[i], &vi[i]);
	}
	solve();
	return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

    private static int m_iTotalTaskDays;

    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        final int iVacationDay = Integer.parseInt(sc.next());
        final int iTaskNum = Integer.parseInt(sc.next());
        for (int i = 0; i < iTaskNum; i++) {
            final int iTaskDays = Integer.parseInt(sc.next());
            calcTotalTaskDays(iTaskDays);
        }
        int iResult = iVacationDay - m_iTotalTaskDays;
        if (0 > (iResult)) {
            iResult = -1;
        }
        System.out.print(iResult);
    }

    private static void calcTotalTaskDays(final int iTaskDays) {
        m_iTotalTaskDays += iTaskDays;
    }
}


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

int main() {
  
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C') {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  int a,b,c,d,e;
  string s,t;
  cin>>a;
  
  vector<int> vec(a);
  vector<int> vee(a);
  for(int i=0;i<a;i++){
  	cin>>vec.at(i);   
  }
  
  b=0;
  for(int i=0;i<a;i++){
  	if(vec.at(i)==1){
    b=1;
    }
  }
  
  c=0;
  d=0;
  if(b){
  	for(int i=0;i<a;i++){
    	if(c+1==vec.at(i)){
        	d++;
           c++;
        
        }
    }
  cout<<a-d<<endl;
  
  }
  else{
  cout<<-1<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 1792
#include <iostream>                                             
using namespace std;                                            
                                                                
int main(void) {                                                
  int m, f, r;                                                  
  while (true) {                                                
    cin >> m >> f >> r;                                         
    if (m+f+r==-3) {                                            
      break;                                                    
    }                                                           
    int x = m+f;                                                
    char ans;                                                   
    if (m==-1 || f==-1) {                                       
      ans = 'F';                                                
    } else if (x>=80) {                                         
      ans = 'A';                                                
    } else if (x>=65) {                                         
      ans = 'B';                                                
    } else if (x>=50) {                                         
      ans = 'C';                                                
    } else if (x>=30) {                                         
      if (r>=50) {                                              
        ans = 'C';                                              
      } else {                                                  
        ans = 'D';                                              
      }                                                         
    } else {                                                    
      ans = 'F';                                                
    }                                                           
    cout << ans << endl;                                        
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                       

Measured memory_bytes: 3088
h,w = map(int,input().split())
ans = 0
c = []
for i in range(10):
    c.append(list(map(int,input().split())))
for _ in range(10):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                c[i][j] = min(c[i][j],c[i][k] + c[k][j])
for i in range(h):
    a = list(map(int,input().split()))
    for j in a:
        if j != -1:
            ans += c[j][1]
print(ans)

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    char C = s[0];
    int count = 1;
    for (int i = 0; i < N;i++)
    {
        if(C != s[i]){
            count++;
        }
        C = s[i];
    }
    cout << count << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int i=1;
  int ans=0;
  while(i*i<=N){
    if(i*i<=N){
      ans=i*i;
    }
  i++;
  }
  cout<<ans<<endl;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++) {
    int f = i / 10000;
    int l = i % 10;
    int f2 = i / 1000 % 10;
    int l2 = i /10 % 10;
    if (f == l && f2 == l2) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long int
int main(){
    ll t,cw1=0,ce1=0,i,sum=9999999,f=0;
    cin>>t;
    char a[t+1];
    cin>>a;
    //cout<<a<<endl;
    for(i=0;i<t;i++){
        if(a[i]=='E')
            ce1++;
    }
    //cout<<ce1<<endl;
    for(i=0;i<t;i++){
        if(a[i]=='W')
            f=1;
        else
            ce1--;
        if(ce1+cw1<sum)
            sum=ce1+cw1;
        if(f==1){
            cw1++;
            f=0;
        }
        //cout<<"sum "<<sum<<endl;
        }
    cout<<sum<<endl;
    return 0;
    //for(i=0;i<n;i++)
}



Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

const int N = 111;
const int H = 555;

const int INF = 1000000007;

int h,w,p,n,t;
vector<int> y;
vector<int> x;

bool input(){
	cin>>h>>w>>p>>n>>t;
	y.resize(n);
	x.resize(n);
	rep(i,n)cin>>y[i]>>x[i];
	return true;
}


double dp[N][H][N];
bool hasbou[H][N];;

void solve(){
	
//	puts("a");
	rep(i,H)rep(j,N)hasbou[i][j]=false;
	rep(i,n){
		hasbou[y[i]][x[i]] = true;
	}
	
//	puts("a");
	
	bool hasbar[H]={false};
	
	int putcount[H] = {0};
	
	rep(i,n){
		hasbar[y[i]] = true;
	}
	reps(i,1,h+1){
		putcount[i] = putcount[i-1];
		if(!hasbar[i])putcount[i]++;
	}
	
///	puts("a");
	
	rep(i,N)rep(j,H)rep(k,N)dp[i][j][k]=0;
	dp[0][h+1][p]=1.0;
	
	/*
	reps(i,1,h+1){
		printf("hasbar = %d\n",hasbar[i]);
	}
	reps(i,1,h+1){
		printf("putcunt%d = %d\n",i,putcount[i]);
	}
	
	puts("a");
	*/for(int j=h; j>=1; j--){
		for(int k=1; k<=w; k++){
			for(int i=0;i<=t;i++){
				dp[i][j][k] = 0;
				
				if(hasbar[j]){
					if(k!=1 && hasbou[j][k-1] == true){
						dp[i][j][k] += dp[i][j+1][k-1];
					}else if(k!=w && hasbou[j][k] == true){
						dp[i][j][k] += dp[i][j+1][k+1];
					}else{
						dp[i][j][k] += dp[i][j+1][k];
					}
				}else{
					
					
					double gyopar = (double)(t-(i-1))/putcount[j];
					//double gyopar = (double)(t-(i-1))/(h-n);
					//double gyopar = (double)k/(h-n);
					
					
					//tasanai
					dp[i][j][k] += dp[i][j+1][k] * (1-(double)(t-i)/putcount[j]);
				
					//tasu
					if(i!=0){
						if(k==1){
							
							//migi
							dp[i][j][k] += dp[i-1][j+1][k+1] * (double)1/(w-1) * gyopar;
							
							//sita
							dp[i][j][k] += dp[i-1][j+1][k] * (double)(w-2)/(w-1) * gyopar;
							
							
							
						}else if(k==w){
							
							//hidari
							dp[i][j][k] += dp[i-1][j+1][k-1] * (double)1/(w-1) * gyopar;
							
							//sita
							dp[i][j][k] += dp[i-1][j+1][k] * (double)(w-2)/(w-1) * gyopar;
							
						}else{
							
							//migi
							dp[i][j][k] += dp[i-1][j+1][k+1] * (double)1/(w-1) * gyopar;
							
							//hidari
							dp[i][j][k] += dp[i-1][j+1][k-1] * (double)1/(w-1) * gyopar;
							
							//sita
							dp[i][j][k] += dp[i-1][j+1][k] * (double)(w-3)/(w-1) * gyopar;
						}
					}
				}
				
			}
		}
	}
	/*
	puts("a");
	rep(i,t+1){
		
		printf("i=%d\n",i);
		reps(j,1,h+1){
			reps(k,1,w+1)printf("%.4lf ",dp[i][j][k]);puts("");
		}puts("");
	}
	*/
	double ans = 0;
	
	reps(i,1,w+1){
		ans = max(ans, dp[t][1][i]);
	}
	
	printf("%.9lf\n",ans);
}


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

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

using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==1000 ||n==2000 || n==3000 ||n==4000 ||n==5000||n==6000||n==7000||n==8000||n==9000||n==10000)
        cout<<0<<endl;
    else if(n<1000)
        cout<<1000-n<<endl;
    else if(n>1000 && n<2000)
    {
        cout<<2000-n<<endl;
    }
     else if(n>2000 && n< 3000)
    {
        cout<<3000-n<<endl;
    }
     else if(n>3000 && n< 4000)
    {
        cout<<4000-n<<endl;
    }
     else if(n>4000 && n< 5000)
    {
        cout<<5000-n<<endl;
    }
     else if(n>5000 && n< 6000)
    {
        cout<<6000-n<<endl;
    }
     else if(n>6000 && n< 7000)
    {
        cout<<7000-n<<endl;
    }
     else if(n>7000 && n< 8000)
    {
        cout<<8000-n<<endl;
    }
     else if(n>8000 && n< 9000)
    {
        cout<<9000-n<<endl;
    }
     else if(n>9000 && n< 10000)
    {
        cout<<10000-n<<endl;
    }















    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main(){
  int A, B;
  cin>>A>>B;
  int coin = 0;
  if(A>=B){
    coin+=A;
    A-=1;
  }
  else{
    coin+=B;
    B-=1;
  }
  if(A>=B){
    coin+=A;
    A-=1;
  }
  else{
    coin+=B;
    B-=1;
  }
  cout<<coin;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
std::vector<int> ps;
void set_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return ;
	}
	ps.push_back(n);
}
bool is_prime(int n){
	if(n<2)return false;
	for(int i=0;i<ps.size();i++){
		int a=ps[i];
		if(a*a>n)return true;
		if(n%a==0)return false;
	}
	return true;
}

int main(){
	for(int i=2;i<10000;i++){
		set_prime(i);
	}
	int n,ans=0;
	scanf("%d",&n);
	while(n--){
		int a;
		scanf("%d",&a);
		ans+=is_prime(a)?1:0;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 2748
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <queue>

using namespace std;

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

const ll MOD = 1000000007;
const ll fuel = (ll) 1e14;
const ll inf = (ll) 1e18;

ll L;

vector<ll> dijkstraDistOnly(const vector<set<Pii> > &edge, int start) {
  vector<ll> length(edge.size(), inf);
  vector<bool> visited(edge.size(), false);
  priority_queue<pair<ll, int> > que;
  que.push(pair<ll, int>(0, start)); // negative distance
  length[start] = 0;
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    for (auto x : edge[now.second]) {
      if (visited[x.first]) continue;
      ll d = -now.first + x.second;
      if (d % fuel > L) {
        d = (d / fuel * fuel) + fuel + x.second;
      }
      if (d < length[x.first]) {
        length[x.first] = d;
        que.push(pair<ll, int>(-d, x.first));
      }
    }
  }
  return length;
}

vector<vector<ll> > dijkstraAll(const vector<set<Pii> > &edge) {
  int n = edge.size();
  vector<vector<ll> > d;
  for (int i = 0; i < n; i++) {
    d.push_back(dijkstraDistOnly(edge, i));
  }
  return d;
}

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

  int n, m;
  cin >> n >> m >> L;
  vector<set<Pii> > edge;
  for (int i = 0; i < n; i++) edge.push_back(set<Pii>());
  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c > L) continue;
    edge[a-1].insert(Pii(b-1, c)); // zero index
    edge[b-1].insert(Pii(a-1, c)); // zero index
  }
  int q;
  cin >> q;
  vector<int> s(q), t(q);
  for (int i = 0; i < q; i++) cin >> s[i] >> t[i];
  for (int i = 0; i < q; i++) {
    s[i]--;
    t[i]--;
  }

  auto distanceMatrix = dijkstraAll(edge);

  for (int i = 0; i < q; i++) {
    if (distanceMatrix[s[i]][t[i]] >= inf) cout << -1 << endl;
    else cout << (distanceMatrix[s[i]][t[i]] / fuel) << endl;
  }

  return 0;
}


Measured memory_bytes: 6932
N,M  = [int(_n) for _n in input().split()]
H = [int(_n) for _n in input().split()]
li = [[] for _ in range(N)]
for i in range(M):
    A, B = [int(_n)-1 for _n in input().split()]
    # print(A,B)
    li[A].append(B)
    li[B].append(A)
res = 0
# print(li)
for i in range(N):
    h = H[i]
    flag = True
    for l in li[i]:
        if H[l] >= h:
            # print(i,l)
            flag = False
            break
    if not flag:
        continue
    res+=1
    # print(i)
print(res)

Measured memory_bytes: 92368
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var inputs = Console.ReadLine().Split(' ');
        var A = new long[N];
        long min = long.MaxValue;
        long minIndex = 0;
        for (int i = 0; i < N; i++)
        {
            A[i] = long.Parse(inputs[i]);
            if (min > A[i])
            {
                min = A[i];
                minIndex = i;
            }
        }

        while (true)
        {
            int zeroCount = 0;
            for (int i = 0; i < N; i++)
            {
                if (minIndex != i)
                {
                    A[i] %= min;
                }

                if (A[i] > 0)
                {
                    if (min > A[i])
                    {
                        min = A[i];
                        minIndex = i;
                    }
                }
                else
                {
                    zeroCount++;
                }
            }
            if (zeroCount == N - 1)
            {
                break;
            }
        }

        Console.WriteLine(min);

    }
}



Measured memory_bytes: 20448