akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = 1;
vector<ll> A, B, C;
int n, k;

int main(void) {
    cin >> n >> k;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (a>=0)A.pb(a);
        else {
            B.pb(-a);
            C.pb(a);
        }
    }
    sort(all(A), greater<ll>());
    sort(all(B), greater<ll>());
    sort(all(C), greater<ll>());

    int an = sz(A), bn = sz(B), cn = sz(C);

    int ac = 0, bc = 0;
    vector<ll> ax, bx;
    while (ac+bc<k) {
        ll amx = -LINF, bmx = -LINF;
        if (ac<an) amx = A[ac];
        if (bc<bn) bmx = B[bc];
        if (amx>=bmx) {
            ax.pb(amx);
            ac++;
        } else {
            bx.pb(bmx);
            bc++;
        }
    }

    // 両方から選べる
    if (bc%2==1 && ac<an && bc<bn && sz(ax)>0 && sz(bx)>0) {
        ll nexta = A[ac], nextb = B[bc];
        if (ax[sz(ax)-1]*nexta>=bx[sz(bx)-1]*nextb) {
            ax.pb(nexta);
            bx.pop_back();
            ac++;
            bc--;
        } else {
            bx.pb(nextb);
            ax.pop_back();
            bc++;
            ac--;
        }
    // 非負をすて、負をとるしかない
    } else if (bc%2==1 && sz(ax)>0 && bc<bn && (ac==an || sz(bx)==0)) {
        ax.pop_back();
        bx.pb(B[bc]);
        ac--;
        bc++;
    // 負をすて、非負を取るしかない
    } else if (bc%2==1 && sz(bx)>0 && ac<an && (sz(ax)==0 || bc==bn)) {
        bx.pop_back();
        ax.pb(A[ac]);
        ac++;
        bc--;
    }

    //処理後に正にできたら、選択したものすべての積
    if (bc%2==0) {
        rep(i, 0, sz(ax)) {
            ans *= ax[i];
            ans %= MOD;
            if (ans<0) ans += MOD;
        }
        rep(i, 0, sz(bx)) {
            ans *= bx[i];
            ans %= MOD;
            if (ans<0) ans += MOD;
        }

    // 負になってしまった
    } else {
        if (k==n) { // kとnが等しい時はすべて取るしかない
            rep(i, 0, sz(A)) {
                ans *= A[i];
                ans %= MOD;
                if (ans<0) ans += MOD;
            }
            rep(i, 0, sz(C)) {
                ans *= C[i];
                ans %= MOD;
                if (ans<0) ans += MOD;
            }
        } else { //k≠nであれば、負から絶対値が小さい順に選ぶ
            rep(i, 0, k) {
                ans *= C[i];
                ans %= MOD;
                if (ans<0) ans += MOD;
            }

        }

    }

    ans %= MOD;
    if (ans<0) ans += MOD;

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



Measured memory_bytes: 9476
k, t = map(int, input().split())
a = list(map(int, input().split()))

