akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, ans = 0; cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a; cin >> a;
		ans += ((i & 1) && (a & 1));
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int N, a, b, p = 0;
	ll M = 0;
	cin >> N;
	vector<vector<int>> G(N);
	vector<int> c(N), score(N);
	rep(i, 0, N - 1) {
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, 0, N)cin >> c[i];
	r_sort(all(c));
	vector<int> path;
	path.push_back(0);
	score[0] = c[p++];
	while (path.size()) {
		auto pos = path.back();
		path.pop_back();
		for (auto v : G[pos]) {
			if (score[v] == 0) {
				path.push_back(v);
				M += (ll)(score[v] = c[p++]);
				//printf("p:%d\n", p);
			}
		}
	}
	printf("%lld\n", M);
	for(auto v : score) {
		printf("%d ", v);
	}
	puts("");
	return 0;
}


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

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

int main() {
  int n, m, count = 0;
  double total = 0, limit = 0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    total += a[i];
  }
  limit = total / (4 * m);
  for (int i = 0; i < n; ++i) {
    if (a[i] >= limit) ++count;
    if (count >= m) break;
  }
  if (count >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int[] nums=new int[n];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        long ans=0;
        ans+=Math.max(0,nums[0]-x);
        nums[0]-=ans;
        int tmp;
        for(int i=1;i<n;i++){
            tmp=Math.max(0, nums[i-1]+nums[i]-x);
            nums[i]-=tmp;
            ans+=tmp;
        }
        System.out.println(ans);
    }
    
    
}

Measured memory_bytes: 50604
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    string A, B, C; cin >> A >> B >> C;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == B[i] && B[i] == C[i]) ans += 0;
        else if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) ans += 1;
        else ans += 2;
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define M 1000000007
// Driver Code 
/*void rec(vector<vector<int>> &jp,vector<vector<int>>&dp)
{

}*/
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
	int n,m,a,b;
    cin>>n>>m;
    vector<vector<ll>>dp(n, vector<ll>(m,0)); 
    vector<vector<char>>jp(n, vector<char>(m)); 
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>jp[i][j];
        }
    }
    for(int i=1;i<n;i++)
    {
        if(jp[i][0]=='.')
           dp[i][0]+=dp[i-1][0];
    }
    for(int i=1;i<m;i++)
    {
        if(jp[0][i]=='.')
           dp[0][i]+=dp[0][i-1];
    }

    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {   
             
            if(jp[i][j]=='.')
            {   

                 
                     dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M;
                

            }
        }
        //cout<<endl;
    }
    cout<<dp[n-1][m-1];
	return 0; 
} 


Measured memory_bytes: 9088
#include <stdio.h>
#include <ctype.h>

