akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
struct box{
  int c,e;
};
int dp[10010];
int main(){
  int m,n;
  cin>>m>>n;
  int p[m],sum[m+1];
  sum[0]=0;
  box b[n];

  for(int i=0;i<m;i++)cin>>p[i];
  for(int i=0;i<n;i++)cin>>b[i].c>>b[i].e;

  sort(p,p+m,greater<int>());
  for(int i=0;i<m;i++)sum[i+1]=sum[i]+p[i];
  for(int i=0;i<=m;i++)dp[i]=1e9;
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=m+b[i].c;j>=b[i].c;j--){
      int next=min(j,m);
      dp[next]=min(dp[next],dp[j-b[i].c] + b[i].e);
    }
  }
  int ans=0;
  for(int i=0;i<=m;i++)ans=max(ans,sum[i]-dp[i]);
  cout << ans << endl;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N, M;
  cin >> N >> M;
  cout << min(N%M, M-N%M) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,i,a[105],m;
	int s=0,y=0;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	int q;
	if(s%(4*m)!=0)
	 q=s/(4*m)+1;
	 else
	 q=s/(4*m);
	for(i=1;i<=n;i++)
	{
		if(a[i]>=q)
		y++;
	}
	if(y>=m)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}


int main(){
    int n;
    cin >> n;
    vector<vi> es(n);
    rep(i, n) {
        int x, k;
        cin >> x >> k;
        --x;
        rep(j, k) {
            int y;
            cin >> y;
            --y;
            es[x].pb(y);
        }
    }
    vi in(n);
    vi out(n);
    int cnt = 0;
    vi used(n);
    function<void(int)> dfs = [&] (int cur) {
        if(used[cur]) return;
        used[cur] = true;
        in[cur] = ++cnt;
        for(auto&& to : es[cur]) dfs(to);
        out[cur] = ++cnt;
    };
    rep(i, n) if(used[i] == 0) dfs(i);
    rep(i, n) {
        cout << i+1 << " " << in[i] << " " << out[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
  int i,n,a[1050],mi,ma;mi=1050;ma=0;
  memset(a,0,sizeof(a));
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
  for(i=1;i<=n;i++)
  {
      if(a[i]>ma)
        ma=a[i];
      if(a[i]<mi)
        mi=a[i];
  }
  printf("%d",ma-mi);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main(){
    int A,B;
    cin >> A >> B;
    // 2 3 4 5 6 7
    if(A%2 == 0 && B%2 == 0) {
        int cnt = B-A;
        cnt/=2;
        if(cnt%2 == 0) {
            cout << B << endl;
        }
        else {
            int ans = 1;
            ans^=B;
            cout << ans << endl;
        }
    }
    // 2 3 4 5
    else if(A%2 == 0 && B%2 == 1) {
        int cnt = B-A+1;
        cnt/=2;
        if(cnt%2 == 0) {
            cout << 0 << endl;
        }
        else {
            cout << 1 << endl;
        }
    }
    // 3 4 5 6
    else if(A%2 == 1 && B%2 == 0) {
        int cnt = B-A-1;
        cnt/=2;
        if(cnt%2 == 0) {
            int ans = A^B;
            cout << ans << endl;
        }
        else {
            int ans = 1;
            ans^=A;
            ans^=B;
            cout << ans << endl;
        }
    }
    // 3 4 5 6 7
    else {
        int cnt = B-A;
        cnt/=2;
        if(cnt%2 == 0) {
            cout << A << endl;
        }
        else {
            int ans = 1;
            ans^=A;
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3604
MOD = 1000000007
def powmod(x, y):
  res = 1
  for i in range(y):
    res = res * x % MOD
  return res

n = int(input())
ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n)
ans = ans % MOD
ans = (ans + MOD) % MOD
print(ans)

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

int main(void){
    string s;
    while(true){
        cin >>s;
        if(s=="0"){
            break;
        }
        int d=0;
        for(int i=0;i<s.size();i++){
            int n=s[i];
            int x=n-48;
            d+=x;
        }
        cout <<d<<endl;
    }
    
}



Measured memory_bytes: 3172
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

//ll mod = 1000000007;
ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}



int main() {
	int k;
	string s;
	cin >> k >>s;
	for (int i = 0; i < min(k,(int)s.size()); i++) {
		cout << s[i];
	}
	if (s.size() > k)cout << "...";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF (1<<30)
using namespace std;
typedef long long ll;
static const ll MAX=1000000000;
static const int NMAX=200;
int N;
int ans=INF;
ll a;

int cunt2(ll n){
    int cunt=0;
    while(!(n%2)){
        n/=2;
        cunt++;
    }
    return cunt;
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a;
        ans=min(ans,cunt2(a));
    }

    cout<<ans<<"\n";

    return 0;
}



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

int main(){
    int V[20] = {0};
    int C[20] = {0};
    int N = 0;
    cin>>N;
    
    for(int i = 0;i < N;i++){
        cin>>V[i];
    }
    
    for(int i = 0;i < N;i++){
        cin>>C[i];
    }
    
    int res = 0;
    
    for(int i = 0; i < N;i++){
        if (V[i] > C[i]){
            res += V[i] - C[i];
        }
    }
    
    cout<<res;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>

using namespace std;

typedef pair<int, int> P;

int n;
priority_queue<P> pq;
set<int> idxs;
long long ans;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    pq.push(P(p, i));
  }
  
  while (pq.size()) {
    int p = pq.top().first;
    int idx = pq.top().second;
    pq.pop();
    
    int w, x, y, z;
    w = x = -1;
    y = z = n;
    
    idxs.insert(idx);
    auto it = idxs.find(idx);
    
    if (it != idxs.begin()) {
      x = *prev(it);
      if (prev(it) != idxs.begin()) {
        w = *prev(it, 2);
      }
    }
    
    if (it != prev(idxs.end())) {
      y = *next(it);
      if (next(it) != prev(idxs.end())) {
        z = *next(it, 2);
      }
    }
    
    ans += p*((long long)(x-w)*(y-idx)+(idx-x)*(z-y));
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <map>

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

  std::multimap<unsigned long, unsigned long, std::less<unsigned long>> BA_map;
  for (unsigned long i = 0; i < N; ++i) {
    unsigned long A, B;
    std::cin >> A >> B;
    BA_map.emplace(B, A);
  }

  unsigned long current_time = 0;

  for (const auto BA : BA_map) {
    const unsigned long B = BA.first;
    const unsigned long A = BA.second;
    current_time += A;
    if (B < current_time) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 12800
s = raw_input()
k = int(raw_input())


s_l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

def s_i(st):
    for i in range(26):
        if st == s_l[i]:
            return i + 1
            break

j = 0
while k > 0 and j <= len(s)-1:
    a = s_i(s[j])
    if s[j] == 'a' and j < len(s)-1:
        pass
    elif 27 - a <= k and j < len(s)-1:
        k = k - (27 - a)
        s = s[:j] + 'a' + s[j+1:]
    elif j == len(s) - 1:
        t = (a+k)%26 - 1
        if t >= 0:
            s = s[:j] + s_l[t]
        else:
            s = s[:j] + s_l[t + 26]
        break
    else:
        pass
    j += 1

print s


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  string T;
  cin >> T;

  rep(i, T.size()) {
    if (T[i] == '?') {
      cout << "D";
    } else {
      cout << (T[i]);
    }
  }
  ENDL;
  return 0;
}

Measured memory_bytes: 3848
#include<stdio.h>
int main(void)
{
	int tate, yoko, menseki, nagasa;
	scanf("%d%d", &tate, &yoko);

	menseki = tate*yoko;
	nagasa = tate * 2 + yoko * 2;

	printf("%d %d\n", menseki, nagasa);

	return 0;
}


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

int main()
{
  int before=0,after;
  int count=0;
  int tmp=1;
  int N;

  cin>>N;
  for(int i=0;i<N;i++)
  {
    cin>>after;
    if(before==after)
    {
      tmp++;
    }
    else
    {
      count+=tmp/2;
      tmp=1;
    }
    before=after;
  }
  if(tmp>1) count+=tmp/2;
  cout<<count<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

module Primes =
    let mutable primes = [7; 5; 3; 2]
    let mutable upper_bound = 7

    let rec create (n : int) : int list =
        for i = upper_bound + 1 to n do
            if isPrime i then
                primes <- i :: primes
            upper_bound <- i
        done
        List.filter ((>=) n) primes

    and isPrime (n : int) : bool = 
        n / 2
        |> create
        |> List.forall (fun p -> n % p <> 0)

    let factorize (n : int) : int list =
        let rec doit (n : int) (primes : int list) (factors : int list) : int list =
            match primes with
            | hp::tp when n % hp = 0 -> doit (n / hp) primes (hp::factors)
            | hp::tp -> doit n tp factors
            | [] -> factors
        let primes = create n
        doit n primes []

let n = ParseInt1 <| Console.ReadLine()
let primes = Primes.create n
let counts = new System.Collections.Generic.Dictionary< int, int>()
primes
|> List.iter (fun p -> counts.[p] <- 1)
counts.[1] <- 1

[2 .. n]
|> List.map Primes.factorize
|> List.iter (fun ps -> List.iter (fun p -> counts.[p] <- counts.[p] + 1 ) ps )

counts.Values
|> Seq.fold (fun acc c -> (acc * int64(c)) % 1000000007L) 1L
|> Console.WriteLine


Measured memory_bytes: 15708
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int x;
    cin >> x;

    int ans = x/11*2;
    x%=11;
    if(x>0){
        ans++;
        x-=6;
    }
    if(x>0){
        ans++;
        x-=5;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!
int wwa[2000000], bwa[2000000];
int A[1000000];
int ma[1000000];
signed main() {
	int N;
	cin >> N;
	int minum = 0;
	rep(i, N) cin >> A[i];
	rep(i, N) if (A[i] < 0) minum++;

	int sum = 0;
	int miniAbs = LL_HALFMAX;
	rep(i, N) {
		sum += abs(A[i]);
		if (abs(A[i]) < miniAbs) {
			miniAbs = abs(A[i]);
		}
	}

	
	int ans = 0;
	if (minum % 2 == 0) ans = sum;
	else ans = sum - miniAbs*2;

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


void solve()
{
    ll n,m,x;
    cin>>n>>m>>x;
    ll a[n][m];
    ll c[n];
    ll mini=1e18;
    ll i,j;
    for(i=0;i<n;i++)
    { 
         cin>>c[i];
         for(j=0;j<m;j++)
         {
             cin>>a[i][j];
         }
    }

    ll la=(1ll<<n);
    
    for(i=0;i<la;i++)
    {  
         ll al[m];
         clr(al);
         ll f=0;
         ll no=i;
        //  cout<<no<<"\n";
         bitset<64> b(no);
         ll tempc=0;
         for(j=0;j<n;j++)
         {
             if(b[j]==1)
             {
                 tempc+=c[j];
                 ll ii;
                 for(ii=0;ii<m;ii++){
                     al[ii]+=a[j][ii];
                 }
             }
         }

         for(j=0;j<m;j++)
         {
             if(al[j]<x)
             {
                 f=1;
                 break;
             }
         }
         if(f==0)
         {
             mini=min(mini,tempc);
         }
    }

    if(mini==(1e18))
    {
        cout<<"-1\n";
        return;
    } 
    else{
        cout<<mini<<"\n";
    }
    
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

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

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	if (a + b < 2 * c) {
		cout << x*a + y*b << endl;
		return 0;
	}
	int mv = min(x, y);
	int dif = abs(x - y);
	int ans = mv * 2 * c;
	if (mv == x) {
		ans += min(b*dif, 2 * c*dif);
	}
	else {
		ans += min(a*dif, 2 * c*dif);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
int n,m;
ll a[N];
ll mp[N];
 
bool cmp(ll x,ll y){
	return abs(x)<abs(y);
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
  	cin>>n>>m;
  	for(int i=1;i<=n;++i){
  		cin>>a[i];
  		if(a[i]>=0) mp[1]++;
  		else mp[2]++; 
  	}
  	int l=1,r=n;
  	ll ans=1;
  	if(mp[1]==0 && m%2==1){
  		sort(a+1,a+1+n,cmp);
  		for(int i=1;i<=m;++i){
  			ans=a[i]*ans%mod;
  		}
  	}
  	else{
  		sort(a+1,a+1+n,greater<int>());
  		while(m>0){
  			if(m%2==1) ans=ans*a[l++]%mod,m--;
  			else if(m>=2){
  				if(a[l]*a[l+1]>=a[r]*a[r-1]){
  					ans=ans*a[l]%mod*a[l+1]%mod;
  					l+=2;
  					m-=2;
  				}
  				else{
  					ans=ans*a[r-1]%mod*a[r]%mod;
  					r-=2;
  					m-=2;
  				}
  			} 
  		}
  	}

  	cout<<(ans%mod+mod)%mod<<endl;

    return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  
  int ar[100009];
  int palanty[100009];
  int accept=0;
  int palantyy=0;
  for(int i=0;i<=n;i++){
    ar[i]=0;
    palanty[i]=0;
  }
  int t;
  string s;
  for(int i=0;i<m;i++){
    cin>>t>>s;
    if(s=="AC" && ar[t]==0){
      ar[t]=1;
      accept++;
      palantyy+=palanty[t];
    }
    else if(ar[t]==0){
      palanty[t]+=1;
    }
  }
  cout<<accept<<" "<<palantyy<<"\n";
 
  return 0;
}


Measured memory_bytes: 1024
import sys

import numpy as np

input = lambda: sys.stdin.readline().rstrip()
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = np.zeros(S + 1, np.int64)
dp[0] = 1
for a in A:
    f = 2 * dp
    f[a:] += dp[:-a]
    f %= MOD
    dp = f

print(dp[S])


Measured memory_bytes: 27460
using namespace std;
#include<deque>
#include<stdint.h>
#include<set>
#include<stack>
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#define sqr(x) (x)*(x)
#define ll long long
#define mp make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mp(mp(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt"):
#define fast ios::sync_with_stdio(false);
/*************************************************/
long long n,ans,x,i;
int main()
{
	cin>>n>>ans;
	for (i=2;i<=n;i++)
	{
		cin>>x;
		ans*=x/(__gcd(ans,x));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAX (long long)1000000000000000000

using namespace std;

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long llres = 1;
    double dres = 1;
    
    for (int i = 0; i < n;i++) {
        llres *= a[i];
        dres *= a[i];
        if ((dres > MAX)|| (llres > MAX)) {
            cout << -1 << endl;
            return 0;
        }
    }
     
    cout << llres << endl;

    return 0;
}

Measured memory_bytes: 4048
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    static Scanner in = new Scanner(System.in);
//    static Scanner in;
//
//    static {
//        try {
//            in = new Scanner(new FileInputStream("./E_sub1_17.txt"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//    }

    static long gcd(long x, long y) {
        if (y == 0) return x;
        return gcd(y, x%y);
    }

    static long modPow(long x, long mod) {
        if (x == 0) return 1;
        long r = modPow(x / 2, mod);
        long ret = (r * r) % mod;
        if (x % 2 != 0) ret = (ret * 2) % mod;
        return ret;
    }

    static void run() {
        long mod = 1000000007;
        int n = in.nextInt();
        Map<Long, Map<Long, Long>> m = new HashMap<>();
        int ab0 = 0;
        int a0 = 0, b0 = 0;
        for (int i=0;i<n;i++) {
            long a = in.nextLong(), b = in.nextLong();
            if (a == 0 && b == 0) ab0++;
            else if (a == 0) {
                a0++;
            } else if (b == 0) {
                b0++;
            } else {
                int sign = (a >= 0 && b >= 0 || a <= 0 && b <= 0) ? 1 : -1;
                a = Math.abs(a);
                b = Math.abs(b);
                long g = gcd(a, b);
                a /= g; b /= g;
                Map<Long, Long> mm = m.computeIfAbsent(sign*a, k->new HashMap<>());
                mm.put(b, mm.getOrDefault(b, 0L) + 1);
            }
        }
        Map<Long, Set<Long>> used = new HashMap<>();
        long ret = 1;
        ret = (ret * (modPow(a0, mod) + modPow(b0, mod) - 1)) % mod;
        for (long a : m.keySet()) {
            for (long b : m.get(a).keySet()) {
                if (used.containsKey(a) && used.get(a).contains(b)) continue;
                Long x = m.get(a).get(b);
                long y = 0;
                long sign = a > 0 ? 1 : -1;
                if (m.containsKey(-sign*b) && m.get(-sign*b).containsKey(sign*a)) {
                    used.computeIfAbsent(-sign*b, k -> new HashSet<>()).add(sign*a);
                    y = m.get(-sign*b).get(sign*a);
                }
                long r = (modPow(x, mod) + modPow(y, mod) - 1) % mod;
                ret = (ret * r) % mod;
            }
        }
        ret--;
        ret += ab0;
        ret = (ret + mod) % mod;
        System.out.println(ret);
    }

    public static void main(String[] args) {
        run();
    }
}


Measured memory_bytes: 128932
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, M, C, B[20];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> C;
    rep(i, 0, M) cin >> B[i];
    
    int ans = 0;
    rep(i, 0, N) {
        int sm = C;
        rep(j, 0, M) {
            int a; cin >> a;
            sm += B[j] * a;
        }
        if (0 < sm) ans++;
    }
    cout << ans << endl;

}




Measured memory_bytes: 256
s = input()
s = s[0:len(s)-2]
while True:
	count = len(s)
	n = count // 2
	front_s = s[0:n]
	back_s = s[n:count]
	if front_s == back_s:
		break
	s = s[0:count-2]
print(len(s))

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

int main(){
    int a,b;
    cin >> a >> b;
    int n;
    if(b / 10 == 0){
        a = a * 10;
    }else if(b / 100 == 0){
        a = a * 100;
    }else{
        a = a * 1000;
    }
    n = a + b;
    for(int i=0; i!=100000; i++){
        if(n == i * i){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


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

UL N;
int A[250];

int main() {
 scanf("%u",&N);
 rep(i,N) scanf("%d",&A[i]);
 rep(i,N){
  printf("node %u: key = %d, ",i+1,A[i]);
  if(i!=0) printf("parent key = %d, ",A[(i-1)>>1]);
  if((i<<1)+1<N) printf("left key = %d, ",A[(i<<1)+1]);
  if((i<<1)+2<N) printf("right key = %d, ",A[(i<<1)+2]);
  printf("\n");
 }
 return 0;
}



Measured memory_bytes: 3212
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
int main(){
  int N,K;
  cin >> N >> K;
  long long x[N],y[N];
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] ;
  }
  long long ans = 4000000000000000000;
  for(int  i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      for(int k = 0; k < N; k ++){
        for(int l = 0; l < N; l++){
          if(x[i] > x[j] || y[k] > y[l]) continue;
          int cnt = 0;

          for(int m = 0; m < N; m++){
            if(x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]){
              cnt ++;
            }
          }
          if(cnt >= K){
            //cout << abs(x[i] - x[j]) * abs(y[k] - y[l]) << endl;
            ans = min(ans, abs(x[i] - x[j]) * abs(y[k] - y[l]) );
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (x, y): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let g: std::collections::HashSet<i64> = vec![4, 6, 9, 11].into_iter().collect::<_>();
    let ans = if x == y || g.contains(&x) && g.contains(&y) || x != 2 && y != 2 && !g.contains(&x) && !g.contains(&y) {
        "Yes"
    } else {
        "No"
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n = I()
A = LI()

for a in A:
    if a % 2 == 0:
        if a % 3 != 0 and a % 5 != 0:
            print("DENIED")
            exit()

print("APPROVED")

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int a, b; cin >> a >> b;
        int ans = a - 1;
        if (b >= a) ans++;
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

string s, t;
long long m;
long long p[100000];

int main()
{	
	cin >> s >> t;

	long long w = s.size();

	s = s + s;

	for (int i = 0; i < t.size(); i++) {
		if (s.find_first_of(t[i]) == std::string::npos) {
			m = -1;
			break;
		}
		else {
			if (i == 0) {
				p[0] = s.find_first_of(t[0]);
				m = p[0] + 1;
			}
			else {
				long long u = s.find_first_of(t[i], p[i - 1] + 1);

				p[i] = u % w;
				m += u - p[i - 1];
			}
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <set>
int main()
{
    int a;
    int b;
    int c;
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;

    int e = 0;
    for (int k = b; k >= a; k--)
    {
        if (c % k == 0)
        {
            e++;
        }
    }
    std::cout << e << "\n";

    return 0;
}


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

void fnInput(string& rsTarget)
{
  cin >> rsTarget;
}

int fnParse(string sTarget)
{
  const vector<string> cnvsWord{"dream", "dreamer", "erase", "eraser"};
  int ixBgn, ixEnd;
  ixBgn = sTarget.size();

  while (ixBgn)
  {
    bool bRslt = false;
    ixEnd = ixBgn;
    for (int i = 0; i < cnvsWord.size(); i++)
    {
      ixBgn = ixEnd - cnvsWord[i].size();
      if (ixBgn < 0)  continue;

      if (sTarget.substr(ixBgn, cnvsWord[i].size()) == cnvsWord[i])
      {
        bRslt = true;
        break;
      }
    }
    if (!bRslt)  return 0;
  }
  return 1;
}

int main()
{
  string sTarget;
  
  fnInput(sTarget);
  if (fnParse(sTarget)) cout << "YES" << endl;
  else                  cout << "NO"  << endl;

  return 0;
}

Measured memory_bytes: 512
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.List             as L
import qualified Data.Map              as M
import           Data.Maybe
import qualified Data.Set              as S
import qualified Data.Tuple            as T

addToSet :: (Num a, Ord a) => S.Set (a, Int) -> [(Int, a)] -> S.Set (a, Int)
addToSet set xs = L.foldl' (\ acc x -> S.insert (T.swap x) acc) set xs


addToMap :: Ord k => M.Map k a -> [(k, a)] -> M.Map k a
addToMap m xs = L.foldl' (\ acc (x, d) -> M.insert x d acc) m xs


dijkstra :: (Num a, Ord a) => M.Map Int [(Int, a)] -> Int -> M.Map Int a
dijkstra graph source = dijkstra' graph (S.singleton (0, source))
                        (M.singleton source 0)


dijkstra' :: (Ord t, Num t) => M.Map Int [(Int, t)]     -- ^ graph structure
          -> S.Set (t, Int)                             -- ^ priority queue
          -> M.Map Int t -> M.Map Int t                 -- ^ result
dijkstra' graph pq res
    | S.null pq = res
    | otherwise = dijkstra' graph (addToSet pq' info) (addToMap res info)
    where
      fwd = M.findWithDefault
      ((dis, node), pq') = S.deleteFindMin pq
      nodes = fwd [] node graph
      update = filter (\ (x, e) -> (fwd (-1) x res) == (-1) ||
                                   dis + e < (fwd (-1) x res)) nodes
      info = map (\ (x, e) -> (x, dis + e)) update


buildGraph :: Ord t => [(t, t1, t2)] -> M.Map t [(t1, t2)]
buildGraph edges =
    let g = L.groupBy (\ (x, _, _) (y, _, _) -> x == y) edges
    in M.fromList (map (\ x -> (f1 $ head x, map (\ (_, y, z) -> (y, z)) x)) g)

readInt' :: BS.ByteString -> Int
readInt' = fst . fromJust . BS.readInt

f1 :: (t, t1, t2) -> t
f1 (x, _, _) = x

f3 :: (t, t1, t2) -> t2
f3 (_, _, x) = x

main :: IO ()
main = do
  contents <- BS.lines <$> BS.getContents
  let edges = map (\ [x, y, z] -> (x, y, z))
              (map (\ x -> map readInt' (BS.words x)) contents)
      res = dijkstra (buildGraph $ L.sort $ tail edges) (f3 $ head edges)
      n = f1 $ head edges
  forM_ [0..(n - 1)] $ \i -> do
         if M.member i res
         then print (M.findWithDefault (-1) i res)
         else putStrLn "INF"

Measured memory_bytes: 256844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }



int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') ans = 0;
  if (s[0] == 'S' && s[1] == 'S' && s[2] == 'R') ans = 1;
  if (s[0] == 'S' && s[1] == 'R' && s[2] == 'S') ans = 1;
  if (s[0] == 'S' && s[1] == 'R' && s[2] == 'R') ans = 2;
  if (s[0] == 'R' && s[1] == 'S' && s[2] == 'S') ans = 1;
  if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') ans = 1;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'S') ans = 2;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') ans = 3;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
import sys
from bisect import bisect_right
input = lambda: sys.stdin.readline()[:-1]
from collections import defaultdict
s =input()
lenth=len(s)
ss=s*2
t =input()
place=defaultdict(list)

for k,l in enumerate(s):
	place[l].append(k+1)
	place[l].append(k+1+lenth)
for i in place.values():
	i.sort()
now=0
ans=0

for i in t:
	if not place[i]:
		print(-1)
		exit()
	mt=place[i][bisect_right(place[i],now)]
	if mt>lenth:
		mt-=lenth
		ans+=lenth
	now=mt
print(ans+now)

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, a;
    cin >> n >> a;

    cout << n*n-a << endl;
    return 0;
}


Measured memory_bytes: 256
n,m,x = map(int, input().split())

A = []
C = []
for i in range(n):
    Z = list(map(int, input().split()))
    C.append(Z[0])
    A.append(Z[1:])

ans = 10**12
for i in range(1<<n):
    rikai  = [0] * m
    cost = 0
    bs = bin(i)[2:]
    bs = bs.zfill(n)
    # print(bs)
    for j,b in enumerate(bs):
        if b == "1":
            # 本を購入
            cost += C[j]
            for k in range(m):
                rikai[k] += A[j][k]            
    a = sum([1 for r in rikai if r >= x])
    if a == m:
        ans = min(ans,cost)
print(ans if ans != 10**12 else -1)

Measured memory_bytes: 9128
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s;
    cin >> s;
    string r = s;
    reverse(r.begin(),r.end());
    REP(i,(int)r.size()) {
        if(r[i] != s[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    string t = "";
    int leng = (s.size() - 1)/2;
    REP(i,leng) {
        string tmp;
        tmp = s[i];
        t += tmp;
    }

    string r2 = t;
    reverse(r2.begin(),r2.end());
    REP(i,(int)r2.size()) {
        if(r2[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    string t2 = "";
    leng = (s.size()+3) /2 -1;
    FOR(i,leng,(int)s.size()) {
        string tmp;
        tmp = s[i];
        t2 += tmp;
    }

    string r3 = t2;
    reverse(r3.begin(),r3.end());
    REP(i,(int)r3.size()) {
        if(r3[i] != t2[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a[10001]={0};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long min=1000000,max=-1000000,sum=0;
    for(int i=0;i<n;i++){
        if(a[i]<min){
            min=a[i];
        }
        if(a[i]>max){
            max=a[i];
        }
        sum=sum+a[i];
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }

void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m);
}

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

	string S;
	cin>>S;

	if(S=="SUN") print(7);
	else if(S=="MON") print(6);
	else if(S=="TUE") print(5);
	else if(S=="WED") print(4);
	else if(S=="THU") print(3);
	else if(S=="FRI") print(2);
	else if(S=="SAT") print(1);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
ll nCr(ll n, ll r){
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
  ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
  return ret;
}

int main(void){
  ll n;
  cin>>n;
  vector<ll> sum,dp,hoge;
  ll ans = 0;
  dp.push_back(1);
  rep(i,n+10){
    sum.push_back(0);
  }
  sum.push_back(0);
  rep(i,n){
    dp[i] %= MOD;
    if(i==n-2){
      ans += dp[i] * (n-1);
      ans += dp[i] * (n-1) %MOD * (n-1);
    }else if(i==n-1){
      ans += dp[i] * n;
    }else{
      ans += dp[i] * (i+2);
      ans += dp[i] * (n-1) %MOD * (n-1);
    }

    ans %= MOD;
    dp.push_back(dp[i]);
    sum[i] %= MOD;
    dp[i] %= MOD;
    sum[i+1] += sum[i];
    dp[i+1] += sum[i+1];
    sum[i+3] += dp[i];
    hoge.push_back(ans);
  }
  hoge.push_back(-1);
  /*rep(i,n+1){
    cerr<<i<<" "<<dp[i]<<" "<<sum[i]<<" "<<hoge[i]<<endl;
  }*/
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<long long> arr;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    string a;
    int cant = -1;

    cin >> a;

    if(a.size() == 26){
        for(int pos = 25; pos > 0; pos--){
            for(int i = 0; i < 26; ++i){
                if(i <= a[pos - 1] - 97) continue;
                bool found = false;
                for(int j = 0; j < pos; ++j){
                    if(a[j] - 97 == i){
                        found = true;
                        break;
                    }
                }
                if(found == false){
                    cout << a.substr(0, pos - 1) << ((char) (i + 97));
                    return 0;
                }
            }
        }

        cout << -1;

        return 0;
    }

    for(int i = 0; i < 26; ++i){
        if(i == cant) continue;
        bool found = false;
        for(char j : a){
            if(j - 97 == i){
                found = true;
                break;
            }
        }
        if(found == false){
            cout << a << ((char) (i + 97));
            return 0;
        }
    }

    cout << -1;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MAX_N = 1e5;
long long n;
long long A[MAX_N+2] ={0};


long long  make_pair(int idx){
    long long  num_pair = (A[idx]+A[idx+1])/2;
    if(A[idx]<num_pair*2){
        A[idx+1] -= (num_pair*2 - A[idx]);
        A[idx] = 0;
    }
    else {
        A[idx] -= num_pair*2;
    }
    return num_pair;
}


void solve(){
    long long res=0;
    for(int i=1;i<=n;i++){
        res += make_pair(i);
    }

    printf("%lld",res);
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
    }
    solve();
    printf("\n");
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;


int main() {
  intll  n  ;
  cin >> n ;
  vector<intll> v(n) ;
  intll total = 0 ;
  rep(i,n){
    cin >> v.at(i) ;
    total += v.at(i) ;
  }
  intll ans = 0 ;
  
  for(int i=0;i<n;i++){
      total -= v.at(i)  ;
      ans += (v.at(i)%MOD) * (total%MOD) % MOD ;
      ans %= MOD ;
    }

  
  cout << ans ;
    
}


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

int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  
  if(a+b<c)
  {
    if(c!=0)
      cout << a+(2*b)+1;
    else
    	cout << a+(2*b);
  }
  else
    cout << b+c;
}


Measured memory_bytes: 256