akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int euclid( int a, int b )
{
    int temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}

int main(void) {
	int n, x, xx,result;
	
	scanf("%d %d", &n, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", &xx);
		if (i == 0) result = abs(xx - x);
		result = euclid(result, abs(x-xx));
	}
	 
	printf("%d\n", result);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) cin >> A[i];
  sort(A.rbegin(), A.rend());

  priority_queue<int64_t> que;
  que.emplace(A[0]);

  int64_t answer = 0;
  for (int i = 1; i < N; ++i) {
    answer += que.top();
    que.pop();
    que.emplace(A[i]);
    que.emplace(A[i]);
  }
  cout << answer << endl;
  return 0;
}


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

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

    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> ab(n + 1);
    vector<int> a(n + 1), b(n + 1);
    rep(i, 1, n + 1) cin >> a[i] >> b[i];

    vector<vector<int>> dp1(n + 2, vector<int>(t));
    vector<vector<int>> dp2(n + 2, vector<int>(t));
    rep(i, 1, n + 1) {
        dp1[i] = dp1[i - 1];
        for (int j = t - 1; j >= a[i]; j--) {
            dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - a[i]] + b[i]);
        }
    }
    for (int i = n; i > 0; i--) {
        dp2[i] = dp2[i + 1];
        for (int j = t - 1; j >= a[i]; j--) {
            dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - a[i]] + b[i]);
        }
    }
    int ans = 0;
    rep(i, 1, n + 1) {
        int sum = 0;
        rep(j, 0, t) sum = max(sum, dp1[i - 1][j] + dp2[i + 1][t - 1 - j]);
        ans = max(ans, sum + b[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70912
import sys
from itertools import product

import numpy as np

input = sys.stdin.readline


def main():
    H, W, K = map(int, input().split())
    c = [None] * H
    for i in range(H):
        S = input().rstrip()
        c[i] = [1 if s == "#" else 0 for s in S]

    ans = 0
    for h_comb in product((True, False), repeat=H):
        for w_comb in product((True, False), repeat=W):
            grid = np.array(c, dtype=np.int64)
            for i, paint in enumerate(h_comb):
                if paint:
                    grid[i, :] = 0
            for i, paint in enumerate(w_comb):
                if paint:
                    grid[:, i] = 0
            if np.sum(grid) == K:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P =pair<ll,ll>;

int main(){
  ll n,m; cin>>n>>m;
  vector<ll> a(n);
  vector<P> p(m);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }sort(a.begin(),a.end());
  for(int i=0;i<m;i++){
    ll x,y; cin>>x>>y;
    p[i]=P(y,x);
  }sort(p.begin(),p.end());
  bool flag =false;
  ll ans=0;
  for(int i=m-1;i>=0;i--){
    for(int j=0;j<p[i].second && !a.empty();j++){
      if(a[0]<p[i].first){
        ans+=p[i].first;
        a.erase(a.begin());
      }else{
        if(j==0) flag = true;
        break;
      }
    }if(flag) break;
  }
  for(int i=0;i<a.size();i++){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
N = int(input())
D, X = map(int,input().split())
arr = [0] * N
ans = 0
for i in range(N):
    arr[i] = int(input())
for i in range(N):
    day = 1
    while day <= D:
        ans += 1
        day += arr[i]
print(ans+X)

Measured memory_bytes: 3064
def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of bool
    """

    is_prime = [True] * (x + 1)
    is_prime[0] = is_prime[1] = False

    for i in range(2, x + 1):
        if is_prime[i]:
            for j in range(i * 2, x + 1, i):
                is_prime[j] = False

    return is_prime


n = int(input())

is_prime = sieve(10 ** 6)
primes = [i for i, e in enumerate(is_prime) if e]

ans = 0
for e in primes:
    div = e
    while n % div == 0:
        n //= div
        ans += 1
        div *= e

    while n % e == 0:
        n //= e


def f(x):
    if x < 2:
        return False

    for e in primes:
        if x % e == 0:
            return False

    return True


ans += n != 1

print(ans)


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

int main(){
  long long N,ans,ans2;
cin>>N;
  ans2=0;
  vector<long long>a(N),b(100001);
  for(int i=0;i<100001;i++){
   b[i]=0;
  }
  for(int i=0;i<N;i++){
cin>>a[i];
    b[a[i]]++;
    if(b[a[i]]==1){
      ans2++;
    }
  }
 if(ans2%2==0){
   ans2--;
 }
    cout<<ans2<<endl;
}


Measured memory_bytes: 1792
total = 9593
primes = [0] * total
primes[0] = 2
x = 1
k = 1
while (k < total):
    x += 2
    j = 0;
    while (j < k and x % primes[j] != 0):
        if (primes[j] * primes[j] >= x):
            primes[k] = x
            k = k + 1
            break
        j = j + 1
# print(primes)

X = int(input())
for p in primes:
    if p >= X:
        print(p)
        exit()


Measured memory_bytes: 39536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> c(4);
    string s;
    for(int i = 0; i < n; ++i){
        cin >> s;
        if(s == "AC") c.at(0)++;
        else if(s == "WA") c.at(1)++;
        else if(s == "TLE") c.at(2)++;
        else if(s == "RE") c.at(3)++;
    }
    cout << "AC x " << c.at(0) << endl;
    cout << "WA x " << c.at(1) << endl;
    cout << "TLE x " << c.at(2) << endl;
    cout << "RE x " << c.at(3) << endl;
    return 0;
}

Measured memory_bytes: 3628
import copy
import time

t1 = time.time()

def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res
    
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]

T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

p = calc(T)

i = D-1
next = -1
while time.time()-t1 < 1.9:
    for j in range(26):
        temp = copy.deepcopy(T)
        temp[i] = j+1
        newp = calc(temp)
        if p < newp:
            T[i] = j+1
            p = newp
    i += next
    if i == -1:
        i = 1
        next = 1
    elif i == D:
        i = D-2
        next = -1

for t in T:
    print(t)

Measured memory_bytes: 80504
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr long long INF = 1e12;

int main() {

    long long N, W;
    cin >> N >> W;

    vector<long long> w(N), v(N);
    for (int i = 0; i < N; i++)cin >> w[i] >> v[i];

    vector<vector<long long>> dp(N + 1, vector<long long>(100010, INF));
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 100005; j++) {
            if (j - v[i] >= 0) {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    long long ans = 0;
    for (int i = 0; i <= 100000; i++) if (dp[N][i] <= W) ans = i;

    cout << ans << endl;

    return 0;
}
















































Measured memory_bytes: 80256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int asort(const void *a, const void *b) {
  ll x = *(ll *)a, y = *(ll *)b;
  if (x > y) return 1;
  if (x < y) return -1;
  return 0;
}

int
main(int argc, char *argv[])
{
  int n; ll v[50];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &v[i]);

  qsort(v, n, sizeof(ll), asort);

  double ans = 0; double x = 1;
  ans += (double)v[0];
  for (int i = 1; i < n; i++) {
    ans += (double)((long long)1 << (i - 1)) * (double) v[i];
    x += (double)((long long)1 << (i - 1));
  }

  printf("%f\n", ans / x);

  return 0;
}

  

  


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

using namespace std;

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

	string s;
	cin >> s;

	int d = s.back() - '0';

	string ans;

	if (d == 2 or d == 4 or d == 5 or d == 7 or d == 9)
		ans = "hon";
	else if (d == 3)
		ans = "bon";
	else
		ans = "pon";

	cout << ans;

	return 0;
}

Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N = int(readline())
    l = []
    for _ in range(N):
        l.append(readline()[:-1])
    s = set(l)
    ans = len(s)
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;

int main()
{
  int a, b;
  cin >> a >> b;

  int large = std::max(a, b);
  int small = std::min(a, b);

  cout << std::max(large * 2 - 1, large + small) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a, b, ans;
  char op;

  while(1){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '+') ans = a + b;
    if(op == '-') ans = a - b;                       
    if(op == '*') ans = a * b;
    if(op == '/') ans = a / b;                         
    if(op == '?') break;

    printf("%d\n", ans);
  }
  
  return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

LL n, k;
LL dp[105][N];
LL a[105];

int main() {
	fastio;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 0; i <= k; i++)
		dp[0][i] = 0;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - 1 >= 0)
				dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			if (j - a[i] - 1 >= 0)
				dp[i][j] = (dp[i][j] - dp[i - 1][j - a[i] - 1] + MOD) % MOD; 
			// cout << dp[i][j] << " "	;
		}
		// cout << endl;
	}
	cout << dp[n][k] << endl;	
	return 0;
}
		

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  long long a,b;
  cin>>a;
  cout<<a<<':';b=a;
  for(int i=2;i*i<=b;i++){
    while(a%i==0){
      cout<<' '<<i;
      a/=i;
    }
    if(a==1)break;
  }
  if(a!=1)cout<<' '<<a;
  cout<<endl;
}

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

int main()
{
	int a, b;
	cin.tie(0);
	cin >> a >> b;
	if (a == b) {
		cout << "a == b" << "\n";
	}
	else if (a < b) {
		cout << "a < b" << "\n";
	}
	else {
		cout << "a > b" << "\n";
	}
}


Measured memory_bytes: 3104
N, Q = map(int, input().split())
S = input()

ac_counts = [0] * N
last = ''
n_count = 0
for idx, current in enumerate(S):
    if last == 'A' and current == 'C':
        n_count += 1
        ac_counts[idx] = n_count
    elif idx != 0:
        ac_counts[idx] = ac_counts[idx - 1]
    last = current

for _ in range(Q):
    l, r = map(int, input().split())
    print(ac_counts[r - 1] - ac_counts[l - 1])


Measured memory_bytes: 6108
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vi = vector<ll>;
using vii = vector<ii>;
using vvi = vector<vi>;


#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

ll cont(string & num, int idx, int kact, vector<vvi> & m, int s) {
	if (kact == 0) return 1;
	else if (idx == num.size() && kact > 0) return 0;
	//else if (m[idx][kact][s] != -1) return m[idx][kact][s];
	else if (s == 0) {
		ll soluciones = 0;
		if (num[idx] != '0') {
			soluciones += cont(num, idx + 1, kact - 1, m, 0);
			soluciones += (num[idx] - '0' - 1) * cont(num, idx + 1, kact - 1, m, 1);
			soluciones += cont(num, idx + 1, kact, m, 1);
		}
		else {
			soluciones += cont(num, idx + 1, kact, m, 0);
		}
		
		
		m[idx][kact][s] = soluciones;
		return soluciones;
	}
	else {
		ll soluciones = 0;
		soluciones += 9 * cont(num, idx + 1, kact - 1, m, 1);
		soluciones += cont(num, idx + 1, kact, m, 1);

		m[idx][kact][s] = soluciones;
		return soluciones;
	}
}

bool res() {
	string s;
	int k;
	cin >> s >> k;
	if (!cin) return false;

	vector<vvi> m(s.size() + 1, vvi(k + 1, vi(2, -1)));
	ll sol = cont(s, 0, k, m, 0);
	cout << sol << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

N = int(input())
S = input()
ele, num = get_sequence(S)
print(len(num))

Measured memory_bytes: 51824
def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float("inf") for _ in range(N+2)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(H[i]-H[i+j]))
    print(dp[N-1])


if __name__ == "__main__":
    main()


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

int main()
{
        string s;
        cin >> s;
        string t;
        cin >> t;
        vector<char> S;
        for (int i = 0; i < s.length(); ++i) {
                S.push_back(s[i]);
        }
        vector<char> T;
        for (int i = 0; i < t.length(); ++i) {
                T.push_back(t[i]);
        }

        sort(S.begin(), S.end());
        sort(T.begin(), T.end(), greater<char>());

        int len = (s.length() < t.length()) ? s.length() : t.length();
        for (int i = 0; i < len; ++i) {

#if 0
                cout << "s= " << S[i] << ",t= " << T[i] << endl;
#else
                if ((int)S[i] < (int)T[i]) {
                        cout << "Yes" << endl;
                        exit(0);
                }
                else if ((int)S[i] > (int)T[i]) {
                        cout << "No" << endl;
                        exit(0);
                }
#endif
        }
        if (T.size() > S.size()) {
                cout << "Yes" << endl;
        }
        else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char S, last;
    cin >> last;
    while ((cin >> S)) {
        if (last == S) {
            cout << "Bad" << endl;
            return 0;
        }

        last = S;
    }

    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n; long ans; cin>>n; ans=0;
  int a[n+1]; int b[n];
  rep(i,n+1) cin>>a[i];
  rep(j,n) cin>>b[j];
  
  for(int k=0;k<n;k++){
  
  if(b[k]==a[k]) ans=ans+a[k];
    
  else if(b[k]>a[k]){ ans=ans+a[k]; b[k]=b[k]-a[k];
                     if(b[k]>=a[k+1]) {ans=ans+a[k+1]; a[k+1]=0;}
                     else {ans=ans+b[k]; a[k+1]=a[k+1]-b[k];}
                    }
    
  else ans=ans+b[k];
    
  }
  
   cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string route;
	cin>>route;
	int a=0,b=0,i;
	for(i=0;i<3;i++)
	{
		if(route[i]=='A')
			a++;
		else
			b++;
	}
	if(a==0||b==0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	return 0;
}


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int d = a / b;
  int r = a % b;

  double fa = a, fb = b;
  printf("%d %d %.5f\n", d, r, (fa / fb));
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

};

int main(){
  vvi a(1,vi(3));
  rep(i,3) cin >> a[0][i];

  int ans = 0;
  int i = 0;
  while(true){
    bool ok = true;
    rep(j,3) if(a[i][j]%2) ok = false;
    if(!ok) break;
    ans++;

    vi tmp(3);
    rep(j,3){
      int sum = 0;
      rep(k,3) {
        if(j == k) continue;
        sum += a[i][k];
      }
      tmp[j] = sum/2;
    }
    a.pb(tmp);
    i++;
    if(a[i] == a[i-1]){
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  ll T[2],A[2],B[2];
  cin>>T[0]>>T[1];
  cin>>A[0]>>A[1];
  cin>>B[0]>>B[1];
  ll X=T[0]*A[0]+T[1]*A[1];
  ll Y=T[0]*B[0]+T[1]*B[1];
  
  if(X==Y){
    cout<<"infinity\n";
    return 0;
  }
  if(X>Y&&A[0]>B[0]){
    cout<<0<<endl;
    return 0;
  }
  if(X<Y&&A[0]<B[0]){
    cout<<0<<endl;
    return 0;
  }
  
  ll D=abs(X-Y);
  ll Z=abs(A[0]-B[0])*T[0];
  
  cout<<Z/D*2+(Z%D!=0)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

template <class T = int>
vector<T> slide_min(const vector<T>& a, int w, function<bool(T, T)> cmp = less<T>()) {
  int n = a.size();
  vector<T> ret(n);
  deque<int> dq;
  REP (i, n) {
    while (!dq.empty() && !cmp(a[dq.back()], a[i])) {
      dq.pop_back();
    }
    dq.push_back(i);
    while (dq.front() <= i - w) {
      dq.pop_front();
    }
    ret[i] = dq.front();
  }
  return ret;
}

signed main() {
  int N, M, K; cin >> N >> M >> K;
  VI A(N);
  REP (i, N) cin >> A[i];

  VVI dp(K + 1, VI(N + 1, 0));
  REPI (i, 1, K + 1) {
    dp[i][0] = -1;
  }
  VVI mas(K + 1, VI(N + 1));
  REPI (i, 1, K + 1) {
    REPI (j, 1, N + 1) {
      int prv = dp[i - 1][mas[i - 1][j - 1]];
      dp[i][j] = prv == -1 ? -1 : prv + i * A[j - 1];
    }
    // スライド最大値
    mas[i] = slide_min<int>(dp[i], M, greater<int>());
  }
  cout << *max_element(ALL(dp[K])) << endl;
}


Measured memory_bytes: 474992
#include <stdio.h>


int solve(int a[], int k, int m, int n) {
    int res;
    if (m == 0) return 1;
    if (k >= n) return 0;
    res = solve (a, k + 1, m, n) || solve(a, k + 1, m - a[k], n);
    return res;
}

int main() {
    int n, q, i, key;
    int a[20];
    
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    
    scanf("%d",&q);
    
    for (i = 0; i < q; ++i) {
        scanf("%d", &key);
        
        if (solve(a, 0, key, n)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
        
        
    }
    
    return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N;cin >> N;
    vector<long long> A(N),B(N),C(N);
    REP(i,N) cin >> A[i];
    REP(i,N) cin >> B[i];
    REP(i,N) cin >> C[i];
    sort ALL(A);sort ALL(B);sort ALL(C);
    vector<long long> H(N,0);
    REP(i,N){
        long long right = N,left = -1,mid,ans = -1;
        while(right - left > 1){
            mid = left + (right - left) / 2;
            if(C[mid] > B[i]){
                right = mid;
                ans = mid;
            }
            else left = mid;
        }
        if(ans == -1) continue;
        H[i] += C.size() - ans;
    }
    rep(i,N-1){
        H[i] += H[i+1];
    }
    ll cnt = 0;
    REP(i,N){
        long long right = N,left = -1,mid,ans = -1;
        while(right - left > 1){
            mid = left + (right - left) / 2;
            if(B[mid] > A[i]){
                right = mid;
                ans = mid;
            }
            else left = mid;
        }
        if(ans == -1) continue;
        cnt += H[ans];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int a, b, c;
    cin >> a >> b >> c;

    cout << ((c - b == b - a) ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
	
	int w, h;
	
	cin >> w >> h;
	
	vector<pair<int, int> > pairs(w + h);
	
	pair<int, int> pair_int;
	
	int num;
	
	for(int i = 0; i < w; i++){
		cin >> num;
		pair_int = make_pair(num, 1);
		pairs[i] = pair_int;
	}
	for(int i = 0; i < h; i++){
		cin >> num;
		pair_int = make_pair(num, 2);
		pairs[i + w] = pair_int;
	}
	
	sort(pairs.begin(), pairs.end());
	
	long long int count_x, count_y, ans;
	
	count_x = 0;
	count_y = 0;
	ans = 0;
	
	for(int i = 0; i < w + h; i++){
		if(pairs[i].second == 1){
			count_x++;
			ans += pairs[i].first * (h - count_y + 1);
		}else{
			count_y++;
			ans += pairs[i].first * (w - count_x + 1);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 1920
import java.io.*;
  
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String sentence;
        int[] abc = new int[26];
        while ((sentence = input.readLine()) != null) {
            int line_len = sentence.length();
            for (int i = 0; i < line_len; i++) {
                char index = solveIndex(sentence.charAt(i));
                if (index >= 0 && index < 26)
                    abc[index]++;
            }
        }
        char cc = 'a';
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 26; i++) {
            sb.append(cc++).append(" : ").append(abc[i]).append('\n');
        }
        System.out.print(sb.toString());
    }
    private static char solveIndex(char c) {
        if (c >= 'a' && c <= 'z')
            c -= 'a';
        else if (c >= 'A' && c <= 'Z')
            c -= 'A';
        return c;
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M);
  for (int i = 0; i < M; ++i) {
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; ++j) {
      cin >> s[i][j];
      --s[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; ++i)
    cin >> p[i];

  int ans = 0;
  for (int bit = 0; bit < 1 << N; ++bit) {
    vector<int> light(M);
    for (int i = 0; i < N; ++i)
      if (bit & 1 << i)
        for (int j = 0; j < M; ++j)
          for (int l = 0; l < k[j]; ++l)
            if (i == s[j][l])
              ++light[j];

    bool flag = true;
    for (int i = 0; i < M; ++i)
      if (light[i] % 2 != p[i])
        flag = false;

    if (flag)
      ++ans;
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {
  int n; cin >> n;
  vector<int> a(n); for (int& x : a) cin >> x;
  
  sort(a.begin(), a.end());
  double ans = 0;
  for (int i = 0; i < n; i++) {
    int e = min(n - i, n - 1);
    ans += (double)a[i] * (1.0 / (double)(1LL << e));
  }
  cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <cmath>
using namespace std;

using ll = long long;

int main(){
  int n; cin >> n;
  ll a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a, a+n);
 
  ll m1 = a[n/2], m2 = a[n/2-1];

  ll s1 = 0, s2 = 0;
  for(int i=0; i<n; i++){
    s1 += abs(a[i]-m1);
    s2 += abs(a[i]-m2);
  }

  cout << min(s1, s2) << endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
// Your code here!
$count = explode(" ",trim(fgets(STDIN)));
$animals = $count[0];
$asi = $count[1];

for($i=0; $i<=$animals; $i++){
    $t = $animals - $i;
    $a = $i*2+$t*4;
    if($a == $asi){
        echo "Yes";
        return 0;
    }else{
        $total = "No";
    }
}

if(isset($total)){
    echo $total;
}


?>


Measured memory_bytes: 16088
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	solve()
}

func solve() {
	var a, b int
	fmt.Scan(&a, &b)
	res := a - b*2
	if res < 0 {
		res = 0
	}
	fmt.Print(res)
}

func max(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Max(res, float64(z))
	}
	return int(res)
}

func min(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Min(res, float64(z))
	}
	return int(res)
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func sqrt(x int) int {
	return int(math.Sqrt(float64(x)))
}

func int2Int(x int) big.Int {
	var res big.Int
	res.SetInt64(int64(x))
	return res
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
typedef pair<int,int>P;
#define MAX 1e9
struct edge{int to,cost;};

int main() {
  int N;
  cin >>N;
  map<string,int>S;
  rep(i,N){
    string g;
    cin >>g;
	S[g]=1;  
  }
  
  cout<<S.size()<<endl;
  
  
}


Measured memory_bytes: 19064
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

lli gcd(lli a,lli b){
    lli x,y;
    x=max(a,b);
    y=min(a,b);
    if(x%y==0){
        return y;
    }
    else{
        return gcd(y,x%y);
    }
}

int main(){
    lli n,x,d;
    vector<lli> vec;
    lli i,j;
    cin>>n>>x;
    vec.push_back(x);
    rep(i,0,n){
        lli a;
        cin>>a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    d=abs(vec[0]-vec[1]);
//    cout<<vec[0]<<"と"<<vec[1]<<"の間は"<<abs(vec[0]-vec[1])<<endl;
    rep(i,1,n){
//        cout<<vec[i]<<"と"<<vec[i+1]<<"の間は"<<abs(vec[i]-vec[i+1])<<endl;
        d=gcd(d,abs(vec[i]-vec[i+1]));
    }
    cout<<d<<endl;
}


Measured memory_bytes: 1400
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {

	int n;
	cin >> n;
	int t = 0, h = 0;
	for (size_t i = 0; i < n; i++)
	{
		string s1, s2;
		cin >> s1 >> s2;
		if (s1 < s2) h += 3;
		else if (s1 > s2) t += 3;
		else {
			t++;
			h++;
		}
	}
	cout << t << " " << h << endl;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3208
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline
V, E, r = map(int, input().split())
G = [[] for _ in [0]*V]
for _ in [0]*E:
    a, b, c = map(int, input().split())
    G[a].append((b, c))

INF = 1 << 30
D = [INF]*V
used = [0]*V
q = []
heappush(q, (0, r))

while q:
    d, v = heappop(q)
    if used[v]:
        continue
    used[v] = 1
    D[v] = d
    for u, c in G[v]:
        if used[u]:
            continue
        if d+c < D[u]:
            heappush(q, (d+c, u))

for i in range(V):
    print(D[i] if D[i] != INF else 'INF')



Measured memory_bytes: 96812
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
	}
}

Measured memory_bytes: 21844
from itertools import permutations
import numpy as np

def main():
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))

    cnt = 0
    a = 0
    b = 0
    for i in permutations(range(1,n+1)):
        cnt += 1
        if list(i) == p :
            a = cnt
        if list(i) == q :
            b = cnt

    print(np.abs(a-b))

if __name__ == "__main__":
    main()

Measured memory_bytes: 12512
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  vector<ll> sum(N+1,0);
  for(int i=0;i<N;i++)  sum.at(i+1)=sum.at(i)+a.at(i);
  vector<vector<ll>> dp(N+1,vector<ll>(N+1,1e18));
  for(int i=0;i<N+1;i++)  dp.at(i).at(i)=0;
  for(int i=0;i<N;i++)  dp.at(i).at(i+1)=0;
  for(int length=0;length<N+1;length++){
    for(int l=0;l+length<N+1;l++){
      int r=l+length;
      for(int m=l+1;m<r;m++){
        dp.at(l).at(r)=min(dp.at(l).at(r),dp.at(l).at(m)+dp.at(m).at(r)+sum.at(r)-sum.at(l));
      }
    }
  }
  cout << dp.at(0).at(N) << endl;

  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	int a[100] = { 0 };
	int n;
	int i;	//ループ用
	int stk, cnt = 0;

	/*入力*/
	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	i = 0;
	while (i < n - 1)
	{
		if (a[i] == a[i + 1])
		{
			cnt++;
			i += 2;
		}
		else
		{
			i++;
		}
	}

	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cassert>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#define el endl
int main(){
	int n,m,s=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a;
		scanf("%d",&a);
		n-=a;
	}
	if(n<0)printf("-1");
	else printf("%d",n);
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,c;
    cin>>n>>c;
    ll x[n+1],v[n+1],y[n+2],a[n+1],b[n+2];
    v[0]=x[0]=a[0]=0;
    y[n+1]=b[n+1]=0;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>v[i];
        y[i]=c-x[i];
        a[i]=v[i]+a[i-1];
    }
    for(int i=n;i>=1;i--){
        b[i]=v[i]+b[i+1];
    }
    ll f[n+2],g[n+2];
    f[0]=g[0]=0;
    for(int i=1;i<=n;i++){
        f[i]=max(a[i]-x[i],f[i-1]);
        g[i]=max(a[i]-2*x[i],g[i-1]);
    }
    ll ans=0,num;
    for(int i=n+1;i>=1;i--){
        num=max(f[i-1]+b[i]-2*y[i],g[i-1]+b[i]-y[i]);
        ans=max(num,ans);
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private final static byte MASK_RIGHT = 0x0F; //右4bit数値化用マスク
	private final static int STRIP_LENGTH = 10; //短冊1行の長さ
	private static int[] punchTape = new int[100]; //10*10の方眼紙を短冊にしてくっつけた紙テープ

	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 512);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private static void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private static void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			punchTape[x * STRIP_LENGTH + y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private static void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int cell : punchTape) {
			if (cell == 0) {
				white++;
			} else if (cell > max) {
				max = cell;
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

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

int main()
{
    int color[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;

    cin >> x >> y;
    if(color[x] == color[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    int N;
    int K;
    int x[100];
    int i;
    int ret = 0;
    scanf("%d",&N);
    scanf("%d",&K);
    for(i=0;i<N;i++){
        scanf("%d ",&(x[i]));
        if(x[i]<=(K/2)){
            ret = ret + x[i]*2;
        }else{
            ret = ret + ( K - x[i]) * 2;
        }
        //printf("X:%d\n",x[i]);
    }
    printf("%d\n",ret);

    return 0;
}


Measured memory_bytes: 1728
#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")

signed main(){
	cout<<fixed<<setprecision(7);
	int xx = INF;
	int n, t, a, j, h;
	
	cin>>n>>t>>a;
	
	for(int i = 1; i <= n; i++){
		cin>>h;
		if(abs(t*1000-h*6-a*1000) < xx){
			xx = abs(t*1000-h*6-a*1000);
			j = i;
		}
	}
	
	cout<<j<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  string ans = "";
  for(int i = 0; i < s.size(); i++){
    if(s.at(i)=='0') ans += '0';
    if(s.at(i)=='1') ans += '1';
    if(s.at(i)=='B' && ans.size()>0) ans.pop_back();
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if ((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

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

int n,k,q;
cin >> n >> k >> q;
vector<int> point(n,k);
int i;
int a;
for(i=0;i<q;++i){
    cin >> a;
    point[a-1]++;
}
for(i=0;i<n;++i){
    if(point[i]-q<=0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .map(d -> Math.pow((d-dm),2) / n)
          .sum();

        System.out.printf("%.8f\n" , Math.sqrt(result));
      }
    }
  }
}


Measured memory_bytes: 32088
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val a = sc.nextInt()
    val b = sc.nextInt()
    println(calc(a, b))
}

fun calc(a: Int, b: Int): String {
    return when {
        a <= 0 && 0 <= b ->
            "Zero"
        a < 0 && (b - a) % 2 == 0 ->
            "Negative"
        else ->
            "Positive"
    }
}


Measured memory_bytes: 31392
#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>
#include <list>
#include <bitset>
#include <unordered_set>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

#define pb push_back
#define mp make_pair

#define MAXN 51
#define MAXX 1000000001
#define MAXD 1000000001
#define MAXM 1000000001

#define MAXV (MAXN*MAXN*MAXN)
#define SMALL 50

#define INF 1000000009

struct item_t {
  int w;     // weight       (<= MAXX)
  int v;     // value        (<= MAXN*MAXN)
  int d;     // amount left  (<= MAXD)

  bool operator<(const item_t& other) const {
    return v * other.w > other.v * w;
  }
};

item_t item[MAXN];
item_t greedy[MAXN];

int dp[MAXN][MAXV];
void solve_knapsack(int N) {
  // compute dp[n][v] := using first n items (0..n-1), the minimum weight necessary to achieve value v 
  FOR(i,MAXN) FOR(j,MAXV) dp[i][j] = INF;

  dp[0][0] = 0;
  FORALL(n,1,N) {
    dp[n][0] = 0;
    int idx = n-1;
    assert(item[idx].v <= N && item[idx].d <= SMALL);
    FORALL(v,1,MAXV-1) {
      FORALL(cnt,0,item[idx].d) { // pick how many copies of item n-1 to use
        int new_v = max(v - cnt * item[idx].v, 0);
        int here = min(1ll*INF, 1ll*cnt*item[idx].w + dp[n-1][new_v]);
        dp[n][v] = min(dp[n][v], here);
      }

      assert(dp[n][v] >= dp[n][v-1]);
      assert(dp[n][v] <= dp[n-1][v]);
    }
  }
}

int solve_greedy(int W, int N) { // solve greedily for weight W (get maximum value)
  int ans = 0; // total value = ?
  FOR(i,N) {  // they are sorted by efficiency
    int take = min(greedy[i].d, W / greedy[i].w);
    W -= take * greedy[i].w;
    ans += take * greedy[i].v;
  }
  return ans;
}



// Construction / dfs stuff
int D;
int M[MAXN];
vector<int> E[MAXN];
void dfs(int i) {
  item[i] = (struct item_t){M[i], 1, (i? D : INF)};
  for (const auto & j: E[i]) {
    dfs(j);
    item[i].w = min(INF, item[i].w + item[j].w);
    item[i].v += item[j].v;
  }
}


int main() {
  int N,X,p;
  scanf("%d%d%d",&N,&X,&D);
  FOR(i,N) {
    scanf("%d",&M[i]);
    if (i > 0) {
      scanf("%d", &p); p--;
      E[p].pb(i);
    }
  }

  dfs(0);
  sort(item, item+N);

  FOR(i,N) {
    greedy[i] = item[i];

    int to_use = min(item[i].d, SMALL);    
    greedy[i].d = item[i].d - to_use;
    item[i].d = to_use;
  }

  solve_knapsack(N);

  int ans = 0;          // maximum value achievable with X weight
  FOR(v,MAXV) {  // decide how much value we get from the dp. then greedy the rest
    if (dp[N][v] > X) continue;
    int total_value = v + solve_greedy(X - dp[N][v], N);
    ans = max(ans, total_value);
  }

  cout << ans << endl;
}














Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int n, m, ans;
pair<int, int> doll[200];
int dp[1000][1000];
int main()
{
	while(cin >> n && n)
	{
		memset(dp, -1, sizeof(dp));
		ans = 0;
		dp[0][0] = 0;
		for(int i = 0; i < n; i++)
			cin >> doll[i].F >> doll[i].S;
		cin >> m;
		for(int i = n; i < n + m; i++)
			cin >> doll[i].F >> doll[i].S;
		sort(doll, doll + n + m);
		for(int i = 0; i < n + m; i++)
			for(int j = 0; j < doll[i].F; j++)
				for(int k = 0; k < doll[i].S; k++)
					dp[doll[i].F][doll[i].S] = max(dp[doll[i].F][doll[i].S], dp[j][k] + 1);

		for(int i = 0; i < 1000; i++)
			for(int j = 0; j < 1000; j++)
				ans = max(ans, dp[i][j]);
			cout << ans << endl;
	}

}

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

int main() {
  int n, i, x, count=0, ans=0;

  cin >> n;
  for(i=0;i<n;i++){
    cin >> x;
    if(x%2 == 0){
      count++;
      if(x%3 == 0 || x%5 == 0) ans++;
    }
  }

  if(count == ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;

  return 0;
  
}


Measured memory_bytes: 256