akhauriyash/Code-Regression huggingface dataset:
import math

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

# n以下の素数列挙(O(n log(n))
def primes(n):
    ans = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ans.append(i)
    return ans


def fctr1(n):
    f = []
    c = 0
    r = int(n ** 0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c != 0:
            f.append([i, c])
            c = 0
    if n != 1:
        f.append([n, 1])
    return f


c = 0
for a in A:
    if a == 1:
        c += 1
    else:
        break


P = primes(A[-1])
L = len(P)

# MAX以下の素数の数より多い
if (N - c) <= L:
    USED = [False] * (10 ** 6 + 10)
    ok = True
    for a in A:
        if a == 1:
            continue

        f = fctr1(a)
        for x, c in f:
            if not USED[x]:
                USED[x] = True
            else:
                ok = False
                break

    if ok:
        print("pairwise coprime")
        exit()

t = A[0]
for a in A:
    t = math.gcd(a, t)
    if t == 1:
        break

if t == 1:
    print("setwise coprime")
else:
    print("not coprime")



Measured memory_bytes: 204640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = n; i > 0; i--) {
    int start = n - i;
    if (s.substr(start, i) == t.substr(0, i)) {
      cout << n + start << endl;
      return 0;
    }
  }  
  cout << n * 2 << endl;
  return 0;
}

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

long long dp[3001][3001][4] = {};

int main(void){
    int R,C,K;
    cin>>R>>C>>K;
    long long item[R][C] = {};
    for(int i=0;i<K;i++){
        int r,c,v;
        cin>>r>>c>>v;
        item[r-1][c-1] = v;
    }



    for(int ri=0;ri<R;ri++){
        for(int ci=0;ci<C;ci++){
            dp[ri+1][ci+1][0] = max(dp[ri+1][ci][0], dp[ri][ci+1][3]);
            dp[ri+1][ci+1][1] = max({dp[ri+1][ci][1], dp[ri+1][ci][0]+item[ri][ci], dp[ri][ci+1][3]+item[ri][ci], dp[ri+1][ci+1][0]});
            dp[ri+1][ci+1][2] = max({dp[ri+1][ci][2], dp[ri+1][ci][1]+item[ri][ci], dp[ri+1][ci+1][1]});
            dp[ri+1][ci+1][3] = max({dp[ri+1][ci][3], dp[ri+1][ci][2]+item[ri][ci], dp[ri+1][ci+1][2]});    
        }

    }
    cout<<dp[R][C][3]<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1);
vector<ll> pw10(19,1);

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	string s; cin>>s;
	ll x,y; cin>>x>>y;
	
	vector<ll> L;
	ll len=0;
	rep(i,s.sz){
		if(s[i]=='T'){
			L.pb(len);
			len=0;
		}
		else len++;
	}
	L.pb(len);
	//rep(i,L.sz) cout<<L[i]<<endl;
	vector<vector<bool>> dpx(L.sz,vector<bool>(16001,false));
	vector<vector<bool>> dpy(L.sz,vector<bool>(16001,false));

	//初手の例外処理
	if(s[0]=='F'){
		dpx[0][8000+L[0]]=true;
	}
	else dpx[0][8000]=true;

	if(L.sz>=2){
		dpy[1][8000+L[1]]=true;
		dpy[1][8000-L[1]]=true;
	}

	for(int i=2;i<=L.sz-1;i++){
		if(i%2==0){//xの動き
			rep(j,16000){
				if(dpx[i-2][j]==true){
					dpx[i][j+L[i]]=true;
					dpx[i][j-L[i]]=true;
				}
			}
		}
		else{
			rep(j,16000){
				if(dpy[i-2][j]==true){
					dpy[i][j+L[i]]=true;
					dpy[i][j-L[i]]=true;
				}
			}
		}
	}
	//sz==1 x=1,y=0 [0] ?(0のみ)
	//sz==2 x=1,y=1 [0] [1]
	//sz==3 x=2,y=1 [2] [1]
	//sz==4 x=2,y=2 [2] [3]
	//(?+1)/2)-1)*2 x
	//(?/2)*2-1 y
	if(L.sz==1){
		if(dpx[0][8000+x]==true && y==0) cout<<"Yes";
		else cout<<"No";
	}
	else{
		ll lx=(((L.sz+1)/2)-1)*2,ly=(L.sz/2)*2-1;
		if(dpx[lx][8000+x]==true && dpy[ly][8000+y]==true) cout<<"Yes";
		else cout<<"No";
	}
}

