akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846264338327950288
#define mt make_tuple


void love() {
	int n; cin>>n;
	int a[n];
	int tmp;
	unordered_map<int, int> b, c;
	for(int i = 0; i<n; i++) cin>>a[i];
	for(int i = 1; i<=n; i++) cin>>tmp, b[i] = tmp;
	for(int i = 1; i<=n-1; i++) cin>>tmp, c[i] = tmp;
	int prev = a[0];
	ll ans = 1L * b[prev];

	for(int i = 1; i<n; i++) {
		if(a[i] > 1 && a[i] == (prev+1)) {
			ans += b[a[i]] + c[a[i]-1];
		}
		else ans += b[a[i]];
		prev = a[i];
	}
	cout<<ans<<endl;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	love();
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

//const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;

//#define __DBG__

void solve(void){
  
  int N;
  cin >> N;
  vector<int> L(N);
  
  REP(i,N){
    cin >> L[i];
  }
  
  sort(ALL(L));
  
  ll ans=0;
  auto itr = L.begin();
  
  REP(i,N){
    REP2(j,i+1,N){
      auto Ita=lower_bound(itr+j+1, L.end(), L[i]+L[j]);
      auto Itd=lower_bound(itr+j+1, L.end(), L[j]-L[i]);
      ans+=Ita-Itd;
//      cout << ans << endl;
    }
  }
  
  cout << ans << endl;

  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

struct edge { int to, cost; };
int n, m;
vector<edge> g[105];
bool used[105][105];
int d[105];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>> pq;
	fill(d, d + n, inf);
	pq.emplace(0, s);
	d[s] = 0;
	while (pq.size()) {
		P p = pq.top(); pq.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto& c : g[v]) {
			edge e = c;
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				pq.emplace(d[e.to], e.to);
			}
		}
	}

	rep(i, n) {
		for (auto& c : g[i]) {
			edge e = c;
			if (d[i] + e.cost == d[e.to]) {
				used[i][e.to] = true;
				used[e.to][i] = true;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b, c });
		g[b].push_back({ a, c });
	}
	rep(i, n) dijkstra(i);
	int ans = m;
	rep(i, n - 1) {
		for (int j = i + 1; j < n; ++j) {
			if (used[i][j]) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);} while(0)
  #define trcc(v) do { cerr << "name : " << #v << "\n"; int cnt = 0; each(x , v){cerr << (cnt++) << " : "; trc(x); } } while(0)
#else
  #define trc(...)
  #define trca(...)
  #define trcc(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(s,t)   rep(i,sz(s)){in(s[i] , t[i]);}
#define in3(s,t,u) rep(i,sz(s)){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N);
  map<string,int> m;
  rep(i , N){
    ins(s);
    m[s]++;
  }
  int ans = 0;
  each(x , m){
    amax(ans , x.second);
  }
  vs bns;
  each(x , m){
    if(x.second == ans) bns.pb(x.first);
  }
  sort(all(bns));
  each(x , bns) out(x);
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> Lucas(N + 1);
  for (int i = 0; i < N + 1; i++) {
    Lucas.at(0) = 2;
    Lucas.at(1) = 1;
    if (i > 1) {
      Lucas.at(i) = Lucas.at(i - 1) + Lucas.at(i - 2);
    }
  }
  cout << Lucas.at(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n; cin >> n;
    string s; cin >> s;
    int rel = 0;
    REP(i, 1, n){
        int cnt=0;
        for(char c = 'a'; c <= 'z'; c++){
            bool left = false, right = false;
            for(int j = 0; j < i; j++){
                if(s[j] == c) left = true;
            }

            for(int j = i; j < n; j++){
                if(s[j] == c) right = true;
            }

            if(left&&right) cnt++;
        }
        if(rel < cnt) rel = cnt;
    }
    cout << rel << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,l;cin>>n>>l;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int id=-1;
  rep(i,n-1)if(a[i]+a[i+1]>=l)id=i;
  if(id==-1){
    cout<<"Impossible"<<endl;;
  }
  else {
    cout<<"Possible"<<endl;
    repi(i,1,id+1)cout<<i<<endl;
    for(int i=n-1;i>=id+2;i--)cout<<i<<endl;
    cout<<id+1<<endl;
  }

  return 0;

}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll n, k, ans, val ;
    cin >> n >> k ;
    val = n % k ;
    ans = min(val, (k - val)) ;
    cout << ans ;

    return 0 ;
}


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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()
#define pb(a) push_back(a)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;
constexpr int MAX = 200020;

