akhauriyash/Code-Regression huggingface dataset:
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[3][3];
ll flag[109];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            cin>>a[i][j];
    }

    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        flag[x]  =1;
    }
    x = 0;
    for(i=0;i<3;i++)
    {
        if(flag[a[i][0]])
            x++;
    }
    if(x==3)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
     x = 0;
    for(i=0;i<3;i++)
    {
        x = 0;
        for(j=0;j<3;j++)
        {
            if(flag[a[i][j]])
                x++;
        }
        if(x==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(i=0;i<3;i++)
    {
        x = 0;
        for(j=0;j<3;j++)
        {
            if(flag[a[j][i]])
                x++;
        }
        if(x==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    x = 0;
    for(i=0;i<3;i++)
    {
        if(flag[a[i][i]]==1)
            x++;
    }
    if(x==3)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    x = 0;
    for(i=2;i>=0;i--)
    {
        if(flag[a[2-i][i]]==1)
            x++;
    }
    if(x==3)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;


    return 0;
}



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

int main()
{
  int a, b;
  int k;

  cin >> a >> b;
  cin >> k;

  for ( int i = a; i <= b; i++) {
    if ( i - k < a || i + k > b ) {
      cout << i << endl;
    }
  }

  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int ar[100000000];
int main()
{
    int i,j,n,cnt=0,x;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>ar[i];
    }
    sort(ar+1,ar+1+n);
    for(i=1; i<=n; i++)
    {

        if(ar[i]==ar[i+1])
        {
            cnt++;
        }

    }
    if(cnt>=1)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 100
#define INF 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int n, A[MAX][MAX];

int prim(){
 
  int u,mv,i,v,sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i = 0; i<n; i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  //0 of weight
  while(1){
    mv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(mv>d[i]&&color[i]!=BLACK){
	u=i;
	mv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&A[u][v]!=INF){
	if(d[v]>A[u][v]){
	  d[v]=A[u][v];
	  p[v]=u;
	  color[v]=GRAY;  
	}
     }
    }
  }//end while
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum += A[i][p[i]];
  }
  
  return sum;
}

int main(){

  int i,j,e;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      if(A[i][j]==NIL) A[i][j]=INF;
    }
  }

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

  return 0;
}



Measured memory_bytes: 2048
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる
# 階乗 & 逆元計算



d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X,Y = LI()

if (X + Y) % 3 != 0:
    ans = 0
else:
    n = 10 ** 6
    factorial = [1]
    inverse = [1]
    for i in range(1, n+2):
        factorial.append(factorial[-1] * i % mod)
        inverse.append(pow(factorial[-1], mod-2, mod))

    def combinations_count(n,r):
        if n-r < 0:
            return 0
        return factorial[n]*inverse[r]*inverse[n-r]%mod
    m = int(X * 2 / 3 - Y / 3)
    n = int(Y * 2 / 3 - X / 3)
    if (X+Y) / 3 > X or (X + Y) / 3 > Y or m < 0 or n < 0:
        ans = 0
    else:
        ans = combinations_count((X + Y)//3, n)
print(ans)


Measured memory_bytes: 137964
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll N;

void dfs(ll &p, ll &q, vl P, vl Q, vl &R, vl &used, ll ind, ll &cnt){
  if(ind == N){
    cnt++;
    bool Pmatch = true, Qmatch = true;
    
    rep(i, N){
      Pmatch = Pmatch && (R[i] == P[i]);
      Qmatch = Qmatch && (R[i] == Q[i]);
    }
    if(Pmatch) p = cnt;
    if(Qmatch) q = cnt;
    
    return;
  }

  rep2(i, 1, N + 1){
    if(used[i] == 1) continue;

    R.push_back(i);
    used[i] = 1;
    dfs(p, q, P, Q, R, used, ind + 1, cnt);
    used[i] = 0;
    R.pop_back();
  }
}

int main(){
  cin >> N;
  vl P(N), Q(N);
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];

  ll p = -1, q = -1;
  vl used(N + 1, 0);
  vl R;
  ll cnt = 0;

  dfs(p, q, P, Q, R, used, 0, cnt);

  cout << abs(p - q) << endl;
  
  return 0;
}


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