Measured memory_bytes: 32128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main() {
	vi v;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		int t;
		scanf("%d",&t);
		v.push_back(t);
	}
	sort(v.begin(),v.end());
	int ra = v.back();v.pop_back();
	int ma = 0;
	for(int i=0;i<v.size();i++) {
		if(abs(v[i]*2-ra) < abs(v[ma]*2-ra)) {ma = i;}
	}
	printf("%d %d\n",ra,v[ma]);
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan =new Scanner(System.in);
        int N=scan.nextInt();
        int K=scan.nextInt();
        int[] l =new int[50];
        int sum=0;

        for(int i=0;i<N;i++)
        {
            l[i]=scan.nextInt();
        }

        for(int j=0;j<N-1;j++)
        {
            for(int k=N-1;k>j;k--)
            {
                if(l[k-1]>l[k]){
                    int tmp=l[k];
                    l[k]=l[k-1];
                    l[k-1]=tmp;
                }
            }
        }

        for(int a=N-1;a>=N-K;a--)
        {
            sum+=l[a];
        }

        System.out.println(sum);
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> a(3);
  for (int i = 0; i < 3; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int d = a[2] * 2 - a[1] - a[0];
  if (d & 1) d += 3;
  cout << d / 2 << '\n';
  return 0;
}

Measured memory_bytes: 256
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <random>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using ull = __uint128_t;

using sc = signed char;
using si = signed int;
using sl = signed long long int;
using sll = __int128_t;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

namespace std {
  template <>
  struct is_integral<__int128_t> {
    constexpr static bool value = true;
  };
};

static sl X;

void solve(void) {
  sl coin_500 = X / 500;
  sl coin_5 = (X - coin_500 * 500) / 5;
  cout << (coin_500 * 1000 + coin_5 * 5) << endl;
}

int main(void) {
  cin >> X;
  solve();
  return 0;
}

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

int main() {
   int n;
   cin >> n;
   int cnt =0;
   
   vector<int> vec(n);
    for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
   }
   
   for(int j=0;j<n-2;j++){
       if(vec.at(j)<vec.at(j+1) && vec.at(j+1)<vec.at(j+2)){
           cnt++;
       }
       else if(vec.at(j)>vec.at(j+1) && vec.at(j+1)>vec.at(j+2)){
           cnt++;
       }
   }
   
   cout << cnt <<endl;

}


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

