akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vd x(n), y(n), d(n);
    REP(i, n) cin >> x[i];
    REP(i, n) cin >> y[i];
    REP(i, n) d[i] = abs(x[i]-y[i]);
    double p1, p2, p3, pinf; p1 = p2 = p3 = pinf = 0;
    REP(i, n) p1 += d[i];
    REP(i, n) p2 += d[i]*d[i]; p2 = sqrt(p2);
    REP(i, n) p3 += d[i]*d[i]*d[i]; p3 = cbrt(p3);
    pinf = *max_element(ALL(d));
    cout << p1 << endl << p2 << endl << p3 << endl << pinf << endl;
}


Measured memory_bytes: 3496
# import numpy as np
# import scipy as sp

n = int(input())
info = []
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        info.append([i, x-1, y])

ans = 0
for i in range(2 ** n):
    bit = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            bit[j] = 1

    flag = True
    # print(bit)
    for idx, j in enumerate(bit):
        if j == 1:
            for k in [x for x in info if x[0] == idx]:
                # print(' ', k)
                if bit[k[1]] != k[2]:
                    flag = False
    if flag:
        ans = max(ans, sum(bit))
    # print(ans)
print(ans)


Measured memory_bytes: 46172
X, N = (int(i) for i in input().split())
p_vals = [int(i) for i in input().split()]

Xp = Xn = X

