akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define max(a, b) ((a)<(b) ? (b) : (a))
#define min(a, b) ((a)<(b) ? (a) : (b))

int main(){
  long long int a, b, c, x, y;
  scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &x, &y);

  long long int ans = 1000000000;
  for(int ci=0; ci<=max(x, y)*2; ci+=2){
    ans = min(ans, (ci*c + max(0, x-ci/2)*a + max(0, y-ci/2)*b));
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
import sys
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
# [[10 ** 9, 1, 2],
#  [3, 10 ** 9, 2]
#  [10 ** 9, 4, 7]]


input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    edge = [[int(x) for x in input().split()] for _ in range(10)]
    A = [[int(x) for x in input().split()] for _ in range(H)]

    G = csgraph_from_dense(edge, null_value=0)
    d = floyd_warshall(G)

    ans = 0
    for a in A:
        for v in a:
            if v == -1:
                continue
            ans += d[v][1]

    print(int(ans))


if __name__ == '__main__':
    main()



Measured memory_bytes: 17768
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

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

    int Pleft = 0, Pright = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '(') Pright++;
        else {
            if (Pright == 0) Pleft++;
            else Pright--;
        }
    }

    string ans = "";
    for (int i = 0; i < Pleft; i++)
    {
        ans += '(';
    }
    ans += s;
    for (int i = 0; i < Pright; i++) {
        ans += ')';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 1000000000 + 7;
const ll INF = 1e+9;
const ld PI = acos((ld)(-1));

#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define Fixed(n) std::fixed << std::setprecision(n)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define print(x) cout << x << endl;
#define next '\n'
#define sp " "
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << endl
#define SIZE(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define eb(e) emplace_back(e)

// 平均値
ld average(const vector<ld>& v){
    int len = v.size();
    ld sum = 0;
    for(int i = 0; i < len; ++i){
        sum += v[i];
    }

    return sum / (ld)len;
}

// 分散
ld variance(const vector<ld>& v, const ld avr){
    int len = v.size();
    ld sum = 0;
    for(int i = 0; i < len; ++i){
        sum += (v[i] - avr) * (v[i] - avr);
    }

    return sum / (ld)len;
}

int main() {
    FAST;

    int n;

    while(cin >> n){
        if(n == 0) return 0;

        vector<ld> A(n);
        rep(i, n){
            cin >> A[i];
        }

        auto m = average(A);
        auto v = variance(A, m);
        cout << Fixed(10) << sqrt(v) << endl;
    }
}




Measured memory_bytes: 3304
n,k=map(int,input().split())
ans=0
v=list(map(int,input().split()))
for i in range(min(n,k+1)):
    for j in range(min(n-i+1,k-i+1)):
        if j!=0:
            tmp=v[:i]+v[-j:]
        else:
            tmp=v[:i]
        tmp.sort()
        t=sum(tmp)
        for d in range(min(k-i-j,len(tmp))):
            if tmp[d]<0:
                t-=tmp[d]
        if t>ans:
            ans=t
print(ans)
    

Measured memory_bytes: 73456
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][0] = max(dp[i - 1][1] + a[i - 1][0], dp[i - 1][2] + a[i - 1][0])
    dp[i][1] = max(dp[i - 1][0] + a[i - 1][1], dp[i - 1][2] + a[i - 1][1])
    dp[i][2] = max(dp[i - 1][0] + a[i - 1][2], dp[i - 1][1] + a[i - 1][2])
print(max(dp[n][0], dp[n][1], dp[n][2]))

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int64_t T = 1, A = 1;
  rep(i, N) {
    int64_t t, a; cin >> t >> a;
    int64_t n = std::max((T - 1) / t + 1, (A - 1) / a + 1);
    T = n * t, A = n * a;
  }
  cout << T + A << endl;
}


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

