akhauriyash/Code-Regression huggingface dataset:
def f(A):
    counter = [0 for _ in range(8)]
    n_free = 0
    for a in A:
        if a >= 3200:
            n_free += 1
        else:
            idx = a // 400
            counter[idx] += 1
    if sum(counter) > 0:
        n_min = sum(count > 0 for count in counter)
        n_max = n_min + n_free
    else:
        n_min = 1
        n_max = n_free
    return n_min, n_max

N = int(input())
A = list(map(int, input().split()))
n_min, n_max = f(A)
print("{} {}".format(n_min, n_max))

Measured memory_bytes: 3064
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


if __name__ == '__main__':
    # 素因数
    x, n = map(int, input().split(" "))
    r = factorize(n)
    r2 = [(c[0], c[1]//x) for c in r if c[1]>=x] # (基数, 指数)で指数をnに合わせて変換
    r3 = [c[0]**c[1] for c in r2]
    r_f = 1
    for c in r3:
        r_f *= c
    print(r_f)

    """
    # 約数列挙
    for d in divisorize(r):
        print(d, num(d))
    """


Measured memory_bytes: 3064
n=int(input())

lis=[0 for i in range(n)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            ni=x*x+y*y+z*z+x*y+y*z+z*x
            if ni<=n:
                lis[ni-1]+=1

for i in range(n):
    print(lis[i])

Measured memory_bytes: 9428
package main

import "fmt"

func main() {
	var n, x int

	fmt.Scan(&n, &x)

	var hs, ps []int
	hs = append(hs, 1)
	ps = append(ps, 1)
	for i := 1; i <= n; i++ {
		hs = append(hs, 2*hs[i-1]+3)
		ps = append(ps, 2*ps[i-1]+1)
	}

	sum := 0
	rem := x

	for level := n; rem > 0; level-- {
		if rem == hs[level] {
			sum += ps[level]
			break
		}

		rem -= 1
		if rem <= hs[level-1] {
			continue
		}

		sum += ps[level-1]
		rem -= hs[level-1]

		rem -= 1
		sum += 1

		if rem == hs[level]+1 {
			rem -= 1
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
n = int(input())
d = {}
e = []
ans = 0
for i in range(n):
  s = list(input())
  s.sort()
  s = "".join(s)
  if s in d:
    d[s] += 1
  else:
    d[s] = 1
for key,value in d.items():
  if value > 1:
    e.append(d[key])
for j in e:
  ans += j*(j-1)//2
print(ans)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;
  vector<int> tmp; int cnt = 0;

  if(S[0] == '0') tmp.push_back(0);
  REP(i, N) {
    cnt++;
    if(S[i] != S[i + 1]) {
      tmp.push_back(cnt);
      cnt = 0;
    }
  }
  if(S[N - 1] == '0') tmp.push_back(0);
  
  vector<int> res(tmp.size() + 1, 0);
  REP(i, tmp.size()) res[i + 1] = res[i] + tmp[i]; // 累積

  int ans = 0;
  for(int i = 0; i < res.size(); i = i + 2) {
    int right = i + (2 * K + 1);
    if(right >= res.size()) right = res.size() - 1;
    ans = max(ans, (res[right] - res[i]) );
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double eps = -1e10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll n, K, a[100010], b[100010], ans;

bool check(ll cul, ll need) {
	for (int i = 0;i < 30;i++) {
		if (!(need&(1 << i)) && (cul&(1 << i)))return false;
	}
	return true;
}

int main() {
	cin >> n >> K;
	for (int i = 0;i < n;i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0;i < 31;i++) {
		if ((1 << i) > K)break;
		ll now = 0, need = K, sum = 0;
		if (need&(1 << i)) {
			need &= ~(1 << i);
			for (int j = 0;j < i;j++)need |= (1 << j);
		}
		for (int j = 0;j < n;j++) {
			ll cul = now;
			cul |= a[j];
			if (check(cul, need)) {
				sum += b[j];
				now |= a[j];
			}
		}
		ans = max(ans, sum);
	}
	ll now = 0, need = K, sum = 0;
	for (int j = 0;j < n;j++) {
		ll cul = now;
		cul |= a[j];
		if (check(cul, need)) {
			sum += b[j];
			now |= a[j];
		}
	}
	ans = max(ans, sum);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
x, n = map(int, input().split())
if n != 0:
    l = list(map(int, input().split()))
else:
    l = []

diff = 10**10
ans = 10**10

for i in range(102):
    if i in l:
        continue
    else:
        if abs(x-i) < diff:
            ans = i
            diff = abs(x-i)

print(ans)


Measured memory_bytes: 9152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  rep(i,M) cin >> p[i] >> S[i];
  vector<bool> result(N);
  vector<int> wa(N);
  rep(i,M) {
    if (!result[p[i]-1]) {
      if (S[i] == "AC") {
        result[p[i]-1] = true;
      }
      else {
        ++wa[p[i]-1];
      }
    }
  }
  int ans = 0, pena = 0;
  rep(i,N) {
    if (result[i]) {
      ++ans;
      pena += wa[i];
    }
  }
  cout << ans << " " << pena << endl;
  return 0;
}

Measured memory_bytes: 5936
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  map<int,int> mp;
  for(int i=0; i<2*M; i++){
    int x;
    cin >> x;
    if(mp.count(x)){
      mp[x]++;
    }
    else{
      mp[x] = 1;
    }
  }
  bool flag = true;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if(itr->second %2 != 0){
      flag = false;
    }
  }
  
  if(flag){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

long long pp(int x, int y) {
  return x * 2000000000LL + y;
}

int ans[42];

int a[123456], b[123456];

std::unordered_set<long long> f, g;

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i, b + i);
    f.insert(pp(a[i], b[i]));
  }
  for (int i = 0; i < n; i++) {
    for (int dx = -2; dx <= 0; dx++) {
      for (int dy = -2; dy <= 0; dy++) {
        int x = a[i] + dx;
        int y = b[i] + dy;
        if (x <= 0 || y <= 0 || x + 2 > h || y + 2 > w) continue;
        if (g.find(pp(x, y)) != g.end()) continue;
        g.insert(pp(x, y));
        int have = 0;
        for (int cx = 0; cx < 3; cx++) {
          for (int cy = 0; cy < 3; cy++) {
            if (f.find(pp(x + cx, y + cy)) != f.end()) ++have;
          }
        }
        ans[have]++;
      }
    }
  }
  int sum = 0;
  for (int i = 1; i <= 9; i++) sum += ans[i];
  printf("%lld\n", (long long) (h - 2) * (w - 2) - sum);
  for (int i = 1; i <= 9; i++) {
    printf("%d\n", ans[i]);
  }

}

Measured memory_bytes: 41488
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    long long res = 1LL << 60;

    for (int i = 0; i + k <= n; ++i) {
        res = min(res, 0LL + A[i + k - 1] - A[i]);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

int main(){
        int N,T;

        cin>>N>>T;

        int *c=new int[N];
        int *t=new int[N];

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

        vector<int> time_OK;

        for(int i=0;i<N;i++){
                if(t[i]<=T){
                        time_OK.push_back(i);
                }
        }
        if(time_OK.size()==0){
                cout<<"TLE"<<endl;
        }else{
                int cost_min=time_OK[0];
                for(int i=1;i<time_OK.size();i++){
                        if(c[time_OK[i]]<c[cost_min]){
                                cost_min=time_OK[i];
                        }
                }
                cout<<c[cost_min]<<endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
int table[11][100000];

int solve(vector<int> &in){
  int n=in.size();
  rep(i,n)rep(j,11)table[j][i]=0;
  if (in[0]!=0 )table[in[0]][0]=1;
  //((a+b*10+...+x*10^y)*10mod11 +zmod11)==
  //(z+a*10+b*100+...+x*10^(y+1))mod11
  REP(i,1,n){
    rep(j,11){
      table[(j*10+in[i])%11][i]+=table[j][i-1];
    }
    if (in[i]!=0)table[in[i]][i]++;
  }
  
  int ret=0;
  rep(i,n)ret+=table[0][i];
  return ret;
}

main(){
  string a;
  while(cin>>a && a!="0"){
    vector<int> in;
    rep(i,a.size())in.push_back(a[i]-'0');
    cout << solve(in)<<endl;
  }
}

Measured memory_bytes: 5032
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n,ans = 0,cnt = 0;
  string s,ss,sss;
  cin>>a>>b>>c>>d>>e;
  if(c == a)ans += d-b;
  else{
    if(b >= d){
      ans += (c-a-1)*60+60-b+d;
    }else{
      ans += (c-a)*60;
      ans += d-b;
    }
  }
  cout<<ans-e<<endl;
  return 0;
}


Measured memory_bytes: 3608
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n=int(input())
c=0
for i in range(1,n+1,2):
      if len(make_divisors(i))==8:
            c+=1
print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
 
 
ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}


void solve()
{
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  cout<<x*min(n,k)+max(0,n-k)*y;
}
 
int main()
{
  fastio
  int tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		m[a]++
	}

	if len(m) <= k {
		fmt.Println(0)
		return
	}

	c := make([]int, len(m))
	i := 0
	for _, v := range m {
		c[i] = v
		i++
	}

	sort.Ints(c)
	ans := 0
	for i := 0; i < len(c)-k; i++ {
		ans += c[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12672
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<ll,ll> mp;
//deque<ll> deq;
vector<ll> vll;
ll num[ten52],num2[ten52];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,k1=0;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        num[i-1]=m-i;
    }
    sort(num,num+n);
    m=n/2;
    for(i=0;i<n;i++)
        k+=abs(num[i]-num[m]);
    cout<<k;
    return 0;
}





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

using namespace std;
string s;
int main(){
	cin >> s;
	int i,n = s.size();
	long long b = 0,ans = 0;
	for(i=0;i<n;i++){
		if(s[i]=='B'){
			b++;
		}else{
			ans += b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;

typedef long long ll;

/*map<pair<ll, ll>,bool> h;

bool ok(ll x, ll y) {
	bool ret = 0;
	if(x < y) swap(x, y); 
	if((x == 0 && y == 0) || (x == 1 && y == 0) || (x == 1 && y == 1)) return 0;
	if(h.count(mp(x,y))) return h[mp(x,y)];
	for(int i = 1; i * 2 <= x; i++) ret |= !(ok(x - 2 * i, y + i));
	for(int i = 1; i * 2 <= y; i++) ret |= !(ok(y - 2 * i, x + i));
	// if(x - (x / 2) * 2 < x) ret |= !(ok(x - (x / 2) * 2, y + (x / 2)));
	// if(x - (x / 2) * 2 + 2 < x) ret |= !(ok(x - (x / 2) * 2 + 2, y + (x / 2) - 1));
	// if(y - (y / 2) * 2 < y) ret |= !(ok(x + (y / 2), y - (y / 2) * 2));
	// if(y - (y / 2) * 2 + 2 < y) ret |= !(ok(x + (y / 2) - 1, y - (y / 2) * 2 + 2));
	return h[mp(x,y)]=ret;
}*/
int main() {
	ll x, y; scanf("%llu%llu", &x, &y);
	if(x < y) swap(x, y);
	if(x - y >= 2) puts("Alice"); else puts("Brown");

	return 0;
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let a=asc(nrin(3))
  out(a[2]-a[0])
}
main();

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, M; cin >> N >> M; 
	long long dp[310][310][310] = {}; // i日目，初訪問順に番号をつけたとき，0に戻れるのがjまでで最大kまで進んでいる
	long long mod = 1000000007; 
	dp[0][0][0] = 1; 
	for(int i = 0; i < M; i++){
		for(int j = 0; j <= min(i, N-1); j++){
			for(int k = j; k <= min(i, N-1); k++){
				if(j == k){
					dp[i+1][j][k+1] += dp[i][j][k] * (N - k - 1) % mod; 
					dp[i+1][j][k+1] %= mod; 
					dp[i+1][j][k] += dp[i][j][k] * (k + 1) % mod; 
					dp[i+1][j][k] %= mod; 
				}else{
					dp[i+1][j][k] += dp[i][j][k] * (k - j) % mod; 
					dp[i+1][j][k] %= mod; 
					dp[i+1][k][k] += dp[i][j][k] * (j + 1) % mod; 
					dp[i+1][k][k] %= mod;
					dp[i+1][j][k+1] += dp[i][j][k] * (N - k - 1) % mod; 
					dp[i+1][j][k+1] %= mod; 
				}
			}
		}
	}
	cout << dp[M][N-1][N-1] << "\n"; 
}

Measured memory_bytes: 236344
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define pll pair<ll,ll>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    cin>>k;
    string s ="ACL";
    for(int i=0;i<k;i++)
    cout<<s;
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<bool> dp(K + 1);
    for (int i = 1; i <= K; i++) {
        bool winning = false;
        for (int j = 0; j < N; j++) {
            int k = i - A[j];
            if (k >= 0) {
                if (!dp[k]) {
                    winning = true;
                    break;
                }
            }
        }
        dp[i] = winning;
    }
    cout << (dp[K] ? "First" : "Second") << endl;
    return 0;
}


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

using namespace std;

struct Sieve {
    vector<int> vec;

    explicit Sieve(int n) : vec(n + 1) {
        for (int i = 2; i <= n; ++i) {
            if (vec[i] == 0) {
                vec[i] = i;
                for (long long j = (long long) i * i; j <= n; j += i) {
                    if (vec[j] == 0) vec[j] = i;
                }
            }
        }
    }

    vector<pair<int, int> > factorize(int n) {
        vector<pair<int, int> > res;
        if (vec[n] != 0) {
            res.emplace_back(vec[n], 1);
            n /= vec[n];
        }
        while (vec[n] != 0) {
            if (vec[n] == res.back().first) {
                ++res.back().second;
            } else {
                res.emplace_back(vec[n], 1);
            }
            n /= vec[n];
        }
        return res;
    }
};

const int mod = 1e9 + 7;

long long inv(long long a) {
    long long res = 1;
    int n = mod-2;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Sieve s(1000000);
    int n;
    cin >> n;
    vector<int> A(n);
    for (auto &a : A) cin >> a;
    map<int, int> m;
    for (const auto a : A) {
        for (const auto &f : s.factorize(a)) {
            m[f.first] = max(m[f.first], f.second);
        }
    }
    long long lcm = 1;
    for (const auto &p : m) {
        for (int i = 0; i < p.second; ++i) {
            if ((lcm *= p.first) >= mod) lcm %= mod;
        }
    }
    long long ans = 0;
    for (const auto a : A) {
        if ((ans += lcm * inv(a) % mod) >= mod) ans -= mod;
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
	int n, r;
	while( cin >> n >> r, n||r ){
		vector<int> card(n+1);
		for( int i=1; i<=n; i++ ){
			card[i] = n-i+1;
		}
		while(r--){
			int p, c;
			cin >> p >> c;
			vector<int> tmp(c);
			for( int i=0; i<c; i++ ){
				tmp[i] = card[p+i];
			}
			for( int i=1; i<p; i++ ){
				card[p+c-i] = card[p-i];
			}
			for( int i=0; i<c; i++ ){
				card[i+1] = tmp[i];
			}
		}
		cout << card[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int n; string s;
vector<vector<int>> inds(10);
int ans = 0;

void fanc(string st)
{
  if(st.size()==3){
    bool flag = true;
    int ind = 0;
    for(auto c: st){
      auto itr = lower_bound(ALL(inds[c-'0']), ind);
      if(itr==inds[c-'0'].end()){
        flag = false;
        break;
      }else{
        ind = (*itr) + 1;
      }
    }
    if(flag) ans++;
  }else{
    REP(i,10){
      st.push_back('0'+i);
      fanc(st);
      st.pop_back();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> s;
  REP(i,n){
    inds[s[i]-'0'].push_back(i);
  }
  fanc("");
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        BigInteger x = ReadLong();
        BigInteger k = ReadLong();
        BigInteger d = ReadLong();
        if (x < 0) x *= -1;

        if (x - k * d > 0)
        {
            Console.WriteLine(x - k * d);
            return;
        }
        var a = x / d;
        x -= a * d;
        k -= a;
        if (k % 2 == 0)
        {
            Console.WriteLine(x);
        }
        else
        {
            Console.WriteLine(d - x);
        }
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}


Measured memory_bytes: 28620
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;

int inf = 1e18;
const int N = 6e5+5;
int mod = 1e9+7;
/*
    int ncr(int n , int r ){
    	r = min(r,n-r);
    	int res = 1 ;
    	for(int i = 1 ; i <= r ; i++ ){
    		( res *= n-i+1 )%= mod;
    		res /= i ;
    	}
    	return res ;
    }
*/
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n;
       cin>>n;
       string s,t;
       cin>>s>>t;
       rep(i,0,n)
       cout<<s[i]<<t[i];

    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for(int i = 1; i < n + 1; i++) {
			if(i % 2 == 1) {
				int tmp = i;
				int[] div = new int[n + 1];
				for(int j = 1; j < n + 1; j++) {
					div[j] = 0;
				}
				while(tmp != 1) {
					for(int j = 2; j < tmp + 1; j++) {
						if(tmp % j == 0) {
							div[j]++;
							tmp /= j;
							break;
						}
					}
				}
				int count = 1;
				for(int j = 2; j < n + 1; j++) {
					count *= div[j] + 1;
				}
				if(count == 8) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}

}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 50;

void solve() {
	int h, a;
	cin >> h >> a;
	cout << h / a + (h % a ? 1 : 0);
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.assign(n+1,0);
    hash2.assign(n+1,0);
    mpow1.assign(n+1,1);
    mpow2.assign(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    ll low=0,high=len;
    while( high-low>1 ){
      ll mid=(high+low)/2ll;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

main(){

  ll n;
  string s;
  cin>>n>>s;

  Rolling_Hash rh(s);
  ll ans=0;
  rep(i,n){
    for(ll j=i+1;j<n;++j){
      ll lcp=rh.get_LCP(i,j);
      ans=max(ans,min(lcp,j-i));
    }
  }
  cout<<(ans)<<endl;

}


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

int main() {
  int fi, li;
  string s; cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'A') {
      fi = i; break;
    }
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'Z') {
      li = i; break;
    }
  cout << li - fi + 1 << endl;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    if n % 10 == 3:
        print("bon")
        return
    elif n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8:
        print("pon")
        return 
    else:
        print("hon")
        return 
main()

Measured memory_bytes: 9100
#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> l(9);
  l = {111,222,333,444,555,666,777,888,999};

  rep(i, 9) {
    if (l[i] - n >= 0) {
      cout << l[i] << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
from itertools import accumulate
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
a, b = zip(*ab)
a = list(a)
b = list(b)
a = list(accumulate(a))
for i, j in zip(a, b):
    if i > j:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 59568
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 300


//問題文のとおり
int N,M,temp,big;
vector<int> A[N_MAX];
int num[N_MAX];
int ans=1000000;

int main() {
	//入力
	cin>>N>>M;
	REP(i,N){
		REP(j, M) {
			cin >> temp;
			A[i].push_back(temp-1);
		}
	}

	//全競技を順に消していく
	REP(roop, M) {
		//まず、どの競技が一番人気か探る
		
		//初期化
		REP(kind,M)num[kind]=0;
		//数え上げ
		REP(person,N)num[A[person][0]]++;
		
		//探索
		big=0;
		FOR(kind, 1, M)if (num[big] < num[kind]) big=kind;
		ans=min(ans,num[big]);
		//cout<<"big "<<big<<endl;

		//消して、更新する。
		REP(person, N) {
			REP(kind, int(A[person].size()) ) {
				//cout<<person<<" "<<kind<<endl;

				if (A[person][kind] == big) {

					A[person].erase(A[person].begin()+kind);

					break;
				}
			}
			/*
			REP(nn, N){
				REP(kk, int(A[nn].size())) {
					cout <<A[nn][kk]<<" ";
				}
				cout<<endl;
			}
			*/

		}


	}

	cout<<ans<<endl;
	//cin>>N;
	return 0;
}

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

using namespace std;

int main() {
  int N, M;
  
  cin >> N >> M;
  
  vector<int> flist(M, 0);
  
  for (int i = 0; i < N; i++) {
    int K_in;
    
    cin >> K_in;
    
    for (int j = 0; j < K_in; j++) {
      int in;
      
      cin >> in;
      
      flist[in - 1]++;
    }
  }
  
  int ans = 0;
  
  for (int i = 0; i < M; i++) {
    if (flist[i] == N) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[110000];
int main(){
	int a;scanf("%s%d",in,&a);
	int len=0;
	for(int i=0;in[i];i++){
		len++;
		if(in[i]!='a'){
			int req='z'-in[i]+1;
			if(a>=req){
				a-=req;
				in[i]='a';
			}
		}
	}
	
	in[len-1]+=a%26;
	if(in[len-1]>'z')in[len-1]-=26;
	printf("%s\n",in);
}

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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(9)<<fixed;
	
	int n;
	cin>>n;
	int a[n];
	int x=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		x=x^a[i];
	}
	for(int i=0;i<n;i++)
	{
		int t=x^a[i];
		cout<<t<<" ";
	}
	cout<<endl;
	return 0;
}

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

#define int long long
#define x first
#define y second

const int MOD = 1e9 + 7LL;

int n, k;
vector<vector<int>> adj;
vector<int> fac;
vector<int> invFac;

int exp(int x, int y) {
	int res = 1LL;
	x %= MOD;
	while(y > 0) {
		if(y % 2LL) res *= x;
		x *= x;
		x %= MOD;
		res %= MOD;
		y /= 2LL;
	}
	return res % MOD;
}

int inv(int x) {
	return exp(x, MOD-2LL);
}

int C(int N, int K) {
	int rep = 1LL;
	rep *= fac[N];
	rep *= invFac[K];
	rep %= MOD;
	rep *= invFac[N-K];
	return rep % MOD;
}

void calc() {
	fac.resize(k+1);
	invFac.resize(k+1);
	fac[0] = 1LL;
	for(int i = 1; i <= k; i++) {
		fac[i] = (fac[i-1] * i) % MOD;
	}
	for(int i = 0; i <= k; i++)
		invFac[i] = inv(fac[i]);
}

int f(int u, int p) {
	int couleursAccessibles = k - 2LL;
	if(p == -1) couleursAccessibles += 1LL;
	int nbEnf = 0;
	for(int v : adj[u]) if(v != p) nbEnf++;
	if(couleursAccessibles < nbEnf) return 0;
	if(nbEnf == 0) return 1LL;
	int rep = C(couleursAccessibles, nbEnf) * fac[nbEnf];
	rep %= MOD;
	for(int v : adj[u]) if(v != p)
		rep *= f(v, u), rep %= MOD;
	return rep % MOD;
}

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

	cin >> n >> k;
	adj.assign(n, vector<int>());

	calc();

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

	cout << (k*f(0, -1))%MOD << endl;
}




















































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

    using namespace std;
     
    int main()
    {
    	string s;
    	cin>>s;
    	vector<int> c(26);
    	for(int i=0;i<s.size();i++)
    		c[s[i]-'a']++;
    	if(s.size()<26)
    	{
    		for(int i='a';i<='z';i++)
    			if(!c[i-'a'])
    			{
                    s=s+(char)i;
                    break;
                }
    		cout<<s;
    	}
    	else
    	{
    		s+=' ';
    		if(next_permutation(s.begin(),s.end()))
    		{
    			for(int i=0; s[i]!=' ';i++)
    				cout<<s[i];
    		}
    		else
    			cout<<-1;
    	}
    	return 0;
    }

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
X = list(map(int, input().split()))

ps = [0] + list(filter(lambda x: x >= 0, X))
ns = [0] + list(sorted(filter(lambda x: x < 0, X), reverse=True))

ans = INF
for i in range(len(ns)):
    val = abs(ns[i]) * 2
    if K - i >= 0 and K - i < len(ps):
        val += abs(ps[K - i])
        ans = min(ans, val)

for i in range(len(ps)):
    val = abs(ps[i]) * 2
    if K - i >= 0 and K - i < len(ns):
        val += abs(ns[K - i])
        ans = min(ans, val)
print(ans)


Measured memory_bytes: 20484
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int f = n / 100;
	int b = n % 100;
	bool check1 = false;
	bool check2 = false;

	if (1 <= b && b <= 12)
		check1 = true;
	if (1 <= f && f <= 12)
		check2 = true;
	if (check1 && check2)
		printf("AMBIGUOUS\n");
	else if (!check1 && !check2)
		printf("NA\n");
	else if (check1)
		printf("YYMM\n");
	else if (check2)
		printf("MMYY\n");
	return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


N, K = map(int, input().split())
R = N-K

for i in range(1, K+1):
    if i > R+1:
        print(0)
    else:
        ans = cmb(R+1, i, mod) * cmb(K-1, i-1, mod) % mod
        print(ans)



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

int main(){
  ll h,w,ch,cw,dh,dw,i;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<string> s(h);
  for(i=0;i<h;i++){
    cin >> s.at(i);
  }
  vector<vector<ll>> m(h,vector<ll>(w,9999999));
  
  queue<pair<ll,ll>> q;
  vector<pair<ll,ll>> v(0),v2(0);
  v.push_back(pair<ll,ll>(ch,cw));
  q.push(pair<ll,ll>(ch,cw));
  m.at(ch).at(cw)=0;
  ll mag=0;
  while(!q.empty()){
    while(!q.empty()){
      ll x=q.front().first,y=q.front().second;
      if(x>=1&&s.at(x-1).at(y)=='.'&&m.at(x-1).at(y)==9999999){
        m.at(x-1).at(y)=m.at(x).at(y);
        q.push(pair<ll,ll>(x-1,y));
        v.push_back(pair<ll,ll>(x-1,y));
      }
      if(x<=h-2&&s.at(x+1).at(y)=='.'&&m.at(x+1).at(y)==9999999){
        m.at(x+1).at(y)=m.at(x).at(y);
        q.push(pair<ll,ll>(x+1,y));
        v.push_back(pair<ll,ll>(x+1,y));
      }
      if(y>=1&&s.at(x).at(y-1)=='.'&&m.at(x).at(y-1)==9999999){
        m.at(x).at(y-1)=m.at(x).at(y);
        q.push(pair<ll,ll>(x,y-1));
        v.push_back(pair<ll,ll>(x,y-1));
      }
      if(y<=w-2&&s.at(x).at(y+1)=='.'&&m.at(x).at(y+1)==9999999){
        m.at(x).at(y+1)=m.at(x).at(y);
        q.push(pair<ll,ll>(x,y+1));
        v.push_back(pair<ll,ll>(x,y+1));
      }
      q.pop();
    }
    for(i=0;i<v.size();i++){
      ll x=v.at(i).first,y=v.at(i).second,j,k;
      for(j=-2;j<=2;j++){
        for(k=-2;k<=2;k++){
          if(0<=x+j&&x+j<=h-1&&0<=y+k&&y+k<=w-1&&s.at(x+j).at(y+k)=='.'&&m.at(x+j).at(y+k)==9999999){
            m.at(x+j).at(y+k)=m.at(x).at(y)+1;
            v2.push_back(pair<ll,ll>(x+j,y+k));
            q.push(pair<ll,ll>(x+j,y+k));
          }
        }
      }
    }
    v=v2;
    v2={};
  }
  
  if(m.at(dh).at(dw)==9999999){
    cout << -1 << endl;
  }else{
    cout << m.at(dh).at(dw) << endl;
  }
}

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

long long int s[214514] = {};
bool f[214514] = {};

int main() {

    long long int n, q;
    cin >> n >> q;

    vector< vector< long long int > > v;
    for ( long long int i = 0; i < n; i++ ) {
        vector< long long int > vv;
        v.push_back( vv );
    }

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

    for ( long long int i = 0; i < q; i++ ) {
        long long int p, x;
        cin >> p >> x;
        p--;
        s[p] += x;
    }

    queue< pair< long long int, long long int > > d;
    d.push( make_pair( 0, 0 ) );

    while( d.size() > 0 ) {
        long long int k = d.front().first;
        long long int m = d.front().second;
        d.pop();
        if ( f[k] == true ) continue;
        f[k] = true;
        s[k] += m;
        for ( long long int i = 0; i < v[k].size(); i++ ) {
            long long int kk = v[k][i];
            if ( f[kk] == true ) continue;
            d.push( make_pair( kk, s[k] ) );
        }
    }

    for ( long long int i = 0; i < n; i++ ) {
        if ( i > 0 ) cout << " ";
        cout << s[i];
    }
    cout << endl;

    return 0;

}


Measured memory_bytes: 21324
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy";
        return 0;
    }
    if(s=="Cloudy")
    {
        cout<<"Rainy";
        return 0;
    }
    if(s=="Rainy")
    {
        cout<<"Sunny";
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
str = list(input())

def isKaibun(src):
  rev = src[:]
  rev.reverse()

  return src == rev


N = len(str)

def num(N):
  return N-1

s1 = num(1)
e1 = (num(N)-1) // 2 + 1
s2 = (num(N) + 3) // 2
e2 = num(N) + 1

if isKaibun(str) and isKaibun(str[s1:e1]) and isKaibun(str[s2:e2]):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int W,N,Case = 1;
    while(cin >> W, W){
        int dp[1005][1005] = {0};
        cin >> N;
        range(i,1,N+1){
            int w, v;
            scanf("%d%*c%d", &v, &w);
            range(j,1,W+1){
                if(j - w >= 0)
                    dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }
        range(i,1,W+1){
            if(dp[N][i] == dp[N][W]){
                cout << "Case " << Case << ':' << endl << dp[N][W] << endl << i << endl;;
                break;
            }
        }
        Case++;
    }
}

Measured memory_bytes: 5200
s=list(input())
B=0;W=0;b=0;w=0
for i in range(len(s)):
  if s[i]=='B':B+=i+1
  elif s[i]=='W':W+=i+1
x=B-W
s.sort()
s.reverse()
for j in range(len(s)):
  if s[j]=='B':b+=j+1
  elif s[j]=='W':w+=j+1
y=b-w
print(int(abs(x-y)/2))

Measured memory_bytes: 5156
import Data.List
import Data.Maybe

main = do
  (n:h:_) <- getLine >>= return . map read . words :: IO [Int]
  ktn <- getContents >>= return . map (map read . words) . lines :: IO [[Int]]

  let
    (a:_) = maximumBy (\(x:_) (y:_) -> compare x y) ktn
    b = scanl (+) 0 $ reverse $ sort $ map (\(x:y:_) -> y) $ filter (\(_:x:_) -> x > a) ktn
  
    c = findIndex (>=h) b

    d =
      if c == Nothing then
        ceiling ((fromIntegral (h-last b)) / (fromIntegral a)) + (length b - 1)
      else
        fromJust c

  print $ d


Measured memory_bytes: 149884
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum,a[310000], b[310000];
string str;
bool f;
char c[1100][1100];
int main() {
	cin >> n>>m;
	if (n <= 5)
		cout << 0 << endl;
	else if (n <= 12)
		cout << m / 2 << endl;
	else
		cout << m << endl;
	return 0;
}


Measured memory_bytes: 764
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	s = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n-1)]
	# s = list(s)
	
	print(int(s**2))
	
 
 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
/*
Author            : Md. Anwarul Habib
Dept. & Institute : CSE - 41st Batch , Ahsanullah University of Science & Technology
Problem Name      : Atcoder-A - Password
*/

#include<bits/stdc++.h>

using namespace std;

long long int i,j,k,l,m,n,t,a,b,c,d,x,y,sum=0,total=0;

int main()
{
    scanf("%lld",&n);
    printf("%lld\n",n*n*n);

}



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

int main()
{
    std::size_t D;
    std::cin >> D;
    std::array<std::uint16_t, 26> Cs;
    for(auto& c : Cs)
    {
        std::cin >> c;
    }

    std::vector<std::array<std::uint16_t, 26>> ss(D);
    for(std::size_t c=0; c<26; ++c)
    {
        for(std::size_t i=0; i<D; ++i)
        {
            std::cin >> ss[i][c];
        }
    }

    std::array<std::uint16_t, 26> last_day;
    last_day.fill(0);

    std::int32_t score = 0;
    for(std::size_t day=1; day<=D; ++day)
    {
        const auto& saty = ss[day-1];
        std::size_t contest = 0;
        std::int32_t s_diff = saty[0] - Cs[0] * (day - last_day[0]);
        for(std::size_t c=1; c<26; ++c)
        {
            std::int32_t c_diff = saty[c] - Cs[c] * (day - last_day[c]);
            if(s_diff < c_diff)
            {
                s_diff = c_diff;
                contest = c;
            }
        }
        last_day[contest] = day;
        score += s_diff;
        std::cout << contest + 1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const 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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> suzu(3);
    for(int i=0; i<3; i++) cin >> suzu[i];
    sort(suzu.rbegin(),suzu.rend());
    int K;
    cin >> K;
    for(int i=0; i<K; i++){
        suzu[0] *= 2;
    }
    int sum = 0;
    for(int i=0; i<3; i++) sum += suzu[i];
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-

from math import ceil,floor

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

# def func(a):
#    return tmp

N = int(input())
A = list(map(int, input().split()))

ans = "APPROVED"

for i in range(0,N):
    if (A[i]%2)==0:
        if not(A[i]%3==0 or A[i]%5==0):
            ans = "DENIED"

print(ans)


Measured memory_bytes: 38256