akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main() {

	int n;
	int *w;
	int dp[301][301];
	int i,j,k;

	for(;;) {
		scanf("%d",&n);
		if(n==0)
			break;
		w = malloc((n+1) * sizeof(int));

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

		for(i=0;i<n+1;i++)
			for(j=0;j<n+1;j++)
				dp[i][j]=0;;

		//??????DP
		for(i=n-1;i>=0;i--) {
			for(j=i+1;j<=n;j++) {
				if(i+1<j&&abs(w[i]-w[j-1])<=1&&dp[i+1][j-1]==j-i-2)
					dp[i][j]=j-i;
				for(k=j+1;k<=n;k++) {
					if(dp[i][k]<(dp[i][j]+dp[j][k]))
							dp[i][k]=dp[i][j]+dp[j][k];
				}
			}
		}
		printf("%d\n",dp[0][n]);
		free(w);
	}

	return 0;
}

Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int h, w;
	while(cin >> h >> w, h | w) {
		vector<string> in;
		for(int i = 0; i < h; i++) {
			string s;
			cin >> s;
			in.push_back(s);
		}
		vector<vector<int> > table = vector<vector<int> >(h, vector<int>(w, 0));

		for(int i = 0; i < in.size(); i++) {
			for(int j = 0; j < in[i].size(); j++) {
				if(in[i][j] == '.' && i == 0)
					table[i][j] = 1;
				else if(in[i][j] == '.')
					table[i][j] = table[i - 1][j] + 1;
				else
					table[i][j] = 0;
			}
		}

		int ret = 0;
		for(int i = 0; i < in.size(); i++) {
			for(int j = 0; j < in[i].size(); j++) {
				int minh = 1000;
				for(int k = j; k < in[i].size(); k++) {
					minh = min(minh, table[i][k]);
					ret = max(ret, minh * (k - j + 1));
				}
			}
		}

		cout << ret << endl;
	}
}

Measured memory_bytes: 2408
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int sgn(int x) { return x < 0 ? -1 : x == 0 ? 0 : 1; }
int divup(int x, int y) { return (x + y - 1) / y; }
vector<pair<int, int>> route(int K, const vector<pair<int, int>> &A) {
    vector<pair<int, int>> ans;
    int x = A[0].first, y = A[0].second, rest = K;
    for (int i = 1; i < A.size(); i++) {
        while (x != A[i].first || y != A[i].second) {
            int t = min(rest, abs(A[i].first - x) + abs(A[i].second - y));
            x += sgn(A[i].first - x) * t;
            y += sgn(A[i].second - y) * t;
            rest -= t;
            if (rest == 0) ans.emplace_back(x, y), rest = K;
        }
    }
    return ans;
}
vector<pair<int, int>> solve(int K, int X, int Y) {
    if (K % 2 == 0 && (X + Y) % 2) return {};
    int s;
    if (X + Y < K && (X + Y) % 2 == 0) {
        s = 2;
    } else {
        s = divup(X + Y, K);
    }
    if ((s * K - X - Y) % 2) s++;
    int a = (s * K - X - Y) / 2;
    if (a == 0 || K <= a + X) {
        return route(K, {{0, 0}, {0, -a}, {X, -a}, {X, Y}});
    } else {
        return route(K, {{0, 0}, {0, -a}, {X+K, -a}, {X+K, Y}, {X, Y}});
    }
}
vector<pair<int, int>> solve2(int K, int X, int Y) {
    if (X < 0) {
        auto ans = solve2(K, -X, Y);
        for (auto &a : ans) a.first *= -1;
        return ans;
    }
    if (Y < 0) {
        auto ans = solve2(K, X, -Y);
        for (auto &a : ans) a.second *= -1;
        return ans;
    }
    if (X < Y) {
        auto ans = solve2(K, Y, X);
        for (auto &a : ans) swap(a.first, a.second);
        return ans;
    }
    return solve(K, X, Y);
}
int main() {
    int K, X, Y;
    cin >> K >> X >> Y;
    auto ans = solve2(K, X, Y);
    if (ans.empty()) {
        cout << -1 << '\n';
    } else {
        cout << ans.size() << '\n';
        for (auto &a : ans) cout << a.first << ' ' << a.second << '\n';
    }
    return 0;
}


Measured memory_bytes: 3952
a_11, a_12, a_13 = map(int, input().split())
a_21, a_22, a_23 = map(int, input().split())
a_31, a_32, a_33 = map(int, input().split())
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