int main(void){
    int key[27] = {0};
    char Input,i;

    while((Input = getchar()) != EOF){
        
        if(isupper(Input)) Input += 32;
        
        if(islower(Input)) key[Input-'a']++;
    }

    for(i='a' ; i<='z'; i++){
        printf("%c : %d\n",i,key[i-'a']);
    }
}


Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	if(A!=B&&B==C){
		cout << A << endl;
	}
	else if(A!=B&&A==C){
		cout << B << endl;
	}
	else{
		cout << C << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

void max_heapify(int *heap, int i, int heap_size) {
	int L, R, largest, tmp;

	L = 2*i;
	R = 2*i + 1;
	if (L <= heap_size && heap[L] > heap[i]) {
		largest = L;
	} else {
		largest = i;
	}
	if (R <= heap_size && heap[R] > heap[largest]) {
		largest = R;
	}
	if (largest != i) {
		tmp = heap[i];
		heap[i] = heap[largest];
		heap[largest] = tmp;
		max_heapify(heap, largest, heap_size);
	}
}

void build_max_heap(int *heap, int heap_size) {
	int i;

	for (i = heap_size/2; i > 0; i--) {
		max_heapify(heap, i, heap_size);
	}
}

int main(void) {
	int heap[500001], heap_size, i;

	scanf("%d", &heap_size);
	for (i = 1; i <= heap_size; i++) {
		scanf("%d", heap+i);
	}

	build_max_heap(heap, heap_size);
	for (i = 1; i <= heap_size; i++) {
		printf(" %d", heap[i]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2552
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def isOK(A):
    A.sort()
    for i in range(len(A) - 1):
        if A[i] + 1 != A[i + 1]:
            return False
    return True


def func(x):
    return 1


def solve():
    K = Scanner.int()
    q = queue.deque()
    for i in range(1, 9 + 1):
        q.append(i)
    for _ in range(K - 1):
        x = q.popleft()
        if x % 10 != 0:
            q.append(x * 10 + x % 10 - 1)
        q.append(x * 10 + x % 10)
        if x % 10 != 9:
            q.append(x * 10 + x % 10 + 1)
    print(q.popleft())


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 62572
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    if(A >= 13){
        cout << B << endl;
    }else if(6 <= A && A <= 12){
        cout << B / 2 << endl; 
    }else{
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
v=[0]*10001
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      d=x*x+y*y+z*z+x*y+x*z+y*z
      if d>10000:
        continue
      else:
        v[d]+=1
for i in range(n):
  print(v[i+1])

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

int main(int argc, char **argv)
{
	ll n, k; cin >> n >> k;
	map<ll, ll> m;

	for (int i = 0; i < n; ++i)
	{
		ll a, b; cin >> a >> b;
		m[a] += b;
	}

	ll ans;
	for (auto &e : m)
	{
		k -= e.second;
		if (k <= 0)
		{
			ans = e.first;
			break;
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 4224
from sys import stdin

s = stdin.readline().rstrip()
k = ""
for i in range(len(s)):
    if s[i] != "x":
        k += s[i]

if k != k[::-1]:
    print(-1)
    exit()

man = (len(k)+1)//2
point = 0
for i,j in enumerate(s):
    if j != "x":
        point += 1
    if point == man:
        kotae = i
        break

a = s[:kotae+1]
b = s[kotae:][::-1]

A = len(a)
B = len(b)

point_a = 0
point_b = 0

total = 0

while point_a < A and point_b < B:
    if a[point_a] == b[point_b]:
        point_a += 1
        point_b += 1
    elif a[point_a] == "x" and b[point_b] != "x":
        point_a += 1
        total += 1
    else:
        point_b += 1
        total += 1

print(total)

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

int count(string str1, int m, string str2, int n){
	if(m == 0 )	return n;
	else if(n == 0)	return m;
	else if(str1[m-1] == str2[n-1])	return count(str1, m-1 ,str2,n-1);
	else {
		int a = count(str1 , m , str2, n-1);
		int b = count(str1, m-1, str2, n);
		int c= count(str1, m-1, str2, n-1);
		return 1 + min(a,min(b,c));
	}
}

void editDist(string str1, string str2){
	int m  = str1.size() , n = str2.size();
	int dp[m+1][n+1];	memset(dp,0,sizeof(dp));
	for(int i=0; i<=m; i++){
		for(int j=0; j<=n; j++){
			if(i == 0 || j== 0)	dp[i][j] = max(i,j);
			else if(str1[i-1] == str2[j-1])	dp[i][j] = dp[i-1][j-1];
			else{
				dp[i][j] = 1 + min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1]));
			}
		}
	}
	cout<<dp[m][n];
}

void lcs(string str1, string str2){
	string ans="";
	int m  = str1.size() , n = str2.size();
	int dp[m+1][n+1];	memset(dp,0,sizeof(dp));
	for(int i=0; i<=m; i++){
		for(int j=0; j<=n; j++){
			if(i == 0 || j== 0)	dp[i][j] = 0;
			else if(str1[i-1] == str2[j-1])	{
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j],  dp[i][j-1]);
			}
		}
	}
	int i = m, j=n;	string str="";
	while(i>0 && j>0){
		if(str1[i-1] == str2[j-1]){
			str.push_back(str1[i-1]);	i--;j--;
		}
		else if(dp[i-1][j] > dp[i][j-1])	i--;
		else	j--;
	}
	reverse(str.begin() ,str.end());
	cout << str;
}

int main(){
	string s1,s2;	cin >> s1 >> s2;
	lcs(s1,s2);
	return 0;
}

Measured memory_bytes: 35456
N = int(input())
A = [[] for i in range(N)]
for i in range(N):
    a = list(map(int, input().split()))
    A[i] = a


num = 0

for i in range(N):
    for j in range(i + 1, N):
        flag = True
        for k in range(N):
            if i == k or k == j:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                flag = False

        if flag:
            num += A[i][j]

print(num)

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;
string S;

int ans[MAX_N];

signed main()
{
  cin >> S; N = S.size();
  int dir = 1;
  int pos = 0;
  REP(n,N) {
    if(dir == 1 && S[n] == 'R') {
      continue;
    } else if(dir == -1 && S[n] == 'L') {
      continue;
    } else if(dir == 1 && S[n] == 'L') {
      FOR(p,pos,n) {
        if((n-p)%2 == 0) {
          ans[n]++;
        } else {
          ans[n-1]++;
        }
      }
      pos = n;
      dir *= -1;
    } else {
      int k = 0;
      FOR(p,pos,n) {
        if(k%2 == 0) {
          ans[pos]++;
        } else {
          ans[pos-1]++;
        }
        k++;
      }
      pos = n;
      dir *= -1;
    }
  }

  if(dir == -1) {
    int k = 0;
    FOR(p,pos,N) {
      if(k%2 == 0) {
        ans[pos]++;
      } else {
        ans[pos-1]++;
      }
      k++;
    }
    pos = N;
    dir *= -1;
  }

  REP(n,N) {
    cout << ans[n];
    if(n < N-1) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>

struct Info {
	int i;
	std::string name;
	int point;

	bool operator < (const Info& rhs) const {
		return (name != rhs.name ? name < rhs.name : point > rhs.point);
	}
};

int main() {
	int n;
	std::cin >> n;

	std::vector<Info> vec(n);
	for (int i = 0; i < n; ++i) {
		vec[i].i = i + 1;
		std::cin >> vec[i].name >> vec[i].point;
	}

	std::sort(vec.begin(), vec.end());

	for (auto&& e : vec)
		std::cout << e.i << std::endl;
}

Measured memory_bytes: 256
N = int(input())
que= [[]for i in range(2)]
for i in range(N):
    x,y = map(int,input().split())
    que[0].append(x-y)
    que[1].append(x+y)
que[0].sort()
que[1].sort()
ans = max(que[0][-1]-que[0][0],que[1][-1]-que[1][0])
print(ans)
    

Measured memory_bytes: 25544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;

int main()
{
ll n,m;
cin >> n >> m ;
set<ll> g[n];
rep(i, m)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].insert(b-1);
    g[b-1].insert(a-1);
}
vector<vector<ll>> gg(n);
rep(i,n)rep(j,n){
  if(i==j)continue;
  if(g[i].find(j)==g[i].end())gg[i].push_back(j);
}
bool see[n]={};
bitset<800> dp;
dp[0]=1;
vector<ll> dist(n);
rep(i,n){
  if(!see[i]){
    ll odd=0,even=1;
    queue<ll> s;
    s.push(i);
    see[i]=1;
    while(s.size()!=0){
      ll now=s.front();
      s.pop();
      for (auto p : gg[now])
      {
        if (see[p] && (dist[p]==dist[now]-1 || dist[p]==dist[now]+1))
            continue;
        else if(see[p]){
          cout << -1 << endl;
          return 0;
        }
        see[p]=1;
        dist[p]=dist[now]+1;
        if(dist[p]%2)odd++;
        else even++;
        s.push(p);
      }
    }
    dp=(dp << odd)|(dp<<even);

  }
}
rep(i,n){
  if(dp[i])ans=min(ans,i*(i-1)/2 +(n-i)*(n-i-1)/2);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 23168
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
q = int(input())
C = [list(map(int,input().split())) for i in range(q)]

B = [0] * (10**5+2)

ans = sum(A)

for i in range(n):
    B[A[i]] += 1
for i in range(q):
    m = B[C[i][0]]
    B[C[i][0]] = 0
    B[C[i][1]] += m
    ans += m * (C[i][1]-C[i][0])
    print(ans)


Measured memory_bytes: 89852
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,s=10,c=0;cin>>n;
	while(n/s) c+=n/s,s*=5;
	if(n%2) cout<<"0\n"; else cout<<c<<endl;
}


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

int main(void)
{
  int A, B;
  cin >> A >> B;
  int ans=-1;
  if(A<=9 && B<=9)
  {
    ans = A*B;
  }
  cout << ans;
 
  return 0;
}

Measured memory_bytes: 256
def judge(N, A):
  cnt = 0
  odd = 0
  for i in range(N):
    if A[i] % 2 != 0:
      odd += 1
    else:
      if (A[i] % 3 == 0) or (A[i] % 5 == 0):
        cnt += 1
  even = N - odd
  if cnt == even:
    print('APPROVED')
  else:
    print('DENIED')
    
N = int(input())
A = list(map(int, input().split()))
judge(N, A)

Measured memory_bytes: 3064
using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);
            System.Console.WriteLine(nm[2] * 60 + nm[3] - (nm[0] * 60 + nm[1]) - nm[4]);
        }
    }
}