while True:
    if Xn not in p_vals:
        print(Xn)
        break
    if Xp not in p_vals:
        print(Xp)
        break
    Xp += 1
    Xn -= 1

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<int> a(N + 1);
  vector<int> pos(N + 1);
  REP1(i, N)
  {
    cin >> a[i];
    pos[a[i]] = i; // 数字a_iの位置はi
  }
  vector<int> pr(N + 2), ne(N + 2);
  for (int i = 0; i <= N + 1; ++i)
  {
    pr[i] = i - 1; // 位置iにある数字より小さい数字の位置(iより左側)
    ne[i] = i + 1; // 位置iにある数字より小さい数字の位置(iより右側)
  }
  ll ans = 0;
  for (int i = N; i >= 1; --i)
  {
    int j = pos[i];
    ans += (ll)i * (j - pr[j]) * (ne[j] - j);
    pr[ne[j]] = pr[j];
    ne[pr[j]] = ne[j];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,K;
  string S;
  cin>>N>>K>>S;

  int n=S[K-1]-'A';
  S[K-1]='a'+n;
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int alice = 0, bob = 0;
    rep(i, n) {
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    ll a, b;
    cin >> n >> a >> b;
    VL x(n);
    REP(i,n) scanf("%lld", &x[i]);
    ll ans = 0;
    REP(i,n-1){
        ll d = x[i+1] - x[i];
        ans += min(b, a*d);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <algorithm>

const int MAXN = 100005;

int h[MAXN], f[MAXN];

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

    f[0] = 0;
    for (int i = 1; i < n; i++)
        f[i] = std::min(i - 2 < 0 ? INT_MAX : f[i - 2] + std::abs(h[i] - h[i - 2]),
                        i - 1 < 0 ? INT_MAX : f[i - 1] + std::abs(h[i] - h[i - 1]));

    printf("%d\n", f[n - 1]);
    
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
struct Init {Init() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} init;

int main() {
    string s;
    cin >> s;
    ll k;
    cin >> k;
    vs v;
    rep(i, sz(s)) {
        rep(j, 1, k + 1) {
            v.pb(s.substr(i, j));
        }
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    print(v[k - 1]);
}

Measured memory_bytes: 1660
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,a,ans=1,b;
    string d="stay";
    vector<string> vec;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        if(i==0){
            b=a;
        }
        else{
            if(b<a){
                vec.push_back("up");
                b=a;
            }
            else{
                if(b>a){
                    vec.push_back("down");
                    b=a;
                }
                else{
                    vec.push_back("stay");
                }
            }
        }
    }
    rep(i,0,vec.size()){
        if(d=="stay"){
            d=vec[i];
        }
        else{
            if(d=="up"){
                if(vec[i]=="down"){
                    ans++;
                    d="stay";
                }
            }
            else{
                if(d=="down"){
                    if(vec[i]=="up"){
                        ans++;
                        d="stay";
                    }
                }
            }
        }
    }
//    rep(i,0,vec.size()){
//        cout<<vec[i]<<" ";
//    }
//    cout<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 5748
abc = list(map(int, input().split()))
abc.sort()
c = abc[2]
ab = abc[0] + abc[1]
if ab % 2 == 0:
    print((c * 2 - ab) // 2)
else:
    c += 1
    ab += 1
    print((c * 2 - ab) // 2 + 1)

Measured memory_bytes: 8992
#include <stdio.h>
#include <vector>

int main(void){
	
	int n, m, c; scanf("%d %d %d", &n, &m, &c);
	
	std::vector<int> B(m);
	for(int i=0; i<m; i++) scanf("%d", &B[i]);
	
	int count = 0;
	std::vector<std::vector<int>> A;
	for(int i=0; i<n; i++){
		A.push_back(std::vector<int>());
		for(int j=0; j<m; j++){
			int temp; scanf("%d", &temp);
			A[i].push_back(temp);
		}
		int result = c;
		for(int j=0; j<m; j++) result += A[i][j] * B[j];
		if(result > 0) count++;
	}
	printf("%d", count);
	return 0;
}

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

int main(){

    int N;
    cin >> N;

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

    //cout << "N A input OK" << endl;
    // (N-1, N-3, ... 0 or 1) の組になっているかどうか
    // j = (N - A[i] - 1)/2 -> B[j] == 2 or B[j] == 1 ( N 奇数 j == N/2 )
    // N==14 --> 13 11 9 7 5 3 1

    int B[ (N+1)/2 ];
    bool flag;

    
    for(int i=0; i<(N+1)/2; i++) B[i]=0;

    flag=false;
    for(int i=0; i<N; i++){
        int j = (N - A[i] -1)/2;
        //cout << "N i A[i] j" << " " << N <<" " << A[i] << " " << i << " " << j << endl;
        B[j]+=1;       
    }
    
    for(int i=0; i < (N+1)/2 ; i++){
        //cout << B[i] << " ";
        if( N%2==1 && i == (N+1)/2 -1 ){
            if( B[i]!=1 ){
                //cout << " odd last " << endl;
                flag=true;
            }
        }else if(B[i]!=2){
            //cout << " normal " << endl;
            flag=true;
        }
    }
    //cout << endl;
    
    if(flag){
        cout << 0 << endl;
        return 0;
    }

    long long ans;

    ans=1;
    for(int i=0; i< N/2; i++ ){
        ans= ans*2;
        if(ans > 1000000000 + 7 ){
            ans= ans%( 1000000000 + 7);
        }
    }

    //cout << "N ans " << N << " " << ans << endl; 
    ans= ans%( 1000000000 + 7);

    cout << ans << endl;

    /**/
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		
		int maxnum = Math.max(a, Math.max(b, c));
		int maxX = maxnum;
		
		for(int i =0; i<k ; i++) {
			maxX*=2;
		}
		
		System.out.println(a+b+c-maxnum+maxX);
	}

}

Measured memory_bytes: 21460
#include<stdio.h>
int main(void){
	int a,b;
	char op=0;
	
	while(1){
			scanf("%d %c %d",&a,&op,&b);
			if(op=='+'){
				printf("%d\n",a+b);
			}else if(op=='-'){
				printf("%d\n",a-b);
			}else if(op=='*'){
				printf("%d\n",a*b);
			}else if(op=='/'){
				printf("%d\n",a/b);
			}else if(op=='?'){
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<int,int> P;
typedef set<int> S;
ll n;
char maze[25][25];
int dist[25][25];
int sx,sy;
int h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
vector<int> ans;
void bfs(){
    queue<P> que;
    for(int i = 0;i < 25; i++){
        for(int j = 0;j < 25; j++){
            dist[i][j]=-1; //距離の初期化
        }
    }
    que.push(P(sy,sx));
    dist[sy][sx]=0;
    while(que.size()){
        P p=que.front();
        que.pop(); //キューの先頭を取り出す
        for(int i=0;i<4;i++){
            int ny = p.first + dy[i] , nx = p.second + dx[i]; 
            if(0<=nx && nx <= (w-1) && 0<=ny && ny <= (h-1) && maze[ny][nx]!='#' && dist[ny][nx] == -1){
            que.push(P(ny,nx));
            dist[ny][nx]=dist[p.first][p.second]+1;
            }
        }
    }
    int cnt=0;
    for(int i=0;i<25;i++){
        for(int j=0;j<25;j++){
            if(dist[i][j]!=-1) cnt++;
        }
    }
    ans.push_back(cnt);
}
int main(){
    while(1){
        cin>>w>>h;
        if(h==0 && w==0){
            for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
            return 0;
        }
        //入力と初期位置の決定
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>maze[i][j];
                if(maze[i][j]=='@'){
                    sx=j;
                    sy=i;
                }
            }
        }
        //cout<<sx<<" "<<sy<<endl;
        bfs();
    }
    return 0;
}


Measured memory_bytes: 3016
import sys
hit, brow = 0, 0
a, b = [], []
for i in sys.stdin:
    a.append(map(int, i.split()))

for i in xrange(0,len(a),2):
    for j in xrange(4):
        if a[i][j] == a[i + 1][j]:
            hit += 1
        elif a[i + 1][j] in a[i]:
            brow += 1

    print hit, brow
    brow, hit = 0, 0

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#include <cstdlib>
#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 n, m;
    int sum = 0;
    int cnt = 0;
    cin >> n >> m;
    vector<float> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sum = static_cast<float>(sum);
    int fm = m;
    fm = static_cast<float>(fm);
    // cout << "sum = ";
    // cout << sum << endl;
    // cout << "fm = ";
    // cout << fm << endl;
    float x = sum * (1.0 / (4.0 * fm));
    // cout << "x = ";
    // cout << x << endl;
    rep(i, n) {
        if (a[i] >= x) {
            cnt++;
        }
    }
    if (cnt >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S, T; cin >> S >> T;
    S += T.back();
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(m);
	rep(i,m){
		int k;
		cin>>k;
		rep(j,k){
			int s;
			cin>>s;
			s--;
			g[i].push_back(s);
		}
	}
	vector<int> p(m);
	rep(i,m) cin>>p[i];
	int ans=0;
	rep(i,1<<n){
		int now=0;
		rep(j,m){
			int x=0;
			for(auto itr:g[j]){
				if(i & 1<<itr){
					x++;
				}
			}
			if(x%2==p[j]) now++;
		}
		if(now==m){
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> pic(h + 2);
  for (int i = 0; i < w + 2; i++) {
    pic.at(0).push_back('#');
    pic.at(h + 1).push_back('#');
  }
  for (int i = 0; i < h; i++) pic.at(i + 1).push_back('#');
  char c;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c;
      pic.at(i + 1).push_back(c);
    }
  }
  for (int i = 0; i < h; i++) pic.at(i + 1).push_back('#');
  for (int i = 0; i < h + 2; i++) cout << pic.at(i) << endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef double db;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<PII> VPI;
typedef vector<long long> VL;
const	int N = 100005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e18;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

void setIO(string a){
#ifndef LOCAL
	freopen((a + ".in").c_str(), "r", stdin);
	freopen((a + ".out").c_str(), "w", stdout);
#endif
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int n;
char s[100005];
int stt[35],ans;

int main(){
#ifdef LOCAL
	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	
	scanf("%s",s+1);
	n=strlen(s+1);
	REP(i,1,n) stt[s[i]-'a']++;
	FOR(j,0,26) if(stt[j]>stt[ans]) ans=j;
	if(n-stt[ans]>=2*stt[ans]-2) puts("YES"); else puts("NO");

	return 0;
}






















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

long long  gcd(long long a, long long  b) {
    if (b == 0)  return a;
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b)*b;
}


int main() {
    int n;
    cin>>n;
    long long ans =1;
    for(int i=0;i<n;i++){
        long long t;
        cin>>t;
        ans=lcm(ans,t);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;

const int nax = 5001;
vi adj[nax];
vector <bool> vis;
vll c;
vll pont;

void solve(int u){
  vis[u]=true;
  for(int v:adj[u]){
    pont.push_back(c[v]);
    if(!vis[v])
      solve(v);
  }
  vis[u]=false;
}
int main(){
  fastio;

  int n,k;
  cin >> n >> k;
  vi p(n+1);
  c.resize(n+1);
  vis.assign(n+1,false);

  for(int i=1;i<=n;i++){
    cin >> p[i];
    adj[i].push_back(p[i]);
  }

   for(int i=1;i<=n;i++)
    cin >> c[i];

  ll ans = -1e18;

  for(int i=1;i<=n;i++){
    pont.clear();
    solve(i);
    ll len = pont.size();
    if(len >= k){
      ll mx = -1e18;
      ll sum = 0;
      for(int j=0;j<k;j++){
        sum += pont[j];
        mx = max(mx,sum);
      }
     ans = max(ans,mx);
    }else{  
      ll sum = 0;
      ll mx = -1e18;
      for(ll x:pont){
        sum += x;
        mx = max(mx,sum);
      }
      if(sum <= 0){
        ll rest = k%len;
        mx = max(mx,sum);
        for(int j=0;j<rest;j++){
          sum += pont[j];
          mx = max(mx,sum);
        }
        ans = max(ans,mx);
      }else{
        ll times = k/len;
        sum *= times;
        mx = max(mx,sum);
        ll rest = k%len;
        for(int j=0;j<rest;j++){
          sum += pont[j];
          mx = max(mx,sum);
        }
        sum = 0;
        for(ll x:pont){
          sum += x;
        }
        times--;
        sum *= times;
        mx = max(mx,sum);
        for(int j=0;j<len;j++){
          sum += pont[j];
          mx = max(mx,sum);
        }
        ans = max(ans,mx);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

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

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}

int main() {
  double c,x;
  cin >> c >> x;
  cout << c/x<<endl;
  return 0;
}
 


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[5]={0},n;
	char f;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>f;
		if(f=='P') a[1]=1;
		if(f=='W') a[2]=1;
		if(f=='G') a[3]=1;
		if(f=='Y') a[4]=1;
	}
	if((a[1]+a[2]+a[3]+a[4])==4) cout<<"Four";
	else cout<<"Three";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

long long n, lis[100005], cnt[100005], cur, ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  FOR (i, 1, n) cin >> lis[i];
  ans = 1;
  cur = 0;
  FOR (i, 1, n - 1) {
  	long long tmp = i - (lis[i] + 1) / 2;
  	cur = max(cur, tmp);
  	cnt[cur]++;
  }
  cur = 1;
  REP (i, n) {
  	cur += cnt[i];
  	ans *= cur;
  	cur--;
  	ans %= mod;
  }
  cout << ans;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

ll sum(int i)
{
        ll r = 0;
        while (i != 0)
        {
                r += (i % 10);
                i /= 10;
        }
        return r;
}

void solve()
{
        int n, a, b; cin >> n >> a >> b;
        ll res = 0;
        for (int i = 1; i <= n; ++i)
        {
                if (sum(i) >= a && sum(i) <= b) 
                {
                        res += i;
                }
        }
        cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s, t := Scanner(), Scanner()
	fmt.Println(t + s)
}


Measured memory_bytes: 1772
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include <bits/stdc++.h>
using namespace std ;
 
 
typedef long long                ll;
typedef long double              ld;
typedef unsigned long long       ull;
typedef pair <int,int>           pii;
typedef pair <ll,ll>             pll;
typedef vector <int>             vi;
typedef vector <ll>              vll;
typedef vector <vector <int> >   vvi;
 
inline int    Int(){int x; cin >> x; return x;}
inline ll     Long(){ll x; cin >> x; return x;}
inline float  Float(){float x; cin >> x; return x;}
inline double Double(){double x; cin >> x; return x;}
inline void   Yes(){cout << "Yes" << endl;}
inline void   No(){cout << "No" << endl;}
inline void   YES(){cout << "YES" << endl;}
inline void   NO(){cout << "NO" << endl;}
 
const int N             =(int)2e5 + 5;
const int maxN          =(int)1e6 + 6;
const ll  Mod           =(ll)1e9 + 7;
const int inf           =(int)2e9;
const ll  Inf           =(ll)1e18;
 
#define     T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b > e); i =i+1-2*(b > e))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
#define     biday       return 0 
 
 
int main(){
	int N,M,A,i,sum=0;
	cin >> N >> M;
	for(i = 0; i < M; i++)
	{
		cin >> A;
		sum = sum + A;
	}
	if(N>=sum)cout << N-sum << endl;
	else cout << -1 << endl;
    

   





    biday;
}
 
//...............BYE BYE................


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

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 3e3 + 2, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int n;
double dp[N];

class ICoins {
public:
    void init() {
        clr(dp,0.0);
    }

    void solve(istream &cin, ostream &cout) {
        init();
        cin >> n;
        dp[0] = 1;
        for (int i = 0; i < n; ++i) {
            double p;
            cin >> p;
            for (int j = i + 1; j >= 0; j--)
                dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
        }
        double ans = 0.0;
        for (int heads = 0; heads <= n; heads++) {
            int tails = n - heads;
            if (heads > tails)
                ans += dp[heads];
        }
        cout << fixed << setprecision(10) << ans <<  el;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	ICoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef long long ll;

const int p=1e9+7;

inline int power(int x, int y){
	int s=1;
	while (y){
		if (y&1) s=(ll)s*x%p;
		x=(ll)x*x%p; y>>=1;
	}
	return s;
}

const int N=1e6+10;

int f[N];

int main(){
	int n,h,d;
	cin>>n>>h>>d;
	int fac=1,sfac=0;
	for (int i=1;i<=n;i++){
		fac=(ll)fac*i%p;
		sfac=(sfac+fac)%p;
	}
	f[0]=fac;
	for (int i=1;i<=h;i++)
		f[i]=((ll)(f[i-1]-(i-d-1<0?0:f[i-d-1]))*sfac+f[i-1])%p;
	cout<<(ll)(f[h]-f[h-1]+p)*power(sfac,p-2)%p;
	return 0;
}


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

long N, A, B;
vector<long> H;

bool f(int mid) {
  vector<long> V = H;
  for (auto &v : V) v -= (long) B * mid;
  long cnt = 0, tmp = A - B;
  for (auto v : V) if (v > 0) cnt += (v + tmp - 1) / tmp;
  return (cnt <= mid) ? true : false;
}

int main() {
  cin >> N >> A >> B;
  H.resize(N);
  for (auto &h : H) cin >> h;
  int ok = 1e9, ng = -1;
    while (ok - ng > 1) {
      int mid = (ok + ng) / 2;
      (f(mid)) ? ok = mid : ng = mid;
    }
  cout << ok << "\n";
}

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

using namespace std;





int  main() {
    
  string s;
  cin>>s;
  
    unsigned long long sum=0;
    int arr[100005];
  for(int i=0;i<(int)s.length();i++)
  {
      arr[i] = s[i] - '0';
      sum+=arr[i];
  }

 
  if(sum == 0)
  cout<<"Yes";
  else if(sum%9==0)
  cout<<"Yes";
  else
  cout<<"No";
  

  
  
    
    return 0;
   
}

Measured memory_bytes: 3760
<?php

fscanf(STDIN, "%d", $n);

$prev;
$i = 1;
$cnt = 0;
while ($n > 0) {
    $i *= 26;
    $prev = $n;
    $n -= $i;
    ++$cnt;
}
/* echo "prev: $prev, cnt: $cnt", PHP_EOL; */

// cnt桁で先頭からprev番目を求める
if ($cnt == 1) {
    echo chr(ord('a') + $prev - 1), PHP_EOL;
    return;
}

$ans = [];
for ($i = 0; $i < $cnt; ++$i) {
    $ans[] = 'a';
}

$i = 0;
--$prev;
while ($prev > 0) {
    $a = $prev % 26;
    /* $ans .= getChar($a); */
    $prev = intdiv($prev, 26);
    --$cnt;
    $ans[$cnt] = chr(ord('a') + $a);
/* echo "しょう: $prev, あまり: $a", PHP_EOL; */
}

echo implode('', $ans), PHP_EOL;

function getChar($n) {
    return chr($n + 96);
}


Measured memory_bytes: 16256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int l;
cin>>l;
cout<<fixed<<setprecision(15)<<(double)(l*l*l)/27;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

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

int main(int argc,char **argv)
{
	int a = 0, b = 0, t = 0;
	int k = 0;
	scanf("%d %d %d",&a,&b,&t);

	t = t + 0.5;

	t = t / a;
	k = t * b;

	printf("%d",k);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;

	ll n , k ;
	cin>>n>>k;
	ll arr[n];
	ll sum=0;
	for(ll i=0;i<n;i++)cin>>arr[i];
	sort(arr,arr+n,greater<ll>());
	for(ll i=k;i<n;i++)sum+=arr[i];
	cout<<sum<<endl;


	return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n ;
	cin >> n ;
	map<int,int> even;
	map<int,int> odd;
	rep(i,n){
		int a ;
		cin >> a ;
		if(i%2==0){
			even[a] ++;
		}
		else odd[a] ++ ;
	}
	vector<pair<int,int>> ODD(0);
	vector<pair<int,int>> EVEN(0);
	for(auto x:even){
		EVEN.push_back(make_pair(x.second,x.first));
	} 
	for(auto x:odd){
		ODD.push_back(make_pair(x.second,x.first));
	} 
	EVEN.push_back(make_pair(0,-1));
	ODD.push_back(make_pair(0,-1));
	SORT(EVEN);
	rSORT(EVEN);
	SORT(ODD);
	rSORT(ODD);
	int ans ;
	if(ODD[0].second == EVEN[0].second){
		//両方値が一緒の場合
		 ans = min(n-ODD[0].first-EVEN[1].first,n-ODD[1].first-EVEN[0].first);
	} else {
		ans = n - ODD[0].first - EVEN[0].first;
	}
	cout << ans << endl;

}


Measured memory_bytes: 6136
#include <stdio.h>

int selection(int a[], int l,int r){
    int i, j;
    int count = 0;
    for(i = l;i < r; i++){
        int min = i;
        for(j = i+1; j<=r; j++){
            if(a[j]<a[min]) min = j;
        }
        if(min != i){
            int temp = a[min];
            a[min] = a[i];
            a[i]= temp;
            count ++;
        }
    }
    return count;
}

int main()
{
    int i;
    int N;
    int A[100];
    scanf("%d", &N);
    for (i = 0; i < N ;i++) {
        scanf("%d", &A[i]);
    }

    int count = selection(A, 0, N-1);
    for (i = 0; i < N ;i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);

    return 0;
}

Measured memory_bytes: 1828
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a,b,c,d = LI()
    b -= a
    n -= 1
    if b < -n*d or b > n*d:
        print("NO")
        return
    m = n*d
    x = -m
    y = n*(d-c)
    z = max(0,(n-1)*(c-d)+2*c)
    b -= x
    b %= (y+z)
    if b <= y:
        print("YES")
    else:
        print("NO")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
N,T = list(map(int,input().split()))

A =[list(map(int,input().split())) for i in range(N)]

A.sort(key = lambda x:x[0])

INF = float("inf")

DP = [[-INF]*(T+3001) for i in range(N+1)]

DP[0][0] = 0

for i in range(N):
    for j in range(T):
        DP[i+1][j] = max(DP[i+1][j],DP[i][j])
        DP[i+1][j+A[i][0]] = max(DP[i+1][j+A[i][0]],DP[i][j+A[i][0]],DP[i][j]+A[i][1])
score = 0
for i in range(N):
    for j in range(T+A[i][0]):
        score = max(DP[i+1][j],score)

print(score)

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

#define ll long long

using namespace std;

const ll N = 1e6, mod = 1e9 + 7;

ll x, y, f[N + 123], ans = 0;

ll factorial(ll n) {
    ll ret = 1;
    for (ll i = 1; i <= n; ++i) {
        ret = (ret * i) % mod;
    }
    return ret;
}

ll inv_mod(ll n) {
    ll a = n % mod, b = mod - 2, ret = 1;
    while (b > 0) {
        if (b & 1) ret = (ret * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ret;
}

ll nPr(ll n, ll r) {
    ll ret = 1;
    for (ll i = n; i >= n - r + 1; --i) {
        ret = ret * (i % mod) % mod;
    }
    return ret * 1ll;
}


ll nCr(ll n, ll r) {
    if (r > n - r) {
        return nCr(n, n - r);
    }
    return nPr(n, r) * inv_mod(factorial(r)) % mod;
}

int main () {
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        printf ("%d", 0);
        exit (0);
    }f[1] = 1;
    for (int i = 2;i <= N;i ++) {
        f[i] = (f[i - 1] * 1ll * i) % mod;
    }
    for (int i = 0;i <= min (x, y);i ++) {
        ll n = i, m = x - i;
        if (m % 2 == 1)continue;
        else m /= 2;
        if (n + 2 * m == x && 2 * n + m == y) {
            if (n < 0 || m < 0) {
                cout << 0;
                exit (0);
            }
            cout << nCr (n + m, n);
            exit (0);
        }
    }cout << 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <int> v[100005];
vector <ll> w[100005];
int sz[100005],son[100005],n,tag=0;
ll ans=0;
inline int read()
{int x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
inline ll readll()
{ll x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10ll+c-'0',c=getchar();
return x;
}
void dfs1(int pos,int fa)
{int i;sz[pos]=1;
for (i=0;i<v[pos].size();i++)
{if (v[pos][i]!=fa)
{dfs1(v[pos][i],pos);
sz[pos]+=sz[v[pos][i]];
son[pos]=max(son[pos],sz[v[pos][i]]);
int p=min(sz[v[pos][i]],n-sz[v[pos][i]]);
ans+=2ll*((ll)p)*w[pos][i];
}
}
son[pos]=max(son[pos],n-sz[pos]);
}
ll mine;
void dfs2(int pos,int fa)
{int i;sz[pos]=1;
for (i=0;i<v[pos].size();i++)
{if (v[pos][i]!=fa)
{dfs2(v[pos][i],pos);
sz[pos]+=sz[v[pos][i]];
int p=min(sz[v[pos][i]],n-sz[v[pos][i]]);
if (2*p==n) {mine=w[pos][i];tag=1;}
}
}
}
int main (){
	int i,a,b,j;
	ll val;
	n=read();
	for (i=1;i<n;i++)
	{a=read();b=read();val=readll();
	v[a].push_back(b);w[a].push_back(val);
	v[b].push_back(a);w[b].push_back(val);
	}
	dfs1(1,0);
	int minn=233333,pl=-1;
	for (i=1;i<=n;i++)
	{if (son[i]<minn)
	{minn=son[i];pl=i;}
	}
	dfs2(pl,0);
	if (!tag)
	{mine=2333333333ll;
	for (i=1;i<=n;i++)
	{if (son[i]<=n/2)
	{for (j=0;j<v[i].size();j++)
	{mine=min(mine,w[i][j]);}
	}
	}
	}
	ans-=mine;
	printf ("%lld",ans);
	return 0;
}

Measured memory_bytes: 18688
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = (1LL << 63);


int main() {
	int n, m;
	cin >> n >> m;
	whei(int) G(n);
	map<Pint, bool> d;
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if (d[Pint(a, b)] || d[Pint(b, a)])continue;
		d[Pint(a, b)] = 1;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int tag = -1;
	hei(bool) T(n, false);
	map<int, int> Z;

	rep(i, 0, n) {
		if (T[i])continue;
		tag++;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int p = que.front(); que.pop();
			T[p] = true;
			Z[tag]++;
			for (auto x : G[p]) {
				if (!T[x]) {
					T[x] = true;
					que.push(x);
				}
			}
		}
	}
	int ans = 0;
	rep(i, 0, tag+1)ans = max(Z[i], ans);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 39476
#include<bits/stdc++.h>
using namespace std;
int n;
void dfs(string s, char ch) {
    if(s.length() == n) {
        cout << s << endl;
    } else {
        for(char i = 'a'; i <= ch; ++ i){
            dfs(s + i, i == ch ? (ch + 1) : ch);
        }
    }
}
int main() {
    cin >> n;
    dfs("", 'a');
    system("pause");
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
int c[100009];

int main(){
  int N;
  cin >> N;
  vector<int> A(N+10),B(N+10),C(N+10);
  int sum=0;
  for(int i=1;i<=N;i++){cin >> A[i];}
  for(int i=1;i<=N;i++){cin >> B[i]; sum+=B[i];}
  for(int i=1;i<=N-1;i++){cin >> C[i];}
  for(int i=1;i<N;i++){
    if(A[i]+1==A[i+1]){sum+=C[A[i]];}
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
    int n,m;
    cin >> n >> m;
    bool flag[n-1];
    rep(i,n-1)flag[i]= false;
    vector<pair<int,int>> a;
    rep(i,m){
        int w,h;
        scanf("%d %d", &w,&h);
        a.emplace_back(h,w);
    }
    sort(a.begin(),a.end());
    int ans = 0;
    rep(i,a.size()){
        for(int j = a[i].second-1;j < a[i].first-1;j++){
            if(flag[j] == true)break;
            if(j == a[i].first-2){
                ans++;
                flag[j] = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
n,l=[int(x) for x in input().split()]
ringo=list(range(l,l+n))

if ringo[0]>0 and ringo[-1]>0:
  print(sum(ringo[1:]))
elif ringo[0]<0 and ringo[-1]<0:
  print(sum(ringo[:-1]))
else:
  print(sum(ringo))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef long long int ll;
            const ll N =  1e6+5;
            const ll mod = 1e9+7;
            const ll inf = 1e18;
            ll   n  , k  , m  , l , r  , x , y  , q , u , z  , a[N] ;

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt , pt %= mod;
        if(n&1)
            pt *= a  ,pt %= mod;
        return pt;
    }


    int main()
    {
         IOS;
         int ts =1;
       ///  cin >> ts ;
         while(ts--)
         {
            cin >> n;
            rep(i,0,n) cin >> a[i];
            ll ans =0  , mx = a[0];
            rep(i,1,n)
            {
                if(a[i] < mx)
                {
                    ans += mx - a[i];
                }
                mx = max(mx , a[i]);
            }
            cout << ans << endl;
         }
    }


Measured memory_bytes: 5172