akhauriyash/Code-Regression huggingface dataset:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

h, w, k = map(int, input().split())
s = ['' for _ in range(h)]
ans = 0
for i in range(h):
    s[i] = input()
for xi in range(2**h):
    t = deepcopy(s)
    b = [0 for _ in range(w)]
    for i in range(h):
        if ((xi >> i)&1):
            t[i] = ''
            for j in range(w):
                t[i] += '.'
    for i in range(h):
        for j in range(w):
            if t[i][j] == '#':
                b[j] += 1
    for xj in range(2**w):
        sumv = 0
        for j in range(w):
            if ((xj >> j)&1):
                sumv += b[j]
        if sumv == k: ans += 1
print(ans)



Measured memory_bytes: 10584
from collections import deque

N, M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

graph = [deque([]) for _ in range(N + 1)]
for _ in range(M):
    u, v = [int(x) for x in input().split()]
    graph[u].append(v)
    graph[v].append(u)  # 無向グラフ

good = []
t = [-1] * (N + 1)


def dfs(v):
    stack = [v]
    flg = True
    t[v] = 1
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if H[w-1] >= H[v-1]:
                flg = False
            else:
                t[w] = 1
        else:
            stack.pop()
    if flg:
        good.append(v)



# 孤立している頂点対策
for i in range(N):
    if t[i+1] < 0:
        dfs(i + 1)

print(len(good))


Measured memory_bytes: 150004
//
// Created by Tzyark on 2018/9/18.
//
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
    string s;
    cin >> s;
    int n = (int) s.size();

    ll ans = 0;
    for (ll x = 0; x < (1 << (n-1)); x++) {
        ll y = s[0] - '0';
        for (int i = 0; i < n-1; i++) {
            if (x & (1 << i)) {
                ans += y;
                y = s[i+1] - '0';
            } else {
                y = y*10 + s[i+1]-'0';
            }
        }
        ans += y;
    }
    cout << ans;
    return 0;
}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> void SORT(vector<T> &a) { sort(a.begin(), a.end()); }
template <class T> void SORTR(vector<T> &a) { sort(a.rbegin(), a.rend()); }
template <class T> void UNIQUE(vector<T> &a) { a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N, M;
int A[10];
int C[11] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10010];
int used[10010];

bool comp(string s, string t) {
  int sz = SZ(s), tz = SZ(t);
  if (sz != tz) return sz > tz;
  return s >= t;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  REP(i, M) cin >> A[i];
  ZERO(used);
  used[0] = 1;
  REP(i, N) if (used[i]) {
    REP(j, M) {
      int c = C[A[j]];
      string s = dp[i]+NUM(A[j]);
      if (i+c <= N && comp(s, dp[i+c])) {
        used[i+c] = 1;
        dp[i+c] = s;
      }
    }
  }
  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 43648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.length()<=k)cout << s;
	else{
		rep(i,k)cout << s[i];
		cout << "...";
	}
}


Measured memory_bytes: 3624
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

a,b,k = map(int,input().split())
g = gcd(a,b)
cnt = 1

while cnt != k:
    g -= 1
    if a%g == 0 and b%g == 0:
        cnt += 1
else:
    ans = g

print(ans)

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

using namespace std;


typedef long long ll;

const int M = 1e9+7 ;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h , w; 
    cin >> h >> w; 

    ll tot  = h*w ;

    if ((w == 1) || (h == 1)){
        cout << 1 << "\n";
        return 0; 
    }
    if (tot % 2){
        cout  << tot - (tot/2) << "\n";
    }
    else {
        cout << tot/2 << "\n";
    }
    
  
    return 0;
}



Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
x=[[],[],[]]
for i in range(n):
    x[i%3]+=i+1,
for a,b in zip(*[iter(t)]*2):
    e[a-1]+=b-1,
    e[b-1]+=a-1,
a=[-1]*n
p=a[:]
p[0]=0
s=[0]
c=[1,0]
while s:
    v=s.pop()
    for w in e[v]:
        if p[w]<0:
            p[w]=p[v]^1
            c[p[w]]+=1
            s+=w,
if min(c)<=n//3:
    x[0]+=x[1]
    f=c[0]<=n//3
    for i,v in enumerate(p):
        j=(v==f)-1
        a[i]=x[j if x[j]else-1].pop()
else:
    for i,v in enumerate(p):
        a[i]=x[v if x[v]else-1].pop()
print(*a)

