akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define DP pair<double,double>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

DP subVec(DP a,DP b){
	DP ans;
	ans.first = a.first-b.first;
	ans.second = a.second-b.second;
	return ans; 
}
DP addVec(DP a,DP b){
	DP ans;
	ans.first = a.first+b.first;
	ans.second = a.second+b.second;
	return ans; 
}
DP devVec(DP a,int x){
	DP ans;
	ans.first = a.first / (double)x;
	ans.second = a.second / (double)x;
	return ans;
}
DP rot60deg(DP x){
	DP ans;
	ans.first = x.first*cos(M_PI/3.0)-x.second*sin(M_PI/3.0);
	ans.second = x.first*sin(M_PI/3.0)+x.second*cos(M_PI/3.0);
	return ans;
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<DP> point;
	point.push_back({0.0,0.0});
	point.push_back({100.0,0.0});

	FOR(i,0,n){
		vector<DP> nextpoint;
		DP now,next;
		now = point[0];
		nextpoint.push_back(now);
		FOR(j,1,point.size()){
			next = point[j];
			DP vec = subVec(next,now);
			vec = devVec(vec,3);
			nextpoint.push_back(addVec(now,vec));
			nextpoint.push_back(addVec(addVec(now,vec),rot60deg(vec)));
			nextpoint.push_back(addVec(now,addVec(vec,vec)));
			nextpoint.push_back(next);
			now = next;
		}
		point = nextpoint;
	}
	FOR(i,0,point.size()){
		cout << fixed;
		cout << setprecision(5) << point[i].first << " " << point[i].second << endl;
	}
}


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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int &i : p) {
    cin >> i;
    i--;
  }
  for (int &i : c) cin >> i;
  ll ans = -1001001001;
  for (int i = 0; i < n; i++) {
    int now = i;
    vector<ll> vs;
    ll res = 0;
    do {
      now = p[now];
      res += c[now];
      vs.push_back(res);
    } while (now != i);
    int sz = vs.size();
    for (int j = 0; j < min(sz, k); j++) ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0ll, res));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>

using namespace std;

int H, W;
int table[500][500];

