akhauriyash/Code-Regression huggingface dataset:
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

object Solve {

  const val INF = (10E17).toLong()

  fun solve() {

    var (longn, k) = readLine()!!.split(' ').map { it.toLong() }

    val n = longn.toInt()

    val p = readLine()!!.split(' ').map { it.toInt() - 1 }
    val c = readLine()!!.split(' ').map { it.toLong() }

    var ans = -INF

    for (i in 0 until n) {
      var cycleCnt = 0
      var cycleSum = 0L
      var now = i

      while (true) {
        cycleCnt++
        cycleSum += c[now]
        now = p[now]
        if (now == i) break
      }

      var cnt = 0
      var nowScore = 0L

      while (cnt <= cycleCnt) {
        cnt++
        now = p[now]
        nowScore += c[now]

        if(cnt > k) break

        val num = (k - cnt) / cycleCnt
        ans = max(ans, nowScore + max(0, num * cycleSum))
      }
    }

    println(ans)
  }
}

fun main(args: Array<String>) {
  Solve.solve()
}

Measured memory_bytes: 40784
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    int w,h,n,x,y,a;
    cin>>w>>h>>n;
    int up=h,bottom=0,left=0,right=w;
    rep(i,n){
        cin>>x>>y>>a;
        switch(a){
        case 1:
            left=max(left,x);
            break;
        case 2:
            right=min(right,x);
            break;
        case 3:
            bottom=max(bottom,y);
            break;
        case 4:
            up=min(up,y);
            break;
        }
    }
    cout<<max(0,up-bottom)*max(0,right-left);
}
/*

*/


Measured memory_bytes: 3632
import sys
import heapq

N, M = list(map(int, input().split()))
jobs = []
for line in sys.stdin:
    A, B = map(int, line.split())
    if A > M:
        continue
    jobs.append((A, B))

jobs.sort(reverse=True)

q = []
ans = 0
for i in range(1, M + 1):
    while jobs and jobs[-1][0] <= i:
        A, B = jobs.pop()
        heapq.heappush(q, -B)

    if q:
        ans += -heapq.heappop(q)
print(ans)


Measured memory_bytes: 17208
#include <bits/stdc++.h>
	    
	    
	    using namespace std;
	
	    #define ll long long
	    #define do double
	    #define ff first
	    #define ss second
	    #define FOR(a,n) for(i=0;i<n;i++){    cin>>a[i];}
	    #define pb push_back
	    #define mp make_pair
	    #define inf LONG_LONG_MAX
	    #define mod  1000000007
	    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	    

	ll d,x,y;
	void extendedEuclid(ll A, ll B) 
	{
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        int temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}

	ll power(ll x,ll y, ll p) 
	{ 
	    ll res = 1; 
	    x = x % p;
	    while (y > 0) 
	    {  // If y is odd, multiply x with result 
	        if (y & 1) 
	            res = (res*x) % p;
	            
	        y = y>>1; 
	        x = (x*x) % p;   
	    } 
	    return res; 
	} 
	ll isPrime(ll n)
	        {
	            
	           if(n==0 || n==1)
	           return 0;
	            if (n%2 == 0) 
	                return 2;
	            
	            if(n%3==0)
	                return 3;
	         
	            for (ll i=5; i*i<=n; i=i+6)
	            {
	                if (n%i == 0)
	                   return i;
	                if (n%(i+2) == 0)
	                   return i+2;
	            }
	            
	            return n;
	        }



map<ll,ll> par,val;
void ini()
{
	for(ll i=0;i<500010;i++)
		{
			par[i]=i;
		}
}

ll root(ll x)
{
	while(par[x]!=x)
	{
		par[x]=par[par[x]];
		x=par[x];
	}
	return x;
}

void uni(ll x,ll y)
{
	x=root(x);
	y=root(y);
	if(val[x]<=val[y])
		par[y]=par[x];
	else
		par[x]=par[y];
	
}
vector<vector<pair<ll,ll> > > v(200010);
vector<ll> ans;
map<ll,ll> vis,dis;

ll bfs(ll n)
{
	vis[1]=1;
	dis[1]=0;
	ll f=0,i;
	queue<ll> q;
	q.push(1);
	ll ans=0;
	while(q.size()>0)
	{
		ll x=q.front();
		q.pop();
		for(i=0;i<v[x].size();i++)
		{
			if(!vis[v[x][i].ff])
			{
				dis[v[x][i].ff]=dis[x]+v[x][i].ss;
				ans=max(ans,dis[v[x][i].ff]);
				q.push(v[x][i].ff);
				vis[v[x][i].ff]=1;
			}
		}
	}
	return ans;
}
vector<ll> a(1000000);
vector<ll> spf(1000000);
void sieve()
{
	ll i,j;
	bool prime[1000000];
	memset(prime, true, sizeof(prime));
	prime[0]=prime[1]=false; 
	for(i=2;i*i<=1000000;i++)
	{
		if(prime[i]==true)
		{
			for(j=i*i;j<=100000;j+=i)
			{
				prime[j]=false;
				if(spf[j]==0)
					spf[j]=i;
			}
		}
	}
}

