akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc 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;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n,m;
    while(cin >> n >> m,n){
        vector<int> a(n+1,0),b(n+1,0);
        for (int i = 0; i < n; i++) {
            cin >> a[i+1];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i+1];
        }
        vector<vector<int>> dp(n+1,vector<int> (n+3,INF));
        dp[0][0]=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(b[i+1]+m*(j+1)-a[i+1]>b[i]+m*j-a[i]) dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+b[i+1]+(j+1)*m-a[i+1]-(b[i]+m*j-a[i]));
                else dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]);

                if(b[i+1]+m*(j+2)-a[i+1]>b[i]+m*j-a[i]) dp[i+1][j+2] = min(dp[i+1][j+2],dp[i][j]+b[i+1]+(j+2)*m-a[i+1]-(b[i]+m*j-a[i]));
                else dp[i+1][j+2] = min(dp[i+1][j+2],dp[i][j]);

                if(j&&a[i+1]<=b[i+1]+m*(j-1)){
                    if(b[i+1]+m*(j-1)-a[i+1]>b[i]+m*j-a[i]) dp[i+1][j-1] = min(dp[i+1][j-1],dp[i][j]+b[i+1]+(j-1)*m-a[i+1]-(b[i]+m*j-a[i]));
                    else dp[i+1][j-1] = min(dp[i+1][j-1],dp[i][j]);
                }

                if(j-1&&a[i+1]<=b[i+1]+m*(j-2)){
                    if(b[i+1]+m*(j-2)-a[i+1]>b[i]+m*j-a[i]) dp[i+1][j-2] = min(dp[i+1][j-2],dp[i][j]+b[i+1]+(j-2)*m-a[i+1]-(b[i]+m*j-a[i]));
                    else dp[i+1][j-2] = min(dp[i+1][j-2],dp[i][j]);
                }
                if(a[i+1]<=b[i+1]+m*j){
                    if(b[i+1]+m*j-a[i+1]>b[i]+m*j-a[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j]+b[i+1]+m*j-a[i+1]-(b[i]+m*j-a[i]));
                    else dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
                }
            }
        }
        int ans=INF;
        for (int i = 0; i < n+2; i++) {
            ans = min(ans,dp[n][i]);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 6860
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  // read problem
  long long int M, tmp1, tmp2;
  std::vector<long long int> d, c;

  scanf("%lld", &M);

  for(long long int i = 0; i < M; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    d.push_back(tmp1);
    c.push_back(tmp2);
  }

  /*std::cerr << "M: " << M << std::endl;
  std::cerr << "d: " << std::endl;
  for(long long int i = 0; i < M; i++){
    std::cerr << d[i] << " ";
  }std::cerr << std::endl;
  std::cerr << "c: " << std::endl;
  for(long long int i = 0; i < M; i++){
    std::cerr << c[i] << " ";
  }std::cerr << std::endl;*/

  // solve problem
  long long int carryover = 0;
  long long int topdigit, period, tmp_pos;
  long long int ans = 0;
  std::vector<long long int> tmp_digits(10);

  for(long long int i = 0; i < M; i++){
    //std::cerr << "i: " << i << " carryover: " << carryover << std::endl;
    // calculate carryover
    topdigit = d[i];
    while(carryover>0){
      ans++;
      topdigit = topdigit+carryover;
      carryover = topdigit/10;
      topdigit = (topdigit+10)%10;
    }

    //std::cerr << "carryover is done" << std::endl;

    // calculate one period
    tmp_digits[0] = topdigit;
    for(long long int j = 1; j < 10; j++){
      tmp_digits[j] = d[i];
    }
    tmp_pos = 0;
    period = 0;
    for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){
      while(tmp_digits[tmp_pos] > 0){
        period++;
        tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1];
        tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10;
        tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10;
      }
      /*for(long long int k = 0; k < 10; k++){
        std::cerr << tmp_digits[k];
      }std::cerr << std::endl;*/
    }

    ans += period*((c[i]-1)/9);
    //std::cerr << "one period calculated" << std::endl;

    // calculate amari
    tmp_pos = 9 - ((c[i]+8)%9);
    if(tmp_pos == 0){
      continue;
    }
    tmp_digits[tmp_pos] = topdigit;
    for(long long int j = tmp_pos+1; j < 10; j++){
      tmp_digits[j] = d[i];
    }
    for(long long int tmp_pos = 0; tmp_pos < 9; tmp_pos++){
      while(tmp_digits[tmp_pos] > 0){
        ans++;
        tmp_digits[tmp_pos+1] = tmp_digits[tmp_pos] + tmp_digits[tmp_pos+1];
        tmp_digits[tmp_pos] = tmp_digits[tmp_pos+1]/10;
        tmp_digits[tmp_pos+1] = (tmp_digits[tmp_pos+1]+10)%10;
      }
    }

    //std::cerr << "amari calculated" << std::endl;

    carryover = tmp_digits[9];
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3564
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int main()
{
	int n;
	while(cin>>n&&n){
		int num[1000],p[1000],q[1000],r[1000],cal[1000];
		for(int i=1;i<=n;i++){
			cin>>num[i]>>p[i]>>q[i]>>r[i];
			cal[i]=p[i]*4+q[i]*9+r[i]*4;
		}
		cin>>p[0]>>q[0]>>r[0]>>cal[0];
		bool ex=false;
		for(int i=1;i<=n;i++){
			if(p[i]>p[0]||q[i]>q[0]||r[i]>r[0]||cal[i]>cal[0])continue;
			printf("%d\n",num[i]);
			ex=true;
		}
		if(!ex)printf("NA\n");
	}

    return 0;
}

