akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

#define FOR(arg, ini, end) for(int arg = ini; arg < end; arg++)

using namespace std;    
long dp[60][60][3000];

int main(int argc, const char * argv[]) {
    
    int n, a; cin >> n >> a;
    vector<int> x(n);
    for(int i=0; i<n;i++){
        cin >> x[i];
    }
    FOR(i, 0, 60){
        FOR(j, 0, 60){
            FOR(k, 0, 3000){
               dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    FOR(i, 0, n){
        FOR(j, 0, n){
            FOR(k, 0, 3000){
                if ( dp[i][j][k] == 0 ) continue;

                dp[i+1][j][k] += dp[i][j][k];
                dp[i+1][j+1][k+x[i]] = dp[i][j][k];
            }
        }
    }
    long ans = 0;
    FOR(i, 1, n+1) {
        ans += dp[n][i][i*a];
    }


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

Measured memory_bytes: 84608
N = input()
L = len(N)
K = int(input())
if L < K:
    print(0)
else:

    def main(d, k):
        if d == L:
            return 0
        if N[d] == "0":
            return main(d + 1, k)
        if (L - d) < k:
            return 0
        if k == 1:
            return ((L - d) - 1) * 9 + int(N[d])
        elif k == 2:
            return (
                ((((L - d) - 1) * ((L - d) - 2)) // 2) * 81
                + ((L - d) - 1) * 9 * (int(N[d]) - 1)
                + main(d + 1, k - 1)
            )
        elif k == 3:
            return (
                ((((L - d) - 1) * ((L - d) - 2) * ((L - d) - 3)) // 6) * (9 ** 3)
                + ((((L - d) - 1) * ((L - d) - 2)) // 2) * 81 * (int(N[d]) - 1)
                + main(d + 1, k - 1)
            )

    print(main(0, K))



Measured memory_bytes: 3064
def main():
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  # M:カードの数字の最大値+1
  M = max(max(A),max(B))+1
  
  INF = float('inf')
  # dp[mask][a]:maskのカードが操作済で、そのうち右端のカードの数字がaであるときの操作回数の最小値
  dp = [[INF for _ in range(M)] for _ in range(1<<N)]
  dp[0][0] = 0
  
  for i in range(1<<N):
    # idx:操作済カードの枚数
    idx = 0
    for k in range(N):
      if (i>>k)&1 == 1:
        idx += 1
    for j in range(M):
      if dp[i][j] >= INF:
        continue
      for k in range(N):
        # k:右端の操作済カードの次に来るカード
        # kがすでに操作済の場合はcontinueする
        if i&(1<<k) == 1:
          continue
        
        # kが何回操作されるかによってkの数字が表の数字になるか裏の数字になるかが決まる
        if abs(k-idx)%2 == 0:
          c = A[k]
        else:
          c = B[k]
  
        # kの数字広義単調増加にならない場合はcontinue
        if j > c:
          continue
        
        # t:kを右端の操作済カードの次に並べるための操作回数
        # それは、初期配置でkより左にあってまだ操作済でないカードの枚数と一致する
        t = 0
        for l in range(k):
          if (i>>l)&1 == 0:
            t += 1
        #print(i,k,idx,c,dp[i|(1<<k)][c],t)
        dp[i|(1<<k)][c] = min(dp[i|(1<<k)][c],dp[i][j]+t)
  
  #print(dp)
  ans = INF
  for i in range(M):
    ans = min(dp[(1<<N)-1][i],ans)
  print(ans if ans < INF else -1)

if __name__ == '__main__':
  main()

Measured memory_bytes: 422604
[d,g]=list(map(int,input().split()))
pc=[]
for i in range(d):
    kari=list(map(int,input().split()))
    pc.append(kari)
gokei=[]
for i in range(d):
    gokei.append(100*(i+1)*pc[i][0]+pc[i][1])

kosumin=10000
for i in range(1<<d):
    score=0
    kosu=0
    jmax=0
    siyouzumi=[]
    for j in range(d):
        if ((i>>j)&1)==1:
            score+=gokei[j]
            kosu+=pc[j][0]
            siyouzumi.append(j)

    if score>=g:
        if kosumin>kosu:
            kosumin=kosu
    if score<g:
        a=d-1
        while True:
            if a==-1:
                break
            if not a in siyouzumi:
                saidai=a
                break
            a-=1
        if a==-1:
            continue

        for k in range(pc[saidai][0]):
            score+=(saidai+1)*100
            kosu+=1
            if k==pc[saidai][0]-1:
                score+=pc[saidai][1]
            if score>=g:
                break
        if score>=g and kosumin>kosu:
            kosumin=kosu
print(kosumin)
                




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define  ff first
#define  ss second
#define sz(a) (ll)a.size()
#define lli long long int
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define M 1000000007
#define pi 3.1415926535


 int main(){

    fast;
     ll n;
   cin>>n;
   
   ll a[n];
   
   for(int i=0;i<n;i++){
   	cin>>a[i];
   }
   ll *dp=new ll[n+1];
   
  dp[0]=0;
   
   
   for(int i=1;i<n;i++){
   	ll ab=1000000;
   	ll ba=1000000;
   	
   	if(i>=1)ab=abs(a[i]-a[i-1])+dp[i-1];
   	
   	if(i>=2)ba=abs(a[i]-a[i-2])+dp[i-2];
   	
   	dp[i]=min(ab,ba);
   	
   }
   
   cout<<dp[n-1]<<"\n";
     return 0;
 }





Measured memory_bytes: 5164
n=int(input())
s=list(input())
s.sort()
cnt=1
cnt_list=[]
if len(s)==1:
    print(1)
    exit()
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt+=1
        if i==n-2:
            cnt_list.append(cnt)
    else:
        cnt_list.append(cnt)
        cnt=1
        if i==n-2:
            cnt_list.append(1)
ans=1
for i in range(len(cnt_list)):
    ans=ans*(cnt_list[i]+1)%(10**9+7)
print(ans-1)

Measured memory_bytes: 50160
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;


int main() {
    int a,b;
    cin >> a>>b;
    for(int i=1;i<4;i++){
        if(i != a && i != b)cout << i;
    }
    return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void){
    int n,m;
    cin>>n>>m;
    char f[55][55];
    rep(i,0,n){
        rep(j,0,m)cin>>f[i][j];
    }
    int dx[4]={-1,0,1,0};
    int dy[4]={0,1,0,-1};
    rep(i,0,n){
        rep(j,0,m){
            if(f[i][j]=='#'){
                bool ok=false;
                rep(k,0,4){
                    if(f[i+dx[k]][j+dy[k]]=='#'){
                        ok=true;
                        break;
                    }else ok=false;
                }
                if(!ok){cout<<"No"<<endl;return 0;}
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    
    int min=-1000000000, max=1000000000, i;
    for(i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        
        if(i && x-max>min) min=x-max;
        if(max>x) max=x;
    }
    
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 2148
import sys

def main():
    s = str(input())
    l = len(s)
    dp = [[0 for _ in range(13)] for _ in range(2)]
    MOD = 10**9+7
    dp[0][0] = 1
    now,use = 0,1
    
    for i in range(l):
        for j in range(13):
            if s[i] != "?":
                num = int(s[i])
                dp[use][(j*10+num)%13] += dp[now][j]
            else:
                for k in range(10):
                    dp[use][(j*10+k)%13] += dp[now][j]
        for j in range(13):
            dp[use][j] %= MOD
        dp[now] = [0 for _ in range(13)]
        now,use = use,now
    
    print(dp[now][5])

if __name__ == "__main__":
    main()


Measured memory_bytes: 42460
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(h: usize, w: usize, aa: Vec<usize>) -> Vec<Vec<usize>> {
    let mut ret = vec![vec![0; w]; h];

    let mut i = 0;
    let mut j = 0;
    let mut dright = true;

    for (c,&a) in aa.iter().enumerate() {
        for _ in 0..a {
            let  x = if dright {
                j
            } else {
                w - 1 - j
            };

            ret[i][x] = c+1;
            j+=1;
            if j == w {
                i+=1;
                j=0;
                dright = !dright;
            }
        }
    }
    ret
}

fn main() {
    let (h,w) = parse_line!(usize, usize);
    let _n = parse_line!(usize);

    let aa = parse_vec!(usize);

    let ans = solve(h,w,aa);

    for line in ans {
        println!("{}", line.iter().map(|c| c.to_string()).collect::<Vec<String>>().join(" "));
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(2,2,vec![2,1,1]),
               vec![vec![1,1],
                    vec![3,2]]);

    assert_eq!(solve(3,5,vec![1,2,3,4,5]),
               vec![vec![1,2,2,3,3],
                    vec![4,4,4,4,3],
                    vec![5,5,5,5,5]]);
}


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

using namespace std;

char sq[] = {'g', 'p'};

signed main(){
	int n, ans = 0;
	string s;
	cin >> s;
	n = s.length();
	for(int i = 0; i < n; ++i){
		if(s[i] != sq[i & 1]){
			if(s[i] == 'g') ++ans;
			else --ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]
def main():
    n,q = map(int,input().split())
    U = Unionfind(n)
    for i in range(q):
        t,u,v = map(int,input().split())
        if t == 0:
            U.union(u,v)
        else:
            print(int(U.same(u,v)))

if __name__ == "__main__":
    main()

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

using namespace std;

array<int, 20000> generate(){
    int cur = 0;
    array<int, 20000> A = {};
    for (int i = 2; i <= 30000; i++){
        if (i % 2 == 0 or i % 3 == 0)
            A[cur++] = i;
    }

    return A;
}

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

    if (n == 3){
        printf("%d %d %d\n", 2, 5, 63);
        return 0;
    }

    auto A = generate();
    constexpr array<int, 6> B = {30000, 0, 29996, 29997, 29998, 0};

    vector<int> ans(n - 1);
    copy_n(A.begin(), n - 1, ans.begin());
    int m = accumulate(ans.begin(), ans.end(), 0) % 6;

    if (m == 5){
        ans[3] = B[3];
        ans.push_back(B[4]);
    } else {
        ans.push_back(B[(6 - m) % 6]);
    }

    copy_n(ans.begin(), n, ostream_iterator<int>(cout, " "));
    cout << endl;

}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n;
    cin>>n;
    vector<long long>a(n+1);

    rep2(i,n){
        cin>>a[i];
        a[i]%=mod;
    }

    long long s[n+1];
    s[0]=0;
    rep2(i,n){
        s[i]=s[i-1]+a[i];
    }
    long long ans=0;
    rep2(i,n-1){
        ans+=(a[i]*((s[n]-s[i])%mod))%mod;
        ans%=mod;
    }
    //rep2(i,n)cout<<s[i]<<" ";

    cout<<ans<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define M 21
#define N 100010
using namespace std;
int dp[N];

int Min(int &a,int b){return a=min(a,b);}

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

  int coin[M];
  for(int i=0;i<m;i++)cin>>coin[i];

  for(int i=0;i<N;i++) dp[i] = 1e9;
  dp[0] = 0;
  for(int i=0;i<m;i++)
    for(int j=0;j<=n;j++)Min(dp[j+coin[i]],dp[j]+1);

  cout<<dp[n]<<endl;

  return 0;
}

Measured memory_bytes: 3436
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;
bool flag=0;
bool vis[100010];
void dfs(int x){
	if(vis[x])return;
	if(x<4)return;
	vis[x]=1;
	if(flag)return;
	if(x-4==0||x-7==0){
		flag=1;
		return;
	}
	dfs(x-4);
	dfs(x-7);
}
int main(){
	int n;
	cin>>n;
	dfs(n);
	if(flag){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int N, M;
    cin >> N >> M;
    vector<lint> A(N), B(N), C(N);
    rep(i, N) cin >> A[i] >> B[i] >> C[i];
    
    lint ans = 0;
    rep(bit, 8) {
        vector<pair<lint, int>> S(N);
        rep(i, N) {
            lint res = 0;
            if (bit & 1) res -= A[i];
            else res += A[i];
            if (bit & 2) res -= B[i];
            else res += B[i];
            if (bit & 4) res -= C[i];
            else res += C[i];
            S[i] = pair<lint, int>{res, i};
        }
        sort(S.rbegin(), S.rend());
        lint A_res = 0, B_res = 0, C_res = 0;
        rep(i, M) {
            A_res += A[S[i].second];
            B_res += B[S[i].second];
            C_res += C[S[i].second];
        }
        ans = max(ans, abs(A_res) + abs(B_res) + abs(C_res));
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define ceil(a, b) ceil((ld) a / (ld) b);                         // div ceiling
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

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

	vector<ll> stick(n);
	each(e, stick)
		cin >> e;

	ll ans = 0;
	sort(all(stick));
	rep(b, 0, n-1)
	{
		rep(c, b+1, n)
		{
			auto it_a = lower_bound(all(stick), stick[b] + stick[c]);
			ll end_a = it_a - stick.begin();
			it_a = upper_bound(all(stick), abs(stick[b] - stick[c]));
			ll begin_a = it_a - stick.begin();

			ans += (end_a - begin_a);
			if (begin_a <= b && b < end_a)
				ans--;
			if (begin_a <= c && c < end_a)
				ans--;

		}
	}
  
	cout << ans / 3;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int h,w;
string st[200005];

int main() {
    //file_put();
	
	scanf("%d%d",&h,&w);
	cin.ignore();
	for (int i=1; i<=h; i++){
		getline(cin,st[i]);
		st[i]='#'+st[i]+'#';
	}
	for (int i=0; i<=w+1; i++) st[0]+='#';
	st[h+1]=st[0];
	for (int i=0; i<=h+1; i++) cout<<st[i]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define A 100

int main(void){

  int n=0, i, j, v=0;
  int a[A];
  
  scanf("%d", &n);
  for(i=0;i < n; i++) scanf("%d", &a[i]);

  for(i=0;i < n; i++){
    printf("%d", a[i]);
    if(i == n-1){
      printf("\n");
      break;
    }
    printf(" ");
  }

  for(i=1; i < n; i++){
    v = a[i];
    j = i - 1;

    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;

    for(j=0;j < n; j++){
      printf("%d", a[j]);
      if(j == n-1){
	printf("\n");
	break;
      }
      printf(" ");
    }
  }
  return 0;
}

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


void solve(long long X){
    rep(i,200){
        rep(j,200){
            if(std::pow(i,5) - std::pow(j,5) == X){
                cout << i << " " << j << endl;
                return;
            }
        }
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


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

int main() {
  int N, A, c, w;
  cin >> N;
  w = 30;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    cin >> A;
    c = 0;
    while (A % 2 == 0) {
      c++;
      A = A / 2;
    }
    if (w > c) {
      w = c;
    }
      
  }
  cout << w << endl;
        
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec pn;

bool isPrime(ll n){
	if(n == 1) return false;
	for(ll i : pn){
		if(i * i > n) return true;
		if(n % i == 0) return false;
	}
	return true;
}

void init(ll n = 2e6){
	pn.pb(2);
	REP(num, 3, n) if(isPrime(num)) pn.pb(num);
}

VecP primeFactorization(ll n){
	VecP res;

	for(ll i : pn){
		ll cnt = 0;
		while(n % i == 0){
			n /= i;
			cnt++;
		}
		if(cnt) res.pb({i, cnt});
		if(n < i * i) break;
	}
	if(n != 1) res.pb({n, 1});

	return res;
}

int main(void){
	init();
	ll n;
	cin >> n;

	auto p = primeFactorization(n);

	Vec cnt(100);
	repn(i, 99) cnt[i] = cnt[i - 1] + i;

	ll ans = 0;
	for(auto i : p){
		ll max = 0;
		rep(j, 100) if (i.sc >= cnt[j]) max = j;
		ans += max;
		// co({i.fs, i.sc, max});
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<ll> p(A), q(B), r(C);
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];

    sort(ALL(p));
    sort(ALL(q));
    sort(ALL(r));

    priority_queue<ll> qa;
    priority_queue<ll> qb;

    for (int i = A - X; i < A; i++) {
        qa.push(-p[i]);
    }
    for (int i = B - Y; i < B; i++) {
        qb.push(-q[i]);
    }

    for (int i = C - 1; i >= 0; i--) {
        if (r[i] <= -qa.top() && r[i] <= -qb.top()) {
            break;
        } else if (-qa.top() < -qb.top()) {
            qa.pop();
            qa.push(-r[i]);
        } else {
            qb.pop();
            qb.push(-r[i]);
        }
    }

    ll ans = 0;

    while (!qa.empty()) {
        ans -= qa.top();
        qa.pop();
    }

    while (!qb.empty()) {
        ans -= qb.top();
        qb.pop();
    }

    cout << ans << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a, 0, sizeof(a))
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 1e5 + 5;

int n;

struct node {
    int a,b;
    bool operator <(const node &p) const{
        return a+b<p.a+p.b;
    }
};

priority_queue<node> q;

int main() {
#ifdef LOCAL
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        q.push({u,v});
    }
    bool p=1;
    ll ans=0;
    for(int i=1;i<=n;i++){
        auto u=q.top();q.pop();
        if (p) ans+=u.a;
        else ans-=u.b;
        p^=1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1400
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

fn main() {
    input! {
        x: i32,
        y: i32,
    }

    println!("{}", x + y/2);
}
                                   

Measured memory_bytes: 4352
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int main() {
	int w, h, n;
	cin >> w >> h >> n;
	int x1 = 0, x2 = w;
	int y1 = 0, y2 = h;
	rep(i,n){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			if(x1 < x) x1 = x;
		}else if(a == 2){
			if(x2 > x) x2 = x;
		}else if(a == 3){
			if(y1 < y) y1 = y;
		}else if(a == 4){
			if(y2 > y) y2 = y;
		}
	}
	int ans;
	if(x1 >= x2 || y1 >= y2) ans = 0;
	else ans = (y2-y1)*(x2-x1);
	cout << ans << endl;
	return 0;
}

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

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int N,K;
  std::cin>>N>>K;
  
  std::vector<int> p(N);
  for(int i=0;i!=N;i++)
  {
    std::cin>>p[i];
  }
  
  std::sort(p.begin(),p.end());
  
  int result=0;

  for(int i=0;i!=K;i++)
  {
    result+=p[i];
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3616
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

pay_list = []
heapq.heapify(pay_list)
ans = 0
# AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, reverse=True)
for i in range(1, M+1):
    # 実行可能なバイトリストを抽出
    for j in range(len(AB)-1, -1, -1):
        a = AB[j][0]
        b = AB[j][1]
        if a <= i:
            # heappopで最大値を取り出したいため、補正値の(-1)を乗じておく
            heapq.heappush(pay_list, b*(-1))
            AB.pop(j)
        else:
            break
    # 最大の報酬の値を取り出して足す
    if len(pay_list) > 0:
        ans += heapq.heappop(pay_list) * (-1)
print(ans)


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

int main() {
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int c[10];
	for (int i = 0; i < 6; i++) {
		cin >> c[i];
	}
	int sum = c[0] * 1 + c[1] * 5 + c[2] * 10 + c[3] * 50 + c[4] * 100 + c[5] * 500;
	if (sum >= 1000) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  p=1e9+7; 
double pi=3.141592653589793238;
  

 int main() {
        ff;
        
         ll a,b,c,k;
         cin>>a>>b>>c>>k;
         
         ll ans=0;
         if(a>=k){
             ans=ans+k;
             k=0;
         }else{
             ans=ans+a;
             k=k-a;
         }
         if(b<k)
           k=k-b;
           else k=0;
         if(k>0  ){
             ans=ans-k;
         }
            cout<<ans<<endl;
            
        
           
       
    return 0;
}


Measured memory_bytes: 3648
n = int(input())
s = input()

r_cnt = s.count("R")
g_cnt = s.count("G")
b_cnt = s.count("B")

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1
print(ans)

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

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

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v.at(i);
    }
    for (int i = 0; i < N; ++i) {
        int max = i;
        for (int j = i+1; j < N; ++j) {
            if (v.at(max) < v.at(j)) {
                max = j;
            }
        }
        int tmp = v.at(i);
        v.at(i) = v.at(max);
        v.at(max) = tmp;
    }
    int Alice = 0;
    int Bob = 0;
    for (int k = 1; k < N + 1; ++k) {
        if (k % 2 != 0) {
            Alice += v.at(k - 1);
        }else {
            Bob += v.at(k - 1);
        }
    }
    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
n, y = map(int, input().split())

a=-1
b=-1
c=-1

for i in range(n+1):
  for j in range(n-i+1):
    k = n-i-j
    if i*10000 + j*5000 + k*1000 == y:
      a,b,c = i,j,k
      break

print("{} {} {}".format(a,b,c))

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

int n,p[1000100],q[1000100],head,tail,ans;
char a[1000100],b[1000100];

int main()
{
    scanf("%d%s%s",&n,a+1,b+1);
    p[n+1]=n+1,head=1,tail=0;
    for (int i=n,lst=n+1; i;)
        if (p[i+1]>i && a[i]==b[i])
            p[i]=i,head=1,tail=0,lst=i--;
        else
        {
            int l=i,r=i;
            for (; l && b[l-1]==b[r]; --l);
            for (p[l]=min(l,p[r+1]); p[l] && a[p[l]]!=b[l]; --p[l]);
            if (!p[l])
            {
                puts("-1");
                return 0;
            }
            if (p[r+1]==r+1)
                q[head=tail]=r-p[l];
            else
            {
                for (int j=head,k=lst-1; j<=tail+1; k-=q[j++])
                    if (k<=r)
                    {
                        if (k<r)
                            q[head=j-1]=r-k;
                        else
                            for (head=j; head<=tail && !q[head]; ++head);
                        break;
                    }
                q[++tail]=p[r+1]-p[l]-1;
            }
            ans=max(ans,tail-head+1);
            lst=r,i=l-1;
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 9984
#include <stdio.h>

int main(void)
{
	int n,i;
	int max=0;
	int temp=0;
	int h1=0,h2;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&h2);
		if(h1>=h2)
			temp++;
		else{
			if(max<temp)
				max=temp;
			temp=0;
		}
		h1=h2;
		}
	if(max<temp)
		max=temp;
	printf("%d",max);
	return 0;
}

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

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

    std::vector<int> a(n);

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<int> sorted = a;

    std::sort(sorted.begin(), sorted.end(), std::greater<int>());

    int max = sorted[0];
    int second_max = sorted[1];

    for (auto i : a) {
        std::cout << (i == max ? second_max : max) << std::endl;
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 043 A / Link: http://abc043.contest.atcoder.jp/tasks/abc043_a  ----- */


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

	LL N; cin >> N;

	LL ans = N*(N+1)/2;


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;(i)<(n);++(i))
using namespace std;
 
// Description: ????????????
// Verifyed: various problem 
using namespace placeholders;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}
 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};
 
auto& operator >> (istream& is,P& p){ R x,y; is >> x >> y,p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}
 
inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline P vec(L l){return l.t-l.s;}
auto sdot = bind(sgn,bind(dot,_1,_2,_3));
auto sdet = bind(sgn,bind(det,_1,_2,_3));
 
// convex_hull Verify AOJ CGL_4_A
VP convex_hull(VP pol) {
    int n = pol.size(), k = 0, t = 1;

    auto cmp_x = [](P a, P b)->bool{
        int sr = sgn(real(a - b)), si = sgn(imag(a - b));
        return sr ? sr < 0 : si < 0;
    };

    sort(begin(pol), end(pol), cmp_x);
    VP res(2 * n);

    auto push = [&](P p)->void{
        while (k > t and sdet(res[k - 1], res[k - 2], p) >= 1) k--;
        res[k++] = p;
    };

    for_each(begin(pol), end(pol), push);
    t = k;
    for_each(rbegin(pol) + 1, rend(pol), push);
    res.resize(k - 1);
    return res;
}
 
 
int main(void){
    int n;
    cin >> n;
    VP pol;
    rep(i,n){
        P p;
        cin >> p;
        pol.push_back(p); 
    }
    VP res=convex_hull(pol);
    int m=res.size(),idx=0;
    rep(i,m){
        if(imag(res[i])<imag(res[idx])) idx=i;
        if(imag(res[i])==imag(res[idx])&&real(res[i])<real(res[idx])) idx=i;
    }
    cout << m << endl;
    rep(i,m) cout << res[(idx+i)%m] << endl;
    return 0;
}

Measured memory_bytes: 15476
def solve():
	N = int(input())
	arr = list(map(int, input().split()))
	xor = arr[0]
	for i in range(1, N):
		xor ^= arr[i]
	for x in arr:
		print(x ^ xor, end = " ")
	print()

def main():
	# for _ in range(int(input())):
	solve()


if __name__ == '__main__':
	main()


Measured memory_bytes: 31680
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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 chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;




signed main() {
    ll n, m; 
    cin >> n >> m;
    
    vll p(m), y(m);
    rep(i, m) {
        cin >> p[i] >> y[i];
        p[i]--;
    }
    
    vvll vals(n);
    rep(i, m) {
        vals[p[i]].push_back(y[i]);
    }
    
    rep(v, n) {
        Sort(vals[v]);
        vals[v].erase(unique(all(vals[v])), vals[v].end());
    }

    rep(i, m) {
        ll v = p[i];
        ll id = lower_bound(all(vals[v]), y[i]) - vals[v].begin();
        
        printf("%06lld", v + 1);
        printf("%06lld\n", id + 1);
    }
}

Measured memory_bytes: 10232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		String sa = makeString(a, b);
		String sb = makeString(b, a);

		String ans = sa.compareTo(sb) < 0 ? sa : sb;

		System.out.println(ans);

		sc.close();
	}

	static String makeString(int n, int m) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; i++) {
			sb.append(n);
		}
		return sb.toString();
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
     
    int main (){
        int N;
        cin >> N;
        LL dp[N+1];
        fill(dp,dp+N+1,0);
        dp[0]=2;
        dp[1]=1;
        for(int i=2;i<N+1;i++){
            dp[i]=dp[i-1]+dp[i-2];
        }
        cout << dp[N] << endl;
        return 0;
    }

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, l[2000];
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> l[i];
    sort(l, l + n);

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int sa = l[j] - l[i];
            int wa = l[i] + l[j];
            int p = upper_bound(l, l + n, sa) - l;
            int q = lower_bound(l, l + n, wa) - l;
            ans += max(0, q - max(p, j + 1));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# ABC075C - Bridge
# find the number of bridges in a given undirected connected graph
# bridge := an edge whose removal disconnects a graph
def dfs(start: int) -> None:
    seen[start] = 1  # make vertex v searched
    stack = [start]
    while stack:
        v = stack.pop()
        for u in g[v]:
            if not seen[u]:
                seen[u] = 1
                stack.append(u)


def main():  # O(M(N + M))
    global g, seen
    N, M, *E = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(E)] * 2):
        G[v].append(u), G[u].append(v)
    bridges = 0
    for v, u in zip(*[iter(E)] * 2):
        g = [v.copy() for v in G]  # subgraph of G except E(v, u)
        g[v].remove(u), g[u].remove(v)
        seen = [0] * (N + 1)
        dfs(1)  # search from vertex 1
        bridges += 1 if 0 in seen[1:] else 0
    print(bridges)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <queue>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

int main()
{
	long long N; //ここをintにするとWAになる！！！！！
	cin >> N;
	long long A[N], dA[N];
	long long sum = 0;//Aの和
	long long x = 0;//取った回数
	REP(i,N){
		cin >> A[i];
		sum+=A[i];
	}
	if(sum % (N*(N+1)/2) != 0){
		cout << "NO" << endl;
	}else{
		x = sum/(N*(N+1)/2);
		REP(i,N){
			dA[i] = A[(i+1)%N]-A[i];
			if((x-dA[i])%N != 0 || (x-dA[i])<0){
				cout << "NO" << endl;
				return 0;
			}
		}
		cout << "YES" << endl;
	}
	return 0;
}

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

int main(void){
  int a,b,c,x;
  int counter=0;
  cin >> a >> b >> c >> x;
  for(int i=0;i<a+1;i++){
  	for(int j=0;j<b+1;j++){
  	  for(int k=0;k<c+1;k++){
  	    if(500*i+100*j+50*k==x){
  	    	counter++;
		}
	  }
    }
  }
  cout << counter << endl;
  return 0;
}


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

int N;
string s;

int dp[510][510];

int f(int l, int r) {
	if(dp[l][r] != -1) return dp[l][r];
	if(l == r) return 1;
	if(l > r) return 0;
	if(s[l] != 'm' || s[r - 1] != 'w') return 0;
	dp[l][r] = 0;
	for(int i = l + 1; i < r; i++) {
		if(s[i] == 'e') {
			int res1 = f(l + 1, i);
			int res2 = f(i + 1, r - 1);
			if(res1 && res2) {
				dp[l][r] = 1;
				break;
			}
		}
	}
	return dp[l][r];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	memset(dp, -1, sizeof dp);
	cin >> s;
	N = s.size();

	if(f(0, N) == 1) {
		cout << "Cat" << endl;
	}
	else {
		cout << "Rabbit" << endl;
	}

}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}
  struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
int main(){
    string s;
    cin>>s;
    int z = s.size();
    if(s[z-1]=='s'){
      s = s + "es";
    }
    else s = s + 's';

    cout<<s<<endl;
}


Measured memory_bytes: 3628
// ABC081C - Not so Diverse

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	map<int, int> A;
	for (int i = 0; i< N; i++) {
		int t;
		cin >> t;
		A[t]++;
	}

	vector<int> temp;
	for (map<int, int>::iterator it = A.begin(); it != A.end(); it++) {
		pair<int, int> t = *it;
		temp.push_back(t.second);
	}

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

	int ans = 0;
	for (int i = 0; i < (int)temp.size() - K; i++) {
		ans += temp[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10748
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 700;
    for (auto& c : s) {
        if (c == 'o') r += 100;
    }

    cout << r << endl;

    return 0;
}

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

int main(){
    int n,x[100],y[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < n; i++){
        cin >> y[i];
    }

    double d[4];
    for(int i = 0; i < 4; i++)d[i] = 0.0;

    for (int p = 1 ; p <= 3 ; p++){
        for(int i = 0; i < n; i++){
            d[p] += pow(fabs(x[i] - y[i]),p);
        }
        d[p]= pow(d[p],1.0/p);
    }
    for(int i = 0; i < n; i++){
        d[0] = (d[0] < fabs(x[i] - y[i])?fabs(x[i] - y[i]):d[0]);
    }

    printf("%lf\n",d[1]);
    printf("%lf\n",d[2]);
    printf("%lf\n",d[3]);
    printf("%lf\n",d[0]);
    
    return 0;

}


Measured memory_bytes: 3344
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
from collections import defaultdict
#from itertools import combinations
sys.setrecursionlimit(10**7)
import math
class SegTree():
    '''
    input idx: 1-
    '''
    def __init__(self, n, init_val=0):
        self.n = n
        self.init_val = init_val
        self.n_leaf = 2 ** math.ceil(math.log2(n))
        self.bins = [init_val] * (self.n_leaf * 2)

    def val_append(self, A):
        '''
        :param A:
        :return:
        '''
        if len(A) != self.n:
            raise ValueError('The number of input should be same with n_leaf')
        for i,a in enumerate(A):
            self.bins[self.n_leaf+i]=a
        self._calc()
        return None

    def _calc(self):
        '''
        Calculate all bins based on values of leaves
        '''
        i = self.n_leaf - 1
        while i > 0:
            self.bins[i] = self._criteria(self.bins[i*2], self.bins[i*2+1])
            i -= 1
        return None

    def _criteria(self, x, y):
        '''
        Define criteria between 2 nodes
        '''
        return x | y

    def eval_between(self, x, y):
        '''
        x, y : node-idx(1-)
        '''
        l, r = x + self.n_leaf - 1, y + self.n_leaf - 1
        ret = self._criteria(self.bins[l], self.bins[r])
        while l < r:
            if l % 2 == 1:
                ret = self._criteria(self.bins[l], ret)
                l += 1
                continue

            if r % 2 == 0:
                ret = self._criteria(self.bins[r], ret)
                r -= 1
                continue
            l = l//2
            r = r//2
            ret = self._criteria(self.bins[l], ret)
            ret = self._criteria(self.bins[r], ret)

        return ret

    def update(self, node, pro):
        '''
        Replacement of the value in a leaf
        '''
        current = node + self.n_leaf - 1
        self.bins[current] = pro
        current //= 2
        while current > 0:
            self.bins[current] = self._criteria(self.bins[current*2+1], self.bins[current*2])
            current //= 2
        return None

def run():
    N = int(input())
    S = list(input())
    Q = int(input())
    queries = [sysread().split() for _ in range(Q)]

    bins = [0] * N# a: ord('a') - 97
    for i,s in enumerate(S):
        id = ord(s) - 97
        bins[i] = 1<<id

    segtree = SegTree(N)
    segtree.val_append(bins)

    for type, i,c in queries:
        if type == '1':
            c = 1 << (ord(c) - 97)
            segtree.update(int(i), c)
        else:
            i,c = int(i), int(c)
            tmp = segtree.eval_between(i,c)
            print(bin(tmp).count('1'))

if __name__ == "__main__":
    run()

Measured memory_bytes: 57684
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	int res = 0;
	int cnt = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '#') {
			sum++;
		}
	}
	res = sum;
	for (int i = 0; i < N; i++) {
		if (S[i] == '#') {
			res = min(res, cnt + N - i - (sum - cnt));
			cnt++;
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 720