akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

const int MaxN = 100 + 5, MaxM = 100000 + 5;

int N, M;
int W[MaxN], V[MaxN];
long long Dp[MaxM];

template <typename T>
inline T max(T x, T y) { return x > y ? x : y; }

void init() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; ++i)
    scanf("%d %d", &W[i], &V[i]);
}

void solve() {
  for (int i = 1; i <= N; ++i)
    for (int j = M; j >= W[i]; --j)
      Dp[j] = max(Dp[j], Dp[j - W[i]] + V[i]);
  long long ans = 0;
  for (int i = 0; i <= M; ++i)
    ans = max(ans, Dp[i]);
  printf("%lld\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

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

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

  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    R += r - l;
//    while(l <= r){
 //     R++;
  //    l++;
   // }
  }
  cout << R << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>



int main(void)
{
    int H, W, N;
    int big;
    int result;

    scanf("%d", &H);
    scanf("%d", &W);
    scanf("%d", &N);

    if (H >= W) {
        big = H;
    } else {
        big = W;
    }
    
    result = ((N % big) == 0) ? (N / big) : ((N / big) + 1 );

    printf("%d", result);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int a,b,c,x,ans=0;
    scanf("%d %d %d",&a,&b,&c);
    
    for(x=a; x<=b; x++) {
        if (c%x==0){
            ans++;
        }
    }
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  vector<int> v,c;
  int n,ii;
  cin >> n;

  v.resize(n);
  c.resize(n);
  
  for(ii=0;ii<n;ii++){
    cin >> v[ii];
    //cout << v[ii] << endl;
  }
  for(ii=0;ii<n;ii++){
    cin >> c[ii];
  }
  int sum=0;
  for(ii=0;ii<n;ii++){
    if(v[ii] - c[ii] > 0){
      sum += v[ii] - c[ii];
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (int) 1e9 + 7;

int main(){
    
    long x;
    cin >> x;
    
    for(long i = -200; i < 200; i++){
        for(long j = -200; j < i; j++){
            long ii = i * i * i * i * i;
            long jj = j * j * j * j * j;
            if(ii - jj == x){
                cout << i << ' ' << j << "\n";
                return 0;
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3148
n = int(input())
s = [i for i in range(1,n+1)]
counter = 0
while(True):
    if len(s)==1:
        print(1)
        break
    if len([i for i in s if i % 2 == 0])==1:
        s = [i for i in s if i % 2 == 0]
        print(int(s[0]) * (2 ** counter))
        break
    else:
        s = [i/2 for i in s]
        counter += 1


Measured memory_bytes: 9192
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

def fact(n,mod):
    f = 1
    for m in range(1,n + 1):
        f *= m
        f %= mod
    return f

N = i()
print(fact(N,mod))

Measured memory_bytes: 77420
N=int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if N==2:
  print(2)
else:
  if N%2==0:
    N+=1
  while len(prime_factorize(N))!=1:
    N+=2
  print(N)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int n,sat=0;
	cin>>n;
	int a[n],b[n-1],c[n-1];
	for(int i=1;i<=n-1;i++)
		cin>>b[i];
	a[1]=b[1];
	a[2]=b[1];
	for(int i=2;i<n;i++)
	{	
		if(b[i]<a[i])
			a[i]=b[i];
		a[i+1]=b[i];
		
	}
	for(int i=1;i<=n;i++)
		sat+=a[i];
	cout<<sat<<endl;	
		
//	for(int i=1;i<=n;i++)
//		cin>>a[i];
//	for(int i=1;i<=n;i++)
//		cin>>b[i];
//	for(int i=1;i<n;i++)
//		cin>>c[i];
//	sat=b[a[1]];
//	for(int i=2;i<=n;i++)
//	{
//		sat+=b[a[i]];
//		if(a[i]==(a[i-1]+1))	
//			sat+=c[a[i]-1];		
//	}	
//	cout<<sat<<endl;
	return 0;
}

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

int main(){
	int n;
	while( cin >> n , n ){
		vector<int> v;
		int h[10000] = {0};
		
		for(int i=1 ; i < n ; i++ ){
			int a = (i * i) % n;
			if( count(v.begin() , v.end() , a ) == 0 ){
				v.push_back( a );
			}
		}
		for(int i=0 ; i < v.size() ; i++ ){
			for(int j=0 ; j < v.size() ; j++ ){
				if( i == j ) continue;
				
				int c = v[i] - v[j];
				if( c < 0 ) c += n;
				if( ((n-1)/2) < c ) c = n - c;
				h[c]++; 
			}
		}
		for(int i=1 ; i <= (n-1)/2 ; i++ ){
			cout << h[i] << endl;
		}
	}
}

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

int main(void) {

	long long int A=0,B=0,q=0,r=0,temp=0,g=1,x=0;
	scanf("%d %d", &A, &B);

	if(B>A){
	 temp = A;
	 A = B;
	 B= temp;
	}

	r=A % B;
	q=B;

	switch(r){
	case 0:x=A;break;
	case 1:x=A*B/g;break;
	default:
		while(r!=1 && r !=0){
		g = r;
		r = q % r;
		q = g;
	}
		if(r!=0){
			g=r;
		}
		x=A*B/g;
	}

	printf("%lld", x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[100005];
ll b[100005];

int main(void){
    scanf("%d",&n);
    ll suma=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        suma+=a[i];
    }
    for(int i=0;i<n;i++){
        scanf("%lld",&b[i]);
        suma-=b[i];
    }
    if(suma<0LL){
        printf("-1\n");
        return 0;
    }
    vector<ll> v1;
    int cnt=0;
    ll su=0;
    for(int i=0;i<n;i++){
        if(a[i]>=b[i]){
            v1.push_back(a[i]-b[i]);
        }else{
            su+=b[i]-a[i];
            cnt++;
        }
    }
    sort(v1.begin(),v1.end());
    reverse(v1.begin(),v1.end());
    for(int i=0;i<v1.size();i++){
        if(su>0LL){
            su-=v1[i];
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 2936
# input -- A B C X Y

A, B, C, X, Y = map(int, input().split())
#print(A, B, C, X, Y )

# can buy '2 * Z' pieces of C-pizza
Z = min(X, Y)
sum_of_pay = 0

if A+B > 2*C:
    sum_of_pay += 2 * Z * C

    if X-Z > 0: # if remain some A-pizza
        if A > 2*C:
            sum_of_pay += 2 * (X-Z) * C
        else:
            sum_of_pay += (X-Z) * A
    else:      # B-pizza
        if B > 2*C:
            sum_of_pay += 2 * (Y-Z) * C
        else:
            sum_of_pay += (Y-Z) * B
else:
    sum_of_pay += (X*A + Y*B)

print(sum_of_pay)


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  unordered_set<ll> as;
  ll a = s;
  as.insert(a);
  for (int n = 2;; n++) {
    a = (a % 2 == 0) ? (a / 2) : (3 * a + 1);
    if (as.find(a) != as.end()) {
      cout << n << endl;
      break;
    } else {
      as.insert(a);
    }
  }
  return 0;
}


Measured memory_bytes: 3604
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = [int(x) for x in input()]

ans1 = [x%2 for x in range(len(S))]
ans2 = [x%2 for x in range(1,len(S)+1)]
count1 = 0
count2 = 0
for i in range(len(S)):
    if S[i] != ans1[i]:
        count1 += 1

for i in range(len(S)):
    if S[i] != ans2[i]:
        count2 += 1
 
print(min(count1,count2))

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

int main() {
    int n; cin >> n;
    ll ans = 0;
    rep(i, n){
        if((i+1)%3 != 0 && (i+1)%5 != 0) ans+=(i+1);
    }
    cout << ans << endl;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

vll binary_convert(ll n){
    vll s;
    ll size = 0;

    while(n / (ll)(pow(2,size)) > 0)size++;
    rep(i,size + 1){
        s.pb(n / (ll)(pow(2,i)));
        n %= (ll)(pow(2,i));
    }

    return s;
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    ll x,a;
    cin >> x >> a;
    if(x < a)cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
{
    int n;
    int i;
    int score, out;
    int base;
    char event[256];
    
    memset(event, '\0', sizeof(event));

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        score = 0;
        out = 0;
        base = 0;

        while (1){
            scanf("%s", event);

            if (strcmp(event, "HOMERUN") == 0){
                score += base + 1;
                base = 0;
            }
            if (strcmp(event, "HIT") == 0){
                if (base < 3){
                    base++;
                }
                else {
                    score++;
                }
            }
            if (strcmp(event, "OUT") == 0){
                    out++;
            }

            if (out == 3){
                break;
            }
        
            memset(event, '\0', sizeof(event));
           
        }

        printf("%d\n", score);
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i=0; i<2; i++){
    if(a >= b){
        ans += a;
        a--;
    }
    else{
        ans += b;
        b--;
    }
    }

    cout << ans << endl;
}

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

a_b_list = list(map(int,input().split()))
a = a_b_list[0]
b = a_b_list[1]

k = (a + b) / 2
l = (a + b) % 2

if l == 0:
  print(int(k))
else:
  print("IMPOSSIBLE")


Measured memory_bytes: 3064
n, k = map(int, input().split())
xlst = list(map(int, input().split()))
minus = []
plus = []
for x in xlst:
    if x < 0:
        minus.append(-1 * x)
    elif x > 0:
        plus.append(x)
    else:
        k -= 1
if k == 0:
    print(0)
    exit()
minus.append(0)
minus = minus[::-1]
plus = [0] + plus
ans = 10 ** 20
ml = len(minus)
pl = len(plus)

pos = min(k, ml - 1)
while 1:
    mm = minus[pos]
    pp = plus[k - pos]
    ans_tmp = max(mm, pp) + min(mm, pp) * 2
    ans = min(ans, ans_tmp)
    pos -= 1
    if pos == -1 or k - pos == pl:
        break
print(ans)


Measured memory_bytes: 20156
#include<stdio.h>
int main(void)
{
	int i,a,b,c;
	for(i=1;i<=4;i++){
		scanf("%d %d",&a,&b);
		if(a==1){
			c=6000*b;
		}
		if(a==2){
			c=4000*b;
		}
		if(a==3){
			c=3000*b;
		}
		if(a==4){
			c=2000*b;
		}
		printf("%d\n",c);
	}
	return 0;
}
		

Measured memory_bytes: 1028
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int N;
  int K;

  scanf("%d %d", &N, &K);

  int k = K;
  int count = 1;
  while (k <= N) {
    k *= K;
    count++;
  }

  printf("%d\n", count);

  return (0);
}


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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    cin >> a >> b;
    int64_t an = 0, bn = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > b[i]) bn += a[i] - b[i];
        if (a[i] < b[i]) an += (b[i] - a[i]) / 2;
    }
    if (bn <= an) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n, t[200005];

void inc(int l, int r) {
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if (l & 1) t[l++]++;
        if (r & 1) t[--r]++;
    }
}

int que(int x) {
    int z = 0;
    for (x += n; x; x >>= 1) z += t[x];
    return z;
}

int main() {
    ios::sync_with_stdio(false);
    int m, u, v, c = 0;
    vector<pii> a[100005] = {};
    cin >> m >> n; c = m; n++;
    while (m--) cin >> u >> v, a[v - u + 1].push_back({u, v + 1});
    for (int i = 1; i < n; i++) {
        int z = 0;
        for (int j = i; j <= n; j += i) z += que(j);
        cout << z + c << '\n';
        for (pii j : a[i]) inc(j.first, j.second), c--;
    }
}


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

int main(void){
  int N;
  cin >> N;
  int cnt = 0;
  vector<string> strList(N);
  for(int i = 0;i < N;i++){
    cin >> strList[i]; 
  }
  for(int i = 0;i < N;i++){
    for(int j = i+1;j < N;j++){
      if(strList[i] == strList[j]){
        cnt++;
        break;
      }
    }
    if(cnt!=0)break;
  }
  for(int i = 0;i < N-1;i++){
    if(strList[i].back() != strList[i+1].front()){
      cnt++;
    }
  }
  if(cnt !=0){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const ll INF = 1001001001;

int main()
{
    ll n;
    cin >> n;
    vector<P> a;
    if (n % 2 != 0)
    {
        rep2(i, 1, n + 1)
        {
            rep2(j, 1, n + 1)
            {
                if (i != j && i != n - j)
                {
                    if (i < j)
                    {
                        a.emplace_back(i, j);
                    }
                }
            }
        }
        cout << a.size() << endl;
        rep(i, a.size())
        {
            cout << a[i].first << " " << a[i].second << endl;
        }
        return 0;
    }
    rep2(i, 1, n + 1)
    {
        rep2(j, 1, n + 1)
        {
            if (i != j && i != n + 1 - j)
            {
                if (i < j)
                {
                    a.emplace_back(i, j);
                }
            }
        }
    }
    cout << a.size() << endl;
    rep(i, a.size())
    {
        cout << a[i].first << " " << a[i].second << endl;
    }
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long

int n;
int f[100][10];
int p[100][11];
int a[10]={0};
int b[100]={0};
int ans=BIG*(-1);
int now;
bool bo=true;
int cnt=0;

void solve(int num){
  if(num==10){
    now=0;
    rep(i,n) b[i]=0;
    rep(i,n){
      rep(j,10){
	if(a[j]==1 && f[i][j]==1) b[i]++;
      }
      now+=p[i][b[i]];
    }
   
    if(bo) bo=false;
    else ans=max(now,ans);
  }else{
    a[num]=0;
    solve(num+1);
    a[num]=1;
    solve(num+1);
  }
}

signed main(){
  //cout<<ans<<endl;
  cin>>n;
  rep(i,n){
    rep(j,10){
      cin>>f[i][j];
    }
  }
  rep(i,n){
    rep(j,11) cin>>p[i][j];
  }
  solve(0);
  // cout<<cnt<<endl;
  cout<<ans<<endl;
  return 0;
}








Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef double R;

// 組み合わせテーブル
ll C[51][51];

void comb_table(int N) {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                C[i][j] = 1LL;
            } else {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    const int MAX_N = 50;
    ll v[MAX_N];

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

    comb_table(N);
    sort(v, v + N);
    reverse(v, v + N);

    R max_average = 0.0;
    for (int i = 0; i < A; i++) {
        max_average += v[i];
    }
    max_average /= A;

    int a_th_val_num = 0, a_th_val_pos = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == v[A - 1]) {
            a_th_val_num++;
            if (i < A) {
                a_th_val_pos++;
            }
        }
    }

    ll cnt = 0LL;
    if (a_th_val_pos == A) {
        for (a_th_val_pos = A; a_th_val_pos <= B; a_th_val_pos++) {
            cnt += C[a_th_val_num][a_th_val_pos];
        }
    } else {
        cnt += C[a_th_val_num][a_th_val_pos];
    }

    cout.precision(20);
    cout << fixed << max_average << endl;
    cout << cnt << endl;

    return 0;
}

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

using namespace std;
	
const int maxn=1e5;
int b[maxn];

int main()
{
	int a,f=0;
	cin >> a;
	for(int i=0;i<a;i++)
	{
		cin >> b[i];
		if(b[i]%2 != 0)
			f++;
	}
	if(f%2 == 0)
		cout << "YES";
	else 
		cout << "NO";
}

 



Measured memory_bytes: 640
import sys
import math
 
def main():
    N = int(input())
    xy=[]
    for _ in range(N):
        xy.append(list(map(int,input().split())))
 
    sqs=[]
    for i in range(0,len(xy)):
        for j in range(i+1,len(xy)):
            sqs.append(math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2))
 
    print(sum(sqs) * 2 / N)
 
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
   int s;cin >>s;
   vector<mint>ans(2000+1,0);
   ans[3]=1;
    for (int i = 4; i <=2000; ++i) {
        ans[i]=ans[i-1]+ans[i-3];
    }
    cout <<ans[s]<<endl;
}


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

int main() {
  string s; cin >> s;
  if (s=="RRS" || s=="SRR") {
    cout << 2 << "\n";
  } else if (s=="RRR") {
    cout << 3 << "\n";
  } else if (s=="SSS") {
    cout << 0 << "\n";
  } else {
    cout << 1 << "\n";
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define INF 987654321
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

#define MAX_N 200010
vector<int> edge[MAX_N];
int lazy[MAX_N];

void dfs(int cur, int par){
    for(auto nxt : edge[cur]){
        if (nxt == par) continue;
        lazy[nxt] += lazy[cur];
        dfs(nxt, cur);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    for(int i=1; i<N;i++){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    for(int i=1; i<=Q;i++){    
        int p, x;
        cin >> p >> x;
        lazy[p] += x;
    }

    dfs(1, -1);
    for(int i=1; i<=N;i++){
        cout << lazy[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
const int CENTER = 30;
int n, r;
int h[60];

bool check(double m) {
	for(int i = 0; i <= r - 1; i++) {
		double sh = -r + m + sqrt(r * r - i * i);
		if(sh < 0) continue;
		if(h[CENTER + i] < sh) return false;
	}
	for(int i = -r; i <= -1; i++) {
		double sh = -r + m + sqrt(r * r - (i + 1) * (i + 1));
		if(sh < 0) continue;
		if(h[CENTER + i] < sh) return false;
	}
	return true;
}

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

	while(cin >> r >> n, n | r) {
		for(int i = 0; i < 60; i++) {
			h[i] = 0.0;
		}

		for(int i = 0; i < n; i++) {
			int xl, xr, hh;
			cin >> xl >> xr >> hh;
			for(int j = xl; j < xr; j++) {
				h[CENTER + j] = max(h[CENTER + j], hh);
			}
		}
		check(4.0);
		double ok = 0, ng = 100;
		for(int loop = 0; loop < 100; loop++) {
			double m = (ok + ng) / 2.0;
			if(check(m)) ok = m;
			else ng = m;
		}

		cout << fixed << setprecision(4) << ok << endl;
	}
}

Measured memory_bytes: 1272
#include<stdio.h>
void swap (long long int *x,long long int *y) {
  long long int temp = *x;
  *x = *y;
  *y = temp;
}
int partition (long long int array[],long long int left,long long int right) {
  long long int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;
  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);
  swap(&array[pivot], &array[j]);
  return j;
}
void quick_sort (long long int array[],long long int left,long long int right) {
  long long int pivot;
  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);
    quick_sort(array, pivot+1, right);
  }
}

int main(){
  long long int n,ans = 0,i;
  scanf("%lld",&n);
  long long int a[3 * n];
  for(i = 0;i < 3 * n;i++){
    scanf("%lld",&a[i]);
  }
  quick_sort(a,0,3 * n - 1);
  for(i = n;i < 3 * n;i += 2){
    ans += a[i];
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2560
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = sorted(a)
bb = sorted(b)
lis = []
mi = 10**12
for i in range(m):
  x, y, c = map(int, input().split())
  s = a[x-1]+b[y-1]-c
  mi = min(s, mi)
mii = aa[0]+bb[0]
ans = min(mii,mi)
print(ans)

Measured memory_bytes: 18648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <complex>

using namespace std;

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

int main(){

	int input[3];
	for (auto&& a : input){
		cin >> a;
	}
	int flags[2] = { };
	for (auto&& a : input){
		if (a == 5) flags[0]++;
		else if (a == 7) flags[1]++;
	}
	if (flags[0] == 2 && flags[1] == 1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}


}


Measured memory_bytes: 764
N = int(input())
vert = [0 for _ in range(N - 1)]
D = {}
E = {i: [i] for i in range(N)}
F = {i: [] for i in range(N)}
for i in range(N - 1):
  a, b = map(int, input().split())
  D[(a-1)*N+b-1], D[(b-1)*N+a-1] = i, i
  E[a-1].append(b-1)
  E[a-1][0] += N
  E[b-1].append(a-1)
  E[b-1][0] += N
m = max(E[i][0] for i in E)
K = m // N
par = [-1 for _ in range(N)]
root = m % N
par[root] = N + 1
p = [root]
cnt = 1
pnt = 0
while cnt < N:
  n = cnt
  for i in range(pnt, cnt):
    for j in range(1, E[p[i]][0] // N + 1):
      tmp = E[p[i]][j]
      if par[tmp] == -1:
        par[tmp] = p[i]
        F[p[i]].append(tmp)
        cnt += 1
        p.append(tmp)
  pnt = n
q = [root]
t = 1
m = -1
cnt = 1
pnt = 0
while cnt < N:
  n = cnt
  for i in range(pnt, cnt):
    t = 1
    if par[q[i]] != N + 1:
      m = vert[D[q[i]*N+par[q[i]]]]
    for j in F[q[i]]:
      if t == m:
        t += 1
      vert[D[j*N+q[i]]] = t
      q.append(j)
      t += 1
      cnt += 1
  pnt = n
print(K)
for i in range(N-1):
  print(vert[i])

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 67280421310721;
const ll INF = (ll) 1e15;

ll cmb(ll n, ll r) {
    if (n < 0 || n < r || r < 0)
        return 0;
    ll t = 1, m = 1;
    REP(i, r) {
        t *= (n - i);
        m *= (i + 1);
    }
    return t / m;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    ll K;
    cin >> S >> K;
    ll ans = 0;
    ll N = S.length();
    ll n = 0;
    REP(i, N) {
        if (S[i] > '0')
            n++;
    }
    if (K == n)
        ans++;
    REP(i, N) {
        if (S[i] == '0')
            continue;
        ans += cmb(N - 1 - i, K) * pow(9, K);
        ans += cmb(N - 1 - i, K - 1) * pow(9, K - 1) * std::max(S[i] - '1', 0);
        K--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long n,a,b,c,d;
int main(){
    while(scanf("%lld",&n)==1){
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    for(int i=0;i<=n-1;i++){
        if((b-a)>=(i*c-(n-i-1)*d)&&(b-a)<=(i*d-(n-i-1)*c)){
            printf("YES");
            return 0;
            }
        }
    }
    printf("NO");
    return 0;    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    string word; cin>>word;
    int cont=0;
    for(int i=1;i<n-1;i++){
        if(word[i-1]=='A'&&word[i]=='B'&&word[i+1]=='C'){
            cont++;
            i++;
        }
    }
    cout<<cont;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<2];
int ha[N], hb[N], tot;
void _add(int *h, int x, int y) { edge[++tot] = Edge(h[x], y); h[x] = tot; }
void add(int *h, int x, int y) { _add(h, x, y); _add(h, y, x); }
int fa[N], son[N], size[N], top[N], d[N];
int ans, cir;
void dfs(int x)
{
    size[x] = 1;
    for(int i = hb[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa[x]) continue;
        d[y] = d[x]+1, fa[y] = x, dfs(y), 
        size[x] += size[y], son[x] = size[son[x]]>size[y]?son[x]:y; 
    }
}
int lca(int x, int y)
{
    while(top[x] != top[y])
    {
        if(d[top[x]] < d[top[y]]) swap(x, y);
        x = fa[top[x]];
    }
    return d[x]<d[y]?x:y;
}
int dis(int x, int y) { return d[x]+d[y]-2*d[lca(x, y)]; }
void dfs(int x, int topf)
{
    top[x] = topf; if(son[x]) dfs(son[x], topf);
    for(int i = hb[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; 
        if(y != fa[x]&&y != son[x]) dfs(y, y);
    }
}
void escape(int x, int fa, int dep)
{
    ans = max(ans, d[x]<<1); 
    for(int i = ha[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; 
        if(dis(x, y) > 2) cir = 1;    
        if(y == fa||dep+1 >= d[y]) continue;
        escape(y, x, dep+1);
    }
}
int n, a, b;
int main()
{
    n = read(), a = read(), b = read();
    for(int i = 1; i < n; ++i)
    {
        int x = read(), y = read();
        add(ha, x, y);
    } 
    for(int i = 1; i < n; ++i)
    {
        int x = read(), y = read();
        add(hb, x, y);
    }
    dfs(b); dfs(b, b); escape(a, 0, 0);
    printf("%d\n", cir?-1:ans);
    return 0;
}

Measured memory_bytes: 20352
#include<stdio.h>
int main( ){
  int n,b,f,r,v,a[4][3][10]={};
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    a[b-1][f-1][r-1]+=v;
    if(a[b-1][f-1][r-1]<0){
      a[b-1][f-1][r-1]=0;
    }
  }
  for(int j=0;j<4;j++){
    for(int p=0;p<3;p++){
      for(int q=0;q<10;q++){
	printf(" %d",a[j][p][q]);
      }
      printf("\n");
    }
    if(j!=3)printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 2668
import sys
input = sys.stdin.readline
N, K = map(int, input().rstrip().split())
heights = sorted([int(input().rstrip()) for _ in range(N)])
ans = float('inf')
for i in range(N - K + 1):
    if abs(heights[i] - heights[i + K - 1]) < ans:
        ans = abs(heights[i] - heights[i + K - 1])
print(ans)

Measured memory_bytes: 8256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char paste[][] = new char[H+2][W+2];
        String line = "";
        for(int i = 0; i < H + 2; i++){
            for(int j = 0; j < W + 2; j++){
                paste[i][j] = ('#'); 
            }
        }
        for(int i = 1; i < H + 1; i++){
            line = sc.next();
            for(int j = 1; j < W + 1; j++){
                paste[i][j] = line.charAt(j-1); 
            }
        }
        for(int i = 0; i < H + 2; i++){
            for(int j = 0; j < W + 2; j++){
                System.out.print(paste[i][j]);
            }
            System.out.println("");
        }
	}
}

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

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

vector<vector<i64>> G;

int main() {
  i64 N;
  cin >> N;
  G.resize(N);
  vector<vector<i64>> s(N, vector<i64>(N));
  rep(i,0,N) {
    string t;
    cin >> t;
    rep(j,0,N) {
      s[i][j] = (t[j] == '1');
      
      if(s[i][j] == 1) G[i].push_back(j);
    }
  }
  i64 MAX = 0;
  for(int i = 0;i < N;i++) {
    queue<pair<i64, i64>> que;
    que.push({i, -1});

    vector<i64> dist(N, -1);
    dist[i] = 0;
    bool OK = true;
    while(!que.empty() && OK) {
      i64 v = que.front().first;
      i64 f = que.front().second;
      que.pop();
      
      for(auto x: G[v]) {
        if(x == f) continue;
        if(dist[x] == -1) {
          dist[x] = dist[v] + 1;
          que.push({x, v});
        }
        else if(dist[x] != dist[v] + 1 && dist[x] != dist[v] - 1) {
          OK = false;
          break;
        }
      }
    }
    if(OK) {
      i64 M = *max_element(begin(dist), end(dist));
      MAX = max(MAX, M + 1);
    }
  }
  if(MAX == 0) {
    cout << -1 << endl;
  }
  else {
    cout << MAX << endl;
  }
}


Measured memory_bytes: 1024
n = input()
numbers = [int(n) for n in input().split()]

result = 0

number_list = []

for i in numbers:
	number_list.append(i)
	if len(number_list) < 3:
		continue
	elif len(number_list) > 3:
		number_list.pop(0)

	sorted_list = sorted(number_list)
	# print(sorted_list, number_list)
	if sorted_list[1] == number_list[1]:
		result += 1

print(result)


Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n;cin>>n;
    int h[114514];
    rep(i,0,n)cin>>h[i];
    int dp[114514];
    fill(dp,dp+n,mod);
    dp[0]=0;
    rep(i,0,n){
        //cout<<dp[i]<<" ";
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
fuga = [0 for i in range(10)]

wordlist={}
for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		fuga[j]=tmp[j]
	fuga.sort()
	hoge=fuga[0]+fuga[1]+fuga[2]+fuga[3]+fuga[4]+fuga[5]+fuga[6]+fuga[7]+fuga[8]+fuga[9]

	if(hoge in wordlist):
		wordlist[hoge]+=1
	else:
		wordlist[hoge]=1

#print(hoge)
#print(wordlist)

total=0
for i in wordlist:
	t=wordlist[i]
	if(t>=2):
		total+=t*(t-1)//2


print(total)

Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	ll a, b, c, d; cin >> a >> b >> c >> d;
	while (a>0 && c>0){
		a -= d;
		c -= b;
	}
	if (c<=0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

int main() { int i,j,k;
	int c[10][10];
	int r,co;
	cin>>r>>co;
	for(i=0;i<10;i++)
	   {
	   	  for(j=0;j<10;j++)
	   	    cin>>c[i][j];
	   }
	for(k=0;k<10;k++)
	  {
	  	 for(i=0;i<10;i++)
	  	   {
	  	   	  for(j=0;j<10;j++)
	  	   	    {
	  	   	    	if(c[i][j]>c[i][k]+c[k][j])
	  	   	    	  c[i][j]=c[i][k]+c[k][j];
	  	   	    }
	  	   }
	  }
	 long int x,count1=0; 
	for(i=0;i<r;i++)
	  {
	  	  for(j=0;j<co;j++)
	  	    {
	  	    	cin>>x;
	  	    	if(x>=0)
	  	    	count1+=c[x][1];
	  	    }
	  	   
	  }
	  cout<<count1<<'\n';
	// your code goes here
	return 0;
}

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

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

    int flag = 0;

    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }

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

    for(int i = 1; i < n - 1; i++){
        if(a.at(i - 1) == a.at(i) || a.at(i) == a.at(i + 1)){
            flag = 1;
            break;
        }
    }

    if(n == 2){
        if(a.at(0) == a.at(1)){
            flag = 1;
        }
    }

    if(flag == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc124/tasks/abc124_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, ans = 0;
    cin >> a >> b;
    if (a > b) {
        ans += a;
        a--;
    } else {
        ans += b;
        b--;
    }

    if (a > b) {
        ans += a;
        a--;
    } else {
        ans += b;
        b--;
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX = 1e6;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& e : a) cin >> e;
  sort(a.begin(), a.end());

  int r = 0;
  vector<bool> v(MAX + 1, true);
  for (int i = 0; i < n; i++) {
    if (!v[a[i]]) continue;
    if (i == n || a[i] != a[i + 1]) r++;
    for (int j = a[i]; j <= (int)MAX; j += a[i]) v[j] = false;
  }
  cout << r << endl;
}


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

struct Interval {
  int start, slutt;
};
bool operator<(Interval a, Interval b) {
  return a.start < b.start;
}

Interval input[1000000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int a[1000000],b[1000000];
  for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++)input[i].start =a[i]-b[i];
  for (int i = 0; i < n; i++)input[i].slutt =a[i]+b[i];

  sort(input, input+n);

  int slutt = -2e9, ans = 0;
  for (int i = 0; i < n; i++){
    if (input[i].start >= slutt) {
      ans++;
      slutt = input[i].slutt;
    } else {
      slutt = min(slutt, input[i].slutt);      
    }
  }
  cout<<ans;	  
}


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

int main() {
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }else if(s=="Cloudy"){
    cout << "Rainy" << endl;
  }else if(s=="Rainy"){
    cout << "Sunny" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = ("0 "+readLine()!!).split(" ").map { it.toLong() }.toLongArray()
    for(i in 1..a.lastIndex) a[i]+=a[i-1]
    a.groupBy { it%m }
            .map { it.value.size }
            .filter { it>=2 }
            .map { it*(it-1L)/2 }
            .sum()
            .let { println(it) }
}

Measured memory_bytes: 61860
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define Coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	cout << ((nn + 1) * nn / 2) << endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int N, L;
    cin >> N >> L;
    v<string> S(N);
    for (int i = 0; i < N; i++)
        cin >> S[i];

    sort(ALL(S));

    for (int i = 0; i < N; i++)
        cout << S[i];

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int L[N], sum = 0;
  for (int i = 0; i < N; i++) cin >> L[i], sum += L[i];
  bool isok = true;
  for (int i = 0; i < N; i++) isok &= sum - L[i] > L[i];
  cout << (isok ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	vector<vector<int>> road(N);
	vector<bool> used(N, false);
	REP(i, N-1){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		road[a].push_back(b);
		road[b].push_back(a);
	}
	int f=1;
	int s=1;
	queue<PII> que;
	que.push({0, 0});
	que.push({N-1, 1});
	while(!que.empty()){
		PII d = que.front();
		que.pop();
		if(d.second==0){
			++f;
		}else{
			++s;
		}
		foreach(i, road[d.first]){
			if(used[i])continue;
			que.push({i, d.second});
			used[i]=true;
		}
	}
	if(f>s){
		cout << "Fennec" << endl;
	}else{
		cout << "Snuke" << endl;
	}
	return 0;
}


Measured memory_bytes: 5888
#include <iostream>

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  for (int lhs=0; lhs<s.size()-1; ++lhs)
  {
    for (int rhs=lhs+1; rhs<s.size(); ++rhs)
    {
      if (s[lhs] == s[rhs])
      {
        cout << "no" << endl;
        return 0;
      }
    }
  }
  
  cout << "yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

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

    set<int> availableAnswerSet;
    for( int A = 1; A <= 9; ++A ){
        for( int B = 1; B <= 9; ++B ){
            availableAnswerSet.insert(A*B);
        }
    }
    
    cout << ((availableAnswerSet.find(N) != availableAnswerSet.end()) ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static int add(int a, int b) {
		int res = a + b;
		return res >= mod ? res - mod : res;
	}

	static int mul(int a, int b) {
		int res = (int) ((long) a * b % mod);
		return res < 0 ? res + mod : res;
	}

	static int mod;

	static void solve() throws Exception {
		int n = scanInt(), k = scanInt();
		mod = scanInt();
		if (k % 2 == 0) {
			out.print(mul(solve2(n / 2, k / 2 + 1), solve2((n + 1) / 2, k / 2 + 1)));
		} else {
			int dyn[][] = new int[k + 2][k + 2];
			dyn[0][0] = 1;
			int ndyn[][] = new int[k + 2][k + 2];
			for (int i = 0; i < (n | 1) / 2 + k / 2 + 2; i++) {
				for (int a[]: ndyn) {
					fill(a, 0);
				}
				int mask = (i < (n + 1) / 2 ? 1 : 0) + (i >= k / 2 + 2 ? 2 : 0);
				for (int m = mask;; m = (m - 1) & mask) {
					for (int j = 0; j < k + 2; j++) {
						for (int jj = 0; jj < k + 2; jj++) {
							int nj = (m & 1) != 0 ? min(j + 1, k + 1) : 0;
							int njj = (m & 2) != 0 && (j != 0 || jj != 0) ? max(j, jj) + 1 : 0;
							if (nj < k + 2 && njj < k + 2) {
								ndyn[nj][njj] = add(ndyn[nj][njj], dyn[j][jj]);
							}
						}
					}
					if (m == 0) {
						break;
					}
				}
				int t[][] = dyn;
				dyn = ndyn;
				ndyn = t;
			}
			int ans = 0;
			for (int i = 0; i < k + 2; i++) {
				for (int j = 0; j < k + 2; j++) {
					ans = add(ans, dyn[i][j]);
				}
			}
			out.print(ans);
		}
	}

	static int solve2(int n, int k) {
		int dyn[] = new int[k];
		fill(dyn, 1);
		for (int i = 0; i < n; i++) {
			int v = dyn[k - 1];
			for (int j = k - 2; j >= 0; j--) {
				dyn[j + 1] = add(dyn[j], v);
			}
			dyn[0] = v;
		}
		return dyn[k - 1];
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 22788