int gcdExtended(int a, int b, int *x, int *y) 
{ 

    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    int x1, y1;
    int gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1;
    return gcd; 
}  
int modInverse(int b, int m) 
{ 
    int x, y; 
    int g = gcdExtended(b, m, &x, &y); 
    if (g != 1) 
        return -1; 
    return (x%m + m) % m; 
} 

int main()
{
		FAST;
		ll n,m,k,i,j,h;
		ll t;
		cin>>n;
		ll a[n],sum[n];
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			if(i)
				sum[i]=a[i]+sum[i-1];
			else
				sum[i]=a[i];
		}
		ll x=sum[n-1];
		ll ans=inf;
		for(i=0;i<n;i++)
		{
			ll a=sum[i];
			ll y=x-sum[i];
			ans=min(ans,abs(a-y));
			//cout<<x-sum[i]<<" ";
		}
		cout<<ans;
}

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

#define ll             long long
#define gcd(a,b)       __gcd(a,b)
#define lcm(a,b)       a*(b/gcd(a,b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define mii            map<int, int>
#define mll            map<ll, ll>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define mt             make_tuple
#define lb             lower_bound
#define ub             upper_bound
#define ff             first
#define ss             second
#define all(v)         v.begin(),v.end()
#define fill(a,b)      memset(a,b,sizeof a)
#define smax(a, b)     a=max(a, b)
#define smin(a, b)     a=min(a, b)
#define sqr(x)         x*x
#define cube(x)        x*x*x
#define asort(a, n)    sort(a+1, a+n+1)
#define FOR(i, l, r)   for(int i=l;i<=r;i++)
#define ROF(i, l, r)   for(int i=r;i>=l;i--)
#define endl           '\n'

int in() {
    int n;
    scanf("%d",&n);
    return n;
}

ll Lin() {
    ll n;
    scanf("%lld",&n);
    return n;
}

double Din() {
    double n;
    scanf("%lf",&n);
    return n;
}

const double gama = 0.57721566490;
const double eps = 0.00000001;
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;




int main() {
    int a=in(), b=in(), c=in(), d=in();
    if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))  printf("Yes\n");
    else printf("No\n");
    return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll H, N;
    cin >> H >> N;
    vector<pair<int, int>> A(N);
    rep(i, N) cin >> A[i].first >> A[i].second;
    ll dp[N+1][H+10001];
    rep(i, N) rep(j, H+10001) dp[i][j] = IMAX;
    rep(i, N) dp[i][0] = 0;
    rep(i, N) rep(j, H+10001) {
        dp[i+1][j] = min(
                dp[i][j],
                dp[i+1][max(0, j-A[i].first)] + A[i].second
        );
    }
    /*
    rep(i, N+1) { 
        rep(j, H+1) cout << dp[i][j] << '\t';
        cout << endl;
    }
    */
    cout << dp[N][H] << endl;


	return 0;
}



Measured memory_bytes: 156672
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a, b, c, d, e, f;

		while (sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			d = sc.nextInt();
			e = sc.nextInt();
			f = sc.nextInt();
			double x;
			double y;
			int a2 = a * e;
			int b2 = b * e;
			int c2 = c * e;
			int d2 = d * b;
			int e2 = e * b;
			int f2 = f * b;
			a2 = a2 - d2;
			c2 = c2 - f2;
			x = c2 * 1.0 / a2;
			if (x == 0.0) {
				x = 0.0;
			}

			a2 = a * d;
			b2 = b * d;
			c2 = c * d;
			d2 = d * a;
			e2 = e * a;
			f2 = f * a;
			b2 = b2 - e2;
			c2 = c2 - f2;
			y = c2 * 1.0 / b2;
			if (y == 0.0) {
				y = 0.0;
			}

			System.out.printf("%1.3f %1.3f\n", x, y);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
const int MAX_N = 5005;
bool visited[MAX_N];
ll P[MAX_N],C[MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		visited[i] = false;
	}
	return;
}

