akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

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

	vector<pair<int32_t, int32_t> > A(N);
	for (int32_t i = 0; i < N; i++) {
		scanf("%d", &A[i].first);
		A[i].second = i + 1;
	}
	sort(A.begin(), A.end());
	for (int32_t i = 0; i < N; i++) {
		printf("%d", A[i].second);
		if (i < N - 1)
			printf(" ");
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(void){
  const int MARK = 4;
  const int NUM = 13;
  int n, i, j, num;
  int card[4][13] = {0};
  char mark;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s %d", &mark, &num);
    if(mark == 'S')
      card[0][num - 1] = 1;
    else if(mark == 'H')
      card[1][num - 1] = 1;
    else if(mark == 'C')
      card[2][num - 1] = 1;
    else
      card[3][num - 1] = 1;
  }
  
  for(i = 0; i < MARK; i++){
    for(j = 0; j < NUM; j++){
      if(!card[i][j]){
	if(i == 0)
	  printf("S %d\n", j + 1);
	else if(i == 1)
	  printf("H %d\n", j + 1);
	else if(i == 2)
	  printf("C %d\n", j + 1);
	else
	  printf("D %d\n", j + 1);
      }
    }
  }
  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int N, K;
const int MAX_N=100005;
int h[MAX_N];
int dp[MAX_N];

void solve() {
    cin >> N >> K;
    rep(i, N) cin >> h[i];
    rep(i, MAX_N) dp[i] = INF_N;

    dp[0] = 0;
    rep(i, N){
        Rep1(j, 0, K){
            if(i+j >= N) break;
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }

    cout << dp[N-1] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main(void) {
  string str;
  cin >> str;
  
  for(int i = 0;i < str.length();i++){
    if(i == str.length()-1){
      if(str[i] == 's'){
		cout << str << "es" << endl;
      }else{
        cout << str << "s" << endl;
      }
    }
  }
}

Measured memory_bytes: 3640
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n, m := scanInt(), scanInt()
	h := make([]int, n)
	for i := range h {
		h[i] = scanInt()
	}
	t := make(map[int][]int, n)

	for i := 0; i < m; i++ {
		a := scanInt() - 1
		b := scanInt() - 1
		t[a] = append(t[a], b)
		t[b] = append(t[b], a)
	}
	ans := make([]int, n)

	for i := 0; i < n; i++ {
		if ans[i] == -1 {
			continue
		}

		ok := true
		for _, num := range t[i] {
			if h[num] >= h[i] {
				ans[i] = -1
				ok = false
			}
		}
		if ok == true {
			ans[i] = 1
		}
	}
	cnt := 0
	for _, i := range ans {
		if i == 1 {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 14980
#include <stdio.h>
#include <algorithm>
#include <vector>

typedef long long ll;
ll N, M;
int main(){
        scanf("%lld %lld",&N,&M);
        ll ans=1;
        std::vector<ll> q;

        for(ll i = 1; i*i <= M; i++){
                if(M % i == 0){
                        q.push_back(i);
                        q.push_back(M/i);
                }
        }
        std::sort(q.begin(),q.end());
        std::vector<ll>::iterator it = std::lower_bound(q.begin(),q.end(),N);
        printf("%lld\n",M/(*it));
        return 0;
}

Measured memory_bytes: 256
t1, t2 = (int(i) for i in input().split())
a1, a2 = (int(i) for i in input().split())
b1, b2 = (int(i) for i in input().split())

sa = t1*a1+t2*a2-t1*b1-t2*b2

if sa==0:
    print("infinity")
else:
    if sa>0:
        if a1>b1:
            print(0)
        else:
            ganba=t1*b1-t1*a1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)
            #print(sa, ganba)
    else:
        sa=sa*(-1)
        if b1>a1:
            print(0)
        else:
            ganba=t1*a1-t1*b1
            if ganba%sa!=0:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-1)
            else:
                gyakuten=(ganba//sa)+1
                print(gyakuten*2-2)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e3 ;
int main(int argc, const char** argv) {
    int N,i,j;
    cin>>N;
    vector<double> dp(N+1);
    dp[0] = 1;
    for(i=0;i<N;i++){
        double heads;
        cin>>heads;
        for(j=i+1;j>=0;--j){
            if(j==0)
                dp[j] = dp[j]*(1-heads);
            else
                dp[j] = dp[j-1]*heads + dp[j]*(1-heads);
        }
    }
    double answer = 0;
    for(i=0;i<=N;i++){
        if(i>N-i)
            answer+=dp[i];
    }
    printf("%.10lf\n",answer);
    
    return 0;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll x;
  cin >> x;
  //  (1+t)*t /2
  for(ll i=1;i<=x;i++){
    if((i*(i+1))/2 >= x){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}




Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define M 100002

using namespace std;
vector<int> v[M];
bool visited[M];
int cost[M];

int dfs(int s){
	if(visited[s])return cost[s];
	for(int i=0;i<v[s].size();i++){
		int child = v[s][i];
		cost[s]=max(cost[s],1+dfs(child));
	}
	visited[s]=true;
	return cost[s];
}

int longpath(int n){
	int m=0;
	for(int i=1;i<=n;i++){
		if(!visited[i])m=max(m,dfs(i));
	}
	
	for(int i=1;i<=n;i++){
		cost[i]=0;
		visited[i]=false;
		v[i].clear();
	}
	return m;			
}

void addedge(int i,int j){
	v[i].push_back(j);	
}


int main(){
	int n,m,x,y;
  	cin>>n>>m;
  	for(int i=0;i<m;i++){
      cin>>x>>y;
      addedge(x,y);
    }
	cout << longpath(n) <<endl;
	return 0;	

}

Measured memory_bytes: 11604
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

from collections import deque

S = deque(inpS())
Q = int(inp())
Query = [list(inpS().split())for _ in range(Q)]
is_revese = False

for q in Query:
  if q[0] == "1":
    is_revese = not is_revese
  else:
    if q[1] == "1": # 先頭に追加
      if is_revese: #反転状態
        S.append(q[2])
      else:
        S.appendleft(q[2])
    else:
      if is_revese: #反転状態
        S.appendleft(q[2])
      else:
        S.append(q[2])

if is_revese:
  S = reversed(S)
print("".join(S))  
    
    

Measured memory_bytes: 35124
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(){
	ios;
	int n,m,i,s=0,a[105];
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	s+=4*m-1;
	s/=(4*m);
	sort(a,a+n,greater<int>());
	for(i=0;i<m;i++)
	{
		if(a[i]<s) break; 
	}
	if(i==m) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		long[] bool = new long[100001];
		for(int i = 0 ; i < 100001; i++) {
			bool[i]	 = 0;
		}
		//System.out.println(1);
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			bool[a[i]]++;
		}
		//System.out.println(2);
		int q = sc.nextInt();
		int[] b = new int[q];
		int[] c = new int[q];
		for(int i = 0; i < q; i++) {
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		//System.out.println(3);
		long[] sa = new long[q];
		java.util.Arrays.sort(a);
		for(int i = 0; i < q; i++) {
			if(bool[b[i]] > 0) {
				//System.out.println(bool[b[i]]);
				sa[i] += bool[b[i]]*(c[i] - b[i]);
				bool[c[i]] += bool[b[i]];
				bool[b[i]] = 0;
			}
		}
		long sum = 0;
		for(int i = 0; i < n; i++) {
			sum+= (long)a[i];
		}
		for(int i = 0; i < q; i++) {
			sum+= sa[i];
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 63640
let n = read_int ()

let a =
  let rec f n ls = 
    if n = 0 then ls else f (n - 1) (Scanf.scanf "%d " (fun x -> x) :: ls)
  in 
  f n []

let rec div2 n =
  let rec aux n count =
    if n mod 2 = 1 then count else aux (n / 2) (count + 1) 
  in aux n 0


let () =
  List.fold_left (fun x y -> min x (div2 y)) max_int a
  |> Printf.printf "%d\n"

Measured memory_bytes: 2432
#include<bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
int main() 
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
    {
      
      string s;
     int n,z=0;
     cin>>n;
     int arr[n];
     for(int i=0;i<n;i++)
     cin>>arr[i];
     sort(arr,arr+n);
     for(int i=1;i<=arr[n-1];i++)
     {
         int x=lower_bound(arr,arr+n,i)-arr;
           if(n/2==x)
             z++;
         
         
     }
     cout<<z;
      
    }
    
    return 0;
}

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

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int cnt=0;
  x-=z;
  while (true)
  {
    /* code */
    if (x>=y+z)
    {
      /* code */
      cnt++;
      x-=y+z;
    }
    else
    {
      break;
    }
    
    
  }
  cout<<cnt<<endl;
  
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

using Graph = vector<vector<int>>;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M; cin >> N >> M;
  
    Graph G(N);
    for(int i=0;i<M;i++){
        int A, B;
        cin >> A >> B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    int dist1[N];
    int dist2[N];
    fill(dist1, dist1+N, INF);
    fill(dist2, dist2+N, INF);
    dist1[0] = 0;
    dist2[0] = 0;
 
    priority_queue<P, vector<P>, greater<P>> que1;
    que1.push(P(0, 0));

    while(!que1.empty()){
        P p = que1.top();
        que1.pop();
        int d = p.first;
        int u = p.second;

        if(d > dist1[u]) continue;

        for(auto v : G[u]){
            

            if(dist1[v] > dist1[u] + 1){
                dist1[v] = dist1[u] + 1;
                dist2[v] = u;
                que1.push(P(dist1[v], v));
            }
        }
    }

    bool ok = true;
    rep(i,N){
        if(dist2[i] == INF){
            ok = false;
        }
    }
    if(ok){
        cout << "Yes" << endl;
        for(int i=1;i<N;i++){
            cout << dist2[i]+1 << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 14932
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	list := make([][]int, n)
	for i := 0; i < n; i++ {
		list[i] = make([]int, 0)
	}

	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		list[a] = append(list[a], b)
		list[b] = append(list[b], a)
	}

	color := make([]int, n)

	q := make([][2]int, 1)
	distance1 := make([]int, n)
	distance2 := make([]int, n)
	q[0][0] = 0
	q[0][1] = 0
	color[0] = 1
	color[n-1] = 2

	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		l := len(list[p[0]])
		for i := 0; i < l; i++ {
			if color[list[p[0]][i]] != 0 {
				continue
			}
			color[list[p[0]][i]] = 1
			distance1[list[p[0]][i]] = p[1] + 1
			q = append(q, [2]int{
				list[p[0]][i],
				p[1] + 1,
			})
		}
	}
	q = append(q, [2]int{
		n - 1,
		0,
	})
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		l := len(list[p[0]])
		for i := 0; i < l; i++ {
			if list[p[0]][i] == 0 {
				continue
			}
			if color[list[p[0]][i]] >= 2 {
				continue
			}
			color[list[p[0]][i]] += 2
			distance2[list[p[0]][i]] = p[1] + 1
			q = append(q, [2]int{
				list[p[0]][i],
				p[1] + 1,
			})
		}
	}

	ans := [3]int{0, 0, 0}
	for i := 0; i < n; i++ {
		if color[i] == 3 {
			if distance1[i] <= distance2[i] {
				ans[1]++
				continue
			}
			ans[2]++
			continue
		}
		ans[color[i]]++
	}

	out := "Snuke"
	if ans[1] > ans[2] {
		out = "Fennec"
	}
	fmt.Fprintln(writer, out)

	writer.Flush()
}


Measured memory_bytes: 17408
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	char b;

	cin >> b;

	if (b == 'A') {
		cout << 'T' << endl;
	}
	else if (b == 'T') {
		cout << 'A' << endl;
	}
	else if (b == 'C') {
		cout << 'G' << endl;
	}
	else if (b == 'G') {
		cout << 'C' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n;
	ll j=0;
	for(int i=3;i<=n;i++)
	{
		a[j]=i;
		j++;
	}
	ll dp[20000]={0};
	dp[0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int k=0;k<j;k++)
		{
			if(a[k]<=i)
			{
				dp[i]=(dp[i]+dp[i-a[k]])%(1000000007);
			}
		}
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 3732
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	int a[3];

	FOR(i, 0,2) {
		cin >> a[i];
	}

	sort(a, a + 3);

	cout << a[2] - a[0] << endl;

	

	return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

n = int(raw_input())
a = map(int, raw_input().split())
l = a[0]

for i in range(1,len(a)):
    b = a[i]
    g = gcd(l,b)
    l = l*b/g
print l
     

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

#define maxn 100002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

int n, d[maxn];
set<int> a[maxn];
priority_queue<ii, vector<ii>, greater<ii> > pq;

int main() {
    //freopen("bwtree.inp", "r", stdin);
    //freopen("", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0);
    scanf("%d", &n);
    FOR(i, 1, n-1) {
        int u, v; scanf("%d%d", &u, &v);
        a[u].insert(v);
        a[v].insert(u);
    }
    FOR(u, 1, n) {
        int cnt = 0;
        for (set<int>::iterator it=a[u].begin(); it!=a[u].end(); ++it) {
            int v = *it;
            if (a[v].sz()==1) ++cnt;
        }
        if (cnt>1) {
            printf("First");
            return 0;
        }
    }
    FOR(i, 1, n) pq.push(ii(d[i]=a[i].sz(), i));
    while (pq.sz()) {
        ii u = pq.top(); pq.pop();
        if (d[u.se]!=u.fi) continue;
        if (d[u.se]==0) {
            printf("First\n");
            return 0;
        }
        int v = *a[u.se].begin();
        d[v] = -1;
        for (set<int>::iterator it=a[v].begin(); it!=a[v].end(); ++it) {
            a[*it].erase(a[*it].find(v));
            d[*it]--;
            if (*it!=u.se) pq.push(ii(d[*it], *it));
        }
    }
    printf("Second");
}



Measured memory_bytes: 15740
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
string S;
int main(){
    cin >> S;
    bool flag = true;
    if(S[0] != 'A') flag = false;
    int ct = 0;
    rep(i,S.size()){
        if(i >= 2 && i <= S.size()-2 && S[i] == 'C') ct++;
        else if(i != 0 && S[i] != 'C' && S[i] >= 'A' && S[i] <= 'Z') flag = false; 
    }
    if(ct != 1) flag = false;
    
    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
using namespace std;

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

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

    long long ans = INF;
    for (int j = 0; j <= 100; ++j) {
        long long tmp = 0;
        for (int i = 0; i < N; ++i) {
            tmp += pow(v[i]-j, 2);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

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

const ll MOD = 998244353;
const int MN = 200'000;
int N, K;
ll DP[MN+2];
ll DPSUM[MN+2];

ll ADD(ll a, ll b)
{
    a %= MOD;
    b %= MOD;
    return (a + b) % MOD;
}


ll cnt2(const vector<pii>& S)
{
    DP[N] = 1;
    DPSUM[N] = 1;
    for(int i = N - 1; i > 0; i--){
        for(const pii& s: S){
            int l = i + s.first;
            int r = min(N, i + s.second);
            if(l > N) continue;
            DP[i] = ADD(DP[i], ADD(DPSUM[l], MOD - DPSUM[r+1]));
        }
        DPSUM[i] = ADD(DPSUM[i+1], DP[i]);
    }
    return DP[1];
}


int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    cin >> N >> K;
    vector<pii> S(K);
    REP(i,0,K) cin >> S[i].first >> S[i].second;
    memset(DP, 0, sizeof DP);
    sort(ALL(S));
    cout << cnt2(S) << endl;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()
{
    ll n;
    cin >> n;
    vector<char> s(0);
    while (n)
    {
        n--;
        s.push_back(97 + (n % 26));
        n /= 26;
    }
    for (ll i = s.size() - 1; i >= 0; i--)
    {
        cout << s[i];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
n=gets.to_i
a=gets.split.map &:to_i
m=gets.to_i
b=gets.split.map &:to_i
a.sort!
b.sort!
c=true
ca=0
b.each do |e|
  loop do
    if ca>=n
      c=false
      break
    end
    if a[ca]==e
      ca+=1
      break
    end
    if a[ca]>e
      c=false
      break
    end
    ca+=1
  end
end
puts c ? :YES : :NO
  



Measured memory_bytes: 34708
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
#define pb push_back
#define skip continue
#define ll long long
ll a,b,c,d=0,e=0,i,f=0,g=0,j,k=0,l=0,r,m,h,p[200001],df[51];
string t,x,q,s;
double w;
vector<ll>dv[101],v,z;
vector<string>u;
map<string,ll>n;
set<ll>y;
void dfs(ll x){
    df[x]=1;
    for(ll i=0;i<dv[x].size();i++){
        if(dv[x][i]==0){
            dfs(dv[x][i]);
            df[dv[x][i]]=1;
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>a;
    for(i=1;i<=a;i++){
        cin>>p[i];
        if(i>1){
            if(p[i]<p[i-1]){
                d+=(p[i-1]-p[i]);
                p[i]=p[i-1];
            }
        }
    }
    cout<<d;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl a(n);
    int v4=0,v2=0,v=0;
    rep(i,n){
        cin >> a[i];
        if(a[i]%4==0) v4++;
        else if(a[i]%2==0) v2++;
        else v++;
    }
    string Y = "Yes",N="No";
    if(v4*2 < v) cout << N << endl;
    else if((v2+v4*2-v)%2==0) cout << Y << endl;
    else cout << N << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;


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

    char c;

    cin >> c;

    cout << char(c + 1);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b" << endl;
	if (a > b)
		cout << "a > b" << endl;
	if (a == b)
		cout << "a == b" << endl;
}



Measured memory_bytes: 3052
pal = lambda x : 1 if x==x[::-1] else 0
s=input();n=len(s)
#print(s[(n+3)//2-1:],s[:(n-1)//2],pal(s))
if s==s[::-1] and pal(s[:(n-1)//2]) and pal(s[(n+3)//2-1:]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	//static long mod = 1000000007;
	static long mod =998244353; 
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res = "";


		int res = 0;


		int n = int.Parse(Console.ReadLine());
		n = n * n;



			Console.WriteLine(n);

		return;

	}

	//	int配列をスペース区切りの文字列に変換
	static string stringBuilderArrayInt(int[] a) {
		StringBuilder sb = new StringBuilder();

		for ( int i = 0; i < a.Length; i++ ) {
			sb.Append(a[i] + " "); 
		}
		if ( sb.Length > 1 ) {
			sb = sb.Remove(sb.Length - 1, 1);
		}
		return sb.ToString(); ;
	}


	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}



}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0 ; i<(n) ;i++)
bool go(int a,int b,int k){
	int n = 0;
	while(k>0){
		n += k%10;
		k /=10;
	}

	return (k>=a && k<=b);
}

int main(){
	int n; cin >> n;
	std::vector<int> v;
	rep(i,n){
		int a; cin >> a;
		v.push_back(a);
	}

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

	ll n1 = 0 , n2 = 0;
	rep(i,n){
		if(i&1){
			n2 += v[i];
		}else{
			n1 += v[i];
		}
	}

	cout << abs(n1 - n2) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main()
{
	int N, A, B;
	scanf("%d%d%d", &N, &A, &B);
	printf("%d %d\n", min(A, B), max(0, A + B - N));
	return 0;
}


Measured memory_bytes: 764
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());		

const ll mod=1e9+7;

map<ll,priority_queue<ll>>fact;

ll power(ll b,int n)
{
	if(n==0) return 1LL;
	
	ll ans=power(b,n/2)%mod;
	ans*=ans;
	ans%=mod;
	
	if(n%2) ans*=b;
	ans%=mod;
	
	return ans;
}

void factorize(int n)
{
	for(int i=2;i*i<=n;i++)
	{
		ll cnt=0;
		while(n%i==0)
		{
			n/=i;
			cnt++;
		}
		if(cnt) fact[i].push(cnt);
	}
	
	if(n>1) fact[n].push(1);
}

void solve()
{
	int n;
	cin>>n;
	
	vector<ll>vec(n);
	for(ll &x: vec) cin>>x;
	
	for(ll x: vec) factorize(x);
	
	auto add=[&](ll a,ll b)
	{
		return (a+b)%mod;
	};
	
	auto mul=[&](ll a,ll b)
	{
		return (a*b)%mod;
	};
	
	ll l=1;
	
	for(auto it: fact)
	{
		ll b=it.first;
		ll k=it.second.top();
		
		l=mul(l,power(b,k));
	}
	
	ll sum=0;
	
	for(ll x: vec)
	{
		ll temp=mul(power(x,mod-2),l);
		sum=add(sum,temp);
	}
	
	cout<<sum;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 4668
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

bool isPrime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int n;
vector<int> v;

int main() { 

  cin >> n;

  for (int i = 2; i <= 55555; i++) {
    if (isPrime(i) && i % 5 == 1) {
      v.push_back(i);
    }
  }

  for (int i = 0; i < n; i++) {
    printf("%d ", v[i]);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s[] = {"AC", "WA", "TLE", "RE"};
    int a[] = {0, 0, 0, 0};
    for (int i = 0; i < n; i++){
      String b = sc.next();
      for (int j = 0; j < 4; j++){
        if (s[j].equals(b)){
          a[j]++;
        }
      }
    }
    for (int i = 0; i < 4; i++){
      System.out.printf("%s x %d\n", s[i], a[i]);
    }
  }
}


Measured memory_bytes: 57628
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;

class MergeTech {
public:
	int minval[1 << 18];
	int sum[1 << 18];
	int group[1 << 18];
	vector<int> G[1 << 18];

	void init(int sz) {
		for (int i = 0; i < sz; i++) {
			group[i] = i;
			minval[i] = i;
			sum[i] = 0;
			G[i].push_back(i);
		}
	}
	void unite(int u, int v) {
		u = group[u]; v = group[v];
		if (G[u].size() < G[v].size()) swap(u, v);
		for (int i = 0; i < G[v].size(); i++) {
			G[u].push_back(G[v][i]);
			group[G[v][i]] = u;
			minval[u] = min(minval[u], G[v][i]);
		}
		sum[u] += sum[v]; sum[v] = 0;
		G[v].clear();
	}
	int getval(int pos) {
		return minval[group[pos]];
	}
};

struct Fraction {
	long long p1, p2;
};

bool operator<(const Fraction& a1, const Fraction& a2) {
	if (a1.p1 * a2.p2 < a1.p2 * a2.p1) return true;
	return false;
}

bool operator==(const Fraction& a1, const Fraction& a2) {
	if (a1.p1 * a2.p2 == a1.p2 * a2.p1) return true;
	return false;
}

// 入力
int N, P[1 << 18], V[1 << 18];
int S[1 << 18];

// 最強部分木を求めるパート
Fraction dp[1 << 18];
MergeTech Z;
vector<int> X[1 << 18];
vector<int> XX[1 << 18];
vector<int> Y;

void dfs(int pos, Fraction V) {
	for (int i : X[pos]) {
		if (!(dp[i] < V)) { Y.push_back(i); continue; }
		dfs(i, V);
	}
}

int main() {
	// Step #1. 入力
	cin >> N;
	for (int i = 2; i <= N; i++) cin >> P[i];
	for (int i = 1; i <= N; i++) cin >> V[i];

	// Step #2. 木の調整
	for (int i = 1; i <= N; i++) {
		if (V[i] == 1) S[i] = i;
		if (V[i] == 0) S[i] = S[P[i]];
	}
	for (int i = 1; i <= N; i++) {
		if (V[i] == 1) P[i] = S[P[i]];
	}
	for (int i = 2; i <= N; i++) { if (P[i] >= 1) X[P[i]].push_back(i); }
	
	// Step #3. 最強部分木を求める
	priority_queue<pair<Fraction, int>, vector<pair<Fraction, int>>, greater<pair<Fraction, int>>> Q;
	Z.init(N + 2);
	for (int i = 1; i <= N; i++) Z.sum[i] = V[i];
	for (int i = 1; i <= N; i++) Q.push(make_pair(Fraction{ 1LL * V[i], 1LL }, i));
	while (!Q.empty()) {
		int pos = Q.top().second;
		Fraction vals = Q.top().first; Q.pop();
		if (dp[pos].p1 + dp[pos].p2 >= 1LL) continue;
		dp[pos] = vals;
		if (P[pos] >= 1) {
			Z.unite(pos, P[pos]);
			int cx = Z.getval(pos);
			int idx = Z.group[pos];
			int F1 = Z.sum[idx], F2 = Z.G[idx].size();
			Q.push(make_pair(Fraction{ F1, F2 }, cx));
		}
	}

	// Step #4. 本計算
	priority_queue<tuple<int, Fraction, int>, vector<tuple<int, Fraction, int>>, greater<tuple<int, Fraction, int>>> Q2;
	for (int i = 1; i <= N; i++) {
		if (P[i] == 0) Q2.push(make_tuple(V[i], dp[i], i));
	}
	vector<int> val;
	while (!Q2.empty()) {
		int pos = get<2>(Q2.top()); Q2.pop();
		val.push_back(V[pos]);
		for (int i : X[pos]) Q2.push(make_tuple(V[i], dp[i], i));
	}

	// Step #5. 出力
	long long Answer = 0, rets = 0;
	for (int i = 0; i < val.size(); i++) {
		if (val[i] == 1) rets++;
		if (val[i] == 0) Answer += rets;
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 58984
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;

long long powmod(long long x, long long n, long long mod = 0) {
  if (mod == 0) {
      long long res=1;
    while (n > 0) {
      if (n%2 == 1) {
        res = ( res*x );
      }
      x = (x*x);
      n /= 2;
    }
    return res;
  }

  long long res=1;
  while (n > 0) {
    if (n%2 == 1) {
      res = ( res*x ) % mod;
    }
    x = (x*x) % mod;
    n /= 2;
  }
  return res;
}

long long modinverse(long long x, long long mod) {
  // mod must be prime number.
  return powmod(x, mod-2, mod);
}

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

  for (auto & e:s) {
    if (e == '?') {
      e = 'D';
    }
  }

  cout << s << endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  cin >> a;
  vector<int> b(m);
  cin >> b;

  vector<vector<ll> > dp(n, vector<ll>(m));
  vector<vector<ll> > sum(n + 1, vector<ll>(m + 1));

  rep(i, n) rep(j, m) {
    if (a[i] == b[j]) {
      (dp[i][j] = sum[i][j] + 1) %= mod;
    }
    sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i][j] + mod) % mod;
  }
  // cout << endl; rep(i, n) cout << dp[i] << endl;
  // cout << endl; rep(i, n + 1) cout << sum[i] << endl;
  ll ans = 0;
  rep(i, n) rep(j, m) (ans += dp[i][j]) %= mod;
  cout << (ans + 1) % mod << endl;
}


Measured memory_bytes: 62976
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [K, S] = list(map(lambda x: int(x), inputs[0].split()))
    pattern = 0
    for x in range(0, K + 1):
        for y in range(0, K + 1):
            tmp_z = S - x - y
            if tmp_z <= K and tmp_z >= 0:
                pattern += 1

    return pattern


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

bool flags[100100];
void Sieve() {
  flags[0] = true;
  flags[1] = true;
  const int sqrt_x = ceil(sqrt(100100) + 0.1);
  FOR(p,2,sqrt_x){
    if (flags[p])continue;
    for (int mult = p * p; mult < 100100; mult += p)
      flags[mult] = true;
  }
}

ll N;
ll bit[1000010];

void bit_add(ll a, ll w){
    for(ll x=a; x <= N; x+=x&-x)bit[x]+=w;
}
ll bit_sum(ll a){
  ll ret=0;
  for(ll x=a;x>0;x-=x&-x) ret+=bit[x];
  return ret;
}

int main(){
  Sieve();
  N=100010;
  rep(i,100010){
    if(flags[i]==false){
      if(i%2){
        if(flags[ll((i+1)/2)]==false){
          bit_add(i,1);
        }
      }
    }
  }

  ll q;cin>>q;
  ll l,r;
  rep(i,q){
    cin>>l>>r;
    cout<<bit_sum(r)-bit_sum(l-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

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

int main() {
	int n;
	scanf("%d", &n);
	
	int a[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	long long res = 0;
	int non_zero = n;
	for (int i = n-1; i >= 0; i--) {
		if (a[i] > i || (!a[i] && i >= non_zero) || (i < n-1 && a[i] < a[i+1]-1)) {
			res = -1;
			break;
		}
		if (i == n-1 || a[i] != a[i+1]-1) {
			res += a[i];
			int new_non_zero = i-a[i]+1;
			non_zero = min(non_zero, new_non_zero);
		}
	}
	
	printf("%lld", res);
	
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans;
int main()
{
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    	for(int j=0;j<=b;j++)
    		if((x-i*500-j*100>=0)&&(x-i*500-j*100<=c*50))ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
// F.

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

using namespace std;

typedef long double LD;
const LD EPS = 1e-8;

struct Point {
	long double x;
	long double y;
	long double z;
	int i;
	bool operator < (const Point& p) const {
		return x < p.x || (x == p.x && y < p.y);
	}
};

long double cross(const Point& O, const Point& A, const Point& B) {
	return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}

vector<Point> convex_hull(vector<Point>& P)
{
	int n = (int)P.size(), k = 0;
	if (n <= 2) {
		return P;
	}
	vector<Point> H(2 * n);
	sort(P.begin(), P.end());
	for (int i = 0; i < n; ++i) {
		while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	for (int i = n - 2, t = k + 1; i >= 0; i--) {
		while (k >= t && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	return vector<Point>(H.begin(), H.begin() + k - 1);
}

void circumscribed_circle(LD x1, LD y1, LD x2, LD y2, LD x3, LD y3, LD& cx, LD& cy, LD& r)
{
	LD ea = x3 - x1;
	LD ca = x2 - x1;
	cy = (ea * (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) - ca * (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3)) /
		(2 * ea * (y1 - y2) - 2 * ca * (y1 - y3));
	if (fabs(ca) <= EPS) {
		cx = (2 * (y1 - y3) * cy - x1 * x1 - y1 * y1 + x3 * x3 + y3 * y3) / (2 * (x3 - x1));
	} else {
		cx = (2 * (y1 - y2) * cy - x1 * x1 - y1 * y1 + x2 * x2 + y2 * y2) / (2 * ca);
	}
	r = sqrt((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy));
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n <= 0) return 0;
		vector<Point> xy(n);
		for (int i = 0; i < n; ++i) {
			cin >> xy[i].x >> xy[i].y;
			xy[i].i = i;
		}
		LD ans = 1e10;
		vector<Point> ch = convex_hull(xy);
		int sz = ch.size();
		for (int i = 0; i < sz; ++i) {
			for (int j = i + 1; j < sz; ++j) {
				LD cx = (ch[i].x + ch[j].x) * 0.5, cy = (ch[i].y + ch[j].y) * 0.5;
				LD dx = ch[i].x - ch[j].x, dy = ch[i].y - ch[j].y;
				LD r = sqrt(dx * dx + dy * dy) * 0.5;
				auto ok = [&](LD cx, LD cy, LD r) {
					for (int l = 0; l < sz; ++l) {
						LD dx = ch[l].x - cx;
						LD dy = ch[l].y - cy;
						if (sqrt(dx * dx + dy * dy) > r + EPS) {
							return false;
						}
					}
					return true;
				};
				if (ok(cx, cy, r)) {
					ans = min(ans, r);
				}
				for (int k = j + 1; k < sz; ++k) {
					circumscribed_circle(ch[i].x, ch[i].y, ch[j].x, ch[j].y, ch[k].x, ch[k].y, cx, cy, r);
					if (ok(cx, cy, r)) {
						ans = min(ans, r);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256