Measured memory_bytes: 1168
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = [-1]*n
num = k
loc = 1

while(num >= 1):
    loc = a[loc-1]
    num -= 1
    if(s[loc-1] == -1):
        s[loc-1] = num
    else:
        num = num%(s[loc-1] - num)
        while(num >= 1):
            loc = a[loc-1]
            num -= 1
        break
print(loc)


Measured memory_bytes: 92296
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;
constexpr int ESP = 1e-9;
constexpr double PI = acos(-1);
constexpr int MAX = 2000;

int dp[MAX*2+1][MAX*2+1];
int a[200000], b[200000];

vector<ll> get_fractorial(int n) {
    vector<ll> ret;
    int i;
    ret.push_back(1);
    REP (i,1,n) {
        ret.push_back(ret[i-1] * i % MOD);
    }
    return ret;
}

ll modpow(ll x, int n) {
    ll ret = 1;
    while (n) {
        if (n % 2)
            ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll modinv(int x) {
    return modpow(x,MOD-2);
}

int main(void) {
    int i, j, n;
    scanf("%d",&n);
    REP (i,n) {
        scanf("%d%d",&a[i],&b[i]);
        dp[a[i]+MAX][b[i]+MAX]++;
    }

    RREP (i,2*MAX,0) RREP (j,2*MAX,0) {
        if (i < 2*MAX) {
            dp[i][j] += dp[i+1][j];
            dp[i][j] %= MOD;
        }
        if (j < 2*MAX) {
            dp[i][j] += dp[i][j+1];
            dp[i][j] %= MOD;
        }
    }

    auto frac = get_fractorial(MAX * 4);

    int ans = 0;
    REP (i,n) ans = (ans + dp[MAX-a[i]][MAX-b[i]]) % MOD;
    REP (i,n) ans = (ans - frac[(a[i]+b[i]) * 2] * modinv(frac[a[i]*2] * frac[b[i]*2] % MOD) % MOD + MOD) % MOD;
    ans = ans * modinv(2) % MOD;
    printf("%d\n",ans);
    return 0;
}


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

bool used[10], ans[10], endR;
int bundo[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

void init(){ for(int i = 0; i < 10; i++) used[i] = false; endR = false;}

void copyAns(){
  for(int i = 0; i < 10; i++) ans[i] = used[i];
}

void dfs(int i, int w){
  if(w == 0) { copyAns(); endR = true; return; }
  if(i == 10 || w < 0 || endR) return;

  if(!used[i]){
    used[i] = true;
    dfs(i + 1, w - bundo[i]);
  }
  used[i] = false;
  dfs(i + 1, w);
}

int main(void){
  int w;
  while(cin >> w){
    init();
    dfs(0, w);
    int cnt = 0;
    for(int i = 0; i < 10; i++){
      if(ans[i]) cnt++;
    }
    for(int i = 0; i < 10; i++){
      if(ans[i]) cout << bundo[i];
      if(ans[i] && --cnt) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,Q=map(int,input().split())
S=input()
res=0
dp=[0]*N
a=0
for i in range(1,N):
  if S[i]=='C':
    if S[i-1]=='A':
      res+=1
  dp[i]=res
for _ in range(Q):
  l,r=map(int,input().split())
  if l==1:
    print(dp[r-1])
  else:
    print(dp[r-1]-dp[l-1])

Measured memory_bytes: 11484
#include<stdio.h>

int main(){
  int N,M,l,r,L,R,i;
  scanf("%d %d",&N,&M);
  l = 1;r = N;
  for(i = 0;i < M;i++){
    scanf("%d %d",&L,&R);
    if(l < L){l = L;}
    if(r > R){r = R;}
  }printf("%d\n",(l <= r)?(r-l+1):0);return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
#define Okay_Bye return 0
#define fo(i,n) for(auto i=0;i<n;i++)
#define f1(i,a,n) for(auto i=a;i<n;i++)
#define pn printf("\n")
#define Yes printf("YES\n")
#define No printf("NO\n")
#define pb push_back

int cs=1;
int wi[105],v[105],dp[105][100005];
int d(int i, int w){
    if(i==-1 or w==0)return 0;
    if(dp[i][w]!=-1)return dp[i][w];
    if(wi[i]>w)return dp[i][w]=d(i-1,w);
    else return dp[i][w]=max(v[i]+d(i-1,w-wi[i]),d(i-1,w));
}
void solve(){
    int n,w;
    cin>>n>>w;
    fo(i,n)cin>>wi[i]>>v[i];
    memset(dp,-1,sizeof dp);
    cout<<d(n-1,w)<<endl;
}

signed main()
{
	int t=1;
	//cin>>t;
	while(t--)solve();
	Okay_Bye;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    long long N;
    cin >> N;
    auto pf = prime_factorize(N);
    long long res = 0;
    for (auto p : pf) {
        long long e = p.second;
        long long tmp = 0, cur = 1;
        while (e >= cur) e -= cur++, ++tmp;
        res += tmp;
    }
    cout << res << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i, a) for(auto&& i:a)
#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for(ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(v) (v).begin(),(v).end()

const ll linf = 1e18;
const ll inf = 1e9;

template<class T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
string toString(ll n) {
    stringstream ss; ss << n;
    string res; ss >> res;
    return res;
}
bool check(ll n) {
    string str = toString(n);
    REP(i, (int)str.size()-1) {
        if (str[i+1] != str[i]+1) return false;
    }
    return true;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<ll> v(n); cin >> v;
    ll ans = -1;
    REP(i, n) FOR(j, i+1, n) {
        if ( check(v[i]*v[j]) ) {
            ans = max(ans, v[i] * v[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3192
H,W=map(int,input().split())
C=[list(map(str,input().split())) for i in range(H)]
ans=[[] for i in range(2*H)]
for i in range(H):
    ans[2*i]=C[i]
    ans[2*i+1]=C[i]

for j in range(2*H):
    print(*ans[j])

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <list>
#include <stack>

using namespace std;


int main()
{
    int N;
    vector<int> H;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        H.push_back(tmp);
    }
    for (int i = N-1; i >= 0; i--) {
        if (i == 0) {
            continue;
        }
        if (H[i-1] <= H[i]) {
            continue;
        }
        else if (H[i-1] - 1 <= H[i]) {
            H[i-1]--;
            continue;
        }
        else {
            cout << "No";
            return 0;
        }



    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

bool solve() {
  int N, M;
  bool virus[SIZE] = {};
  pair<int, pair<int,int> > query[SIZE];

  scanf("%d%d", &N, &M);

  if (N == 0) return false;

  for (int i=0; i<M; i++) {
    int t, s, d;
    scanf("%d%d%d", &t, &s, &d);
    s--; d--;
    query[i] = {t, {s, d}};
  }

  sort(query, query+M);

  virus[0] = true;

  for (int i=0; i<M; i++) {
    int s = query[i].second.first;
    int d = query[i].second.second;
    virus[d] |= virus[s];
  }

  int ans = 0;

  for (int i=0; i<N; i++)
    ans += virus[i];

  cout << ans << endl;

  return true;
}

int main(){

  while(solve());

  return 0;
}



Measured memory_bytes: 5648
#include <iostream>
using namespace std;
static const int N = 100;

int main() {
    int M[N][N];
    int n, u, k, v;
    
    cin >> n;
    
    for ( int i = 0; i < n; i++ ){
        for (int j = 0; j < n; j++ ) M[i][j] = 0;
    }
    
    for ( int i = 0; i < n; i++ ){
        cin >> u >> k;
        u--;
        for ( int j = 0; j < k; j++ ){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j < n; j++ ){
            if ( j ) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3152
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  int p[a], q[b], r[c];
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];

  sort(p, p + a, greater<>());
  sort(q, q + b, greater<>());
  sort(r, r + c, greater<>());

  vector<int> sl;
  rep(i, x) { sl.push_back(p[i]); }
  rep(i, y) { sl.push_back(q[i]); }

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

  // for (auto u : sl) cout << " " << u;
  // cout << '\n';

  int s = 0, t = 0;
  rep(i, x + y) {
    // if (s >= x + y) break;
    if (t >= c) break;

    if (sl[s] < r[t]) {
      sl[s] = r[t];
      ++s, ++t;
    } else {
      ++s;
    }
  }

  // for (auto u : sl) cout << " " << u;
  // cout << '\n';

  ll ans = 0;
  rep(i, x + y) { ans += sl[i]; }

  // ll ans = accumulate(sl.begin(), sl.end(), 0);

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    long long one = min({Q*4, H*2, S});
    cout << min(one*N, D*(N/2)+one*(N%2)) << endl;    
}




Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
if(s[0]=='a' and s[1]=='b' and s[2]=='c') cout<<"Yes";
else if(s[0]=='a' and s[1]=='c' and s[2]=='b') cout<<"Yes";
else if(s[0]=='b' and s[1]=='a' and s[2]=='c') cout<<"Yes";
else if(s[0]=='b' and s[1]=='c' and s[2]=='a') cout<<"Yes";
else if(s[0]=='c' and s[1]=='b' and s[2]=='a') cout<<"Yes";
else if(s[0]=='c' and s[1]=='a' and s[2]=='b') cout<<"Yes";
else cout<<"No";
system("pause");
return 0;
}

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

using namespace std;

typedef long long ll;

#ifdef DEBUG
#define dbg(arg) (printf arg)
#define LOG cout << "line:" << __LINE__ << ":" << endl;
#else
#define dbg(arg)
#define LOG
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(15);
    int m;
    int n(10);
    int sum(0);
    for (int i = 0; i < 5; ++i) {
        cin >> m;
        sum += ((m + 9) / 10) * 10;
        n = min(n, m % 10 == 0 ? 10 : m % 10);
    }
    cout << sum - 10 + n << endl;
    return 0;
}



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

int main() {
  int64_t X, p = 100, ans = 0;
  cin >> X;
  while (p < X) {
    p += p / 100;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main(){
    string w;
    cin >> w;
    int ans=0;
    while(1){
        string s;
        cin >> s;
        if(s=="END_OF_TEXT")break;
        for(int i=0;i<s.size();i++){
            s[i]=tolower(s[i]);
        }
        if(s==w)ans++;
    }
    cout << ans << endl;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

const int MX = 1000010;
bool ok[1000010];

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> Acnt;
    for (int i=0; i<N; ++i) {
        cin >> A[i];
        ok[A[i]] = true;
        Acnt[A[i]] ++;
    }
    sort(A.begin(), A.end());

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (A[0] == 1) {
        if (A[1] == 1) {
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
        }
        return 0;
    }

    for (int i=0; i<N; ++i) {
        if ( ! ok[A[i]]) continue;
        for (int j=2*A[i]; j<MX; j+=A[i]) {
            ok[j] = false;
        }
    }

    int cnt = 0;
    for (int i=0; i<MX; ++i) {
        if (ok[i] && Acnt[i] == 1) {
            cnt ++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 13764
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int K,N;
    cin>>N>>K;
    double p[N];
    vector<double>t(N+1,0);
    for(int i=0;i<N;i++){
        cin>>p[i];
        t[i+1]=t[i]+p[i]*(0.5)+0.5;
        //cout<<i<<" "<<t[i]<<endl;
    }
    double maxp=0;
    for(int i=0;i<N-K+1;i++){
        maxp=max(maxp,t[i+K]-t[i]);
    }
    cout<<setprecision(18)<<maxp<<endl;
    return 0;

}

Measured memory_bytes: 6468
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)
#define size size()

int main(){
    int n,k;
    cin >> n >> k;
    vi l(n);
    rp(i,n){
        cin >> l.at(i);
    }
    sort(l);
    reverse(l);
    int ans=0;
    rp(i,k){
        ans += l.at(i);
    }
    cout << ans << endl;
}





Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int N;
  cin >> N;
  int c[500];
  int s[500];
  int f[500];
  rep(i, N - 1){
    cin >> c[i] >> s[i] >> f[i];
  }
  rep(i, N){
    int ans = 0;
    rep(j, i, N - 1){
      if(ans < s[j]) ans = s[j];
      if(ans % f[j]) ans += f[j] - (ans % f[j]);
      ans += c[j];
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t

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


int main(){
    ll N, S; cin >> N >> S;
    vector<ll> A(N); rep(i, N) cin >> A[i];
    vector<vector<ll>> DP(N+1, vector<ll>(5000+1,0));
    DP[0][A[0]] = 1;
    for(int i = 1; i < N; i++){
        ll a = A[i];
        for(int j = 0; j <= S; j++){
            DP[i][j] += DP[i-1][j] * 2; DP[i][j] %= MOD;
            if(j == a) DP[i][j] += modpow(2, i); DP[i][j] %= MOD;
            if(j-a>=0)DP[i][j] += DP[i-1][j-a]; DP[i][j] %= MOD;
        }
    }
    cout << DP[N-1][S] << endl;

}

Measured memory_bytes: 120740
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
const int infi=1e9+7;
int32_t main()
{
fastio;
int n;in n;int k;in k;
int arr[n+1];
rep(i,n) in arr[i];
vi dp(n,infi);
dp[0]=0;
for(int i=0;i<n;++i){
    for(int j=i+1;j<=i+k;++j)
        {
            //printArray(dp,n);
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
        }
}
out dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
   
using namespace std;
   
string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
long double p;
   
int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
}
   
bool check(int s_w, int s_t, int f_w, int f_t){
  if(!(t_w == -1 || (t_w == s_w && t_w == f_w))) return false;
  if(t_t == 0){
    if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) return true;
  }
  if(t_t == 1){
    if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) return true;
  }
  if(t_t == 2){
    if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
       && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) return true;
  }
  return false;
}
   
main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    if(str[1] == "All") t_t = 0;
    if(str[1] == "Day") t_t = 1;
    if(str[1] == "Night") t_t = 2;
    long double ans = 0.0;
    for(int i=0;i<7;i++){
      for(int j=0;j<24*60;j++){
        int s_w = i;
        int s_t = j;
        int cnt = 0;
        //long double cnt = 0.0;
        for(int k=0;k<m;k++){
          int f_w = s_w;
          int f_t = s_t + s;
          if(f_t >= 24 * 60){
            f_t -= 24 * 60;
            f_w = (f_w + 1) % 7;
          }
          if(check(s_w, s_t, f_w, f_t)) cnt++;
          s_t += t;
          if(s_t >= 24 * 60){
            s_t -= 24 * 60;
            s_w = (s_w + 1) % 7;
          }
        }
        ans = max(ans, 1.0 - pow((p - 1.0) / p, n * cnt));
      }
    }
    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
  }
}

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

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int N, D;
vector<int> C;
vector<vector<int>> S;

vector<int> ans;

void Read(bool local = false) {
  N = 26;
  if (local) {
    D = 365;
  } else {
    cin >> D;
  }
  C.resize(N);
  for (int i = 0; i < N; i++) {
    if (local) {
      C[i] = rnd() % 100;
    } else {
      cin >> C[i];
    }
  }
  S.resize(D);
  for (int i = 0; i < D; i++) {
    S[i].resize(N);
    for (int j = 0; j < N; j++) {
      if (local) {
        S[i][j] = rnd() % 20000;
      } else {
        cin >> S[i][j];
      }
    }
  }
  ans.assign(D, 0);
}

void Write() {
  for (auto i : ans) {
    cout << i + 1 << "\n";
  }
}

int Arithmetic(int n) {
  return n * (n - 1) / 2;
}

vector<set<int>> Build(vector<int> a) {
  vector<set<int>> occ(N);
  for (int i = 0; i < D; i++) {
    occ[a[i]].insert(i);
  }
  for (int i = 0; i < N; i++) {
    occ[i].insert(-1);
    occ[i].insert(D);
  }
  return occ;
}

int Evaluate(vector<int> a) {
  vector<int> last(N, -1);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += S[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      score -= C[j] * (i - last[j]);
    }
  }
  return score;
}

int Evaluate(int init_score, const vector<int> &a, const vector<set<int>> &occ, int d, int q) {
  if (a[d] == q) return init_score;
  const set<int> &cur = occ[a[d]];
  auto pos = cur.lower_bound(d);
  int lst = *prev(pos);
  int nxt = *next(pos);

  int score = init_score;
  score += C[a[d]] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  pos = occ[q].upper_bound(d);
  lst = *prev(pos);
  nxt = *pos;
  score -= C[q] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  score -= S[d][a[d]];
  score += S[d][q];

  return score;
}

void Change(int &init_score, vector<int> &a, vector<set<int>> &occ, int d, int q) {
  int new_score = Evaluate(init_score, a, occ, d, q);
  init_score = new_score;
  occ[a[d]].erase(d);
  a[d] = q;
  occ[a[d]].insert(d);
}

void Solve() {
  vector<int> a(D);
  for (int i = 0; i < D; i++) {
    a[i] = i % N;
  }
  int score = Evaluate(a);
  vector<set<int>> occ = Build(a);

  double temp = 10000;
  double cooling_rate = 0.9999;
  double absolute_zero = 0.001;

  while (temp > absolute_zero) {
    int d = rnd() % D;
    int q = rnd() % N;
    int delta = Evaluate(score, a, occ, d, q) - score;
    if (delta > 0 || exp(delta / temp)) {
      Change(score, a, occ, d, q);
    }
    temp *= cooling_rate;
  }
  if (Evaluate(ans) < Evaluate(a)) {
    ans = a;
  }
}

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

  Read();
  for (int rep = 0; rep < 10; rep++) {
    Solve();
  }
  Write();
  // cerr << Evaluate(ans) << "\n";
  return 0;
}


Measured memory_bytes: 4376
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V<int> a, b, ta, tb;

// V<int> MorisPlatt(const string s) {
//     int n = s.size();
//     V<int> ret(n + 1, -1);
//     int j = -1;
//     for (int i = 0; i < n; i++) {
//         while (j >= 0 && s[i] != s[j]) j = ret[j];
//         j++;
//         ret[i + 1] = j;
//     }
//     return ret;
// }

V<int> MorisPlatt(const V<int> s) {
    int n = s.size();
    V<int> ret(n + 1, -1);
    int j = -1;
    for (int i = 0; i < n; i++) {
        while (j >= 0 && s[i] != s[j]) j = ret[j];
        j++;
        ret[i + 1] = j;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n), b.resize(n), ta.resize(n), tb.resize(2 * n);

    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
        ta[i] = a[i] ^ a[(i + 1) % n];
        tb[i] = tb[i + n] = b[i] ^ b[(i + 1) % n];
    }

    V<int> con_ab;
    for (int i = 0; i < ta.size(); i++) con_ab.emplace_back(ta[i]);
    con_ab.emplace_back(-1);
    for (int i = 0; i < tb.size(); i++) con_ab.emplace_back(tb[i]);
    V<int> mp = MorisPlatt(con_ab);
    // DEBUG_VLL(con_ab)
    // DEBUG_VLL(mp)
    V< P<int, int> > ans;
    for (int i = 0; i < n; i++) {
        if (mp[mp.size() - i - 1] == n) {
            ans.emplace_back(i, a[(i - 1 + n) % n] ^ b[n - 1]);
        }
    }
    for (int i = 0; i < ans.size(); i++) cout << ans[i].first << ' ' << ans[i].second << '\n';
    return 0;
}


Measured memory_bytes: 17348
ans = Array.new(2) {0}
gets.to_i.times do
  a, b = gets.chomp.split
  case a <=> b
  when 1; ans[0] += 3
  when 0
    ans[0] += 1
    ans[1] += 1
  when -1; ans[1] += 3
  end
end
puts ans * ' '

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(10)<<fixed;
  double r;
  cin>>r;
  cout<<r*2*3.141592<<'\n';
  return 0;
}


Measured memory_bytes: 3804
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int x[100] = { 0 }, y[100] = {0};
	long h[100] = {0};//存放方程
	int n;
	cin >> n;
	int i, j;//工具人
	for (i = 0;i < n;i++)//输入方程
		cin >> x[i] >> y[i] >> h[i];
	int p = 0;
	while (h[p] == 0)p++;//应付0
	int h_ans, h_t, k, judge;
	for(i=0;i<=100;i++)//使用（i,j）来测中心坐标
		for (j = 0;j <= 100;j++)
		{
			h_ans = h[p] + abs(i - x[p]) + abs(j - y[p]);
			judge = 1;
			for (k = 0;k < n;k++)
			{
				h_t = max(h_ans - abs(i - x[k]) - abs(j - y[k]), 0);
				if (h_t!=h[k])
				{
					judge = 0;
					break;
				}
			}
			if (judge)
			{
				cout << i << ' ' << j << ' ' << h_ans << endl;
				return 0;
			}
		}
}

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

using namespace std;

typedef uint64_t ulint;
typedef int64_t lint;

// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);
template<typename T> ostream& operator << (ostream& s, const vector<T>& v);
ulint gcd(lint a, lint b);
ulint lcm(lint a, lint b);

bool flagdebug = false;





int main(){
//////////////////////////////////////////////////////

    flagdebug = true; ///本番時削除！！！！！

    //入力

    lint n;
    cin >> n;

    vector<string> s(n);
    //2次元配列
    //vector<vector<lint>> mat(row, vector<lint>(column, 初期値));

    rep0(i, n)
    {
        cin >> s[i];
    }

    sort(all(s));

    lint cnt = 1;

    rep0(i, n - 1)
    {
        if(s[i] != s[i+1])
        cnt ++;
    }

    cout << cnt << endl;


    //2次元配列
    //vector<vector<lint>> mat(row, vector<lint>(column, 初期値));
    //ペア
    //pair<lint,lint> p = make_pair(1,2);
    //vector<pair<lint,lint>> c(100010, pair<lint,lint>(0,0));
    //タプル
    //tuple<lint,lint,lint> t  = make_tuple(1,2,3);


    //昇順ソート
    //sort(all(a));
    //降順ソート
    //sort(all(a),greater<lint>());
    //特殊なソート（ラムダ式）
    //sort(all(mat), [&i](const vector<lint> &a, const vector<lint> &b){return a[i] < b[i];});
    // //[&i]は参照する変数，いらなければからの大括弧でよし．
    //ソート済集合（順序付き集合）
    //set<lint> st;
    //itr.insert(0);
    //auto itrmin = st.begin(); //最小値の次へアクセス
    //auto itrmax = st.end(); //最大値の次へアクセス（かならずデクリメントが必要）
    //itrmax --; //最大値はst.end()の1つ前
    //st.erase(0);
    //st.find;
    
    //////////////////////////////////////////////////////
    //キュー
    //queue<lint> que;
    //que.push(value);
    //que.front(); //トップを参照（消されないので消したい場合は直後にpop()を使う）
    //que.pop(); //追い出す
    //que.empty(); //空なら1，あれば0
    //優先度付きキュー
    //priority_queue<lint> que;
    //キューにque.push()で入れると最大値順に並べられる．que.pop()で取り出すときは常に最大値が前にくる．
    //最小値から取り出したい時はpriority_queue< lint, std::vector<lint>, std::greater<lint> >
    //////////////////////////////////////////////////////
    //スタック
    //stack<lint> stk;
    //stk.push(value);
    //stk.top(); //先頭を参照（消されないので消したい場合は直後にpop()を使う）
    //stk.pop(); //トップを削除
    //stk.empty(); //空なら1,あれば0
    //stk.size(); //数
    //
    // sort(input.begin() , input.end());
    // uint64_t max = numeric_limits<uint64_t>::max();

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}

//vectorprint用
template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
    s << "[\t";
    for (auto i = v.begin(); i < v.end() - 1; i++){s << *i << "\t";}
    s << *(v.end() - 1) << "\t]\n";
	return s;
}

// 最大公約数
ulint gcd(lint a, lint b){
    if(b!=0){return gcd(b, a % b);}
    return a;    
}

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


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

using ll = long long;
const int mod = 1e9 + 7;

bool is_palindrome(string S) {
    string T = S;
    reverse(begin(T), end(T));
    return S == T;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int N = S.size();
    string A = S.substr(0, N / 2);
    string B = S.substr((N + 1) / 2);
    if (is_palindrome(S) && is_palindrome(A) && is_palindrome(B)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if(S.back() == 's') S += "es";
    else S += "s";
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int count = Integer.parseInt(reader.readLine());
        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 0; i < count; ++i) {
            edges.put(i, new ArrayList<>(3));
        }

        for (int i = 0; i < count - 1; ++i) {
            String[] parts = reader.readLine().split(" ");
            int from = Integer.parseInt(parts[0]) - 1;
            int to = Integer.parseInt(parts[1]) - 1;
            edges.get(from).add(to);
            edges.get(to).add(from);
        }

        if (count == 1) {
            System.out.println(2);
            return;
        }

        int root = 0;
        for (int i = 0; i < count; ++i) {
            if (edges.get(i).size() == 1) {
                root = i;
                break;
            }
        }

        List<Integer> sorted = sortBfs(root, edges);
        Collections.reverse(sorted);

        long[] countWhite = new long[count];
        long[] countBlack = new long[count];

        for (int i : sorted) {
            countWhite[i] = 1;
            countBlack[i] = 1;
            for (int n : edges.get(i)) {
                if (countWhite[n] > 0) {
                    countWhite[i] = countWhite[i] * (countBlack[n] + countWhite[n]) % 1000000007;
                    countBlack[i] = countBlack[i] * countWhite[n] % 1000000007;
                }
            }
        }

        System.out.println((countWhite[root] + countBlack[root]) % 1000000007);
    }

    public static List<Integer> sortBfs(int start, Map<Integer, List<Integer>> edges) {
        Set<Integer> seen = new HashSet<>(edges.size());
        Queue<Integer> queue = new ArrayDeque<>();
        List<Integer> res = new ArrayList<>(edges.size());

        queue.add(start);
        seen.add(start);

        while (!queue.isEmpty()) {
            int current = queue.poll();
            res.add(current);
            for (int n : edges.get(current)) {
                if (!seen.contains(n)) {
                    queue.add(n);
                    seen.add(n);
                }
            }
        }

        return res;
    }
}

Measured memory_bytes: 81236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=10,INF=mod;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        int ma=-INF,mi=INF;
        bool ok=true;
        vector<string> S(N);
        
        for(int i=0;i<N;i++){
            cin>>S[i];
        }
        
        for(int i=0;i<N-1;i++){
            if(S[i]=="x"){
                if(S[i+1]=="x") ok=false;
                else if(i%2==0){
                    mi=min({mi,stoi(S[i+1])-1});
                }else{
                    ma=max({ma,stoi(S[i+1])+1});
                }
            }
        }
        
        for(int i=N-1;i>=1;i--){
            if(S[i]=="x"){
                if(S[i-1]!="x"){
                    if(i%2==1){
                        ma=max(ma,stoi(S[i-1])+1);
                    }else{
                        mi=min(mi,stoi(S[i-1])-1);
                    }
                }
            }
        }
        
        for(int i=1;i<N;i++){
            if(S[i-1]!="x"&&S[i]!="x"){
                if(i%2==0){
                    if(stoi(S[i-1])<=stoi(S[i])) ok=false;
                }else{
                    if(stoi(S[i-1])>=stoi(S[i])) ok=false;
                }
            }
        }
        
        if(ok){
            if(mi-ma>=1) cout<<"ambiguous"<<endl;
            else if(ma==mi) cout<<ma<<endl;
            else cout<<"none"<<endl;
        }else{
            cout<<"none"<<endl;
        }
    }
}



Measured memory_bytes: 3092
#include<iostream>
#define INF 100000000
#define N 101
#define W 0
#define G 1
#define B 2
using namespace std;
int n,M[N][N],d[N];
void dijkstra(int s){
  int color[N],mincost,p[N],u;
  for(int i=0;i<n;i++) color[i]=W,d[i]=INF;
  d[s]=0;
  p[s]=-1;

  while(1){
    mincost=INF;
     u=-1;    
    for(int i=0;i<n;i++)
      if(color[i]!=B && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
        if(mincost==INF) break;
        color[u]=B;
    for(int i=0;i<n;i++)
      if(color[i]!=B && M[u][i]!=INF)
	if(d[u]+M[u][i]<d[i]){
	  d[i]=d[u]+M[u][i];
	  p[i]=u;
	  color[i]=G;
	}
  }
}
int main(){
  int u,k,c,v;
  cin>>n;
  for(int i=0;i<N;i++) for(int j=0;j<N;j++)M[i][j]=INF;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
    M[u][v]=c;
    }
  }
  dijkstra(0);
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int N,A[3][3],b[10];
bool appear[3][3];

int main() {
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++)cin>>A[i][j];
	}
	cin>>N;
	for(int i=0;i<N;i++)cin>>b[i];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			appear[i][j]=false;
			for(int k=0;k<N;k++){
				if(A[i][j]==b[k])appear[i][j]=true;
			}
		}
	}
	
	string ans="No";
	for(int i=0;i<3;i++){
		if(appear[i][0]&&appear[i][1]&&appear[i][2])ans="Yes";
	}
	for(int i=0;i<3;i++){
		if(appear[0][i]&&appear[1][i]&&appear[2][i])ans="Yes";
	}
	if(appear[0][0]&&appear[1][1]&&appear[2][2])ans="Yes";
	if(appear[0][2]&&appear[1][1]&&appear[2][0])ans="Yes";
	
	cout<<ans<<endl;
	return 0;
}