Measured memory_bytes: 126044
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n; cin >> n;
	int i = 1;
	while ((i + 1)*(i + 1) <= n) i++;
	cout << (i*i) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main(){
    
    long int r, D, x;
    cin >> r >> D >> x;
    long int xb = 0;
    
    for (int i = 1; i <= 10; i++) {
        xb = r * x - D;
        cout << xb << endl;
        x = xb;
        
    }
   
    
    
    return 0;
    
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> data(n);
  for(int i = 0; i < n; i++)
  {
    cin >> data.at(i);
  }
  sort(begin(data), end(data));
  reverse(begin(data), end(data));
  int count = 0;
  int judge = 0;
  for(int i = 0; i < n; i++)
  {
    if(i == 0 || judge > data.at(i))
    {
      count++;
      judge = data.at(i);
    }
    else if(judge == data.at(i))
    {
      continue;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l,q,a[100005],b[100005][21];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&l);
	int dem=1,sum=0;
	for(int i=2;i<=n;i++){
		sum+=a[i]-a[i-1];
		while(sum>l){
			b[dem][0]=i-1;
			dem++;
			sum-=(a[dem]-a[dem-1]);
		}
	}
	for(int i=dem;i<=n;i++){
		b[i][0]=n;
	}
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i<=n;i++){
			b[i][j]=b[b[i][j-1]][j-1];
		}
	}
	scanf("%d",&q);
	while(q--){
		int u,v;
		scanf("%d %d",&u,&v);
		if(u>v) swap(u,v);
		int ans=1;
		for(int i=log2(n);i>=0;i--){
			if(b[u][i]<v){
				u=b[u][i];
				ans+=(1<<i);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 9472
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

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

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

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  const int n = N;
  int a[n],num[100000]={},max = 0;
  for (size_t i = 0; i < n; i++) {
    std::cin >> a[i];
  }

for (size_t i = 0; i < n; i++) {
  if (a[i]==0) {
    num[a[i]]++;
    num[a[i]+1]++;
  }else{
    num[a[i]-1]++;
    num[a[i]]++;
    num[a[i]+1]++;
  }
}
for (size_t i = 0; i < 100000; i++) {
  if (max < num[i]) {
    max = num[i];

  }
}
std::cout << max;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){ 
    int a, b,c,cnt=0; 
    scanf("%d %d %d",&a, &b, &c);  
    for (int i = a; i <= b; ++i) { 
        if (c%i == 0) ++cnt;
    }    
    printf("%d\n", cnt);  
    return 0; 
    
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	int a[5];
	for(int i=0;i<5;i++) cin>>a[i];
	for(int i=0;i<5;i++)
	{
		if(a[i]==0) cout<<i+1<<endl;
	}
 	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define PI 3.141592653
#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);
}
int main(void){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        if(i*(i+1)/2>=n){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}


int main(){
	fast;
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=1; i<=n;i++) cin>>a[i];
    ll dp[n+1][2]={};
    dp[1][0] = 0;
    dp[1][1] = a[1];
	for(ll i = 2; i <= n ; i++){
		 if(i%2 == 0){
		 	  dp[i][0] = max(dp[i-1][1],dp[i-2][0]+a[i]);
		 }
		 else{
		 	 dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i]);
		 	 dp[i][1] = dp[i-2][1]+a[i];
		 }
       
	}

	cout<<dp[n][0]<<endl;
 
}


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


from collections import defaultdict

class ReRooting:
    def __init__(self, f, g, merge, ie):
        self.tree = defaultdict(list)
        self.f = f
        self.g = g
        self.merge = merge
        self.ie = ie
        self.dp = defaultdict(dict)

    def add_edge(self, u, v):
        self.tree[u].append(v)
        self.tree[v].append(u)

    def __dfs1(self, u, p):
        o = []
        s = [(u, -1)]
        while s:
            u, p = s.pop()
            o.append((u, p))
            for v in self.tree[u]:
                if v == p:
                    continue
                s.append((v, u))

        for u, p in reversed(o):
            r = self.ie
            for v in self.tree[u]:
                if v == p:
                    continue
                # ep(u_, v, self.dp)
                r = self.merge(r, self.f(self.dp[u][v], v))
            self.dp[p][u] = self.g(r, u)

    def __dfs2(self, u, p, a):
        s = [(u, p, a)]

        while s:
            u, p, a = s.pop()

            self.dp[u][p] = a

            pl = [0] * (len(self.tree[u]) + 1)
            pl[0] = self.ie
            for i, v in enumerate(self.tree[u]):
                pl[i+1] = self.merge(pl[i], self.f(self.dp[u][v], v))

            pr = [0] * (len(self.tree[u]) + 1)
            pr[-1] = self.ie
            for i, v in reversed(list(enumerate(self.tree[u]))):
                pr[i] = self.merge(pr[i+1], self.f(self.dp[u][v], v))

            for i, v in enumerate(self.tree[u]):
                if v == p:
                    continue
                r = self.merge(pl[i], pr[i+1])
                s.append((v, u, self.g(r, v)))


    def build(self, root=1):
        self.__dfs1(root, -1)
        self.__dfs2(root, -1, self.ie)

    def slv(self, u):
        r = self.ie
        for v in self.tree[u]:
            r = self.merge(r, self.f(self.dp[u][v], v))

        return r


