akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

long long kMod = 1e9+7;

class Node {
  public:
    int id;
    int cnt;
    vector<int> neighbors;
    bool is_visited;
    Node() { id = -1; is_visited = false; cnt = 1; }
};

void dfs(vector<Node>& node, long long k, long long& result, int i, int parent)
{
  if (node.at(i).is_visited) {
    return;
  }
  node.at(i).is_visited = true;
  result = (result * (k - node.at(parent).cnt)) % kMod;
  node.at(parent).cnt++;
  node.at(i).cnt++;
  for (int nx : node.at(i).neighbors) {
    dfs(node, k, result, nx, i);
  }
}

int main()
{
  int nnodes, ncolors;
  cin >> nnodes >> ncolors;
  vector<Node> node(nnodes);
  for (int i = 0; i < nnodes; i++) {
    node.at(i).id = i;
  }
  for (int i = 0; i < nnodes - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    node.at(a).neighbors.push_back(b);
    node.at(b).neighbors.push_back(a);
  }
  long long result = 0;
  result += ncolors;
  node.at(0).is_visited = true;
  for (int nx : node.at(0).neighbors) {
    dfs(node, ncolors, result, nx, 0);
  }
  cout << result << '\n';

  return 0;
}


Measured memory_bytes: 11904
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}


int main() {
	//file();
	fast();
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct Range
{
	Range() {}
	Range(int top, int n) : top(top), n(n) {}
	pair<Range, Range> split(int num)
	{
		return make_pair(Range(top, num), Range(top + num, n - num));
	}
	int top, n;
};
queue<Range> pile;
Range a[500000], b[500000], c[500000];
int size;
int next(int& sum, int until_sum, Range* a)
{
	int j = 0;
	for (; sum < until_sum; )
	{
		if (sum + pile.front().n <= until_sum)
		{
			//a.push_back(pile[i]);
			a[j++] = pile.front();
			sum += pile.front().n;
			pile.pop();
		}
		else
		{
			pair<Range, Range> t = pile.front().split(until_sum - sum);
			//a.push_back(t.first);
			a[j++] = t.first;
			sum = until_sum;

			pile.front() = t.second;
			break;
		}
	}
	return j;
}
int main()
{
	int n, m, p, q, r;
	while (scanf("%d", &n), n)
	{
		scanf("%d%d%d%d", &m, &p, &q, &r);

		//pile.push_back(Range(1, n));
		pile = queue<Range>();
		pile.push(Range(1, n));
		while (m--)
		{
			int x, y;
			scanf("%d%d", &x, &y);

			int sum = 0;
			//next(pile, p, sum, x, a);
			//next(pile, p, sum, y, b);
			//for ( ; p < pile.size(); ++p)
			//	c.push_back(pile[p]);
			int a_size = next(sum, x, a);
			int b_size = next(sum, y, b);
			
			//pile.insert(pile.end(), all(b));
			//pile.insert(pile.end(), all(a));
			rep (i, b_size)
				pile.push(b[i]);
			rep (i, a_size)
				pile.push(a[i]);
		}


		int i = 0, sum = 0;
		//next(pile, i, sum, p - 1, a);
		//next(pile, i, sum, q, b);
		int a_size = next(sum, p - 1, a);
		int b_size = next(sum, q, b);

		int res = 0;
		rep (i, b_size)
			res += min(b[i].n, max(0, r - (b[i].top - 1)));
		
		printf("%d\n", res);
	}
}

Measured memory_bytes: 1068
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n = sc.nextInt();
    double min = Math.pow(10,10);
    double max = 0;
    for(int i=0; i<n; i++){
      double target = sc.nextInt();
      if(min > target){
         min = target;
      }
      if(max < target){
        max = target;
      }
    }
    System.out.println((int)(max - min) );
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,w=0,r=0,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W'){w++;}
        else if(s[i]=='R'){r++;}
    }
    for(int i=0;i<r;i++)
    {
        if(s[i]=='W'){ans++;}
    }
    cout<<ans;

}


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

using namespace std;

const string ord = "ABC";