N,Q = map(int,input().split())
AB = [[x for x in map(int,input().split())] for _ in range(N-1)]
PX = [[x for x in map(int,input().split())] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

cnt = [0]*N
for p,x in PX:
    cnt[p-1] += x

def dfs(v,parent,add):
    for w in graph[v]:
        if w != parent:
             cnt[w-1] += add
             dfs(w,v,cnt[w-1])

for i in graph[1]:
    cnt[i-1] += cnt[0]
    dfs(i,1,cnt[i-1])

print(*cnt)

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

int main(){
    ll n,k;
    cin >> n >> k;
    k--;
    vector<ll> p(n),c(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
        p.at(i)--;
    }
    for(int i=0; i<n; i++){
        cin >> c.at(i);
    }
    ll ans=-pow(10,18);
    for(int i=0; i<n; i++){
        ll now=p.at(i);
        ll calc=c.at(p.at(i));
        vector<ll> point;
        point.push_back(c.at(p.at(i)));
        ll tot=c.at(p.at(i));
        //iから始める
        while(now!=i){
            now=p.at(now);
            tot+=c.at(now);
            point.push_back(tot);
        }
        ll p_sum=tot;
        /*
        for(int i=0; i<point.size(); i++){
            cout << point.at(i) << " ";
            p_sum+=point.at(i);
        }*/
        for(int i=0; i<point.size(); i++){
            ll q;
            if(i>k) q=calc;
            else{
                if(p_sum>0){
                    q=point.at(i)+((k-i)/point.size())*p_sum;
                }
                else{
                    q=point.at(i);
                }
            }
            calc=max(calc,q);
        }
        ans=max(ans,calc);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3796
#include<iostream>
using namespace std;
bool isp[1<<17];
int n;
main()
{
    isp[0]=isp[1]=1;
    for(int i=2;i<=5e4;i++)
    {
        if(!isp[i])
        {
            for(int j=i+i;j<=5e4;j+=i)isp[j]=1;
        }
    }
    while(cin>>n,n)
    {
        int c=0;
        for(int i=2;i<=n/2;i++)if(!isp[i]&&!isp[n-i])c++;
        cout<<c<<endl;
    }
}


Measured memory_bytes: 3144
n = int(input())
t = 0
st = 0
cn = []
sn = []
fn = []

for i in range(n-1):
  c,s,f = map(int,input().split())
  cn.append(c)
  sn.append(s)
  fn.append(f)

for j in range(n-1):
    t = 0
    for i in range(j,n-1):
      st = sn[i]
      if t <= sn[i]:
        t = sn[i]
      if t%fn[i] != 0:
          t += fn[i]-t%fn[i]
      t += cn[i]
    print(t)


print(0)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	char s[50];
	int i = 0,br = 0,m1 = 1;
	scanf("%s",s);
		while (br == 0){
			while (s[i] != 'A'){
				i = i + 1;
				if(i == 49){
					br = 1;
					break;
				}
			}
			if (br == 1){
				break;
			}
			while (s[i] != 'Z'){
				i = i + 1;
				if(i == 49){
					br = 1;
					break;
				}
			}
			if (br == 1){
				break;
			}
			m1 = 0;
			printf("AZ");
	}
	if (m1){
		printf("%d", -1);
	}
	printf ("\n");
	return 0;
}

Measured memory_bytes: 968
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String x = sc.next();
    int p = 0;
    ArrayList<Integer> lists = new ArrayList<Integer>();
    ArrayList<Integer> listt = new ArrayList<Integer>();
    int len = 0;
    for(int i = 0; i < x.length(); i++) {
      if(x.charAt(i) == 'S') {
        if(i == 0) {
          len++;
        } else {
          if(x.charAt(i - 1) == 'S') {
            len++;
          } else {
            if(p == 1) listt.add(len);
            len = 1;
          }
          if(i == (x.length() - 1)) lists.add(len);
        }
        p = 1;
      } else {
        if(i == 0) {
          len++;
        } else {
          if(x.charAt(i - 1) == 'S') {
            lists.add(len);
            len = 1;
          } else {
            len++;
          }
        }
        if((i == (x.length() - 1)) && (p == 1)) listt.add(len);        
      }
    }
    int t = 0;
    int sum = 0;
    for(int i = 0; i < lists.size(); i++) {
      if(listt.size() > i) {
        int a = lists.get(i) + sum;
        int b = listt.get(i);
        t += Math.min(a, b);
        sum = (a - Math.min(a, b)); 
      }
    }
    System.out.println(x.length() - 2 * t);
  }
}


Measured memory_bytes: 26468
h,w=map(int,input().split())
num=[list(map(int,input().split())) for i in range(h)]
ctrl=[]
cnt=0
for i in range(h):
  for j in range(w):
    if i==h-1:
      if j==w-1:pass
      else:
        if num[i][j]%2==1:
          num[i][j]-=1
          num[i][j+1]+=1
          ctrl.append([i+1,j+1,i+1,j+2])
          cnt+=1
    else:
      if num[i][j]%2==1:
        num[i][j]-=1
        num[i+1][j]+=1
        ctrl.append([i+1,j+1,i+2,j+1])
        cnt+=1
print(cnt)
for i in range(cnt):
  print(ctrl[i][0],ctrl[i][1],ctrl[i][2],ctrl[i][3])