_1 = [a_11, a_12, a_13]
_2 = [a_21, a_22, a_23]
_3 = [a_31, a_32, a_33]
_4 = [a_11, a_21, a_31]
_5 = [a_12, a_22, a_32]
_6 = [a_13, a_23, a_33]
_7 = [a_11, a_22, a_33]
_8 = [a_31, a_22, a_13]

def list_check2(list1, list2):
    return set(list1).issubset(list2)

is_contain = False
for i in [_1, _2, _3, _4, _5, _6, _7, _8]:
    if list_check2(i, b):
        is_contain = True
        break

if is_contain:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		int h[]=new int[N];
		int z=0;
		int max=999999999;
		int y=0,ir=1;
		while(z<N){
			h[z]=stdIn.nextInt();
			z++;
		}z=0;
		Arrays.sort(h);
		while(z<N){
			if(h[z+K-1]-h[z]<max)
				max=h[z+K-1]-h[z];
			z++;
			if(z+K-1==N)
				break;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 51180
#include<iostream>
#include <vector>
#include <cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
#define ll long long int
using namespace std;
    vector <ll> a;
    vector <ll> b;
    vector <ll> c;


int main()
{
    ll n,w;
    cin>>n>>w;
    vector <ll> we;
    vector <ll> v;
    for(ll i=0;i<n;i++)
    {
        ll temp1,temp2;
        cin>>temp1>>temp2;
        we.push_back(temp1);
        v.push_back(temp2);
    }
    vector <vector <ll>> arr(n+1,vector <ll> (w+1,0));
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                arr[i][j]=0;
                continue;
            }
            if(j<we[i-1])
            arr[i][j]=arr[i-1][j];
            else
            {
                arr[i][j]=max(arr[i-1][j],arr[i-1][j-we[i-1]]+v[i-1]);
            }
           // cout<<arr[i][j]<<" ";
            
        }
       // cout<<endl;
        

    }
    cout<<arr[n][w];
  //  cin>>n;
    return 0;

   

}

Measured memory_bytes: 83016
def C(n, r, MOD):
    num = 1
    den = 1
    for i in range(r):
        num *= n - i
        num %= MOD
        den *= i + 1
        den %= MOD
    return (num * pow(den, MOD - 2, MOD)) % MOD

N, K = map(int, input().split())
MOD = 1_000_000_007
for i in range(1, K + 1):
    print((C(N - K + 1, i, MOD) * C(K - 1, i - 1, MOD)) % MOD)


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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000