int main(){
  bool flag = false;
  int start,stop;
  cin >> start >> stop;
  int num;
  cin >> num;
  int book_start,book_stop;
  for(int i=0;i<num;i++){
    cin >> book_start >> book_stop;
    if(start>=book_start && start<book_stop){
      flag = true;
    }
    if(stop>book_start && stop<=book_stop){
      flag = true;
    }
    if(start<=book_start&&stop>=book_stop){
      flag = true;
    }
  }

  cout << flag << endl;

}



Measured memory_bytes: 3100
n = int(input())
p = input().split()
p = [int(i) for i in p]
a = 0
for i in range(1,n-1):
    b = sorted([p[i-1], p[i], p[i+1]])
    if b.index(p[i]) == 1:
        a += 1
    else:
        pass
print(a)


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

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// typedef vector<vector<int>> matrix;
const int64_t m = 1e18;
void solve()
{

    ll n;
    cin >> n;
    ll a[n];
    bool zero = 0;
    fr(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
            zero = 1;
    }
    ll ans = 1;
    if (zero == 1)
    {
        cout << 0 << "\n";
        return;
    }
    fr(i, n)
    {
        if (a[i] > m / ans)
        {
            cout << -1 << "\n";
            return;
        }
        ans *= a[i];
    }
    cout << ans;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 4436
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
using namespace std;
string n;
int ans=0;
int main()
{
  cin>>n;
    int l=n.size();
    for(int i=0;i<l;i++)
    {
        if(n[i]!=n[i+1])ans++;
    }
    printf("%d\n",ans-1);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 N, ptr, res;
int A[100000];

int main () {
  scanf("%d",&N);
  REP(i,N) scanf("%d",&A[i]);

  sort(A,A+N);

  while (ptr<N) {
    int cc = A[ptr], f = 0;
    while (ptr<N && A[ptr]==cc) f++, ptr++;
    res += f%2;
  }

  printf("%d\n",res);
}

Measured memory_bytes: 640
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
// #define int unsigned long long int
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int mul1 = 1003, mul2 = 5, mul3 = 8;
const int MOD3 = 179424673, MOD2 = 982451653, MOD1 = 1190494759;
const ld EPS = 1e-9;
 
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=10*xx+ch-'0';ch=getchar();}
    return xx*ff;
}
 
ull hasher(ull a, ull b) {
    return 14831553208299411291ull * (a ^ 16184882973064831860ull) + b;
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n;
const int LIM = 2e5+5;
string s[LIM];
unordered_map<ull, int> m;
 
int main(){
    fastio;
 
    cin>>n;
 
    ll ans = -n;
 
    forn(i,n){
        cin>>s[i];
        reverse(s[i].begin(), s[i].end()); 
        
        ull h1 = 0;
        forn(j,s[i].length()){
            h1 = hasher(h1, s[i][j]);
        }
        ++m[h1];
    }


    forn(i,n) {
        int num[26] = {0};
        forn(j,s[i].length()){
            ++num[s[i][j]-'a'];
        }

        ull h1 = 0;
        forn(j,s[i].length()){
            forn(k,26){
                if (num[k]) {
                    ull n1 = hasher(h1, k+'a');
                    
                    auto it = m.find(n1);
                    if (it != m.end())
                        ans += (*it).second;
                }
            }
            h1 = hasher(h1, s[i][j]);
            --num[s[i][j]-'a'];
        }
    }
 
    cout<<ans<<ln;
    return 0;
}


Measured memory_bytes: 17680
#include <stdio.h>
int main(){
    int H,W,i,j;
    
    while(1){
        scanf("%d%d",&H,&W);
        
        if(H==0 && W==0) break;
        
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                
                if(i%2==0 && j%2==0){
                    printf("#");
                }
                else if(i%2==1 && j%2==1){
                    printf("#");
                }
                else printf(".");
                
                
            }
        printf("\n");    
        }
    printf("\n");
        
    }
    return 0;
}