Measured memory_bytes: 27348
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int x, y; cin >> x >> y;
  if((4 * x - y) % 2 == 0){
    int a = (4 * x - y) / 2;
    int b = x - a;
    if(a >= 0 && b >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        x: [i64; m],
    }
    let mut x = x;
    x.sort();

    let mut diff = vec![];
    for i in 0..m - 1 {
        diff.push((x[i] - x[i + 1]).abs())
    }
    diff.sort();
    for _ in 0..n - 1 {
        diff.pop();
    }
    println!("{}", diff.iter().sum::<i64>())
}


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

int main(){
    float a,b;
    cin >> a >> b;
    for (int i = 1; i < 1300; i++){
        if (int(i*0.08) == a && int(i*0.1) == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  
  int n, alice = 0, bob = 0;
  
  cin >> n;
  
  int a[n];
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  sort(a, a+n, greater<int>());
  
  for(int i = 0; i < n; i=i+2){
    alice += a[i];
  }
  for(int i = 1; i < n; i=i+2){
    bob += a[i];
  }
  
  cout << alice-bob << endl;
  
  return 0;
}

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

N = int(input())

ans = 0
for n in range(1,N+1,2):
    count = 0
    for i in range(1,n+1):
        # if i > n:
        #     break
        if n % i == 0:
            count += 1

    if count == 8:
        # print('n=',n)
        # print('i=',i)
        ans += 1

print(ans)


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

string L;

const int mod=1e9+7;
const int vmax=100010;
int dp[vmax][2];


signed main(){
	cin>>L;
fill(dp[0],dp[vmax],0);
dp[0][1]=2,dp[0][0]=1;

int n=L.size();

	for(int j=1;j<n;j++){
		dp[j][0]=dp[j-1][0]*3%mod;
		if(L[j]=='1'){
			(dp[j][0]+=dp[j-1][1])%=mod;
			dp[j][1]=dp[j-1][1]*2%mod;
		}
		else{
			dp[j][1]=dp[j-1][1];
		}

	}
	int ret=(dp[n-1][0]+dp[n-1][1])%mod;
	cout<<ret<<endl;
}


Measured memory_bytes: 2048
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int N;
    int[] p;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      p = new int[N];
      for(int k = 0; k < N; k++) {
        p[k] = sc.nextInt();
      }
    }
    if ( isOk(p) ) {
      System.out.println("YES");
    }
    else {
      System.out.println("NO");
    }
  }
  
  private static boolean isOk(int[] p) {
    int n = p.length;
    if ( isAscending(p) ) {
      return true;
    }
    else {
      for(int i = 0; i < n - 1; i++) {
        int pi = p[i];
        for (int j = i+1; j < n; j++) {
          int pj = p[j];
          int[] p_result = new int[n];
          for(int k = 0; k < n; k++) {
            if ( k == i ) {
              p_result[k] = pj;
            }
            else if ( k == j ) {
              p_result[k] = pi;
            }
            else {
              p_result[k] = p[k];
            }
          }
          if ( isAscending(p_result) ) {
            return true;
          }
        }
      }
    }
    return false;
  }
  
  private static boolean isAscending(int[] p) {
    int n = p.length;
    if ( n < 2 ) {
      return true;
    }
    for(int i = 0; i < n - 1; i++ ) {
      int pi = p[i];
      for(int j = i+1; j < n; j++ ) {
        int pj = p[j];
        if ( pi > pj ) {
          return false;
        }
      }
    }
    return true;
  }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/14  Problem: 051_abc_c / Link: https://abc051.contest.atcoder.jp/tasks/abc051_c?lang=en  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int U = ty - sy;
	int D = U;
	int R = tx - sx;
	int L = R;
	string UU = string(U, 'U');
	string DD = string(D, 'D');
	string RR = string(R, 'R');
	string LL = string(L, 'L');
	string ans = "";

	ans = UU + RR + DD + LL + "LU" + UU + RR + "RDRD" + DD + LL + "LU";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>
