akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

const int INF = 1e18;
int n;
int val[200005];
int ans[200005];
int d[200005];
vector<int> ed[200005];

void dfs(int u, int p)
{
    int x = lower_bound(d+1, d+n+1, val[u]) - d;

    int tmp = d[x];
    d[x] = min(d[x], val[u]);
    ans[u] = max(x-1, ans[p]);


    for (auto v : ed[u])
    {
        if (v == p)
            continue;
        dfs(v, u);
    }
    d[x] = tmp;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

//    freopen("depart.inp", "r", stdin);
//    freopen("depart.out", "w", stdout);

    cin >> n;

    for (int i = 1; i <= n; i++)
        d[i] = INF;
    d[1] = 0;

    for (int i = 1; i <= n; i++)
        cin >> val[i];
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ed[a].push_back(b);
        ed[b].push_back(a);
    }

    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        cout << ans[i] << "\n";
}


Measured memory_bytes: 33572
N=int(input())
X=input()
def fx(n,c):
    if c==0:
        return 0
    b=n%c
    if b==0:
        return 1
    if b==1 or b==2:
        return 2
    t=bin(b).count("1")
    return fx(b,t)+1
c=X.count("1")
n=int(X,2)
lp=[1]*N
lm=[1]*N
for i in range(N-2,-1,-1):
    lp[i]=2*lp[i+1]%(c+1)
    if c==1:
        lm[i]=1
    else:
        lm[i]=2*lm[i+1]%(c-1)
np=n%(c+1)
if c>1:
    nm=n%(c-1)
else:
    nm=1
for i in range(N):
    if X[i]=="0":
        print(fx(np+lp[i],c+1))
    else:
        print(fx(nm-lm[i],c-1))