def main():
    N, M = map(int, input().split())
    XY = [list(map(int, input().split())) for _ in range(N-1)]

    f = lambda x, y: x
    g = lambda x, y: x + 1
    merge = lambda x, y: (x * y) % M
    rr = ReRooting(f, g, merge, 1)
    for x, y in XY:
        rr.add_edge(x, y)

    rr.build()
    for u in range(1, N+1):
        print(rr.slv(u))



if __name__ == '__main__':
    main()


Measured memory_bytes: 166100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int calccount(int n)
{
    int ret = 0;
    while(n > 0)
    {
        if (n % 2 == 1) ++ret;
        n = n / 2;
    }
    return ret;
}

int main()
{
    int N;
    cin >> N;
    bitset<200000> X;
    cin >> X;
    int popcntX = X.count();
    if (popcntX > 1)
    {
        // plusVal = X mod (popcount(X) + 1), minusVal = X mod (popcount(X) - 1)
        int plusVal = 0, minusVal = 0;
        for (int i = N - 1; i >= 0; --i) // 上位のビットから走査
        {
            plusVal = (plusVal * 2 + X[i]) % (popcntX + 1);
            minusVal = (minusVal * 2 + X[i]) % (popcntX - 1);
        }
        vector<int> factorPlus(N), factorMinus(N);
        factorPlus[0] = 1, factorMinus[0] = 1;
        for (int i = 1; i < N; ++i)
        {
            factorPlus[i] = (factorPlus[i - 1] * 2) % (popcntX + 1);
            factorMinus[i] = (factorMinus[i - 1] * 2) % (popcntX - 1);
        }

        vector<int> res(N, 1);
        for (int i = 0; i < N; ++i)
        {
            int num;
            if (X[N - 1 - i] == 1)
            {
                num = (minusVal - factorMinus[N - 1 - i] + popcntX - 1) % (popcntX - 1);
            }
            else
            {
                num = (plusVal + factorPlus[N - 1 - i] + popcntX + 1) % (popcntX + 1);
            }
            
            while(num > 0)
            {
                int popcntNum = calccount(num);
                num = num % popcntNum;
                ++res[i];
            }
        }

        for (int i = 0; i < N; ++i)
        {
            cout << res[i] << endl;
        }
        return 0;
    }
    else //(popcntX == 1)
    {
        int plusVal = 0;
        for (int i = N - 1; i >= 0; --i) // 上位のビットから走査
        {
            plusVal = (plusVal * 2 + X[i]) % (popcntX + 1);
        }
        vector<int> factorPlus(N);
        factorPlus[0] = 1;
        for (int i = 1; i < N; ++i)
        {
            factorPlus[i] = (factorPlus[i - 1] * 2) % (popcntX + 1);
        }

        vector<int> res(N, 1);
        for (int i = 0; i < N; ++i)
        {
            int num;
            if (X[N - 1 - i] == 1)
            {
                res[i] = 0;
                continue;
            }
            else
            {
                num = (plusVal + factorPlus[N - 1 - i] + popcntX + 1) % (popcntX + 1);
            }
            
            while(num > 0)
            {
                int popcntNum = calccount(num);
                num = num % popcntNum;
                ++res[i];
            }
        }

        for (int i = 0; i < N; ++i)
        {
            cout << res[i] << endl;
        }
        return 0;
    }
    return 0;
}