Measured memory_bytes: 30296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
    int N, K; cin >> N >> K;
    vector<int> h(N, 0);

    for (auto &i: h)
        cin >> i;

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

    int ans = 1000000000;

    for (int i = 0; i < N-K+1; ++i)
        if (h[i+K-1] - h[i] < ans)
            ans = h[i+K-1] - h[i];
    
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    int result;
    char S[] ="2019/02/24";
    char *s_year[5],s_month[3],s_day[3];
    unsigned int year,month, day;
    enum {
        HEISEI = 0,
        TBD,
    } seireki = HEISEI;


    result = scanf("%s", S);

    memcpy(s_year, S, 4);
    s_year[4] = '\0';
    memcpy(s_month, S+5, 2);
    s_month[2] = '\0';
    memcpy(s_day, S+8, 2);
    s_day[2] = '\0';

    year = strtol( (const char*)s_year, NULL, 10);
    month = strtol( (const char*)s_month, NULL, 10);
    day = strtol( (const char*)s_day, NULL, 10);

    if( year >= 2019 ){
        if(month <= 4){
            seireki = HEISEI;
        }else{
            seireki = TBD;
        }
    }else{
        seireki = HEISEI;
    }

    if( seireki == HEISEI){
        printf("Heisei");
    }else if(seireki == TBD){
        printf("TBD");

    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX_X_Y (101)
#define MATCH (1)
#define NO_MATCH (-1)
#define VISIT (1)
#define NO_VISIT (-1)
#define NO_ID (-1)

typedef struct _Point{
    int dst[MAX_X_Y];
    int size;
} Point;

int bipartite_matching(Point *pair, int src, int *matches, int* is_visits) {
    int i, size, dst;
    if(src<0) return MATCH;

    for(i=0,size=pair[src].size;i<size;i++) {
        dst = pair[src].dst[i];
        if(is_visits[dst] == NO_VISIT) {
            is_visits[dst] = VISIT;

            if(bipartite_matching(pair, matches[dst], matches, is_visits) == MATCH) {
                // X側からとY側、両方マッチすれば
                matches[src] = dst;
                matches[dst] = src;
                return MATCH;
            }
        }
    }

    return NO_MATCH;
}

int solve(int X, int Y, int E) {
    int i, j, x, y;
    Point pair[MAX_X_Y*2];
    int is_visits[MAX_X_Y*2];
    int matches[MAX_X_Y*2];
    int count;

    for(i=0;i<MAX_X_Y*2;i++) pair[i].size = 0, matches[i] = NO_ID;

    for(i=0;i<E;i++) {
        scanf("%d %d\n", &x, &y);
        y += MAX_X_Y;
        pair[x].dst[pair[x].size++] = y;
        pair[y].dst[pair[y].size++] = x;
    }

    count = 0;
    for(i=0;i<X;i++) {
        for(j=0;j<MAX_X_Y*2;j++) is_visits[j] = NO_VISIT;
        if(bipartite_matching(pair, i, matches, is_visits) == MATCH) {
            count ++;
        }
    }

    return count;
}

int main(void) {
    int X, Y, E;

    scanf("%d %d %d\n", &X, &Y, &E);    
    printf("%d\n", solve(X, Y, E));
    
    return 0;
}

Measured memory_bytes: 692
n,c,k=map(int,input().split())
t = [int(input()) for _ in range(n)]
a = [0]*(n+1)
i = 0
j = 0
t = sorted(t)
while i < n:
    now = t[i]
    a[j] += 1
    i += 1
    while a[j] <c and i<n:
        if now<=t[i]<=now+k:
            a[j] += 1
        else:
            break
        i += 1
    j += 1
print(len([x for x in a if x != 0]))

Measured memory_bytes: 57816
#include<iostream>
using namespace std;
int bubblesort(int a[],int n){
    int sw=0;
    bool flag=1;
    for(int i=0;flag;i++){
        flag=0;
        for(int j=n-1;j>=i+1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flag=1;
                sw++;
            }
        }
        
    }
    return sw;
}
int main(){
    int a[100],n,sw;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sw=bubblesort(a,n);
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout<<endl<<sw<<endl;
    return 0;
}





Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll n;
 	cin>>n;
 	vector<ll> data(100001,0);
 	ll a;
 	ll sum=0;
 	for(int i=0;i<n;i++){
 		cin>>a;
 		data[a]++;
 		sum+=a;
 	}  
 	ll q;
 	cin>>q;
 	while(q--){
 		ll b,c;
 		cin>>b>>c;
 		ll time = data[b];
 		data[b] = 0;
 		data[c]+=time;
 		sum = sum - b*time +c*time;
 		// sum = 
 		cout<<sum<<endl;
 	}
    return 0;
}

Measured memory_bytes: 3972
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let upperBound (array: int []) first last value =
    let rec loop left right =
        if left > right then
            left
        else
            let mid = left + ((right - left) >>> 1)
            if array.[mid] <= value then
                loop (mid + 1) right
            else
                loop left (mid - 1)
    loop first (last - 1)

[<EntryPoint>]
let main _ =
    let N = read int
    let LS = reada int |> Array.sort

    let mutable ans = 0
    for i in [N-1 .. -1 .. 2] do
        for j in [i-1 .. -1 .. 1] do
            let high = LS.[i]
            let mid = LS.[j]
            let bound = upperBound LS 0 LS.Length (high - mid)
            let lows = max 0 (j - bound)
            ans <- ans + lows

    Console.WriteLine(ans)
    0

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

using namespace std;

using ll = long long;