Measured memory_bytes: 80408
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans;
  if(b > n){
  	ans = a * n / b;
  }
  else{
  	ans = a * (b - 1) / b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    """
    heapqを使う発想は正しかったが、(Ai, *, *)を全てキューに突っ込んで
    Aiを削除しようとしたのが敗因。

    キューの中で(Ai + Bj + Ck)だけではなく(Ai + Bj + Ck, i, j, k)の
    添字まで管理しておけば、最大値を取り出した後にキューに突っ込むのは
        (A(i+1) + Bj + Ck, i+1, j, k)
        (Ai + B(j+1) + Ck, i, j+1, k)
        (Ai + Bj + C(k+1), i, j, k+1)
    の3つだけでよくなる。。。
    """

    q =[(-A[0]-B[0]-C[0], 0, 0, 0)]
    pushed = set([])
    for _ in range(K):
        val, i, j, k = heappop(q)
        print(-val)
        if i < X - 1 and (i+1, j, k) not in pushed:
            heappush(q, (-A[i+1]-B[j]-C[k], i+1, j, k))
            pushed.add((i+1, j, k))
        if j < Y - 1 and (i, j+1, k) not in pushed:
            heappush(q, (-A[i]-B[j+1]-C[k], i, j+1, k))
            pushed.add((i, j+1, k))
        if k < Z - 1 and (i, j, k+1) not in pushed:
            heappush(q, (-A[i]-B[j]-C[k+1], i, j, k+1))
            pushed.add((i, j, k+1))
        #print(q)



if __name__ == "__main__":
    main()


Measured memory_bytes: 56668
#include<bits/stdc++.h>
 
using namespace std;
/*
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
typedef long long ll ;
const ll mk = 200055;
const ll logn  = 29;
const ll mod = 1e9 + 7;
 
#define endl             "\n"
#define IOS              ios::sync_with_stdio(0); cin.tie(0);
#define fi               first
#define se               second
#define pii              pair<ll,ll>
#define mp               make_pair
#define pq               priority_queue<int, std::vector<int>, std::greater<int> >
#define rep(i, n)        for(int i = 0 ; i < n ; i++)
#define repf(i , n )     for(int i = 1; i <= n ; i++)
#define pb               push_back

int dp[1 << 20] ;
int a[1 << 20] , n ;

void init() {
	cin >> n ; 
	for(int i = 0 ; i < (1 << n) ; i++) cin >> a[i];
	for(int i = 1 ; i < (1 << n) ; i++) {
		int x = 0 , y = 0; 
		for(int sub_mask = i ; ; sub_mask = (sub_mask - 1) & i) 
		{
			if(a[sub_mask] > y) x = y, y = a[sub_mask];
			else if(a[sub_mask] > x) x = a[sub_mask];
			if(!sub_mask)  break;
		}
		//cout << x << ' ' << y << ' ';
		dp[i] = max(dp[i - 1] , x + y);
		cout << dp[i] << endl; 
	}
}

signed main() {
    init();
}

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

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

	int i = x / 500;
	x -= (500 * i);
	int j = x / 5;

	cout << i*1000 + j*5 << endl;

	return 0;
}


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

typedef long long ll;

int main()
{
	//freopen("input.txt","r",stdin);
	ll i,j,k,n,tab[310][310];
	cin>>n;
	for (i=1;i<=n;i++)
	 for (j=1;j<=n;j++)
	  cin>>tab[i][j];
	bool cek[310][310];
	memset(cek,0,sizeof(cek));
	ll sum=0;
	for (i=1;i<=n;i++)
	 for (j=1;j<=n;j++)
	 {
	 	if (i==j) continue;
	 	if (cek[i][j]) continue;
	 	//cout<<i<<" "<<j<<" ij\n";
	 	//sum+=tab[i][j];
	 	//cek[i][j]=1;
	 	cek[j][i]=1;
	 	bool ada=true;
	 	for (k=1;k<=n;k++)
	 	{
	 		if (k==j) continue;
	 		if (k==i) continue;
	 		if (tab[k][j]+tab[k][i]==tab[i][j])
	 		{
	 			//cout<<k<<" "<<i<<" "<<j<<" masuk\n";
	 			if (!cek[k][j] && !cek[j][k])
	 			 cek[k][j]=1;
	 			if (!cek[k][i] && !cek[i][k])
	 			 cek[k][i]=1;
	 			cek[i][j]=1;
	 			ada=false;
			}
			if (tab[k][j]+tab[k][i]<tab[i][j])
			{
				cout<<-1<<"\n";
				return 0;
			}
		}
	 }
	for (i=1;i<=n;i++)
	 for (j=1;j<=n;j++)
	  if (!cek[i][j])
	   {
	   		sum+=tab[i][j];
	   		//cout<<i<<" "<<j<<" tambah\n";
	   }
	cout<<sum<<"\n";
}

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

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

int main(){
  int   n;
  cin >> n;
  double x;
  
  if(n%2==0){
     x = n/2;
  }
    else {
       x = n/2+1;
    }
  double  y = x/n;
  cout<< y << endl;
  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const ll N = 1e5 + 7;
const ll mod = 1e18 + 7;

int n, m, a[N], x;
int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGn
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> n >> m;
    priority_queue < int > q;
    ll ans = 0;
    for ( int i = 0; i < n; i++ ) {
        cin >> x;
        ans += x;
        q.push(x);
    }
    for ( int i = 0; i < m; i++ ) {
        int v = q.top();
        q.pop();
        ans -= v - (v / 2);
        q.push(v / 2);
    }
    cout << ans;
}


Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll r,g,b,n;
    cin>>r>>g>>b>>n;

    ll ans=0;
    FOR(i,0,n/r+1){
      FOR(j,0,n/g+1){
        if((n-i*r-j*g)%b == 0 && (n-i*r-j*g)>=0){
          ans++;
//          cout<<"i = "<<i<<" j = "<<j<<" "<<n-i*r-j*g<<endl;
        }
      }
    }
    cout<<ans<<endl;
}


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

using namespace std;

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

	int count = 0;
	if (A >= B) {
		count += A;
		A = A - 1;
	}
	else {
		count += B;
		B = B - 1;
	}


	if (A >= B) {
		count += A;
		A = A - 1;
	}
	else {
		count += B;
		B = B - 1;
	}

	cout << count << endl;
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(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 pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int n,m;
vi node[8];

int solve(){
  queue<pair<vector<bool>, int>> qt;
  vector<bool> start(8);
  REP(i,8) start[i] = false;
  start[0] = true;
  qt.push(mp(start, 0));
  int ans = 0;
  for(;!qt.empty();){
	auto f = qt.front();
	qt.pop();
	auto status = f.first;
	int nowpoint = f.second;
	//cout << status << " " << nowpoint << endl;
	bool ok = true;
	REP(i,n) if(!status[i]) ok = false;
	if(ok){
	  ans++;
	  continue;
	}
	REP(i,node[nowpoint].size()){
	  int next = node[nowpoint][i];
	  if(status[next]) continue;
	  vector<bool> nextstatus = status;
	  nextstatus[next] = true;
	  qt.push(mp(nextstatus,next));
	}
  }
  return ans;
}
int main(){
  cin >> n >> m;
  REP(i,m){
	int a,b;
	cin >> a >> b;
	node[a-1].pb(b-1);
	node[b-1].pb(a-1);

  }
  cout << solve() << endl;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a, b, c, d, e, k;
	scanf("%d\n%d\n%d\n%d\n%d\n%d", &a, &b, &c, &d, &e, &k);
	if (e - a > k)
	{
		printf(":(");
	}
	else
	{
		printf("Yay!");
	}
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
int n,m,c[1010],d[1010],dp[1010][1010];
int main()
{
	cin>>n>>m;
	FOR(i,1,n+1)cin>>d[i];
	FOR(i,1,m+1)cin>>c[i];
	FOR(i,1,n+1)dp[i][i]=dp[i-1][i-1]+c[i]*d[i];
	if(n==m)
	{
		cout<<dp[n][m]<<endl;
		return 0;
	}
	else
	{
		FOR(j,2,m+1)
		{
			dp[1][j]=min(dp[1][j-1],d[1]*c[j]);
		}
		FOR(i,2,n+1)
		{
			FOR(j,i+1,m+1)
			{
				dp[i][j]=min(dp[i-1][j-1]+d[i]*c[j],dp[i][j-1]);
			}
		}
		cout<<dp[n][m]<<endl;
		return 0;
	}
}

Measured memory_bytes: 6284
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 105;

int w[N], v[N];
int dp[N][100005];

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i < 100005; i++)
        dp[0][i] = inf;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < 100005; j++) {
            dp[i][j] = dp[i-1][j];
            if (j >= v[i])
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < 100005; i++)
        if (dp[n][i] <= k) ans = i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80128
import scala.io.Source.stdin

object Main extends App {
  for( i<- stdin.getLines ) {
    val n = i.split(" ").map(_.toDouble)
    val (a,b,c,d,e,f) = (n(2)-n(0),n(4)-n(0),n(3)-n(1),n(5)-n(1),n(6)-n(0),n(7)-n(1))
    val g = a*d-b*c
    val x = (e*d-b*f)/g
    val y = (a*f-e*c)/g
    if(x<=0 || y <= 0 || x+y>=1) println("NO") else println("YES")
  }
}

Measured memory_bytes: 44212
n, a, b = map(int, input().split())
tmp = (n % (a+b))

if a == 0:
    print('0')
elif tmp == 0:
    print(a * (n // (a+b)))
else:
    if tmp < a:
        print(a * (n // (a+b)) + tmp)
    else:
        print(a * (n // (a+b)) + a)


Measured memory_bytes: 3060
n,k = map(int,input().split())
from collections import Counter
s = list(map(int,input().split()))
num = Counter(s)
if len(num) <= k:
    print(0)
else:
    n = len(num) - k
    a = 0
    ans = 0
    for i in sorted(num.values()):
        if a == n:
            break
        
        ans += i
        a += 1
        
    print(ans)

Measured memory_bytes: 34956
S = input()

mem = True
for i, s in enumerate(S):
    if (i+1)%2 == 1:
        if not s in ['R', 'U', 'D']:
            mem *= False
    else:
        if not s in ['L', 'U', 'D']:
            mem *= False
if mem:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38512
N = int(input())
say = []
for i in range(N):
    A = int(input())
    t = []
    for j in range(A):
        s = list(map(int,input().split()))
        t.append(s)
    say.append(t)

a = 0
for i in range(2**N):
    judge = 1 
    
    for j in range(N):
        if judge == 0:
            break
        if ((i >> j) & 1):
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) != say[j][k][1]:
                    judge = 0
    
    if judge:
        c = bin(i).count("1")
        a = max(a,c)
print(a)

Measured memory_bytes: 42224
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int H, N;
int S;

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

  rep( i, N )
  {
    int A;
    scanf( "%d", &A );

    S += A;
  }

  puts( S >= H ? "Yes" : "No" );

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
const int SIZE=100001;
int a[SIZE]={00},b[SIZE]={00},c[SIZE]={00};

int main() {
	while(true){
		int n=0,k=0;
		cin >> n >> k;
		if(n==0) break;
		int max;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		for(int i=1;i<=n;i++){
			b[i]=b[i-1]+a[i];
		}
		for(int i=0;i<=n-k;i++){
			c[i]=b[i+k]-b[i];
		}
		max=c[1];
		for(int i=0;i<n;i++){
			if(max<c[i]){
				max=c[i];
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

  switch (N % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon";
      break;
    default:
      cout << "bon";
      break;
  }
  cout << endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

using namespace std;

int main(){
    int N, K, R, S, P; 
    string T;
    char c;
    cin >> N >> K >> R >> S >> P >> T;
    vector<int> v(N,0);
    int score = 0;
    rep(i,N){
        c = T[i];
        if(c == 'r'){
            if((i >= K && v[i-K] != 3) || i < K){
                v[i] = 3;
                score += P;
            }
        }else if(c == 's'){
            if((i >= K && v[i-K] != 1) || i < K){
                v[i] = 1;
                score += R;
            }
        }else{
            if((i >= K && v[i-K] != 2) || i < K){
                v[i] = 2;
                score += S;
            }
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define SZ(a) ((int)(a).size())
#define ALL(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const int N=131080;
int n,l[N],r[N];LL v[N];vector<pii>f[N];
pii g[N],h[N],tmp[N];
bool chk(LL mid){
	per(k1,n,1){
		LL lim=mid+2*v[k1];
		f[k1].clear();
		if(!l[k1]){f[k1].PB(MP(v[k1],v[k1]));continue;}
		int i,j,gl=0,hl=0;
		for(i=0,j=0;i<SZ(f[l[k1]]);++i){
			while(j<SZ(f[r[k1]])&&f[l[k1]][i].first+f[r[k1]][j].second>lim)++j;
			if(j>=SZ(f[r[k1]]))break;
			g[++gl]=MP(f[l[k1]][i].second,f[r[k1]][j].first);
			h[++hl]=MP(f[r[k1]][j].first,f[l[k1]][i].second);
		}
		reverse(g+1,g+1+hl);
		int len=merge(g+1,g+1+gl,h+1,h+1+hl,tmp+1)-tmp-1;
		if(!len)return 0;
		rep(i,1,len){
			if(i==1||tmp[i].second<f[k1].back().second)f[k1].push_back(tmp[i]);
		}
//		printf("%d:",k1);
//		for(auto x:f[k1])printf("|%d %d|",x.first,x.second);puts("");
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	LL L=0,R=0,ans;
	rep(i,2,n){
		int k1,k2;scanf("%d%d",&k1,&k2);
		if(l[k1])r[k1]=i;else l[k1]=i;
		v[i]=k2,R+=k2,v[i]+=v[k1];
	}
//	chk(16);
	while(L<=R){
		LL mid=(L+R)>>1;
		if(chk(mid))ans=mid,R=mid-1;
		else L=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 32372
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	ll x[N+1], y[N+1];
	x[0] = 0, y[0] = 0;
	for (int i = 1; i <= N; i++) x[i] = a[i-1] + x[i-1];
	for (int i = 1; i <= N; i++) y[i] = a[N-1-(i-1)] + y[i-1];

	ll ans = LINF;
	for (int i = 1; i < N; i++) {
		ans = min(ans, abs(x[i] - y[N-i]));
	}

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


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

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

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int x;
    cin >> x;
    ans += min(2 * x, 2 * (K - x));
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  vector<ll> p(n);
  REP(i,n) cin>> p[i];
  VSORT(p)
  ll p_min = INF;
  REP(i,n-k+1){
    ll tmp=p[i+k-1] - p[i];
    p_min = min(p_min,tmp);
  }
  cout << p_min << endl;
}


Measured memory_bytes: 1152
/**
*    author:  Dooloper
*    created: 17.09.2020 22:59:02
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int di[] = {0,-1,0,1};
int dj[] = {1,0,-1,0};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int h,w,sh,sw,gh,gw;
  cin >> h >> w >> sh >> sw >> gh >> gw;
  sh--;sw--;gh--;gw--;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];

  deque<P> q;
  q.emplace_front(sh,sw);
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  dist[sh][sw] = 0;
  while(!q.empty()){
    int i = q.front().first;
    int j = q.front().second;
    int t = dist[i][j];
    q.pop_front();
    for(int v = 0; v < 4; v++){
      if(i+di[v] < 0 || i+di[v] >= h || j+dj[v] < 0 || j+dj[v] >= w) continue;
      if(s[i+di[v]][j+dj[v]] == '#') continue;
      if(dist[i+di[v]][j+dj[v]] <= t) continue;
      dist[i+di[v]][j+dj[v]] = t;
      q.emplace_front(i+di[v],j+dj[v]);
    }
    for(int ci = -2; ci <= 2; ci++){
      for(int cj = -2; cj <= 2; cj++){
        if(i+ci < 0 || i+ci >= h || j+cj < 0 || j+cj >= w) continue;
        if(s[i+ci][j+cj] == '#') continue;
        if(dist[i+ci][j+cj] <= t+1) continue;
        dist[i+ci][j+cj] = t+1;
        q.emplace_back(i+ci,j+cj);
      }
    }
  }
  int ans = (dist[gh][gw]==INF)?-1:dist[gh][gw];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8640
import numpy as np

N, X = map(int, input().split())
L = list(map(int, input().split()))
# D = [np.array([])]
D = [0, 0]

for i in range(2, N + 2):
    D.append(D[i - 1] + L[i - 2])

D2 = np.array(D)    # numpy配列D2を作成

D3 = D2[D2 <= X]    # numpyを使ってX以下の要素を抽出

print('{}'.format(D3.size - 1))    # 回数を出力(D3[0]は不要なのでｰ1)



Measured memory_bytes: 14424
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif

static const int MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}


static void ABC109A_ABC333();

#if 1
int main()
{
	ABC109A_ABC333();
	fflush(stdout);
	return 0;
}
#endif

static void ABC109A_ABC333()
{
	int A, B;
	get2int(A, B);

	printf("%s\n", ((A * B) % 2) ? "Yes" : "No");
}


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

int main(){
	int i; long long int k, res[55];
	cin >> k;
	for(i = 1; i <= 50; ++ i)
		res[i] = k / 50 + 49;
	k %= 50;
	for(i = 1; i <= k; ++ i)
		res[i] += 51 - k;
	for(; i <= 50; ++ i)
		res[i] -= k;
	cout << 50 << endl;
	for(i = 1; i <= 50; ++ i)
		cout << res[i] << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
signed main(){
    int n,k,a[2000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
    for(int i=1;i<n;i++)
        for(int j=0;j<i;j++)
            if(a[j]<a[i])
                (ans+=k*(k-1)/2)%=mod;
            else if(a[j]>a[i])
                (ans+=k*(k+1)/2)%=mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from sys import stdin


def get_result(data):
    N, K = data
    mod = 10**9+7
    e_val = [i for i in range(N+1)]
    # 累積和を使ってsumを計算
    e_cumsum = [0]
    for i in range(N+1):
        e_cumsum.append(e_cumsum[i] + e_val[i])
    ans = 0
    for r in range(K, N+2):
        min_val = e_cumsum[r]
        max_val = e_cumsum[N+1] - e_cumsum[N+1-r]
        ans += (max_val - min_val + 1) % mod
    return ans % mod


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)


Measured memory_bytes: 27116
use std::cmp;
use std::io;

fn main() {
    loop {
        let mut row = String::new();
        io::stdin().read_line(&mut row).ok();
        let row: usize = row.trim().parse().unwrap();
        if row == 0 {
            break;
        }

        let mut v: Vec<isize> = Vec::new();
        for _ in 0..row {
            let mut input = String::new();
            io::stdin().read_line(&mut input).ok();
            let input: isize = input.trim().parse().unwrap();
            v.push(input);
        }

        let mut sum = 0;
        let mut min = 0;
        let mut max = -99999999;
        for z in 0..row {
            sum = sum + v[z];
            max = cmp::max(max , sum - min);
            min = cmp::min(min, sum);
        }

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


Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    int sum = 0;
    for (int i=0;i<i+1;i++) {
        cin >> n >> x;
        if ( n==0 && x==0 ) {
            break;
        } else {
            for (int a=1;a<n;a++) {
                for (int b=1;b<n;b++) {
                    if ( a!=b && a<b ) {
                        for (int c=1;c<=n;c++) {
                            if ( a!=b && b!=c && c!=a && a<b && b<c && a<c && a+b+c==x ) {
                                sum = sum + 1;
                            }
                        }
                    }
                }
            }
        }
        cout << sum << endl;
        sum = 0;
    }
}



Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main(){
	int x[10002],i,j;
	for (int i = 0; i < 10001; i++){
		cin >> x[i];
		if (x[i] == 0){
			j=i;
			break;
		}
	}
	for (int i=0; i < j; i++){
		cout <<"Case "<<i+1<<": "<< x[i]<<endl;
	}
	return 0;
}

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


int main() {
    int h,w;
    cin >> h >> w;
    vector<string> grid (h);
    for(int i=0; i<h; i++){
        cin >> grid.at(i);
    }
    vector<vector<ll>> cnt (h,vector<ll>(w));
    for(int i=0; i<h; i++){
        vector<ll> seen (w);
        for(int j=0; j<w; j++){
            if(grid.at(i).at(j) == '#') continue;
            if(seen.at(j)) continue;
            int l =0;
            while(j+l < w){
                if(grid.at(i).at(j+l) == '#') break;
                l++;
            }
            for(int k=0; k<l; k++){
                cnt.at(i).at(j+k) += l;
                seen.at(j+k) = 1;
            }
        }
    }

    for(int i=0; i<w; i++){
        vector<ll> seen (h);
        for(int j=0; j<h; j++){
            if(grid.at(j).at(i) == '#') continue;
            if(seen.at(j)) continue;
            int l =0;
            while(j+l < h){
                if(grid.at(j+l).at(i) == '#') break;
                l++;
            }
            for(int k=0; k<l; k++){
                cnt.at(j+k).at(i) += l;
                seen.at(j+k) = 1;
            }
        }
    }
    
    ll ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(grid.at(i).at(j) == '#') continue;
            ans = max(ans,cnt.at(i).at(j));
        }
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s, t;
  cin >> s >> t;
  queue<char> p, q;
  rep(i, 0, s.size()) {
    p.push(s[i]);
    q.push(t[i]);
  }
  bool ok = false;
  rep(i, 0, s.size()) {
    if (p==q){
      ok = true;
      break;
    }
    p.push(p.front());
    p.pop();
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
S = input()
s1 = int(S[0:2])
s2 = int(S[2:4])


if s1 >= 1 and s1 <= 12 and s2 >= 1 and s2 <= 12:
    print("AMBIGUOUS")
elif s2 >= 1 and s2 <= 12 and s1 >= 1 and s1 <= 12:
    print("AMBIGUOUS")
elif s1 >= 0 and s1 <= 99 and s2 >= 1 and s2 <= 12:
    print("YYMM")
elif s2 >= 0 and s2 <= 99 and s1 >= 1 and s1 <= 12:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		long n = Long.parseLong(scn.next());
		long m = Long.parseLong(scn.next());

		ArrayList<Integer>[] input = new ArrayList[(int)n];

		for(int i=0;i<n;i++){
			input[i] = new ArrayList<Integer>();
		}

		for(int i=0;i<m;i++){
			int a = scn.nextInt() - 1;
			int b = scn.nextInt() - 1;

			input[a].add(b);
			input[b].add(a);
		}


		boolean[] flag = new boolean[(int)n];
		int count = solve(input,flag, 0);
		System.out.println(count);

	}

	public static int solve(ArrayList<Integer>[] input,boolean[] flag, int I){
		//訪問した
		flag[I] = true;

		int sum = 0;

		//終了条件
		boolean f = true;
		//全て通ったか
		for(int i=0;i<flag.length;i++){
			if(flag[i] == false){
				f = false;
			}
		}
		if(f){
			sum++;
		}


		for(int i=0;i<input[I].size();i++){
			int next = input[I].get(i);
			if(flag[next] == false){
				sum += solve(input, flag,next);
			}
		}

		//訪問し終わった。
		flag[I] = false;

		return sum;
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int dp[100100];
int v[100100];
int n, k;
int INF = 1e9 + 100; 

int run(int i) {
	if(i > n - 1) return 0;
	if(dp[i] != -1) return dp[i];
	
	int mn = INF;
	for(int j=1; j<=k; ++j) {
		if (i + j < n - 1) {
			int val = run(i + j);
			mn = min(mn, val + abs(v[i] - v[i + j]));
		} else if(i + j == n - 1) {
			mn = min(mn, abs(v[i] - v[i + j]));
		}
	}
	return dp[i] = mn;
}

int main() {
	cin>>n>>k;
	for(int i=0; i<n; ++i) {
		cin>>v[i];
	}
	memset(dp, -1, sizeof dp);
	
	cout<< run(0) <<endl;
	/*for(int i=0; i<n; ++i) {
		cout<<dp[i]<<" ";
	} cout<<endl;*/
	
	return 0;
}