Measured memory_bytes: 5488
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  int A,ans=0;
  cin>>A;
  
  co(A*A);
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
import math
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def comb(n,r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,k = map(int, input().split())
    redn = n-k
    modn = 10**9+7
    for i in range(1,k+1):
        ans = comb(redn+1,i)*comb(k-1,i-1)%modn
        print(ans)
        

if __name__ == '__main__':
    main()


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

ys=[]
ss=[]

for i in range(n):
    [y, s]=[i for i in input().split()]
    ys.append(y)
    ss.append(s)

ans=0
for i in range(n):
    if ss[i]=="JPY":
        ans+=int(ys[i])
    else:
        ans+=float(ys[i])*380000

print(ans)


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

int main(void){
    
    string S;
    cin >> S;
    
    for(int i = 0; i < S.size()-1;i++){
        if(S[i]=='A' && S[i+1]=='C'){
            cout << "Yes"<<endl; 
            return 0;
        }
    }
    cout << "No"<<endl; 
    return 0;
    
}


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

ans = 0

for i in range(n - 1):
  x = v.pop(v.index(min(v)))
  y = v.pop(v.index(min(v)))

  ans = (x + y) / 2 
  v.append(ans)

print(ans)

Measured memory_bytes: 38896
#include <iostream>
#include <cmath>
#include <vector>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> s;
 
    char temp;
    long long int ir = 0;
    long long int ig = 0;
    long long int ib = 0;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        //s.push_back(temp);
        if (temp == 'R') {
            s.push_back(1);
            ir++;
        }
        else if (temp == 'G') {
            s.push_back(2);
            ig++;
        }
        else {
            s.push_back(3);
            ib++;
        }
    }
    long long int ans = 0;
 
    ans = ir * ig * ib;
 
    int haba = (n - 1) / 2;
 
    for (int i = 1; i <= haba; i++) {
        for (int j = 0; j + i + i < n; j++) {
            if (s[j] != s[j + i] && s[j + i] != s[j + i + i] && s[j + i + i] != s[j]) {
                ans--;
            }
        }
    }
 
    cout << ans;
 
 
    return 0;
}

Measured memory_bytes: 3652
// uno {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }

// }}}
const int MAX_N = 200010;
int n, k, a[MAX_N], s[MAX_N];
map<int, LL> me;
void input()
{
    RI(n, k);
    REP(i, n) RI(a[i]);
}

void solve() {
    LL ans = 0;
    s[0] = 0;
    REP(i, n) s[i + 1] = (s[i] + a[i] - 1) % k;
    REP(i, n + 1)
    {
        if (i >= k)
            me[s[i - k]]--;
        ans += me[s[i]];
        #ifdef DEBUG
            cout << i << ' ' << ans << endl;
        #endif
        me[s[i]]++;
    }
    printf("%lld\n", ans);
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 14336
def prime_fact(n):
    primes = []
    i = 2
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            n //= i
            cnt += 1
        if cnt:
            primes.append([i, cnt])
        i += 1

    if n != 1:
        primes.append([n, 1])
    return primes

n = int(input())

primes = prime_fact(n)

cnt = 0
for i, j in primes:
    k = 1
    while k <= j:
        j -= k
        k += 1
        cnt += 1

print(cnt)

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<String> shiritoriList = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			shiritoriList.add(sc.next());
		}
		sc.close();

		ArrayList<String> checkList = new ArrayList<>();
		for(int i = 0; i < shiritoriList.size(); i++) {
			String word = shiritoriList.get(i);
			if(i != 0) {
				String formerWords = shiritoriList.get(i - 1);
				char lastWord = formerWords.charAt(formerWords.length() - 1);
				if(lastWord != word.charAt(0)) {
					System.out.println("No");
					return;
				}
				if(checkList.contains(word)) {
					System.out.println("No");
					return;
				}
			}
			checkList.add(word);
		}
		System.out.println("Yes");
		return;
	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  vector<int>counts(n,1);
  int i,j;
  j=0;
  int a,b;
  a = 0;
  b = 0;
  int count = 0;
  for(i=0;i<n;i++){
    if(i<n-2&&s[i]=='R'&&s[i+1]=='R'){
      counts[i+2]+=counts[i];
      counts[i]=0;
    }
  }
  for(i=n-1;i>=0;i--){
    if(i>1&&s[i]=='L'&&s[i-1]=='L'){
      counts[i-2]+=counts[i];
      counts[i]=0;
    }
  }
  for(i=0;i<n;i++){
    cout << counts[i] << endl;
  }
}


Measured memory_bytes: 1024
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;