#include <ext/rope>
 
#define F1(x,y,z) for(int x=y;x<z;x++)
#define F2(x,y,z) for(int x=y;x<=z;x++)
#define F3(x,y,z) for(int x=y;x>z;x--)
#define F4(x,y,z) for(int x=y;x>=z;x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second
 
#define MAX 100005
#define AMAX 1500
#define MOD 1000000007
 
#define f(c,d) ((1<<(c))*(d))
 
using namespace std;
using namespace __gnu_cxx;
 
int n,cnt;
LL ta,tb,tc,td,ans;
vector<int> p;
vector<LL> pp;
vector<pair<pair<LL,int>,LL> > vx;
vector<pair<LL,bool> > vy;
bool o;

int main(){
	p.pb(2),pp.pb(4);
	for(int a=3;a<=100000;a+=2){
		o=1;
		F1(b,0,p.size()){
			if(pp[b]>a)break;
			if(a%p[b]==0){
				o=0;
				break;
			}
		}
		if(o)p.pb(a),pp.pb(((LL)a)*a);
	}
	p.pb(INT_MAX);
	pp.pb(LLONG_MAX);
	scanf("%d",&n);
	F1(a,0,n){
		scanf("%lld",&ta);
		cnt=0;
		tb=tc=0;
		int b=0;
		for(;pp[b]<=ta&&p[b]<2154;b++){
			if(ta%p[b]==0){
				td=0;
				while(ta%p[b]==0){
					ta/=p[b];
					td++;
				}
				td%=3;
				if(td){
					if(td==2)tc+=(1LL)<<cnt;
					cnt++;
					tb=(tb*INT_MAX+p[b])%MOD;
				}
			}
		}
		if(ta!=1){
			td=lower_bound(pp.begin(),pp.end(),ta)-pp.begin();
			if(pp[td]==ta)tb=(tb*INT_MAX+p[td])%MOD,tc+=(1LL)<<cnt;
			else tb=(tb*INT_MAX+ta)%MOD;
			cnt++;
		}
		vx.pb(mp(mp(tb,cnt),tc));
	}
	sort(vx.begin(),vx.end());
	F1(a,0,n){
		ta=vx[a].se;
		tb=(1<<(vx[a].fi.se))-1;
		if(ta>=(ta^tb))vy.pb(mp(ta,0));
		else vy.pb(mp(ta^tb,1));
		if(a==n-1||vx[a].fi!=vx[a+1].fi){
			if(tb==0)ans++;
			else{
				sort(vy.begin(),vy.end());
				ta=tb=0;
				F1(b,0,vy.size()){
					if(vy[b].se)ta++;
					else tb++;
					if(b==vy.size()-1||vy[b].fi!=vy[b+1].fi){
						ans+=max(ta,tb);
						ta=tb=0;
					}
				}
			}
			vy.clear();
		}
	}
	printf("%lld\n",ans);
	#ifdef LOCAL_PROJECT
    system("pause");
    #endif
    return 0;
}