int main(){
    int W,H;
    int x,y,r;
    
    cin >> W >> H >> x >> y >> r;
    if(x-r < 0){
        cout << "No" << endl;
        return 0;
    }
    if(x+r > W){
        cout << "No" << endl;
        return 0;
    }
    if(y+r > H){
        cout << "No" << endl;
        return 0;
    }
    if(y-r < 0){
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
}

Measured memory_bytes: 1160
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
H = inpl()
good = [1] * N
for _ in range(M):
    A, B = inpl()
    A -= 1
    B -= 1
    if H[A] < H[B]:
        good[A] = 0
    elif H[A] > H[B]:
        good[B] = 0
    else:
        good[A] = good[B] = 0

print(sum(good))


Measured memory_bytes: 84904
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

int main(){
	int n;
	cin >> n;
    vector<int> as, bs;
    for(int i=0;i<n;i++){
        as.push_back(i * 20000 + 1);
        bs.push_back(1e9 - i * 20000);
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        int p;
        cin >> p;
        p--;
        as[p] += cnt;
        cnt++;
    }
    for(int i=0;i<n;i++){
        cout << as[i] <<' ';
    }
    cout << endl;
    for(int i=0;i<n;i++){
        cout << bs[i] <<' ';
    }
    cout << endl;
	return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>

int main(){
    std::string str;
    std::cin >> str;

    std::sort(str.begin(), str.end());

    if(str.at(0) == str.at(1) && str.at(1) != str.at(2) && str.at(2) == str.at(3)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> v(100000,0);

void print_vec(int leng){
  for(int i =leng;i>=0;i--)
    cout<<v[i];
  cout<<" "<<leng<<" \n";
}
int main(){
  int k;
  cin>>k;
  
  string str = "123456789";
  
  if(k <= 9)
  {
    cout<<str[k-1]<<"\n";;
    return 0;
  }
  k = k - 9;
  
  v[0]= 0;
  v[1] = 1;
  int leng = 1;

  while(k > 1){
    int l =0;
    for(l = 0;l <= leng; l++){
      if(l == leng){
        if(v[leng] + 1 <= 9)
          {v[leng] = v[leng] + 1;
            for(int i = leng-1;i>=0;i--)
          if(v[i+1] - 1 >=0)
            v[i] = v[i+1] - 1;
          else
            v[i] = 0;
        }
        else
          {v[leng+1] = 1;
           leng = leng + 1;
           l = l + 1;
            for(int m = l - 1;m>=0;m--){
              v[m] = 0;
            }
           break;
          }
      }
      else if(v[l] + 1 <= 9 && abs(v[l] + 1  - v[l+1]) <= 1){
        v[l] = v[l] + 1;
        for(int i = l-1;i>=0;i--)
          if(v[i+1] - 1 >=0)
            v[i] = v[i+1] - 1;
          else
            v[i] = 0;

        break;
      }
    }
    //print_vec(leng);
    //cout<<"============\n";
    k--;
  }

  for(int i =leng;i>=0;i--)
    {cout<<v[i];}
  cout<<"\n";
  //cout<<" "<<leng<<endl;
  
  return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var res = abc[1] / abc[0];
            Console.WriteLine(res < abc[2] ? res : abc[2]);
        }
    }

Measured memory_bytes: 13268
a, b , c, x, y = map(int, input().split())

s = set()
s.add(a*x + b*y)
if x < y:
    s.add(2*x*c + b*(y-x))
    s.add(2*(x+1)*c + b*(y-x-1))
    s.add(2*y*c)
    print(min(s))
else:
    s.add(2*y*c + a*(x-y))
    s.add(2*(y+1)*c + a*(x-y-1))
    s.add(2*x*c)
    print(min(s))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b)
    cout << "a < b" << endl;
    else if (a > b) 
    cout << "a > b" << endl;
    else if (a == b )
    cout  << "a == b" << endl;
    return 0;
  
}


Measured memory_bytes: 3076
program ABC
    implicit none
    integer(8) a, b, c, d, l
    read*, a, b, c, d
    a = a - 1
    l = c * d / GCD(c, d)
    print"(i0)", ((b - b / c - b / d + b / l) - (a - a / c - a / d + a / l))
contains
    !GCDを求めるよ！
    recursive integer(8) function GCD (a, b) result (res)
        implicit none
        integer(8) a, b
        if (b > 0) then
            res = GCD(b, mod(a, b))
        else 
            res = a
        end if
    end function
end program ABC

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n;
long long mod = pow(10,9)+7;
vector <int> a;
long long ans = 0;
int main(){
    cin >> n;
    if(n==1){
        cout << 0 << endl;
        return 0;
    }else if(n==2){
        cout << 2 << endl;
        return 0;
    }else{
        long long all = 1;
        long long loop = n;
        while(true){
            all*=10;
            all%=mod;
            loop--;
            if(loop==0)break;
        }
        long long no0 = 1;
        loop = n;
        while(true){
            no0 *= 9;
            no0 %= mod;
            loop--;
            if(loop==0)break;
        }
        long long no9 = no0;
        long long no9no0 = 1;
        loop = n;
        while(true){
            no9no0 *= 8;
            no9no0 %= mod;
            loop--;
            if(loop==0)break;
        }
        long long ans = all - no9;
        ans %= mod;
        ans -= no0;
        ans %= mod;
        ans += no9no0;
        ans %= mod;
        if(ans<0)ans+=mod;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
# Aizu Problem 0087: Strange Mathematical Expression
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def upn(inputs):
    # inverse polish notation
    res = 0
    stack = []
    for inp in inputs:
        if inp in ['+', '-', '*', '/']:
            b = stack.pop()
            a = stack.pop()
            c = str(eval(a + inp + b))
            stack.append(c)
        else:
            stack.append(inp)
    return float(stack[0])

    
for line in sys.stdin:
    print("%.6f" % upn(line.split()))

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

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

int A[N+1],B[N];
for (int i = 0; i <= N ;i++) cin >> A[i];
for (int i = 0; i < N; i++) cin >> B[i];


long ans = 0 ;
for (int i = 0; i < N ;i++){
if (B[i] <= A[i]+A[i+1]){
   ans += B[i];
   if (B[i] <= A[i]){
   A[i+1] = A[i+1];
   }
   else{
   A[i+1] = A[i]+A[i+1] -B[i];
   }
}
else {
    ans += A[i]+A[i+1];
    A[i+1] =0;
}}
cout << ans << endl;
  return 0;
}





Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 1e5 + 10;
struct node
{
    int a, b;
} p[maxn];
bool cmp(node a, node b)
{
    if (a.a != b.a)
        return a.a < b.a;
    return a.b > b.b;
}
priority_queue<int> q;
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i].a >> p[i].b;
    }
    sort(p, p + n, cmp);
    // for (int i = 0; i < n; i++)
    //     cout << p[i].a << " " << p[i].b << endl;
    int ans = 0, mid = 0, maxx = 0;
    for (int i = 0; i < m; i++)
    {
        while (mid < n && p[mid].a <= i + 1)
            q.push(p[mid].b), mid++;
        if (!q.empty())
        {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1660
n=int(input())
a=list(map(int,input().split()))
can_root=1
ls=[1]
for i in range(n):
    if can_root<a[i]:
        print(-1);exit()
    can_root=(can_root-a[i])*2
    ls.append(can_root)
if can_root < a[-1]:print(-1);exit()
ans=a[-1]
start=a[-1]
for i in range(n)[::-1]:
    start+=a[i]
    ans+=min(ls[i],start)
print(ans)

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

int main() {
  int n, p; cin>>n>>p;
  vector<int> a(n);
  rep(i, n) cin>>a[i];

  int cnt=0;
  rep(i, n) if (a[i]%2==1) cnt++;
  ll ans=powl(2, n-1);
  if (p==0&&cnt==0) ans*=2;
  if (n==1&&cnt!=p) ans=0;
  if (p==1&&cnt==0) ans=0;
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <utility>
#include <queue>
#include <map>

using namespace std;

#define AT(X,Y) ((X)>>(7-Y)*3&7)

typedef pair<int,int> P;

int main() {
	queue<P> Q;
	map<int,int> mp;
	int d[]={1,-1,4,-4};
	Q.push(P(01234567,0));
	while(!Q.empty()) {
		P p=Q.front();Q.pop();
		for(int i=0;i<4;i++) {
			int nd=p.second+d[i];
			if((p.second%4==3&&i==0)||(p.second%4==0&&i==1)||(0>nd)||(nd>7)) continue;
			int v=0;
			for(int j=0;j<=7;j++) v<<=3,v|=(j==nd)?AT(p.first,p.second):(j==p.second)?AT(p.first,nd):AT(p.first,j);
			if(mp.find(v)!=mp.end()) continue;
			Q.push(P(v,nd));
			mp[v]=mp[p.first]+1;
		}
	}
	while(1) {
		int v=0;
		for(int i=0;i<8;i++) {
			int d=0;
			if(scanf("%d",&d)==EOF) return 0;
			v<<=3,v|=d;
		}
		printf("%d\n",mp[v]);
	}
}

Measured memory_bytes: 2000
#include <cstdio>

#ifdef GRUNDY_SLOW
unsigned grundy(unsigned A, unsigned K) {
  if (A < K) return 0;
  else if (A % K == 0) return A / K;
  return grundy(A - (1 + A / K), K);
}
#else
unsigned grundy(unsigned A, unsigned K) {
  while (A >= K) {
    const unsigned X = A % K;
    const unsigned Y = A / K;
    if (X == 0) return Y;
    const unsigned A2 = A - X;
    const unsigned S = 1 + Y;
    if (X % S == 0) return A2 / K;
    A -= (X / S + 1) * S;
  }
  return 0;
}
#endif

int main() {
  int N = 0;
  scanf("%d", &N);

  unsigned x = 0, y = 0, ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%u%u", &x, &y);
    grundy(x, y);
    ans ^= grundy(x, y);
  }

  if (ans != 0) puts("Takahashi");
  else puts("Aoki");
  return 0;
}


Measured memory_bytes: 128
/**/

#include <bits/stdc++.h>

using namespace std;

int N, M, P;
vector<tuple<int, int, long long>> grafo;
long long resp;

void BellmanFord(int inicio)
{
     vector<long long> distancia(N + 1, LONG_LONG_MAX);
     distancia[inicio] = 0;

     //Verifica o looping negativo (não há máximo)
     vector<bool> verifica(N + 1, false);
     verifica[N] = true;

     int primeiro, segundo;
     long long moedas;

     //Verifica o máximo possível, exceto os casos de looping negativo
     for (int i = 1; i < N; i++)
     {
          for (int j = 0; j < M; j++)
          {
               tie(primeiro, segundo, moedas) = grafo[j];

               if (distancia[primeiro] != LONG_LONG_MAX &&
                   distancia[primeiro] + moedas < distancia[segundo])
               {
                    distancia[segundo] = distancia[primeiro] + moedas;
               }

               //Salvando o vértice percorrido
               if(verifica[segundo] == true)
               {
                    verifica[primeiro] = true;
               }
          }
     }

     //Salvando a resposta máxima atual
     resp = max((long long)0, -distancia[N]);

     //Percorrendo o grafo e verificando se há o looping negativo
     for(int i = 0; i < M; i++)
     {
          tie(primeiro, segundo, moedas) = grafo[i];

          if (distancia[primeiro] != LONG_LONG_MAX &&
              distancia[primeiro] + moedas < distancia[segundo] &&
              verifica[segundo] == true)
          {
               //Looping negativo = impossível
               resp = -1;
               break;
          }     
     }
     

}

int main()
{
     cin >> N >> M >> P;

     for (int i = 0; i < M; i++)
     {
          int primeiro, segundo;
          long long moedas;
          cin >> primeiro >> segundo >> moedas;

          grafo.push_back({primeiro, segundo, P - moedas});
     }

     BellmanFord(1);
     cout << resp << endl;

     return 0;
}

Measured memory_bytes: 3764
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

string s;
map<char,int> mci;
void solve(){
    cin>>s;
    int n=s.size();
    for(int i=0;i<s.size();i++)mci[s[i]]++;
    bool ok=true;
    int cnt=0;
    int sum=0;
    vector<int> v;
    for(map<char,int>::iterator it=mci.begin();it!=mci.end();it++){
        if(n%2==0&&it->second%2==1){
            ok=false;break;
        }
        else if(n%2==1&&it->second%2==1){
            cnt++;
            if(cnt>=2){
                ok=false;break;
            }
        }
        sum+=it->second/2;
        v.push_back(it->second/2);
    }
    ll fact[21];
    fact[0]=1;
    for(int i=1;i<=20;i++){
        fact[i]=fact[i-1]*i;
    }
    if(!ok)cout<<0<<endl;
    else{
        ll res=fact[sum];
        for(int i=0;i<v.size();i++){
            res/=fact[v[i]];
        }
        cout<<res<<endl;
    }
}int main(){
    solve();

    return 0;
}

Measured memory_bytes: 0
//#define LOCAL

#include <cstdio>

#define M 100010
#define S 2000000000
struct Card {
    char p;
    int q;
};
Card A[M], B[M], L[M], R[M];

void merge(int l, int m, int r) {
    int i, j, k, n1 = m-l, n2 = r-m;
    for(i=0; i<n1; ++i) L[i] = A[l+i];
    for(i=0; i<n2; ++i) R[i] = A[m+i];
    i = j = 0, L[n1].q = R[n2].q = S;
    for(k=l; k<r; ++k) {
        if(L[i].q <= R[j].q) A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(int l, int r) {
    if(l+1 < r) {
        int m = (l+r)/2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}

int partition(int l, int r) {
    int i = l-1, j, x = B[r].q;
    for(j=l; j<r; ++j) {
        if(B[j].q <= x) {
            ++i;
            Card t = B[j]; B[j] = B[i]; B[i] = t;
        }
    }
    Card t = B[r]; B[r] = B[i+1]; B[i+1] = t;
    return i+1;
}

void quickSort(int l, int r) {
    int m;
    if(l < r) {
        m = partition(l, r);
        quickSort(l, m-1);
        quickSort(m+1, r);
    }   
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int i, m, n;
    char t[10];
    scanf("%d", &n);
    for(i=0; i<n; ++i) {
        scanf("%s%d", t, &m);
        A[i].p = B[i].p = t[0];
        A[i].q = B[i].q = m;
    }

    mergeSort(0, n);
    quickSort(0, n-1);
    for(i=0; i<n; ++i) {
        if(A[i].p != B[i].p) {
            printf("Not stable\n");
            break;
        }
    }
    if(i == n) printf("Stable\n");
    for(i=0; i<n; ++i) {
        printf("%c %d\n", B[i].p, B[i].q);
    }

    return 0;
}


Measured memory_bytes: 4964
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m) = (v[0] as usize, v[1]);
    let a = read_vec::<i64>();

    let mut a0 = a[0];
    let mut count = 0;
    while a0 % 2 == 0 {
        a0 >>= 1;
        count += 1;
    }
    for i in 1..n {
        let mut a0 = a[i];
        let mut temp_count = 0;
        while a0 % 2 == 0 {
            a0 >>= 1;
            temp_count += 1;
        }
        if count != temp_count {
            println!("0");
            return;
        }
    }

    let a = a.into_iter().map(|x| x >> count).collect::<Vec<_>>();
    let m = m >> count - 1;

    let mut lcmnum = a[0];
    for i in 1..n {
        let gcdnum1 = gcd(lcmnum, a[i]);
        lcmnum = lcmnum / gcdnum1 * a[i];
        if lcmnum > m * 2 + 10 {
            println!("0");
            return;
        }
    }
    let all = m / lcmnum;
    let ans = (all + 1) / 2;
    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define hell                         1000000007

#define Maxi                      10000000000000000
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                            long long
 
#define vll                          vector<ll>
#define vi                           vector<long long>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
//#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first  
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'
 
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
 
using namespace std;






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


	
	ll n;
	cin>>n;

	ll i,j;
	map<ll,ll>m1;
	for(i=1;i<=n;i++)
	{
		m1[i]=0;
	}
	for(i=0;i<n-1;i++)
	{
		ll x;
		cin>>x;

		m1[x]++;
	}

	for(i=1;i<=n;i++)
	{
		cout<<m1[i]<<endl;
	}


	



	
	




}

Measured memory_bytes: 16168
prev,pt = (0,0),0
b = True
def f(a,b): return abs(b[0]- a[0]) + abs(b[1] - a[1])
for _ in range(int(raw_input())):
	t,x,y  = map(int, raw_input().split())
	if (t - pt) < f((x,y), prev) :
		b = False
		break 

	if ((t - pt) - f((x,y), prev)) % 2:
		b = False
		break
	prev,pt = (x,y),t

print 'Yes' if b else 'No'

Measured memory_bytes: 79900
#if 0
date +%Y.%m.%d

醉了，一开始有个 sb 想法，结果最坏 s 的长度可以被卡到 700+ ，就不说了。
构造，s 前半部分是 1 到 p 的排列，后半部分是 1 到 p 升序。
那么 s 满足条件的子序列数就是前半部分的上升子序列数，
从小到大构造前半部分，对于当前数 x ，加到左边会使得上升子序列 +1 ，右边会使之 x2 。
注意这样会将空集算作一个子序列，把 n + 1 即可。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef unsigned long long ull;

struct {
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 205;
int L[maxn], R[maxn], lp, rp;
int p = 0;

void work(ll n) {
	if(n == 1) return;
	if(n & 1) {
		L[++ lp] = ++ p;
		work(n ^ 1);
	} else {
		R[++ rp] = ++ p;
		work(n >> 1);
	}
}

int main() {
	work(read + 1);
	printf("%d\n", p << 1);
	for(int i = 1; i <= lp; i ++)
		printf("%d ", p - L[i] + 1);
	for(int i = rp; i; i --)
		printf("%d ", p - R[i] + 1);
	for(int i = 1; i <= p; i ++)
		printf("%d ", i);
	puts("");
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int a,b,s[1001],f[1001],n,i,k=0;
	scanf("%d%d%d",&a,&b,&n);
	for(i=0;i<n;i++)scanf("%d%d",&s[i],&f[i]);
	for(i=0;i<n;i++){
		if(s[i]<a && a<f[i])k=1;
		if(s[i]<b && b<f[i])k=1;
		if(s[i]==a || f[i]==b)k=1;
		if(a<s[i] && s[i]<b)k=1;
		if(a<f[i] && f[i]<b)k=1;
	}
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 2116
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main()
{
	int r, d, x;
	cin >> r >> d >> x;
	ll now = x;
	rep(i, 10) {
		now =(ll) now * r - d;
		cout << now << endl;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int x, a, b; cin >> x >> a >> b;
    int dead = b - a;
    if (dead <= 0) out("delicious");
    else if (dead <= x) out("safe");
    else out("dangerous");
}



Measured memory_bytes: 384
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

# print("Yes")
# print("No")

# print("YES")
# print("NO")


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

mm = sum(A)

cnt = 0
for i in range(N):
    if A[i] >= mm/(4*M):
        cnt += 1

if cnt >= M:
    print("Yes")
else:
    print("No")









Measured memory_bytes: 2940
#!/usr/bin/env python3

n, m = map(int, input().strip().split())
xs = list(map(int, input().strip().split()))

if m <= n:
    print(0)
    exit()

xs.sort()

ls = [xs[i] - xs[i - 1] for i in range(1, len(xs))]
ls.sort()

print(sum(ls[:m - n]))


Measured memory_bytes: 13960
#include<iostream>
#include<cmath>
#include<algorithm>
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<<#X<<": "<<X<<" ";
#define ARDEB(i,X) cout<<#X<<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(X) {}
#define END {}
#endif
using namespace std;
int main(){
	/*int n,a[2001];
	int m,c[1001];
	cin>>n>>m;
	for(int i=0;i<n*2;i++)a[i]=i+1;
	/*for(int i=0;i<m;i++){
		cin>>c[i];
		if(c[i]==0){
			
			}
		}
	}
	for(int j=1;j<n;j++){
		swap(a[j],a[n+j-1]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
		swap(a[n+j-1],a[j+1]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
		swap(a[j+2],a[j+3]);
		for(int j=0;j<n*2;j++)cout<<a[j]<<" ";
		cout<<endl;
	}
	for(int j=0;j<n*2;j++)cout<<a[j]<<" ";*/
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define gcd __gcd
#define x first
#define y second
#define st first
#define nd second
#define pb push_back

using namespace std;

template<typename T> ostream& operator<<(ostream &out, const vector<T> &v){ out << "{"; for(const T &a : v) out << a << ", "; out << "}"; return out; }
template<typename S, typename T> ostream& operator<<(ostream &out, const pair<S,T> &p){ out << "(" << p.st << ", " << p.nd << ")"; return out; }

typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef vector<int> VI;

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

int n, t, e;
long long X[100010];
long long T[100010];
multiset<long long> D, G;

long long minS(const multiset<long long> &M){
	if(M.empty()) return 1000LL*1000*1000*1000 + 3;
	return *M.begin();
}

int main(){
	scanf("%d %d %d", &n, &e, &t);
	FWD(i,1,n+1) scanf("%lld", &X[i]);

	D.insert(T[0] - X[0] + t);

	int p = 0;
	FWD(k,1,n+1){
		while(2*(X[k] - X[p+1]) > t){
			D.erase(D.find(T[p] - X[p] + t));
			G.insert(T[p] - 2*X[p+1] - X[p]);
			++p;
		}
		T[k] = min(minS(G) + 3*X[k], minS(D) + X[k]);
		D.insert(T[k] - X[k] + t);
	}
	printf("%lld\n", T[n] + e - X[n]);
	return 0;
}


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

int main(){
	int a, b, c;
	long long int d, e;
	while (cin >> a >> b){
		c = a;
		d = a;
		e = b;
		while (a != b){
			if (a > b){
				c = a - b;
				a = b;
				b = c;
			}
			else {
				c = b - a;
				a = b;
				b = c;
			}
		}
		cout << c << " " << d*e/c << '\n';
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll power(long a, long b) { return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;
    int A[200100];
    rep(i, N)
            cin >>
        A[i];

    long dp[200100][2][3];
    rep(i, N + 1) rep(x, 2) rep(y, 3) dp[i][x][y] = -1LL << 60;
    dp[0][1][0] = 0;
    for (int i = 0; i < N; i++)
    {
        rep(j, 2) rep(k, 3)
        {
            // not take
            if (k + j < 3)
                dp[i + 1][1][k + j] = max(dp[i + 1][1][k + j], dp[i][j][k]);
            // take
            if (j == 1)
                dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A[i]);
        }
    }
    if (N % 2 == 0)
        cout << max(dp[N][1][0], dp[N][0][1]) << "\n";
    else
        cout << max(dp[N][0][2], dp[N][1][1]) << "\n";
}

Measured memory_bytes: 13776
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    int r[] = new int[n];
    int a[] = new int[n];
    for(int i = 0 ; i < n ; ++i){
      a[i] = l+i;
      r[i] = Math.abs(a[i]);
    }
    int num = 0;
    int min = 1000000000;
    int sum = 0;
    for(int i = 0 ; i < n ; ++i){
      if(min>r[i]){
        min = Math.min(min,r[i]);
        num = i;
      }  
    }
    for(int i = 0 ; i < n ; ++i){
      if(i!=num){
        sum += a[i];
      }  
    }
    System.out.println(sum);
    
  }
}

Measured memory_bytes: 35692
while True:
    h, w = map(int,input().split())
    if h == 0 and w ==0:
        break

    else:
        print('#'*w)

        h2 = h-2
        w2 = w-2
        for i in range(0, h2):
            print('#' + '.'*w2 + '#')
        print('#'*w)
        print('')

Measured memory_bytes: 7576
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    
    int highest = H[0];
    int res = 1;
    
    
    for(int i = 1; i < N; i++){
        if(H[i] >= highest){
            res++;
            highest = H[i];
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i = 0;
    int n;
    scanf("%d", &n);
    int min = 1000;
    int max = 0;
    for (i = 0; i < n; i++)
    {
        int h = 0;
        scanf("%d", &h);
        if (max < h)
            max = h;
        if (min > h)
            min = h;
    }
    int c = max - min;
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        int n, k;
        cin >> n >> k;
        vector<int> a(2 * k);
        for (int i = 0; i < k; ++i)
            cin >> a[i];
        for (int i = 0; i < k; ++i)
            a[i + k] = a[i] + n;
        int ans = n;
        for (int i = 0; i < k; ++i) {
            ans = min(ans, a[i + k - 1] - a[i]);
        }
        cout << ans << '\n';
    }

} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

int main() {
    string s;
    cin >> s;
    vector<int> seq;

    int flip1 = 0;
    int flip2 = 0;
    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0 && s[i] == '0') {
            flip1++;
        }
        if (i % 2 != 0 && s[i] == '1') {
            flip1++;
        }

        if (i % 2 != 0 && s[i] == '0') {
            flip2++;
        }
        if (i % 2 == 0 && s[i] == '1') {
            flip2++;
        }
    }
    cout << min(flip1, flip2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

string w;
int MOD;

const int N = 1e4 + 5;
const int D = 1e2 + 5;
const int G = 1e9 + 7;

i64 dp [N][D];

i64 solve (int p, int sum, bool tight) {
  if (p == -1) return sum == 0;
  if (tight && ~dp[p][sum]) return dp[p][sum];
  i64 tot = 0;
  for (int i = 0; i <= (tight ? 9 : w[p] - '0'); i++) {
    tot += solve (p - 1, (sum + i) % MOD, tight | (i < (w[p] - '0')));
    tot %= G;
  }
  return (tight ? dp[p][sum] = tot : tot);
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> w >> MOD;
  reverse (all(w));
  memset (dp, -1, sizeof(dp));
  cout << (solve (sz(w) - 1, 0, 0) - 1 + G) % G << '\n';
  return 0;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] , arr2[MAX] ;
int n , m , k ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>k ;
	int Min1 = 1e9 , Min2 = 1e9 ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>arr[i] ;
		Min1 = min(Min1 , arr[i]) ;
	}
	for(int i = 0 ; i < m ; ++i)
	{
		cin>>arr2[i] ;
		Min2 = min(Min2 , arr2[i]) ;
	}
	int ans = Min1 + Min2 ;
	for(int i = 0 ; i < k ; ++i)
	{
		int x , y , c ;
		cin>>x>>y>>c ;
		x-- , y-- ;
		ans = min(ans , arr[x] + arr2[y] - c) ;
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    r,s,p=map(int,input().split())
    T=input()

    ans=0
    win=[0]*n
    for i in range(n):
        if(i>=k and T[i]==T[i-k] and win[i-k]): continue
        if(T[i]=='r'): ans+=p
        elif(T[i]=='s'): ans+=r
        else: ans+=s
        win[i]=1

    print(ans)
resolve()

Measured memory_bytes: 42096
#include <bits/stdc++.h>
using namespace std;
long long X;
long long func(long long C){
  if(C==-1){
    return 0;
  }
  return C/X+1;
}
  
int main(){
  long long A,B;
  cin >> A >> B >> X;
  cout << func(B)-func(A-1) << endl;
}
  

Measured memory_bytes: 3624
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, D;
	
	cin >> N >> D;

	int t = N / (2 * D + 1);
	if (N % (2 * D + 1))
	{
		t++;
	}
	cout << t << endl;

	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[4];
		int[] b = new int[4];
		while(sc.hasNextInt()) {
			for(int i=0;i<4;i++) {
				a[i] = sc.nextInt();
			}
			for(int i=0;i<4;i++) {
				b[i] = sc.nextInt();
			}
			
			int hi = 0;
			int bl = 0;
			for(int i=0;i<4;i++) {
				for(int j=0;j<4;j++) {
					if(a[i] == b[j]) {
						if(i==j) hi++;
						else bl++;
					}
				}
			}
			System.out.println(hi + " " + bl);
		}
		
	}	
}





Measured memory_bytes: 26276
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(n, k; usize);
    scan!(dices; Vec<f64>);

    let exps = dices.iter()
        .map(|&x| ( x * (x + 1.0) ) / (2.0 * x) )
        .collect::<Vec<f64>>();

    let mut acc = exps[0..k].iter().sum::<f64>();
    let mut max: f64 = acc;

    for i in k..n {
        acc -= exps[i - k];
        acc += exps[i];
        if acc > max { max = acc; }
    }

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


Measured memory_bytes: 10492
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<deque>
#include<queue>

using namespace std;

int main(){
  int h,w;
  while(scanf("%d%d\n",&w,&h),w+h){
    char board[22][24]={{0}};
    deque<pair<int,int> > pos;
    int count=3;
    for(int i=1;i<=h;i++){
      fgets(&board[i][1],23,stdin); board[i][w+1]=0;
      for(int j=1;j<=w;j++){
	if(board[i][j]=='x')      board[i][j]=0;
	else if(board[i][j]=='.') board[i][j]=1;
	else if(board[i][j]=='*'){
	  board[i][j]=count++;
	  pos.push_back(make_pair(j,i));
	}else if(board[i][j]=='o'){
	  board[i][j]=2;
	  pos.push_front(make_pair(j,i));
	}
      }
    }

    /*
    for(int i=0;i<h+2;i++){
      for(int j=0;j<w+2;j++){
	printf("%d ",board[i][j]);
      }
      puts("");
    }
    */

    //int darty=pos.size()-1;
    int dist[11][11]={{0}};
    bool possible=true;
    for(int i=0;i<pos.size()-1;i++){
      //dijkstra
      int flag[22][22]={{0}};
      int d[22][22];
      for(int x=0;x<22;x++)
	for(int y=0;y<22;y++)
	  d[y][x]=1000;
      count=0;
      priority_queue<pair<int,pair<int,int> > > q;
      q.push(make_pair(0,make_pair(pos[i].first,pos[i].second)));
      while(!q.empty()){
	if(count==pos.size()) break;
	int x=q.top().second.first,y=q.top().second.second,hy=q.top().first;
	q.pop();
	//printf("(%d,%d)=%d\n",x,y,-hy);
	if(flag[y][x]!=0) continue;
	flag[y][x]=1;
	if(board[y][x]>=2){//darty or initial
	  //printf("test %d\n",board[y][x]-2);
	  dist[i][board[y][x]-2]=-hy;
	  dist[board[y][x]-2][i]=-hy;
	  count++;
	}
	if(board[y][x-1]!=0 && d[y][x-1]>-hy+1){
	  d[y][x-1]=-hy+1;
	  q.push(make_pair(hy-1,make_pair(x-1,y)));
	}
	if(board[y][x+1]!=0 && d[y][x+1]>-hy+1) {
	  d[y][x+1]=-hy+1;
	  q.push(make_pair(hy-1,make_pair(x+1,y)));
	}
	if(board[y-1][x]!=0 && d[y-1][x]>-hy+1){
	  d[y-1][x]=-hy+1;
	  q.push(make_pair(hy-1,make_pair(x,y-1)));
	}
	if(board[y+1][x]!=0 && d[y+1][x]>-hy+1){
	  d[y+1][x]=-hy+1;
	  q.push(make_pair(hy-1,make_pair(x,y+1)));
	}
      }
      if(count!=pos.size()){
	possible=false;
	break;
      }
    }
    if(!possible){
      puts("-1");
      continue;
    }
    
    /*
    for(int i=0;i<pos.size();i++){
      for(int j=0;j<pos.size();j++){
	printf("%3d",dist[i][j]);
      }
      printf("\n");
    }
    */
    //traveling salesman problem
    vector<int> v(pos.size()-1);
    int ans=100000;
    for(int i=0;i<pos.size()-1;i++) v[i]=i+1;
    do{
      int tmp=dist[0][v[0]];
      for(int i=0;i<pos.size()-2;i++){
	tmp+=dist[v[i]][v[i+1]];
	if(tmp>ans){
	  sort(&v[i+1],&v[pos.size()-2],greater<int>());
	  break;
	}
      }
      if(ans>tmp) ans=tmp;
    }while(next_permutation(v.begin(),v.end()));
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 932
#include<stdio.h>
#include<stdlib.h>
int desc(const void *a, const void *b){
  return *(int*)b - *(int *)a;
}
int main(){
  int n,i;
  long long int tmp=0,ans=0;
  scanf("%d",&n);
  int a[n],b[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),desc);
  for(i=0;i<n;i++){
    if(i%2==0)b[i]=1;
    else b[i]=-1;
    if(i!=0 && i!=n-1)b[i]*=2;
  }
  qsort(b,n,sizeof(int),desc);
  for(i=0;i<n;i++){
    ans+=a[i]*b[i];
  }
  for(i=0;i<n;i++){
    tmp+=a[i]*(-1*b[n-1-i]);
  }
  printf("%lld\n",((tmp<ans)?ans:tmp));
  return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int count = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if ((i + 1) % 2 == 1) {
			if (a % 2 == 1) {
				count++;
			}
		}
	}
	cout << count << endl;

}


Measured memory_bytes: 3532
N = int(input())
ans = [0] * N
tree = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    tree[u].append((v, w))
    tree[v].append((u, w))

stack = [(0, -1, 0)]
while stack:
    v, par, dist = stack.pop()
    if dist % 2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for child, child_dist in tree[v]:
        if child == par:
            continue
        stack.append((child, v, dist + child_dist))

for x in ans:
    print(x)

Measured memory_bytes: 38828
#include<iostream>

using namespace std;

int main(void) {
	int N, A, B;
	int buff, digsum, sum, num;
	cin >> N >> A >> B;
	
	sum = 0;
	for (int i = 1; i <= N; i++) {
		num = i;
		digsum = 0;
		while (num) {
			buff = num % 10;
			digsum += buff;
			num = num / 10;
		}
		if ((digsum >= A) && (digsum <= B))sum += i;
	}
	cout << sum;
	return 0;
}

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

signed main()
{
    int n;
    string s;
    cin >> n >> s;

    int r[n], g[n], b[n];
    r[n - 1] = 0;
    g[n - 1] = 0;
    b[n - 1] = 0;
    if (s[n - 1] == 'R')
        r[n - 1] = 1;
    else if (s[n - 1] == 'G')
        g[n - 1] = 1;
    else
        b[n - 1] = 1;

    for (int i = n - 2; i >= 0; i--)
    {
        r[i] = r[i + 1];
        g[i] = g[i + 1];
        b[i] = b[i + 1];
        if (s[i] == 'R')
            r[i] = 1 + r[i + 1];
        else if (s[i] == 'G')
            g[i] = 1 + g[i + 1];
        else
            b[i] = 1 + b[i + 1];
        //printf("%d %d %d \n", r[i], g[i], b[i]);
    }

    int ans = 0;

    for (int i = 0; i < n - 3; i++)
    {
        for (int j = i + 1; j < n - 1; j++)
        {
            if (s[i] == s[j])
                continue;
            //cout << s[i] << s[j] << endl;
            if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
            {
                if (s[j + j - i] == 'B')
                    ans--;
                ans += b[j + 1];
            }
            else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
            {
                if (s[j + j - i] == 'G')
                    ans--;
                ans += g[j + 1];
            }
            else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G'))
            {
                if (s[j + j - i] == 'R')
                    ans--;
                ans += r[j + 1];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define print(x) cout << x << '\n';

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.in", "r", stdin);
    int n;
    cin >> n;
    int temp = n;
    int dig = 0;
    while(temp > 0){
        dig += temp % 10;
        temp /= 10;
    }
    // cout << dig;

    if(n % dig == 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	//sort(a, a + n);
	int q;
	cin >> q;
	while(q--){
		int op, b, e;
		cin >> op >> b >> e;
		if(op == 0){
			int min_ = a[b];
			for(int i = b + 1; i < e; i++)min_ = min(min_, a[i]);
			cout << min_ << '\n';
		}else{
			int max_ = a[b];
			for(int i = b + 1; i < e; i++)max_ = max(max_, a[i]);
			cout << max_ << '\n';
		}
	}
	return 0;
}



Measured memory_bytes: 3200
A, B, C, X, Y = map(int, input().split())

ans = float("inf")
for c in range(0, max(X, Y)*2+1, 2):
    ans = min(A*max(X-c//2, 0) + B*max(Y-c//2, 0) + C*c, ans) 

print(ans)

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	int n; cin >> n;
	vector<int> a(n);
	for(int &t: a) cin >> t;

	sort(a.begin(), a.end());

	ll ans = 0;
	int p1 = 0, p2 = n-2;
	ans += a[n-1];
	n -= 2;
	
	while(n){
		ans += a[p2];
		p1++;
		n--;
		if(!n) break;	
		ans += a[p2];
		p2--;
		n--;
	}
	
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3984