akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  return res;
}



int main(){

  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(14);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,0);
  rep(d,D){
    t[d] = d%26;
  }
  ll now = calc(t, -1, -1);
  while(1){
    int d=mt()%365, q=mt()%26;
    if(now<calc(t,d,q)){
      t[d]=q;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1800) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3680
def main(n,w,item):
    #dp[i][sum_w]:i-1番目までの品物から重さsum_wを超えないように
    #選択した場合の価値の最大値
    dp = [[0]*(w+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(w+1):
            #選択する場合
            weight, value = item[i]
            if j+weight <= w:
                dp[i+1][j+weight] = max(dp[i+1][j+weight], dp[i][j]+value)
            #選択しない場合
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    return max(dp[-1])

n,w = map(int, input().split())
item = [list(map(int, input().split())) for _ in range(n)]
print(main(n,w,item))

Measured memory_bytes: 120044
#include <bits//stdc++.h>
using namespace std;
int main(void){
    unsigned long long a,b,c,d,i,j,ans;
    ans=0;
    cin>>a>>b;
    vector<unsigned long long> v;
    v.push_back(0);
    for(i=0;i<a;i++){
        cin>>c;
        ans=ans+c;
        while(c){
            d=c/2;
            v.push_back(c-d);
            c=d;
        }
    }
    sort(v.begin(),v.end());
    j=v.size();
    if(j<b)
    b=j;
    for(i=0;i<b;i++){
        ans=ans-v[j-1-i];
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 34660
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  println(agc035a(n, a))
}

private fun agc035a(n: Int, a: List<Int>): String {
  var sum = 0
  for (ai in a) {
    sum = sum xor ai
  }
  if (sum == 0) {
    return "Yes"
  }

  return "No"
}


Measured memory_bytes: 55276
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef struct {
	ll p;
	char s[3];
} DATA_t ;

DATA_t PS[100001] = {0};
int ans[100002] = {0};
int a[100002] = {0};
int w[100002] = {0};
int wt[100002] = {0};
int main()
{
	ll N = 0, M = 0, i = 0;
	int ans_w = 0, ans_a = 0;
	scanf("%lld %lld", &N, &M);
	for (i = 0; i < M; i ++) {
		scanf("%lld %s", &(PS[i].p), &(PS[i].s[0]));
		//printf("%lld %s\n", PS[i].p, PS[i].s);
	}

	for (i = 0; i < M; i++) {
			if (PS[i].s[0] == 'W') {
				wt[PS[i].p]++;
			}
			if (ans[PS[i].p] == 0) {
				if (PS[i].s[0] == 'A') {
					a[PS[i].p]++;
					w[PS[i].p] = wt[PS[i].p];
					ans[PS[i].p]++;
				}
			}
	}
	for (i = 0; i < 100002; i++) {
		ans_a += a[i];
		ans_w += w[i];
	}
	printf("%d %d\n", ans_a, ans_w);
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int a,b,c;
    string S,T;

    cin>>c>>a>>b;
    cout<<((a/c==b/c&&a%c!=0&&b%c!=0)?"NG":"OK")<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   cin>>TT;
   map <string,ll> mp;
   while(TT--)
   {      
       string s;
       cin>>s;
       mp[s]++;
   }
   cout<<"AC x "<<mp["AC"]<<"\n";
   cout<<"WA x "<<mp["WA"]<<"\n";
   cout<<"TLE x "<<mp["TLE"]<<"\n";
   cout<<"RE x "<<mp["RE"]<<"\n";
}

Measured memory_bytes: 3668
# encoding:utf-8

import copy
import numpy as np
import random

nums = [int(i) for i in input().split()]
ans = 0
even = 0

for i in range(3):
    if nums[i]%2 == 0:
        even+=1

if even==3:
    pass
elif even==2:
    for i in range(3):
        if nums[i]%2==0:
            nums[i]+=1
    ans+=1

elif even==1:
    for i in range(3):
        if nums[i]%2==1:
            nums[i]+=1
    ans+=1
else:
    pass

goal_num = max(nums)
ans += (3*goal_num-sum(nums))//2
print(ans)


Measured memory_bytes: 23832
#include<stdio.h>

#define VMAX 10001

int main()
{
    int i, n, val, max, C[VMAX];
    scanf("%d", &n);
    max = 0;

    for(val = 0; val < VMAX; val++) C[val] = 0;

    for(i = 0; i < n; i++){
        scanf("%d", &val);
        C[val] = C[val] + 1;
        if(max < val) max = val;
    }
    for(val = 0; C[val] == 0; val++);
    printf("%d", val);
    C[val] = C[val] - 1;

    while(val <= max){
        if(C[val] > 0){
            printf(" %d", val);
            C[val] = C[val] - 1;
        }else{
            val++;
        }
    };
    printf("\n");

    return 0;
}

Measured memory_bytes: 1072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}
	ll h1 = ((w + 1) / 2) * ((h + 1) / 2);
	ll h2 = (h / 2) * (w / 2);
	ll ans = h1 + h2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
M = 10**9 + 7
def cmb(n,r):
    x = 1
    y = 1
    for i in range(r):
        x *= n - i
        x %= M
        y *= (i + 1)
        y %= M
    return x * pow(y, M-2, M) % M

print((pow(2,n,M)-cmb(n,a)-cmb(n,b)-1)%M)

Measured memory_bytes: 80076
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 100010
const int mod = 1e9 + 7;
int a[maxn], b[maxn], mn[maxn], mx[maxn];
int main()
{
//	setfile();
	int n, maxx, ans = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	if (n == 1) return !printf("%d\n", a[1] == b[1] );
	maxx = dmax(a[n], b[1]);
	for (int i = 1; i <= n; ++i) mn[i] = 1, mx[i] = maxx;
	mn[1] = mx[1] = a[1];
	for (int i = 2; i <= n; ++i)
		if (a[i] > a[i - 1])
			mn[i] = mx[i] = a[i];
		else
			cmin(mx[i], a[i]);
	for (int i = n; i; --i)
		if (i == n || b[i] > b[i + 1])
			if (mn[i] <= b[i] && b[i] <= mx[i])
				mn[i] = mx[i] = b[i];
			else ans = 0;
		else
			cmin(mx[i], b[i]);
	for (int i = 1; i <= n && ans; ++i)
		ans = 1ll * ans * (mn[i] <= mx[i] ? mx[i] - mn[i] + 1 : 0) % mod;
	printf("%d\n", ans );
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    map<long, vector<long>, greater<long>> nums;
    for(int i = 0; i < N; i++){
        long num;
        cin >> num;
        nums[num].push_back(i);
    }
    nums[0] = {};
    vector<long> ans(N, 0);
    long leftmost = 1e9;
    long second_size_sum = 0;
    for(auto i = nums.begin(); i != --nums.end(); ){
        leftmost = min(leftmost, (*i).second[0]);
        second_size_sum += int((*i).second.size());
        ans[leftmost] += ((*i).first - (*(++i)).first) * second_size_sum;
    }
    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 12800
n=int(input())
s=input()
w=[0]*(n+1)
for i in range(n):
    w[i+1]=w[i]+(s[i]=="E")
ans=n
for i in range(n):
    ans=min(ans,(i-w[i])+(w[n]-w[i+1]))
print(ans)


Measured memory_bytes: 15244
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>

using namespace std;

typedef pair<int, int> P;

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

int main() {
  while(true) {
    int T, N;
    cin >> T >> N;

    if (T == 0 && N == 0) break;
    // x, y
    set<P> obj;

    for(int i = 0; i < N; i++) {
      int x, y;
      cin >> x >> y;
      obj.insert(make_pair(x, y));
    }

    P start;
    cin >> start.first >> start.second;

    queue<P> Q;
    queue<P> Next;
    set<P> vis;
    Q.push(start);

    vis.insert(start);

    int cnt = 1;

    while(T--) {
      while(!Next.empty()) Next.pop();

      while(!Q.empty()) {
        P cur = Q.front(); Q.pop();
        //cerr << "(" << cur.first << "," << cur.second << ")" << endl;
        for(int i = 0; i < 6; i++) {
          P p;
          p.first = cur.first + dx[i];
          p.second = cur.second + dy[i];
          if(obj.count(p)) continue;
          if(vis.count(p)) continue;
          vis.insert(p);
          Next.push(p);

          cnt++;
        }
      }

      Q = Next;
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 1368
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
const int MAXN = 30;
typedef long long LL;
const LL mod = 998244353;
int main()
{
    int n, k;
    scanf("%d %d",&n, &k);
    LL sum=0;
    if(k==0)
    {
        printf("%lld\n", 1LL*n*n);
        return 0;
    }
    for(int i=k+1;i<=n;++i)
    {
        sum+=n/i*(i-k);
        if(n%i!=0&&n%i>=k)
        {
            sum+=n%i-k+1;
        }
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    c = 0
    while True:
        if K ** c > N:
            print(c)
            return
        else:
            c += 1


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
count = 0
for i in 0..a do
    for j in 0..b do
        for k in 0..c do
            if i * 500 + j * 100 + k * 50 == x
                count += 1
            end
        end
    end
end
puts count

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,r; cin >> n >> r;
  int ans=r;
  
  if(n<10) ans = r+100*(10-n);

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a[200111],b[200111];
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get1(b[i]);
	for(int i=1;i<=n;i++)a[b[i]]=i;
	int ans=0,last=0;
	for(int i=2;i<=n;i++)
	{
		if(a[i]>a[i-1])last++;
		else last=0;
		ans=max(ans,last);
	}
	printendl(n-ans-1);
	return 0;
}

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

int main(){
  int H,W;
  cin>>H>>W;
  
  string a;
  for(int i=0;i<W+2;i++)
    a+="#";
    cout<<a<<endl;
  
  for(int i=0;i<H;i++){
    string S;
    cin>>S;
    cout<<'#'+S+'#'<<endl;
  }
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
    int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
    NodePointer cur = nil->next;
    while( cur != nil && cur->key != key ){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    NodePointer cur = nil->next;
    int isf = 0;
    while(1){
        if ( cur == nil ){break;}
        if ( isf ++> 0){printf(" ");}
        printf("%d", cur->key);
        cur = cur->next;
        
    }
    printf("\n");
}


void deleteNode(NodePointer t){
    if(t==nil){return;}
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    NodePointer t = nil->next;
    if ( t == nil ) return;
    deleteNode(t);
}


void deleteLast(){
    
    if ( nil->prev == nil ) return;
    deleteNode(nil->prev);
}

void delete(int key){
    
    if ( listSearch(key) == nil ) return;
    deleteNode(listSearch(key));
}


void insert(int key){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ){
        scanf("%s%d", com, &key);
    
        if ( com[0] == 'i' ) {insert(key); np++; size++;}
        else if ( com[0] == 'd' ) {
        if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
        } else {
        delete(key); nd++; 
        }
        size--;
        }
        
    }

    
    printList();


    return 0;
}





Measured memory_bytes: 32948
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def can_replace(S, T):
    cnt = 0
    for s, t in zip(S, T):
        if s == t or s == '?':
            cnt += 1
    if cnt == len(S):
        return True
    else:
        return False


def main():
    S = list(ns()[::-1])
    T = list(ns()[::-1])
    for i in range(len(S) - len(T) + 1):
        if can_replace(S[i:i + len(T)], T):
            S[i:i + len(T)] = T
            S = ''.join(S)
            print(S.replace('?', 'a')[::-1])
            return
    print('UNRESTORABLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
MOD = 10 ** 9 +7
h, w, k = map(int,input().split())

if w == 1:
    print(1)
else:
    acr = []
    for p in range(2**(w-1)):
        det = 0
        pp = p
        exist = [0] * (w-1)
        for i in range(w-1):
            exist[i] = pp % 2
            pp = pp // 2
        for ii in range(w-2):
            if exist[ii] == 1 and exist[ii+1] == 1:
                det = 1
        if det == 0:
            acr.append(exist[:])
    #print(acr)

    cur = [0] * w
    cur[0] = 1
    

    for t in range(h):
        n = [0] * w
        for x in range(len(acr)):
            n[0] = (n[0] + cur[1] * acr[x][0] + cur[0] * (1-acr[x][0]))%MOD
            for j in range(1,w-1):
                n[j] = (n[j] + cur[j-1] * acr[x][j-1] + cur[j+1] * acr[x][j] + cur[j] * (1-acr[x][j-1])*(1-acr[x][j]))%MOD
            n[w-1] = (n[w-1] + cur[w-2] * acr[x][w-2] + cur[w-1] * (1-acr[x][w-2])) % MOD
        
        cur = n[:]
        
    print(cur[k-1])

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))


dp = [0] * 100
dp[0] = 1000
for i in range(1,N):
    dp[i] = dp[i-1]
    for j in range(0,i):
        V = int(dp[j] / A[j])
        W = dp[j] + (A[i] - A[j]) * V
        dp[i] = max(dp[i], W)
print(dp[N-1])



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

int main()
{
  int A, B; cin >> A >> B;
  int res = 0;
  for(int i = 0; i < 2; i++)
  {
    if(A > B)
    {
      res += A;
      A -= 1;
    }
    else
    {
      res += B;
      B -= 1;
    }
  }
  cout << res << endl;
}

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

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

    set<string> S;
    rep(i,N){
        string s;
        cin >> s;
        S.insert(s);
    }

    cout << S.size() << endl;
}

Measured memory_bytes: 19148
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var ans = int.MaxValue;
            for (int i = 0; i <= S.Length - 3; i++)
            {
                var num = int.Parse(S.Substring(i, 3));
                if (Math.Abs(753 - num) < ans) ans = Math.Abs(753 - num);
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main()
{
  long long int X;

  cin >> X;

  long long int x = 100;

  long long int count = 0;

  while (X > x)
  {
    count++;
    x *= 1.01;
  }

  cout << count << endl;
}


Measured memory_bytes: 3636
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

vector<vector<char> > solve(vector<vector<char> > &in){
	// 90度回転
	vector<vector<char> > out(8, vector<char>(8));
	FOR(i, 0, 8){
		for (int j = 7, k = 0; j >= 0, k < 8; j--,k++){
			out[i][k] = in[j][i];
		}
	}
	return out;
}

void Output(vector<vector<char> > now, int a){
	cout << a << endl;
	FOR(i, 0, 8){
		FOR(j, 0, 8){
			cout << now[i][j];
		}
		cout << endl;
	}
}

int main(){
	fastIO;
	vector<vector<char> > in(8, vector<char>(8));

	FOR(i, 0, 8)
		FOR(j, 0, 8)
		cin >> in[i][j];

	in = solve(in);
	Output(in, 90);
	in = solve(in);
	Output(in, 180);
	in = solve(in);
	Output(in, 270);

	return 0;
}

Measured memory_bytes: 1204
fun main(args:Array<String>){
    val (n,l) = readLine()!!.split(" ").map{it.toInt()}
    val a = Array<Int>(n){0}
    for(i in 0 until n){
        a[i] = l + i
    }
    val sum = a.sum()
    var ans = 100000
    var mi = 100000
    for(i in 0 until n){
        if(Math.abs(a[i]) < mi){
            ans = sum - a[i]
            mi = Math.abs(a[i])
        }
    }
    println(ans)
}


Measured memory_bytes: 38028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define lb lower_bound
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a[200010],b[200010],c[200010],d[200010],k1,k2,t,u,cnt,ans=0;
  cin>>n;
  fr(i,n) cin>>a[i];
  fr(i,n) cin>>b[i];
  fr(i,30){
    t=1ll<<i;
    u=2*t-1;
    fr(i,n) c[i]=a[i]&u;
    fr(i,n) d[i]=b[i]&u;
    sort(d,d+n);
    cnt=0;
    fr(i,n){
      k1=lb(d,d+n,2*t-c[i])-lb(d,d+n,t-c[i]);
      k2=lb(d,d+n,4*t-c[i])-lb(d,d+n,3*t-c[i]);
      cnt+=k1+k2;
    }
    ans+=(cnt%2)*t;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include <iostream>
     #include <string>
     #include <vector>
     #include <algorithm>
     #include <utility>
     #include <map>
     using namespace std;
     typedef long long ll;
     #define rep(i, n) for (int i=0;i < (int)(n);i++)
     
     double dp[2][3001];

     int main(){
          int n;
          cin >> n;
          vector<double> p(n);
          rep(i,n) cin >> p[i];
          int now=0;
          int nxt=1;
          dp[0][0]=1.0f;
          rep(i,n){
               rep(l,n+1) dp[nxt][l]=0.0f;
               rep(x,n+1){
                    if (dp[now][x]==0) continue;
                    dp[nxt][x+1]+=dp[now][x]*p[i];
                    dp[nxt][x]+=dp[now][x]*(1.0-p[i]);
               }
               //rep(q,n+1) rep(w,n+1) printf("(i,j) = (%d,%d) p = %.8f\n " ,q,w,dp[now][q][w]);
               //printf("\n");
               swap(now,nxt);
          }
          double ans=0.0;
          rep(i,n+1) {
               if (i >= (n+2-1)/2) ans+=dp[now][i];
               //printf("(i,j) = ( %d,%d ) p = %.8f\n",i,j,dp[now][i][j]);
          }
          printf("%.10f\n",ans);
          return 0;
     }


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

int main() {
  int n;
  cin >> n;
  set<int> st;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  cout << st.size() << endl;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
ll a, ans, tmp = 1, ls[200001];
const int MOD = 1e9 + 7;

ll sqr(int x) {
	return (ll)x * x % MOD;
}

ll pow(int x, int y) {
	return y ? sqr(pow(x, y / 2)) * (y & 1 ? x : 1) % MOD : 1;
}

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

	cin >> n;
	FOR(i, 1, n + 1) ls[i] = (ls[i - 1] + pow(i, MOD - 2)) % MOD;
	FOR(i, 1, n + 1) {
		cin >> a;
		(ans += a * (ls[i] + ls[n - i + 1] - 1 + MOD) % MOD) %= MOD;
		(tmp *= i) %= MOD;
	}
	cout << ans % MOD * tmp % MOD << endl;

    return 0;
}                         




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

struct vec{
    double x,y;
    vec operator-(vec b){
        vec& a = *this;
        vec c;
        c.x=a.x-b.x; c.y=a.y-b.y;
        return c;
    }
    vec operator+(vec b){
        vec& a = *this;
        vec c;
        c.x=a.x+b.x; c.y=a.y+b.y;
        return c;
    }
    vec operator*(double d){
        vec& a = *this;
        vec c;
        c.x=a.x*d; c.y=a.y*d;
        return c;
    }
};

const double eps = 0.0000001;

double inner_product(vec& a, vec& b){
    return a.x*b.x+a.y*b.y;
}

double outer_product(vec& a, vec& b){
    return a.x*b.y-a.y*b.x;
}

vec interSection(vec (&p)[4]){
    vec p23=p[3]-p[2],p02=p[2]-p[0],p01=p[1]-p[0];
    double k = outer_product(p23,p02)/outer_product(p23,p01);
    return p[0]+p01*k;
}

int main(void){
    vec p[4];
    int q;
    cin >> q;
    cout.precision(10);
    cout << fixed;
    while(q--){
        for(auto& v : p) cin >> v.x >> v.y;
        vec v = interSection(p);
        cout << v.x << " " << v.y << endl;
    }
    return 0;
}

Measured memory_bytes: 3244
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>

#define numof(array) (sizeof (array) / sizeof *(array))
using namespace std;

#define INF (1 << 29)
static const int dx[] = {1, 0, -1, 0};
static const int dy[] = {0, 1, 0, -1};

#define MAX_H 1000
#define MAX_W 1000

int H, W, N;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W];//スタートからの距離


typedef pair<int, int> P;

int bfs(const P start, const P goal)
{
    queue<P> que;
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = INF;
        }
    }

    que.push(start);
    d[start.second][start.first] = 0;


    while (que.size()) {
        P p = que.front();
        que.pop();
        if (p == goal) break;
        
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
                
            if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] != 'X' && d[ny][nx] == INF) {
                que.push(P(nx, ny));
                d[ny][nx] = d[p.second][p.first] + 1;
            }
            
        }
    }
    return d[goal.second][goal.first];
}

    
int main(void)
{
    cin  >> H >> W >> N;

    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            field[y][x] = 'X';
        }
    }

    P zahyo[10];//スタートと工場1,2,3...の座標
    for (int i = 0; i < 10; i++) {
        zahyo[i] = P(-1, -1);
    }


    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            cin >> field[y][x];
            
            //スタートと工場を見つけておく
            if ('0' < field[y][x] && field[y][x] <= '9') {
                zahyo[field[y][x] - '0'] = P(x, y);
            }
            if (field[y][x] == 'S') {
                zahyo[0] = P(x, y);
            }
            
        }
    }
        
    int cnt = 0;
    int answer = 0;
    while (cnt < N) {//-1でない間
        answer += bfs(zahyo[cnt], zahyo[cnt+1]);
        cnt++;
    }

    cout << answer << endl;
	return 0;
}