Measured memory_bytes: 5760
fn main() {
    proconio::input! {
        s: String,
    }
    let mut v = vec![];
    for c in s.chars() {
        match c {
            '0' | '1' => {
                v.push(c);
            }
            'B' => {
                v.pop();
            }
            _ => unreachable!(),
        }
    }
    let ans = v.iter().collect::<String>();
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 20;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int N;
vector<int> a;
vector<int> cnt(MAX);
/* function */
void add(int x) { for (int b = 0; b < MAX; b++) cnt[b] += (a[x] >> b) % 2; }
void sub(int x) { for (int b = 0; b < MAX; b++) cnt[b] -= (a[x] >> b) % 2; }
bool check() {
    for (int c : cnt) if (c >= 2) return false;
    return true;
}
/* main */
int main(){
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    ll ans = 0;

    ll right = 0;
    for (ll left = 0; left < N; ++left) {
    for (; right < N; ) {
        add(right);
        if (check()) ++right;
        else {
            sub(right);
            break;
        }
    }
    /* break した状態で right は条件を満たす最大なので、何かする */
    ans += (right - left);
    /* left をインクリメントする準備 */
    if (right == left) ++right;
    else sub(left);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1024
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############

S = input()

mae = S[:2]
usiro = S[2:]

ms = ["01", "02","03","04","05","06","07","08","09","10","11","12"]

if mae in ms and usiro in ms:
    print("AMBIGUOUS")
elif mae in ms:
    print("MMYY")
elif usiro in ms:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3700
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a - b * 2) << endl;
    return 0;
}


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

using namespace std;

int main() {
  int l, n;
  int i;
  
  vector<string> words;
  string input;
  
  cin >> n >> l;
  
  for (i = 0; i < n; i++) {
    cin >> input;
    words.push_back(input);
  }
  
  sort(words.begin(), words.end());
  
  for (i = 0; i < n; i++) {
    cout << words[i];
  }
  
  cout << endl;
  
  return 0;
}

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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;

    printf("%d %d %d %d", x2 - dy, y2 + dx, x1 - dy, y1 + dx);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int i;
int main(void)
{
  int a[5000],b;
  scanf("%d",&b);
  for(i=0;i<b-1;i++)
    {
      scanf("%d ",&a[b-i-1]);
	}
  scanf("%d",&a[0]);
  for(i=0;i<b-1;i++)
    {
      printf("%d ",a[i]);
    }
  printf("%d\n",a[b-1]);
  return 0;  

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
#define ll long long
char a[N];
int main(){
    int n,q,k;
    scanf("%d\n",&n);
    scanf("%s",a);
    scanf("%d",&q);
    while(q--){
        scanf("%d",&k);
        ll nowd=0,nowm=0,cnt=0;
        ll sum=0;
        for(int i=0;i<n;i++){
            if(i-k>=0&&a[i-k]=='D'){
                nowd--;
                cnt-=nowm;
            }
            else if(i-k>=0&&a[i-k]=='M'){
                nowm--;
            }
            if(a[i]=='D')nowd++;
            if(a[i]=='M'){
                nowm++;
                cnt+=nowd;
            }
            if(a[i]=='C')sum+=cnt;
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x=0,y=0,z=0,l=0,m=0;
  int p[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 };
  int n;
  cin >> n;
  int a[16];
  fill(a,a+16,0);
  
  for (int i = 2; i <= n; i++) {
    int j = 0, temp = i;
    while (temp > 1 && j < 15) {
      if (temp%p[j]) j++;
      else {
        temp /= p[j];
        a[j]++;
      }
    }
  }

  for(int i=0;i<15;i++){
   if(a[i]>=2){
     x++;
   }
   if(a[i]>=4){
     y++;
   }     
   if(a[i]>=14){
     z++;
   }   
   if(a[i]>=24){
     l++;
   } 
   if(a[i]>=74){
     m++;
   }   
 }
	cout << m + l * (x - 1) + z * (y - 1) + y * (y - 1) / 2 * (x - 2) << endl;
	return 0;
}


Measured memory_bytes: 3624
//empty sockets
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n, i;
	cin >> n;
	long long int a[n];
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	int flag = 1;
	for (i = 0; i < n; i++)
	{
		if (a[i] == a[i + 1])
		{
			flag = 0;
			break;
		}
	}
	if (flag == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}



Measured memory_bytes: 5136
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, w: usize,
        wv: [(usize, i64); n]
    }

    let mut dp = vec![-1; w+1];
    dp[0] = 0;
    for (g, v) in wv {
        for i in (0..=w).rev() {
            if dp[i] >= 0 && i+g <= w {
                dp[i+g] = max(dp[i+g], dp[i]+v);
            }
        }
    }
    let ans = dp.iter().max().unwrap();
    println!("{}",ans);
}


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

int graph[105][105];
int main() {
  int n, k;

  scanf("%d%d", &n, &k);

  if (k > (n-1)*(n-2)/2) {
    printf("-1\n");
  } else {
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) graph[i][j] = 0;
    for (int i = 1; i < n; i++) {
      graph[0][i] = 1;
    }
    int m = (n-1)*(n-2)/2 - k;
    int x = 1;
    int y = 2;
    int n_e = m + n - 1;
    while (m--) {
      graph[x][y] = 1;
      y++;
      if (y % n == 0) {
        x++;
        y = x+1;
      }
    }
    printf("%d\n", n_e);
    for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) if(graph[i][j] == 1) printf("%d %d\n", i+1, j+1);
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool dfs(int left, int t[10])
{
    int arr[10] = {0};

    for (int i = 0; i < 10; ++i)
    {
        arr[i] = t[i];
    }
    bool res = false;

    if (left == 10)
    {
        bool f = true;
        for (int i = 1; i < 10; ++i)
        {
            if (arr[i] != 0)
                f = false;
        }
        return f;
    }
    if (arr[left] == 0)
    {
        return dfs(left + 1, arr);
    }
    if (arr[left] < 0)
        return false;
    if (left + 2 < 10)
    {
        int a = arr[left];

        while (a >= 0)
        {
            arr[left] = 0;
            arr[left + 1] -= a;
            arr[left + 2] -= a;
            res |= dfs(left + 1, arr);
            arr[left] = a;
            arr[left + 1] += a;
            arr[left + 2] += a;

            a -= 3;
        }
    }
    else
    {
        if (arr[left] % 3 == 0)
        {
            arr[left] = 0;
            res |= dfs(left + 1, arr);
        }
        else
        {
            return false;
        }
    }
    return res;
}
int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    cout << fixed << setprecision(7);

    string s;
    while (cin >> s)
    {

        int arr[10] = {0};
        for (int i = 0; i < s.size(); ++i)
        {
            arr[s[i] - '0']++;
        }

        vector<int> ans;

        for (int i = 1; i < 10; ++i)
        {
            arr[i]++;
            if (arr[i] > 4)
            {
                arr[i]--;
                continue;
            }
            bool res = false;
            for (int j = 1; j < 10; ++j)
            {
                if (arr[j] >= 2)
                {
                    arr[j] -= 2;
                    res |= dfs(1, arr);
                    arr[j] += 2;
                }
            }
            if (res)
                ans.push_back(i);
            arr[i]--;
        }

        if (ans.size() == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            for (int i = 0; i < ans.size(); ++i)
            {
                if (i)
                    cout << " ";
                cout << ans[i];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
double a[104];
double mul=1,up=0;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		scanf("%lf",&a[i]);
		mul*=a[i];
	}
	for (int i=1;i<=n;++i) {
		up+=mul/a[i];
	}
	printf("%.6lf\n",mul/up);
	return 0;
}

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

int n,s,f[105][10];

int main(){
	scanf("%d",&n);
	memset(f,-0x3f,sizeof f);
	f[0][0]=0;
	for(int i=1,s;i<=n;++i){
		scanf("%d",&s);
		for(int j=0;j<10;++j)
			f[i][j]=f[i-1][j];
		for(int j=0;j<10;++j)
			f[i][(j+s)%10]=max(f[i][(j+s)%10],f[i-1][j]+s);
	}
	int ret=0;
	for(int i=1;i<10;++i)ret=max(ret,f[n][i]);
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 256
from collections import deque


n, x, y= map(int, input().split())
x -= 1
y -= 1

graph = [[] for i in range(n)]
for i in range(n - 1):
    graph[i].append(i + 1)
    graph[i + 1].append(i)
graph[x].append(y)
graph[y].append(x)


ans = [0] * n
def solve(i):
    q = deque([i])
    visited = [-1] * n
    visited[i] = 0
    while q:
        v = q.popleft()
        for nxt_v in graph[v]:
            if visited[nxt_v] >= 0:
                continue
            else:
                visited[nxt_v] = visited[v] + 1
                q.append(nxt_v)
    for i in range(n):
        ans[visited[i]] += 1

for i in range(n):
    solve(i)
for i in ans[1:]:
    print(i // 2)

Measured memory_bytes: 47196
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  ll ans = 0;
  const int N = S.size() - 1;
  for (int s = 0; s < (int)(1 << N); ++s) {
    ll v = 0;
    for (int i = 0; i < (int)N + 1; ++i) {
      v *= 10;
      v += S[i] - '0';
      if (i < N && ((s >> i) & 1)) {
        ans += v;
        v = 0;
      }
    }
    ans += v;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;


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




int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int d,c;
    cin>>d>>c;
    if(abs(d-c)>1){
        cout<<0<<endl;
        return 0;
    }
    else{
        int s = min(d,c);
        int b = max(d,c);
        if(s==b){
            int x =factorial(s);
            cout<<((x*x*2)%mod);
        }
        else{
            int x = factorial(s);
            cout<< (x*(((b%mod)*x)%mod))%mod;
        }



    }






}













































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME ""
using namespace std;
typedef long long LL;
typedef double DB;
typedef pair <LL, LL> pLL;
typedef pair <int, int> pii;
const int NMAX = 1e5+3;

int n, m;
vector <pii> a[NMAX];
string s[NMAX];

string toStr(int x, int y) {
    string rs;
    while(x > 0) {
        rs = char(x%10 + '0') + rs;
        x /= 10; y /= 10;
    }
    /// Add 0
    while(y > 0) {
        rs = '0' + rs;
        y /= 10;
    }
    return rs;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= m; ++i) {
        int x, y;
        cin >> x >> y;
        a[x].push_back(pii(y, i));
    }

    for(int i = 1; i <= n; ++i)
        sort(a[i].begin(), a[i].end());

    for(int i = 1; i <= n; ++i)
    for(int j = 0; j < a[i].size(); ++j) {
        s[a[i][j].se] = toStr(i, 100000) + toStr(j+1, 100000);
    }

    for(int i = 1; i <= m; ++i)
        cout << s[i] << '\n';
    return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
lli gcd(lli a,lli b){
	if(a%b == 0)return b;
	return gcd(b,a%b);
}
int main(){
	lli N ,X;
	cin >> N >> X;
	cout << 3*(N-gcd(N,X))<<endl;
return 0 ;
}


Measured memory_bytes: 256