int main() {
    int ball[] = {1, 0, 0};
    string s;
    while (cin >> s) {
        if (s == "A,B" || s == "B,A") swap(ball[0], ball[1]);
        if (s == "B,C" || s == "C,B") swap(ball[1], ball[2]);
        if (s == "C,A" || s == "A,C") swap(ball[2], ball[0]);
    }

    for (int i = 0; i < 3; i++)
        if (ball[i]) cout << ord[i] << endl;
    
    return 0;
}


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

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

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1147
{
    class Program
    {
        static void Main(string[] args)
        {
            string tmp = "";
            List<double> answer = new List<double>();
            while ((tmp = Console.ReadLine()) != "0")
            {
                int judges = int.Parse(tmp);
                int[] point = new int[judges];
                int[] pointCopy = new int[judges - 2];
                for (int i = 0; i < judges; i++)
                {
                    point[i] = int.Parse(Console.ReadLine());
                }
                Array.Sort(point);
                Array.Copy(point,1,pointCopy,0,pointCopy.Length);
                answer.Add(Math.Floor(pointCopy.Average()));
            }
            foreach (int item in answer)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 18360
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int M = Integer.parseInt(scan.next());

	Map<Integer, Node> nodes = new HashMap<Integer, Node>();
	nodes.put(1, new Node(0));
	for (int i = 2; i <= N; i++) {
	    nodes.put(i, new Node(N * 1000000000L));
	}

	List<Edge> edges = new ArrayList<Edge>(M);
	for (int i = 0; i < M; i++) {
	    int a = Integer.parseInt(scan.next());
	    int b = Integer.parseInt(scan.next());
	    long c = Long.parseLong(scan.next());

	    edges.add(new Edge(nodes.get(a), nodes.get(b), -c));
	}

	for (int i = 0; i < N-1; i++) {
	    for(Edge edge: edges) {
		Node s = edge.source;
		Node d = edge.destination;
		long tmp = s.distance + edge.weight;
		d.distance = tmp < d.distance ? tmp : d.distance;
	    }
	}
	String ans = String.valueOf(-nodes.get(N).distance);

	boolean[] negative = new boolean[N];
	for (int i = 0; i < N; i++) {
	    negative[i] = false;
	}

	for (int i = 0; i < N; i++) for(Edge edge: edges) {
	    Node s = edge.source;
	    Node d = edge.destination;
	    long tmp = s.distance + edge.weight;
	    if(tmp < d.distance) {
		d.distance = tmp;
		d.negative = true;
		break;
	    }

	    if(s.negative)
		d.negative = true;
	}
	ans = nodes.get(N).negative ? "inf" : ans;
	System.out.println(ans);
	scan.close();
    }
}

class Node {
    long distance;
    boolean negative = false;

    Node(long d) {
	distance = d;
    }
}

class Edge {
    Node source;
    Node destination;
    long weight;

    Edge(Node s, Node d, long w) {
	source = s;
	destination = d;
	weight = w;
    }
}


Measured memory_bytes: 28508
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for(int msk=0;msk< (1<<3);msk++){
    int sum = s[0] - '0';
    REP(i,3){
      if(msk & (1 << i)) sum+=s[i+1] - '0';
      else sum-=s[i+1] - '0';
    }
    if(sum == 7){
      cout << s[0];
      REP(i,3){
        if(msk & (1<<i)) cout << '+';
        else cout << '-';
        cout << s[i+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
flg = 'APPROVED'
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            flg = 'DENIED'
print(flg)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir[] = {"R", "D", "L", "U"};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[MAX_N], b[MAX_N]{};
    cin >> n;
    REP(i,n)cin >> a[i+1];
    int k = 1, cnt = 0;
    while(1){
        if(b[k]>0){
            cout << -1 << endl;
            break;
        }
        if(k==2){
            cout << cnt << endl;
            break;
        }
        b[k]++;
        cnt++;
        k = a[k];
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef double ld;

vector<pair<ll,ll>> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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

#define MAX_N 100010
#define MAX_H 310
#define MAX_W 310
struct edge{ll to,cost;};
bool x[MAX_N];
ll num[MAX_N];

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    
    return p;
}

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


vector<edge> G[MAX_N];
ll color[MAX_N];

bool dfs(ll v,ll p,ll c){
    color[v]=c;
    for (auto e: G[v]){
        if (e.to==p)continue;
        if (e.cost%2!=0)dfs(e.to,v,1-c);
        else dfs(e.to,v,c);
    }
    return true;
}

int main(){
    ll v;
    cin >> v;
    ll s,t,w;
    for (ll i=0;i<v-1;i++){
        cin >> s >> t >> w;
        s--;
        t--;
        G[s].push_back(edge{t,w});
        G[t].push_back(edge{s,w});
    }
    dfs(0LL,-1,1);
    for (ll i=0;i<v;i++){
        cout << color[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
#define ll double

int main()
{
    speed;

    string s;
    cin>>s;

    int ans=0;

    for(int i=0;i<s.size();i++) ans+=(s[i]-'0');

    if(ans%9==0) cout<<"Yes"<<"\n";

    else cout<<"No"<<"\n";
    
}

Measured memory_bytes: 3740
# -*- coding: utf-8 -*-
n = int(input())

tmp = 0
ans = 0
if n == 1:
    print(1)
    exit()
for i in range(1, n + 1):
    tmp2 = 0
    while True:
        if i % 2 == 1:
            break
        else:
            i /= 2
            tmp2 += 1
    if tmp2 > tmp:
        tmp = tmp2
        ans = i * pow(2, tmp2)
print(int(ans))

"""
count = []
for i in range(1,n + 1):
    count.append([0, i])

for i in range(n):
    tmp = 0
    while True:
        if count[i][1] == 2 ** tmp:
            count[i][0] = tmp
            break
        elif count[i][1] > 2 ** tmp:
            tmp += 1
        else:
            break

count.sort()
print(count[n - 1][1])
"""

Measured memory_bytes: 3064
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ts <- getInts
  vs <- getInts
  let ts' = makets $ map fromIntegral ts 
      vs' = makevs $ map fromIntegral vs
      fs = makeFun ts' vs'
      t = fst $ last ts'
  print $ solve t fs

getInts :: IO [Int]
getInts = map read . words <$> getLine

makevs :: [Float] -> [Float]
makevs vs = 0 : vs ++ [0]

makets :: [Float] -> [(Float, Float)]
makets ts = (0, 0) : (zip ts' $ drop 1 ts' ++ [last ts'])
  where
    ts' = scanl (+) 0 ts

makeFun :: [(Float, Float)] -> [Float] -> [Float -> Float]
makeFun ts vs = zipWith (curry f) ts vs
  where
    f ((l, r), v) x
      | 0 <= x && x <= l = v + (l - x)
      | l <= x && x <= r = v
      | otherwise = v + (x - r)
 
solve :: Float -> [Float -> Float] -> Float
solve t fs = sum $ map f [0, 0.5..t-0.5]
  where
    f t' = --trace (unwords (map show ((app t') : [app (t' + 0.5)]))) $
      area (app t') (app (t' + 0.5))
    app x = minimum $ map (\g -> g x) fs
    area x y = 0.25 * (x + y)



Measured memory_bytes: 1916
try: 
    N = int(input())
except:
    exit()
def main(n, var):
    mylist = []
    dupliN = n
    for i in range(2, int(-(-n**0.5//var))+var):
        if dupliN%i==0:
            cnt=0
            while dupliN%i==0:
                cnt+=var
                dupliN //= i
            mylist.append([i, cnt])
 
    if dupliN!=1:
        mylist.append([dupliN, 1])
    if mylist==[]:
        mylist.append([n, 1])
    return mylist
if N == 1:
    print(0)
    exit()
f = main(N, 1)
ansval = 0
for extra, value in f:
    num = 1
    while True:
        value -= num
        if value < 0:
            break
        ansval += 1
        num += 1 
print(ansval)

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    sort(L.begin(),L.end());
    int M = L[N-1];
    int S = 0;
    for(int i = 0; i < N-1; i++) S += L[i];
    if(S > M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define getchar_unlocked getchar
int ri() {
	int r=0, c, s=0;
	for(;;){c=getchar_unlocked();if(c=='-'){s=1;break;}if(c<='9'&&c>='0'){r=c-'0';break;}}
	for(;;){c=getchar_unlocked();if(c<'0'||c>'9')break;r=r*10+c-'0';}
	if(s)r=-r;
	return r;
}
char buf[3000000];
char *ptr = buf;
void wi(int n) {
	static char tmp[12];
	char *cur = tmp + 11;
	if (n) {
		while (n) {
			*--cur = n % 10 + '0';
			n /= 10;
		}
	} else *--cur = '0';
	while (*cur) *ptr++ = *cur++;
	*ptr++ = ' ';
}

int main() {
	int n;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int max = 0, x = 0;
	for (int i = 0; i < n; i++) if (max < a[i]) max = a[i], x = 1; else if (max == a[i]) x++;
	int max2 = 0;
	for (int i = 0; i < n; i++) if (a[i] != max && max2 < a[i]) max2 = a[i];
	for (int i = 0; i < n; i++) {
		if (x == 1 && a[i] == max) wi(max2);
		else wi(max);
	}
	fwrite(buf, 1, ptr - buf, stdout);
	return 0;
}


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

int top, S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a, b, x, no, np;
  top = 0;
  char s[100];
  no = np = 0;
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
      no++;
    } else if ( s[0] == '-' ){
      b = pop();
      a = pop();
      push(a - b);
      no++;
    } else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
      no++;
    } else {
      x = atoi(s);
      assert(0 <= x && x <= 1000000);
      push(x);
      np++;
    }
  }
  assert(2 <= np && np <= 100);
  assert(1 <= no && no <= 99);

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

  return 0;
}

Measured memory_bytes: 0
//
//  main.cpp
//  codechef
//
//  Created by Krishnam Srivastava on 08/02/20.
//  Copyright © 2020 Krishnam Srivastava. All rights reserved.


#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<string>
#include<climits>
#include<cmath>
#include<iomanip>
#include<unordered_map>
#include<set>
//#include<utility>
#define MAX 2147483647
typedef long long int lli;
using namespace std;

int main(){
    int x,y;
    cin>>x>>y;
    if(y%2!=0)cout<<"No"<<"\n";
    else{
        if((y>4*x)||(y<2*x))cout<<"No"<<"\n";
        else{
            cout<<"Yes"<<"\n";
        }
    }
}


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

int main(int, char**)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int t = (c+b-1) / b;
    int s = (a+d-1) / d;
    if (s >= t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main(){
    int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y;
    cin >> x >>y;
    cout << (a[x]==a[y] ? "Yes":"No") << endl;
}


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

int main() {
  int N,Z=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
      Z++;
    }
  }
  cout<<Z<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  i64 n,k;
  std::cin>>n>>k;

  std::vector<i64> a(n);
  for(auto&& e:a)std::cin>>e;

  i64 left=0,right=0;

  rep(i,0,n)chmax(right,a[i]);

  right++;

  while(right-left>1){
    i64 mid=(left+right)>>1;
    i64 cnt=0;
    rep(i,0,n)cnt+=(a[i]+mid-1)/mid -1;
    if(cnt<=k)right=mid;
    else left=mid;
  }

  std::cout<<right<<"\n";
  
  return 0;
}

Measured memory_bytes: 4712
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
//vector
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pp pop_back
//pair
#define pi pair<int ,int >
#define mk make_pair
#define ff first
#define ss second
//set
#define si set<int>
#define sit set<int>::iterator 
using namespace std;
int main()
{
	/*
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
	#endif
	*/
fast;
string a,b;cin>>a>>b;
int t=b.size();
int ans=INT_MAX;
fr(i,0,a.size())
{
	if(i+t<=a.size())
	{
		int k=0,cnt=0;
		fr(j,i,i+t)
		{
			if(b[k]==a[j]) cnt++;
			k++;
		}
		ans=min(t-cnt,ans);
	}
}
cout<<ans;

return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
double calcAngle(double h, double m) {
    if (h == 12) h = 0;
    if (m == 60) m = 0;
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;
    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
    return angle;
}
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double angel_c = calcAngle(h, m) * pi / 180;
    double c = sqrt(a * a + b * b - ((2 * a * b) * cos(angel_c)));
    cout << fixed;
    cout << setprecision(12);
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 4248
n = int(input())

a = list(map(int,input().split()))

b = list(map(int,input().split()))

c = list(map(int,input().split()))

ans = 0

for i in range(n):
    ans += b[a[i]-1]
    if i>0 and a[i]-a[i-1] == 1 :
        ans += c[a[i-1]-1]

print(ans)


Measured memory_bytes: 9192
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()

ans = 0
for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			b1 = a[i]!=a[j] and a[j]!=a[k] and a[k]!=a[i]
			b2 = a[i]+a[j]>a[k] and a[j]+a[k]>a[i] and a[k]+a[i]>a[j]
			if b1 and b2:
				ans+=1

print(ans)

Measured memory_bytes: 9492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int s[2020][2020];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    if(b-a>=2019){
      cout<<0<<endl;
      return 0;
    }
    for(int i=1;i<=2019;i++)for(int j=1;j<=2019;j++){
      s[i][j]=i*j%2019;
      if(i==j)s[i][j]=2020;
    }
    a%=2019;
    b%=2019;
    int mini=2020*2020;
    for(int i=a;i<=b;i++)for(int j=a;j<=b;j++)if(s[i][j]<mini) mini=s[i][j];
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e6+10 ;
const int mod = 1e9+7 ;
vl g[N];
vl vis(N,0);
// vl compute(string s){
//         vl has(s.length());
//         ll i;

//         for(i=0;i<s.length();i++){
//             if(i==0){
//                 has[i]=((s[i]-'a'+1))%mod;
//             }
//             else
//                 has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
//         }
//         return has;
// }
ll dfs(ll x){
  // cout << x << endl;
    vis[x]=1;
    ll c=1;
    for(auto &it:g[x]){
      if(!vis[it])
        c+=dfs(it);
    }
    return c;
 }

ll po(ll a,ll x,ll m){
    if(x==0)
      return 1;
    if(x==1)
      return a%m;
    ll z=po(a,x/2,m)%m;
    if(x&1)
      return (((z%m)*(z%m))%m*(a%m))%m;
    return (((z%m)*(z%m))%m)%m;
}
int main(){
 ios_base::sync_with_stdio(0);
 ll i,n,s=0,j;
 cin >> n;
 s=n;
 if(n%2==0)
  s++;
 vll ans;
 for(i=1;i<=n;i++){
   for(j=i+1;j<=n;j++){
      if(i+j==s)
        continue;
      ans.eb(i,j);
   }
 }
 
 cout << ans.size() << endl;
 for(i=0;i<ans.size();i++)
  cout << ans[i].first << " " << ans[i].second << "\n"; 
 return 0;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;


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

  while (cases--) {
    int M, Y, N; cin >> M >> Y >> N;
    int ans = 0;
    rep(i, N) {
      int T, F;
      double R;
      cin >> T >> R >> F;

      int unyo = M, rishi = 0;
      rep(j, Y) {
        int t = unyo * R;
        if (T) unyo += t;
        else rishi += t;
        unyo -= F;
      }

      ans = max(ans, unyo + rishi);
    }

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

Measured memory_bytes: 1232
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author otsuhata
 */
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        //System.out.println("???H * ?¨?W ?????§???????????????????????????????????°????????§??????");
        //System.out.println("H??¨W?????????3??????300?????????????????\????????????????????????");
        
        for(int i = 0; i < 3000; i ++) {
            //System.out.print("??????????§????????????????????????§??\?????????????????????(0 0??§???????????????):");
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            
            if(printJudge(m,f,r)) {
                printGrade(m,f,r);
            }else {
                //System.out.println("##### GAME OVER #####");
                break;
            }            
            //printUpBtm(W);
            
            //System.out.print("\n");
        }
    }    

    public static void printGrade(int m, int f, int r) { 
        if(m == -1 || f == -1) {
            System.out.println("F");
        }else if((m + f) >= 80) {
            System.out.println("A");
        }else if((m + f) >= 65) {
            System.out.println("B");
        }else if((m + f) >= 50) {
            System.out.println("C");
        }else if((m + f) >= 30) {
            if(r >= 50) {
                System.out.println("C");
            }else {
                System.out.println("D");
            }            
        }else {
            System.out.println("F");
        }           
    }
    
     public static void printUpBtm(int W) {  
	for(int i = 0; i < W; i++) {
		System.out.print("#");                
	}
        System.out.print("\n");    
    }
    
    
    public static boolean printJudge(int m, int f, int r) {
        if((50 < m ||  50 < f || 100 < r)) {
            return false;
        }else if(m == -1 && f == -1 && r == -1) {
            return false;
        }else {
            return true;
        }
    }    
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    vector<pair<string, ll>> p(N);
    rep(i, N) {
        string str;
        ll tmp;
        cin >> str >> tmp;
        p[i] = pair<string, ll>(str, tmp);
    }
    string X;
    cin >> X;
    ll cnt = 0;
    bool flag = false;
    rep(i, N) {
        if (flag) {
            cnt += p[i].second;
        }
        if (X == p[i].first) {
            flag = true;
        } 
    }
    print(cnt);
    return 0;
}

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

int N;
vector<int> A;

bool feasible() {
    bool ok = true;
    ok &= A[0] == 0;
    for (int i = 1; i < N; i++) {
        ok &= A[i] <= A[i-1] + 1;
    }
    return ok;
}

long long min_ops() {
    long long result = 0;
    vector<bool> covered(N);
    for (int i = N-1; i >= 0; i--) {
        const int start = i - A[i];
        if (!covered[start]) {
            result += A[i];
        }
        covered[start] = true;
    }
    return result;
}

int main() {
    cin >> N;
    A.resize(N);
    for (int& x : A) {
        cin >> x;
    }

    if (!feasible()) {
        cout << -1 << endl;
    } else {
        cout << min_ops() << endl;
    }
}


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

using namespace std;
int n;
const int maxn = 100000 + 1;
int main()
{
	cin >> n;
	long long int a[3 * n];
    for(int i = 0; i < 3 * n; i++){
        cin >> a[i];
    }
    long long int x = 3 * n - 2;
    long long int ans = 0;
    sort(a, a + (3 * n));
    for(int i = 0; i < n; i++){
        ans += a[x];
        x -= 2;
    }
 
    cout << ans << endl;
}


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

int main(){
    long long n;
    cin>>n;
    long long a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int co=0;
    for (int i=0; i<n; i++){
        while(a[i]%2==0 & a[i]>0){
            a[i]/=2;
            co++;
        }
    }
    cout<<co<<endl;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    int MIN = INF;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        MIN = min(MIN, a[i]);
        a[i] -= MIN;
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] == a[0])
            ans++;
        else
            break;
    }
    cout << ans << endl;
}

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

#define MAX_N 101000
#define SWAP( a, b ) do { int tmp; tmp = a; a = b; b = tmp; } while( 0 )

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 };

void insertionSort( int *, int );
void quickSort( int *, int );
void quickSort_body( int *, int, int );
int median( int, int, int );

int main( void ) {
	int i, j, N, P, cnt, p[ 22 ], sum[ 253 ];

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d", &N, &P ), N != -1; printf( "%d\n", sum[ P - 1 ] ) ) {
		cnt = 0;
		for ( i = N + 1; cnt < 22; i++ )
			if ( isPrime[ i ] )
				p[ cnt++ ] = i;

		cnt = 0;
		for ( i = 0; i < 22; i++ )
			for ( j = i; j < 22; j++ )
				sum[ cnt++ ] = p[ i ] + p[ j ];

		quickSort( sum, 222 );
	}

	return 0;
}

void insertionSort( int *data, int n ) {
	int i, j, tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ] > tmp ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];

				j--;
			} while ( j && data[ j - 1 ] > tmp );

			data[ j ] = tmp;
		}
	}
}