int main()
{
	int N;
	ll K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> P[i];
	}
	rep(i,N)
	{
		cin >> C[i];
	}
	ll ans = -1e15;
	rep(i,N)
	{
		init();
		ll tempS = 0, now = i+1, loop = -1, tempans = -1e15;
		visited[i] = true;
		rep(j,K)
		{
			now = P[now-1];
			tempS += C[now-1];
			tempans = max(tempans,tempS);
			if (visited[now-1])
			{
				loop = j+1;
				break;
			}
			visited[now-1] = true;
		}
		if (loop > 0 && tempS > 0)
		{
			ll tempS2 = 0, tempans2 = -1e15;
			now = i+1;
			rep(j,K%loop)
			{
				now = P[now-1];
				tempS2 += C[now-1];
				tempans2 = max(tempans2,tempS2);
			}

			ans = max(ans,max(tempS*(K/loop)+tempans2,tempS*(K/loop-1)+tempans));
			
		}
		else
		{
			ans = max(ans,tempans);
		}
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      int[] l = new int[]{0,0,0};
      String ans;
      StringBuilder result = new StringBuilder();

      for(int i=0; i<n; i++) {
        ans = "NO";
        line = br.readLine().split(" ");
        l[0] = Integer.parseInt(line[0]);
        l[1] = Integer.parseInt(line[1]);
        l[2] = Integer.parseInt(line[2]);

        for(int j=0,t; j<3; j++) {
          for(int k=0; k<3; k++) {
            if( l[j] < l[k] ) {
              t = l[j];
              l[j] = l[k];
              l[k] = t;
            }
          }
        }

        if( l[0]*l[0] + l[1]*l[1] == l[2]*l[2] )
          ans = "YES";
        result.append( ans ).append("\n");
      }

      System.out.print(result);
    }
  }
}


Measured memory_bytes: 25284
import sys
n,*S = map(int, sys.stdin.readlines())
total = sum(S)
S.sort()
if total % 10 == 0:
    for i in range(n):
        if S[i] % 10 != 0:
            print(total - S[i])
            break
    else:
        print(0)
else:
    print(total)

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<vi> s(h, vi(w));
    rep(i, h) rep(j, w) {
        if (i<b && j<a) s[i][j] = 1;
        else if (i>=b && j>=a) s[i][j] = 1;
    }
    rep(i, h) {
        rep(j, w) printf("%d", s[i][j]);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 7660
import java.util.*;

public class Main{
  public static void main(String[] args) throws Exception{
	Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    int length = str.length();
    int count = str.substring(1,length - 1).length();
    String result = str.substring(0,1) + String.valueOf(count) + str.substring(length - 1,length);
    System.out.println(result);
  }
}

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

int main() {
  int N;
  cin >> N;
  unsigned long long l_a = 2;
  unsigned long long l_b = 1;
  unsigned long long l_n;
  
  if (N == 1) {
    cout << l_b << endl;
  } else { 
    for (int i = 0; i < N-1; i++) {
      l_n = l_a + l_b;
      l_a = l_b;
      l_b = l_n;
    }
    cout << l_n << endl;
  }
}

Measured memory_bytes: 384
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    vec<int> v(5);
    for (auto & e : v)
    {
        cin >> e;
    }

    int k;
    cin >> k;
    
    bool connectable {true};

    for (auto e : v)
    {
        for (auto e2 : v)
        {
            if (abs(e - e2) > k)
            {
                connectable = false;
                // cout << e << ":" << e2 << endl;
            }
        }
    }

    if (connectable)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++){
                values[i] = i + 1;
            }
            for(int i =0;i <n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                int c = 0;
                c = values[a];
                values[a] = values[b];
                values[b] = c;
            }
            for(int j =0; j<n;j++){
                System.out.printf("%d\n",values[j]);
            }
        }
        }
}



Measured memory_bytes: 26348
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
using namespace std;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m, value;
	string s;
	unordered_map<string, int> blue;
	unordered_map<string, int> red;
	unordered_set<string> names;
	cin >> n;
	rep(i, n) {
		cin >> s;
		names.insert(s);
		blue[s]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> s;
		names.insert(s);
		red[s]++;
	}
	int result = -1000;
	for (string name : names) {
		value = blue[name] - red[name];
		chmax(result, value);
	}
	if (result < 0)
		cout << "0\n";
	else
		cout << result << "\n";
}


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