maxA = max(a)
# print(a)
t = a.index(maxA)
# 最大を置いて，間に挟んでいく
# 間に挟める個数はk - a[t]個ある
# a[t] - 1個はdefault
ans = max(a[t] - 1 - (k - a[t]), 0)
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, h, w; cin>>n>>h>>w;
    int ans=0;
    while(n--){
        int a, b; cin>>a>>b;
        ans += (a >= h && b >= w);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n, x, t = mi()
    tmp = 0
    ans = 0
    for i in range(10000):
        ans += t
        tmp += x
        if n <= tmp:
            break
    print(ans)


main()


Measured memory_bytes: 10004
# coding:utf-8
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if (b-a > k) or (c-a > k) or (d-a >k) or(e-a > k) or(c-b >k) or (d-b >k) or (e-b >k) or (d-c > k) or (e-c >k) or (e-d > k):
    print(':(')
else:
    print('Yay!')


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

const ll mod = 1000000007 ;

using namespace std ;

int main()
{
	string s;
	cin>>s;
	if(s=="SSS")
		cout<<0;
	if(s=="SSR")
		cout<<1;
	if(s=="SRS")
		cout<<1;
	if(s=="RSS")
		cout<<1;
	if(s=="RRR")
		cout<<3;
	if(s=="RRS")
		cout<<2;
	if(s=="RSR")
		cout<<1;
	if(s=="SRR")
		cout<<2;


}


Measured memory_bytes: 3632
using System;
using System.Linq;

class Atcoder86
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        int[] calc = new int[3];
        calc[0] = a + b;
        calc[1] = a - b;
        calc[2] = a * b;

        Console.WriteLine(calc.Max());
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		// cin.ignore(); must be there when using getline(cin, s)
		ll n,w;
		cin>>n>>w;
		ll wt[n];
		ll v[n];
		for(ll i=0;i<n;i++)
		{
			cin>>wt[i]>>v[i];
		}
		ll dp[n+1][w+1];
		for(ll i=0;i<=n;i++)
		{
			for(ll j=0;j<=w;j++)
			{
				if(i==0 || j==0)
					dp[i][j]=0;
				else if(wt[i-1]<=j)
				{
					dp[i][j]=max(dp[i-1][j-wt[i-1]]+v[i-1],dp[i-1][j]);
				}
				else
				{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
		cout<<dp[n][w];
		return 0;
	}


Measured memory_bytes: 79232
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, k, ans = 1;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    if (ans + k < 2 * ans)
      ans += k;
    else
      ans *= 2;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int i, j, k;
    int x, y[m];
    int ans=0;
    for(i=0; i<m; i++){
        y[i] = 0;
    }
    for(i=0; i<n; i++){
        scanf("%d",&k);
        for(j=0; j<k; j++){
            scanf("%d",&x);
            y[x-1]++;
        }
    }
    for(i=0; i<m; i++){
        if(y[i] == n){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

using ll = long long;


string Bits(ll x, int len) {
    if (x == 0) return string(len, '0');

    string s;
    while (x) {
        if (x % 2 == 0) s = "0" + s;
        else s = "1" + s;
        x /= 2;
    }
    if (s.size() < len) s = string(len - s.size(), '0') + s;
    return s;
}

ll n, k;
int len;
vector<ll> a;
string K;
vector<string> A;
ll dp[100][2];

ll Res(int idx, int f) {
    if (idx == len) return 0;
    if (dp[idx][f] != -1) return dp[idx][f];

    ll res = 0;
    if (f == 0) { // 自由に選べない
        int b = (int)(K[idx] - '0');
        if (b == 0) {
            ll sum = 0;
            for (int i = 0; i < n; ++i)
                if (A[i][idx] == '1') ++sum;
            res = sum * (1ll << (len - idx - 1));
            res += Res(idx + 1, 0);
        }
        else {
            ll sum = 0;
            for (int i = 0; i < n; ++i)
                if (A[i][idx] == '0') ++sum;
            res = sum * (1ll << (len - idx - 1));
            res += Res(idx + 1, 0);

            ll sum0 = 0;
            for (int i = 0; i < n; ++i)
                if (A[i][idx] == '1') ++sum0;
            res = max(res, sum0 * (1ll << (len - idx - 1)) + Res(idx + 1, 1));
        }
    }
    else { // 自由に選べる
        ll sum0 = 0, sum1 = 0;
        for (int i = 0; i < n; ++i) {
            if (A[i][idx] == '0') ++sum1;
            else ++sum0;
        }
        res = max(res, Res(idx + 1, f) + sum0 * (1ll << (len - idx - 1)));
        res = max(res, Res(idx + 1, f) + sum1 * (1ll << (len - idx - 1)));
    }
    return dp[idx][f] = res;
}

ll Solve() {
    cin >> n >> k;
    a.resize(n);

    len = log2(k) + 1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        len = max(len, (int)log2(a[i]) + 1);
    }

    K = Bits(k, len);
    A.resize(n);
    for (int i = 0; i < n; ++i) A[i] = Bits(a[i], len);

    // cout << "len = " << len << " " << log2(k) + 1 << endl;
    // cout << "K = " << K << endl;
    // for (int i = 0; i < n; ++i) cout << a[i] << " " << A[i] << endl;

    for (int i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1;
    return Res(0, 0);
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 10624
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int n,k,c; cin >>n >>k >>c;
  string s; cin >>s;
  vector<int> v(n,0);
  int cnt=k;
  rep(_i,n){
    int i=n-1-_i;
    if(df)print(s[i]);
    if(s[i]=='o'){
      v[i]=cnt;
      cnt--;
      _i+=c;
    }
  }
  if(df)print(v);
  vector<int> ans;
  cnt=0;
  rep(i,n){
    if(s[i]=='o'){
      cnt++;
      if(v[i]==cnt) ans.push_back(i+1);
      i+=c;
    }
  }
  for(int x:ans) print(x);
}


Measured memory_bytes: 5192
A,B,C,D = map(int,input().split())
def dev_num(X):
  m = A//X if A%X == 0 else A//X + 1
  n = B//X
  return n-m+1
def gcd(x,y):
  if x>y:
    x,y=y,x
  if y%x == 0:
    return x
  else:
    return gcd(y%x,x)
def lcm(x,y):
  return x*y//gcd(x,y)

print(B-A+1 - dev_num(C) - dev_num(D) + dev_num(lcm(C,D)))  

Measured memory_bytes: 3064
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

int main() {
	ll N;
	cin >> N;
	auto dist = make_vec_nd((ll)0, N, N);
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < N; j++) {
			cin >> dist[i][j];
		}
	}
	unordered_set<ll> unused;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (dist[i][j] > dist[i][k] + dist[k][j]) {
					cout << -1 << endl;
					return 0;
				}
				if (dist[i][j] == dist[i][k] + dist[k][j] 
					&& i != k && k != j && i < j) {
					unused.insert((((ll)i) << 32) | ((ll)j));
				}
			}
		}
	}
	ll ans = 0;
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < N; j++) {
			if (i < j && unused.find((((ll)i) << 32) | ((ll)j)) == unused.end()) {
				ans += dist[i][j];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 2740
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n, m;
	cin >> n >> m;
	string s;
	char t[100][10000];
	int i, j; int now=0;
	for (i = 0; i < m; i++) {
		cin >> s;
		for (j = 0; j < n; j++) {
			t[i][j] = s[j];
			if (s[j] == 'W')now++;
		}
	}
	int wes[10000];
	for (i = 0; i < n; i++) {
		int sum = 0;
		for (j = 0; j < m; j++) {
			if (t[j][i] == 'W')sum++;
		}
		wes[i] = 2*sum-m;
	}
	int ma = now;
	int check=0;
	for (i = 0; i < n; i++) {
		now += wes[i];
		if (now > ma) {
			ma = now; check = i + 1;
		}
	}
	cout << check << " " << check + 1 << endl;
	return 0;
}



Measured memory_bytes: 4260
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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

#define P (1'000'000'007)

signed main() {
    capi(n);

    int ans = 0;
    int prev = 0;

    cin >> prev;
    rep(i, n - 1) {
        capi(a);

        ans += max(0ll, prev - a);
        prev = max(prev, a);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    ll t=N;
    ll h=0;
    while(t>0){
        h+=t%10;
        t/=10;
    }
    cout<<(N%h==0?YES:NO)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}


Measured memory_bytes: 256
#include <stdio.h>

int
main()
{
	int table[101][101] = {0};
	int r, c;
	int x, y;

	scanf("%d %d", &r, &c);
	for (y = 0; y < r; y++)
	{
		for (x = 0; x < c; x++)
		{
			scanf("%d", &table[y][x]);
			table[r][x] += table[y][x];
			table[y][c] += table[y][x];
			table[r][c] += table[y][x];
		}
	}

	for (y = 0; y <= r; y++)
	{
		for (x = 0; x <= c; x++)
		{
			if (x != 0)
			{
				printf(" ");
			}
			printf("%d", table[y][x]);
		}
		printf("\n");
	}

	return 0;
}

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

int S;

void input() {
    cin >> S;
}

int main() {
    input();
    int hour = S / 3600;
    int min = (S - 3600 * hour) / 60;
    int sec = S - 3600 * hour - 60 * min;
    

    cout << hour << ":"<< min << ":" << sec << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

bool p[5001][5001];

int main(){
  
  int n;
  while(cin >> n, n){
    memset(p, false, sizeof(p));
    vector <iP> pos(n);
    for(int i = 0; i < n; i++){
      cin >> pos[i].fr >> pos[i].sc;
      p[pos[i].fr][pos[i].sc] = true;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j) continue;
        int dx = pos[i].fr - pos[j].fr, dy = pos[i].sc - pos[j].sc;
        if(0 < pos[i].fr - dy && pos[i].fr - dy < 5001 && 
           0 < pos[j].fr - dy && pos[j].fr - dy < 5001 &&
           0 < pos[i].sc + dx && pos[i].sc + dx < 5001 && 
           0 < pos[j].sc + dx && pos[j].sc + dx < 5001){
          if(p[pos[i].fr - dy][pos[i].sc + dx] &&
             p[pos[j].fr - dy][pos[j].sc + dx])
            ans = max(dx * dx + dy * dy, ans);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 25648
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


x,a,b = map(int,input().split())
if a >= b:
    print("delicious")
elif x + a >= b:
    print("safe")
else:
    print("dangerous")


Measured memory_bytes: 3316
// fahadmd16(IIEST Shibpur)

#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll                          long long
#define pb                          push_back
#define pf                          push_front
#define eb                          emplace_back
#define mp                          make_pair
#define ff                          first
#define ss                          second
#define db                          double
#define pll                         pair<ll, ll>
#define ALL(a)                      (a).begin(),(a).end()
#define endl                        "\n"

#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define forab(i, a, b) for(ll i = a; i < b; i++)
#define eps 1e-10

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)


#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;


const ll sz = 2e5 + 3;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9;


typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;

ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}

void solver() {
    ll n, k; cin >> n >> k;
    ll a[n + 1];
    forn(i, n + 1)a[i] = i;
    VL pref(n + 2), suff(n + 2);
    pref[0] = 0;
    forn1(i, n + 2)pref[i] = pref[i - 1] + a[i - 1];
    suff[n + 1] = 0;
    ford(i, n + 1)suff[i] = suff[i + 1] + a[i];

    // trace(pref);
    // trace(suff);
    ll ans = 0;
    forab(i, k, n + 2) {
        ll min = pref[i] - pref[0];
        ll max = suff[n + 1 - i] - suff[n + 1];
        // trace3(min, max, i);
        ans += (max - min + 1);
        ans %= mod;
    }
    cout << ans << endl;
}


int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    IOS;
    ll T = 1; //cin >> T;
    forn1(i, T + 1) {
        clock_t z = clock();
        solver();
        debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
    }
    return 0;
}


Measured memory_bytes: 7948
import numpy as np

h,w,k = map(int,input().split())
lines = [input() for v in range(h)]
ans = 0

for ir in range(2**h):
    for ic in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (ir>>i) & 1 == 0 and (ic>>j) & 1 == 0:
                    if lines[i][j]  == '#':
                      cnt += 1
        if cnt == k:
            ans += 1

print(ans)


Measured memory_bytes: 27176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
#define MAXN 5000
#define LL long long
int n,ans;
char s[MAXN+5];
int dp[MAXN+5][MAXN+5];
LL read(){
	LL x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}
int main()
{
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
		if(s[i]==s[j])dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=0;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
		ans=max(ans,min(dp[i][j],j-i));
	printf("%d",ans);
}

Measured memory_bytes: 96768
#include<stdio.h>

int main(){
    int a,x=0;
    scanf("%d", &a);
    for(int i=1; i<=9 ; i++){
        if(a%i==0){
            if(a/i>=1 && a/i<=9){
                x=1;
                break;
            }
        }
    }
    if (x==1)
    printf("Yes\n");
    else
    printf("No\n");;
    return 0;
}

Measured memory_bytes: 1660
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;

int main()
{
    int n;
    string T;
    cin >> n;
    vector<string>s(n);
    vector<int>t(n);
    rep(i,n){
        cin>>s[i];
        cin>>t[i];
    }
    cin>>T;
    ll count=0,ans=0;
    rep(i,n){
        if(T==s[i])break;
        count++;
    }
    rep(i,n){
        if(i>count)ans+=t[i];
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	NR := sc.nextInts()
	N := NR[0]
	R := NR[1]
	if N >= 10 {
		fmt.Println(R)
	} else {
		sub := 100 * (10 - N)
		fmt.Println(R + sub)
	}
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
import java.util.Scanner;

class A {
    public static void main(String...args) {
        final Scanner sc = new Scanner(System.in);
        final char[] S = sc.next().toCharArray();
        long ans = 0;
        for(int i = 0, b = 0; i < S.length; i++)
            if(S[i] == 'B')
                b++;
            else
                ans += b;
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String...args) {
        A.main();
    }
}


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

long long int a[100000000];
long long arr[100000000];
int main(){
	int n;
//	scanf("%d",&n);
	cin>>n; 
	for(int i=1;i<=n;i++){
//		scanf("%d",&a[i]);
		cin>>a[i];
	}
	long long sum=0;
	for(int i=1;i<=n;i++){
		if(i%2!=0){
			sum+=a[i];
		}else{
			sum-=a[i];
		} 
	}
	arr[1]=sum/2;
//	printf("%d\n",sum);
	for(int i=2;i<=n;i++){
		arr[i]=a[i-1]-arr[i-1];
	}
	for(int i=1;i<=n;i++){
		if(i==1){
			cout<<2*arr[i];
//			printf("%d",2*arr[i]);
		}else{		
			cout<<" "<<2*arr[i];
//			printf(" %d",2*arr[i]);
		}
	}
	return 0;
} 

Measured memory_bytes: 4096
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
const ll MOD = 1000000007;

bool isin(int n, vector<int> a){
	int sz = a.size();
  	rep(i,sz){
		if(n == a[i]){return true;} 
    }
	return false;
}

void Main()
{
	int N, M;
  	cin >> N >> M;
  	vector<int> a;
  	if(M==0) {
    	a = vector<int>(2,0);   
    }
  	else{
  		a = vector<int>(M);
  		rep(i,M) cin >> a[i];
    }
  	sort(a.begin(),a.end());
  	
  	vector<ll> dp(N+5);
  	dp[0] = 1;
  	int temp = 0;
  	if(1 == a[temp]) {
      	dp[1] = 0;
    	temp++;
    }
  	else dp[1] = 1;
  
  	rep(i,N-1){
		if(i+2 == a[temp]){
          dp[i+2] = 0;
          temp++;
        }
  		else {
          dp[i+2] = (dp[i+1] + dp[i])%MOD;
        }
    }
  	//rep(i,N+1) {
	//	cout << i << ": " << dp[i] << ": " << isin(i,a) << endl;
    //}
  	cout << dp[N] << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[0].size()){ cout << m[i][j] << ","; } cout << endl; }}

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

#define M 3300
signed main(){

    int N, K; cin >> N >> K;
    int mod = 1000000007;

    mat dp(N + 1, vec(M + 1, 0));
    if(K >= N) dp[N][1] = 1;
    dp[N][0] = K + 1 - dp[N][1];
    IFOR(i, 1, N){
        int d = K - i;
        if(d > 0) REP(j, M + 1){
            dp[i][j] += d * dp[i + 1][j];
            dp[i][j] %= mod;
        }
        REP(a, min(K, i) + 1){
            REP(j, M + 1){
                int s = j + (a + j) / i;
                if(s <= M){
                    dp[i][s] += dp[i + 1][j];
                    dp[i][s] %= mod;
                }
            }
        }
    }
    //debug(dp);
    
    int ans = (K * (K + 1) / 2 * N * modpow(K + 1, N - 1, mod)) % mod;;
    //cout << ans << endl;
    REP(i, M + 1){
        ans -= i * dp[1][i];
        ans = (ans % mod + mod) % mod; 
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	map<int,int> m;
	m[a]++;
	m[b]++;
	m[c]++;
	m[d]++;
	string s ="1974";
	for(auto c:s){
		int i = c-'0';
		if(m[i]!=1){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


Measured memory_bytes: 256
using System;
public class Class1
{
	public static void Main()
	{
		string dataSet =Console.ReadLine();
		string[] data=dataSet.Split();
		int n=int.Parse(data[0]);
		int m=int.Parse(data[1]);
		int[,] rc=new int[n,m];
		int[] vector=new int[m];
		int[] answer=new int[n];
		
		for (int i =0; i < n; i++)
		{
			string matrixSet =Console.ReadLine();
			string[] matrix=matrixSet.Split();
			
			for(int j =0;j<m;j++)
			{
				rc[i,j]=int.Parse(matrix[j]);
							}				
		}
	
		for(int k=0;k<m;k++)
		{
			string vectorSet=Console.ReadLine();		    
			vector[k]=int.Parse(vectorSet);
		}
		for(int l=0;l<n;l++)
		{
			for(int p=0;p<m;p++)
			{
				answer[l]+=rc[l,p]*vector[p];
			
			}
			Console.WriteLine(answer[l]);
		}
		
		
	}
		
}

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  string S; cin >> S;
  vector<vector<int> > alp(N+1, vector<int>(26, 0));
  REP(i, N){
    REP(j, 26){
      alp[i+1][j] = alp[i][j];
    }
    alp[i+1][(S[i] - 'a')]++;
  }
  int ans = 0;
  for(int i = 1; i < N; i++){
    int cnt = 0;
    REP(j, 26){
      if(alp[i][j] > 0 && alp[N][j] > alp[i][j]) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

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

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    rep(i,n) {
        int a; cin>>a;
        if (a%2) continue;
        if (a%3!=0 && a%5!=0) {
            cout << "DENIED" << '\n';
            return 0;
        }
    }
    cout << "APPROVED" << '\n';
    return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int n;
    cin >> n;
    auto counter = map<int, int>();
    auto maxval = 0;
    for (auto i = 0; i < n; ++i) {
        auto x = 0;
        cin >> x;
        counter[x]++;
        maxval = max(maxval, x);
    }

    auto divisible = map<int, int>();
    for (auto [a_i, cnt] : counter) {
        for (auto x = 2 * a_i; x <= maxval; x += a_i) {
            auto itr = counter.find(x);
            if (itr == counter.end())
                continue;
            divisible[x]++;
        }
        if (cnt >= 2) {
            divisible[a_i]++;
        }
    }

    for (auto [a_i, d] : divisible) {
        counter.erase(a_i);
    }

    cout << counter.size() << endl;
    return 0;
}


Measured memory_bytes: 22376
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int H, W;
    while (cin >> H >> W) {
        if (H == 0 && W == 0) {
            break;
        }

        for (int j = 0; j < W; j++) {
            cout << "#";
        }
        cout<< endl;

        for (int i = 1 ; i < H-1; i++) {
            cout << "#";
            for (int j = 0; j < W-2; j++) {
                cout << ".";
            }
            cout << "#";
            cout << endl;
        }

        for (int j = 0; j < W; j++) {
            cout << "#";
        }
        cout << endl;

        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int L, N; cin >> L >> N;
    vec X(N); readv(X);

    vec sumL(N + 1, 0), sumR(N + 1, 0);
    REP(i, N) sumL[i + 1] = sumL[i] + X[i];
    IREP(i, N) sumR[i] = sumR[i + 1] + L - X[i]; 

    int ans = 0;
    REP(i, N){
        if((N - 1 - i) % 2 == 0){
            int m = i + (N - 1 - i) / 2;
            int tmp = 2 * (sumL[m + 1] - sumL[i + 1 - 1] + sumR[m + 1]) - X[m];
            ans = max(ans, tmp);
        }else{
            int m = i + (N - 1 - i) / 2;
            int tmp = 2 * (sumL[m + 1] - sumL[i + 1 - 1] + sumR[m + 1]) - (L - X[m + 1]);
            ans = max(ans, tmp);
        }

        if(i % 2 == 0){
            int m = i - i / 2;
            int tmp = 2 * (sumR[m] - sumR[i + 1] + sumL[m - 1 + 1]) - (L - X[m]);
            ans = max(ans, tmp);
        }else{
            int m = i - i / 2;
            int tmp = 2 * (sumR[m] - sumR[i + 1] + sumL[m - 1 + 1]) - X[m - 1];
            ans = max(ans, tmp);
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 4992
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
        int max = -BIG_NUM, min = BIG_NUM;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            for(int loop = 0; loop < N; loop++){
                int tmp = Integer.parseInt(br.readLine());
                max = Math.max(max, tmp - min);
                min = Math.min(min, tmp);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        System.out.println(max);
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c;cin>>a>>b>>c;
    cout<<a*b/2;
    return 0;
}

Measured memory_bytes: 3640
import math
s = input("")
s = s.split(" ")
A = int(s[0])
B = int(s[1])
H = int(s[2])
M = int(s[3])
k = 360*M/60-(360*H/12+360*M/12/60)
k = abs(k)
j = math.cos(k*3.14159265359*2/360)
c = math.sqrt(A*A+B*B-2*A*B*j)
print(c)

Measured memory_bytes: 9404
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <set>
#define ll long long
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 2e5;

int n;
int fa[N + 1], f[N + 1];
struct Node {
	int	num, val0, val1;
	ll	val;
	inline bool operator <(Node a) const
	{
		if (1ll * val0 * a.val1 == 1ll * val1 * a.val0)
			return num < a.num;
		return 1ll * val0 * a.val1 > 1ll * val1 * a.val0;
	}
} node[N + 1];
set<Node> s;

inline int getfa(int x)
{
	if (f[x] == x)
		return x;
	f[x] = getfa(f[x]);
	return f[x];
}
inline void solve()
{
	for (int i = 1; i <= n; i++)
		f[i] = i;
	while (!s.empty()) {
		Node now = *s.begin();
		if (now.num == 1) {
			s.erase(now);
			continue;
		}
		Node faa = node[getfa(fa[now.num])];
		s.erase(now);
		s.erase(faa);
		f[now.num] = faa.num;
		faa.val += now.val;
		faa.val += 1ll * now.val0 * faa.val1;
		faa.val0 += now.val0;
		faa.val1 += now.val1;
		node[now.num] = now;
		node[faa.num] = faa;
		s.insert(faa);
	}
	return;
}
int main()
{
	n = read();
	for (int i = 2; i <= n; i++)
		fa[i] = read();
	for (int i = 1; i <= n; i++) {
		node[i].num = i;
		node[i].val = 0;
		int x = read();
		if (x) {
			node[i].val0 = 0;
			node[i].val1 = 1;
		} else {
			node[i].val0 = 1;
			node[i].val1 = 0;
		}
		s.insert(node[i]);
	}

	solve();

	printf("%lld\n", node[1].val);
	return 0;
}


Measured memory_bytes: 21888
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;
    char ch;
    cin>>ch;
    ch++;
    cout<<ch<<endl;

    return 0;
}

Measured memory_bytes: 256
import bisect
INF = 1e12
A, B, Q = map(int, input().split())
s_list = [-INF]
t_list = [-INF]
for i in range(A):
    s_list.append(int(input()))
for i in range(B):
    t_list.append(int(input()))
x_list = [int(input()) for i in range(Q)]
s_list.append(INF)
t_list.append(INF)

def calc_min_dist(x):
    s_index = bisect.bisect_right(s_list, x)
    t_index = bisect.bisect_right(t_list, x)
    tmp_s_right = s_list[s_index]
    tmp_s_left = s_list[s_index-1]
    tmp_t_right = t_list[t_index]
    # print("!!!", tmp_s_right, tmp_t_right)
    tmp_t_left = t_list[t_index-1]
    return min(abs(tmp_s_right-x)+abs(tmp_t_right-tmp_s_right),abs(tmp_s_right-x)+abs(tmp_t_left-tmp_s_right),
    abs(tmp_s_left-x)+abs(tmp_t_right-tmp_s_left),abs(tmp_s_left-x)+abs(tmp_t_left-tmp_s_left),
    abs(tmp_t_left-x)+abs(tmp_s_right-tmp_t_left), abs(tmp_t_left-x)+abs(tmp_s_left-tmp_t_left),
    abs(tmp_t_right-x)+abs(tmp_s_right-tmp_t_right), abs(tmp_t_right-x)+abs(tmp_s_left-tmp_t_right))

for x in x_list:
    print(calc_min_dist(x))


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

class F
{
	struct P
	{
		public double x, y;
		public string d;
	}

	struct V
	{
		public double x;
		public int d;
	}

	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var ps = new int[n].Select(_ => Console.ReadLine().Split()).Select(x => new P { x = double.Parse(x[0]), y = double.Parse(x[1]), d = x[2] }).ToArray();

		var rs = ps.Where(x => x.d == "R").ToArray();
		var ls = ps.Where(x => x.d == "L").ToArray();
		var us = ps.Where(x => x.d == "U").ToArray();
		var ds = ps.Where(x => x.d == "D").ToArray();

		var xs = new List<V>();
		Edge(xs, rs, p => p.x, 1);
		Edge(xs, us.Concat(ds).ToArray(), p => p.x, 0);
		Edge(xs, ls, p => p.x, -1);

		var ys = new List<V>();
		Edge(ys, us, p => p.y, 1);
		Edge(ys, rs.Concat(ls).ToArray(), p => p.y, 0);
		Edge(ys, ds, p => p.y, -1);

		var tx = GetTurnTimes(xs);
		var ty = GetTurnTimes(ys);

		Func<V, double, double> f = (v, t) => v.x + v.d * t;
		Func<double, double> rect = t => (xs.Max(v => f(v, t)) - xs.Min(v => f(v, t))) * (ys.Max(v => f(v, t)) - ys.Min(v => f(v, t)));
		Console.WriteLine(new[] { 0.0 }.Concat(tx).Concat(ty).Min(t => rect(t)));
	}

	static void Edge(List<V> vs, P[] ps, Func<P, double> toValue, int d)
	{
		if (ps.Length == 1)
		{
			vs.Add(new V { x = toValue(ps[0]), d = d });
		}
		else if (ps.Length > 1)
		{
			vs.Add(new V { x = ps.Max(toValue), d = d });
			vs.Add(new V { x = ps.Min(toValue), d = d });
		}
	}

	static double[] GetTurnTimes(List<V> vs) => vs.SelectMany(u => vs.Where(v => u.d != v.d).Select(v => (u.x - v.x) / (v.d - u.d))).Where(t => t >= 0).ToArray();
}


Measured memory_bytes: 33400
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
const int MaxN = 1000;
const int x = 400;
using namespace std;
int a[MaxN + 5][MaxN + 5];
int H , W , h , w;

int main()
{
	while(~scanf("%d%d%d%d" , &H , &W , &h , &w)){
		long long ans = 0;
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(i % h == h - 1 && j % w == w - 1) a[i][j] = -x * (h * w - 1) - 1;
				else a[i][j] = x;
				ans += a[i][j];
			}
		}
		if(ans < 0) printf("No\n");
		else {
			printf("Yes\n");
			for(int i = 0;i < H;i++){
				for(int j = 0;j < W;j++){
					if(j != W - 1) printf("%d " , a[i][j]);
					else printf("%d\n" , a[i][j]);
				}
			}
		}
	}
}

Measured memory_bytes: 3200
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int x1,x2,x3;
	scanf("%d%d%d",&x1,&x2,&x3);
	if (x1==x2) printf("%d\n",x3);
	else if (x1==x3) printf("%d\n",x2);
	else printf("%d\n",x1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int dp[1010][1010];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int i=0;i<1001;i++){
		for(int j=0;j<1001;j++){
			dp[i][j]=1e9;
		}
	}
	int n,m; cin >> n >> m;
	vector<int> a(n),b(m);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int j=0;j<m;j++){
		cin >> b[j];
	}
	dp[0][0]=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			if(dp[i][j]==1e9)continue;
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j<n){
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+b[i]*a[j]);
			}
		}
	}
	cout << dp[m][n] << endl;
}


Measured memory_bytes: 7152
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
  let (a, b) = read_touple::<i64>();
  let mut ans = -1;
  for x in 1..10_001 {
    let i = (8 * x) / 100;
    let j = (10 * x) / 100;
    if (i == a) && (j == b) {
       ans = x;
       break
    }
  }

  println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int q = 0;
    for(int i = 0; i < 3; ++i){
        if(s[i] == s[i+1])q = 1;
    }
    if(q){
        cout <<"Bad\n";
    }
    else {
        cout <<"Good\n";
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] d = new int[N];
        int sum = 0;
        
        for(int i = 0; i < N; i++){
            d[i] = sc.nextInt();
        }
        
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j < N; j++){
                sum += d[i] * d[j];
            }
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())


n = readi()
if n % 2 == 0:
    print((n // 2) / n)
else:
    print(((n + 1) // 2) / n)

Measured memory_bytes: 6864