void quickSort( int *data, int n ) {
	quickSort_body( data, 0, n - 1 );
}

void quickSort_body( int *data, int l, int r ) {
	if ( l < r ) {
		int i = l, j = r, pivot = median( data[ i ], data[ ( i + j ) / 2 ], data[ j ] );

		while ( 1 ) {
			for ( ; data[ i ] < pivot; i++ ) ;
			for ( ; pivot < data [ j ]; j-- ) ;
			if ( i >= j )
				break;

			SWAP( data[ i ], data[ j ] );

			i++;
			j--;
		}

		if ( i - l < 20 )
			insertionSort( data + l, i - l );
		else
			quickSort_body( data, l, i - 1 );

		if ( r - j < 20 )
			insertionSort( data + j + 1, r - j );
		else
			quickSort_body( data, j + 1, r );
	}
}

int median( int x, int y, int z ) {
	if ( x < y )
		if ( y < z )
			return y;
		else if ( z < x )
			return x;
		else
			return z;
	else if ( z < y )
		return y;
	else if ( x < z )
		return x;
	else
		return z;
}

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

int main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  if (N >= M) {
    cout << 0 << endl;
  }
  else {
    vector<int> X(M);
    for (int i = 0; i < M; i++) cin >> X.at(i);
    sort(X.begin(), X.end());

    vector<int> Y(M - 1);
    for (int i = 0; i < M - 1; i++) Y.at(i) = X.at(i + 1) - X.at(i);
    sort(Y.begin(), Y.end());

    int ans = 0;
    for (int i = 0; i < M - N; i++) ans += Y.at(i);

    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
n = gets.chomp.to_i
my_cards = {S:(1..13).to_a, H:(1..13).to_a, C:(1..13).to_a,D:(1..13).to_a}

n.times do
    card_case, number = gets.chomp.split
    case card_case
    when "S"
        my_cards[:S] -= [(number.to_i)]
    when "H"
        my_cards[:H] -= [(number.to_i)]
    when "C"
        my_cards[:C] -= [(number.to_i)]
    when "D"
        my_cards[:D] -= [(number.to_i)]
    end
end

my_cards[:S].each do |i|
    puts "S #{i}"
end
my_cards[:H].each do |i|
    puts "H #{i}"
end
my_cards[:C].each do |i|
    puts "C #{i}"
end
my_cards[:D].each do |i|
    puts "D #{i}"
end

Measured memory_bytes: 8656
import java.util.*;
public class Main {
	//模範解答の理解度確認
	static int[][] seat;
	static int[][] hate;
	//前後左右のやり方も今後パクる
	static int[] x = {1, 0, -1, 0};
	static int[] y = {0, 1, 0, -1};

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String[] lineString = sc.nextLine().split(" ");
		int n = Integer.parseInt(lineString[0]);
		seat = new int[n][n];
		hate = new int[n][n];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				seat[i][j] = 1;
				hate[i][j] = Math.min(Math.min(i, j), Math.min(n - i - 1, n - j - 1));
			}
		}

		lineString = sc.nextLine().split(" ");
		int hateCount = 0;
		for (int i = 0; i < n * n; i++) {
			int number = Integer.parseInt(lineString[i]) - 1;
			int row = number / n;
			int column = number % n;

			hateCount += hate[row][column];
			seat[row][column] = 0;

			hateCalc(row, column);
		}

		// 出力
		System.out.println(hateCount);
		sc.close();
	}

	static void hateCalc(int currentRow, int currentColumn) {
		int currentHate = hate[currentRow][currentColumn] + seat[currentRow][currentColumn];	//他からこの座標に来たときの、ここからのhateカウント。

		for (int i = 0; i < 4; i++) {
			try {
				if (hate[currentRow + y[i]][currentColumn + x[i]] > currentHate) {
					//自分を通ることで、隣のhateが減る場合は、そちらを採用。
					hate[currentRow + y[i]][currentColumn + x[i]] = currentHate;
					//hateが変動した席も再計算。
					hateCalc(currentRow + y[i], currentColumn + x[i]);	//
				}
			} catch (ArrayIndexOutOfBoundsException e) {
				//配列外の探索はしない。
			}
		}
	}
}