Measured memory_bytes: 572
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

ans = [[a11, a12, a13], [a21, a22, a23], [a31, a32, a33],
       [a11, a21, a31], [a12, a22, a32], [a13, a23, a33],
       [a11, a22, a33], [a13, a22, a31]]

for a in ans:
    if (a[0] in b) and (a[1] in b) and (a[2] in b):
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    string s; cin >> s;
    int ans=0;
    char last=0;
    for(int i=s.size()-1; i>=0; --i){
        if(s[i]==last){
            last=0;
            --i;
            if(i>=0) ++ans;
        } else {
            last=s[i];
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct Point {
	int x;
	int y;
	int i;
};

pair<int64_t, int64_t> search(vector<Point>& ps, vector<Point>& psx, vector<Point>& psy, vector<bool>& used, int i) {
	assert(!used[i]);

	multiset<int64_t> xused;
	multiset<int64_t> yused;

	queue<Point> search;
	search.push(ps[i]);
	used[i] = true;

	int  count = 1;

	while (!search.empty()) {
		Point cur = search.front();
		search.pop();

		if (xused.find(cur.x) == xused.end()) {
			auto it = lower_bound(psx.begin(), psx.end(), cur, [](const Point & lhs, const Point & rhs) {
				return lhs.x < rhs.x;
				});
			while (it != psx.end() && it->x == cur.x) {
				if (it->y != cur.y && !used[it->i]) {
					used[it->i] = true;
					search.push(*it);
					count++;
				}
				it++;
			}
			xused.insert(cur.x);
		}
		if (yused.find(cur.y) == yused.end()) {
			auto it = lower_bound(psy.begin(), psy.end(), cur, [](const Point & lhs, const Point & rhs) {
				return lhs.y < rhs.y;
				});
			while (it != psy.end() && it->y == cur.y) {
				if (it->x != cur.x && !used[it->i]) {
					used[it->i] = true;
					search.push(*it);
					count++;
				}
				it++;
			}
			yused.insert(cur.y);
		}
	}

	if (xused.size() == 1 && yused.size() == 1) {
		return make_pair(count, 0);
	}
	return make_pair(count, (xused.size() * yused.size()) - count);
}

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

	int n; cin >> n;

	vector<Point> ps(n);
	FOR_LT(i, 0, n) {
		cin >> ps[i].x >> ps[i].y;
		ps[i].i = i;
	}

	vector<Point> psx = ps;
	vector<Point> psy = ps;
	sort(psx.begin(), psx.end(), [](const Point & lhs, const Point & rhs) {
		return lhs.x < rhs.x;
		});
	sort(psy.begin(), psy.end(), [](const Point & lhs, const Point & rhs) {
		return lhs.y < rhs.y;
		});

	vector<bool> used(n, false);

	int64_t sum = 0;
	int64_t ans = 0;
	int i = 0;
	while (sum != n) {
		pair<int64_t, int64_t> cur = search(ps, psx, psy, used, i);

		sum += cur.first;
		ans += cur.second;

		while (i != n && used[i]) i++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8576
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


struct BinaryLifting{
    int n;
    vector<vector<int>> next;
    vector<int> par;
    vector<vector<int>> childs;
    vector<int> depth;

    BinaryLifting(vector<int> par) : n(par.size()) {

        next.push_back(par);
        for(int k = 0; k < 70; ++k){
            next.emplace_back(n, -1);
            for(int i = 0; i < n; ++i){
                next[k + 1][i] = next[k][next[k][i]];
            }
        }
    }
    // kth_next(x, 0) => x
    int kth_next(int x, i64 k){
        for(int i = 0; i < 64; ++i){
            if((k >> i) & (1uLL)){
                x = next[i][x];
                if(x == -1)
                    break;
            }
        }
        return x;
    }

};



signed main(){
    i64 n, k;
    cin >> n >> k;
    vector<int> a(n);

    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
    }
    BinaryLifting b(a);
    cout << b.kth_next(0, k) + 1 << endl;

    return 0;
}


Measured memory_bytes: 60548
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I a,b,c;
  cin >> a >> b >> c;
  int x = c - (a -b);
  int t = max(x, 0);
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
    int n, X; cin >> n >> X;
    vector<ll> x(n), sum(n + 1, 0LL);
    rep(i, n) {
        cin >> x[i];
        sum[i + 1] = sum[i] + x[i];
    }
    ul ans = (1LL<<63)-1;
    for(int y = 1; y <= (n + 1) / 2; ++y) {
        ul res = (ul)X * (n + y);
        res += (ul)sum[n] * 5ULL;
        for(int i = 2; n - i * y > 0; ++i) {
            res += (ul)sum[n - i * y] * 2ULL;
        }
        chmin(ans, res);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


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

int main(){
  long long n;
  cin >> n;
  vector<long long> countVec(35, 0);
  for(long long i=0; i<n; i++){
    long long num;
    cin >> num;
    for(int j=0; j<35; j++){
      if(num & 1<<j) countVec[j]++;
    }
  }
  for(int i=0; i<35; i++){
    if(countVec[i] % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
    

Measured memory_bytes: 256
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline
h, w, k = map(int, input().split())

c = []
for _ in range(h):
    c.append(list(input()))
#c = list(map(list, input()) for _ in range(h))
cnt = 0
for hi in product((0, 1), repeat=h):
    for wi in product((0, 1), repeat=w):
        cc = copy.deepcopy(c)
        for hc, hii in enumerate(hi):
            if hii == 1:
                for i in range(w):
                    cc[hc][i] = '.'
        for wc, wii in enumerate(wi):
            if wii == 1:
                for j in range(h):
                    cc[j][wc] = '.'
        ss = ""
        for li in cc:
            ss += "".join(li)
        ccc = collections.Counter(ss)
#         print(hc, wc)
#         print(ss)
#         print(ccc["#"])
        if ccc["#"] == k:
            cnt += 1
print(cnt)












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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int h,w,m; cin >> h >> w >> m;
  static vector<P<int,int>> b(m);
  int cntr[300001] = {};
  int cntc[300001] = {};
  int maxr=0,maxc=0;
  for(int i = 0; i < m; ++i){
    cin >> b[i].first >> b[i].second;
    ChangeMax(maxr,++cntr[b[i].first]);
    ChangeMax(maxc,++cntc[b[i].second]);    
  }
  vector<int> r,c;
  for(int i = 1; i <= h; ++i)if(maxr == cntr[i])r.push_back(i);
  for(int i = 1; i <= w; ++i)if(maxc == cntc[i])c.push_back(i);
  int cntd = 0;
  for(auto e:b)
    cntd += binary_search(r.begin(),r.end(),e.first)&&binary_search(c.begin(),c.end(),e.second);
  cout << maxr + maxc - (cntd == (ll)r.size()*(int)c.size()) << endl;
}


Measured memory_bytes: 11988
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[] price = {0, 6000, 4000, 3000, 2000};
    int t, n;

    void run(){
	while(sc.hasNext()){
	    t = sc.nextInt();
	    n = sc.nextInt();
	    System.out.println(price[t] * n);
	}
    }
}

Measured memory_bytes: 17224
def main():
    n = int(input())
    *a, = map(int, input().split())
    b = list(map(int, input().split())) + [0]

    n_monster = 0
    for i in range(n+1):
        if i == 0:
            n_monster += min(a[i], b[i])
        else:
            n_monster += min(a[i], b[i-1] + b[i])
        b[i] -= min(max(0, a[i] - b[i-1]), b[i])
    print(n_monster)


main()


Measured memory_bytes: 19156
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <string>
#include <tuple>
#include <climits>
#include <cmath>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
const int INF = 987654321;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

int main(){
    ll n;
    scanf("%lld",&n);
    n--;
    vector<char> ans;
    while(n>=0){
        int ch = n%26;
        ans.push_back('a'+ch);
        n/=26;
        n--;
    }
    for(int i = ans.size()-1;i>=0;i--){
        printf("%c",ans[i]);
    }
    printf("\n");
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int L,R;
  cin >> L >> R;
  int ans;
  if(R-L+1>=2019){
    ans=0;
  }
  else{
    int x=L%2019;
    int y=R%2019;
   int a=2019;
  for(int j=x+1;j<=y;j++){
    for(int i=x;i<j;i++){
      if((i*j)%2019<a){
        a=(i*j)%2019;
      }
    }
  }
    ans=a;
  }
      cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  string c = to_string(N);
  int i = -1;
  while(c[++i]!='\0'){
    if(c[i]=='7'){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}

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

int main(){
    int s; cin >> s;
    int i = 0;
    for(;; i++){
        if(i){
            if(s%2) s = 3 * s + 1;
            else s /= 2;
        }
        if((s==4) || (s==2) || (s==1)) break;
    }
    cout << i + 4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s[0]==s[1] or s[1]==s[2] or s[2]==s[3])puta("Bad");
	else puta("Good");
	return 0;
}

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

int check(vector<int>& hand){
	int winner =-1;
	for(int i=0;i<hand.size();i++){
		if(hand[i]!=0){
			if(winner==-1){
				winner=i;
			}else{
				return -1;
			}
		}
	}
	return winner;
}

int main(){
	while(true){
		int n,p,pos=0;
		vector<int> hand;
		cin>>n>>p;
		if(n==0)break;
		hand.resize(n);
		while(true){
			int tmp;
			tmp=p/n;
			for(vector<int>::iterator it=hand.begin();it!=hand.end();++it)*it+=tmp;
			for(tmp=p%n;tmp>0;tmp--){
				hand[pos]++;
				pos==n-1?pos=0:pos++;
			}
			tmp=check(hand);
			if(tmp!=-1){
				cout<<tmp<<endl;
				break;
			}
			p=hand[pos];
			hand[pos]=0;
			pos==n-1?pos=0:pos++;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
import java.lang.Math.sqrt

fun main(args: Array<String>) {
    var x = readInt()
    while (!isPrime(x)) {
        x++
    }
    println(x)
}


// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

// 素数判定
fun isPrime(num: Int): Boolean {
    if (num < 2) return false
    if (num == 2) return true
    if (num % 2 == 0) return false
    val sqrtNum = sqrt(num.toDouble())
    var i = 3
    while (i <= sqrtNum) {
        if (num % i == 0) return false
        i += 2
    }
    return true
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a*100 + b*10 + c) % 4 == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
        fastio;

        double w,h,x,y;
        cin>>w>>h>>x>>y;
        cout<<fixed<<setprecision(12);
       cout<<(w*h)/2<<' ';
       if(x==(w/2)&&y==(h/2))
        cout<<1<<endl;
    else
        cout<<0<<endl;
    }

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, m;
    cin >> n >> m;

    ll res = 0;
    if(2*n < m){
        res += n;
        m -= 2*n;
        res += m/4;
    }else{
        res += m/2;
    }

    cout << res << endl;

    return 0;
}

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


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

int main(){
    int ans = 0;
    //vector<int> arr(5);
    for(int i = 0; i < 5; ++i){
        int tmp;
        cin >> tmp;
        if(tmp == 0){
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a;
  if(n>a) k=n;
  else k=a;
  ll ans=k;
  if(k==a) a--;
  else n--;
  if(a>n) k=a;
  else k=n;
  ans+=k;
  cout<<ans;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
string s;
cin>>s;
int i,j,r=0;
for ( i=0;i<s.length();i++)
{
    if (s[i]=='A'){

        for (j=s.length()-1;j>i+1;j--   )
            {
            if (s[j]=='Z'){

            break;


        }}

        break;



}}
                r=j-i+1;
cout<<r<<endl;
return 0;
}


Measured memory_bytes: 640
if __name__ == "__main__":
    A, B, C, X, Y = list(map(int, input().split()))
    ans = 0
    if (A + B) >= 2*C:
        # ABピザ2枚買ってAとBに分けた方がお得
        if (A >= B):
            if (B >= 2*C):
                # 全部ABの方がお得
                if X >= Y:
                    ans += (2*C) * X
                    print(ans)
                    exit()
                else:
                    ans += (2*C) * Y
                    print(ans)
                    exit()
            elif (A >= 2*C):
                # Aの分はABピザで買ったほうがお得
                ans += (2*C) * X
                if Y >= X:
                    ans += A * (Y - X)
                print(ans)
                exit()
            else:
                # 枚数が少ない方をABで買う
                if X >= Y:
                    ans += (2*C) * Y
                    ans += A * (X - Y)
                else:
                    ans += (2*C) * X
                    ans += B * (Y - X)
                print(ans)
                exit()
        else:
            if (A >= 2*C):
                if X >= Y:
                    # 全部ABの方がお得
                    ans += (2*C) * X
                    print(ans)
                    exit()
                else:
                    # 全部ABの方がお得
                    ans += (2*C) * Y
                    print(ans)
                    exit()
            elif (B >= 2*C):
                # Bの分はABピザで買ったほうがお得
                ans += (2*C) * Y
                if X >= Y:
                    ans += A * (X - Y)
                print(ans)
                exit()
            else:
                # 枚数が少ない方をABで買う
                if X >= Y:
                    ans += (2*C) * Y
                    ans += A * (X - Y)
                else:
                    ans += (2*C) * X
                    ans += B * (Y - X)
                print(ans)
                exit()
    else:
        # 普通に買ったほうがよい
        ans += A * X + B * Y
        print(ans)
        exit()


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    int n, sum=0;
    cin >> n;
    vector<pair<int,int>> v(n);
    for (auto && value : v)
    {
        cin >> value.first >> value.second;
        sum += value.second - value.first + 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1

void Print(int);
int depth(int, int);

struct Node{
  int parent, left, right;
};

struct Node Tree[MAX];

int Depth[MAX];

int main(){
  int n,i,j,num,dep,c,l,r;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&num,&dep);
    for(j = 0 ; j < dep ; j++){
      scanf("%d",&c);
      if(j == 0) Tree[num].left = c;
      else Tree[l].right = c;
      l = c;
      Tree[c].parent = num;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    if(Tree[i].parent == NIL) r = i;
  }

  depth(r,0);
 
  for(i = 0 ; i < n ; i++) Print(i);

  //printf("\n");
  
  return 0;
}

void Print(int x){
  int i,c;

  printf("node %d: ",x);
  printf("parent = %d, ",Tree[x].parent);
  printf("depth = %d, ",Depth[x]);

  if(Tree[x].parent == NIL) printf("root, ");
  else if(Tree[x].left == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i = 0, c = Tree[x].left ; c != NIL ; i++, c = Tree[c].right){
    if(i > 0) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int depth(int x, int y){
  Depth[x] = y;
  if(Tree[x].right != NIL) depth(Tree[x].right, y);
  if(Tree[x].left != NIL) depth(Tree[x].left ,y+1);
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define CIN>>x scanf("%lld",&x);
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
	float a,b;
    cin >> a>>b;
	x=a/0.08+0.999;
	y=b/0.1+0.999;
	z=(a+1)/0.08;
	w=(b+1)/0.1;

	if(max(x,y)>=min(z,w))cout<<-1<<endl;
	else cout<<max(x,y)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll ruiseki[n+1];
ll w;
ruiseki[0]=0;
for(int i=0;i<n;i++){
    cin>>w;
    ruiseki[i+1]=ruiseki[i]+w;
}
ll ans=infll;
for(int i=0;i<n;i++){
chmin(ans,abs(ruiseki[i]-(ruiseki[n]-ruiseki[i])));
}
cout<<ans<<endl;

}











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

int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
		return 0;
	}
	if (a.size() < b.size()) {
		cout << "LESS" << endl;
		return 0;
	}
	for (int i = 0; i < a.size(); i++) {
		if (a[i] > b[i]) {
			cout << "GREATER" << endl;
			return 0;
		}
		if (a[i] < b[i]) {
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
	return 0;
}

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

int main() {
	int x,n;cin>>x>>n;
	vector<int> p(n);
	vector<int> exist(102,0);
	for(int i=0;i<n;i++){
		cin>>p[i];
		exist[p[i]]=1;
	}
	for(int i=0;i<=101;i++){
		if(exist[x-i]==0){
			cout<<x-i<<endl;
			return 0;
		}
		if(exist[x+i]==0){
			cout<<x+i<<endl;
			return 0;
		}

	}


	return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += p[i];
            max = Math.max(p[i], max);
        }
        sum -= max / 2;
        System.out.println(sum);
    }

}


Measured memory_bytes: 21716
#include<iostream>
#include<cstring>
using namespace std;
int X, Y;
int c[17][17];
int dp[17][17];
int solve(int x, int y, int bx);
int main(){
  long long int ans;
  while(1){
    ans = 0;
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < Y; i++){
      for(int j = 0; j < X; j++){
	cin >> c[i][j];
      }
    }
    for(int i = 0; i < X; i++){
      ans += solve(i, 0, i); 
    }
    cout << ans << endl;
  }
}

int solve(int x, int y, int bx){
  if(x < 0 || x >= X || c[y][x] == 1 || c[y][x] == 2 && x != bx) return 0;
  if(y >= Y - 1) return 1;
  if(dp[y][x] > 0) return dp[y][x];
  if(bx == x && c[y][x] == 2) return solve(x, y + 2, x);
  else if(c[y][x] == 0) return dp[y][x] = solve(x - 1, y + 1, x) + solve(x, y + 1, x) + solve(x + 1, y + 1, x);
}

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

int main(){
  int i,j,cnt;
  string s;
  cin>>s;
  for(i=0;i<s.size();i++){
    if(i%2==0 && s[i]=='L'){
      cout<<"No";
      return 0;
    }
    if(i%2==1 && s[i]=='R'){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod = 1000000007


def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
    denom = pow(reduce(lambda x, y: x * y % mod, range(1, r + 1), 1), mod - 2, mod)
    return numer * denom % mod


def solve():
    pass


def main():
    a, b, c, d = map(int, input().strip().split())
    ans=-1*sys.maxsize
    for x in [a, b]:
        for y in [c, d]:
            ans = max(ans, x * y)
    print(ans)


if __name__ == '__main__':
    main()


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A[3][3];
int N;
int B[100];
bool ok[3][3];

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

  for(int i=0;i<3;++i){
      for(int j=0;j<3;++j){
          std::cin >> A[i][j];          
      }
  }

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> B[i];

      for(int j=0;j<3;++j){
          for(int k=0;k<3;++k){
              if(A[j][k] == B[i]){
                  ok[j][k] = true;
              }
          }
      }
  }
  
  bool f = ok[0][0] && ok[1][1] && ok[2][2] || ok[0][2] && ok[1][1] && ok[2][0];

  for(int i=0;i<3;++i){
      if(ok[i][0] && ok[i][1] && ok[i][2] ||
         ok[0][i] && ok[1][i] && ok[2][i]){
          f = true;
      }
  }

  if(f){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int x;
  cin>>x;
  if(x==3||x==5||x==7)cout<<"YES";
  else cout<<"NO";

}


Measured memory_bytes: 256