void solve()
{
    ll a, b, k;
    in3(a, b, k);
    if (a >= k)
    {
        a = a - k;
    }
    else
    {
        if (b >= k - a)
        {
            b -= k - a;
        }
        else
        {
            b = 0;
        }
        a = 0;
    }
    cout << a << " " << b << '\n';
}

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

Measured memory_bytes: 256
h,w,K=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0
for i in range(2**h):
  cc=[]
  for j in range(h): 
    if ((i >> j) & 1):
      continue
    else:
      cc.append(c[j])
  cc=[list(x) for x in zip(*cc)]
  for k in range(2**w):
    ccc=[]
    for l in range(w): 
      if ((k >> l) & 1):
        continue
      else:
        if not cc==[]:
          ccc.append(cc[l])
    cnt=0
    for v in ccc:
      cnt+=v.count('#')
    if cnt==K:
      ans+=1
print(ans)

Measured memory_bytes: 9224
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [a1^a2 for a1, a2 in zip(A, A[1:])] + [A[0]^A[-1]]
C = C + C
D = [b1^b2 for b1, b2 in zip(B, B[1:])] + [B[0]^B[-1]]

K = []
k = 0
while k < N:
  next_k = k
  is_first = True
  for i in range(N):
    if is_first and i>0 and C[k+i]==D[0]:
      next_k = k + i
      is_first = False
    if C[k+i] != D[i]:
      if next_k == k:
        k = k + i + 1
      else:
        if D[k+i-next_k] == C[k+i]:
          k = next_k
        else:
          k = k + i + 1
      break
  
  if i == N-1:
    K.append(k)
    if next_k == k:
      break
    else:
      k = next_k
      if len(K) == 2:
        diff = K[1] - K[0]
        while K[-1] < N:
          K.append(K[-1]+diff)
      
        _ = K.pop()
        break

for k in K:
  print(k, A[k]^B[0])

Measured memory_bytes: 36560
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

long long a, b, c, d;

void Solve()
{
	cin >> a >> b >> c;
	d = c - a - b;
	if(d > 0 and d * d > 4 * a * b)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}

signed main()
{
	Solve();
}


Measured memory_bytes: 256
from collections import *
import sys
try: inp = raw_input
except: inp = input
def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N = ni()

sm = 0
for i in range(1, N+1):
    if i%5 and i%3:
        sm += i
