akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class D
{
	public static void Main()
	{
		int H = getInt();
		int W = getInt();
		int N = getInt();
		int[] a = new int[N+1];
		for(int i = 1; i <= N; i++)
			a[i] = getInt();		
		
		int[,] c = new int[H,W];
		int color = 1;
		int rest = a[1];
		for(int i = 0; i < H; i++)
		{
			for(int j = 0; j < W; j++)
			{
				c[i,j] = color;
				rest--;
				if(rest > 0)
					continue;
				
				if(color == N)
					break;

				color++;
				rest = a[color];
			}			
		}

		for(int i = 0; i < H; i++)
		{			
			for(int j = 0; j < W; j++)
				Console.Write("{0} ", (i % 2 == 0) ? c[i,j] : c[i,W-j-1]);
			Console.WriteLine();
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int getInt(){ return int.Parse(getArg()); }
	public static long getLong(){ return long.Parse(getArg()); }
	public static double getDouble(){ return double.Parse(getArg()); }
	public static string getString(){ return getArg(); }
}


Measured memory_bytes: 13780
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
#define rip(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main() {
	int a, b; cin >> a >> b;
	string ans;
	if (a * b % 2 == 0) {
		ans = "Even";
	}
	else
	{
		ans = "Odd";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, x;
    cin >> N >> x;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll res = 0;
    for(int i = 1; i < N; i++) {
        if(A[i - 1] + A[i] > x) {
            res += A[i] - max(0LL, x - A[i - 1]);
            A[i] = max(0LL, x - A[i - 1]);
        }
        if(A[i] == 0 && A[i - 1] > x) {
            res += A[i - 1] - x;
            A[i - 1] = x;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{
    lint n, k;
    scanf("%lld", &n);
    scanf("%lld", &k);

    std::string s;
    std::cin >> s;

    std::vector<lint> line;
    std::vector<lint> line_state;

    lint stream = 0;
    lint state;

    if (s.front() == '0')
        state = 0;
    else
        state = 1;

    for (int i = 0; i < n; ++i)
    {
        if (s[i] == '0')
        {
            if (state == 0)
            {
                stream++;
            }
            else
            {
                line.push_back(stream);
                line_state.push_back(state);
                stream = 1;
                state = 0;
            }
        }
        else
        {
            if (state == 1)
            {
                stream++;
            }
            else
            {
                line.push_back(stream);
                line_state.push_back(state);
                stream = 1;
                state = 1;
            }
        }
    }
    line.push_back(stream);
    line_state.push_back(state);

    if (line_state.size() - std::accumulate(line_state.begin(), line_state.end(), 0) <= k)
    {
        printf("%lld", n);
        return 0;
    }
    else
    {
        std::vector<lint> line_cumsum(line.size());
        lint cumsum = 0;
        for (lint i = 0; i < line.size(); i++)
        {
            cumsum += line[i];
            line_cumsum[i] = cumsum;
        }

        lint ans = 0;
        lint cand;

        for (int i = 0; i < line.size(); i++)
        {
            lint right;
            lint left;
            if (line_state[i] == 0)
            {
                left = std::max(0, i - 1);
                right = std::min(i + 2 * int(k) - 1, int(line.size()) - 1);
            }
            else
            {
                left = i;
                right = std::min(i + 2 * int(k), int(line.size()) - 1);
            }

            if (right >= line.size())
                break;
            if (left == 0)
                cand = line_cumsum[right];
            else
                cand = line_cumsum[right] - line_cumsum[left - 1];
            ans = std::max(ans, cand);
        }
        printf("%lld", ans);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 2924
s = input()
n =int(len(s))
k1 = int((n-1) / 2)
k2 = int((n+3)/2)
median = int(n/2)
x = []
y = []
answer = 0

for i in  range(k1):
  x.append(s[i])

for i in range(k2-1,n):
  y.append(s[i])
  
for i in range(0,median):
  if x[i] == y[i]:
    answer += 1
if answer == median:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define plli pair<lli,lli>
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}
/*********************************reused****************************/

int main()
{
    string s,t;
    cin >>s>>t;
    int n = s.length();
    int k = t.length();
    bool found = true;
    int win = -1;
    for(int i=n-1;i>=0;i--){
        if(i<(k-1))
            break;
        found = true;
        for(int j=k-1;j>=0;j--){
            if(!(t[j]==s[i-(k-j-1)] || s[i-(k-j-1)]=='?')){
                found = false;
                break;
            }
        }
        if(found){
            win = i;
            break;
        }
    }
    if(win == -1){
        cout << "UNRESTORABLE"<<endl;
    }else{
        win = win-k+1;
        for(int i=0;i<n;i++){
            if(i==win){
                for(int j=0;j<k;j++){
                    cout<<t[j];
                    i++;
                }
                i--;
            }else{
                if(s[i]=='?')
                    cout<<'a';
                else
                    cout<<s[i];
            }
        }

        cout<<endl;
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  int sum;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if((a*b)%2 == 0 ){
      System.out.println("Even");
    }else{
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll vet[n+2];
    rep(i,0,n){
        cin>>vet[i];
    }
    ll ans=0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,j+1,n){
                vector<ll> nums(3);
                nums[0]=vet[i];
                nums[1]=vet[j];
                nums[2]=vet[k];
                sort(all(nums));
                if(vet[i]!=vet[j] && vet[j]!=vet[k] && vet[i]!=vet[k] && nums[0]+nums[1]>nums[2]){
                    // cout<<vet[i]<<" "<<vet[j]<<" "<<vet[k]<<endl;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<'\n';
    return 0;  
}   

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    map<ll,ll> m1;
    map<ll,ll> m2;
    m1[0];
    m2[0];
    for(ll i=0;i<N;i+=2){
        m1[A[i]]++;
    }
    for(ll i=1;i<N;i+=2){
        m2[A[i]]++;
    }
    ll m1_1=0,m1_2=0,kind_1;
    for(auto it=m1.bg;it!=m1.ed;it++){
        if((it->b)>m1_1){
            m1_1=(it->b);
            kind_1=(it->a);
        }
    }
    for(auto it=m1.bg;it!=m1.ed;it++){
        if((it->a)!=kind_1 && (it->b)>m1_2){
            m1_2=(it->b);
        }
    }
    ll m2_1=0,m2_2=0,kind_2;
    for(auto it=m2.bg;it!=m2.ed;it++){
        if((it->b)>m2_1){
            m2_1=(it->b);
            kind_2=(it->a);
        }
    }
    for(auto it=m2.bg;it!=m2.ed;it++){
        if((it->a)!=kind_2 && (it->b)>m2_2){
            m2_2=(it->b);
        }
    }
    
    ll L=N/2;
    if(kind_1!=kind_2){
        cout<<L*2-m1_1-m2_1<<endl;
    }
    else{
        cout<<min(L*2-m1_1-m2_2, L*2-m1_2-m2_1)<<endl;
    }
}



Measured memory_bytes: 10236
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    int a, b;
    cin >> a >> b;
    if(a>9 || b>9) cout << -1 << endl;
    else cout<< a*b << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u32,
    };
    for i in 0..26{
        for j in 0..15{
            if 4 * i + 7 * j == n {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(char, c);
    Cout((char)(c+1));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,d,i,cnt=0;
	double r,area,syu;
	scanf("%lf",&r);
	area = (double)r*r*M_PI;
	syu = (double)2*r*M_PI;
	printf("%f %f\n",area,syu);
	return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] s = new String[n];
      int[] p = new int[n];
      int[] index = new int[n];

      sc.nextLine();
      for (int i = 0; i < n; i++) {
        s[i] = sc.next();
        p[i] = sc.nextInt();
        index[i] = i + 1;
      }
      for(int i=0; i<n-1; i++){
        for(int j=0; j<n-1-i; j++){
          if(s[j].compareTo(s[j+1]) > 0){
            String temp=s[j];
            s[j]=s[j+1];
            s[j+1]=temp;
            int temp_p=p[j];
            p[j]=p[j+1];
            p[j+1]=temp_p;
            int temp_i=index[j];
            index[j]=index[j+1];
            index[j+1]=temp_i;
          } else if (s[j].compareTo(s[j+1]) == 0) {
            if (p[j] < p[j+1]){
              String temp=s[j];
              s[j]=s[j+1];
              s[j+1]=temp;
              int temp_p=p[j];
              p[j]=p[j+1];
              p[j+1]=temp_p;
              int temp_i=index[j];
              index[j]=index[j+1];
              index[j+1]=temp_i;
            }
          }
        }
      }
      for(int i=0; i<n; i++){
        System.out.println(index[i]);
      }
    }
  }

Measured memory_bytes: 23508
def main():
    s  = int(input())
    k = s//100
    t = s%100

    if(k>0 and k<13) and (t>0 and t<13):
        res = "AMBIGUOUS"
    elif(k>0 and k<13):
        res = "MMYY"
    elif(t>0 and t<13):
        res = "YYMM"
    else:
        res = "NA"
    print(res)






if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
    int t,h,s;
    while(cin >> t >> h >> s) {
        if(t == -1 && h == -1 && s == -1) break;
        int temp = 7200 - (3600 * t + 60 * h + s);
        int a,b,c;
        a = temp / 3600;
        b = temp / 60 % 60;
        c = temp % 60;
        printf("%02d:%02d:%02d\n",a,b,c);
        
        temp *= 3;
        a = temp / 3600;
        b = temp / 60 % 60;
        c = temp % 60;
        printf("%02d:%02d:%02d\n",a,b,c);
    }
    return 0;
}

Measured memory_bytes: 1160
// 2020-09-26 21:14:42
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
#include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
using mint = modint998244353;
mint memo[10][200020], memo10[200020];
struct S {
  mint a;
  int sz;
};
S op(S l, S r) { return S{l.a * memo10[r.sz] + r.a, l.sz + r.sz}; }
S e() { return S{0, 0}; }
using F = int;
S mapping(F f, S x) {
  if (f == 0) {
    return x;
  } else {
    return S{memo[f][x.sz], x.sz};
  }
}
F composition(F f, F g) {
  if (f == 0)
    return g;
  else
    return f;
}
F id() { return 0; }
void answer() {
  REPC(i, 1, 9) {
    memo[i][0] = 0;
    memo[i][1] = i;
    REPC(j, 2, 200000) { memo[i][j] = memo[i][j - 1] * 10 + i; }
  }
  memo10[0] = 1;
  memo10[1] = 10;
  REPC(j, 2, 200000) { memo10[j] = memo10[j - 1] * 10; }
  int n, q;
  cin >> n >> q;
  lazy_segtree<S, op, e, F, mapping, composition, id> st(n);
  rep(i, n) st.set(i, S{1, 1});
  rep(qi, q) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    st.apply(l, r, d);
    cout << st.all_prod().a.val() << '\n';
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 18516
package main

import (
	"fmt"
	"math"
)

func main() {
	var counter int
	fmt.Scanf("%d", &counter)
	arr := make([]int, counter, 10000)
	for i := 0; i < counter; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	IsPrime(arr)
}
func IsPrime(arr []int) {
	//var temp int
	n := 0
	var flag int
	for i, v := range arr {
		//temp = arr[i]
		flag = 1
		//if v!=2 && v!=3 {
		rt_v := int(math.Sqrt(float64(arr[i])))
		//fmt.Println(rt_v)
		for j := 2; rt_v >= j; j++ {
			if j > 2 && j%2 == 0 {
				continue
			}
			if v%j == 0 {
				flag = 0
				break
			}
			//fmt.Println(arr[i])
		}
		//fmt.Println("There is out of the loop")
		//}else{
		//	fmt.Println(arr[i])
		//}
		if flag == 1 {
			n++
			//fmt.Println(temp)
		}

	}
	fmt.Println(n)
}



Measured memory_bytes: 1772
# -*- coding: utf-8 -*-
"""
Social Game
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0652

"""
import sys
from math import ceil

def solve(a, b, c):
    q, r = divmod(c, (a*7 + b))
    return q * 7 + min(ceil(r / a), 7)


def main(args):
    a, b, c = map(int, input().split())
    ans = solve(a, b, c)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5684
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

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

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  ll tmp = (x + d - 1) / d;
  if (tmp > k) {
    //途中までしか近づけない
    if(x <= 0){
      x += k * d;
    }else{
      x -= k * d;
    }
    x = abs(0 - x);
  }else{
    ll xt1, xt2;
    if(x <= 0){
      xt1 = x + tmp * d;
      xt2 = x + (tmp - 1) * d;
    }else{
      xt1 = x - tmp * d;
      xt2 = x - (tmp - 1) * d;
    }
    if ((k - tmp) % 2 == 0) {
      x = abs(0 - xt1);
    }else{
      x = abs(0 - xt2);
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 3584
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val AB = rd.readListLongCols(N)

    val C = AB.mapIndexed{ i,ls ->
        i to ls[0]+ls[1]
    }.sortedByDescending { it.second }

    var ans = 0L
    for (i in 0 until N) {
        val idx = C[i].first
        if (i%2 == 0) {
            ans += AB[idx][0]
        } else {
            ans -= AB[idx][1]
        }
    }

    println(ans)
}


//val rd = debug.Reader("etc", "nikkei2019-qual", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 78992
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;

void solve()
{
   ll h,n,a,s=0;
   cin>>h>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a;
       s+=a;
   }
   if(s>=h)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n = gi

if n[0]+n[1] >=10
puts "error"
else
  puts (n[0]+n[1])
end

Measured memory_bytes: 4348
#include <stdio.h>
#include <string.h>
int main(void){
    char r[11],t[11],u[11];
    int a,b;
    scanf("%s %s %d %d %s",r,t,&a,&b,u);
    if(strcmp(r,u)==0) a--;
    else b--;
    printf("%d %d",a,b);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[100010];
ll V[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N + 1; i++) {
		cin >> A[i];
		//A[i] = 0;
	}
	if (N == 0 && A[0] != 1) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 0 && A[0] == 1) {
		cout << 1 << endl;
		return 0;
	}
	ll ans = 0;
	V[0] = 1;
	if (A[0] == 1) V[0]--;
	for (int i = 1; i < N + 1; i++) {
		V[i] = V[i - 1];
		if (V[i] < INF) V[i] *= 2;
		if(i != N) V[i] -= A[i];
	}
	if (V[N] < A[N]) {
		cout << -1 << endl;
		return 0;
	}
	V[N] = 0;
	for (int i = N - 1; i > 0; i--) {
		if (V[i] < (V[i + 1] + A[i + 1] + 1) / 2) {
			cout << -1 << endl;
			return 0;
		}
		if (V[i] > V[i + 1] + A[i + 1]) {
			V[i] = V[i + 1] + A[i + 1];
		}
	}
	for (int i = 0; i < N + 1; i++) {
		//cout << V[i] + A[i] << " " << V[i] << endl;
		ans += V[i] + A[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4792
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long X, c1 = 0, c2 = 0;

  std::cin >> X;

  c1 = X / 500;

  X -= c1 * 500;

  c2 = X / 5;

  std::cout << c1 * 1000 + c2 * 5 << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  a[0]=toupper(a[0]);
  b[0]=toupper(b[0]);
  c[0]=toupper(c[0]);
  cout<<a[0]<<b[0]<<c[0];
  return 0;
}

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

int main(void){
  int X;
  bool swi = false;
  cin >> X;
  if(X >= 30)
    swi = true;
  if(swi) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;


int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  string s;
  while (cin >> s) {
    int n = (int) s.size();
    int ans = n;
    for (int i = 0; i < n; i++) {
      char c = s[i];
      int last = 0;
      int cur = 0;
      for (int j = 0; j < n; j++) {
        if (s[j] == c) {
          cur = max(cur, j - last);
          last = j + 1;
        }
      }
      cur = max(cur, n - last);
      ans = min(ans, cur);
    }
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b) a>b?b:a
#define max(a,b) a>b?a:b

int main(){
    int n,i,x,y,k;

    scanf("%d%d",&n,&k);

    for(;k-->0;){
        scanf("%d%d",&x,&y);

        x--;y--;
        x=min(x,n-1-x);
        y=min(y,n-1-y);
        x=min(x,y);

        printf("%d\n",x%3+1);
    }
    return 0;
}

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

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

    int a, b, c;
    cin >> a >> b >> c;
    if (c < a) {
        cout << "NO";
        return 0;
    } else if (a + b >= c) {
        cout << "YES";
        return 0;
    } else {
        cout << "NO";
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		a[l]+=1;
		a[r+1]-=1;
	}
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+a[i];
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]==m){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    if (n % 3 == 0) {
        map<int, int> mp;
        rep(i, n) mp[a[i]]++;
        if (mp.size() == 1) {
            if (mp[0] == n) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
        else if (mp.size() == 2) {
            auto ite1 = mp.begin();
            auto ite2 = ++mp.begin();
            if ((ite1->second == n / 3 || ite1->second == n / 3 * 2) &&
                (ite1->first == 0 || ite2->first == 0)) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
        }
        else if (mp.size() == 3) {
            P ps[3];
            int idx = 0;
            for (auto p: mp) {
                ps[idx++] = p;
            }
            if (ps[0].second == n / 3 && ps[1].second == n / 3 && (ps[0].first ^ ps[1].first) == ps[2].first) {
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else if (3 < mp.size()) {
            cout << "No" << endl;
        }
    }
    else {
        rep(i, n) {
            if (a[i] != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 7268
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

S = stdin.readline().rstrip()

A = S[:2]
B = S[2:]

isYYMM = False
isMMYY = False

if int(B) <= 12 and int(B) >= 1:
    isYYMM = True

if int(A) <= 12 and int(A) >= 1:
    isMMYY = True

if isMMYY and isYYMM:
    print("AMBIGUOUS")
elif isMMYY:
    print("MMYY")
elif isYYMM:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 66156
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*ll N;
    cin>>N;
    
    vll A(N+1);
    for(ll i=0;i<=N;i++)cin>>A[i];
    if(N==0){
        if(A[0]==1){
            cout<<1<<endl;
            return 0;
        }else {
            cout<<-1<<endl;
            return 0;
        }
    }
    if(A[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    
    
    vll B(N+1);
    for(ll i=0;i<=N;i++){
        if(i==0){
            B[0]=1;
        }else{
            B[i]=(B[i-1]-A[i-1])*2;
            if(B[i]<A[i]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    
    vll C(N+1);
    for(ll i=N;i>=0;i--){
        if(i==N){
            C[i]=A[i];
        }else{
            C[i]=C[i+1]+A[i];
        }
    }
    
    ll ans=0;
    for(ll i=0;i<=N;i++){ans+=min(B[i],C[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}

int main() {*/
    ll n,a[100005]={0},b[100005],c[100005],pv,ans=0;
      bool ok=false;
    cin >> n;
    for(ll i=0;i<=n;i++){
        cin >> a[i];
    }
    for(ll i=0;i<=n;i++){
        if(i==0){
            if(a[i]>1){
                cout << -1 << endl;
                return 0;
            }
            b[0]=1;
        } else {
            if(ok) b[i]=2*1e17;
            else b[i]=(b[i-1]-a[i-1])*2;
              if(b[i]>=1e17) ok=true;
            if(a[i]>b[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    b[n+1]=1;
    for(ll i=n;i>=0;i--){
        if(i==n){
            c[i]=a[i];
        } else {
            c[i]=c[i+1]+a[i];
        }
    }
    c[n+1]=0;
    for(ll i=0;i<=n+1;i++){
        if(b[i]>c[i]){
            pv=i;
            break;
        }
    }
    for(ll i=0;i<=n;i++){
        if(i<pv){
            ans+=b[i];
        } else {
            ans+=c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5964
mod = 10**9+7
N,K = map(int,input().split())
fact = [1]*(N+1)
for i in range(N):
    fact[i+1] = (i+1)*fact[i]
    fact[i+1] %= mod
factinv = [1]*(N+1)
for i in range(N+1):
    factinv[i] = pow(fact[i],mod-2,mod)

def comb(n,k):
    return fact[n]*factinv[k]*factinv[n-k]%mod

A = list(map(int,input().split()))
A.sort()
M = 0
m = 0
for n in range(K-1,N):
    M += A[n]*comb(n,K-1)
    M %= mod
for n in range(N-K+1):
    m += A[n]*comb(N-n-1,K-1)
    m %= mod
print((M-m)%mod)

Measured memory_bytes: 65392
class _Node {
  constructor(key, left = null, right = null) {
    this.key = key;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    if (cmd.charAt(0) === 'i') tree.insert(Number(cmd.split(' ')[1]));
    else tree.print();
  });
})();



Measured memory_bytes: 197300
let k = stdin.ReadLine() |> int

/// return newList, count, newCount
let rec createMightAnsList beforeList count =
    let newList =
        beforeList
        |> List.map (fun (a:string) -> 
            match int (string a.[a.Length-1]) with
            | 0 -> [a+"0"; a+"1"]
            | 9 -> [a+"8"; a+"9"]
            | n -> [a + string (n - 1) ; a + string n; a + string (n + 1)])
        |> List.collect id

    let newCount = count + newList.Length
    
    if newCount >= k then
        newList, count, newCount
    else
        createMightAnsList newList newCount

let countAns (newList:list<_>) count newCount = newList.[(k - count - 1)]

if k <= 9 then
    k.ToString()
else
    createMightAnsList 
        ([1..9] |> List.map string)
        9
    |||> countAns 
|> stdout.WriteLine

Measured memory_bytes: 35528
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vl bit(40,0),fun(40),sum(41,0);
ll n,k;

ll rec(ll K,ll kbit){
    if(K<=0) return 0;
    kbit--;
    if(K>=(1LL<<kbit)) return max(fun[kbit] + rec(K-(1LL<<kbit), kbit), sum[kbit]);
    return rec(K, kbit);
}

int main(){
    cin >> n >> k;
    ll mxbit = 0;
    ll s = 0;
    rep(i,n){
        ll a; cin >> a;
        s += a;
        ll keta = 0;
        while(a > 0){
            if(a % 2 == 1) bit[keta]++;
            a /= 2;
            keta++;
            mxbit = max(mxbit, keta);
        }
    }
    if(k==0){
        cout << s << endl;
        return 0;
    }
    ll kbit = 0;
    while(k >= (1LL<<kbit)){
        kbit++;
    }
    mxbit = max(mxbit, kbit);
    rep(i,mxbit) fun[i] = (n - 2*bit[i]) * 1<<i;
    //rep(i,mxbit) cout << fun[i] << " ";
    rep(i,mxbit) sum[i+1] = sum[i] + max(0LL,fun[i]);
    //rep(i,mxbit+1) cout << sum[i] << " ";
    //cout << kbit << endl;
    cout << rec(k,kbit)+s << endl;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    // 単純な素因数分解								
    Map<Long, Long> dec(long n){								
    	// 割った数を保存するマップ　３で２回割れたら、ans.get(3) == 2　となる							
    	Map<Long, Long> ans = new HashMap<Long, Long>();							
            								
    	long num = n;							
    	Long wk = 0L;							
    	// ２　～　ルートｎ　の間、繰り返す							
    	for(long i = 2; i * i <= n && num != 1; ++i){							
    		// i で割り切れる間、割る						
    		while(num % i == 0){						
    			num /= i;					
    			wk = ans.get(i);					
    			if(wk == null) {					
    				ans.put(i, 1L);				
    			} else {					
    				ans.replace(i, (wk+1L));				
    			}					
    		}						
    	}							
    	if(num != 1) {							
    		wk = ans.get(num);// 最後に残った数も含める						
    		if(wk == null) {						
    			ans.put(num, 1L);					
    		} else {						
    			ans.replace(num, (wk+1L));					
    		}						
    	}							
    	return ans;							
    }
    int MAX = 510000;					
    int MOD = 1000000007;					
    long[] fac, finv, inv;			// a! (fac[a])   (a!)の-1乗 (finv[a])		
    // テーブルを作る前処理　→　これを呼んでから COM() を呼ぶ					
    void COMinit() {					
    	fac = new long[MAX];				
    	finv = new long[MAX];				
    	inv = new long[MAX];				
    	fac[0] = fac[1] = 1;				
    	finv[0] = finv[1] = 1;				
    	inv[1] = 1;				
    	for (int i = 2; i < MAX; i++){				
        		fac[i] = fac[i - 1] * i % MOD;			
    		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;			
    		finv[i] = finv[i - 1] * inv[i] % MOD;			
    	}				
    }					
    // 二項係数計算					
    long COM(int n, int k){					
    	if (n < k)		return 0;		
    	if (n < 0 || k < 0)		return 0;		
    	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;				
    }					
    public void solve() {
    	int N = Integer.parseInt(sc.next());
    	int M = Integer.parseInt(sc.next());
    	Map<Long, Long> D = dec(M);
    	long ans = 1;
    	COMinit();
    	for(long key : D.keySet()) {
    		long val = D.get(key);
    		ans = (ans * COM((int)val + N - 1, N - 1)) % MOD;
    	}
    	out.println(ans);
    }
}


Measured memory_bytes: 35796
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define INF (1e9)
#define se second
#define f first
#define N 505
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
int dijkstra();
int w,h,n,sy,sx,gy,gx,ay,ax,t,c[4][N][N],d[N][N];

int main(){
  string s;
  cin>>w>>h>>n;
  cin>>sx>>sy>>gx>>gy;
  while(n--){
    cin>>ax>>ay;
    cin>>t>>s;
    string a=s;
    while(--t) s+=a;
    for(int i=0;i<s.size();i++){
      if(s[i]=='L'&&ax!=0) c[3][ay][ax]++,c[1][ay+1][ax]++,ax--;
      if(s[i]=='U'&&ay!=0) c[2][ay][ax]++,c[0][ay][ax+1]++,ay--;
      if(s[i]=='R'&&ax!=w-1) c[1][ay+1][ax+1]++,c[3][ay][ax+1]++,ax++;
      if(s[i]=='D'&&ay!=h-1) c[0][ay+1][ax+1]++,c[2][ay+1][ax]++,ay++;
    }
  }
  cout<<dijkstra()<<endl;
  return 0;
}

int dijkstra(){
  priority_queue<P1,vector<P1>,greater<P1> > q;
  int dy[4]={0,-1,0,1},dx[4]={-1,0,1,0};
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) d[i][j]=INF;
  for(int i=0;i<4;i++) d[sy][sx]=0,q.push(P1(0,P(sy,sx)));
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int cost=t.f,y=t.se.f,x=t.se.se;
    if(d[y][x]<cost) continue;
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i],co=c[i][y][x];
      if(ny<0||nx<0||h<ny||w<nx) continue;
      if(d[ny][nx]>cost+co){
	d[ny][nx]=cost+co;
	q.push(P1(cost+co,P(ny,nx)));
      }
    }
  }
  return d[gy][gx];
}

Measured memory_bytes: 10392