/*
まったくわからず...
*/

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf (1 << 21)
#define mod 1000000007

int main() {
    string S; cin >> S;
    int red = 0, blue = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '0') {
            red++;
        }
        else {
            blue++;
        }
    }
    cout << 2 * min(red, blue) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
        int n,i,flg=0;
        ll a,b,now;
        cin >> n;
        vector<ll> t;
        map<ll, ll> m;
        for(i=0;i<n;++i){
                cin >> a >> b;
                if(m.find(b)==m.end()) t.push_back(b);
                m[b] += a;
        }
        sort(t.begin(),t.end());
        now = 0;
        for(auto e : t){
                now += m[e];
                if(now>e){
                        flg = 1;
                        break;
                }
        }
        if(flg) cout << "No" << endl;
        else cout << "Yes" << endl;
        return 0;
}

Measured memory_bytes: 17312
#include <iostream>
#include <bitset>

int main(void) {
	using namespace std;
	int N, M;
	cin >> N >> M;
	const int INF = 100001;
	bitset<INF> edges;
	for(int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		if(b < a) {
			int t = a;
			a = b;
			b = t;
		}
		--a;
		--b;
		edges ^= ((~bitset<INF>()) << a) & (~bitset<INF>() >> (INF - b));
	}
	edges &= (~bitset<INF>() >> (INF - (N - 1)));
	if(edges.any()) {
		cout << "NO\n";
	} else {
		cout << "YES\n";
	}
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int t, a, b;
int main(void) {
    cin >> t >> a >> b;
    cout << min(a * t, b) << endl;
    return 0;
}

Measured memory_bytes: 3552
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    a = LI()
    b = LI()
    a = [0] + a
    b = [0] + b + [0]
    cnt = 0
    for i in range(1, N+2):
        if a[i] - b[i-1] >= 0:
            cnt += b[i-1]
            a[i] = a[i] - b[i-1]
            b[i-1] = 0
        else:
            cnt += a[i]
            b[i-1] = b[i-1] - a[i]
            a[i] = 0

        if a[i] - b[i] >= 0:
            cnt += b[i]
            a[i] = a[i] - b[i]
            b[i] = 0

        else:
            cnt += a[i]
            b[i] = b[i] - a[i]
            a[i] = 0
    print(cnt)

main()



Measured memory_bytes: 21672