print(sm)


Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

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

    long long res = 0;
    if(a[0] > x) {
        res = a[0]-x;
        a[0] = x;
    }
    for(int i = 1; i < n; i++){
        if(a[i-1]+a[i] > x){
            res += a[i-1]+a[i] - x;
            a[i] = x-a[i-1];
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
N = int(input())
X = N / 1.08
min_x = np.floor(X)
max_x = np.ceil(X)
if max_x != min_x:
    for i in range(int(min_x), int(max_x+1)):
        if int(i * 1.08) == N:
            print(i)
            break
        elif i == max_x:
            print(':(')
            break  
        else:
            continue
else:
    print(int(min_x))

Measured memory_bytes: 12504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  rep(i, tx - sx) cout << 'R';
  rep(i, ty - sy) cout << 'U';
  rep(i, tx - sx) cout << 'L';
  rep(i, ty - sy + 1) cout << 'D';
  rep(i, tx - sx + 1) cout << 'R';
  rep(i, ty - sy + 1) cout << 'U';
  cout << 'L' << 'U';
  rep(i, tx - sx + 1) cout << 'L';
  rep(i, ty - sy + 1) cout << 'D';
  cout << 'R' << endl;






  
  return 0;
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;
    cin>>n>>x;
    ll tp;
    cin>>tp;
    ll gc = abs(x-tp);
    for(ll i=1;i<n;i++)
    {
        ll t;
        cin>>t;
        gc = __gcd(gc,abs(x-t));
    }
    cout<<gc<<endl;
   
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        int n = Integer.parseInt(br.readLine());
        String[] str = br.readLine().split("");

        if(str[0].equals(str[2])){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

#define ll long long int
#define pi 3.141592653589793238
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

void solve()
{
    ll s;
    cin>>s;
    vector<ll> dp(s+1,0);
    dp[0]=1;
    for(ll i=3;i<=s;i++)
    {
        for(ll j=i-3;j>=0;j--)
            dp[i]=(dp[i]+dp[j])%mod;
 
    }
    cout<<dp[s]%mod;
    return;
}

int main()
{
    FAST;
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      #endif
    ll q;
    q=1;
    // sieve();
    // cin>>q;
    while(q--)
        solve();
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
int n;
int mp[10][10];
int nextt[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
typedef struct note
{
    int a[5][5];
    int x,y,s;
}eight;
queue<eight>Q;
int hash(eight x)
{
    int sum=0;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            sum=sum*10+x.a[i][j];
        }
    }
    return sum;
}
void bfs()
{
    map<int,bool>flag;
    eight now,temp;
    now=Q.front();
    now.s=0;
    int index=hash(now);
    flag[index]=1;
    while(!Q.empty())
    {
        now=Q.front();
        //printf("%d\n",hash(now));
        if(hash(now)==123456780)
        {
            printf("%d\n",now.s);
            return ;
        }
        Q.pop();
        for(int i=0;i<4;i++)
        {
            int tx=now.x+nextt[i][0];
            int ty=now.y+nextt[i][1];
            temp=now;
            if(tx<0||ty<0||tx>=3||ty>=3)continue;
            temp.a[now.x][now.y]=temp.a[tx][ty];
            temp.a[tx][ty]=0;
            index=hash(temp);
            if(flag[index]==0)
            {
                flag[index]=1;
                temp.x=tx;
                temp.y=ty;
                temp.s=now.s+1;
                Q.push(temp);
            }
        }
    }
}
int main()
{
    eight now;
    while(!Q.empty())
        Q.pop();
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                now.x=i;
                now.y=j;
                now.a[i][j]=0;
                now.s=0;
            }
            else
                now.a[i][j]=mp[i][j];
        }
    }
    Q.push(now);
    bfs();
    return 0;
}



Measured memory_bytes: 12812
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++){
			s[i] = sc.next();
		}
		
		String result = "";
		for(char c = 'a'; c <= 'z'; c++){
			int min = 50;
			for(int i = 0; i < s.length; i++){
				int count = 0;
				for(int j = 0; j < s[i].length(); j++){
					if(s[i].charAt(j) == c){
						count ++;
					}
				}
				min = Math.min(count, min);
			}
			for(int i = 0; i < min; i++){
				result += c;
			}
		}
		
		System.out.println(result);
		sc.close();
	}
}


Measured memory_bytes: 22612
#!/usr/bin/env python3
import sys


def solve_iter(N: int, A: "List[int]"):
    from collections import Counter
    def f(n):
        return n * (n - 1) // 2
    c = Counter(A)
    base = sum(map(f, c.values()))
    for a in A:
        yield base - f(c[a]) + f(c[a]-1)

def solve(N: int, A: "List[int]"):
    return list(solve_iter(N, A))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, A), sep='\n')

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vi cts(3);
int d;
map<ll, ll> memo;
ll cost(ll n) {
    if (n == 0) return 0;
    if (n == 1) return memo[1] = d;
    if (memo.count(n)!=0) return memo[n];
    ll res = INT64_MAX;
    if (n <= INT64_MAX/d) res = min(res, n * d);
    vi rs = { 2, 3, 5 };
    rep(i, 3) {
        int r = rs[i], ct = cts[i];
        if (n < r) continue;
        ll cnt1 = cost(n/r) + ct + d * llabs(n-n/r*r);
        res = min(res, cnt1);
        ll cnt2 = cost((n+r-1)/r) + ct + d * llabs(n-(n+r-1)/r*r);
        res = min(res, cnt2);
    }
    return memo[n] = res;
}