int main()
{
    IOS();

    int n,i;
    cin>>n;
    string s,res="";
    cin>>s;
    f(i,0,s.size())
    {
    	char c;
    	int w=n;
    	if(s[i]-'A'+n>25)
    	{
    		w=n+(s[i]-'A')-26;
    		c=char('A'+w);
    	}
    	else
    		c=char(s[i]+n);
    	res+=c;
    }
    cout<<res<<'\n';
    
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var count = 0
    val set = mutableSetOf(
            333, 335, 337, 353, 355, 357, 373, 375, 377,
            533, 535, 537, 553, 555, 557, 573, 575, 577,
            733, 735, 737, 753, 755, 757, 773, 775, 777
    )
    for (i in 1..6) {
        val temp = mutableSetOf<Int>().apply { addAll(set) }
        for (v in temp) {
            set.add((v.toString() + "3").toInt())
            set.add((v.toString() + "5").toInt())
            set.add((v.toString() + "7").toInt())
            set.add(("3" + v.toString()).toInt())
            set.add(("5" + v.toString()).toInt())
            set.add(("7" + v.toString()).toInt())
        }
    }
    val temp = set.filter { it.toString().contains('3')&&it.toString().contains('5') &&it.toString().contains('7')}
    println(temp.count { it <= n})
}


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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> v(n);
  for(ll i=0;i<n;i++) {
    cin >> v[i];
  }
  ll ans=0;
  for(ll i=1;i<=min(n,k);i++) {
    for(ll j=0;j<=i;j++) {
      ll tans=0;
      ll count=k-i;
      priority_queue<ll,vector<ll>,greater<ll>> q;
      for(ll l=0;l<j;l++) {
        tans+=v[l];
        q.push(v[l]);
      }
      for(ll l=0;l<i-j;l++) {
        tans+=v[n-1-l];
        q.push(v[n-1-l]);
      }
      while(q.size()&&count>0&&q.top()<0) {
        tans-=q.top();
        q.pop();
        count--;
      }
      ans=max(ans,tans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={0, 1, 0, -1};
int dy[]={-1, 0, 1, 0};





int maxg,ans,n,t[10][10];

int getxy(int g){
	int x=1,y;
	int plus = n-1;
	for(int i = n-1;plus >= 1;x++){
		plus--;
		if(g <= i){
			y = n - (i - g);
			break;
		}
		i += plus;
	}

	return (10*x+y);
}

void solve(int g,int l[10],int w[10]){
	int xy = getxy(g);
	int x = xy / 10,y = xy % 10;

	int eq = (n-1)/2;
	if(g == maxg){ //finish solve
		if(t[x][y] == 1){  //win
			if(w[x] == eq && l[y] == eq){
				ans++;
			}
		}else if(t[x][y] == -1){
			if(w[y] == eq && l[x] == eq){
				ans++;
			}
		}else{
			if(w[x]+1 == eq && l[y]+1 == eq){
				ans++;
			}
			if(w[y]+1 == eq && l[x]+1 == eq){
				ans++;
			}
		}
		return;
	}else if(t[x][y] == 0){
		if(w[x]+1 <= eq && l[y]+1 <= eq){
			w[x]++; l[y]++;
			solve(g+1,l,w);
			w[x]--; l[y]--;
		}
		if(w[y]+1 <= eq && l[x]+1 <= eq){
			w[y]++; l[x]++;
			solve(g+1,l,w);
			w[y]--; l[x]--;
		}
	}else if(t[x][y] == -1){
		if(w[y] <= eq && l[x] <= eq){
			solve(g+1,l,w);
		}
	}else{
		if(w[x] <= eq && l[y] <= eq){
			solve(g+1,l,w);
		}
	}
	return;
}


int d[40][2];
int l[10],w[10],g;

int main(){
	int m;
	while(true){
		cin >> n;
		if(n == 0)break;
		cin >> m;
		maxg = 0;
		ans = 0;
		for(int i = n-1;i >= 1;i--){
			maxg += i;
		}
		for(int i = 1;i <= n;i++){
			l[i] = 0;
			w[i] = 0;
			for(int j = 1;j <= n;j++){
				t[i][j] = 0;
			}
		}

		for(int i = 0;i < m;i++){
			int x,y;
			cin >> x >> y;
			w[x]++;
			l[y]++;
			t[x][y] = 1;
			t[y][x] = -1;
		}
		solve(1,l,w);
		cout << ans << endl;

	}

}


Measured memory_bytes: 3024
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double sum = 0;
    for(int i=0; i<N; i++){
      sum += 1.0/sc.nextInt();
    }
    sum = 1.0/sum;
 
    System.out.print(sum);
  }
}


Measured memory_bytes: 21716
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 開催するコンテスト
    T = randomize(D)

    def scoring():
        # 最後に開かれた日付
        last = [0]*26
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            last[T[i]-1] = i+1
            for j in range(26):
                score -= C[j] * (i+1 - last[j])
        return score

    max_score = scoring()
    # print(max_score)
    ans = T.copy()
    # a = 0
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # if a % 10000 == 0:
        #     print(a, *T, score, max_score)
        # a += 1
        end = get_now()
    print(*ans, sep='\n')

main()


Measured memory_bytes: 9816
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
mo=10**9+7
imp='IMPOSSIBLE'

n,m=MI()
w=[[] for _ in range(10**5+3)]
for i in range(n):
    a,b=MI()
    w[a].append(-b)

q=[]
ans=0
for i in range(1,m+1):
    for j in w[i]:
        heappush(q,j)
    if q:
        x=heappop(q)
        ans+=-x
        

print(ans)


Measured memory_bytes: 73448
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define MOD 1000000007
using namespace std;
typedef long long ll;
#define int long long

char s[300005];
int n;
int dp[300005][2][2];

int f(int k, int d, int p){
	int& r=dp[k][d][p];
	if(r>=0)return r;
	r=0;
	if(k==0){
		if(s[0]=='?')r=(f(k+1,0,0)+f(k+1,1,1))%MOD;
		else r=f(k+1,s[0]-'0',s[0]-'0');
	}
	else if(k==n)r=!p||!d;
	else if(k==n-1)r=!p||s[k]!='1';
	else {
		if(d==1&&p==1){
			if(k==n-2){
				r=s[k]!='1'&&s[k+1]!='1';
				//fore(a,0,2)fore(b,0,2){
				//	if(s[k]=='0'+(a^1))continue;
				//	if(s[k+1]=='0'+(b^1))continue;
				//	if(a+)
				//}
			}
			else if(s[k]=='1')r=0;
			else r=f(k+1,0,1);
		}
		else {
			fore(a,0,2)fore(b,0,2){
				if(s[k]=='0'+(a^1))continue;
				if(s[k+1]=='0'+(b^1))continue;
				int nd=a+b+d>=2;
				if(nd&&p)continue;
				r+=f(k+2,nd,p||nd);r%=MOD;
			}
		}
	}
	return r;
}

main(){
	mset(dp,-1);
	scanf("%s",s);n=strlen(s);
	if(n==1){
		if(s[0]=='0')puts("0");
		else puts("1");
		return 0;
	}
	int a=1;
	fore(i,0,n)if(s[i]=='?')a=(a*2)%MOD;
	//printf(" %lld\n",a);
	printf("%lld\n",(a+MOD-f(0,0,0))%MOD);
	return 0;
}

Measured memory_bytes: 21632
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, K = LI()

    if K > ((N-1) * (N-2)) // 2 :
        print(-1)
        return

    V = []

    import itertools

    # 中心をNとするN-1角形を書いて、中心とそのほか全てを繋ぐ。
    for i in range(1, N):
        V.append((i, N))
    # このとき、 K = Kmax = N-1 C 2 本。
    # ここから、辺を1本追加するごとに、Kは1つずつ減少していく。
    # Kが欲しい値になったときに、追加するのをやめる。
    left = ((N-1) *  (N-2)  // 2) - K
    for i,j in itertools.combinations(range(1, N), 2):
        if left == 0: break
        V.append((i,j))
        left -= 1

    print(len(V))
    for item in V:
        print(item[0], item[1])
    return

main()

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    if (a>=b) {
        cout<<"delicious"<<endl;
    } else {
        if (b-a<=x) {
            cout<<"safe"<<endl;
        } else {
            cout<<"dangerous"<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<int> C;

int main() {
    C dr[] = {C(-1, 0), C(0, -1), C(1, 0), C(0, 1)};
    int N;
    int n[200], d[200];
    while (true) {
        C arrangement[200];
        cin >> N;
        if (N == 0) {
            break;
        }
        n[0] = -1;
        d[0] = -1;
        for (int i=1; i<N; i++) {
            cin >> n[i] >> d[i];
        }
        int x_max = 0;
        int x_min = 0;
        int y_max = 0;
        int y_min = 0;
        arrangement[0] = C(0, 0);
        for (int i=0; i<N; i++) {
            for (int j=0; j<N; j++) {
                if (n[j] < 0) {
                    continue;
                }
                if (n[j] == i) {
                    arrangement[j] = arrangement[i]+dr[d[j]];
                    if (arrangement[j].real() > x_max) {
                        x_max = arrangement[j].real();
                    }
                    else if (arrangement[j].real() < x_min) {
                        x_min = arrangement[j].real();
                    }
                    if (arrangement[j].imag() > y_max) {
                        y_max = arrangement[j].imag();
                    }
                    else if (arrangement[j].imag() < y_min) {
                        y_min = arrangement[j].imag();
                    }
                    n[j] = -1;
                }
            }
        }
        cout << x_max-x_min+1 << ' ' << y_max-y_min+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>


int main()
{
	int a,b,c,t;
	scanf("%d%d%d",&a,&b,&c);
	if(a>=b){
		t=a;a=b;b=t;
	}
	if(b>=c){
		t=b;b=c;c=t;
	}	
	if(a>=b){
		t=a;a=b;b=t;
	}
	if(a>=b){
		t=a;a=b;b=t;
	}
	if(b>=c){
		t=b;b=c;c=t;
	}	
	if(a>=b){
		t=a;a=b;b=t;
	}
	printf("%d",c-a);
	
	
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)

using namespace std;

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

    vector<int> ones{0};
    while (ones[ones.size() - 1] < N)
        ones.push_back(ones[ones.size() - 1] * 10 + 1);

    long long result = 0;
    FOR(A, 1, N + 1) {
        if (A < 10) {
            result += 1;
        } else {
            string s = to_string(A);
            char head = s[0];
            char tail = s[s.size() - 1];
            if (tail == '0') continue;
            if (head < tail) {
                result += ones[s.size() - 2] * 2;
            } else if (head > tail) {
                result += ones[s.size() - 1] * 2;
            } else /* if (head == tail) */ {
                int mid;
                if (s.size() > 2) {
                    mid = stoi(s.substr(1, s.size() - 2));
                } else {
                    mid = 0;
                }
                result += (1 + ones[s.size() - 2] + mid) * 2 + 1;
            }
        }
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;
int main()
{
    long long a,b;
    long long x;
    cin >> x;
    long long buf = 0;
    bool ans = false;
    int i = 0;
    a = -118;
    b = -118;
    while(a<120){
        b = -118;
        while(b<120){
            if(x==a*a*a*a*a-b*b*b*b*b){
                i = 1;
                break;
            }
            //cout << a*a*a*a*a-b*b*b*b*b;
            b++;
        }
        if(i==1){
            break;
        }
        a++;
    }
    cout << a << " " << b;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A) rep(i,0,A.size()){cout<<(i ? " ":"")<<A[i];}cout<<endl;
const long mod=2019;
int main(){
	long R,L;cin>>L>>R;
	if(R-L>=2018||R/mod<L/mod){
		cout<<0<<endl;
	}else{
		long res=mod;
		L=L%mod;R=R%mod;
		rep(i,L,R+1){
			rep(j,i+1,R+1){
				res=min(res,(i*j)%mod);
			}
		}cout<<res<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int n = a[0];
    int lb = 1, ub = N;
    while (lb + 1 < ub) {
        int mid = (lb + ub) / 2;
        if (a[mid] - n / 2 >= 0) lb = mid;
        else ub = mid;
    }
    if (lb+1 < N && n/2 - a[lb+1] < a[lb] - n/2)
        lb = lb+1;
    cout << n << " " << a[lb] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N),y(M);
    for (int i = 0; i < N; i++){
        cin >> x.at(i);
    }
    for (int i = 0; i < M; i++){
        cin >> y.at(i);
    }

    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    int x_max = x.at(N-1);
    int y_min = y.at(0);

    if (x_max >= y_min){
        cout << "War" << endl;
    }else if(y_min <= X){
        cout << "War" << endl;
    }else if(x_max >= Y){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }

}

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

int way;
long long int cost[102];

bitset<102> dv[102];
long long int C;

vector<int> gr[102];

bool pos[102];


inline void dfs(long long int idx, bitset<102> val) {
	if (idx == 25) {
		long long int ans = 0;
		for (int j = 1; j <= 24; j++) {
			if ((val&dv[j]) == 0LL) {
				ans += cost[j];
			}
		}
		for (int j = 25; j <= 50; j++) {
			if (j * 3 <= 100 && j % 2) {
				if ((dv[j] & val).any())continue;
				long long int U = cost[j];
				if ((val&dv[j * 2]) == 0LL) {
					U += max(0LL, cost[j * 2]);
				}
				if ((val&dv[j * 3]) == 0LL) {
					U += max(0LL, cost[j * 3]);
				}
				if (U >= 0) {
					ans += cost[j];
				}
				else {
					val.set(j, 1);
					//val |= (1LL << (long long int)(j));
				}
				continue;
			}
			if (j * 3 <= 100) {
				int o1 = j;
				int o2 = j * 3 / 2;
				long long int www = 0;
				int id = -1;
				for (int k = 0; k < 4; k++) {
					auto val2 = val;
					if (k & 1) {
						val2.set(o1, 1);
						//val2 |= (1LL << (long long int)(o1));
					}
					if ((k >> 1) & 1) {
						//val2 |= (1LL << (long long int)(o2));
						val2.set(o2, 1);
					}
					long long int ad = 0;
					for (auto el : gr[j]) {
						if ((dv[el] & val2) == 0LL) {
							if (el >= 50) {
								ad += max(0LL, cost[el]);
							}
							else {
								ad += cost[el];
							}
						}
					}
					www = max(www, ad);
					if (www == ad) {
						id = k;
					}
				}
				if (id & 1) {
					val.set(o1, 1);
					//val |= (1LL << (long long int)(o1));
				}
				if ((id >> 1) & 1) {
					//val |= (1LL << (long long int)(o2));
					val.set(o2, 1);
				}
				for (auto el : gr[j]) {
					if ((dv[el] & val) == 0LL) {
						if (el >= 50) {

						}
						else {
							ans += cost[el];
						}
					}
				}
				continue;
			}
			if (pos[j] == false) {
				if ((val&dv[j]).any())continue;
				long long int nex = j * 2;
				long long int U = cost[j];
				if ((val&dv[nex]) == 0LL) {
					U += max(0LL, cost[nex]);
				}
				if (U >= 0) {
					ans += cost[j];
				}
				else {
					val |= (1LL << (long long int)(j));
				}
				continue;
			}
		}
		for (int j = 51; j <= 100; j++) {
			if ((val&dv[j]).any()) {
				continue;
			}
			ans += max(0LL, cost[j]);
		}
		C = max(C, ans);

		return;
	}
	bool ng = false;
	if ((val&dv[idx]).any()) {
		ng = true;
	}
	if (ng == false) {
		dfs(idx + 1, val);
	}
	val.set(idx, 1);
	dfs(idx + 1, val );
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 100; i++) {
		scanf("%lld", &cost[i]);
	}
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				dv[i].set(j, 1);// |= (1LL << (long long int)(j));
			}
		}
		if (i >= 25) {
			if (i * 3 <= 100) {
				gr[i].push_back(i);
				gr[i].push_back(i * 3);
				gr[i].push_back(i * 3 / 2);
				gr[i].push_back(i * 2);
				if ((i * 3) % 2 == 0)pos[i * 3 / 2] = true;
			}
		}
	}
	dfs(1, 0);
	printf("%lld\n", C);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int index = 1;
            foreach(char c in str)
            {
                if(c == 'U' | c == 'D')
                {

                }
                else
                {
                    if (index % 2 == 1)
                    {
                        if(c == 'L')
                        {
                            Console.WriteLine("No");
                            //Console.ReadKey();
                            return;
                        }
                    }
                    else
                    {
                        if(c == 'R')
                        {
                            Console.WriteLine("No");
                            //Console.ReadKey();
                            return;
                        }
                    }
                }
                index++;
            }
            Console.WriteLine("Yes");
            //Console.ReadKey();

        }
    }
}


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

using namespace std;
const int N = 1e5;
int arr[N];
int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k, cnt =0;
    cin >> n >> k;
    for(int i =0 ; i < n; ++i){
        cin >> arr[i];
        if(arr[i] >= k)
            cnt++;
    }
    cout << cnt;
}

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