Measured memory_bytes: 6320
#include<iostream>
#include<cstdio>
#define p 1000000007
#define ll long long
using namespace std;
int h,w,a,b;
ll fac[202020],ans;
ll ksm(ll x,ll t)
{
	ll res=1;
	while(t)
	{
		if(t&1) res=res*x%p;
		x=x*x%p;
		t>>=1;
	}
	return res;
}
ll C(int x,int y){ return fac[x]*ksm(fac[y],p-2)%p*ksm(fac[x-y],p-2)%p;}
ll calc(int x,int y){ return C(x+y-2,x-1);}
int main()
{
	scanf("%d%d%d%d",&h,&w,&a,&b);
	fac[0]=fac[1]=1;
	for(int i=2;i<=h+w;i++)
		fac[i]=fac[i-1]*i%p;
	for(int i=1;i<=h-a;i++)
		(ans+=calc(i,b)*calc(h-i+1,w-b)%p)%=p;
	printf("%lld\n",ans);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
  int N,C;
  cin>>N>>C;
  vector<vector<int>> D(C,vector<int>(C));
  REP(i,C) {
    REP(j,C) {
      cin>>D[i][j];
    }
  }
  vector<vector<int>> G(N,vector<int>(N));
  REP(i,N) {
    REP(j,N) {
      cin>>G[i][j];
    }
  }

  vector<vector<int>> A(3,vector<int>(C,0));
  REP(i,N) {
    REP(j,N) {
      int n = (i + j) % 3;
      REP(k,C) {
        A[n][k] += D[G[i][j]-1][k];
      }
    }
  }

  ll ans = INF;
  REP(i,C) {
    REP(j,C) {
      REP(k,C) {
        if (i==j || j==k || k==i) continue;
        ll sum = A[0][i] + A[1][j] + A[2][k];
        ans = min(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1280
n = int(input())
s = input()
en = [1 if s[0]=="E" else 0] #S0からSiまでのうち東を向いている人の数
for i in range(1,n):
    en.append(1 if s[i]=="E" else 0)
    en[-1] += en[-2]
ans = en[-1]-en[0]
for i in range(1,n):
    ans = min(ans, (en[-1]-en[i]) + (i-en[i-1]))
print(ans)


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

int main(void){
  int i,sum;
  long N;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atol(p);
  
  i=0,sum=0;
  while(p[i]!='\0'){
    sum+=p[i]-'0';
    i++;
  }
  
  if(N%sum==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N; string s1, s2;
    cin >> N >> s1 >> s2;

    if(N == 1) cout << 3 << endl;
    else{
        ll ans = 1;
        int MOD = 1000000007;
        bool all_tate = true;
        rep(i, N){
            if(s1[i] != s2[i]) all_tate = false;
        }
        if(all_tate){
            rep(i, N){
                if(i == 0) ans = 3;
                else ans = (ans << 1) % MOD;
            }
        }
        else{
            rep(i, N){
                if(i == 0){
                    if(s1[i] == s2[i]) ans = 3;
                    else{
                        ans = 6;
                        i++;
                    }
                }
                else{
                    // AX
                    // AX この時は*2
                    // AAX
                    // BBX この時は*1
                    // AXX
                    // AYY この時は*2してi++
                    // AAXX
                    // BBYY この時は*3してi++
                    if(s1[i-1] == s2[i-1]) ans = (ans << 1) % MOD;
                    else if(s1[i] != s2[i]) ans = (ans * 3) % MOD;

                    if(s1[i] != s2[i]) i++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 256
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  924844033ll
using namespace std;
int n,k;
ll a[2005],b[2005],c[2005][2005],x[2005],jc[2005],ans;
int main(){
    scanf("%d%d",&n,&k);
    c[0][0]=1;
    for(int i=1;i<=n;++i){
        c[i][0]=c[i][i]=1;
        for(int j=1;j<i;++j){
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            if(c[i][j]>=orz)c[i][j]-=orz;
        }
    }
    a[0]=1;
    for(int i=1;i<=k;++i){
        int p=(n-i)/k+1,q=p/2;
        for(int j=0;j<=q;++j)x[j]=c[p-j][j];
        for(int j=0;j<=n;++j){
            b[j]=0;
            for(int _=0;_<=q&&_<=j;++_)(b[j]+=a[j-_]*x[_])%=orz;
        }
        for(int j=0;j<=n;++j){
            a[j]=0;
            for(int _=0;_<=q&&_<=j;++_)(a[j]+=b[j-_]*x[_])%=orz;
        }
    }
    jc[0]=1;
    for(int i=1;i<=n;++i)jc[i]=jc[i-1]*i%orz;
    int o=1;
    for(int i=0;i<=n;++i)(ans+=a[i]*o*jc[n-i])%=orz,o*=-1;
    printf("%lld\n",(ans%orz+orz)%orz);
    //system("pause");
    return 0;
}


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

int gcd(int x, int y){
	return y == 0 ? x : gcd(y, x % y);
}

int main(){
	int n, maxx, k, num, rec;
	scanf("%d %d",&n,&k);
	scanf("%d",&rec);
	maxx = rec;
	for (int i = 2; i <= n; i++){
		scanf("%d",&num);
		rec = gcd(rec, num);
		maxx = max(maxx, num);
	}
	if (k <= maxx && k % rec == 0) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N,M,K;
    cin >> N >> M >> K;
    int A[N],B[M];
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];

    int At[N+1],Amax=-1;
    At[0] = 0;
    rep(i,N){
        At[i+1] = At[i] + A[i];
        if(At[i+1]>K){
            Amax = i;
            break;
        }
    }
    if(Amax==-1) Amax=N;

    int ans = Amax;
    //cout << Amax << endl;
    rep(i,M){
        K -= B[i];
        if(K<0) break;
        for(int j = Amax; j>=0; --j){
            if( At[j] <= K ){
                //if(chmax(ans, j+i+1)) cout << j << " " << i+1 << endl;;
                chmax(ans, j+i+1);
                Amax = j;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
const int maxn=1e5+5;
struct
{
    long long start,add;
}lazy[maxn<<2];
void up(int id,int l,int r,int tl,int tr,int start,int add)
{
    //printf("%d %d %d %d %d\n",l,r,tl,tr,id);
    if(l==tl&&r==tr){
        lazy[id].start+=start;
        lazy[id].add+=add;
        //printf("%d %d %d %d\n",l,r,start,add);
        return;
    }
    int mid=(l+r)>>1;
    if(tr<=mid) up(id<<1,l,mid,tl,tr,start,add);
    else if(tl>mid) up(id<<1|1,mid+1,r,tl,tr,start,add);
    else{
        up(id<<1,l,mid,tl,mid,start,add);
        up(id<<1|1,mid+1,r,mid+1,tr,start+add*(mid-tl+1),add);
    }
}
long long get(int id,int l,int r)
{
    if(l==r){
        //printf("%lld ",lazy[id].start);
        return lazy[id].start;
    }
    int mid=(l+r)>>1;
    lazy[id<<1].start+=lazy[id].start;
    lazy[id<<1].add+=lazy[id].add;
    lazy[id<<1|1].start+=lazy[id].start+lazy[id].add*(mid-l+1);
    lazy[id<<1|1].add+=lazy[id].add;
    lazy[id].start=lazy[id].add=0;
    //get(id<<1,l,mid);
    //get(id<<1|1,mid+1,r);
    return min(get(id<<1,l,mid),get(id<<1|1,mid+1,r));
}
int main() {
    memset(lazy,0,sizeof(lazy));
    int n,m;
    scanf("%d%d",&n,&m);
    int last;
    scanf("%d",&last);
    for(int i=1;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x>last){
            up(1,1,m,last+1,x,x-last,-1);
            //get(1,1,m);printf("\n");continue;
            if(x!=m)
                up(1,1,m,x+1,m,x-last,0);
            up(1,1,m,1,last,x-last,0);
        }
        else{
            if(last!=m)
                up(1,1,m,last+1,m,x+m-last,-1);
            up(1,1,m,1,x,x,-1);
            up(1,1,m,x+1,last,x+m-last,0);
        }
        last=x;
        //get(1,1,m);
        //printf("\n");
    }
    printf("%lld\n",get(1,1,m));
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  int sum = 0;
  cin >> N >> K;
  
  for( int i = 0; i < N; i++) {
    int ball;
    cin >> ball;
    
    if (ball < ( K - ball )) {
      sum = sum + ball * 2;
    } else {
      sum = sum + ( K - ball ) * 2;
    }
  }
  cout << sum << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


void solve()
{
    ll n;
    cin>>n;
    ll i;
    ll res=0;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
        {
            res+=i;
        }
    }
    cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3604
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 100005
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;

int visited[maxn], ac, pen, wa[maxn];

int main() {
    int n, q;
    cin >> n >> q;
    while(q--){
        int x;
        string s;
        cin >> x >> s;
        if(s == "WA"){
            wa[x] ++;
        }
        else{
            if(!visited[x]){
                visited[x] = 1;
                ac++;
                pen += wa[x];
            }
        }
    }
    cout << ac << " "<<pen << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int dp[200][200];
int x[100][100],y[100][100];
int main()
{
    int n;
    cin>>n;
    ll a[n];
    ll sum=0;
    ll t=1LL;
    for(int i=0;i<n;i++){
         cin>>a[i];
         ll tmp=t*a[i];
         sum+=tmp;
         t=-t;
    }
    ll f=sum;
    cout<<f<<" ";
    for(int i=0;i<n-1;i++){
         f=(a[i]-f/2)*2ll;
         cout<<f<<" ";
    }
}


























Measured memory_bytes: 4348
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	d := make([]byte, K)
	for i := 0; i < K; i++ {
		d[i] = getString()[0]
	}

	ans := N

	// out(d, N)
	for {
		s := strconv.FormatInt(int64(ans), 10)
		flg := true
	L0:
		for _, v := range s {
			for _, e := range d {
				if byte(v) == e {
					flg = false
					break L0
				}
			}
		}
		if flg {
			break
		}
		ans++
	}
	out(ans)
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>

using namespace std;

#define MAXN 1000
int seen[MAXN][MAXN];
char g[MAXN][MAXN];

int dist(int a, int b, int x, int y) {
  return abs(a-x) + abs(b-y);
}

int main(void) {
  int n, m, k;
  scanf("%i %i %i", &n, &m, &k);
  
  int sx = 0, sy = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &g[i][j]);
      if (g[i][j] == 'S') {
        sx = i, sy = j;
      }
    }
  }
  
  vector<pair<int, int>> a, b;
  
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 || i == n || j == 1 || j == m) {
        b.push_back(make_pair(i,j));
      }
    }
  }
  
  queue<int> Q; 
  Q.push(sx), Q.push(sy);
  while (!Q.empty()) {
    int x = Q.front(); Q.pop();
    int y = Q.front(); Q.pop();
    
    a.push_back(make_pair(x, y));
                
    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};
    
    for (int j = 0; j < 4; j++) {
      int nx = x + dx[j], ny = y + dy[j];
      if (nx >= 1 && nx <= n &&
          ny >= 1 && ny <= m &&
          !seen[nx][ny] && g[nx][ny] != '#' &&
          dist(nx, ny, sx, sy) <= k) {
        seen[nx][ny] = 1;
        Q.push(nx); Q.push(ny);
      }
    }
  }
  
  int ans = 10000000;
  for (auto s : a) {
    int rows[] = {1, n};
    for (int j = 0; j < 2; j++) {
      int d = dist(s.first, s.second, rows[j], s.second);
      ans = min(ans, (d + k - 1) / k + 1);  
    }
    
    int cols[] = {1, m};
    for (int j = 0; j < 2; j++) {
      int d = dist(s.first, s.second, s.first, cols[j]);
      ans = min(ans, (d + k - 1) / k + 1);  
    }
  }
  
  printf("%i\n", ans);
  
  return 0;
}

Measured memory_bytes: 15232
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      		int a = sc.nextInt();


      int[] ary=new int[a];
      for (int i=0; i < a;i++){
        ary[i]=sc.nextInt();
      }
	int ans=0;      
    int min=2000000;
      int max=0;
      for (int i=0; i < a;i++){
        if (ary[i]<min){
          ans++;
          min=ary[i];
        } else if (true) {
        }
      }
		System.out.println(ans);
	}
}

Measured memory_bytes: 78160
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def era(n):
    ret = [1 for i in range(n + 2)]
    for i in range(2, int(math.sqrt(n) +3)):
        if ret[i] != 0:
            for j in range(2, n//i + 1):
                ret[i * j] = 0
    rret = []
    for i, r in enumerate(ret):
        if r == 1 and i != 0:
            rret.append(i)

    return rret


def solve():
    n = getN()
    # sosu = era(n)

    ans = 0
    for so in range(1, n+1):
        kazu = n // so
        ans += so * (kazu * (kazu+1) // 2)
        # print(so, ans)


    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 67796