#define all(x) begin(x), end(x)
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end()); 

int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll n,m; cin >> n >> m;
// tekler icin
// sadece m'i hesaplayabiliriz
ll ans = 0;
ans += (n-1)*(n)/2;
ans += (m-1)*(m)/2;
cout << ans << "\n";

}


Measured memory_bytes: 3628
#include <stdio.h>
main(){     
int a,b,c,x,y,z;     
scanf("%d%d%d",&a,&b,&c);     
if(a > b){     
x = a;   
a = b;   
b = x;  }     
if(b > c){    
y = b;    
b = c;    
c = y;  }     
if(a > b){    
z = a;    
a = b;    
b = z;  }     
printf("%d %d %d\n",a,b,c);     
return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  cout << "A" << s2[0] << "C" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

vector<vector<i64>> g;
vector<vector<i64>> rg;
int N,M;

int cmp[101010];
int rev[101010];
int in[101010];

int main() {
  cin >> N >> M;
  g.resize(N);
  rg.resize(N);
  rep(i,0,N + M - 2) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    rg[b].push_back(a);
    in[b]++;
  }
  queue<int> que;
  rep(i,0,N - 1) {
    if(in[i] == 0) que.push(i);
  }
  int cnt = 0;
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    cmp[v] = cnt++;
    rev[cmp[v]] = v;
    for(int t : g[v]) {
      in[t]--;
      if(in[t] == 0) que.push(t);
    }
  }
  rep(i,0,N - 1) {
    int ans = -1;
    for(int t : rg[i]) {
      if(ans == -1) ans = t;
      else ans = rev[max(cmp[ans], cmp[t])];
    }
    cout << ans + 1 << endl;
  }
}


Measured memory_bytes: 12928
N = input()

a = []
for i in range(int(N)):
    s = input().split()
    ss = [int(s[0]), int(s[1]), int(s[2])]
    ss.sort()

    if ss[2]**2 == ss[0]**2 + ss[1]**2:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 5600
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．

int main() {
    double L;
    cin >> L;
    double l = L/3.0;
    cout << fixed << setprecision(10);
    cout << l * l * l << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define dot array <int, 2>

int debug = 0;

bool up(dot A) {
    return A[1] > 0 || (A[1] == 0 && A[0] > 0);
}

int operator * (dot A, dot B) {
    return A[0] * B[1] - A[1] * B[0];
}

dot operator + (dot A, dot B) {
    return {{A[0] + B[0], A[1] + B[1]}};
}

bool cmp(dot A, dot B) {
    if (up(A) && !up(B)) {
        return 1;
    } else if (!up(A) && up(B)) {
        return 0;
    } else {
        return A * B > 0;
    }
}

main() {
    int n;
    cin >> n;
    vector <array <int, 2>> p;
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        if (x * x + y * y > 0) {
            p.push_back({{x, y}});
        }
    }
    n = p.size();
    sort(p.begin(), p.end(), cmp);
    int ans = 0;
    rep(st_i, 0, n) {
        dot O = p[st_i];
        int j = (st_i + 1)%n;
        if (debug) {
            cerr << "p[st_i]= " << O[0] << ' ' << O[1] << '\n';
        }
        ans = max(ans, O[0]*O[0] + O[1]*O[1]);
        while (j != st_i) {
            O = O+ p[j];
            if (debug) {
                cerr << " while " << O[0] << ' ' << O[1] << endl;
            }
            j = (j+1)%n;
            ans = max(ans, O[0]*O[0] + O[1]*O[1]);
        }
        if (debug) {
            cerr << " st_i=" << st_i << ' ' << j << "  O=" << O[0] << ' ' << O[1] << '\n';
        }
        ans = max(ans, O[0]*O[0] + O[1]*O[1]);
    }
    cout << fixed << setprecision(12) << sqrt(ans) << '\n';
}

Measured memory_bytes: 256
#include"stdio.h"
#include"math.h"
#include <limits.h>


