akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i > b; i--)
#define repll(i, a, b) for (ll i = a; i < b; i++)

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

  int n, m;
  cin >> n >> m;

  int temp = 0, sum = 0;
  rep(i, 0, m) {
    cin >> temp;
    sum += temp;
  }

  if (sum > n)
    cout << -1 << endl;
  else
    cout << n - sum << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define N 100003
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

int main() {
	// for fast input output using cin cout
	std::ios_base::sync_with_stdio(false);

	// input
	int n, k;
	cin>>n>>k;

	long long ans = 1;
	while (n--) {
		if (ans < k)
			ans *= 2;
		else
			ans += k;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3", "5", "10","15" ].parse.expand.solve == 25 );
	assert( [ "3", "10", "10", "15" ].parse.expand.solve == 35 );
	assert( [ "3", "10", "20", "30" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto ss = new long[ n ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.strip.to!( long );
	}
	return tuple( ss );
}

auto solve( long[] ss )
{
	auto t = ss.sum;
	if( t % 10 != 0 ) return t;
	
	auto s = ss.sort().filter!( ( s ) => ( t - s ) % 10 != 0 ).takeOne;
	if( s.empty ) return 0;
	else          return t - s.front;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var m, d int
	fmt.Scan(&m, &d)
	sum := 0
	for i := 1; i <= m; i++ {
		for j := 1; j <= d; j++ {
			if v1, v2 := j/10, j%10; 2 <= v1 && 2 <= v2 {
				if i == v1*v2 {
					sum++
				}
			}
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int main()
{
	fast;
	int n;cin>>n;
	vector<ll> xx,yy;
	for(int i=0;i<n;i++)
	{
		ll x,y;cin>>x>>y;
		xx.push_back(x+y);
		yy.push_back(x-y);
	}
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	ll ans=0;
	ans=max(ans,abs(xx[0]-xx[n-1]));
	ans=max(ans,abs(yy[0]-yy[n-1]));

	cout<<ans<<nl;

}

Measured memory_bytes: 6636
import java.util.*
fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)

    var result = 0L
    val maxMod = 1000000007L
    val N = reader.nextInt()
    val nums = mutableListOf<Long>()
    repeat(N){
        nums.add(reader.nextLong())
    }

    var initSum : Long = 0L
    initSum += nums[nums.size - 1]

    for(index in nums.size - 2 downTo  0){
       result = (result + initSum * nums[index]).rem(maxMod)
        initSum += nums[index]
        initSum = initSum.rem(maxMod)
    }
    println(result)
}

Measured memory_bytes: 66492
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
long long mod = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//////////////////////////////////

int main() {
    int n; cin >> n;
    vector<double> v(n);
    priority_queue<double> pq;
    for(int i=0; i<n; i++) {cin >> v[i]; pq.push(-v[i]);}

    while(pq.size() != 1) {
        double tmp = -pq.top();
        pq.pop();
        double tmp2 = -pq.top();
        pq.pop();

        pq.push(-(tmp+tmp2)/2.0);
    }

    printf("%.10lf\n", -pq.top());

    return 0;
}




// EOF


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
#define PI 3.14159265358979323846
using namespace std;
int main(){
	ll n,m,sum=0;
	cin>>n>>m;
	ll a[m];
	l(i,0,m) cin>>a[i],sum+=a[i];
	if(sum>n) cout<<-1<<"\n";
	else{
		cout<<n-sum<<"\n";
	}
}

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

typedef long long ll;

int main() {
   string s;
   cin >> s;
   int sum=0;
   for(char d : s){
    sum+=(d-'0');
   }
   if(sum%9) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3728
# -*- coding:utf-8 -*-
S = int(input())

a = [S]
cnt = 1
while True:
    if S%2 == 0:
        S /= 2
    else:
        S = 3*S + 1
    cnt += 1
    if S in a:
        break
    else:
        a.append(S)

print(cnt)

Measured memory_bytes: 9228
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long[] sum = new long[n];
    sum[0] = sc.nextLong();
    for(int i = 1; i < n; i++) {
      sum[i] = sum[i - 1] + sc.nextLong();
    }
    long xm = 0;
    for(int i = 41; i >= 0; i--) {
      long t = xm + (long)Math.pow(2, i);
      int p = 0;
      for(int j = 0; j < n; j++) {
        for(int l = j; l < n; l++) {
          long y = 0;
          if(j == 0) {
            y = sum[l];
          } else {
            y = sum[l] - sum[j - 1];
          }
          if((t & y) == t) p++;
        }
      }
      if(p >= k) xm = t;
    }
    System.out.println(xm);
  }
}


Measured memory_bytes: 24060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
struct Bridge{
  int n;
  vector<vector<int> > G;
  vector<int>low,used,depth;
  set<pair<int,int> >ans;
  Bridge(){}
  Bridge(int sz):n(sz),low(sz),used(sz),depth(sz),G(sz){}
  void add(int a,int b){
    G[a].push_back(b);
    G[b].push_back(a);
  }
  void dfs(int x,int d,int prev){
    depth[x]=d;
    for(int i=0;i<G[x].size();i++){
      int nx=G[x][i];
      if(nx==prev)continue;
      if(!used[nx]){
        used[nx]=true;
        dfs(nx,d+1,x);
        if(!low[nx]) ans.insert(P(min(x,nx),max(x,nx)));
        low[x]+=low[nx];
      }
      else if(d>depth[nx])low[nx]--,low[x]++;
    }
  }
  void build(){
    fill(used.begin(),used.end(),0);
    fill(low.begin(),low.end(),0);
    fill(depth.begin(),depth.end(),0);
    used[0]=1;
    dfs(0,0,0);
  }
  void prin(){
    set<P>::iterator it=ans.begin();
    while(it!=ans.end()){
      cout<< (*it).first <<' '<< (*it).second <<endl;
      it++;
    }
  }
};
int main(){
  int n,m,s,t;
  cin>>n>>m;
  Bridge B(n);
  for(int i=0;i<m;i++){
    cin>>s>>t;
    B.add(s,t);
  }
  B.build();
  B.prin();
  return 0;
}


Measured memory_bytes: 4648
N=int(input())
a=[]
for i in range(N):
  a.append(int(input()))
success=0
current=1
for i in range(N+5):
  if current==2:
    success=i
    break
  current=a[current-1]
if success==0:
  print(-1)
else:
  print(success)

Measured memory_bytes: 7084
A,B,K = map(int,input().split())
ansA = [1]
ansB = [1]
for i in range(1,A*B):
    if A%i == 0:
        ansA.append(i)
    if B%i == 0:
        ansB.append(i)
      
ans = []
for i in ansA:
    if i in ansB:
        ans.append(i)
print(ans[-K])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;

void solve(){
	int n,k;
	cin>>n>>k;
	int x=1;
	while(n--){
		if(x*2-x<=k){
			x*=2;
		}
		else x+=k;
	}
	cout<<x;
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    ll a;
    ll total = 0;
    int negs = 0;
    ll absm = 1e9;
    REP(i, n){
        cin >> a;
        total += abs(a);
        if(a < 0){
            negs++;
        }
        if(absm > abs(a)){
            absm = abs(a);
        }
    }
    if(negs & 1){
        cout << total - 2*absm << endl;
    }else{
        cout << total << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,num=0,ans=0;string s;
	cin>>a>>s;
	for(int i=0;i<a;i++)
		if(s[i]=='W')
			num++;
	for(int i=0;i<a-num;i++)
		if(s[i]=='W')
			ans++; 
	cout<<ans;
	return 0;
}

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

int main(){
  int a,b,c,d,sum;
  cin >> a >> b >> c >> d;
  
  if(a < b){
    sum = a*c;
  }
  
  if(a >= b){
    sum = b*c+(a-b)*d;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a;
	int b;
	int c;
	while(~scanf("%d%d",&a,&b)){
		if(a-2*b>0){
			c=a-2*b;
			printf("%d",c);
		}
		if(a-2*b<=0){
			printf("0\n");
		}
	}
	
	return 0;
 } 

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

using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int result = 0;
  for (int i = a; i <= b; i++) {
    string a = to_string(i);
    if (a[0] == a[4] && a[1] == a[3]) result++;
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
import fractions

n,m = map(int,input().split())

s = list(input())
t = list(input())

l = len(s)
u = len(t)

a = fractions.gcd(l,u)
b = (l*u)//a

for i in range(a):
	if s[(l//a)*i]  != t[(u//a)*i]:
		print(-1)
		break
else:
	print(b)

Measured memory_bytes: 6712
from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

n = inp()
p = list(map(float, input().split()))
# dp[i][j]=最初のi枚のコインを投げた時に表がj枚になる確率
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    for j in range(n):
        dp[i + 1][j + 1] += dp[i][j] * p[i]  # i+1枚目が表
        dp[i + 1][j] += dp[i][j] * (1.0 - p[i])  # i枚目が裏

print(sum([dp[n][i] for i in range(math.ceil(n / 2), n + 1)]))
# for i in dp:
#     print(i)


Measured memory_bytes: 252680
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

while True:
    M,F,R = map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print("F")
    elif M+F >= 80:
        print("A")
    elif M+F >= 65:
        print("B")
    elif M+F >= 50:
        print("C")
    elif M+F >= 30:
        if R >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;

	auto check = [&](int i) {
		int res = 0;
		while (i % 2 == 0) {
			i /= 2;
			res++;
		}
		return res;
	};
	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		ans = min(ans, check(a[i]));
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
ll lcm(ll x, ll y){ return (x  / gcd(x, y) * y ); }
ll ctx(ll s, ll c, ll d){
	ll dc = s /c;
	ll dd = s /d;
	ll g = lcm(c, d);
	ll dg = s /g;
	return s - dc - dd + dg;
}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll a,b,c,d;
	cin >>a >>b >>c >>d;
	
	ll w0= ctx(a-1, c,d);
	ll w1= ctx(b, c,d);
	//dbg(w1, w0);
	cout << w1 - w0 <<"\n";
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	vector<ll> pref(n);
	map<int, int> cnt;
	vin(a);
	pref[0] = a[0];
	ll ans = 0;
	for (int i = 1; i < n; ++i)
	{
		pref[i] = pref[i - 1] + a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		ll ned = pref[i] % m;
		int have = cnt[ned];
		if (!ned)
		{
			have++;
		}
		ans += have;
		cnt[ned]++;
	}
	cout << ans;
	system("pause");
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<int, int>

ll S(ll n){
  if(n<10) return n;
  else return (S(n/10) + (n%10));
}

int main(){
  ll pt = 1;
  vector<ll> ans;
  REP(i, 16){
    ll x = 2;
    while((x*pt-1)*S(x*pt+pt-1) <= (x*pt+pt-1)*S(x*pt-1)){
      ans.pb(x*pt-1);
      x++;
    }
    pt *= 10LL;
  }
  sort(ALL(ans));
  REP(i, ans.size()-1){
    if(ans[i] == ans[i+1]){
      ans.erase(ans.begin()+i);
      i--;
    }
  }
  int p;
  cin >> p;
  REP(i, p) cout << ans[i] << endl;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<bool> red(n, false);
    vector<int> num(n, 1);
    red[0] = true;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if(num[x] == 1) {
            if(red[x]) {
                red[x] = false;
                red[y] = true;
            }
        }
        else {
            if(red[x]) {
                red[y] = true;
            }
        }
        num[x]--;
        num[y]++;
    }
    int ans = 0;
    rep(i, n) {
        if(red[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int price = 0;

		if (a >= 13) {
			price = b;
		} else if (a >= 6 && a <= 12) {
			price = b / 2;
		}else {
			price = 0;
		}
		System.out.println(price);

	}

}

Measured memory_bytes: 21844
//
//  main.cpp
//  Testcpp
//
//  Created by sandeep.m on 07/07/17.
//  Copyright © 2017 sandeep.m. All rights reserved.
//


#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    int ans = 0;
    int block = 0;
    
    for(int i = 0; i < n; i++)  {
        cin >> a[i];
        if(a[i] == i + 1)   {
            block++;
        }   else    {
            ans += (block + 1) / 2;
            block = 0;
        }
    }
    
    if(block)   {
        ans += (block + 1) / 2;
    }
    
    cout << ans << endl;
    
    
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
const int inf=1e9+7;
const ll INF=1e18;


int main() {
  string s;
  cin>>s;
  int n=s.size();
  ////////////
  ll ans=0;
  char c=s[0];
  rep(i,n-1){
    if(s[i+1]!=c){
      ans++;
      c=s[i+1];
    }
  }
  cout<<ans<<endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    REP(i, N) cin >> P[i];

    vector<int> pos(N+1);
    REP(i, N) pos[P[i]] = i;

    long long ans = 0;
    multiset<int> s{-1, -1, pos[N], N, N};
    for(int i = N-1; i > 0; --i){
        auto tmp = s.lower_bound(pos[i]);
        int x = *next(tmp, -1);
        int w = *next(tmp, -2);
        int y = *tmp;
        int z = *next(tmp, 1);
        long long cases = (long long) (x-w)*(y-pos[i]) + (long long) (pos[i]-x)*(z-y);
        ans += i * cases;
        s.insert(pos[i]);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans = 0;
    vector<int> cost(100010,0);

    for(int i = 0; i < N; i++){
        cost[a[i]]++;
        cost[a[i] + 1]++;
        if(a[i] > 0) cost[a[i] - 1]++;
    }

    rep(i, 100010){
        ans = max(cost[i],ans);
    }

    cout << ans << endl;





}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  unsigned long long N,P,i;
  cin>>N;

  P = 1;
  i = 1;

  while (i <= N) {
    P = P*i;
    if (P > 1000000007) {
      P = P%1000000007;
    }
    i++;
  }

  /*while (P > 1000000007) {
    P = P-1000000007;
  }*/

  P = P%1000000007;

  cout<<P;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>

#define Size(c) (int)(c).size()
#define INT(...) int __VA_ARGS__;IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;IN(__VA_ARGS__)

int scan(){ return getchar(); }
void scan(int& a){ cin>>a; }
void scan(long long& a){ cin>>a; }
void scan(char &a){cin>>a;}
void scan(double &a){ cin>>a; }
void scan(long double& a){ cin>>a; }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }

void IN(){}
template <class Head, class... Tail> void IN(Head& head, Tail&... tail){ scan(head); IN(tail...); }

#define ios cin.tie(NULL), ios_base::sync_with_stdio(false)
#define cfs(n) cout<<fixed<<setprecision((n))
#define endl '\n'
#define ret return 0

constexpr ll mod=998244353;
constexpr ll mod2=10e9+7;
const double PI = 3.1415926535897932384626433832795028841971; //acos(-1)

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

ll a[100010];
int main(){
  ios; cfs(15);

  INT(n);
  rep(i, n) {
    scan(a[i]);
    if(a[i]==0) {
      cout<<"0"<<endl;
      ret;
    }
  }

  ll prod = 1;
  rep(i,n) {
    if(a[i] <= 1000000000000000000/prod) {
      prod *= a[i];
    } else {
      prod = -1;
      break;
    }
  }

  cout << prod << endl;
  ret;
}


Measured memory_bytes: 4392
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

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

using namespace std;

typedef long long ll;

int group(int n){
    if(n==2)
        return 2;
    else if(n==4 || n==6 || n==9 || n==11)
        return 1;
    else
        return 0;

}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int X,A,B;
    cin >> X >> A >> B;
    int c=-A+B;
    if(c<=0)
        cout << "delicious" << endl;
    else if(0<c&&c<=X)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}

int main(){
    int n,X,now,num;
    cin >> n >> X;
    cin >> now;
    now = abs(X - now);
    for (int i=1; i<n; i++) {
        cin >> num;
        now = gcd(now, abs(X-num));
    }
    cout << now << endl;
    return 0;
}


Measured memory_bytes: 256
local mod = 1000000007
local bls, brs = bit.lshift, bit.rshift
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = {}
  for j = 1, n do
    t[i][j] = io.read("*n") == 1
  end
end

local tot = bls(1, n)
local alltask = {}
local stagetask = {}
do
  for i = 1, n do
    stagetask[i] = {}
  end
  for i = 1, tot - 1 do
    -- set empty state
    alltask[i] = 0
  end
  for i = 1, tot - 1 do
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        ti = ti - 1
      end
      ti = ti / 2
    end
    table.insert(stagetask[cnt], i)
  end
  -- set first state
  local tmp = 1
  for i = 1, n do
    alltask[tmp] = t[1][i] and 1 or 0
    tmp = tmp * 2
  end
end

for stage = 1, n - 1 do
  local stlen = #stagetask[stage]
  for i_stagetask = 1, stlen do
    local used = stagetask[stage][i_stagetask]
    local mul = 1
    local tmp = used
    for j = 1, n do
      if tmp % 2 == 0 then
        if t[stage + 1][j] then
          alltask[used + mul] = (alltask[used + mul] + alltask[used]) % mod
        end
      else
        tmp = tmp - 1
      end
      tmp = tmp / 2
      mul = mul * 2
    end
  end
end
print(alltask[tot - 1])


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

bool isACGT(char c) {
    if ( c == 'A' || c == 'C' || c == 'G' || c == 'T') {
        return true;
    }
    return false;
}

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

    int longest = 0;
    for (int i = 0; i < s.length(); i++) {
        int cnt = 0;
        int j = i;
        while(isACGT(s[j])) {
            ++cnt;
            ++j;
        }
        if (cnt > longest) {
            longest = cnt;
        }
    }
    cout << longest << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std ;
#define A 10 B 11 C 12 D 13 E 14 F 15

int main()
{
  char X,Y ;
  cin>>X>>Y ;
  
  if(X<Y) cout<<"<"<<endl ;
  else if(X>Y) cout<<">"<<endl ;
  else cout<<"="<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define nl endl
#define inf 1e18
#define cases ll t;cin>>t;while(t--)
#define BLOCK 500
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;


const int N=3005;
ll dp[N][N];
int main()
{
    
    fast
    ll n;
    cin>>n;
    ll a[n];

    f(i,n)
    cin>>a[i];

    

    for(ll l=n-1;l>=0;l--)
    {
        for(ll r=l;r<n;r++)
        {
            if(l==r)
            dp[l][r]=a[l];

            dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);

        }
    }

    cout<<dp[0][n-1];




    

       
    return 0;
    
}



Measured memory_bytes: 70016
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double DB;
const int N=100005;
struct node
{
    DB x,y;
}a[N],O;
int n;
DB r;
inline DB power(DB x)
{
    return x*x;
}
inline DB dis(node a,node b)
{
    return sqrt(power(a.x-b.x)+power(a.y-b.y));
}
inline bool in_circle(node a)
{
    return dis(a,O)<=r?1:0;
}
inline int calc(DB a,DB b,DB c,DB d,DB e,DB f)
{
    O.x=(b*f-d*e)/(b*c-a*d);
    O.y=(c*e-a*f)/(b*c-a*d);
}
inline void min_cover_circle(void)
{
    register int i,j,k;
    random_shuffle(a+1,a+n+1);
    for (i=1;i<=n;++i)
    if (!in_circle(a[i]))
    {
        O=a[i]; r=0;
        for (j=1;j<i;++j)
        if (!in_circle(a[j]))
        {
            O.x=(a[i].x+a[j].x)/2.0; O.y=(a[i].y+a[j].y)/2.0; r=dis(a[i],O);
            for (k=1;k<j;++k)
            if (!in_circle(a[k])) calc(a[i].x-a[j].x,a[i].y-a[j].y,a[i].x-a[k].x,a[i].y-a[k].y,
            ((power(a[i].x)-power(a[j].x))-(power(a[j].y)-power(a[i].y)))/2.0,
            ((power(a[i].x)-power(a[k].x))-(power(a[k].y)-power(a[i].y)))/2.0),r=dis(a[i],O);
        }
    }
    printf("%.18lf\n",r);
}
int main()
{
    register int i; scanf("%d",&n);
    for (i=1;i<=n;++i)
    scanf("%lf%lf",&a[i].x,&a[i].y);
    min_cover_circle();
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N;
  cin >> N;
  ll X[N];
  for(int i=0; i<N; i++) cin >> X[i];
  
  
  ll Y[N];
  memcpy(Y, X, sizeof(X));
  sort(Y, Y+N);
  int mid = N/2;
  for(int i=0; i<N; i++){
    ll ans;
    if(X[i] < Y[mid]){
      ans = Y[mid];
    }else{
      ans = Y[mid-1];
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

int main () {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2;
  int y = y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  rep(_,2) {
    swap(dx,dy);
    dx = -dx;
    x += dx;
    y += dy;
    cout << x SP y << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    long long int x, y=100, count = 0;
    cin >> x;
    while(y < x){
        y *= 1.01;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
import heapq

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
A.append(0)
S = []
heapq.heapify(S)
c = A[0]
cnt = 1
for i in range(1, N + 1):
    if A[i] == c:
       cnt += 1
    else:
        heapq.heappush(S, (A[i - 1], cnt))
        cnt = 1
        c = A[i]


for i in range(M):
    B, v = map(int, input().split())
    flag = False #Sからの取り出し比較を1度以上終えているか
    b = B # 残りカード
    while len(S) > 0 and S[0][0] < v:
        x = heapq.heappop(S)
        if b <= x[1]:
            heapq.heappush(S, (v, B))
            if not b == x[1] : heapq.heappush(S, (x[0], x[1] - b))
            flag = False
            break
        else:
            flag = True
            b -= x[1]

    if flag: #交換しきらないで、途中で終わっているのでこの分は挿入する
        heapq.heappush(S, (v, B - b))

sumS = 0
while len(S) > 0:
    x = heapq.heappop(S)
    sumS += x[0] * x[1]
print(sumS)


Measured memory_bytes: 16536
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [a, b] <- map (read :: String -> Int) . words <$> getLine                                                                
  if even (a * b)                                                                                                          
    then putStrLn "No"                                                                                                     
    else putStrLn "Yes"

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
typedef queue<int> qi;
typedef stack<int> sti;
typedef priority_queue<int> pqi;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//std::uniform_int_distribution<long long> rg(1,1e18);
#define maxn 300005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
struct node{
    int l, r, mx;
}N[maxn * 4];
void update(int k) {
    if(N[k].l == N[k].r) return;
    N[k].mx = max(N[k<<1].mx, N[k + k + 1].mx);
}
void build(int k, int l, int r) {
    N[k].l  = l;
    N[k].r = r;
    N[k].mx = 0;
    if(N[k].l == N[k].r) {
        return ;
    }
    int mid = (l + r) / 2;    
    build(2*k,l,mid);
    build(2*k + 1,mid + 1, r);
}
void change(int k, int x, int y) {
    if(N[k].l == N[k].r) {
        N[k].mx = y;
        return;
    }
    int mid = (N[k].l + N[k].r)>>1;
    if(x <= mid) change(k << 1, x, y);
    else change(2*k+1,x,y);
    update(k);
}
int query(int k, int l, int r) {
    if(N[k].l == l && N[k].r ==r) return N[k].mx;
    int mid = (N[k].l + N[k].r) >> 1;
    if(l > mid) return query(k+k+1,l,r);
    else if(r <= mid) return query(k<<1, l, r);
    else return max(query(k<<1,l, mid) , query(k + k+ 1, mid + 1, r) );
}
void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    fori(i,0,n) {
        cin >> a[i];
    }
    build(1,0,maxn);
    fori(i,0,n) {
        int p = query(1, max(0, a[i] - k), min(maxn, a[i] + k) );
        change(1, a[i], p + 1);
    }
    cout << query(1, 0, maxn);

}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
//	freopen("D:\\data_in.txt", "r", stdin);
   
    solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 16704
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int H =sc.nextInt();
    int W =sc.nextInt();
    int M =sc.nextInt();
    int A[]=new int[M];
    int B[] =new int[M];
    int C[] =new int[H];
    int D[] =new int[W];
    int E[] =new int[H];
    int F[] =new int[W];
    for(int i=0;i<M;i++){
      A[i]=sc.nextInt();
      B[i]=sc.nextInt();
      C[A[i]-1]=C[A[i]-1]+1;
      D[B[i]-1]=D[B[i]-1]+1;
      E[A[i]-1]=E[A[i]-1]+1;
      F[B[i]-1]=F[B[i]-1]+1;}
    Arrays.sort(C);
    Arrays.sort(D);
    long r =C[H-1]+D[W-1];
    long s =0;
    long t =0;
    for(int j=0;j<M;j++){
      s=E[A[j]-1]+F[B[j]-1];
      if(s==r){t=t+1;}}
    long u=0;
    long v=0;
    for(int i=H-1;i>=0;i--){
      if(C[i]==C[H-1]){u=u+1;}
      else{break;}}
    for(int j=W-1;j>=0;j--){
      if(D[j]==D[W-1]){v=v+1;}
      else{break;}}
    if(u*v-t>0){System.out.println(r);}
    else{System.out.println(r-1);}
  }
}

Measured memory_bytes: 67480
import scala.io.StdIn
object Main extends App {
  val S = StdIn.readLine().toList
  val T = StdIn.readLine().toList
  val list = for {
    i <- 0 until 3
    s = S(i)
    t = T(i)
    if (s == t)
  } yield (s,t)
  println(list.length)
}


Measured memory_bytes: 27312
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int a,b;

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

        cin >> a >> b;

        if (a >= 13) {
                cout << b << endl;
        } else if (6 <= a && a <= 12) {
                cout << b/2 << endl;
        } else {
                cout << 0 << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0,tmp=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='I'){
      tmp++;
    }else if(s[i]=='D'){
      tmp--;
    }
    ans=max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    int e, f;

    e = a * b;
    f = c * d;

    if (e >= f){
        cout << e << endl;
    } else {
        cout << f << endl;
    }
}

Measured memory_bytes: 256
S = input()
U = S
T = ""
while True:
    flag = False
    for s in ["dream", "dreamer","erase","eraser"]:
        if S.endswith(s):
            S = S[:-len(s)]
            T = s + T
            flag = True
    if T == U:
        print("YES")
        break 
    elif not flag:
        print("NO")
        break

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

int n, k, ans = 0;

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans += min(x, abs(x - k));
  }
  cout << 2 * ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

static inline void MainTask() {
  uint32_t N;
  cin >> N;
  vector<uint32_t> A(N), B(N), C(N - 1);
  ArrayInput(A);
  ArrayInput(B);
  ArrayInput(C);
  uint32_t Prev = A[0];
  uint64_t res = B[A[0] - 1];

  for (uint32_t i = 1; i < N; ++i) {
    res += B[A[i] - 1];
    if (Prev == A[i] - 1) res += C[A[i] - 2];
    Prev = A[i];
  }
  cout << res << endl;
}

int main() {
  MainTask();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int x,a,b;
	cin >> x >> a >> b;

	if (a - b >= 0) {
		cout << "delicious" << endl;
	}else if (b-a <= x){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
deque < long long > a;
deque < long long > b;
int main()
{
	int n,a2,b2;
	cin>>n;
	for(long long i=0;i<n;i++)
	{
		cin>>a2;
		a.push_back(a2);
	}
	for(long long i=0;i<n;i++)
	{
		cin>>b2;
		b.push_back(b2);
	}
	long long k=0,k2=0;
	for(long long i=0;i<n;i++)
		k+=b[i]-a[i];
	for(long long i=0;i<n;i++)
	{
		if(b[i]-a[i]>0)
			k2+=(b[i]-a[i]+1)/2;
	}
	if(k2>k) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            while(true)
            {
                string input = Console.ReadLine();
                string[] nm = input.Split(' ');
                int n = int.Parse(nm[0]);
                int x = int.Parse(nm[1]);
                int cnt = 0;

                if(n == 0 && x == 0)
                    break;

                for (int i = 1; i <= n; i++)
                {
                    for (int j = i+1; j <= n; j++)
                    {
                        for (int k = j+1; k <= n; k++)
                        {
                            if (i + j + k == x)
                            {
                                cnt = cnt + 1;
                            }
                        }
                    }
                }

                Console.WriteLine(cnt);
            }
    }
    }
}

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

#define ll long long
#define pb push_back

void solve()
{

    ll a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    ll k;
    cin>>k;
    cout<<a[k-1]<<endl;

    
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String S = "";

        int N = scan.nextInt();
        if(N==0){
            System.out.println("0");    
            System.exit(0);
        }
        while(N != 1){
            if(N % -2 == -1){
                S = "1" + S;
                N = N/-2 + 1;
            }
            else if(N % -2 == 1){
                S = "1" + S;
                N = N/-2;
            }
            else{
                S = "0" + S;
                N = N/-2;
            }
        }
        S = "1" + S;
        System.out.println(S);
    }
}


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

using namespace std;

const int N_MAX = 19;

typedef long long ll;

int k;

int v[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> k;
    int lg = 1;
    v[1] = 1;
    k--;
    while(k--)
    {
        bool ok = false;
        for(int i = 1; i <= lg; i++)
            if((i == lg || v[i] < v[i + 1] + 1) && v[i] < 9)
            {
                v[i]++;
                for(int j = i - 1; j >= 1; j--)
                    v[j] = max(0, v[j + 1] - 1);
                ok = true;
                break;
            }
        if(ok == true)
            continue;
        lg++;
        for(int i = 1; i < lg; i++)
            v[i] = 0;
        v[lg] = 1;
    }
    for(int i = lg; i >= 1; i--)
        cout << v[i];
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;


namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] arr = sc.intarr;
            int a = arr[0];
            int b = arr[1];

            int ans = Method.max(a*b, a+b, a-b);

            wr.wri(ans);
        }
    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define pb push_back
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll,ll> 
ll fac[1000001];
void powe(ll p)
{
     fac[0] = 1; 

     
    for (ll i = 1; i <= 1000000; i++) 
        fac[i] = (fac[i - 1] *i) % p; 
  
}
 
 
        
      long long power( long long x, 
                         ll y, ll p) 
{ 
   long long res = 1; // Initialize result 
  
    x = x % p; 
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
 long long modInverse( long long n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
 long long nCrModPFermat( long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
       return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
 ll gcd(ll a,ll b)
 {
     if(b==0)
     return a;
     return gcd(b,a%b);
 }
  
int main() {
   ll t=1;

  // cin>>t;
  powe(1000000007);
  
   //ll vis[10]={0};
   while(t--)
   {
   
    ll n;
    cin>>n;
    ll ggg=360;
  cout<<ggg/gcd(n,ggg);
   }
  
   

      

return 0;    
}


Measured memory_bytes: 11408
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int dp[100001]={0};
    int stone[100001];
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&stone[i]);
    }
    dp[1] = 0;
    dp[2] = abs(stone[2]-stone[1]);
    for(int i=3;i<=n;i++){
        dp[i] = min(dp[i-1]+abs(stone[i]-stone[i-1]),dp[i-2]+abs(stone[i]-stone[i-2]));
    }
    printf("%d",dp[n]);
}


Measured memory_bytes: 896