akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;

namespace PaizaSkillCheck
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');

            int n = int.Parse(line[0]);
            long k = long.Parse(line[1]);

            //  BIT
            long[] bit = new long[63];
            for (int i = 0; i < bit.Length; i++)
            {
                bit[i] = (long)Math.Pow(2, i);
            }

            //  二進数において出てきたその桁の数
            int[] count_digits = new int[64];

            line = Console.ReadLine().Split(' ');
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
            {
                long v = long.Parse(line[i]);
                a[i] = v; 

                for (int j = 0; j < 63; j++)
                {
                    if ((v & bit[j]) == bit[j])
                    {
                        count_digits[j]++;
                    }
                }
            }


            int digits = (int)Math.Log(k, 2) + 1;

            int h = n / 2;
            long x = 0;

            for (int i = (digits - 1); i >= 0; i--)
            {
                if(count_digits[i] <= h)
                {
                    long v = x + bit[i];

                    if(v <= k)
                    {
                        x = v;
                    }
                }
            }

            long sum = 0;
            for (int i = 0; i < a.Length; i++)
            {
                sum += x ^ a[i];
            }

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }

}


Measured memory_bytes: 32348
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  cout << (1000 - (N % 1000)) % 1000 << endl;
}


Measured memory_bytes: 3640
import sys
import heapq as h

inf = sys.maxsize

class heapq:
    def __init__(self):
        self.q = []

    def push(self,v):
        h.heappush(self.q, v)
    
    def pop(self):
        return h.heappop(self.q)

    def is_empty(self):
        return len(self.q) == 0

# 入力:graphと始点s
# 出力:始点sから各頂点tへの距離dist
def shortestPath0(graph, s):
    n = len(graph)

    dist    = [inf for _ in range(n)]
    visited = [False for _ in range(n)]
    dist[s] = 0

    while True:
        idx, u  = -1, inf
        for i in range(n):
            if not visited[i] and dist[i] < u:
                idx = i
                u = dist[i]
        
        if u == inf: break
        
        visited[idx] = True

        for (next, w) in graph[idx]:
            newdist = w + dist[idx]
            if newdist < dist[next]:
                dist[next] = newdist
    return dist

def shortestPath1(graph, s):
    n = len(graph)

    dist    = [inf for _ in range(n)]
    visited = [False for _ in range(n)]
    
    q = heapq()
    q.push((0, s))

    while not q.is_empty():
        (cur_dist, v) = q.pop()

        if visited[v] or dist[v] <= cur_dist:
            continue

        dist[v] = cur_dist
        visited[v] = True

        for next, w in graph[v]:
            if not visited[next] and dist[v] + w < dist[next]:
                q.push((dist[v] + w, next))

    return dist

def main():
    v, e, s = map(int, input().split())
    
    # 隣接リスト
    graph = [[] for _ in range(v)]
    
    for i in range(e):
        a, b, cost = map(int, input().split())
        graph[a].append((b, cost))
            
    c_dist = shortestPath1(graph, s)
            
    for d in c_dist:
        if d == inf:
            print("INF")
        else:
            print(d)
main()

Measured memory_bytes: 107780
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
map<int,int> m;
string s;
int msk,bst,x,j,i,t;
int main()
{
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        x=s[i]-'a';
        msk^=(1<<x);bst=(1<<30);
        for(j=0;j<26;j++)
        {
            t=(msk^(1<<j));
            if(m[t]||t==0)
                bst=min(bst,m[t]+1);
        }
        t=msk;
        if(m[t]||t==0)
            bst=min(bst,m[t]+1);
        m[msk]=min(bst,m[msk]);
        if((!m[msk])&&msk!=0)
            m[msk]=bst;
    }
    cout<<bst;
    return 0;
}


Measured memory_bytes: 204292
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
//typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
# define EPS 1e-9
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (ll)1e10
# define maxn 200005
# define offset 2000005
#define N 100005
const ld eps = 1e-10L;

/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){

        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;    
	}
};

**************************************************/

int leaf;
vector<int>g[maxn];
int n;
int dp[maxn][2];

ll solve(int x,int p,int f)
{
	if(dp[x][f]!=-1)
		return dp[x][f];
	ll ans=1;
	for(int i=0;i<g[x].size();i++)
	{
		int y=g[x][i];
		if(y==p)
			continue;
		if(f)
			ans*=solve(y,x,0);
		else
		{
			ans*=(solve(y,x,1)+solve(y,x,0));
		}
		ans%=mod;
	}
	ans%=mod;
	return dp[x][f]=ans;
}