int main() {
	long int n, a, b, a1, a2, a3, a4,ans;
	scanf("%ld%ld%ld", &n, &a, &b);


	if (a % 2 == b % 2) {
		ans = (b - a) / 2;
	}
	else {
		a1 = b - 1;
		a2 = n - a;
		a3 = (n - b + 1) + (-a + b - 1) / 2;//(n - b + 1) + (n-(a + n - b + 1) ) / 2;
		a4 = a + (b - a - 1) / 2;
		if (a1 <= a2 && a1 <= a3 && a1 <= a4)ans = a1;
		if (a2 <= a1 && a2 <= a3 && a2 <= a4)ans = a2;
		if (a3 <= a2 && a3 <= a1 && a3 <= a4)ans = a3;
		if (a4 <= a2 && a4 <= a3 && a4 <= a1)ans = a4;
	}

	printf("%ld", ans);
	//printf("%ld/n%ld/n%ld/n%ld/n", a1,a2,a3,a4);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

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

//-----end of template-----//

int h[100];

int rec(int l, int r){
	if(r - l <= 1){
		int tmp = h[l];
		h[l] = 0;
		return tmp;
	}
	int idx, m;
	m = 100;
	for(int i = l; i < r; ++i){
		if(m > h[i]){
			m = h[i];
			idx = i;
		}
	}
	int sum = m, z = l;
	for(int i = l; i < r; ++i){
		h[i] -= m;
		if(h[i] == 0){
			sum += rec(z, i);
			z = i + 1;
		}
	}
	sum += rec(z, r);
	return sum;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	cout << rec(0, n) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 998244353;
const ll N = 555555;

//a^(p-2)=a^(-1) (mod p)
//(x^n)%mod
ll mod_pow(ll x,ll n,ll mod){
  if(n==0)return 1;
  ll res=mod_pow( x*x%mod , n/2 , mod );
  if( n & 1 )res = res*x%mod;
  return res;
}

ll fact[N];
ll infact[N];

void make_factorial(void){
  fact[0] = 1;
  for( ll i = 1 ; i < N ; i++ ){
    fact[i] = fact[i-1] * i;
    fact[i] %= MOD;
  }
  for( ll i = 0 ; i < N ; i++ ){
    infact[i] = mod_pow( fact[i] , MOD-2 , MOD );
  }
}

ll comb(ll a,ll b){
  if(a == 0 && b == 0)return 1;
  if(a < b || a < 0)return 0;
  ll tmp = infact[a-b]* infact[b] % MOD;
  return tmp * fact[a] % MOD; 
}

int main(){
  ll n,a,b,k;
  cin>>n>>a>>b>>k;
  
  if(k==0){
    cout<<1<<endl;
    return 0;
  }

  make_factorial();

  ll ans=0;
  for(ll i=0;i<=n;i++){
    if(k<a*i)continue;
    if((k-i*a)%b)continue;
    ll x=i;
    ll y=(k-i*a)/b;
    
    ans+=(comb(n,x)*comb(n,y))%MOD;
    ans%=MOD;
  }
  
  cout<<ans<<endl;
  return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    int ans = 0;
    for_(A,1,N) {
        for_(B,1,N) {
            if (lint(A) * B >= N) break;
            ++ans;
        }
    }
    cout << ans << endl;
}

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

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

void func(char (*imap)[12], int x, int y){
  imap[x][y] = '0';
  for(int k=0; k<4; ++k){
      int nx = x + dx[k], ny = y + dy[k];
      if(nx < 0 || 12 <= nx) continue;
      if(ny < 0 || 12 <= ny) continue;
      if(imap[nx][ny] == '0') continue;
      else func(imap,nx,ny);
  }
}

int main(void){
  char island_map[12][12];
  int res=0;
  while(1){
    for(int i=0; i<12; ++i){
      for(int j=0; j<12; ++j){
	if(cin >> island_map[i][j]);
	else return 0;
      }
    }
    for(int i=0; i<12; ++i){
      for(int j=0; j<12; ++j){
	if(island_map[i][j]=='1'){
	  res++;
	  func(island_map,i,j);
	  }
      }
    }
    cout << res << endl;
    res = 0;
  }
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 1e9 + 7;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
//ruogu_alter
//
int main() {
  int n = getint(); n = n * 60 + getint();
  int m = getint(); m = m * 60 + getint();
  printf("%d\n", m - n - getint());
  return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int h,w; cin >> h >> w;
  vvc s(h+2,vc(w+2,'.'));
  rep1(i,h+1)rep1(j,w+1)cin>>s[i][j];
  bool is_res = false;
  rep1(i,h+1){
      rep1(j,w+1){
      bool check = false;
        for(int k=0;k<8;k+=2){
            int nx = i + dx[k];
            int ny = j + dy[k];
            if(s[nx][ny] == '#')check = true;
        }
        if(!check && s[i][j] == '#'){
            out("No");
            return 0;
        }
    }
  }
  out("Yes");
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
num = 100002
count = [0]*num
tot = 0
for a in A:
    count[a] += 1
    tot += a
    
Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    tot += count[B]*(C-B)
    print(tot)
    count[C] += count[B]
    count[B] = 0
    

Measured memory_bytes: 20320
import java.util.*;
//reference http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			String s[]=in.next().split(",");
			double x[]=new double[4];
			double y[]=new double[4];
			for(int i=0;i<4;i++)
			{
				x[i]=Double.valueOf(s[i*2]);
				y[i]=Double.valueOf(s[i*2+1]);
			}
			if(judge(x[0],y[0],x[2],y[2],x[1],y[1],x[3],y[3])>0||judge(x[1],y[1],x[3],y[3],x[0],y[0],x[2],y[2])>0)
				System.out.println("NO");
			else
				System.out.println("YES");
		}
	}
	
	static double judge(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
	{
		double tc=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
		double td=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
		return tc*td;
	}
	
	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

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

int main()
{
    vector< pair<int, int> > in;

    do
    {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0)
        {
            break;
        }
        pair<int, int> pin(n, x);
        in.push_back(pin);
    } while (true);

    int size = static_cast<int>(in.size());
    rep(i, 0, size)
    {
        int n = in[i].first;
        int x = in[i].second;
        int count = 0;

        rep(i, 1, n + 1)
        {
            rep(j, i + 1, n + 1)
            {
                rep(k, j + 1, n + 1)
                {
                    if (i + j + k == x)
                    {
                        ++count;
                    }
                }
            }
        }

        cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3116
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve();
void precalc();
clock_t start;
//int timer = 1;

int testNumber = 1;

bool todo = true;

int main() {
#ifdef AIM
    freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
    cout.sync_with_stdio(0);
    cin.tie(0);
    precalc();
    cout.precision(10);
    cout << fixed;
    //cin >> t;
    int testNum = 1;
    while (t--) {
        //cerr << testNum << endl;
        //cout << "Case #" << testNum++ << ": ";
        solve();
        ++testNumber;
        //++timer;
    }

#ifdef AIM
    cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

    return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

void precalc() {

}

//#define int li

//const int mod = 1000000007;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    int xxor = 0;
    const int L = 30;
    vector<int> has(L);
    for (int i = 0; i< n; ++i) {
        cin >> a[i];
        xxor ^= a[i];
        int cur = a[i];
        int cnt = 0;
        while (cur % 2 == 0) {
            ++cnt;
            cur /= 2;
        }
        ++has[cnt];
    }

    vector<vector<int>> dp(L + 1, vector<int>(2, (int)1e9));
    dp[L][0] = 0;
    for (int i = L; i > 0; --i) {
        for (int par = 0; par < 2; ++par) {
            if (dp[i][par] > 1e8) {
                continue;
            }
            int state = (par ^ bool(xxor & (1 << (i - 1))));
            if (!state) {
                dp[i - 1][par] = min(dp[i - 1][par], dp[i][par]);
                continue;
            }
            if (!has[i - 1]) {
                continue;
            }
            dp[i - 1][par ^ 1] = min(dp[i - 1][par ^ 1], dp[i][par] + 1);
        }
    }

    int res = min(dp[0][0], dp[0][1]);

    if (res > 1e8) {
        cout << "-1\n";
    }
    else {
        cout << res << "\n";
    }

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
       	ll x;cin>>x;
       	for(ll a=-3000;a<=3000;a++){
       		for(ll b=-3000;b<=3000;b++){
       			ll X=a*a*a*a*a-b*b*b*b*b;
       			if(X==x){
       				cout<<a<<" "<<b;return 0;
       			}
       		}
       	}
    }   
    timecalculater();
    return 0;   
} 	

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define buff ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define xy pair<int, int>
#define x first
#define y second 

#define inf std::numeric_limits<int>().max()

int main() {
	double n, x, t;
	cin >> n >> x >> t;
	cout.precision(10);
	cout << (int) ceil(n/x) * t << endl;
}


Measured memory_bytes: 3296
N, M = map(int, input().split())
ans = [0 for i in range(N)]
pen = [0 for i in range(N)]

for i in range(M):
	p, S = input().split()
	p = int(p) - 1
	if ans[p] == 0:
		if S == "AC":
			ans[p] = 1
		else:
			pen[p] += 1

ANS = 0
PEN = 0
for i in range(N):
	ANS += ans[i]
	PEN += ans[i] * pen[i]

print(ANS, PEN)

Measured memory_bytes: 4656
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    long long int n,i,x,ans;
    scanf("%lld",&n);
    vector<long long int>v;
    for(i=0;i<n;i++)
    {
        long long int p;
        scanf("%lld",&p);
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    ans=v[0];
    for(i=1;i<n;i++)
    {
        x=__gcd(ans,v[i]);
        ans=min(x,v[i]);
    }
    printf("%lld",ans);

    return 0;


}



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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n,k;cin>>n>>k;
    int cnt=0;
    FOR(i,n){
        int x;cin>>x;
        cnt += x>=k;
    }
    cout << cnt;
    return 0;
}



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

using namespace std;

const int N = 5e3 + 5;
const int mod = 1e9 + 7;
int _w;

int pls( int a , int b ) { return a + b >= mod ? a + b - mod : a + b; }
int mns( int a , int b ) { return a - b < 0 ? a - b + mod : a - b; }

int f[N][N] , g[N] , h[N] , n , head[N] , eidx , siz[N];
struct Edge { int nxt , to; } edge[N << 1];

void addedge( int u , int v ) {
  edge[++eidx] = (Edge) { head[u] , v }; head[u] = eidx;
  edge[++eidx] = (Edge) { head[v] , u }; head[v] = eidx;
}

void dfs( int u , int fa = 0 ) {
  siz[u] = 1 , f[u][1] = 1;
  for( int e = head[u] , v ; e ; e = edge[e].nxt ) 
    if( ( v = edge[e].to ) != fa ) {
      dfs( v , u );
      for( int i = 0 ; i <= siz[u] ; ++i )
        for( int j = 0 ; j <= siz[v] ; ++j )
          g[i + j] = pls( g[i + j] , 1LL * f[u][i] * f[v][j] % mod );
      siz[u] += siz[v];
      for( int i = 0 ; i <= siz[u] ; ++i )
        f[u][i] = g[i] , g[i] = 0;
    }
  int tmp = 0;
  for( int i = 0 ; i <= siz[u] ; i += 2 ) tmp = mns( tmp , 1LL * h[i] * f[u][i] % mod );
  f[u][0] = tmp;
}

int main( void ) {
  _w = scanf("%d",&n);
  for( int i = 1 , u , v ; i < n ; ++i ) {
    _w = scanf("%d%d",&u,&v);
    addedge( u , v );
  }
  h[0] = 1;
  for( int i = 2 ; i <= n ; i += 2 ) h[i] = 1LL * ( i - 1 ) * h[i - 2] % mod;
  dfs( 1 );
  cout << mod - f[1][0] << endl;
  return 0;
}


Measured memory_bytes: 97280
def factorization(n):
    res = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            res.append([i, cnt])
 
    if tmp!=1:
        res.append([tmp, 1])
 
    return res

N = int(input())
ans = 0
for tmp,cnt in factorization(N):
    i = 1
    while i<=cnt:
        ans += 1
        cnt-=i
        i += 1
print(ans)

Measured memory_bytes: 63456
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[105];
bool dp[N];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    for (int i = 0; i <= k; i++) {
        if (dp[i])
            continue;
        for (int x = 0; x < n && ((i + A[x] <= k)); x++)
            dp[i + A[x]] = 1;
    }

    if (dp[k])
        cout << "First";
    else
        cout << "Second";

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	int mi = 1100000;
	for(int A = 1; A < N; A++) {
		int Bt = N - A;
		int At = A;
		int Asum = 0, Bsum = 0;
		while(At) { Asum += At % 10; At /= 10; }
		while(Bt) { Bsum += Bt % 10; Bt /= 10; }
		mi = min(mi, Asum + Bsum);
	}
	cout << mi << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))

q = [0 for i in range(N)]

for i in range(N):
    q[p[i]-1]=i+1

a = [str((i+1)*N)  for i in range(N)]
b = [str((N-i-1)*N + q[i]) for i in range(N)]
print(" ".join(a))
print(" ".join(b))

Measured memory_bytes: 8436
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

int N;
int main (){
    cin >> N;
    map<int,int> mp;
    vector<int> v;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        mp[x]++;
        if( mp[x] == 2 ) {
            v.push_back(x);
            mp[x] = 0;
        }
    }
    sort( v.begin(), v.end(), greater<int>());
    if (v.size() > 1)cout << (long long )v[0] * v[1] << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 4992