Measured memory_bytes: 6100
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda:0)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 94288
//Induber
//PRAVEEN FULERA

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

typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)
vector <int> v;

int main(){
  speed up
  int m , k;
  cin >> m >> k;
  m = pow(2 , m) - 1;
  if(k>m || (k==1 && m==1)){
      cout << "-1\n";
      return 0;
  }
  if(k==0){
      for(int i = 0; i <= m; i++){
          cout << i << " " << i << " ";
      }
      return 0;
  }
  int tot = 0;
  int yes;
  for(int i = 0; i <= m; i++){
      v.pb(i);
      tot^=i;
  }
  for(int i = 0; i <= m; i++){
      yes = tot^v[i];
      if(yes == k){
          yes = v[i];
          break;
      }
  }
  cout << yes << " ";
  for(int i = 0; i <= m; i++){
      if(v[i]!=yes){
          cout << v[i] << " ";
      }
  }
  cout << yes << " ";
  for(int i = m; i >= 0; i--){
      if(v[i]!=yes){
          cout << v[i] << " ";
      }
  }
}

Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>

using namespace std;

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

#define fs first
#define sc second


class x{
public:
    string s;
    int p;
    int id;
};

bool comp(x y1, x y2){
    if(y1.s < y2.s){
        return true;
    }
    else if(y1.s > y2.s){
        return false;
    }
    else{
        return y1.p >= y2.p;
    }
}