int main()
{
	cin >> n;
	int x,y;
	for(int i=1;i<n;i++)
	{
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	memset(dp,-1,sizeof dp);
	int ans=solve(1,1,0)+solve(1,1,1);
	ans%=mod;
	cout << ans;
}

Measured memory_bytes: 17920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt(); //????????§???????????\???
		int b = scan.nextInt(); //????????§???????????\???

		int d = a / b;
		int r = a % b;
		double A = a;
		double B = b;
		double f = A / B;

		System.out.println(d +  " " + r + " " + String.format("%.5f", f));
	}
}

Measured memory_bytes: 26396
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	a, b, k := r.nextInt(), r.nextInt(), r.nextInt()

	for {
		a -= k
		if a < 0 {
			k = -a
			a = 0
		} else {
			break
		}
		b -= k
		if b < 0 {
			k = -b
			b = 0
		} else {
			break
		}
		break
	}
	fmt.Fprintln(stdout, a, b)
}


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

int main(void) {
    int n, m, sum = 0, cnt = 0;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; i++) {
        if (4 * a[i] * m >= sum) cnt++;
    }
    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

#define MOD 1000000007

int main(void) {
    ll N, K;
    ll A = 0, B = 0;
    cin >> N >> K;
    for(ll i = 0;i < N;i++) {
        ll x;
        ll a, b;
        cin >> x;
        a = x; b = K - x;
        if(a < b) A += 2 * a;
        else B += 2 * b;
    }
    cout << A + B << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if ((int)((double)i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
cfs = [list(map(int, readline().split())) for i in range(n - 1)]
for i in range(n - 1):
    cnt = 0
    for j in range(i, n - 1):
        if cnt < cfs[j][1]:
            cnt = cfs[j][1]
        elif cnt % cfs[j][2] == 0:
            pass
        else:
            cnt += cfs[j][2] - (cnt % cfs[j][2])
        cnt += cfs[j][0]
    print(cnt)
print(0)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int count=0;
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i<n/2;i++)
	{
		if(s[i]!=s[n-i-1])
		{
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int a,b,c,d;
scanf("%d %d %d",&a,&b,&c);
if(a>b) d=a,a=b,b=d;
if(b>c) d=b,b=c,c=d;
if(a>b) d=a,a=b,b=d;
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
#define INFTY 1000000000000000000

LL labs(LL x){
    if(x>0){
        return x;
    }else{
        return -1*x;
    }
}

int main(){
    LL n;
    cin >> n;
    vector<LL> h(n);
    vector<LL> dp(n, INFTY);

    for(LL i=0; i<n; i++){
        cin >> h[i];
    }

    dp[0]=0;
    for(LL i=0; i<n-1; i++){
        dp[i+1]=min(dp[i+1], dp[i]+labs(h[i+1]-h[i]));
        if(i<n-2){
            dp[i+2]=min(dp[i+2], dp[i]+labs(h[i+2]-h[i]));
        }
    }

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

    return 0;
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 9e17
ll dp[101][100001];


ll min(ll x,ll y)
{
	return x<y?x:y;
}
ll max(ll x,ll y)
{
	return x>y?x:y;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
	ll n,wt;
	cin>>n>>wt;
	ll w[n+1],v[n+1];

	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];

	for(int i=0;i<101;i++)
	{
		for(int j=0;j<100001;j++)
		{
			if(j==0)
				dp[i][j]=0;
			else
				dp[i][j]=mx;
		}
	}

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

	ll ans=0;
	for(int j=0;j<100001;j++)
	{
		if(dp[n][j]<=wt)
		{
			ans=j;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i]=='?'){
      s[i]='D';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3852
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	string s;
	cin >> s;
	string y = s.substr(0, 4),m=s.substr(5,2);
	int yy=atoi(y.c_str()), mm=atoi(m.c_str());
	if (yy < 2020 && mm < 5) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin >> s >> t;
	int ret=0;
	for (int i=0; i<3; i++)
		if (s[i]==t[i])
			ret++;
	cout << ret << endl;
	return 0;
}


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

int main() {
  string N;
  cin >> N;
  if( N[0] == N[1] && N[0] == N[2]){
    cout << "Yes" << endl;
  }
  else if( N[1] == N[2] && N[1] == N[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  ll n;
  cin>>n;
  if(n%2==0)
    cout<<n<<endl;
  else
    cout<<2*n<<endl;



  return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e6) + 17;

int n;
ll X;
ll x[MAXN], sumx[MAXN];

bool read() {
    if (!(cin >> n >> X))
        return false;

    forn (i, n)
        cin >> x[i + 1];

    return true;
}

void solve() {
    forn (i, n)
        sumx[i + 1] = sumx[i] + x[i + 1];

    __int128_t ans = LINF;

    for (int k = 1; k <= n; ++k) {
        __int128_t res = X * k + 2ll * (sumx[n] - sumx[n - k]), t = 2;

        for (int i = n; i > 0; i -= k, ++t)
            res += (sumx[i] - sumx[max(i - k, 0)]) * (2 * t - 1);

        ans = min(ans, res);
    }

    cout << X * n + (ll) ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int>> s(h,vector<int>(w));
    vector<vector<int>> ans(h,vector<int>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char buf;
            cin >> buf;
            if(buf == '#'){
                s.at(i).at(j) = 1;
            }else{
                s.at(i).at(j) = 0;
            }
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i == 0 && j == 0){
                ans.at(i).at(j) = s.at(i).at(j);
            }else if(i == 0 && j != 0){
                ans.at(i).at(j) = ans.at(i).at(j-1);
                if(s.at(i).at(j) == 1 && s.at(i).at(j-1) == 0)ans.at(i).at(j)++;
            }else if(i != 0 && j == 0){
                ans.at(i).at(j) = ans.at(i-1).at(j);
                if(s.at(i).at(j) == 1 && s.at(i-1).at(j) == 0)ans.at(i).at(j)++;
            }else{
                int buf1 = ans.at(i-1).at(j);
                int buf2 = ans.at(i).at(j-1);
                if(s.at(i).at(j) == 1 && s.at(i-1).at(j) == 0)buf1++;
                if(s.at(i).at(j) == 1 && s.at(i).at(j-1) == 0)buf2++;
                ans.at(i).at(j) = min(buf1,buf2);
            }
        }
    }
    /*for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans.at(i).at(j);
        }
        cout << endl;
    }*/
    cout << ans.at(h-1).at(w-1) << endl;
}


Measured memory_bytes: 384
from heapq import heapify, heappush as hpush, heappop as hpop
N, M, S = map(int, input().split())
k = 2451
X = [[] for _ in range(N * k)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u-1, v-1
    for i in range(a, k):
        X[u * k + i].append([v * k + i - a, b])
        X[v * k + i].append([u * k + i - a, b])

for i in range(N):
    c, d = map(int, input().split())
    for j in range(k - 1):
        X[i * k + j].append([i * k + min(j + c, k - 1), d])

def dijkstra(n, E, i0=0):
    h = [[0, i0]]
    D = [-1] * n
    done = [0] * n
    D[i0] = 0
    
    while h:
        d, i = hpop(h)
        done[i] = 1
        for j, w in E[i]:
            nd = d + w
            if D[j] < 0 or D[j] > nd:
                if done[j] == 0:
                    hpush(h, [nd, j])
                    D[j] = nd
    return D

D = dijkstra(N * k, X, min(S, k - 1))
print(*[min(D[i * k:(i+1) * k]) for i in range(N)][1:], sep = "\n")

Measured memory_bytes: 105360
num = gets.to_i
arr = gets.split.map(&:to_i)
cor = 1
ans = 0
arr2 =arr.sort
if arr2[0] == 1
	num.times do |i|
		if arr[i] == cor
			cor += 1
		else
			ans += 1
		end
	end
	p ans
else
	p -1
end

Measured memory_bytes: 18544
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {

   int N;
   cin >> N;

   vector<pair<pair<string, int>, int>> a(N);
   for (int i = 0; i < N; ++i) {
      string s;
      int p;
      cin >> s >> p;
      a[i] = make_pair(make_pair(s, -p), i + 1);
   }

   sort(a.begin(), a.end());
   for (int i = 0; i < N; ++i) {
      int n = a[i].second;
      cout << n << endl;
   }


   return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [[] for i in range(N)]
for i in range(N):
    n = int(input())
    for _ in range(n):
        x, y = map(int, input().split())
        A[i].append((x - 1, y))

ans = 0
for i in range(1 << N):
    ok = True
    cnt = 0
    for j in range(N):
        if (i >> j & 1) == 1:
            cnt += 1
    for j in range(N):
        if (i >> j & 1) == 1:
            for x, y in A[j]:
                if y == 0:
                    if (i >> x & 1) == 1:
                        ok = False
                elif y == 1:
                    if (i >> x & 1) == 0:
                        ok = False
    if ok:
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 44252
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S;
  int64_t K;
  cin >> S >> K;
  constexpr int64_t kNum = 'z' - 'a' + 1;
  const int64_t L = static_cast<int64_t>(S.length());

  string result = S;

  for (int64_t i = 0; i < L; ++i) {
    const char ch = S.c_str()[i];
    if (ch == 'a') {
      continue;
    }
    const int64_t d = kNum - static_cast<int64_t>(ch - 'a');
    if (K < d) {
      continue;
    }
    K -= d;
    result[i] = 'a';
  }

  K = K % kNum;

  result[L - 1] += K;

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

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

	int n;
	cin >> n;
	vector<int> a(n);
	map<ll, ll> mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	ll res = 0;
	for (auto m : mp) {
		res += m.second * (m.second - 1) / 2;
	}
	rep(i, n) {
		ll k = mp[a[i]];
		ll before = k * (k - 1) / 2;
		ll after = (k - 1) * (k - 2) / 2;
		out(res + after - before);
	}

	return 0;
}

Measured memory_bytes: 11896
import Control.Applicative
import Control.Monad
main = do
    [h, w] <- (map read . words) <$> getLine
    printAFrame h w

printAFrame :: Int -> Int -> IO()
printAFrame 0 0 = putStr ""
printAFrame h w = do
    putStrLn $ replicate w '#'
    replicateM_ (h - 2) $ do
        putStrLn $ "#" ++ (replicate (w - 2) '.') ++ "#"
    putStrLn $ replicate w '#'
    putStrLn ""
    [h, w] <- (map read . words) <$> getLine
    printAFrame h w

Measured memory_bytes: 4080
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    bool isPairwiseCoprime = true;
    vector<ll> primeFlags(1000000, false);
    rep(i, n)
    {
        if (isPairwiseCoprime == false)
            break;
        ll b = a[i];
        if (b == 1)
            continue;
        for (ll j = 2; j <= 1000; ++j)
        {
            if (b % j == 0)
            {
                if (primeFlags[j])
                {
                    isPairwiseCoprime = false;
                    break;
                }
                else
                {
                    primeFlags[j] = true;
                    while (b % j == 0)
                    {
                        b = b / j;
                    }
                }
            }
        }

        if (primeFlags[b] && b != 1)
        {
            isPairwiseCoprime = false;
        }
        else
        {
            primeFlags[b] = true;
        }
    }
    if (isPairwiseCoprime)
    {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    // setwiseを調べる
    ll greatestCD = a[0];
    rep(i, n - 1)
    {
        greatestCD = gcd(greatestCD, a[i + 1]);
    }
    if (greatestCD == 1)
    {
        cout << "setwise coprime" << endl;
    }
    else
    {
        cout << "not coprime" << endl;
    }
    return 0;
}

Measured memory_bytes: 18380
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define G 1

signed main(){
  while(1){
  int w,d;
  cin>>w>>d;
  if(w==0&&d==0) break;
  int a[21],b[21];
  lp(i,21){
    a[i]=b[i]=0;
  }
  lp(i,w){
    int x;
    cin>>x;
    a[x]++;
  }
  lp(i,d){
    int y;
    cin>>y;
    b[y]++;
  }
  int ans=0;
  lp(i,21){
    if(i==0) continue;
    ans+=i*max(a[i],b[i]);
  }
  cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true)
    {
        c-=b;
        if(c<=0) return 0*printf("Yes\n");
        a-=d;
        if(a<=0) return 0*printf("No\n");
    }
}


Measured memory_bytes: 3628
s = list(input())
k = int(input())

if len(s) == 1:
    print(s[0])
else:
    for i in s:
        if int(i) == 1:
            k -= 1
            if k == 0:
                print(1)
                exit(0)
        else:
            print(i)
            exit(0)

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

int N, X, Y;
int a[2010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> X >> Y;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int ans = abs(a[N-1] - Y);
  if (N == 1) {
    cout << ans << endl;
    return 0;
  }
  ans = max(ans, abs(a[N-2] - a[N-1]));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	int x, y, s;
	while (cin >> x >> y >> s && x != 0 && y != 0 && s != 0)
	{
		int MAX = 0;
		for (int i = 1; i < s; i++)
		{
			int beforeI = i * (x + 100) / 100;
			for (int j = 1 ; j < s; j++)
			{
				int beforeJ = j * (x + 100) / 100;
				if (beforeI + beforeJ == s)
				{
					int afterI = (i * (y + 100)) / 100;
					int afterJ = (j * (y + 100)) / 100;
					MAX = max(MAX,afterI + afterJ);
					break;
				}
			}
		}

		cout << MAX << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char a[] = new char[4];
        int sum = 0;
        for(int i=0; i<4; i++){
            a[i] = s.charAt(i);
            if(a[i]=='+'){
                sum += 1;
            }
            else{
                sum -= 1;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define ub  upper_bound
#define lb  lower_bound
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " << endl

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  int n;
  cin >> n;
  bool oc = false;
  int row = 0;

  while(n--){
    int d1,d2;
    cin >> d1 >> d2;
    if(d1 == d2)
      row++;
    else
      row = 0;
    if(row == 3)
      oc = true;
  }

  if(oc)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(a, b, c) for(ll c=a;c<b;c++)
#define re(b, c) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

vll check(100001, 0), a;
vvl G = vv(100001, 0, 0, ll);
set<vll> t;
multiset<ll> s;

ll c = 0;
vector<multiset<ll>> num(100001);

void dfs(ll now, ll from, bool flag){
  check[now] = 1;
  num[c].insert(a[now]);
  if(flag) s.insert(a[now]);
  else t.insert(vll{a[now], now});
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    dfs(G[now][i], now, flag);
  }
}
void er(ll now, ll from){
  if(from!=-1) s.insert(a[now]);
  auto itr = t.lower_bound(vll{a[now], now});
  t.erase(itr);
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    er(G[now][i], now);
  }
}

int main(int argc, char const *argv[]) {
  ll x, y, n, m;std::cin >> n >> m;
  a.resize(n);
  for(int i=0;i<n;i++) std::cin >> a[i];
  for(int i=0;i<m;i++){
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for(int i=0;i<n;i++) if(check[i]==0) c++, dfs(i, -1, (i==0));
  if(2*(c-1)>n){
    std::cout << "Impossible" << '\n';
    return 0;
  }

  ll ans = 0;
  /*
  for(int i=0;i<c-1;i++){
    ans += *s.begin();
    s.erase(s.begin());
    ans += (*t.begin())[0];
    er((*t.begin())[1], -1);
  }
  */
  if(c==1){
    std::cout << 0 << '\n';
    return 0;
  }
  multiset<ll> k;
  ll p=0;
  for(int i=1;i<=c;i++) {
    ans += *num[i].begin();
    num[i].erase(num[i].begin());
    p++;
    for(auto itr=num[i].begin();itr!=num[i].end();itr++){
      k.insert(*itr);
    }
  }
  for(auto itr = k.begin();p<2*(c-1);p++, itr++){
    ans += *itr;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a[7];
  for(int i=0;i<7;i++) cin>>a[i];
  int ans,tmp=0;
  ans=a[1]+a[0]/2*2+a[3]/2*2+a[4]/2*2+(a[0]%2&&a[3]%2&&a[4]%2)*3;
  if(a[0]&&a[3]&&a[4]) tmp=a[1]+(a[0]-1)/2*2+(a[3]-1)/2*2+(a[4]-1)/2*2+3;
  cout<<max(ans,tmp)<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>

#define SIZE 100002
typedef long long ll;
 
using namespace std;
 

 int main(){
     int K;
     int A,B;
     int flg =0 ;
     cin >> K;
     cin >> A>> B;
     for(int i = A ; i <= B ; i++){
         if(i % K == 0){
             flg = 1;
         }
     }
     if(flg){
         cout << "OK";
     }else{
         cout << "NG";
     }
     return 0;
 }

Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define endl '\n'
#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define ld long double
#define PI 3.14159265359

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	while (t--) {
		int n, a, b;
		cin >> n >> a >> b;
		cout << ((b - a) & 1 ? "Borys" : "Alice");
	}
}

Measured memory_bytes: 3664
#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;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

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

const int N = 2e5 + 5;
vector<int> g[N];
void dfs(int u,int p,int d,int &uu, int &dmax){
	if(d > dmax){
		dmax = d;
		uu = u;
	}
	for(int v : g[u]){
		if(v != p){
			dfs(v, u, d + 1, uu, dmax);
		}
	}
}
void solve(){
	int n;
	cin >> n;
	fr(i, 1, n - 1){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int u = -1, dmax = -1;
	dfs(1, 0, 0, u, dmax);
	dmax = -1;
	dfs(u, 0, 0, u, dmax);
	dmax++;
	if(dmax % 3 < 2){
		cout << "First";
	}
	else{
		cout << "Second";
	}
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(0);
    
    bool can = true;
    while(can){
        if(n < k){
            can = false;
            continue;
        }
        a.push_back(n%k);
        n /= k;
    }

    cout << a.size() + 1 << endl;
}

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

int ans = 1e9;
int a, b, x;

void dfs(int c, int sum) {
  if(sum >= x) {
    ans = min(ans, c);
    return;
  }
  dfs(c + a, sum + 1000);
  dfs(c + b, sum + 500);
}

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

  cin >> a >> b >> x;
  dfs(0, 0);
  cout << ans << endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        if (mp.count(a.at(i)) == 0)
        {
            mp.insert(make_pair(a.at(i), 1));
        }
        else
        {
            mp[a.at(i)] += 1;
        }
    }

    int answer = 0;
    for (auto x : mp)
    {
        int number = x.first, count = x.second;
        if (count >= number)
        {
            answer += count - number;
        }
        else
        {
            answer += count;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> A(N);
  rep(i,N) cin >> A[i];

  int h = 0;
  ll ans = 0;

  rep(i,N){
    h = max(h, A[i]);
    ans += h - A[i];
  }

  cout << ans << endl;
}


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

b=0
for i in range(N):
  a=0
  for j in range(i+1):
   
    if a==9:
      b=b-1
      break
    if (i+1)%2!=0 and (i+1)%(j+1)==0:      
      a=a+1
    if a==8:
      b=b+1

print(b)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  string a, b;
  cin >> a >> b;
  string c = a;
  string ans = "No";
  rep(i, a.size()){
    rep(j, a.size()) a.at(j) = c.at((j + i) % a.size());
    if (a == b) ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    vector<ll> num(26,0);
    ll ans = 0;

    rep(i,s.size()){
        for(char c = 'a'; c<='z'; c++){
            if(c == s[i]) num[c - 'a']++; 
        }
    }

    rep(i,26) ans += (num[i]*(num[i]-1))/2;

    cout << (s.size()*(s.size()-1))/2 - ans + 1 << endl;
}

Measured memory_bytes: 640
n,x,m=gets.split.map(&:to_i)
ml=[0]*100001
l=[nil]
i=1
s,t=0,0
while i<=n
  if ml[x]>0
    s=ml[x]
    t=i-1
    break
  end
  ml[x]=i
  l << x
  i+=1
  x=x**2%m
end
if s==0
  puts l[1..n].sum
else
  c=l[1...s].sum
  c+=l[s..t].sum*((n-s+1)/(t-s+1))
  c+=l[s,((n-s+1) % (t-s+1))].sum
  puts c
end



Measured memory_bytes: 15660
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int dp[55][105][105];
int a[105];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= 2 * N - 1 ; ++i) read(a[i]);
    sort(a + 1,a + 2 * N);
    dp[1][1][1] = 1;
    for(int i = 1 ; i < N ; ++i) {
	for(int j = 1 ; j <= 2 * N - 1 ; ++j) {
	    for(int h = 1 ; h <= j ; ++h) {
		int tj = j,th = h;
		if(a[N + i] != a[N + i - 1]) ++tj;
		if(a[N - i] != a[N - i + 1]) ++tj,++th;
		for(int k = 1 ; k <= tj ; ++k) {
		    if(k < th)
			update(dp[i + 1][k + tj - th + 1][k],dp[i][j][h]);
		    else if(k > th)
			update(dp[i + 1][th + tj - k + 1][th + 1],dp[i][j][h]);
		    else if(k == th) 
			update(dp[i + 1][tj][th],dp[i][j][h]);
		}
	    }
	}
    }
    int ans = 0;
    for(int j = 1 ; j <= 2 * N - 1 ; ++j) {
	for(int h = 1 ; h <= j ; ++h) {
	    update(ans,dp[N][j][h]);
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 2304
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        int outcnt = 0, ans = 0;
        int bit = 0;
        while(1) {
            string s; cin >> s;
            if(s == "OUT") outcnt++;
            if(outcnt >= 3) break;

            if(s == "HIT") {
                if(bit >> 2 & 1) ans++;
                bit = (bit << 1 | 1) & ((1 << 3) - 1);
            }
            else if(s == "HOMERUN") {
                ans += (__builtin_popcount(bit) + 1);
                bit = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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


int main(){
    string s;
    int w;
    cin >> s >> w;
    int n = 0;
    while(n<s.size()){
        cout << s[n];
        n += w;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256