ll n,we;
ll w[101];
ll v[101];
ll dp[101][100001];

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

    cin >> n >> we;

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

    rep(i,101)
    {
        rep(j,100001)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    fr(i,1,n)
    {
        fr(j,0,100000)
        {
            dp[i][j] = min(dp[i][j],dp[i-1][j]);
            if(v[i-1]<=j)
            {
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1]);
            }
        }
    }

    ll ans;
    frr(i,100000,0)
    {
        if(dp[n][i]<=we)
        {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

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

int main()
{
    int x;
    cin >> x;
    int a, b;
    for (a = -120; a<= 120; ++a) {
        ll a5 = 1;
        rep(i, 5) a5 *= a;
        for (b = -120; b <= 120; ++b) {
            ll b5 = 1;
            rep(i, 5) b5 *= b;
            if(a5 - b5 == x) {
                //printf("a5 = %d, b5 = %d\n", a5, b5);
                printf("%d %d\n", a, b);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long A, long long B, long long C, long long X){
  int ans = 0;
  for (int i = 0; i <= A; i++) {
    for (int l = 0; l <= B; l++) {
      for (int m = 0; m <= C; m++) {
        int n = i*500 + l*100 + m*50;
        if(n == X){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long X;
    scanf("%lld",&X);
    solve(A, B, C, X);
}


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

int cnt = 0;

void InsertionSort(vector<int>::iterator itr, int n, int g) {

	for (int i = g; i < n; i++) {
		int v = itr[i];
		int j = i - g;

		while (j >= 0 && itr[j] > v)
		{
			itr[j + g] = itr[j];
			j -= g;
			cnt++;
		}
		itr[j + g] = v;
	}

}

void ShellSort(vector<int>::iterator itr,int n) {

	vector<int> G;

	int m = 1;
	while (m <= n)
	{
		G.push_back(m);
		m = m * 3 + 1;
	}

	cout << G.size() << endl;

	cout << G.back();
	for (int i = G.size() - 2; i >= 0; i--) {
		cout << " " << G[i];
	}
	cout << endl;

	for (int i = G.size() - 1; i >= 0; i--) {
		InsertionSort(itr, n, G[i]);
	}

}

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

	vector<int> vec;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		vec.push_back(a);
	}

	ShellSort(vec.begin(), n);

	cout << cnt << endl;

	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << endl;
	}

	return 0;
}




Measured memory_bytes: 6964
#include <stdio.h>

int main(void)
{
	int n,i,j;
	long a[5500];
	long max, tmp;
	
	while (scanf("%d", &n) && n != 0){
	
		for (i = 0; i < n; i++){
			scanf("%ld", &a[i]);
		}
		
		max = a[0];
		tmp = 0;
		
        for(i = 0; i < n; i++){
            for(j = i; j < n; j++){
                tmp += a[j];
                if(max < tmp)
                    max = tmp;
            }
            tmp =0;
        }
        printf("%lld\n",max);
    }
  
    return 0;
}	

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF = 1e9;
const int MOD = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll>p(m);
  vector<string>s(m);
  rep(i,m) cin >> p[i] >> s[i];
  vector<ll>num(n);
  
  ll sum1=0;
  ll sum2=0;
  rep(i,m){
    if(s[i]=="AC"){
      if(num[p[i]-1]>=0){
        sum2+=num[p[i]-1];
        num[p[i]-1]=-1;
        sum1++;
      }          
    }
    else{
      if(num[p[i]-1]>=0)num[p[i]-1]++;
    }
  }
  cout << sum1 << " " << sum2 << endl;
  
  
}

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

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

prime = False
x = X

while not prime:
    if is_prime(x):
        prime = True
        print(x)
    else:
        x += 1

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
#include <numeric>
using namespace std;

int main()
{
	int A,B;
	cin >> A >> B;
	int res = 0;

	for (int i = A;i <= B;i++) {
		if (i / 10000 == i % 10) {
			int n=i % 10000;
			int m = i % 100;
			if (n / 1000 == m / 10) {
				res++;
			}
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

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

  int cnt[26] = {};
  int itr = -1;
  for (int i = 0; i < s.size(); ++i)
  {
    cnt[s[i] - 'a']++;
    if (i > 0 && s[i - 1] < s[i])
      itr = i;
  }
  if (s.size() != 26)
  {
    char a;
    for (int i = 0; i < 26; ++i)
    {
      if (!cnt[i])
      {
        a = char(i + 'a');
        break;
      }
    }
    cout << s << a << endl;
  }
  else
  {
    if (itr == -1)
      cout << -1 << endl;
    else
    {
      for (int i = itr; i < s.size(); ++i)
      {
        cnt[s[i] - 'a']--;
      }
      char a;
      for (int i = s[itr - 1] - 'a'; i < 26; ++i)
      {
        if (!cnt[i])
        {
          a = char(i + 'a');
          break;
        }
      }
      cout << s.substr(0, itr - 1) << a << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    rep(i,M) cin >> p.at(i) >> S.at(i);

    vector<int> AC(N,0), WA(N,0);

    for(int i=0; i<M; i++){
        if(AC.at(p.at(i)-1)==0){
            if(S.at(i)=="WA") WA.at(p.at(i)-1)++;
            else AC.at(p.at(i)-1)++;
        }
    }
    
    for(int i=0; i<N; i++){
        if(AC.at(i)==0) WA.at(i)=0;
    }

    int ac = accumulate(all(AC),0);
    int wa = accumulate(all(WA),0);

    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<c){
		if(a+b>=c){
			cout<<"safe"<<endl;
		}
		else{
			cout<<"dangerous"<<endl;
		}
	}
	else{
		cout<<"delicious"<<endl;
	}
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class BCollectingBallsEasyVersion {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, k;
    cin >> n >> k;
    vector<int> X(n);
    for (auto &x: X)
        cin >> x;

    int ans = 0;
    for (const auto &x: X)
        ans += 2 * min(x, abs(x - k));

    cout << ans << endl;

}
};

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


Measured memory_bytes: 256
use std::cmp::{max, min};
fn main() {
    let v = read_vec::<i32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    let x = v[3];
    let y = v[4];

    let mut ans = vec![];
    ans.push(min(x, y) * 2 * c + max(x - y, 0) * a + max(y - x, 0) * b);
    ans.push(a * x + b * y);
    ans.push(max(x, y) * c * 2);
    println!("{}", ans.iter().min().unwrap());
}

#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

long long gcd(long long a, long long b){
  if (a < b) return gcd(b, a);
  if (a % b == 0) return b;
  else return gcd(b, a % b);
}

int main(){
  int n;  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long t;
    cin >> t;
    long long u = gcd(ans, t);
    ans = ans * (t / u);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main() {

	ull N; cin >> N;
	int ans = 0;
	for(int i=2;i<=1000000;++i) {
		int cur = 0;
		while (N % i == 0) {
			cur++;
			N /= i;
		}
		for(int j=1;j<=cur;++j) {
			if (cur < j) break;
			ans++; cur -= j;
		}
	}
	if (N > 1) ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<cmath>
    #include<tuple>
    #include<string>
    typedef unsigned long long ll;
    #define rep(i,a,b) for(int i=(a);i<(b);i++)
    #define F first
    #define S second
    using namespace std;
    const ll INF = 1e12;
    const int i_INF = 2147483647;
     
    int main() {
      int H,W,h,w;
      cin>>H>>W>>h>>w;
      cout<<(H-h)*(W-w)<<endl;
    }
    

Measured memory_bytes: 256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  // val inputs = Seq("56 25 31")
  val vowel = "aiueo"
  val str = inputs.head

  println(
    if(vowel.contains(str)) { "vowel" } else { "consonant" }
  )
}

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

using namespace std;

int main()
{
  int h,w,count;
  string s[50];
  cin>>h>>w;
  //cout<<h<<w;
  for(int i=0;i<h;i++)
  {
    cin>>s[i];
    //cout<<s[i]<<endl;
  }
  /////////////////////////////////
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      count=0;
      if(s[i].at(j)=='#')
      {
        cout<<'#';
        continue;
      }
      for(int k=max(0,i-1);k<=min(i+1,h-1);k++)
      //for(int k=0;k<=h-1;k++)
      {
        for(int l=max(0,j-1);l<=min(j+1,w-1);l++)
        //for(int l=0;l<w-1;l++)
        {
          if(s[k].at(l)=='#')
          {
            //cout<<10;
            count++;
          }
        }
      }
      cout<<count;
    }
    cout<<endl;
  }
}


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

using namespace std;

using ll = long long;
bool used[101];

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!used[x]) {
      ans++;
      used[x] = true;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
INF = 1000000

dp = [INF for i in range(100040)]

dp[0]= 0

a = [1]
n = 6
while True:
    a.append(n)
    n *= 6
    if n > 100000:
        break
n= 9
while True:
    a.append(n)
    n *= 9
    if n > 100000:
        break
a.sort()
for i in range(len(a)):
    a_ =  a[i]
    for j in range(a[i],len(dp)):
        dp[j] = min(dp[j],dp[j-a_] + 1)

print(dp[int(input())])


Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 

int main(){
    set_combi();
    int n;cin >> n;
    LL ans = 1;
    LL c = 0;
    for (int i = 0; i < n; i++) {
        LL x;cin >> x;
        if(x < 2 * c + 1){
            ans = ans * (c + 1) % mod;
            c--;
        }
        c++;
    }
    ans = ans * fact[c] % mod;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 1006
#define mod 1000000007
#define mod2 998244353
#define inf 1e18

char a[N][N];

int solve(int i,int j,vector <vector <int>> &dp)
{
    if(i<0 || j<0)
        return 0;
    if(a[i][j]=='#')
        return 0;
    if(i==0 && j==0)
        return 1;

    int &ans=dp[i][j];
    if(ans!=-1)
        return ans;

    ans=(solve(i-1,j,dp)%mod+solve(i,j-1,dp)%mod)%mod;
    return ans;


}


int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif

    int h,w;
    cin >> h >> w;
    vector <vector <int>> dp(h+1,vector <int> (w+1,-1));

    
    int i,j;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin >> a[i][j];
        }
    }

    int ans=solve(h-1,w-1,dp);
    cout << ans << endl;
}

Measured memory_bytes: 9216
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;

int i, j, k, tmp, ans, cnt, N;
string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;

/*------------------------------------------
	関数名：gcd
	機　能：a/b の最大公約数を求める
	引　数：a b
	戻り値：T
-------------------------------------------*/
template<class T> inline T gcd(T a, T b) {
	T candidate = a;
	if (a == 0) {
		return b;
	}
	while (b % a != 0) {
		candidate = b % a;
		b = a;
		a = candidate;
	}
	return candidate;
}

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int m1, m2;

int main(void) {
	

	scanf("%d", &N);


	vector<int> A(N, 0);
	vector<int> L(N + 1, 0);
	vector<int> R(N + 1, 0);

	REP(i, N) {
		scanf("%d", &tmp);
		A.at(i) = tmp;
	}

	for(int i = 0; i < N; ++i){
		L.at(i+1) = gcd(L.at(i), A.at(i));
	}
	for (int i = N - 1; i >= 0; --i) {
		R.at(i) = gcd(R.at(i + 1), A.at(i));
	}

	//集計
	int res = 0;

	REP(i, N) {
		int l = L.at(i);
		int r = R.at(i + 1);
		chmax(res, gcd(l, r));
	}
	
	cout << res;

	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

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

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

#define NUM_MAX 100000

int main(void) {
    int comas, ps;
    get_int2(&comas, &ps);
    int points[NUM_MAX];
    fget_array(points, ps);
    if(comas >= ps) {
        printf("0\n");
        return 0;
    }
    qsort(points, ps, sizeof(int), asc);
    int diff[NUM_MAX];
    int i;
    for(i = 1; i < ps; i++) {
        diff[i-1] = points[i] - points[i-1];
    }

    qsort(diff, ps-1, sizeof(int), asc);
    int selects = ps-1 - (comas-1);
    int ans = 0;
    for(i = 0; i < selects; i++) {
        ans += diff[i];
    }

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

    return 0;
}

Measured memory_bytes: 1396
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int[] len = new int[n];

    for (int i=0;i<n;i++) {
      len[i] = cin.nextInt();
    }

    Arrays.sort(len);

    int max = len[len.length-1];
    int sum = 0;
    for (int i=0;i<n-1;i++) {
      sum+=len[i];
    }
    if (max < sum) {
      System.out.println("Yes");
    }
    else {
      System.out.println("No");
    }

  }

}

Measured memory_bytes: 21844
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    vector<ll> X(N), x(N);
    REP(i, N)
    cin >> X[i];

    x = X;
    sort(ALL(x));
    ll M = N / 2 - 1;

    REP(i, N)
    {
        if (X[i] <= x[M])
        {
            cout << x[M + 1] << "\n";
        }
        else
        {
            cout << x[M] << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 5896
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	int W, H, N; cin >> W >> H >> N;
	vi X(N), Y(N), A(N);
	FOR(i, 0, N) cin >> X[i] >> Y[i] >> A[i];

	int xs = 0, xt = W;
	int ys = 0, yt = H;
	FOR(i, 0, N) {
		switch (A[i]) {
		case 1:
			if (xs < X[i]) xs = X[i];
			break;
		case 2:
			if (xt > X[i]) xt = X[i];
			break;
		case 3:
			if (ys < Y[i]) ys = Y[i];
			break;
		case 4:
			if (yt > Y[i]) yt = Y[i];
			break;
		default:
			break;
		}
	}

	int w = xt > xs ? xt - xs : 0;
	int h = yt > ys ? yt - ys : 0;
	int ans = w * h;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ll long long
#define f(i) return cout<<i<<"\n",0;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define lp(i,a,b) for (int i=(a);i<=(int)(b);++i)
#define lp2(i,a,b) for (int i=(a);i>=(b);--i)
#define clr(c,x) memset(c,x,sizeof(c))
#define allr(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
const int N=2e5+5,mod=(int)1e9+7;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    string s;
    cin>>s;
    int ff=(s[0]-'0')*10+(s[1]-'0');
    int ss=(s[2]-'0')*10+(s[3]-'0');
    if (ff<=12&&ss<=12&&ff>=1&&ss>=1) cout<<"AMBIGUOUS\n";
    else if (ss<=12&&(ff>12||!ff)&&ss) cout<<"YYMM\n";
    else if ((ss>12||!ss)&&ff<=12&&ff) cout<<"MMYY\n";
    else cout<<"NA\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const ll mod=1000000007;

using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll tc = 1;

  //  cin >> tc;


    while(tc--){
		ll k, n, i1, i2, i, maxm = 0, x, j, fl = 0;
        ll y, z;
        
        cin >> x >> y >> z;
		
		swap(x,y), swap(x,z);
		
		cout << x << " " << y << " " << z << endl;
    }

}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (C - (A - B) > 0) cout << C - (A - B) << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3576
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let f = |i| a.iter().filter(|&&a| a % i == 0).count();

    let mut ans = 1;
    for &a in a[0..2].iter() {
        for i in 1.. {
            if i * i > a {
                break;
            }
            if a % i == 0 {
                if f(i) >= n - 1 {
                    ans = max(ans, i);
                }
                if f(a / i) >= n - 1 {
                    ans = max(ans, a / i);
                }
            }
        }
    }

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


Measured memory_bytes: 4352
d={}
w1=input()
w2=input()
num=len(w1)
b=True
for i in list("qwertyuiopasdfghjklzxcvbnm"):
  d[i]=""
for i in range(num):
  if d[w1[i]]=="":
    d[w1[i]]=w2[i]
  elif d[w1[i]]==w2[i]:
    pass
  elif d[w1[i]]!=w2[i]:
    b=False
    break
if not b:
  print("No")
else:
  l=[]
  for i in d:
    if d[i] in l:
      b=False
      break
    else:
      if d[i]!="":
        l.append(d[i])
  if b:
    print("Yes")
  else:
    print("No")
    



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

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

    for (int i = 0; i < K; i++) {
        if (i % 2 == 0) {
            if (A % 2 == 1) A--;
            int half = A / 2;
            A -= half;
            B += half;
        } else {
            if (B % 2 == 1) B--;
            int half = B / 2;
            A += half;
            B -= half;
        }
    }

    cout << A << ' ' << B << endl;
    return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
 ll N;
 cin >> N;
 ll m = 0;
 ll M = N;
 ll ans = 0;
 while(M){
   m++;
   M/=10;
 }
 ll n = 0;
 for(ll i = 0;i < m;i++){
   for(ll j = 9;j > 0;j--){
     //cout << n + pow(10,i) * j << endl;
     if(n + pow(10,i) * j <= N){
       n += pow(10,i) * j;
       ans += j;
       break;
     }
   }
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.size()%2==1){
        cout<<"No";
        return 0;
    }
    string t=s.substr(0,s.size()/2);
    string tt=s.substr(s.size()/2,s.size()/2);
    if(t==tt){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
	exit(0);
}


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

using namespace std;
typedef long long ll;
const int N = 85;
int h, w, a[N][N], b[N][N];
bool psb[N][N][26000];
int slot(int val) { return val + 13000; }
int main() {
	cin >> h >> w;
	for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) cin >> a[i][j];
	for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
		cin >> b[i][j]; a[i][j] -= b[i][j];
	}
	psb[0][0][slot(a[0][0])] = psb[0][0][slot(-a[0][0])] = true;
	for (int i=0; i<h; ++i)
		for (int j=0; j<w; ++j)
			for (int k=0; k<26000; ++k)
				if (psb[i][j][k]) {
					psb[i + 1][j][k + a[i + 1][j]] = true;
					psb[i + 1][j][k - a[i + 1][j]] = true;
					psb[i][j+1][k + a[i][j+1]] = true;
					psb[i][j+1][k - a[i][j+1]] = true;
				}
	int ans = 1e9;
	for (int k = 0; k < 26000; ++k) {
		if (psb[h - 1][w - 1][k])
			ans = min(ans, abs(k - 13000));
	}
	cout << ans << endl;
}


Measured memory_bytes: 175232
n = int(input())
arr = list(map(int,input().split()))

flag = True

for a in arr:
    if a % 2 == 0:
        if a%3 == 0 or a%5 ==0:
            continue
        else:
            flag = False
    else:
        continue

if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E5 + 10;

long long n, a[N], res = 0;

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
}

void Solve()
{
    for (int i = 2; i <= n; i++) {
        res += max(a[i - 1] - a[i], (long long)0);
        a[i] = max(a[i], a[i - 1]);
    }

    cout << res;
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




Measured memory_bytes: 4684
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin>>x[i][j];
        }
    }
    int ans=0;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            int norm=0;
            rep(k,d){
                int diff=x[i][k]-x[j][k];
                norm+=diff*diff;
            }

            bool flg=false;
            for(int k=0;k<=norm;++k){
                if(k*k==norm)flg=true;
            }
            if(flg)++ans;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3636
N, K = map(int, input().split())
A = [1] + list(map(int, input().split()))
B = [1]

is_passed_list = [None] + [False] * N

first_find_indexes = [None] + [-1] * N

root = []

i = 1
j = 0
k = K
while k > 0:
    if not is_passed_list[i]:
        is_passed_list[i] = True
        first_find_indexes[i] = j
        B.append(A[i])

        i = A[i]
    else:
        break
    j += 1
    k -= 1

if k > 0:
    cur_index = j
    first_find_index = first_find_indexes[i]

    i = (K - first_find_index) % (cur_index - first_find_index)
    print(B[first_find_index:cur_index][i])
else:
    print(B[j])


Measured memory_bytes: 32264
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
namespace Dsu {
	int fa[N], si[N];
	inline int Ask(int x) { return fa[x] ? fa[x] = Ask(fa[x]) : x; }
	inline void Merge(int x, int y) {
		x = Ask(x); y = Ask(y);
		if (x != y) si[x] += si[y], fa[y] = x;
	}
}
int n, fa[N], si[N], sm[N], ans, va[N];
struct Node {
	int x, si, sm;
	inline friend bool operator<(const Node &x, const Node &y) {
		return x.si * y.sm > y.si * x.sm;
	}
};
priority_queue<Node> q;
signed main() {
	scanf("%lld", &n);
	fa[1] = n + 1; for (int i = 2; i <= n; ++i) scanf("%lld", fa + i);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", va + i);
		if (!va[i]) {
			Dsu::si[i] = 1;
			Dsu::Merge(fa[i], i);
		}
	}
	for (int i = 1; i <= n; ++i) if (va[i] == 1) {
		si[i] = 1;
		sm[i] = Dsu::si[i];
		ans += sm[i];
		q.push((Node){i, si[i], sm[i]});
	}
	while (!q.empty()) {
		Node u = q.top(); q.pop();
		if (u.si != si[u.x]) continue;
		int ff = Dsu::Ask(fa[u.x]);
		Dsu::Merge(ff, u.x);
		ans += si[ff] * u.sm;
		si[ff] += u.si;
		sm[ff] += u.sm;
		if (va[ff] == 1) q.push((Node){ff, si[ff], sm[ff]});
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 16624
#include<stdio.h>

int main(void)
{
  long long i,j,N,sum=0;

  scanf("%lld",&N);

  for (i = 1; i*i <= N; i++)
  {
    if((N-i)%i==0)
    {
      j=(N-i)/i;
      if(j&&N/j==N%j)sum+=j;
    }
    if(N/i==N%i)
      sum+=i;
  }

  printf("%lld\n",sum);

  return 0;
}

Measured memory_bytes: 128
s = ['S', 'H', 'C', 'D']
d = {}
for c in s:
  d[c] = [i for i in range(1, 14)]

n = int(input())
for i in range(n):
  s, j = input().split()
  d[s].remove(int(j))

for s in d:
    for i in d[s]:
        print('{} {}'.format(s, i))


Measured memory_bytes: 5600
a,b,k=map(int,input().split())
l=[]
for i in range(k):
    if a+i<=b:
        if a+i not in l:
            l.append(a+i)#小さい方からk番目以内
    if b-i>=a:
        if b-i not in l:
            l.append(b-i)#小さい方からk番目以内
l.sort()
[print(i) for i in l]

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c;
	cout<<min(a+b,min(a+c,b+c));
	return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;

//----------------------------------------------------------

int N;
ll A[10005];
map< int64_t, int > g;

void prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
    chmax(g[i],ret[i]);
  }
  if(n != 1) ret[n] = 1;
  chmax(g[n],ret[n]);
}