int main() {
  int N, Q, t, l, r, a;
  string S;
  set<int> s[26];
  char c;
  cin >> N;
  cin >> S;
  for (int i=0; i<N; i++)
    s[S[i] - 'a'].insert(i);
  cin >> Q;
  for (int i=0; i<Q; i++) {
    cin >> t;
    if (t == 1) {
      cin >> a >> c;
      a--;
      s[S[a]-'a'].erase(a);
      s[c-'a'].insert(a);
      S[a] = c;
    } else {
      cin >> l >> r;
      l--;
      r--;
      int cnt = 0;
      for (int j=0; j<26; j++) {
        auto it = s[j].lower_bound(l);
        if (it == s[j].end() || *it > r)
          continue;
        cnt++;
      }
      cout << cnt << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 24196
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

def div2(n):
    count=0
    while n%2==0:
        n=n//2
        count+=1
    return count
        

n=int(input())
a=list(map(int,input().split()))
for ai in a:
    count+=div2(ai)
print(count)


Measured memory_bytes: 43500
n = int(input())
h = list(map(int, input().split()))

INF = 10**12
dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    dp[i] = min(dp[i - 1] + abs(h[i] - h[i-1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[-1])


Measured memory_bytes: 13976
// OURL: https://atcoder.jp/contests/abc123/tasks/abc123_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  auto vs = make_v<int>(5);
  REP(i,5) {
    cin >> vs[i];
  }
  int ans = 140*10;
  do {
    int t = 0;
    for(auto x : vs) {
      if (t % 10 != 0) {
        t += 10 - t % 10;
      }
      t += x;
    }
    ans = min(ans, t);
  } while( next_permutation(vs.begin(), vs.end()) );
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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

//https://qiita.com/drken/items/a14e9af0ca2d857dad23

//N=1の時に自分で対応しなきゃいけないから注意
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  map<ll,ll> mp;
  rep(i,N-1){
    ll num=i+2;
    auto vec=prime_factorize(num);
    for(auto p:vec){
      mp[p.first]+=p.second;
    }
  }
  
  ll ans=1;
  for(auto p:mp) ans=ans*(p.second+1)%MOD;
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int a,b,k,u,g[200];

int cmp(int u,int v){
	return u>v;
}

int main(){
	u=0;
	cin>>a>>b>>k;
	for(int i=1;i<=min(a,b);i++){
		if(a%i==0&&b%i==0){
			g[++u]=i;
		}
	}
	sort(g+1,g+u+1,cmp);
	cout<<g[k]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    
    res = 0
    for k in range(K, N + 2):
        res += (k * (N - k + 1) + 1) % mod
        res %= mod
    print(res)


if __name__ == "__main__":
    main()


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#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(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int digitSum(int x)
{
    int retval = 0;
    while(x > 0){
        retval += x % 10;
        x /= 10;
    }
    return retval;
}

int main()
{
	int n,a,b;
	cin >> n >> a >> b;
	int ans = 0;
	FOR(i,1,n+1){
	    int d = digitSum(i);
	    if(a <= d && d <= b)ans+=i;
	}
	ANS(ans);
	return 0;
}


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

int main() {
    int s;
    cin >> s;
    int a[100100];
    bool memo[100100] = {false};

    a[1] = s;
    memo[a[1]] = true;

    for (int i = 2; ; i++) {
        //a[i - 1]が奇数か偶数か。
        if (a[i - 1] % 2 == 0) a[i] = a[i - 1] / 2;
        else a[i] = 3 * a[i - 1] + 1;
        
        //メモした数字が出てきたら出力。
        if (memo[a[i]] == true) {
            cout << i << endl;
            return 0;
        }

        //a[i]をメモしておき、次に同じ数字が出て来るときに備える。
        memo[a[i]] = true;
    }
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
0,0,0,...,0,ev,ev,ev,,,ev,od,od,,,od,ev,ev,,,,ev,0,0,0,0,0
"""

L = int(input())
A = (int(x) for x in sys.stdin.read().split())

# どの状態まで進んだかごとに、最小スコア
a,b,c,d,e = 0,0,0,0,0
for x in A:
    ev_score = 1 if x&1 else (0 if x > 0 else 2)
    od_score = 1-(x&1)
    a1 = a + x
    b1 = min(a,b) + ev_score
    c1 = min(a,b,c) + od_score
    d1 = min(c,d) + ev_score
    e1 = min(b,c,d,e) + x
    a,b,c,d,e = a1,b1,c1,d1,e1

answer = min(a,b,c,d,e)
print(answer)

Measured memory_bytes: 19380
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    ll a, b, n;
    //string s;
    cin >> a >> b >> n;
    ll x = min(b-1, n);
    ll r = floor(a*x/b) - a*(x/b);
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;

ll a[5],c;
void solve()
{
string s;
ll n;
cin>>n;

for (int i = 0; i < n; ++i)
{
  cin>>s;
  if(s[0]=='M')
  {
    //c(s);
    a[0] += 1; 
   

  }
  else if(s[0]=='A' )
  {
 
    a[1] += 1; 

  }
  else if(s[0]=='R')
  {
    
    a[2] += 1; 
  

  }
else if(s[0]=='C' )
  {
    
    a[3] += 1; 
   

  }
  else if(s[0]=='H')
  {
    a[4] += 1; 
  }
}
sort(a,a+5);
fr(i,0,5)
fr(j,i+1,5)
fr(k,j+1,5)
{
  if(a[i]>0 and a[j]>0 and a[k]>0)
    c+=a[i]*a[j]*a[k];
}
c(c);
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=130;
const int MAXB=11;
const int MAXS=(1<<MAXB)+5;
int m, n;
struct data{
    int ans;
}obj[MAXN];
short dp[MAXS][MAXS];
int dfs(int state, int now){
    short &ret=dp[state][now];
    if(ret!=-1) return ret;
    int cnt=0;
    for(int i=0; i<n; i++){
        if((obj[i].ans&state)==now){
            cnt++;
        }
    }
    if(cnt<2) return ret=0;
    ret=m;
    for(int i=0; i<m; i++){
        if(state>>i&1) continue;
        ret=min((int)ret,1+max(dfs(state|(1<<i),now),dfs(state|(1<<i),now|(1<<i))));
    }
    return ret;
}
int main(){
    while(cin>>m>>n&&(n||m)){
        string str;
        for(int i=0; i<n; i++){
            cin>>str;
            int ans=0;
            for(int j=0; j<m; j++){
                ans=(ans<<1)|(str[j]=='1');
            }
            obj[i].ans=ans;
        }
        memset(dp,-1,sizeof dp);
        cout<<dfs(0,0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 9448
s = input()
n = len(s)
s_1 = s[::-1]

s_2a = s[:(n-1)//2]
s_2b = s_2a[::-1]

s_3a = s[(n+3)//2 -1  :]
s_3b = s_3a[::-1]

if(s==s_1)&(s_2a==s_2b)&(s_3a==s_3b):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//comb(fac, ifac, MOD, n, k)でnCk
ll comb(ll fac[], ll ifac[], ll m, int n, int k){
    ll c = fac[n];
    c *= ifac[n-k], c %= m;
    c *= ifac[k], c %= m;
    return c;
}

//perm(fac, ifac, MOD, n, k)でnPk
ll perm(ll fac[], ll ifac[], ll m, int n, int k){
    return(fac[n]*ifac[n-k])%m;
}

int main(){
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    //1〜nまでのmod(m)における逆元
    ll n = 3e6, m = MOD, inv[n+1];
    rep2(i, 1, n){
        ll e[31];
        e[0] = i;
        rep2(j, 1, 30) e[j] = (e[j-1]*e[j-1]) % m;
        inv[i] = 1;
        ll k = m-2;
        int cnt = 0;
        while(k > 0){
            if(k % 2 == 1) inv[i] *= e[cnt], inv[i] %= m;
            k /= 2;
            cnt++;
        }
    }
    //i!とi!の逆元
    ll fac[n+1], ifac[n+1];
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, n){
        fac[i] = (fac[i-1]*i) % m;
        ifac[i] = (ifac[i-1]*inv[i]) % m;
    }
    ll ans = 0;
    ans += comb(fac, ifac, m, r2+c2+2, c2+1);
    ans += MOD-comb(fac, ifac, m, c2+r1+1, r1);
    ans += MOD-comb(fac, ifac, m, r2+c1+1, c1);
    ans += comb(fac, ifac, m, r1+c1, r1);
    cout << ans%MOD << endl;
}

Measured memory_bytes: 70528
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int a,b;

int main()
{
	a=read();b=read();
	if(b>=a)
		printf("unsafe\n");
	else
		printf("safe\n");
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll N, M, Q;
ll ans = 0;
string S;
vector<ll>a, b, c, d;



int main() {
    cin >> S;
    if (S[2]==S[3]&&S[4]==S[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  
  for (int i = 0; i < 5; i++) {
    int x_i;
    cin >> x_i;
    if ( x_i == 0 ){
      cout << i+1 << endl;
    }
  }
 
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(void) {
	int x[3000], y[3000];
	int a, b, s;
	int flag = 1;
	int cnt = 0;
	int i;
	
	do {
		scanf("%d %d", &a, &b);
		
		if (a > b) {
			s = a;
			a = b;
			b = s;
		}
		if (a == 0 && b == 0) {
			flag = 0;
		} 
		x[cnt] = a;
		y[cnt] = b;
		cnt++;
	} while (flag);
	
	for (i = 0; i < cnt-1; i++) {
		printf("%d %d\n", x[i], y[i]);
	}
	
	return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9

ll an(int n,vector<ll>& a){
    if(n<=1) return 0;
    ll t=a[0],ans=0;
    for(int i=1;i<n;i++){
        if(a[i]<=t){
            ans+=(t-a[i]);
        }
        else{
            t=a[i];
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    vector<ll> a(n);
    for(auto &i: a) cin>>i;
    cout<<an(n,a);
    return 0;
}



Measured memory_bytes: 4740
import itertools

n = int(input())
ppp = tuple(map(int, input().split()))
qqq = tuple(map(int, input().split()))

p = None
q = None
for i, aaa in enumerate(itertools.permutations(range(1, n+1))):
  if aaa == ppp:
    p = i
  if aaa == qqq:
    q = i

if p > q:
  print(p - q)
else:
  print(q - p)

Measured memory_bytes: 3064
h,w=map(int, input().split())
s=list(list(input()) for i in range(h))
ans=0
dpL=[[0]*(w) for i in range(h)]
dpR=[[0]*(w) for i in range(h)]
dpU=[[0]*(w) for i in range(h)]
dpD=[[0]*(w) for i in range(h)]
#四方向用意
for i in range(h):
    for j in range(w):
        
        if s[i][j]=='.':
            if j==0:
                dpL[i][j]=1
            else:
                dpL[i][j]=dpL[i][j-1]+1
        else:
            continue
            
for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j]=='.':
            if j==w-1:
                dpR[i][j]=1
            else:
                dpR[i][j]=dpR[i][j+1]+1
        else:
            continue
            
for i in range(w):
    for j in range(h):
        if s[j][i]=='.':
            if j==0:
                dpU[j][i]=1
            else:
                dpU[j][i]=dpU[j-1][i]+1
        else:
            continue
            
for i in range(w):
    for j in range(h-1,-1,-1):
        if s[j][i]=='.':
            if j==h-1:
                dpD[j][i]=1
            else:
                dpD[j][i]=dpD[j+1][i]+1
        else:
            continue

for i in range(h):
    for j in range(w):
        x=dpU[i][j]+dpD[i][j]+dpR[i][j]+dpL[i][j]-3
        if x>ans:
            ans=x
print(ans)

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

class Program{
  static void Main(string[] args) {
    int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int n = x[0];
    int k = x[1];
    int cnt = 0;
    for(int i = 1; i <= n; i+=2) cnt ++;
    Console.WriteLine(cnt>=k ? "YES" : "NO");
  }
}


Measured memory_bytes: 13268
import java.util.Scanner;//文字列の読み込みにScanner使用
class Main
{
 public static void main(String[] args)
    {
    String str;
    Scanner scan = new Scanner(System.in);
    str = scan.nextLine();
        if(str.equals("SUN")) //格納された文字列の比較は 文字列.equals(文字オブジェクト)
        System.out.println("7");
    else if(str.equals("MON"))
        System.out.println("6");
    else if(str.equals("TUE"))
        System.out.println("5");
    else if(str.equals("WED"))
        System.out.println("4");
    else if(str.equals("THU"))
        System.out.println("3");
    else if(str.equals("FRI"))
        System.out.println("2");
    else if(str.equals("SAT"))
        System.out.println("1");
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll a, b, c, d;
string str;

ll gcd(ll a, ll b){
	if(a < b){ll tmp = a; a = b; b = tmp;}
	if(a == b || b == 0){return a;}
	return gcd(b, a%b);
}

ll cal(ll x, ll n, ll m){
	ll cn = x/n;
	ll cm = x/m;
	ll cnm = x/(n*m/gcd(n, m));
	//cout << cn << cm << cnm << endl;
	return x-cn-cm+cnm;
}

int main(){
	cin >> a >> b >> c >> d;
	//cout << gcd(12, 9) << endl;
	cout << cal(b, c, d) - cal(a-1, c, d) << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

X = int(input())

p = [1]*(10**5+4)
for i in range(2, 10**5+4):
    if p[i]:
        for j in range(i*2, 10**5+4, i):
            # print(j)
            p[j] = 0

q = []
for i, p_i in enumerate(p):
    if p_i:
        q.append(i)

print(q[bisect_left(q, X)])


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

int main() {
    string str;
    cin >> str;
    int q;
    cin >> q;

    for(int i = 0; i < q; i++) {
        string order;
        cin >> order;
        int a, b;
        cin >> a >> b;

        if (order == "print") {
            cout << str.substr(a, b-a+1) << endl;
        } else if (order == "reverse") {
            string tmp = str.substr(a, b-a+1);
            reverse(tmp.begin(), tmp.end());
            str.replace(a, b-a+1, tmp);
        } else {
            string strRep;
            cin >> strRep;
            str.replace(a, b-a+1, strRep);
        }
    }
}


Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

bool C(int i){
    int keta=0;
    while(i!=0){
        i/=10;
        keta++;
    }
    if(keta%2==1) return true;
    else return false;
}

int main(){
    int N;
    cin >> N;
    int sum=0;
    for(int i=1;i<=N;i++){
        if(C(i)) sum+=1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

#include <map>
#include <cassert>

#define PRIME_MAX 1000000

template <typename T>
class PrimeFactorization {
    static bool *isPrime;

    // isPrimeを初期化
    bool initPrimeFact() {
        fill(isPrime, isPrime+PRIME_MAX+1, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i <= PRIME_MAX; i++)
            if (isPrime[i])
                for (int j = 2 * i; j <= PRIME_MAX; j += i) isPrime[j] = false;
        return true;
    }

    T pow(T x, int n) {
        if (n <= 0) return 1;
        else {
            T xn = pow(x, n/2);
            if (n%2 == 0) return xn*xn;
            else return xn*xn*x;
        }
    }

    map<T, int> factors;

public:
    PrimeFactorization(T x = 1) {
        static bool call_once = initPrimeFact();
        assert(call_once);
        for (ll i = 2; T(i * i) <= x; i++) {
            if (!isPrime[i]) continue;
            while (x % i == 0) {
                x /= (T)i;
                factors[(T)i]++;
            }
        }
        if(x > 1)
            factors[x] = 1;
    }

    PrimeFactorization(map<T, int> &facts) : factors(facts) {}

    void gcd(PrimeFactorization &r) {
        for (auto &f:r.factors)
            if (factors.count(f.first))
                factors[f.first] = min(factors[f.first], f.second);
    }
    void gcd(T rval) {
        auto r = PrimeFactorization(rval);
        gcd(r); 
    }

    void lcm(PrimeFactorization &r) {
        for (auto &f:r.factors)
            factors[f.first] = max(factors[f.first], f.second);
    }
    void lcm(T rval) {
        auto r = PrimeFactorization(rval);
        lcm(r); 
    }

    T val() {
        T ans = 1;
        for (auto &f:factors)
            ans *= pow(f.first, f.second);
        return ans;
    }

    int operator[](T x) {
        if (factors.count(x)) return factors[x];
        else return 0;
    }

    auto begin() { return factors.begin(); };
    auto end()   { return factors.end();   };
};

template <typename T>
PrimeFactorization<T> &pf_gcd(PrimeFactorization<T> &l, PrimeFactorization<T> &r) {
    PrimeFactorization<T> ans(l);
    ans.gcd(r);
    return ans;
}

template <typename T>
PrimeFactorization<T> &pf_lcm(PrimeFactorization<T> &l, PrimeFactorization<T> &r) {
    PrimeFactorization<T> ans(l);
    ans.lcm(r);
    return ans;
}

template <typename T>
bool *PrimeFactorization<T>::isPrime = new bool[PRIME_MAX+1];

using P = pair<ll, int>;
#define fi first
#define se second

int main() {
    ll n;
    cin >> n;
    PrimeFactorization<ll> pf(n);
    int ans = 0;
    for (auto &pi:pf) {
        int z, sum;
        for (z = 0, sum = 0; sum <= pi.se; sum += ++z);
        ans += z - 1;
    }
    cout << ans << '\n';
    return 0;
}

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

#define MN 1001000

using namespace std;
typedef long long ll;

ll n, r, g, b, ans;

int main() {
    scanf("%lld %lld %lld %lld", &r, &g, &b, &n);
    for(int i = 0; i * r <= n; i++) {
        for(int j = 0; i * r + j * g <= n; j++) {
            int k = (n - i * r - j * g);
            if(k % b) continue;
            ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	counts := make(map[string]int)
	var a string
	for i := 0; i < h; i++ {
		fmt.Scan(&a)
		for _, c := range a {
			counts[string(c)]++
		}
	}

	var g1, g2, g4 int
	if h%2 == 1 && w%2 == 1 {
		g1 = 1
	}

	if h%2 == 1 {
		g2 += w / 2
	}
	if w%2 == 1 {
		g2 += h / 2
	}

	g4 = (h / 2) * (w / 2)

	// g1
	for i := 0; i < g1; i++ {
		for k, v := range counts {
			if v%4 == 1 || v%4 == 3 {
				counts[k]--
				break
			}
		}
	}

	// g2
	t2 := 0
	for i := 0; i < g2; i++ {
		for k, v := range counts {
			if v > 0 && v%4 == 2 {
				counts[k] -= 2
				t2++
				break
			}
		}
	}
	g2 -= t2

	// g4
	for i := 0; i < g4; i++ {
		for k, v := range counts {
			if v > 0 && v%4 == 0 {
				counts[k] -= 4
				break
			}
		}
	}

	for i := 0; i < g2; i++ {
		for k, v := range counts {
			if v > 0 && v%2 == 0 {
				counts[k] -= 2
				break
			}
		}
	}

	ans := "Yes"
	for _, v := range counts {
		if v != 0 {
			ans = "No"
			break
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
signed main(){
	float a;
	while( scanf("%f", &a) != EOF ){
		if(a <= 48) cout << "light fly" << endl;
		else if(a <= 51) cout << "fly" << endl;
		else if(a <= 54) cout << "bantam" << endl;
		else if(a <= 57) cout << "feather" << endl;
		else if(a <= 60) cout << "light" << endl;
		else if(a <= 64) cout << "light welter" << endl;
		else if(a <= 69) cout << "welter" << endl;
		else if(a <= 75) cout << "light middle" << endl;
		else if(a <= 81) cout << "middle" << endl;
		else if(a <= 91) cout << "light heavy" << endl;
		else  cout << "heavy" << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
n,m=map(int,input().split())
A=[[0 for j in range(m)] for i in range(n)]
C=[0 for i in range(m)]
ANS=[0 for i in range(n)]
for i in range(n):
    A[i]=list(map(int,input().split()))
for i in range(m):
    C[i]=int(input())
for i in range(n):
    for j in range(m):
        ANS[i]+=(A[i][j]*C[j])
for i in range(n):
    print(ANS[i])


Measured memory_bytes: 5964
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
     String[] nyu=sc.nextLine().split(" ");

//     String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}

//if(A+B<C+D){
//double res=Math.ceil((AB)/2);

System.out.println(res);
//}else if(A+B>C+D){
//System.out.println("Left");

//}else{
//System.out.println("Balanced");

//}




	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  vector <int> n(3);
  for(int i=0;i<3;++i) cin >> n[i];
  sort(n.begin(),n.end());
  cout << n[0]+n[1] << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
t = int(s[:2])
tt = int(s[2:])
if t <= 12 and tt <= 12 and (t >= 1 and tt >= 1):
  print("AMBIGUOUS")
elif tt <= 12 and tt >= 1:
  print("YYMM")
elif t <= 12 and t >= 1:
  print("MMYY")
else:
  print("NA")

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

string s;

int main(){
    cin >> s;

    int n = s.size();
    int k0 = n, k1 = n;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0') k0 = min(k0, max(i, n-i-1));
        else k1 = min(k1, max(i, n-i-1));
    }

    cout << max(k0, k1) << endl;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(N), y(N), aN(N), bN(N), aM(M), bM(M);
  rep(i, N) cin >> aN.at(i) >> bN.at(i);
  rep(i, M) cin >> aM.at(i) >> bM.at(i);
  rep(i, N){
      x.at(i)=abs(aN.at(i)-aM.at(0))+abs(bN.at(i)-bM.at(0));
      y.at(i)=1;
    rep(j, M){
      if(abs(aN.at(i)-aM.at(j))+abs(bN.at(i)-bM.at(j))<x.at(i)){
        x.at(i)=abs(aN.at(i)-aM.at(j))+abs(bN.at(i)-bM.at(j));
        y.at(i)=j+1;
      }
    }
  }
  rep(i, N) cout << y.at(i) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100003
#define NIL -1

struct node {
	int parent, left, right;
};
struct node T[MAX];
int D[MAX], H[MAX];

int setHight(int u){
	int h1  = 0, h2 = 0;
	if(T[u].right != NIL){
		h1 = setHight(T[u].right)+1;
	}
	if(T[u].left != NIL){
		h2 = setHight(T[u].left)+1;
	}
	return H[u] = max(h1,h2);
}

void setDepth(int u, int p){
	D[u] = p;
	if(T[u].right != NIL){
		setDepth(T[u].right, p+1);
	}
	if(T[u].left != NIL){
		setDepth(T[u].left,p+1);
	}
}

int sibling(int u){
	if(T[u].parent== NIL) return -1;
	return T[T[u].parent].left == u ? T[T[u].parent].right: T[T[u].parent].left;
}


string foo(int u){
	if(T[u].parent == NIL) return "root";
	if(T[u].left == NIL && T[u].right == NIL) return "leaf";
	else return "internal node";
}

int degree(int u){
	return (T[u].left != NIL) + (T[u].right != NIL);
}

int main(){
	int n, id, k, c, c2, root, left, right;
	cin>>n;
	for(int i = 0; i < n; i++){
		T[i].parent = T[i].left = T[i].right = NIL;
	}
	
	for(int i = 0; i < n; i++){//cout<<i<<endl;
		cin>>id>>left>>right;
		T[id].left = left;
		T[id].right = right;
		if(left != NIL){
			T[left].parent = id;
		}
		if(right != NIL){
			T[right].parent = id;
		}
	}
	for(int i = 0; i < n; i++){
		if(T[i].parent == NIL) root = i;
	}
	
	setDepth(root,0);
	setHight(root);
	
	for(int i = 0; i < n; i++){
		cout<<"node "<<i<<": parent = "<<T[i].parent<<", sibling = "<<sibling(i)<<", degree = "<<degree(i)<<", depth = "<<D[i]<<", height = "<<H[i]<<", "<<foo(i)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3228
N = int(input())
s = input()
mn=N
lw=0
re=s[1:].count("E")
for i in range(N):
    if i-1>=0 and s[i-1]=="W":
        lw+=1
    if i-1>=0 and s[i]=="E":
        re-=1
    
    sm=lw+re
    if mn>sm:
        mn=sm
print(mn)
    

Measured memory_bytes: 69280