int main(){
    int N;
    cin >> N;
    vector<x> z;
    for(int i = 0; i < N; i++){
        x y;
        cin >> y.s >> y.p;
        y.id = i+1;
        z.emplace_back(y);
    }

    sort(z.begin(), z.end(), comp);

    for(auto zz: z){
        cout << zz.id << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int h,H,m,M,k,time; cin>>h>>m>>H>>M>>k;
  
  time=(H*60+M)-(h*60+m);
  
  
  cout<< time-k <<endl;
}


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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		int crr[n], drr[m];
		for (int i = 0; i < n; i++) {
			cin >> crr[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> drr[i];
		}
		int s = 0;
		int i, j;
		for (i = 0; i < n; i++) {
			if (s + crr[i] <= k)
				s += crr[i];
			else break;
		}
		int z = i - 1;
		for (j = 0; j < m; j++) {
			if (s + drr[j] <= k)
				s += drr[j];
			else break;
		}
		int x = j;
		int ans = 0;
		ans = max(ans, z + x + 1);
		while (z >= 0) {
			if (x >= m) break;
			if (z < 0) break;
			s = s - crr[z];
			z--;
			ans = max(ans, z + x + 1);
			if (x >= m) break;
			while (s + drr[x] <= k) {
				if (x >= m) break;
				s += drr[x];
				x++;
				ans = max(ans, z + x + 1);
				if (x >= m) break;
			}
		}
		ans = max(ans, z + x + 1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6732
(let* ((H (read))
       (W (read))
       (N (read))
       (As (loop repeat N
                 collect (read)))
       (Cs (apply #'append (loop for i from 1
                                 for e in As
                                 collect (loop repeat e
                                              collect i)))))
  (labels ((f (list rev-q)
             (when list (format t "~{~A ~}~%" (if rev-q
                                                  (subseq list 0 W)
                                                  (reverse (subseq list 0 W))))
                        (f (nthcdr W list) (not rev-q)))))
    (f Cs nil)))

Measured memory_bytes: 18912
// abc133_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, A, B;
    cin >> N >> A >> B;

    print(min(N*A, B));

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
P = list(map(int,input().split()))

s=0
for i in range(k):
    s += P[i]

ms=s
for i in range(len(P)-k):
    s +=(P[i+k]-P[i])
    if s>ms :
        ms=s

print( (ms+k)/2)




Measured memory_bytes: 32028
#include <bits/stdc++.h>
#define MOD (long long)(1e9 + 7)
using namespace std;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

long long n;
vector<long long> cnt, edges[200005], par;
vector<bool> ch;

ModInt<MOD> solve();
long long rec(long long now);

int main() {
  cin >> n;
  for(int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  cout << solve() << endl;
  return 0;
}

ModInt<MOD> solve() {
  ModInt<MOD> res, two = 2;
  cnt.assign(n, 0);
  ch.assign(n, 0);
  par.assign(n, -1);
  ch[0] = 1;
  rec(0);
  for(int i = 0; i < n; ++i) {
    ModInt<MOD> now = 0;
    for(auto nowp : edges[i])
      if(par[i] != nowp) now += two.pow(cnt[nowp]) - 1;
    if(par[i] != -1) now += two.pow(n - cnt[i]) - 1;
    res += two.pow(n - 1) - 1 - now;
  }
  return res / two.pow(n);
}

long long rec(long long now) {
  long long res = 0;
  for(auto nextp : edges[now]) {
    if(!ch[nextp]) {
      ch[nextp] = 1;
      par[nextp] = now;
      res += rec(nextp);
    }
  }
  return cnt[now] = res + 1;
}

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

using namespace std;


#define PI 3.14159265
#define int long long

const int MAXN = 1e5;




main(){

	string s; cin >> s;

	deque <char> deq;

	for(char c : s) deq.push_back(c);

	bool rev = false;

	int q; cin >> q;

	int t, f; char c;
	for(int i = 0; i < q; i++){
		cin >> t;

		if(t == 1){
			if(rev){
				rev = false;
			}else{
				rev = true;
			}
		}else{
			cin >> f >> c;
			if(f == 1){
				if(rev){
					deq.push_back(c);
				}else{
					deq.push_front(c);
				}
			}else{
				if(rev){
					deq.push_front(c);
				}else{
					deq.push_back(c);
				}
			}
		}
	}

	// cout << rev << endl;
	
	if(rev){
		while(!deq.empty()){
			cout << deq.back();
			deq.pop_back();
		}
	}else{
		while(!deq.empty()){
			cout << deq.front();
			deq.pop_front();
		}
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
using namespace std;


int main() {
	int N, K; cin >> N >> K;
	int x[1000000]; for (int i = 1; i <= N; i++) cin >> x[i];
	long res = 1000000000;

	for (int i = 1; i <= N - K + 1; i++) {
		long af = abs(x[i]), al = abs(x[i + K - 1]);
		res = min(res, x[i + K - 1] - x[i] + min(af, al));
	}

	cout << res << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var pa=new Pair[n];
		var c=new Pair(0,0);
		for(int i = 0;i<n;i++) {
			pa[i]=new Pair(sc.Da);
			c.x+=pa[i].x;
			c.y+=pa[i].y;
		}
		c.x/=n;
		c.y/=n;
		double p=0.1,d=0;
		while(true){
			int g=0;
			d=(pa[0].x-c.x)*(pa[0].x-c.x)+(pa[0].y-c.y)*(pa[0].y-c.y);
			for(int i = 1;i<n;i++) {
				var f=(pa[i].x-c.x)*(pa[i].x-c.x)+(pa[i].y-c.y)*(pa[i].y-c.y);
				if(d<f){d=f;g=i;}
			}
			c.x+=(pa[g].x-c.x)*p;
			c.y+=(pa[g].y-c.y)*p;
			if(Abs((pa[g].x-c.x)*p)+Abs((pa[g].y-c.y)*p)<1e-11){break;}
			p*=0.999;
		}
		Console.WriteLine("{0}",Sqrt(d));
	}
}
public struct Pair{
	public double x,y;
	public Pair(double x,double y){this.x=x;this.y=y;}
	public Pair(double[] d){x=d[0];y=d[1];}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

ll parr(vector<ll> vt, int p){
    ll add = 0 ;
    ll res = 0;
    ll nadd;
    for(int i = 0 ; i < vt.size(); i ++ ){
        nadd = vt[i] + add;
        if(i % 2 == p){
            if(nadd <= 0){
                res += (-nadd) + 1;
                vt[i] += (-nadd) + 1;
            }
        }
        else{
            if(nadd >= 0){
                res += nadd + 1;
                vt[i] -= nadd + 1;
            }
        }
        add += vt[i];
    }
    return res;
}

int main(){
    fastIO;
    int n;
    cin >> n;
    ll x;
    vector<ll> t;
    for(int i = 0 ; i< n ; i ++ ){
        cin >> x;
        t.push_back(x);
    }
    cout << min(parr(t,0), parr(t,1));
    return 0;
}

Measured memory_bytes: 2804
#include<stdio.h>
int main(){
	int a,b,d=0,r=0;
	double f=0.0;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 2684
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
 
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;
 

void solve(){
    ll n;
    cin >> n;
    
    map<int,int> ps;
    
    int c2 = 0;
    while (n % 2 == 0){  
        c2++;
        n = n/2;  
    }  
    if (c2) ps[2] = c2;
  
    for (ll i = 3; i*i <= n; i = i + 2){  
        int c = 0;
        while (n % i == 0){  
            c++;
            n = n/i;  
        }  
        if (c) ps[i] = c;
    }  
    if (n!=1) ps[n] = 1;
    
    
    int ans = 0;
    
    for(auto e: ps){
        int t = e.second;
        int i = 1;
        while(t){
            while(t-i <= i && t-i > 0){
                i++;
            }
            
            while(t-i > i || t-i == 0){
                t-=i;
                i++;
                ans++;
            }
        }
    }
    cout << ans;
}


 
int main(){
    int T;
    T = 1;
    while(T--){
        solve(); 
    }
}
 


Measured memory_bytes: 3632