int64_t mul(int64_t a, int64_t b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

int64_t power(int64_t x, int64_t y){
    if   (y == 0) return 1;
    else if (y == 1) return x % MOD;
    else if (y % 2 == 0) {int64_t tmp = power(x, y/2);return mul(tmp,tmp) % MOD;}
    else {int64_t tmp = power(x, y/2);return mul(mul(tmp,tmp),x) % MOD;}
}

int64_t division(int64_t a, int64_t b){
    return mul(a, power(b, MOD-2));
}

int main(){
    cin >> N;
    FOR(i,1,N+1)cin >> A[i];
    int64_t ans=0;
    sort(A+1,A+N+1,greater<>());
    FOR(i,1,N+1)
    {
        prime_factor(A[i]);
    }
    int64_t total=1;
    for(auto it=g.begin();it!=g.end();it++)
    {
        int64_t a1=1;
        REP(i,(*it).second)
        {
            a1=mul(a1,(*it).first);
        }
        total = mul(total,a1);
    }
    FOR(i,1,N+1)
    {
        ans+=division(total,A[i]);
    }
    cout << (ans%MOD) << endl;
    return 0;
}

Measured memory_bytes: 1024
// CPP program to find circumference of circle
#include<bits/stdc++.h>
using namespace std;

#define PI 3.1415

double circumference(double r)
{
	double cir = 2*PI*r;
	return cir;
}

// driver function
int main()
{
double r  ;
cin>>r;
cout << circumference(r);
return 0;
}


Measured memory_bytes: 3788
import collections
N=int(input())
L=list(map(int,input().split()))
S=collections.Counter(L)
K={}
ans=0
for x,y in S.items():
	K[x]=(y*(y-1)//2,(y-1)*(y-2)//2)
	ans+=K[x][0]
for i in range(N):
	print(ans-K[L[i]][0]+K[L[i]][1])

Measured memory_bytes: 39068
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
  int go;
  int five;
  long long int result;
  long long int x;
  cin >> x;
  
  go = x / 500;
  x -= go * 500;
  five = x / 5;
  
  result = (go * 1000) + (five * 5);
  cout << result;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N, M;
    cin >> N >> M;
    vector<lint> A(M);
    REP(i, M) cin >> A[i];
    lint sum = 0;
    REP(i, M) sum += A[i];
    if(N >= sum) {
        cout << N-sum << endl;
    } else {
        cout << -1 << endl;
    }
}

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

int main(){
    long long int n;
    vector<long long int> x, y, sum, dif;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        x.push_back(0);
        y.push_back(0);
        cin >> x[i] >> y[i];
        sum.push_back(x[i]+y[i]);
        dif.push_back(x[i]-y[i]);
    }

    // for (int i = 0; i < n; i++)
    // {
    //     cout << sum[i] << " " << dif[i] << endl;
    // }
    

    long long int ind1 = 0, ind2 = 0, ind3 = 0, ind4 = 0;

    for (int i = 0; i < n; i++)
    {
        if (sum[ind1] < sum[i]){
            ind1 = i;
        }

        if (sum[ind2] > sum[i]){
            ind2 = i;
        }

        if (dif[ind3] < dif[i]){
            ind3 = i;
        }

        if (dif[ind4] > dif[i]){
            ind4 = i;
        }
    }

    // cout << ind1 << " " << ind2 << " " << ind3 << " " << ind4 << " " << endl;

    long long int temp1 = abs(x[ind1] - x[ind2]) + abs(y[ind1] - y[ind2]);
    long long int temp2 = abs(x[ind3] - x[ind4]) + abs(y[ind3] - y[ind4]);
    long long int ans = max(temp1, temp2);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9700
#include<bits/stdc++.h>
#define int long long int
#define db double
#define ull unsigned long long
#define vii vector <int>
#define pii pair <int, int>
#define fi first
#define se second
#define rep(i,a,n)		for(int i=a;i<n;i++)
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof a)
#define mkp make_pair
#define pb push_back
#define mod 1000000007LL
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;
db pi=3.1415926535;
db eps=0.000001;
 
void print(vector <int> &arr){
	for(int i=0;i<arr.size();i++)
		cout<<arr[i]<<" ";
	
	cout<<endl;
}
int ncr(int n, int r)
{
    r=min(r,n-r);
    int A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  //initializing A starting from n-r+1 to n
    iota(B,B+r,1);      //initializing B starting from 1 to r

    int g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    int ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}


int32_t main(){
/////////////////////////////////////////////////////////////////////
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//	std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//    std::cout.precision(5);
	int n,m;
	cin>>n>>m;
	vii arr(n);
	rep(i,0,n) cin>>arr[i];
	sort(arr.rbegin(), arr.rend());
	int sum=accumulate(arr.begin(), arr.end(),0);
	sum=ceil((db)sum/(db)(4*m));
	int i=0;
	while(arr[i]>=sum && i<=n-1) i++;
	
	//print(arr);
	//cout<<"Val/i: "<<sum<<" "<<i<<endl;
	if(i>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
int main()
{
    int age,money;
    cin >> age >> money;
    if(age >= 13)
    {
        cout << money;
    }
    else if(age <= 12 && age >= 6)
    {
        cout << money / 2;
    }
    else 
    {
        cout << 0;
    }
}

Measured memory_bytes: 256