int a[100][100],n;
int d[100],f[100],c[100],tt;
int nt[100];

int next(int u){
  for(int i=nt[u];i<n;i++){
    nt[u]=i+1;
    if(a[u][i]) return i;
  }
  return -1;
}

void dfs_v(int r){
  for(int i=0;i<n;i++) nt[i]=0;
  stack<int> s;
  s.push(r);
  c[r]=1;
  d[r]=++tt;
  while(!s.empty()){
    int u=s.top();
    int v=next(u);
    if(v!=-1){
      if(c[v]==0){
	c[v]=1;
	d[v]=++tt;
	s.push(v);
      }
    }else{
      s.pop();
      c[u]=2;
      f[u]=++tt;
    }
  }
}

void dfs(){
  for(int i=0;i<n;i++){
    c[i]=0;
    nt[i]=0;
  }
  tt=0;
  for(int i=0;i<n;i++){
    if(c[i]==0) dfs_v(i);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
}


  
int main(){
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) a[i][j]=0;
  }
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      a[u][v]=1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, k; cin >> a >> b >> k;
    set<int> se;
    rrep(i, a, min(a + k, b)) se.insert(i);
    for (int i = max(a, b - k + 1); i <= b; ++i) se.insert(i);
    for (auto e : se) {
        cout << e << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));

  vector<int> sum = A;
  REP(i, N-1) sum[i+1] += sum[i];

  vector<bool> ans(N, false);
  ans[N-1] = true;
  RREP(i, N){
    int it = upper_bound(ALL(A), sum[i]*2)-A.begin();
    if(ans[it-1]) ans[i] = true;
  }

  int ret = 0;
  REP(i, N){
    if(ans[i]) ret++;
  }

  cout << ret << "\n";

  return 0;
}

Measured memory_bytes: 1792
N=int(input())
A=sorted(map(int,input().split()))
ans=1
yakusu=[[],[]]

for i in range(2):
    for j in range(2,int(A[i]**0.5)+1):
        if A[i]%j==0:
            yakusu[i].append(j)
            yakusu[i].append(A[i]//j)
    yakusu[i].append(A[i])

yakusum=yakusu[0]
yakusum.extend(yakusu[1])
yakusum=sorted(set(yakusum))

for i in yakusum:
    counter=0
    for j in range(N):
        if A[j]%i!=0:
            counter+=1
            if counter==2:
                break
    if counter<=1:
        ans=i
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    int res=0;
    for(int i=0;i<6;i++) if(s[i]=='1') res++;
    cout<<res<<endl;
}


Measured memory_bytes: 256