int main() {
	cin >> H >> W;
	if ((H * W) % 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

// uniform_int_distribution<int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	int n,h,m;

	scanf("%d%d%d", &n, &h, &m);

	printf("%d\n", (m/n)*h);

    return 0;
}

Measured memory_bytes: 256
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    s = input()    # 数字
    t = input()    # 数字

    # ------ 処理 ------#
    sMin = len(t)
    for i in range(len(s)-len(t)+1):
        str1 = s[i:i+len(t)]
        count = 0
        for j in range(len(str1)):
            if str1[j] != t[j]:
                count += 1
        if sMin > count:
            sMin = count

    # ------ 出力 ------#
    print("{}".format(sMin))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


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

int main(){
  vector<int> price(5);
  for(int i = 0; i < 5; i++){
    cin >> price.at(i);
  }
  int index = 0, tmp, saisho = 10;
  for(int i = 0; i < 5; i++){
    if (0 < (price.at(i) % 10) && (price.at(i) % 10) < saisho){
      index = i;
      saisho = price.at(i) % 10;
    }
  }
  int ans = 0;
  for(int i = 0; i < 5; i++){
    if(i == index) ans+= price.at(i);
    else if(price.at(i) % 10 == 0) ans+= price.at(i);
    else ans += price.at(i) + (10 - price.at(i) % 10);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

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

using namespace std;
typedef long long ll;
const int INF = 10000000;

int main() {
    int x, y;
    cin >> x >> y;
    

    for(int i = 0; i <= x; ++i) {
        if(2 * i + 4 * (x - i) == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n) {
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
      int a, v;
      cin >> a >> v;
      d[a - 1] = v;
    }
    int id = 0;
    for (int i = 0; i < n; i++) {
      if (d[i] > d[id]) id = i;
    }
    cout << id + 1 << " " << d[id] << endl;
  }

  return 0;
}


Measured memory_bytes: 3140
/**
 * ReversingNumbers.cpp
 * Create:20180418
 * Description:与えられた数列を逆順に出力するプログラム。
 */
#include <iostream>

int main(int argc, char* argv[]){
  int n;  // 数列の数

  std::cin >> n;

  int array[n];
  for (int i = 0; i < n; i++){
    std::cin >> array[i];
  }

  for (int i = n - 1; i >= 0; i--){
    std::cout << array[i];
    if (i != 0){
      std::cout << " ";
    } else {
      std::cout << std::endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3088
package main

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

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

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var N int
	var h [100000]int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		sc.Scan()
		h[i], _ = strconv.Atoi(sc.Text())
	}
	var dp [100000]int
	dp[1] = abs(h[0] - h[1])
	for i := 2; i < N; i++ {
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
	}
	fmt.Println(dp[N-1])
}


Measured memory_bytes: 3892
i = input().split()
a,b,c,d=int(i[0]),int(i[1]),int(i[2]),int(i[3])
if(a<=100 and b<=100 and c<=100 and d<=100 and a>0 and b>0 and c>0 and d>0):
    while(1):
        c-=b
        if(c<=0):
            print("Yes",end="")
            break
        a-=d
        if(a<=0):
            print("No",end="")
            break

Measured memory_bytes: 9208
#include<stdio.h>
int main()
{
	int a,b,i;

	scanf("%d %d",&a, &b);
	if (a >= b) {
		for (i = 0; i < a; i++) {
			printf("%d", b);
		}
	}
	else {
		for (i = 0; i < b; i++) {
			printf("%d",a);
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, p;
vector<ll> a;


vector<vector<ll>> comb(int n, int r) {
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}

void solve() {
    vector<ll> e, o;
    rep(i, n) if (a[i] % 2 == 0)e.emplace_back(a[i]); else o.emplace_back(a[i]);
    ll o_temp = 0;
    repone(i, o.size()) {
        if (i % 2 == 1) {
            if (i == o.size())o_temp++;
            else o_temp += comb(o.size(), i)[o.size()][i];
        }
    }
    if (p == 0) cout << ll(pow(ll(2), n)) - ll(pow(ll(2), ll(e.size()))) * o_temp << endl;
    else cout << ll(pow(ll(2), ll(e.size()))) * o_temp << endl;
}

int main() {
    cin >> n >> p;
    a.resize(n);
    rep(i, n) cin >> a[i];
    solve();
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

    vector<ll> dp;
    dp.push_back(a[0]);
    for(int i = 1; i < n; i++){
        auto it = lower_bound(dp.begin(),dp.end(),a[i]);
        if(it == dp.end()){
            dp.push_back(a[i]);
        } else {
            (*it) = a[i];
        }
    }

    cout << dp.size() << endl;

    return 0;
}


Measured memory_bytes: 4620
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long int
#define ff first
#define ss second
#define u128 __int128
#define pb push_back

#define N 100010
#define MOD 1000000007
#define mod 998244353

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	int n;
	cin >> n;
	int a[n];
	int f[1003] = {};
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		f[a[i]]++;
	}

	for(int i = 1; i < 1003; ++i)
		f[i] += f[i - 1];

	int ans = 0;
	sort(a, a + n);

	for(int i = 0; i < n; ++i)
	{
		for(int j = i + 1; j < n; ++j)
		{
			int l = j + 1, r = n - 1;
			while(l < r)
			{
				int mid = l + r + 1 >> 1;
				if(a[i] + a[j] <= a[mid])
					r = mid - 1;
				else
					l = mid;
			}
			if(a[i] + a[j] > a[l])
			{
				ans += l - j;
			}
		}
	}
	cout << ans << "\n";
 	return 0;	 
}



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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	int t1 = n/500;
	int t2 = n%500;
	cout<<t1*1000+t2-t2%5<<endl;
}


Measured memory_bytes: 256
import itertools
n,m = map(int,input().split())
perm = []
for j in range(n):
	perm.append(j)
perm_list = list(itertools.permutations(perm))
	
net_arr = [[0 for _ in range(n)] for _ in range(n)]
for i in range(0,m):
	a,b = map(int,input().split())
	a -= 1
	b -= 1
	net_arr[a][b] = 1
	net_arr[b][a] = 1
def check_path(path,net):
	for i in range(len(path)-1):
		if not net_arr[path[i]][path[i+1]] == 1:
			return False
	return True
	
ans = 0
for path in perm_list:
	if not path[0] == 0:
		break
	if check_path(path,net_arr):
		ans += 1	
print(ans)


Measured memory_bytes: 8052
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    cin >> n;

    vvl a(n, vl(2));
    rep(i, n) {
        a[i][0] = i + 1;
        cin >> a[i][1];
    }

    sort(all(a), [](vl a, vl b) {return a[1] < b[1];});

    rep(i, n - 1) {
        cout << a[i][0] << " " << endl;
    }
    cout << a[n - 1][0] << endl;
}

Measured memory_bytes: 8716
k = int(input())

import math
d=0
e=0
f=0
s = 0
ss=0
sss=0
for a in range(1,k+1):
    for b in range(1,k+1):
        e+=1
        d = math.gcd(a,b)

        for c in range(e,k+1):
#            print(a,b,c)                                                      
            if f==0:
                ss+=math.gcd(d,c)
#                print(a,b,c)                                                  
                f+=1
            else:
                s+=math.gcd(d,c)

        d=0
        s *=2
        s+=ss
        sss+=s
        s=0
        ss=0
        f=0
    e=0
print(sss)

Measured memory_bytes: 9216
'use strict'

function main(input) {
  let S = input.trim() //.split('\n')

  const words = 'dream dreamer erase eraser'.split(' ')

  while (true) {
    let found = false
    for (let i = 0; i < words.length; i++) {
      const tmp = S.match(new RegExp(words[i] + '$'))
      if (tmp) {
        const xx = -1 * tmp[0].length
        S = S.slice(0, xx)
        found = true
      }
      if (S === '') {
        console.log('YES')
        return
      }
    }
    if (!found) {
      console.log('NO')
      return
    }
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

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

  if ( K%2 == 0 ) {
    cout << K*K/4 << endl;  
  }
  else {
    cout << (K-1)/2*((K-1)/2+1) << endl; 
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <random>

using namespace std;

int main()
{
    long long N, K;
    cin >> N >> K;
    cout << N - (K-1) << endl;

    return 0;
}

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

		if (S.length() == T.length() - 1){
			if (S.equals(T.substring(0, T.length() - 1))){
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35780
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//
int a[maxn], b[maxn];
//
//initialization finish


// your function is here
//


//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n; cin >> n;
	rep(i, n)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a, a + n);

	rep(i, n)b[i] = (lower_bound(a, a + n, b[i])-a);
	
	ll cnt0 =0, cnt1=0;
	rep(i, n)
	{
		if (i % 2 == 0 and b[i] % 2 == 1)cnt0++;
		if (i % 2 == 1 and b[i] % 2 == 0)cnt1++;
	}

	Print(max(cnt0,cnt1));
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, T;
  cin >> A >> B >> T;

  cout << B*(T/A) << "\n";

  return 0;
}


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

int main() {
  int n, ones_place;
  string ans;
  cin >> n;
  
  ones_place = n % 10;
  
  switch (ones_place) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      ans = "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      ans = "pon";
      break;
    case 3:
      ans = "bon";
      break;
  }
  
  cout << ans;
  
  return 0;
}

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

int main(){
  int R, G, B, N;
  cin >> R >> B >> G >> N;

  int ans = 0;
  for(int r=0; r*R<=N; r++){
    for(int g=0; g*G+r*R<=N; g++){
      if((N-g*G-r*R) % B == 0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/

void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    ll n, a, b;
    cin >> n >> a >> b;
    ll loop = a + b;
    ll cnt = n / loop;
    ll ans = cnt * a;
    ans += min(a, n % loop);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	int count = 0;
	for(int i = 0; i < n; i++) {
		int p; scanf("%d", &p);
		
		count += (i + 1 != p);
	}
	
	if(count <= 2) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

int main() {
  int H, N, A, i;
  int S = 0;
  cin >> H >> N;

  for(i = 0; i < N; i++) {
    cin >> A;
    S += A;
  }
  
  if(S >= H) {
    cout << "Yes";
  }
  else{
    cout << "No";
  }

}


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


char s[120];

pair<pair<string, int>, int> p[101];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tm;
		cin >> s >> tm;
		string tmp = s;
		p[i] = make_pair(make_pair(s, -tm), i);
	}
	std::sort(p, p + n);

	for (int i = 0; i < n; i++)cout << p[i].second + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a==1) a+=13;
    if(b==1) b+=13;
    if(a==b) cout << "Draw" << endl;
    else if(a > b) cout << "Alice" << endl;
    else cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 100010
#define LL long long
LL a[maxn];
int n;
int q;
LL K;
LL sum=0;
int main()
{
	cin>>n>>K>>q;
	
	for(int i=1;i<=q;i++)
	{
		int tmp;
		cin>>tmp;
		a[tmp]++;
		
	}
	for(int i=1;i<=n;i++)
	{
		a[i]+=K;
		a[i]-=q;
		if(a[i]<=0)
		{
			cout<<"No"<<endl; 
		}
		else
		{
			cout<<"Yes"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1408
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int ans = n * 2;
    for(int len : in(1, n + 1)) {
        auto s1 = s.substr(n - len, len);
        auto s2 = t.substr(0, len);
        if(s1 == s2)
          ans = min(n * 2 - len, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 21:07:24 2019

@author: Yamazaki Kenichi
"""

N = int(input())
A = [list(map(str,input().split())) for i in range(N)]

ans = 0
for i in range(N):
    if A[i][1] == 'BTC':
        ans += float(A[i][0])*380000
    else:
        ans += int(A[i][0])
print(ans)

Measured memory_bytes: 3060
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, label)
  size = queue.size
  index = queue.index{|entry| entry[0] >= label} || size
  return queue[index][1] if index < size && queue[index][0] == label

  return nil if index > 0 && !label.start_with?(queue[index - 1][0])
  queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(label)

  nodes = {}
  queue.insert(index, [label.dup, nodes])
  nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  result = ''
  queue = [['', {start => true}]]
  until queue.empty?
    label, nodes = queue.shift
    result << label
    return result if nodes[goal]
    return nil if result.size > limit

    size = label.size
    queue.each do |next_label, _|
      next_label.slice!(0...size)
    end

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = a.times.map{
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  }

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 9720
n = input()
def check(st) : 
    n = len(st) 
    digitSum = 0 
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i])  
    return (digitSum % 9 == 0)  
     
if(check(n)) : 
    print("Yes") 
else :  
    print("No")

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i = 0; i < m; i++) cin >> a[i];
    int sum = 0;
    for(int i = 0; i < m; i++) sum += a[i];
    int res = n - sum;
    if(res < 0) res = -1;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char 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;}

int main() {
  int n;
  cin >> n;
  ll tmp;
  cin >> tmp;
  ll ans = tmp;
  rep (i, n - 1) {
    cin >> tmp;
    ans = lcm(ans, tmp);
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, n, x, min, max;
  long long int sum = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(i == 0){
      min = x;
      max = x;
    }
    else{
      if(x < min)
	min = x;
      if(max < x)
	max = x;
    }
    sum += x;
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;

ll n;
vector<ll> arr;

int main(){
    cin >> n;
    for(int i = 0;i < n; i++){
        ll x;
        cin >> x;
        arr.pb(x);
    }

    sort(arr.begin(), arr.end());
    ll cnt = 0;
    ll ans = -1;
    for(int i = 0; i < n-1; i++){
        cnt += arr[i];
        if(cnt*2 < arr[i+1]) ans = max(ans, ll(i));
    }
    if(ans == -1){
        cout << n << endl;
        return 0;
    }

    cout << n-(ans+1) << endl;

    return 0;
}


Measured memory_bytes: 1400
n=int(input())
a=list(map(int,input().split()))
cnt=0
cnt1=0
ans=1
aa=a[0]
for i in range(n):
    #print(ans)
    if aa>a[i] and cnt1==0:
        cnt=1
        aa=a[i]
    elif aa<a[i] and cnt==0:
        cnt1=1
        aa=a[i]
    elif aa>a[i] and cnt1!=0:
        aa=a[i]
        ans+=1
        cnt1=0
    elif aa<a[i] and cnt!=0:
        aa=a[i]
        ans+=1
        cnt=0
    else:
        continue
print(ans)

Measured memory_bytes: 14436
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// 素因数分解 O(√n)以下
// (素因数,個数)
template<typename T>
vector<pair<T, T> > prime_factorization(T n) {
    vector<pair<ll, ll> > res;
    for (ll i = 2; i*i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) res.push_back(make_pair(i,cnt));
    }
    if (n > 1) res.push_back(make_pair(n,1));
    return res;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,p,m=0,k,h,w,sum=0,ans=1,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u,v;
    bool ok=false;
    cin >> n >> p;
    vector<pair<ll,ll> > pp(1000000);
    pp = prime_factorization(p);
    rep(i,pp.size()){
        if(n <= pp[i].second){
            x = pp[i].second/n;
            ans *= pow(pp[i].first, x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int func(int n,int m){
    vector<int> have(n,0);
    int cnt = 0;
    int p = 0;
    while(m or cnt>1){
        if(m){
            if(!have[p])++cnt;
            ++have[p];
            --m;
        }else{
            if(have[p])--cnt;
            m += have[p];
            have[p] = 0;
        }
        p = (p + 1) % n;
    }
    return (p-1+n)%n;
}

int main(){
    int n,m;
    while(true){
        n = in();
        m = in();
        if(n==0)break;
        cout << func(n,m) << endl;
    }
  return 0;
}



Measured memory_bytes: 3148
n, k = map(int, input().split())
As = list(map(int, input().split()))
maps = {}

for i, a in enumerate(As):
    maps[i] = a - 1

probs = [0] * n
p = 0  # 現在位置
target = 0  # はじめて2回出現する場所
h = 0  # ターゲットの初回出現時のワープ回数
t = 0  # ターゲットの2回目の出現時のワープ回数

# はじめて2回出現する場所(target)と、その時点でのワープ回数を取得
for i in range(n + 1):
    probs[p] += 1
    if (probs[p] == 2):
        target = p
        t = i
        break
    p = maps[p]

# 初回出現位置を取得(めんどうくさいのでもう一回回した。)
p = 0
for i in range(n):
    if (p == target):
        h = i
        break
    p = maps[p]

s = t - h  # 周期
if (k <= h):
    p = 0
    for i in range(k):
        p = maps[p]
    print(p + 1)
    exit()

d = (k - h) % s  # targetに到着後にワープすべき回数

# 実際に必要な回数だけワープ
p = 0
for i in range(h + d):
    p = maps[p]

print(p + 1)


Measured memory_bytes: 44396
# -*- coding: utf-8 -*-
import numpy as np

def main(num, w_list):
    t = range(1, num);
    res = list(map(lambda x: int(np.abs(np.sum(w_list[0:x])-np.sum(w_list[x:num]))),t));
    print(np.min(res))

if __name__ == '__main__':
    n = int(input());
    w = list(map(int,input().split()));
    main(n,w);

Measured memory_bytes: 12436
#include <iostream>
#include<stdio.h>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int a,b,k;
    cin >>k>> a >> b ;
    int i,result=-1;
    for(i=a;i<=b;i++){
        if(i%k==0){
            result=1;
            break;
        }

    }
    if(result==1)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	ll ans(0);
	rep(i, n) {
		ans ^= a[i];
	}
	//vector<int>an(n);
	rep(i, n) {
		a[i] ^= ans;
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string>s;
    long long n;
    cin>>n;
    while(n--)
    {
        string p;
        cin>>p;
        s.insert(p);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 19152
if __name__ == "__main__":
    scores = [0, 0]
    turn_num = int(input())
    for turn in range(turn_num):
        cards = input().split()
        if cards[0] == cards[1]:
            scores[0] += 1
            scores[1] += 1
        elif cards[0] > cards[1]:
            scores[0] += 3
        else:
            scores[1] += 3
    print(f"{scores[0]} {scores[1]}")



Measured memory_bytes: 5612
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <algorithm>
#include <climits>
#include <queue>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

template <typename T>
using V = vector<T>;

struct N {
	int n, c;
	bool operator < (N a) const {
		return c > a.c;
	}
};

int main() {
	for (int n, m, s, g1, g2; n = in, m = in, s = in, g1 = in, g2 = in;) {
		s--, g1--, g2--;
		V<V<N>> g(n), h(n);
		times(i, m) {
			int s {(int) in - 1}, e {(int) in - 1}, c {in};
			g[s].push_back({e, c});
			h[e].push_back({s, c});
		}
		auto f = [&](int s, V<V<N>> &x) {
			V<int> d(n, INT_MAX / 4);
			d[s] = 0;
			priority_queue<N> q;
			q.push({s, 0});
			while (!q.empty()) {
				N t = q.top();
				q.pop();
				for (N i : x[t.n])
					if (d[i.n] > d[t.n] + i.c)
						q.push({i.n , d[i.n] = d[t.n] + i.c});
			}
			return d;
		};
		V<int> rs {f(s, g)}, r1 {f(g1, h)}, r2 {f(g2, h)};
		int r {INT_MAX};
		for (int i: range(n))
			r = min(r, rs[i] + r1[i] + r2[i]);
		outl(r);
	}
}


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

int main() {
  int n;
  int f[100][14];
  int p[100][15];
  cin >> n;
  rep(i, n) rep(j, 10) cin >> f[i][j];
  rep(i, n) rep(j, 11) cin >> p[i][j];

  int ans = -1e9; 
  rep(bit, (1<<10)) {
    if (bit == 0) continue;
    int sum = 0;
    rep(i, n) {
      int c = 0;
      rep(j, 10) if (bit & (1<<j)) if (f[i][j]) c++;
      sum += p[i][c];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
ll s[200032];
int main() {
	int n, x; ll W;
	scanf("%d%lld",&n,&W);
	for (int i = 0; i < n; i++) {
		scanf("%d",&x);
		s[i+1] = s[i] + x;
	}
	ll ans = 1ll << 60;
	for (int i = 1; i <= n; i++) {
		ll cost = W * i;
		for (int r = n, l, t = 0; r && cost < ans; r = l)
			cost += (s[r] - s[l = r>i ? r-i : 0]) * (t++ ? t<<1|1 : 5);
		if (cost < ans) ans = cost;
	}
	printf("%lld\n", ans + W * n);
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
vector<long long> a(n);
long long neg=0;
  for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  	  if(a[i]<0)
  	    neg++,
  	    a[i]*=-1;
  }
sort(a.begin(),a.end());
long long sum=0;
  for(int i=0;i<n;i++)
    sum+=a[i];
neg%=2;
  if(neg)
    sum-=a[0]*2;
cout<<sum<<endl;
return 0;
}

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

int div(int A, int B, int mod_p) {
  stack<int> q_stack;
  int a = B, b = mod_p, r;
  while (b) {
    q_stack.push(a / b);
    r = a % b; a = b; b = r;
  }
  long u = 1, v = 0;
  while (!q_stack.empty()) {
    int q = q_stack.top(); q_stack.pop();
    long u1 = v, v1 = u-q*v; u = u1 % mod_p; v = v1 % mod_p;
  }
  return (long)A * (u + mod_p) % mod_p;
}

int main() {
  int DIV = 998244353;
  int N, M, K; cin >> N >> M >> K;
  if (M == 1) {
    if (K == N-1) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  int sum = 0, x = 1;
  for (int i = 0; i < N-1; i++) x = (long)x * (M-1) % DIV;
  sum += x;
  for (int i = 0; i < K; i++) {
    x = (long)x * (N - i - 1) % DIV;
    x = div(x, i + 1, DIV);
    x = div(x, M - 1, DIV);
    sum = (sum + x) % DIV;
  }
  cout << (long)sum * M % DIV << endl;
}

Measured memory_bytes: 3628
MOD=10**9+7
n,m = list(map(int, input().split()))
a = set([int(input()) for _ in range(m)])

dp = [0] * (n+1)

dp[0] = 1
dp[1] = int(1 not in a)
for step in range(2, n+1):
    if dp[step-1]==0 and dp[step-2]==0:
        break
    if step not in a:
        dp[step] = (dp[step-1] + dp[step-2])%MOD
    else:
        dp[step] = 0
        
print(dp[-1])

Measured memory_bytes: 18764
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ll n,sum=0;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			sum=sum+arr[i]*arr[j];
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll MOD = 1e9+7;

const int INF = 1001001001;
 
int c[10][1005];
 
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = INF;
  rep(div,1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i,h) {
      id[i] = g;
      if (div>>i&1) ++g;
    }
    ++g;
    rep(i,g)rep(j,w) c[i][j] = 0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j]-'0');
    bool ok = true;
    rep(i,g)rep(j,w) if(c[i][j] > k) ok = false;
    if(!ok) continue;
 
    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if (now[i] > k) return false;
      return true;
    };
    rep(j,w) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        add(j);
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

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

  while (1)
  {
    bool yes = true;
    // エラトステネス
    for (int i = 2; i < sqrt(x); i++)
    {
      if (x % i == 0)
      {
        yes = false;
        continue;
      }
    }
    if (yes)
    {
      break;
    }

    x++;
  }

  cout << x << endl;

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
int arr[MAXX];
void trozen()
{
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int ans=0;
    rep(i,n) if(s[i]!=t[i]) ans++;
    cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 3772
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

ll N;

template<typename T>
struct BIT {
  int n;
  std::vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

using Tup = std::tuple<ll, ll, ll>;

struct UnionFind {
  std::vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) std::swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

UnionFind uf( 200010 );

ll ip[200010];

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

  std::vector<ll> x(N), y(N);

  std::vector<Tup> ts;

  rep( i, N ) {
    std::cin >> x[i] >> y[i];
    --x[i];
    --y[i];

    ts.emplace_back( x[i], y[i], i );
    
    ip[y[i]] = i;
  }

  std::sort(all(ts));

  std::set<ll> S;

  rep( i, N ) {
    auto [tx, ty, ti] = ts[i];

    auto it = S.begin();
    auto ub = S.upper_bound(ty);

    if( it == ub ) {
      S.emplace(ty);

      continue;
    }

    ll mi = *it;

    for( ; it != ub; ) {
      uf.unite( ip[*it], ti );
      it = S.erase(it);
    }

    S.emplace(mi);
  }

  rep( i, N )
    std::cout << uf.size(i) << endl;

  return 0;
}

Measured memory_bytes: 15884