Measured memory_bytes: 85128
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val input = StdIn.readInt()
    val h = input / 3600
    val m = (input%3600)/60
    val s = (input%3600)%60
    println(s"${h}:${m}:${s}")
  }
}


Measured memory_bytes: 43692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int k;
  int a, b, c;
  cin >> a >> b >> c >> k;
  while(a>=b){
    b *= 2;
    k--;
    if(k==0){
      break;
    }
  }
  while(b>=c&&k>=1){
    c *= 2;
    k--;
  }
  if(a<b&&b<c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
    int N, K, S = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x < K - x)
        {
            S += x * 2;
        }
        else
        {
            S += (K - x) * 2;
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    map<int,ll> mp;
    vector<ll> r;
    rep(i,N){
        ll b;
        cin >> b;
        mp[b]++;
        if(mp[b]==1)r.push_back(b);
    }
    sort(All(r));
    if(mp.size()>3){
        cout << "No" << endl;
    }else if(mp.size()==1){
        if(r[0]==0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }else if(mp.size()==2){
        if(r[0]==0&&2*mp[r[0]]==mp[r[1]])cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        if((r[0]^r[1])==r[2]&&mp[r[0]]==mp[r[1]]&&mp[r[1]]==mp[r[2]])cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 10000000000
#define P pair<int,int>
int n,s,ans;
int x[200000],dis[200000];
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
signed main(){
    cin>>n>>s;
    rep(i,n){
        cin>>x[i];
        dis[i]=abs(s-x[i]);
    }
    ans=abs(s-x[0]);
    if(n!=1){
        rep(i,n){
            ans=gcd(ans,abs(s-x[i]));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
/*input
10 5
4 7 10 6 5
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int x, n; cin >> x >> n;
	vector<int> p(n);
	bool seen[105];
	memset(seen, false, sizeof(seen));
	for(int i = 0; i < n; i++) {
		cin >> p[i];
		seen[p[i]] = true;
	}
	int lo = x;
	while(seen[lo]) lo--;
	int hi = x;
	while(seen[hi]) hi++;
	if(hi - x < x - lo) {
		cout << hi << endl;
	}
	else {
		cout << lo << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
# coding: utf-8
import itertools

(H, W, K) = map(int, input().split(' '))
table = []
for _ in range(H):
    table.append(input())

def count_black(table):
    count = 0
    for line in table:
        for s in line:
            if s == "#":
                count += 1
    return count


def paint_col(table, col_index):
    for index, line in enumerate(table):
        table[index] = line[:col_index] + "." + line[col_index + 1:]


def paint_row(table, row_index):
    table[row_index] = "." * len(table[row_index])


def bin_tuple_to_index_tuple(bin_tup):
    res = []
    for idx, v in enumerate(bin_tup):
        if v == 1:
            res.append(idx)
    return res


result = 0
for row in itertools.product([0, 1], repeat=H):
    row_tup = bin_tuple_to_index_tuple(row)
    table_tmp = table.copy()
    for r in row_tup:
        paint_row(table_tmp, r)
    for col in itertools.product([0, 1], repeat=W):
        table_tmp_t = table_tmp.copy()
        col_tup = bin_tuple_to_index_tuple(col)
        for c in col_tup:
            paint_col(table_tmp_t, c)
        if count_black(table_tmp_t) == K:
            result += 1

print(result)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    long long x=0;
    for(int i=0;i<n;i++){
        x+=(lower_bound(a,a+n,b[i])-a)*(n-(upper_bound(c,c+n,b[i])-c));
    }
    cout<<x<<endl;
    return 0;
}

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

#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int Maxn  =  2019;
const ld  pi   =  acos(-1);
const int mod =  1000000007;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}


int32_t main(){ IOS
    int n;  cin>>n;
    n = powr((int)2,floor(log2(n)));
    int ans =  2*n-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();

		int d = 0;
		long x = 1;
		while (x <= k) {
			d++;
			x = x << 1;
		}

		long answer = 0;
		int[] ones = new int[d + 1];
		for (int i = 0; i < n; i++) {
			long a = sc.nextLong();
			answer += a;

			int j = 0;
			while (a > 0 && j <= d) {
				ones[j++] += a % 2;
				a /= 2;
			}
		}

		long[] delta = new long[d + 1];
		for (int i = 0; i <= d; i++) {
			delta[i] = (n - 2L * ones[i]) << i;
		}

		long[][] dp = new long[d + 1][2];
		dp[d][1] = answer;

		for (int i = d; i > 0; i--) {
			dp[i - 1][1] = dp[i][1];
			if (dp[i][0] > 0) dp[i - 1][0] = Math.max(
					dp[i][0], dp[i][0] + delta[i - 1]);

			if (((k >> (i - 1)) & 1) == 1) {
				dp[i - 1][0] = Math.max(dp[i - 1][0], dp[i][1]);
				dp[i - 1][1] += delta[i - 1];
			}
		}

		System.out.println(Math.max(dp[0][0], dp[0][1]));
	}
}


Measured memory_bytes: 48016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve(){
    ll x,y;cin>>x>>y;
    cout<<gcd(x,y)<<endl;
}

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



Measured memory_bytes: 3208