int main(){
    int t;
    cin >> t;
    rep(i, t) {
        ll n;
        int a, b, c;
        cin >> n >> a >> b >> c >> d;
        memo.clear();
        cts = { a, b, c };
        memo[0] = 0;
        cout << cost(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 4420
import itertools

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]

# 1 ~ Mまでの数を用いたN項の重複数列を作成する
arrs = []
for arr in itertools.combinations_with_replacement(range(1, M + 1), N):
    arrs.append(list(arr))

answer = - float("inf")
for arr in arrs:
    tmp = 0
    for a, b, c, d in ABCD:
        if arr[b - 1] - arr[a - 1] == c:
            tmp += d
    answer = max(answer, tmp)

print(answer)

Measured memory_bytes: 90188
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	ll x, ans;

	cin >> x;

	ans = x / 11 * 2;
	if(x % 11 != 0){
		if(x % 11 <= 6){
			ans++;
		}
		else{
			ans += 2;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char s[1];
  scanf("%s",s);
  if(s[0]=='A') printf("T\n");
  if(s[0]=='T') printf("A\n");
  if(s[0]=='C') printf("G\n");
  if(s[0]=='G') printf("C\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int MAX = 200;

int bubbleSort(int *A, int n)
{
    bool flag = 1;
    int sw = 0;
    while (flag)
    {
        flag = 0;
        for (int i = n - 1; i > 0; --i)
        {
            if (A[i] < A[i - 1])
            {
                int temp = A[i];
                A[i] = A[i - 1];
                A[i - 1] = temp;
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main()
{
    int A[MAX];
    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    int sw = bubbleSort(A, n);

    for (int k = 0; k < n; k++)
    {
        if (k > 0)
            cout << " ";
        cout << A[k];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 305

struct Info{
	Info(int arg_ancestor,int arg_descendant){
		ancestor = arg_ancestor;
		descendant = arg_descendant;
	}
	int ancestor,descendant;
};

int name_index,N;
map<string,int> MAP;
vector<int> RELATION[NUM][NUM];
vector<Info> DOCUMENT[1005];
bool check[NUM][NUM];
bool decided[1005],visited[NUM];


int get_index(string tmp_str){

	auto at = MAP.find(tmp_str);

	if(at == MAP.end()){

		MAP[tmp_str] = name_index++;
	}
	return MAP[tmp_str];
}

void bfs(int start_index){

	for(int i = 0; i < name_index; i++){
		visited[i] = false;
	}
	visited[start_index] = true;

	queue<int> Q;
	Q.push(start_index);

	while(!Q.empty()){

		for(int i = 0; i < name_index; i++){
			if(!check[Q.front()][i])continue;

			if(visited[i] == false){
				visited[i] = true;
				check[start_index][i] = true;
				Q.push(i);
			}
		}
		Q.pop();
	}
}

int main(){

	name_index = 0;

	string ANC,DES;

	cin >> ANC >> DES;

	int first_ancestor = get_index(ANC);
	int first_descendant = get_index(DES);

	scanf("%d",&N);

	int tmp_num,tmp_anc,tmp_des;

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp_num);

		for(int loop = 0; loop < tmp_num; loop++){

			cin >> ANC >> DES;
			tmp_anc = get_index(ANC);
			tmp_des = get_index(DES);

			RELATION[tmp_anc][tmp_des].push_back(i);
			DOCUMENT[i].push_back(Info(tmp_anc,tmp_des));
		}
	}

	for(int i = 0; i < name_index; i++){
		for(int k = 0; k < name_index; k++){
			check[i][k] = false;
		}
	}

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

	queue<Info> Q;
	Q.push(Info(first_ancestor,first_descendant));

	int tmp_document;

	while(!Q.empty()){

		if(check[Q.front().ancestor][Q.front().descendant]){

			Q.pop();

		}else{

			check[Q.front().ancestor][Q.front().descendant] = true;

			for(int i = 0; i < RELATION[Q.front().ancestor][Q.front().descendant].size(); i++){

				tmp_document = RELATION[Q.front().ancestor][Q.front().descendant][i];

				if(decided[tmp_document])continue;

				decided[tmp_document] = true;
				for(int k = 0; k < DOCUMENT[tmp_document].size(); k++){
					Q.push(DOCUMENT[tmp_document][k]);
				}
			}

			for(int i = 0; i < name_index; i++){
				if(check[Q.front().descendant][i] == false || check[Q.front().ancestor][i] == true)continue;
				Q.push(Info(Q.front().ancestor,i));
			}

			for(int i = 0; i < name_index; i++){
				if(check[i][Q.front().ancestor] == false || check[i][Q.front().descendant] == true)continue;
				Q.push(Info(i,Q.front().descendant));
			}
			Q.pop();
		}
	}

	for(int i = 0; i < name_index; i++){
		bfs(i);
	}

	for(int i = 0; i < name_index; i++){
		for(int k = 0; k < name_index; k++){
			if(k == i || check[i][k] == false)continue;

			if(check[k][i]){
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	return 0;
}



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

int main(void) {
    string S,T; cin >> S >> T;
    for(int i=0; i<int(S.size()); i++) {
        if(S[i]!=T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  int n, a;
  cin >> n;
  int ans = 0;
  rep(i, 0, n) {
    cin >> a;
    ans += __builtin_ctz(a);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3672
from collections import deque
n = int(input())
G = [None for i in range(n)]

for i in range(n):
    u,k,*vs = map(int,input().split())
    G[u-1] = [e-1 for e in vs]


dist = [-1]*n #全頂点を未訪問に初期化(-1)で未訪問
que = deque([0])   #初期条件 (頂点 0 を初期ノードとする) 
dist[0] = 0 #0を訪問済み

while len(que)>0:
    now = que.popleft()
    for i in G[now]:
        if dist[i] != -1:
            continue
        dist[i] = dist[now] + 1 #新たな頂点wについて距離情報を更新してキューに追加する
        que.append(i)

for i in range(n):
    print(i+1,dist[i])


Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define for(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,x,sum=0,b;
    cin >> n >> x;
    int a[n];
    vector<int> c;
    for(i,n){
        cin >> a[i];
        sum += a[i];
        c.pb(a[i]);
    }
    b = x - sum;
    sort(c.begin() , c.end());
    cout << n + (b/c[0]) << endl;

}

Measured memory_bytes: 256
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<iostream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

int n;
int s[100005];
int dg[100005];
vector<int> v[100005];
bool lf[100005];

void init() {
  scanf("%d", &n);
  for (int i = 1; i < n; i ++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
}

void bad() {
  puts("-1");
  exit(0);
}

bool vis[100005];
void dfs(int x, vector<int> &vv) {
  vis[x] = true;
  int cnt = 0, nxt = -1;
  for (int y : v[x]) {
    if (lf[y]) cnt ++;
    else if (!vis[y]) nxt = y;
  }

  vv.push_back(cnt);
  if (nxt != -1)
    dfs(nxt, vv);
}

void process() {
  bool g2 = false;
  for (int i = 1; i <= n; i ++) {
    if (v[i].size() == 1u)
      lf[i] = true;
    if (v[i].size() > 2u) g2 = true;
  }

  if (!g2) {
    for (int i = 1; i <= n; i ++) printf("%d%c", i, " \n"[i == n]);
    return;
  }

  bool flag = true;
  vector<int> dg1, dg2, zer;
  for (int i = 1; i <= n; i ++) if (!lf[i]) {
    int td = 0;
    for (int j : v[i]) if (!lf[j]) {
      td ++;
    }
    if (td > 2) flag = false;
    else if (td == 2) dg2.push_back(i);
    else if (td == 1) dg1.push_back(i);
    else zer.push_back(i);
  }

  if (!flag) bad();
  if (zer.size()) {
    if (dg1.size() || dg2.size()) bad();
    printf("1");
    for (int i = 3; i <= n - 1; i ++) printf(" %d", i);
    printf(" 2 %d\n", n);
    return;
  }

  if (dg1.size() != 2) bad();
  vector<int> vt[2];
  memset(vis, false, sizeof vis);
  dfs(dg1[0], vt[0]);
  memset(vis, false, sizeof vis);
  dfs(dg1[1], vt[1]);

  int bt = 0;
  for (int i = 0; i < (int)vt[1].size(); i ++) {
    if (vt[0][i] > vt[1][i]) {
      bt = 1;
      break;
    } else if (vt[0][i] < vt[1][i]) {
      bt = 0;
      break;
    }
  }

  vector<int> &vv = vt[bt];
  printf("1");
  vv[0] --;
  vv.back() --;
  int prt = 2;
  for (int i = 0; i < (int)vv.size(); i ++) {
    for (int j = 0; j < vv[i]; j ++)
      printf(" %d", prt + j + 1);
    printf(" %d", prt);
    prt += vv[i] + 1;
  }
  printf(" %d\n", n);
}

int main() {
/*
#ifdef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf("%d", &Cases);
  for (int cs = 1; cs <= Cases; cs ++) {
*/
    init();
    process();
/*
  }
*/
  return 0;
}


Measured memory_bytes: 11640
using System;
using System.IO;

namespace Contest
{

    class Program
    {
        private Scanner sc;

        public void Solve()
        {
            sc = new Scanner();
            int N = sc.NextInt();
            int X = sc.NextInt();
            int[] L = sc.IntArray();

            long p = 0;
            int cnt = 1;
            foreach (var i in L)
            {
                p += i;
                if (p <= X) cnt++;
            }
            Console.WriteLine(cnt);
        }

        static void Main() => new Program().Solve();
    }
}



class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

int main(){
  int N, M, Q;cin>>N>>M>>Q;
  map<ii, int> lr;
  for (int i=0;i<M;++i){
    int l, r;cin>>l>>r;lr[{l-1,r-1}]++;
  }

  vvi l_cum(N, vi(N+1, 0));
  for (int i=0;i<N;++i){
    for (int j=0;j<N;++j){
      l_cum[i][j+1]=l_cum[i][j]+lr[{i,j}];
    }
  }

  vvi cum(N+1, vi(N+1, 0));
  for (int j=0;j<=N;++j){
    for (int i=0;i<N;++i){
      cum[i+1][j]=cum[i][j]+l_cum[i][j];
    }
  }
  
  for (int i=0;i<Q;++i){
    int p,q;cin>>p>>q;
    int ans=cum[N][q]-cum[p-1][q];
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    long H, W, h, w;
    cin >> H >> W >> h >> w;
    auto t = (H / h) * (W / w), k = H * W - (H / h) * (W / w) * h * w;
    if(k == 0)return 0 & puts("No");
    puts("Yes");
    auto c = 1 + t / k, l = c * (h * w - 1) + 1;
    for(unsigned long i = 1; i <= H; ++i){
        for(unsigned long j = 1; j <= W; ++j)cout << (i % h || j % w ? c : -l) << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
# C - Forbidden List
X, N = map(int, input().split()) 
num_list = list(map(int, input().split())) 
for i in range(len(num_list)):
    num_list[i] = num_list[i]-X
for i in range(101):
    if (-i in num_list) is False:
        print(X-i)
        break
    if (i in num_list) is False:
        print(X+i)
        break

Measured memory_bytes: 8836
k = int(input())
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(lst[k-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
    cin>>a>>b>>c;
    if(((a == b) && (a != c)) || ((b == c) && (a != c)) || ((a == c) && (a != b)))
    	cout<<"Yes";
    else
    	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int n, m;
	int t;
	
	while (scanf("%d%d", &a, &b) != EOF){
		n = a;
		m = b;
		if (a < b){
			n = b;
			m = a;
		}
		
		while (n > 0){
			t = n;
			n = m % n;
			m = t;
		}
		
		printf("%d\n", m);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
using namespace std;
static const int MAX_H = 100;

int H, W;
string s[MAX_H];

int main(){
	cin >> H >> W;
	for(int i = 0; i < H; i++) cin >> s[i];
	for(int i = 0; i < H; i++){
		int res = -1;
		for(int j = 0; j < W; j++){
			if(s[i][j] == 'c'){
				res = 0;
			}else if(s[i][j] == '.'){
				if(res != -1){
					res++;
				}
			}
			cout << res;
			if(j == W - 1) cout << endl;
			else cout << ' ';
		}
	}
	return 0;
}


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

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

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

/* -----  2017/11/29  Problem: 070_abc_b / Link: https://abc070.contest.atcoder.jp/tasks/abc071_b  ----- */
/* ------問題------

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

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

LL N;
LL ans = 0LL;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	ans = min(b,d) - max(a,c);
	if (ans < 0)ans = 0;
	cout << ans << "\n";

	return 0;
}


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

#define MOD 998244353

using ll = long long int;

int main()
{
	int n, k; cin >> n >> k;
	vector<pair<int,int>> jumps;
	for(int i = 0; i < k; ++i)
	{
		int a, b; cin >> a >> b;
		jumps.push_back({a, b});
	}
	vector<ll> dp(n+1, 0);
	if(n == 1)
	{
		cout << 1; 
	}
	else
	{
		int ans = 0;
		dp[1] = 1;
		for(int i = 2; i <= n; ++i)
		{
		
			for(auto& p : jumps)
			{
				int jumpMinPos = i - p.second;
				int jumpMaxPos = i - p.first;
				
				
				int rangeMin = max(1, jumpMinPos);
				int rangeMax = min(i, jumpMaxPos);
	
				if((rangeMin <= rangeMax) and (rangeMin >= 1) and (rangeMax <= i))
				{
					ll toAdd = dp[rangeMax] - dp[rangeMin-1];
				
					dp[i] = (dp[i] + toAdd + MOD ) % MOD;
				}
				
			}
			dp[i] = (dp[i] + dp[i-1] + MOD) % MOD;
			
		}
		cout << (dp[n] - dp[n-1] + MOD ) % MOD;
	}
	return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

namespace BPM {
const int maxn = 110;
vector<int> g[maxn];
int n, m, l[maxn];
bool vis[maxn];
bool match(int x) {
  for (int y : g[x])
    if (!vis[y]) {
      vis[y] = true;
      if (l[y] == -1 || match(l[y])) {
        l[y] = x;
        return true;
      }
    }
  return false;
}
int solve() {
  memset(l, -1, sizeof l);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    memset(vis, 0, sizeof vis);
    if (match(i))
      ans++;
  }
  return ans;
}
}

namespace Sieve {
const int maxn = 1e7 + 10;
bool vis[maxn] = {};
vector<int> prime;
void linear_sieve(int n) {
  for (int i = 2; i < n; ++i) {
    if (!vis[i]) {
      prime.push_back(i);
    }
    for (int y : prime) {
      if (1LL * i * y >= n)
        break;
      int t = i * y;
      vis[t] = true;
      if (i % y == 0) {
        break;
      }
    }
  }
}
}

int n, a[110];
vector<int> b[2];
int main() {
  Sieve::linear_sieve(Sieve::maxn);
  scanf("%d", &n);
  set<int> s;
  REP(i, n) {
    scanf("%d", &a[i]);
  }
  REP(i, n) {
    if (i == 0 || a[i] - 1 != a[i - 1]) s.insert(a[i]);
    if (i == n - 1 || a[i] + 1 != a[i + 1]) s.insert(a[i] + 1);
  }
  for (int x : s) b[x&1].PB(x);
  BPM::n = SZ(b[0]);
  BPM::m = SZ(b[1]);
  REP(i, BPM::n) REP(j, BPM::m) {
    int d = abs(b[0][i] - b[1][j]);
    if (d >= 3 && !Sieve::vis[d]) BPM::g[i].PB(j);
  }
  int k = BPM::solve();
  int ans = k + ((BPM::n - k) / 2 + (BPM::m - k) / 2) * 2 + ((BPM::n - k) % 2) * 3;
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const ll mod = 1e9+7;
const ld error = 2e-6;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll
//mt19937 rng(199);

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1061109567;
const int nmax = 1e5+10;

#define contents(T, c) ostream_iterator<T>(cerr, c)
///===========================================  template  =======================================================

vector<int> adj[nmax];
bool visited[nmax];
bool color[nmax];

bool dfs(int root, int c){
    visited[root] = true;
    color[root] = c;
    bool ret = true;
    for(int u : adj[root]){
        if(visited[u]){
            ret &= (color[u] == (c^1));
        }
        else{
            ret &= dfs(u, c^1);
        }
    }
    return ret;
}

int main(){
    FASTIO;
    int n, m;
    cin>>n>>m;
    for(int i = 1; i<=m; i++){
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    ll bipartite = 0;
    ll nonBipartite = 0;
    ll isolated = 0;

    for(int u = 1; u <= n; u++){
        if(!visited[u]){
            bool colorable = dfs(u, 0);

            if(adj[u].size() == 0) isolated++;
            else if(colorable) bipartite++;
            else nonBipartite++;
        }
    }

//    debug(bipartite);
//    debug(nonBipartite);
//    debug(isolated);

    ll ans = ll(n)*ll(n);
    ans -= (n-isolated) * (n-isolated);
    ans += (bipartite+nonBipartite)*(bipartite+nonBipartite);
    ans += bipartite*bipartite;
    cout<<ans;
    return 0;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    int l[60];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n,greater<int>());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=l[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp
	while(1){
		int w,h;
		scan(w);scan(h);
		if(w==0&&h==0) break;
		int A[51][51];
		rep(i,h){
			rep(j,w){
				scan(A[i][j]);
			}
		}
		UnionFind uf(h*w);
		rep(i,h){
			rep(j,w-1){
				if(A[i][j]==1&&A[i][j+1]==1) uf.unite(i*w+j,i*w+j+1);
			}
		}
		rep(i,h-1){
			rep(j,w){
				if(A[i][j]==1&&A[i+1][j]==1) uf.unite(i*w+j,(i+1)*w+j);
			}
		}
		rep(i,h-1){
			rep(j,w-1){
				if(A[i][j]==1&&A[i+1][j+1]==1) uf.unite(i*w+j,(i+1)*w+j+1);
				if(A[i+1][j]==1&&A[i][j+1]==1) uf.unite((i+1)*w+j,i*w+j+1);
			}
		}
		int ans=0;
		rep(i,h){
			rep(j,w){
				if(A[i][j]==0) continue;
				if(uf.root(i*w+j)==i*w+j) ans++;
			}
		}
		prin(ans);
	}
	return 0;
}



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

int main(){
    long long int n, k;
    cin >> n >> k;

    vector<pair<long long int, long long int>> ins(n);
    for(int i=0; i<n; i++){
        long long int a, b;
        cin >> a >> b;
        ins[i] = make_pair(a,b);
    }
    sort(ins.begin(),ins.end());

    for(int i=0; i<n; i++){
        k -= ins[i].second;
        if(k <= 0){
            cout << ins[i].first << endl;
            return 0;
        }
    }
    return 0;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0LL)
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

template<typename A, size_t N, typename T> // n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int a[200000];

int rangesum(int l, int r){
  // a[]: accumulative sum
  if (l > r) return 0;
  if (l-1>=0){ return a[r] - a[l-1]; }
  else{ return a[r]; }
}

int solve(){
  int N,X;cin>>N>>X;
  int x[N]; rep(n, N){ cin>>x[n]; }

  a[0]=x[0];
  rep(i, 1, N){ a[i] = a[i-1]+x[i]; }

  int ans = INF;
  rep(n, 1, N+1){ // n: robot numbers
    int right = N-1;
    int res = N*X + n*X;  // 拾うコスト + 捨てるコスト
    res += rangesum(N-1-n+1, N-1);  // 行きのコスト
    int ord = 1;
    while (right>=0){
      if (ord==1)
        res += rangesum(right-n+1, right) * (ord+1)*(ord+1);
      else{
        if (rangesum(right-n+1, right) > INF/(2*ord+1)){
          res = INF; break;
        }
        if (rangesum(right-n+1, right) * (2*ord+1) > INF - res){
          res = INF; break;
        }
        res += rangesum(right-n+1, right) * (2*ord+1);
      }
      // 終端
      ord++; right -= n;
    }
    chmin(ans, res);
  }

  cout << ans << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

int main(){
	int N;
	cin >> N;
	int cnt = 0, res = 0;
	for(int i = 1; i <= N; i++){
		int a;
		cin >> a;
		if(a == 1){
			cnt++;
			res = max(res, cnt);
		}else{
			cnt = 0;
		}
	}
	cout << res + 1 << endl;
	return 0;
}


Measured memory_bytes: 3100